Botan 3.8.0
Crypto and TLS for C&
ec_key_data.h
Go to the documentation of this file.
1/*
2* (C) 2024 Jack Lloyd
3*
4* Botan is released under the Simplified BSD License (see license.txt)
5*/
6
7#ifndef BOTAN_EC_KEY_DATA_H_
8#define BOTAN_EC_KEY_DATA_H_
9
10#include <botan/ec_apoint.h>
11#include <botan/ec_group.h>
12#include <botan/ec_scalar.h>
13
14#include <botan/bigint.h>
15
16#if defined(BOTAN_HAS_LEGACY_EC_POINT)
17 #include <botan/ec_point.h>
18#endif
19
20namespace Botan {
21
23
24class EC_PublicKey_Data final {
25 public:
27
28 EC_PublicKey_Data(const EC_Group& group, std::span<const uint8_t> bytes) :
30
31 const EC_Group& group() const { return m_group; }
32
33 const EC_AffinePoint& public_key() const { return m_point; }
34
35#if defined(BOTAN_HAS_LEGACY_EC_POINT)
36 const EC_Point& legacy_point() const { return m_legacy_point; }
37#endif
38
39 private:
40 EC_Group m_group;
41 EC_AffinePoint m_point;
42#if defined(BOTAN_HAS_LEGACY_EC_POINT)
43 EC_Point m_legacy_point;
44#endif
45};
46
47class EC_PrivateKey_Data final {
48 public:
50
51 EC_PrivateKey_Data(const EC_Group& group, std::span<const uint8_t> bytes);
52
53 std::shared_ptr<EC_PublicKey_Data> public_key(RandomNumberGenerator& rng, bool with_modular_inverse) const;
54
55 std::shared_ptr<EC_PublicKey_Data> public_key(bool with_modular_inverse) const;
56
57 void serialize_to(std::span<uint8_t> output) const;
58
59 template <typename T>
60 T serialize() const {
61 T bytes(this->group().get_order_bytes());
62 this->serialize_to(bytes);
63 return bytes;
64 }
65
66 const EC_Group& group() const { return m_group; }
67
68 const EC_Scalar& private_key() const { return m_scalar; }
69
70 const BigInt& legacy_bigint() const { return m_legacy_x; }
71
72 private:
73 EC_Group m_group;
74
75 EC_Scalar m_scalar;
76 BigInt m_legacy_x;
77};
78
79} // namespace Botan
80
81#endif
const EC_Scalar & private_key() const
Definition ec_key_data.h:68
const EC_Group & group() const
Definition ec_key_data.h:66
void serialize_to(std::span< uint8_t > output) const
std::shared_ptr< EC_PublicKey_Data > public_key(RandomNumberGenerator &rng, bool with_modular_inverse) const
const BigInt & legacy_bigint() const
Definition ec_key_data.h:70
EC_PrivateKey_Data(EC_Group group, EC_Scalar x)
EC_PublicKey_Data(const EC_Group &group, std::span< const uint8_t > bytes)
Definition ec_key_data.h:28
const EC_AffinePoint & public_key() const
Definition ec_key_data.h:33
const EC_Group & group() const
Definition ec_key_data.h:31
EC_PublicKey_Data(EC_Group group, EC_AffinePoint pt)