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

randombit / botan / 13579810322

28 Feb 2025 02:06AM UTC coverage: 91.693% (-0.005%) from 91.698%
13579810322

Pull #4724

github

web-flow
Merge 068727df0 into 0e7c06384
Pull Request #4724: Cleanups and deprecations for key agreement

95849 of 104533 relevant lines covered (91.69%)

11440327.08 hits per line

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

90.0
/src/lib/pubkey/x25519/x25519.h
1
/*
2
* (C) 2014,2024 Jack Lloyd
3
*
4
* Botan is released under the Simplified BSD License (see license.txt)
5
*/
6

7
#ifndef BOTAN_X25519_H_
8
#define BOTAN_X25519_H_
9

10
#include <botan/pk_keys.h>
11

12
namespace Botan {
13

14
class BOTAN_PUBLIC_API(2, 0) X25519_PublicKey : public virtual Public_Key {
15
   public:
16
      std::string algo_name() const override { return "X25519"; }
3,493✔
17

18
      size_t estimated_strength() const override { return 128; }
44✔
19

20
      size_t key_length() const override { return 255; }
1,999✔
21

22
      bool check_key(RandomNumberGenerator& rng, bool strong) const override;
23

24
      AlgorithmIdentifier algorithm_identifier() const override;
25

26
      std::vector<uint8_t> raw_public_key_bits() const override;
27

28
      std::vector<uint8_t> public_key_bits() const override;
29

30
      BOTAN_DEPRECATED("Use raw_public_key_bits") std::vector<uint8_t> public_value() const {
22✔
31
         return raw_public_key_bits();
22✔
32
      }
33

34
      bool supports_operation(PublicKeyOperation op) const override { return (op == PublicKeyOperation::KeyAgreement); }
403✔
35

36
      std::unique_ptr<Private_Key> generate_another(RandomNumberGenerator& rng) const final;
37

38
      /**
39
      * Create a X25519 Public Key.
40
      * @param alg_id the X.509 algorithm identifier
41
      * @param key_bits DER encoded public key bits
42
      */
43
      X25519_PublicKey(const AlgorithmIdentifier& alg_id, std::span<const uint8_t> key_bits);
44

45
      /**
46
      * Create a X25519 Public Key.
47
      * @param pub 32-byte raw public key
48
      */
49
      explicit X25519_PublicKey(std::span<const uint8_t> pub);
50

51
   protected:
52
      X25519_PublicKey() = default;
2,742✔
53
      std::vector<uint8_t> m_public;
54
};
55

56
BOTAN_DIAGNOSTIC_PUSH
57
BOTAN_DIAGNOSTIC_IGNORE_INHERITED_VIA_DOMINANCE
58

59
class BOTAN_PUBLIC_API(2, 0) X25519_PrivateKey final : public X25519_PublicKey,
×
60
                                                       public virtual Private_Key,
61
                                                       public virtual PK_Key_Agreement_Key {
62
   public:
63
      /**
64
      * Construct a private key from the specified parameters.
65
      * @param alg_id the X.509 algorithm identifier
66
      * @param key_bits PKCS #8 structure
67
      */
68
      X25519_PrivateKey(const AlgorithmIdentifier& alg_id, std::span<const uint8_t> key_bits);
69

70
      /**
71
      * Generate a private key.
72
      * @param rng the RNG to use
73
      */
74
      explicit X25519_PrivateKey(RandomNumberGenerator& rng);
75

76
      /**
77
      * Construct a private key from the specified parameters.
78
      * @param secret_key the private key
79
      */
80
      explicit X25519_PrivateKey(std::span<const uint8_t> secret_key);
81

82
      std::vector<uint8_t> public_value() const override { return raw_public_key_bits(); }
2,633✔
83

84
      secure_vector<uint8_t> agree(const uint8_t w[], size_t w_len) const;
85

86
      secure_vector<uint8_t> raw_private_key_bits() const override { return m_private; }
1✔
87

88
      BOTAN_DEPRECATED("Use raw_private_key_bits") const secure_vector<uint8_t>& get_x() const { return m_private; }
89

90
      secure_vector<uint8_t> private_key_bits() const override;
91

92
      std::unique_ptr<Public_Key> public_key() const override;
93

94
      bool check_key(RandomNumberGenerator& rng, bool strong) const override;
95

96
      std::unique_ptr<PK_Ops::Key_Agreement> create_key_agreement_op(RandomNumberGenerator& rng,
97
                                                                     std::string_view params,
98
                                                                     std::string_view provider) const override;
99

100
   private:
101
      secure_vector<uint8_t> m_private;
102
};
103

104
BOTAN_DIAGNOSTIC_POP
105

106
/*
107
* The types above are just wrappers for curve25519_donna, plus defining
108
* encodings for public and private keys.
109
*/
110
BOTAN_DEPRECATED_API("Use X25519_PrivateKey or Sodium::crypto_scalarmult_curve25519")
111
void curve25519_donna(uint8_t mypublic[32], const uint8_t secret[32], const uint8_t basepoint[32]);
112

113
/**
114
* Exponentiate by the x25519 base point
115
* @param mypublic output value
116
* @param secret random scalar
117
*/
118
BOTAN_DEPRECATED_API("Use X25519_PrivateKey or Sodium::crypto_scalarmult_curve25519_base")
119
void curve25519_basepoint(uint8_t mypublic[32], const uint8_t secret[32]);
120

121
}  // namespace Botan
122

123
#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