• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

randombit / botan / 5454043422

04 Jul 2023 11:13AM CUT coverage: 91.659% (-0.07%) from 91.732%
5454043422

Pull #3609

github

web-flow
Merge 5741e183c into cf8d8a6ca
Pull Request #3609: [TLS 1.3] Hybrid PQ/T key establishment

78635 of 85791 relevant lines covered (91.66%)

12300857.61 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

22.22
/src/lib/pubkey/pk_ops_impl.h
1

2
/*
3
* (C) 2015 Jack Lloyd
4
*
5
* Botan is released under the Simplified BSD License (see license.txt)
6
*/
7

8
#ifndef BOTAN_PK_OPERATION_IMPL_H_
9
#define BOTAN_PK_OPERATION_IMPL_H_
10

11
#include <botan/hash.h>
12
#include <botan/kdf.h>
13
#include <botan/internal/eme.h>
14
#include <botan/internal/pk_ops.h>
15

16
namespace Botan {
17

18
namespace PK_Ops {
19

20
class Encryption_with_EME : public Encryption {
21
   public:
22
      size_t max_input_bits() const override;
23

24
      secure_vector<uint8_t> encrypt(const uint8_t msg[], size_t msg_len, RandomNumberGenerator& rng) override;
25

26
      ~Encryption_with_EME() = default;
×
27

28
   protected:
29
      explicit Encryption_with_EME(std::string_view eme);
30

31
   private:
32
      virtual size_t max_ptext_input_bits() const = 0;
33

34
      virtual secure_vector<uint8_t> raw_encrypt(const uint8_t msg[], size_t len, RandomNumberGenerator& rng) = 0;
35
      std::unique_ptr<EME> m_eme;
36
};
37

38
class Decryption_with_EME : public Decryption {
39
   public:
40
      secure_vector<uint8_t> decrypt(uint8_t& valid_mask, const uint8_t msg[], size_t msg_len) override;
41

42
      ~Decryption_with_EME() = default;
×
43

44
   protected:
45
      explicit Decryption_with_EME(std::string_view eme);
46

47
   private:
48
      virtual secure_vector<uint8_t> raw_decrypt(const uint8_t msg[], size_t len) = 0;
49
      std::unique_ptr<EME> m_eme;
50
};
51

52
class Verification_with_Hash : public Verification {
53
   public:
54
      ~Verification_with_Hash() = default;
×
55

56
      void update(const uint8_t msg[], size_t msg_len) override;
57
      bool is_valid_signature(const uint8_t sig[], size_t sig_len) override;
58

59
      std::string hash_function() const override final { return m_hash->name(); }
1,792✔
60

61
   protected:
62
      explicit Verification_with_Hash(std::string_view hash);
63

64
      explicit Verification_with_Hash(const AlgorithmIdentifier& alg_id,
65
                                      std::string_view pk_algo,
66
                                      bool allow_null_parameters = false);
67

68
      /*
69
      * Perform a signature check operation
70
      * @param msg the message
71
      * @param msg_len the length of msg in bytes
72
      * @param sig the signature
73
      * @param sig_len the length of sig in bytes
74
      * @returns if signature is a valid one for message
75
      */
76
      virtual bool verify(const uint8_t msg[], size_t msg_len, const uint8_t sig[], size_t sig_len) = 0;
77

78
   private:
79
      std::unique_ptr<HashFunction> m_hash;
80
};
81

82
class Signature_with_Hash : public Signature {
83
   public:
84
      void update(const uint8_t msg[], size_t msg_len) override;
85

86
      secure_vector<uint8_t> sign(RandomNumberGenerator& rng) override;
87

88
   protected:
89
      explicit Signature_with_Hash(std::string_view hash);
90

91
      ~Signature_with_Hash() = default;
×
92

93
      std::string hash_function() const override final { return m_hash->name(); }
435✔
94

95
#if defined(BOTAN_HAS_RFC6979_GENERATOR)
96
      std::string rfc6979_hash_function() const;
97
#endif
98

99
   private:
100
      virtual secure_vector<uint8_t> raw_sign(const uint8_t msg[], size_t msg_len, RandomNumberGenerator& rng) = 0;
101

102
      std::unique_ptr<HashFunction> m_hash;
103
};
104

105
class Key_Agreement_with_KDF : public Key_Agreement {
106
   public:
107
      secure_vector<uint8_t> agree(size_t key_len,
108
                                   const uint8_t other_key[],
109
                                   size_t other_key_len,
110
                                   const uint8_t salt[],
111
                                   size_t salt_len) override;
112

113
   protected:
114
      explicit Key_Agreement_with_KDF(std::string_view kdf);
115
      ~Key_Agreement_with_KDF() = default;
×
116

117
   private:
118
      virtual secure_vector<uint8_t> raw_agree(const uint8_t w[], size_t w_len) = 0;
119
      std::unique_ptr<KDF> m_kdf;
120
};
121

122
class KEM_Encryption_with_KDF : public KEM_Encryption {
123
   public:
124
      void kem_encrypt(std::span<uint8_t> out_encapsulated_key,
125
                       std::span<uint8_t> out_shared_key,
126
                       RandomNumberGenerator& rng,
127
                       size_t desired_shared_key_len,
128
                       std::span<const uint8_t> salt) override final;
129

130
      size_t shared_key_length(size_t desired_shared_key_len) const override final;
131

132
   protected:
133
      virtual void raw_kem_encrypt(std::span<uint8_t> out_encapsulated_key,
134
                                   std::span<uint8_t> out_raw_shared_key,
135
                                   RandomNumberGenerator& rng) = 0;
136

137
      virtual size_t raw_kem_shared_key_length() const = 0;
138

139
      explicit KEM_Encryption_with_KDF(std::string_view kdf);
140
      ~KEM_Encryption_with_KDF() = default;
×
141

142
   private:
143
      std::unique_ptr<KDF> m_kdf;
144
};
145

146
class KEM_Decryption_with_KDF : public KEM_Decryption {
147
   public:
148
      void kem_decrypt(std::span<uint8_t> out_shared_key,
149
                       std::span<const uint8_t> encapsulated_key,
150
                       size_t desired_shared_key_len,
151
                       std::span<const uint8_t> salt) override final;
152

153
      size_t shared_key_length(size_t desired_shared_key_len) const override final;
154

155
   protected:
156
      virtual void raw_kem_decrypt(std::span<uint8_t> out_raw_shared_key,
157
                                   std::span<const uint8_t> encapsulated_key) = 0;
158

159
      virtual size_t raw_kem_shared_key_length() const = 0;
160

161
      explicit KEM_Decryption_with_KDF(std::string_view kdf);
162
      ~KEM_Decryption_with_KDF() = default;
×
163

164
   private:
165
      std::unique_ptr<KDF> m_kdf;
166
};
167

168
}  // namespace PK_Ops
169

170
}  // namespace Botan
171

172
#endif
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc