Botan 3.5.0
Crypto and TLS for C&
kyber_encaps_base.h
Go to the documentation of this file.
1/*
2 * Key encapsulation base operations for Kyber
3 * (C) 2024 Jack Lloyd
4 * (C) 2024 René Meusel, Rohde & Schwarz Cybersecurity
5 *
6 * Botan is released under the Simplified BSD License (see license.txt)
7 */
8
9#ifndef BOTAN_KYBER_KEY_ENCAPSULATION_BASE_H_
10#define BOTAN_KYBER_KEY_ENCAPSULATION_BASE_H_
11
12#include <botan/internal/kyber_constants.h>
13#include <botan/internal/kyber_structures.h>
14#include <botan/internal/kyber_types.h>
15#include <botan/internal/pk_ops_impl.h>
16
17namespace Botan {
18
20 public:
21 size_t raw_kem_shared_key_length() const override { return mode().shared_key_length(); }
22
23 size_t encapsulated_key_length() const override { return mode().encapsulated_key_length(); }
24
25 void raw_kem_encrypt(std::span<uint8_t> out_encapsulated_key,
26 std::span<uint8_t> out_shared_key,
27 RandomNumberGenerator& rng) final {
29 StrongSpan<KyberSharedSecret>(out_shared_key),
30 rng);
31 }
32
33 protected:
34 Kyber_KEM_Encryptor_Base(std::string_view kdf) : PK_Ops::KEM_Encryption_with_KDF(kdf) {}
35
36 virtual void encapsulate(StrongSpan<KyberCompressedCiphertext> out_encapsulated_key,
37 StrongSpan<KyberSharedSecret> out_shared_key,
38 RandomNumberGenerator& rng) = 0;
39
40 virtual const KyberConstants& mode() const = 0;
41};
42
44 public:
45 size_t raw_kem_shared_key_length() const override { return mode().shared_key_length(); }
46
47 size_t encapsulated_key_length() const override { return mode().encapsulated_key_length(); }
48
49 void raw_kem_decrypt(std::span<uint8_t> out_shared_key, std::span<const uint8_t> encapsulated_key) final {
52 }
53
54 protected:
55 Kyber_KEM_Decryptor_Base(std::string_view kdf) : PK_Ops::KEM_Decryption_with_KDF(kdf) {}
56
57 virtual void decapsulate(StrongSpan<KyberSharedSecret> out_shared_key,
59
60 virtual const KyberConstants& mode() const = 0;
61};
62
63} // namespace Botan
64
65#endif
size_t shared_key_length() const
size_t encapsulated_key_length() const
size_t raw_kem_shared_key_length() const override
virtual const KyberConstants & mode() const =0
size_t encapsulated_key_length() const override
void raw_kem_decrypt(std::span< uint8_t > out_shared_key, std::span< const uint8_t > encapsulated_key) final
Kyber_KEM_Decryptor_Base(std::string_view kdf)
virtual void decapsulate(StrongSpan< KyberSharedSecret > out_shared_key, StrongSpan< const KyberCompressedCiphertext > encapsulated_key)=0
virtual void encapsulate(StrongSpan< KyberCompressedCiphertext > out_encapsulated_key, StrongSpan< KyberSharedSecret > out_shared_key, RandomNumberGenerator &rng)=0
void raw_kem_encrypt(std::span< uint8_t > out_encapsulated_key, std::span< uint8_t > out_shared_key, RandomNumberGenerator &rng) final
size_t encapsulated_key_length() const override
Kyber_KEM_Encryptor_Base(std::string_view kdf)
virtual const KyberConstants & mode() const =0
size_t raw_kem_shared_key_length() const override
KEM_Decryption_with_KDF(std::string_view kdf)
Definition pk_ops.cpp:223
KEM_Encryption_with_KDF(std::string_view kdf)
Definition pk_ops.cpp:190