10#include <botan/internal/ffi_ec.h>
11#include <botan/internal/ffi_mp.h>
12#include <botan/internal/ffi_oid.h>
13#include <botan/internal/ffi_rng.h>
14#include <botan/internal/ffi_util.h>
39 if(name ==
nullptr || out ==
nullptr) {
60 if(ec_group ==
nullptr) {
67 auto group_ptr = std::make_unique<Botan::EC_Group>(std::move(group));
74 if(ec_group ==
nullptr || ber ==
nullptr) {
80 auto group_ptr = std::make_unique<Botan::EC_Group>(std::move(group));
87 if(ec_group ==
nullptr || pem ==
nullptr) {
93 auto group_ptr = std::make_unique<Botan::EC_Group>(std::move(group));
100 if(ec_group ==
nullptr) {
106 auto group_ptr = std::make_unique<Botan::EC_Group>(std::move(group));
113 if(ec_group ==
nullptr || name ==
nullptr) {
119 auto group_ptr = std::make_unique<Botan::EC_Group>(std::move(group));
144 auto oid_ptr = std::make_unique<Botan::OID>(g.get_curve_oid());
150int botan_ec_group_get_component(
botan_mp_t* out,
157 auto val = std::make_unique<Botan::BigInt>(getter(g));
164 return botan_ec_group_get_component(p, ec_group, [](
const auto& g) ->
const Botan::BigInt& {
return g.get_p(); });
168 return botan_ec_group_get_component(a, ec_group, [](
const auto& g) ->
const Botan::BigInt& {
return g.get_a(); });
172 return botan_ec_group_get_component(b, ec_group, [](
const auto& g) ->
const Botan::BigInt& {
return g.get_b(); });
176 return botan_ec_group_get_component(
177 g_x, ec_group, [](
const auto& g) ->
const Botan::BigInt& {
return g.get_g_x(); });
181 return botan_ec_group_get_component(
182 g_y, ec_group, [](
const auto& g) ->
const Botan::BigInt& {
return g.get_g_y(); });
186 return botan_ec_group_get_component(
187 order, ec_group, [](
const auto& g) ->
const Botan::BigInt& {
return g.get_order(); });
224 return ffi_new_object(mp, std::make_unique<Botan::BigInt>(sc.to_bigint()));
257 std::optional<Botan::EC_AffinePoint> pt =
259 if(!pt.has_value()) {
263 return ffi_new_object(ec_point, std::make_unique<Botan::EC_AffinePoint>(pt.value()));
269 const uint8_t* bytes,
276 return ffi_new_object(ec_point, std::make_unique<Botan::EC_AffinePoint>(std::move(pt)));
282 auto bytes = p.x_bytes();
289 auto bytes = p.y_bytes();
296 auto bytes = p.xy_bytes();
303 auto bytes = p.serialize_uncompressed();
310 auto bytes = p.serialize_compressed();
316 return BOTAN_FFI_VISIT(ec_point, [=](
const auto& p) ->
int {
return p.is_identity() ? 1 : 0; });
332 return ffi_new_object(result, std::make_unique<Botan::EC_AffinePoint>(std::move(res)));
342 return ffi_new_object(result, std::make_unique<Botan::EC_AffinePoint>(std::move(res)));
352 return ffi_new_object(result, std::make_unique<Botan::EC_AffinePoint>(std::move(res)));
EC_AffinePoint negate() const
Point negation.
static EC_AffinePoint identity(const EC_Group &group)
Return the identity element.
static std::optional< EC_AffinePoint > from_bigint_xy(const EC_Group &group, const BigInt &x, const BigInt &y)
EC_AffinePoint mul(const EC_Scalar &scalar, RandomNumberGenerator &rng) const
Multiply a point by a scalar returning a complete point.
EC_AffinePoint add(const EC_AffinePoint &q) const
static EC_AffinePoint generator(const EC_Group &group)
Return the standard group generator.
static EC_Group from_name(std::string_view name)
static EC_Group from_PEM(std::string_view pem)
static EC_Group from_OID(const OID &oid)
static bool supports_application_specific_group()
static bool unregister(const OID &oid)
static bool supports_named_group(std::string_view name)
static EC_Scalar from_bigint(const EC_Group &group, const BigInt &bn)
static EC_Scalar random(const EC_Group &group, RandomNumberGenerator &rng)
struct botan_asn1_oid_struct * botan_asn1_oid_t
struct botan_ec_group_struct * botan_ec_group_t
int(* botan_view_bin_fn)(botan_view_ctx view_ctx, const uint8_t *data, size_t len)
struct botan_mp_struct * botan_mp_t
struct botan_rng_struct * botan_rng_t
struct botan_ec_scalar_struct * botan_ec_scalar_t
@ BOTAN_FFI_ERROR_NULL_POINTER
@ BOTAN_FFI_ERROR_BAD_PARAMETER
struct botan_ec_point_struct * botan_ec_point_t
int(* botan_view_str_fn)(botan_view_ctx view_ctx, const char *str, size_t len)
int botan_ec_group_get_g_x(botan_mp_t *g_x, botan_ec_group_t ec_group)
int botan_ec_point_destroy(botan_ec_point_t ec_point)
int botan_ec_point_equal(botan_ec_point_t x_w, botan_ec_point_t y_w)
int botan_ec_group_view_pem(botan_ec_group_t ec_group, botan_view_ctx ctx, botan_view_str_fn view)
int botan_ec_group_get_curve_oid(botan_asn1_oid_t *oid, botan_ec_group_t ec_group)
int botan_ec_group_from_params(botan_ec_group_t *ec_group, botan_asn1_oid_t oid, botan_mp_t p, botan_mp_t a, botan_mp_t b, botan_mp_t base_x, botan_mp_t base_y, botan_mp_t order)
int botan_ec_group_get_g_y(botan_mp_t *g_y, botan_ec_group_t ec_group)
int botan_ec_point_mul(botan_ec_point_t *result, botan_ec_point_t ec_point, botan_ec_scalar_t ec_scalar, botan_rng_t rng)
int botan_ec_point_add(botan_ec_point_t *result, botan_ec_point_t x_w, botan_ec_point_t y_w)
int botan_ec_point_generator(botan_ec_point_t *ec_point, botan_ec_group_t ec_group)
int botan_ec_scalar_to_mp(botan_ec_scalar_t ec_scalar, botan_mp_t *mp)
int botan_ec_group_get_a(botan_mp_t *a, botan_ec_group_t ec_group)
int botan_ec_point_view_x_bytes(botan_ec_point_t ec_point, botan_view_ctx ctx, botan_view_bin_fn view)
int botan_ec_group_view_der(botan_ec_group_t ec_group, botan_view_ctx ctx, botan_view_bin_fn view)
int botan_ec_group_supports_named_group(const char *name, int *out)
int botan_ec_point_from_bytes(botan_ec_point_t *ec_point, botan_ec_group_t ec_group, const uint8_t *bytes, size_t bytes_len)
int botan_ec_group_equal(botan_ec_group_t curve1_w, botan_ec_group_t curve2_w)
int botan_ec_group_get_order(botan_mp_t *order, botan_ec_group_t ec_group)
int botan_ec_point_identity(botan_ec_point_t *ec_point, botan_ec_group_t ec_group)
int botan_ec_group_from_oid(botan_ec_group_t *ec_group, botan_asn1_oid_t oid)
int botan_ec_scalar_from_mp(botan_ec_scalar_t *ec_scalar, botan_ec_group_t ec_group, botan_mp_t mp)
int botan_ec_group_from_name(botan_ec_group_t *ec_group, const char *name)
int botan_ec_group_supports_application_specific_group(int *out)
int botan_ec_group_destroy(botan_ec_group_t ec_group)
int botan_ec_point_negate(botan_ec_point_t *result, botan_ec_point_t ec_point)
int botan_ec_point_view_xy_bytes(botan_ec_point_t ec_point, botan_view_ctx ctx, botan_view_bin_fn view)
int botan_ec_point_from_xy(botan_ec_point_t *ec_point, botan_ec_group_t ec_group, botan_mp_t x, botan_mp_t y)
int botan_ec_group_unregister(botan_asn1_oid_t oid)
int botan_ec_group_get_b(botan_mp_t *b, botan_ec_group_t ec_group)
int botan_ec_group_get_p(botan_mp_t *p, botan_ec_group_t ec_group)
int botan_ec_group_from_ber(botan_ec_group_t *ec_group, const uint8_t *ber, size_t ber_len)
int botan_ec_scalar_destroy(botan_ec_scalar_t ec_scalar)
int botan_ec_group_from_pem(botan_ec_group_t *ec_group, const char *pem)
int botan_ec_scalar_random(botan_ec_scalar_t *ec_scalar, botan_ec_group_t ec_group, botan_rng_t rng)
int botan_ec_point_view_uncompressed(botan_ec_point_t ec_point, botan_view_ctx ctx, botan_view_bin_fn view)
int botan_ec_point_view_y_bytes(botan_ec_point_t ec_point, botan_view_ctx ctx, botan_view_bin_fn view)
int botan_ec_point_is_identity(botan_ec_point_t ec_point)
int botan_ec_point_view_compressed(botan_ec_point_t ec_point, botan_view_ctx ctx, botan_view_bin_fn view)
#define BOTAN_FFI_VISIT(obj, lambda)
#define BOTAN_FFI_CHECKED_DELETE(o)
int invoke_view_callback(botan_view_bin_fn view, botan_view_ctx ctx, std::span< const uint8_t > buf)
T & safe_get(botan_struct< T, M > *p)
BOTAN_FFI_ERROR ffi_new_object(T *obj, Args &&... args)
int ffi_guard_thunk(const char *func_name, T thunk)
bool any_null_pointers(Ptrs... ptr)