Botan 3.6.1
Crypto and TLS for C&
kyber_types.h
Go to the documentation of this file.
1/*
2 * Crystals Kyber key encapsulation mechanism
3 *
4 * Strong Type definitions used throughout the Kyber implementation
5 *
6 * (C) 2024 Jack Lloyd
7 * (C) 2024 René Meusel, Rohde & Schwarz Cybersecurity
8 *
9 * Botan is released under the Simplified BSD License (see license.txt)
10 */
11
12#ifndef BOTAN_KYBER_TYPES_H_
13#define BOTAN_KYBER_TYPES_H_
14
15#include <botan/secmem.h>
16#include <botan/strong_type.h>
17#include <botan/internal/kyber_polynomial.h>
18#include <botan/internal/pqcrystals.h>
19
20#include <variant>
21#include <vector>
22
23namespace Botan {
24
28
31
32/// Principal seed used to generate Kyber key pairs
33using KyberSeedRandomness = Strong<secure_vector<uint8_t>, struct KyberSeedRandomness_>;
34
35/// Public seed value to generate the Kyber matrix A
36using KyberSeedRho = Strong<std::vector<uint8_t>, struct KyberSeedRho_>;
37
38/// Private seed used to generate polynomial vectors s and e during key generation
39using KyberSeedSigma = Strong<secure_vector<uint8_t>, struct KyberSeedSigma_>;
40
41/// Secret random value (called Z in the spec), used for implicit rejection in the decapsulation
42using KyberImplicitRejectionValue = Strong<secure_vector<uint8_t>, struct KyberImplicitRejectionValue_>;
43
44/// Random message value to be encrypted by the CPA-secure Kyber encryption scheme
45using KyberMessage = Strong<secure_vector<uint8_t>, struct KyberMessage_>;
46
47/// Random value used to generate the Kyber ciphertext
48using KyberEncryptionRandomness = Strong<secure_vector<uint8_t>, struct KyberEncryptionRandomness_>;
49
50/// PRF value used for sampling of error polynomials
51using KyberSamplingRandomness = Strong<secure_vector<uint8_t>, struct KyberSamplingRandomness_>;
52
53/// Shared secret value generated during encapsulation and recovered during decapsulation
54using KyberSharedSecret = Strong<secure_vector<uint8_t>, struct KyberSharedSecret_>;
55
56/// Public key in serialized form (t || rho)
57using KyberSerializedPublicKey = Strong<std::vector<uint8_t>, struct KyberSerializedPublicKey_>;
58
59/// Hash value of the serialized public key
60using KyberHashedPublicKey = Strong<std::vector<uint8_t>, struct KyberHashedPublicKey_>;
61
62/// Compressed and serialized ciphertext value
63using KyberCompressedCiphertext = Strong<std::vector<uint8_t>, struct KyberCompressedCiphertext_>;
64
65/// Hash of the compressed and serialized ciphertext value
66/// TODO: Remove this once Kyber-R3 is removed
67using KyberHashedCiphertext = Strong<std::vector<uint8_t>, struct KyberHashedCiphertext_>;
68
69/// Variant value of either a KyberSeedSigma or a KyberEncryptionRandomness
71 std::variant<StrongSpan<const KyberSeedSigma>, StrongSpan<const KyberEncryptionRandomness>>;
72
74 std::pair<std::shared_ptr<Kyber_PublicKeyInternal>, std::shared_ptr<Kyber_PrivateKeyInternal>>;
75
76/// NIST FIPS 203, Section 3
77/// The seed (𝑑,𝑧) generated in steps 1 and 2 of ML-KEM.KeyGen can be stored
78/// for later expansion using ML-KEM.KeyGen_internal.
80 std::optional<KyberSeedRandomness> d;
82};
83
84} // namespace Botan
85
86#endif
std::variant< StrongSpan< const KyberSeedSigma >, StrongSpan< const KyberEncryptionRandomness > > KyberSigmaOrEncryptionRandomness
Variant value of either a KyberSeedSigma or a KyberEncryptionRandomness.
Definition kyber_types.h:70
std::pair< std::shared_ptr< Kyber_PublicKeyInternal >, std::shared_ptr< Kyber_PrivateKeyInternal > > KyberInternalKeypair
Definition kyber_types.h:73
KyberImplicitRejectionValue z
Definition kyber_types.h:81
std::optional< KyberSeedRandomness > d
Definition kyber_types.h:80