Coverage Report

Created: 2024-11-29 06:10

/src/botan/build/include/internal/botan/internal/kyber_round3_impl.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Crystals Kyber key encapsulation mechanism and key codec
3
 *
4
 * (C) 2024 Jack Lloyd
5
 * (C) 2024 René Meusel, Rohde & Schwarz Cybersecurity
6
 *
7
 * Botan is released under the Simplified BSD License (see license.txt)
8
 */
9
10
#ifndef BOTAN_KYBER_R3_ENCAPSULATION_H_
11
#define BOTAN_KYBER_R3_ENCAPSULATION_H_
12
13
#include <botan/rng.h>
14
15
#include <botan/internal/kyber_encaps_base.h>
16
#include <botan/internal/kyber_keys.h>
17
18
namespace Botan {
19
20
class Kyber_KEM_Encryptor final : public Kyber_KEM_Encryptor_Base {
21
   public:
22
      Kyber_KEM_Encryptor(std::shared_ptr<const Kyber_PublicKeyInternal> key, std::string_view kdf) :
23
0
            Kyber_KEM_Encryptor_Base(kdf, *key), m_public_key(std::move(key)) {}
24
25
   protected:
26
      void encapsulate(StrongSpan<KyberCompressedCiphertext> out_encapsulated_key,
27
                       StrongSpan<KyberSharedSecret> out_shared_key,
28
                       RandomNumberGenerator& rng) override;
29
30
0
      const KyberConstants& mode() const override { return m_public_key->mode(); }
31
32
   private:
33
      std::shared_ptr<const Kyber_PublicKeyInternal> m_public_key;
34
};
35
36
class Kyber_KEM_Decryptor final : public Kyber_KEM_Decryptor_Base {
37
   public:
38
      Kyber_KEM_Decryptor(std::shared_ptr<const Kyber_PrivateKeyInternal> private_key,
39
                          std::shared_ptr<const Kyber_PublicKeyInternal> public_key,
40
                          std::string_view kdf) :
41
0
            Kyber_KEM_Decryptor_Base(kdf, *public_key),
42
0
            m_public_key(std::move(public_key)),
43
0
            m_private_key(std::move(private_key)) {}
44
45
   protected:
46
      void decapsulate(StrongSpan<KyberSharedSecret> out_shared_key,
47
                       StrongSpan<const KyberCompressedCiphertext> encapsulated_key) override;
48
49
0
      const KyberConstants& mode() const override { return m_private_key->mode(); }
50
51
   private:
52
      std::shared_ptr<const Kyber_PublicKeyInternal> m_public_key;
53
      std::shared_ptr<const Kyber_PrivateKeyInternal> m_private_key;
54
};
55
56
class Kyber_Expanded_Keypair_Codec final : public Kyber_Keypair_Codec {
57
   public:
58
      KyberInternalKeypair decode_keypair(std::span<const uint8_t> buffer, KyberConstants mode) const override;
59
      secure_vector<uint8_t> encode_keypair(KyberInternalKeypair private_key) const override;
60
};
61
62
}  // namespace Botan
63
64
#endif