Coverage Report

Created: 2024-11-29 06:10

/src/botan/build/include/public/botan/frodokem.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * FrodoKEM implementation
3
 * Based on the MIT licensed reference implementation by the designers
4
 * (https://github.com/microsoft/PQCrypto-LWEKE/tree/master/src)
5
 *
6
 * The Fellowship of the FrodoKEM:
7
 * (C) 2023 Jack Lloyd
8
 *     2023 René Meusel, Amos Treiber - Rohde & Schwarz Cybersecurity
9
 *
10
 * Botan is released under the Simplified BSD License (see license.txt)
11
 */
12
13
#ifndef BOTAN_FRODOKEM_H_
14
#define BOTAN_FRODOKEM_H_
15
16
#include <botan/frodo_mode.h>
17
#include <botan/pk_keys.h>
18
19
#include <tuple>
20
#include <vector>
21
22
namespace Botan {
23
24
class FrodoKEM_PublicKeyInternal;
25
class FrodoKEM_PrivateKeyInternal;
26
27
/**
28
 * FrodoKEM is an unstructured lattice-based post-quantum secure KEM. It is a
29
 * round 3 candidate in NIST's PQC competition but was eventually not considered
30
 * for standardization by NIST. Nevertheless, it is endorsed by the German
31
 * Federal Office for Information Security for its conservative security
32
 * assumptions and is being standardized as an ISO standard.
33
 */
34
class BOTAN_PUBLIC_API(3, 3) FrodoKEM_PublicKey : public virtual Public_Key {
35
   public:
36
      FrodoKEM_PublicKey(std::span<const uint8_t> pub_key, FrodoKEMMode mode);
37
38
      FrodoKEM_PublicKey(const AlgorithmIdentifier& alg_id, std::span<const uint8_t> key_bits);
39
40
      FrodoKEM_PublicKey(const FrodoKEM_PublicKey& other);
41
      FrodoKEM_PublicKey& operator=(const FrodoKEM_PublicKey& other);
42
      FrodoKEM_PublicKey(FrodoKEM_PublicKey&&) = default;
43
      FrodoKEM_PublicKey& operator=(FrodoKEM_PublicKey&&) = default;
44
45
0
      ~FrodoKEM_PublicKey() override = default;
46
47
0
      std::string algo_name() const override { return "FrodoKEM"; }
48
49
      AlgorithmIdentifier algorithm_identifier() const override;
50
51
      OID object_identifier() const override;
52
53
      size_t key_length() const override;
54
55
      size_t estimated_strength() const override;
56
57
      std::vector<uint8_t> raw_public_key_bits() const override;
58
59
      std::vector<uint8_t> public_key_bits() const override;
60
61
      bool check_key(RandomNumberGenerator&, bool) const override;
62
63
0
      bool supports_operation(PublicKeyOperation op) const override {
64
0
         return (op == PublicKeyOperation::KeyEncapsulation);
65
0
      }
66
67
      std::unique_ptr<Private_Key> generate_another(RandomNumberGenerator& rng) const final;
68
69
      std::unique_ptr<PK_Ops::KEM_Encryption> create_kem_encryption_op(std::string_view params,
70
                                                                       std::string_view provider) const override;
71
72
   protected:
73
0
      FrodoKEM_PublicKey() = default;
74
75
   protected:
76
      std::shared_ptr<FrodoKEM_PublicKeyInternal> m_public;  // NOLINT(misc-non-private-member-variables-in-classes)
77
};
78
79
BOTAN_DIAGNOSTIC_PUSH
80
BOTAN_DIAGNOSTIC_IGNORE_INHERITED_VIA_DOMINANCE
81
82
class BOTAN_PUBLIC_API(3, 3) FrodoKEM_PrivateKey final : public virtual FrodoKEM_PublicKey,
83
                                                         public virtual Private_Key {
84
   public:
85
      FrodoKEM_PrivateKey(RandomNumberGenerator& rng, FrodoKEMMode mode);
86
87
      FrodoKEM_PrivateKey(std::span<const uint8_t> sk, FrodoKEMMode mode);
88
89
      FrodoKEM_PrivateKey(const AlgorithmIdentifier& alg_id, std::span<const uint8_t> key_bits);
90
91
      std::unique_ptr<Public_Key> public_key() const override;
92
93
      secure_vector<uint8_t> private_key_bits() const override;
94
95
      secure_vector<uint8_t> raw_private_key_bits() const override;
96
97
      std::unique_ptr<PK_Ops::KEM_Decryption> create_kem_decryption_op(RandomNumberGenerator& rng,
98
                                                                       std::string_view params,
99
                                                                       std::string_view provider) const override;
100
101
   private:
102
      std::shared_ptr<FrodoKEM_PrivateKeyInternal> m_private;
103
};
104
105
BOTAN_DIAGNOSTIC_POP
106
107
}  // namespace Botan
108
109
#endif