7#include <botan/internal/ec_key_data.h>
9#include <botan/exceptn.h>
10#include <botan/mem_ops.h>
12#include <botan/internal/ct_utils.h>
28 return std::move(pt_uncompressed).value();
30 return std::move(pt_compressed).value();
32 throw Decoding_Error(
"Failed to deserialize elliptic curve point");
42 m_group(std::move(
group)), m_point(std::move(pt)) {
45 if(m_point.is_identity()) {
46 throw Decoding_Error(
"ECC public key cannot be point at infinity");
49 if(m_point._group() != m_group._data()) {
50 if(m_point.group() != m_group) {
51 throw Decoding_Error(
"ECC public key point is not an element of the specified group");
57 m_point = std::move(rebound).value();
59 throw Decoding_Error(
"ECC public key point is not an element of the specified group");
63#if defined(BOTAN_HAS_LEGACY_EC_POINT)
64 m_legacy_point = m_point.to_legacy_point();
69 m_group(std::move(
group)), m_scalar(std::move(x)), m_legacy_x(m_scalar.to_bigint()) {
70 if(m_scalar.group()._data() != m_group._data()) {
71 if(m_scalar.group() != m_group) {
72 throw Decoding_Error(
"ECC private key scalar is not an element of the specified group");
76 m_scalar = std::move(rebound).value();
78 throw Decoding_Error(
"ECC private key scalar is not an element of the specified group");
84 if(m_scalar.is_zero()) {
85 throw Decoding_Error(
"ECC private key cannot be zero");
91EC_Scalar decode_ec_secret_key_scalar(
const EC_Group& group, std::span<const uint8_t> bytes) {
92 const size_t order_bytes = group.get_order_bytes();
94 if(bytes.size() < order_bytes) {
105 copy_mem(std::span{padded_sk}.last(bytes.size()), bytes);
106 return decode_ec_secret_key_scalar(group, padded_sk);
126 bool with_modular_inverse)
const {
127 const auto public_point = [&] {
135 return std::make_shared<EC_PublicKey_Data>(m_group, public_point());
140 return this->
public_key(null_rng, with_modular_inverse);
144 m_scalar.serialize_to(output);
static std::optional< EC_AffinePoint > deserialize_uncompressed(const EC_Group &group, std::span< const uint8_t > bytes)
static EC_AffinePoint g_mul(const EC_Scalar &scalar, RandomNumberGenerator &rng)
Multiply by the group generator returning a complete point.
static std::optional< EC_AffinePoint > deserialize_compressed(const EC_Group &group, std::span< const uint8_t > bytes)
const EC_Group & group() const
void serialize_to(std::span< uint8_t > output) const
std::shared_ptr< EC_PublicKey_Data > public_key(RandomNumberGenerator &rng, bool with_modular_inverse) const
EC_PrivateKey_Data(EC_Group group, EC_Scalar x)
const EC_Group & group() const
EC_PublicKey_Data(EC_Group group, EC_AffinePoint pt)
static std::optional< EC_Scalar > deserialize(const EC_Group &group, std::span< const uint8_t > bytes)
constexpr auto scoped_poison(const Ts &... xs)
constexpr void unpoison(const T *p, size_t n)
constexpr void copy_mem(T *out, const T *in, size_t n)
std::vector< T, secure_allocator< T > > secure_vector