Botan
3.6.1
Crypto and TLS for C&
src
lib
pubkey
ecc_key
ec_key_data.cpp
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
#include <botan/internal/ec_key_data.h>
8
9
#include <botan/rng.h>
10
11
namespace
Botan
{
12
13
EC_PublicKey_Data::EC_PublicKey_Data
(
EC_Group
group, std::span<const uint8_t> bytes) :
14
m_group(std::move(group)), m_point(m_group, bytes), m_legacy_point(m_point.to_legacy_point()) {}
15
16
EC_PrivateKey_Data::EC_PrivateKey_Data
(
EC_Group
group,
RandomNumberGenerator
& rng) :
17
m_group(std::move(group)), m_scalar(
EC_Scalar
::random(m_group, rng)), m_legacy_x(m_scalar.to_bigint()) {}
18
19
EC_PrivateKey_Data::EC_PrivateKey_Data
(
EC_Group
group,
const
BigInt
& x) :
20
m_group(std::move(group)), m_scalar(
EC_Scalar
::from_bigint(m_group, x)), m_legacy_x(m_scalar.to_bigint()) {}
21
22
EC_PrivateKey_Data::EC_PrivateKey_Data
(
EC_Group
group,
EC_Scalar
x) :
23
m_group(std::move(group)), m_scalar(std::move(x)), m_legacy_x(m_scalar.to_bigint()) {}
24
25
EC_PrivateKey_Data::EC_PrivateKey_Data
(
EC_Group
group, std::span<const uint8_t> bytes) :
26
m_group(std::move(group)), m_scalar(m_group, bytes), m_legacy_x(m_scalar.to_bigint()) {}
27
28
std::shared_ptr<EC_PublicKey_Data>
EC_PrivateKey_Data::public_key
(
RandomNumberGenerator
& rng,
29
bool
with_modular_inverse)
const
{
30
auto
public_point = [&] {
31
std::vector<BigInt> ws;
32
if
(with_modular_inverse) {
33
return
EC_AffinePoint::g_mul
(m_scalar.
invert
(), rng, ws);
34
}
else
{
35
return
EC_AffinePoint::g_mul
(m_scalar, rng, ws);
36
}
37
};
38
39
return
std::make_shared<EC_PublicKey_Data>(m_group, public_point());
40
}
41
42
std::shared_ptr<EC_PublicKey_Data>
EC_PrivateKey_Data::public_key
(
bool
with_modular_inverse)
const
{
43
Null_RNG
null_rng;
44
return
this->
public_key
(null_rng, with_modular_inverse);
45
}
46
47
void
EC_PrivateKey_Data::serialize_to
(std::span<uint8_t> output)
const
{
48
m_scalar.
serialize_to
(output);
49
}
50
51
}
// namespace Botan
Botan::BigInt
Definition
bigint.h:26
Botan::EC_AffinePoint::g_mul
static EC_AffinePoint g_mul(const EC_Scalar &scalar, RandomNumberGenerator &rng, std::vector< BigInt > &ws)
Definition
ec_apoint.cpp:105
Botan::EC_Group
Definition
ec_group.h:51
Botan::EC_PrivateKey_Data::serialize_to
void serialize_to(std::span< uint8_t > output) const
Definition
ec_key_data.cpp:47
Botan::EC_PrivateKey_Data::EC_PrivateKey_Data
EC_PrivateKey_Data(EC_Group group, RandomNumberGenerator &rng)
Definition
ec_key_data.cpp:16
Botan::EC_PrivateKey_Data::public_key
std::shared_ptr< EC_PublicKey_Data > public_key(RandomNumberGenerator &rng, bool with_modular_inverse) const
Definition
ec_key_data.cpp:28
Botan::EC_PublicKey_Data::EC_PublicKey_Data
EC_PublicKey_Data(EC_Group group, EC_AffinePoint pt)
Definition
ec_key_data.h:23
Botan::EC_Scalar
Definition
ec_scalar.h:28
Botan::EC_Scalar::serialize_to
void serialize_to(std::span< uint8_t > bytes) const
Definition
ec_scalar.cpp:84
Botan::EC_Scalar::invert
EC_Scalar invert() const
Definition
ec_scalar.cpp:133
Botan::Null_RNG
Definition
rng.h:284
Botan::RandomNumberGenerator
Definition
rng.h:31
Botan
Definition
alg_id.cpp:13
Generated by
1.12.0