Botan 3.12.0
Crypto and TLS for C&
ffi_ec.cpp File Reference
#include <botan/ffi.h>
#include <botan/internal/ffi_ec.h>
#include <botan/internal/ffi_mp.h>
#include <botan/internal/ffi_oid.h>
#include <botan/internal/ffi_rng.h>
#include <botan/internal/ffi_util.h>
#include <functional>

Go to the source code of this file.

Functions

int botan_ec_group_destroy (botan_ec_group_t ec_group)
int botan_ec_group_equal (botan_ec_group_t curve1_w, botan_ec_group_t curve2_w)
int botan_ec_group_from_ber (botan_ec_group_t *ec_group, const uint8_t *ber, size_t ber_len)
int botan_ec_group_from_name (botan_ec_group_t *ec_group, const char *name)
int botan_ec_group_from_oid (botan_ec_group_t *ec_group, botan_asn1_oid_t oid)
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_from_pem (botan_ec_group_t *ec_group, const char *pem)
int botan_ec_group_get_a (botan_mp_t *a, botan_ec_group_t ec_group)
int botan_ec_group_get_b (botan_mp_t *b, botan_ec_group_t ec_group)
int botan_ec_group_get_curve_oid (botan_asn1_oid_t *oid, botan_ec_group_t ec_group)
int botan_ec_group_get_g_x (botan_mp_t *g_x, botan_ec_group_t ec_group)
int botan_ec_group_get_g_y (botan_mp_t *g_y, botan_ec_group_t ec_group)
int botan_ec_group_get_order (botan_mp_t *order, 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_supports_application_specific_group (int *out)
int botan_ec_group_supports_named_group (const char *name, int *out)
int botan_ec_group_unregister (botan_asn1_oid_t oid)
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_view_pem (botan_ec_group_t ec_group, botan_view_ctx ctx, botan_view_str_fn view)
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_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_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_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_point_generator (botan_ec_point_t *ec_point, 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_point_is_identity (botan_ec_point_t ec_point)
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_negate (botan_ec_point_t *result, 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)
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_x_bytes (botan_ec_point_t ec_point, botan_view_ctx ctx, botan_view_bin_fn view)
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_view_y_bytes (botan_ec_point_t ec_point, botan_view_ctx ctx, botan_view_bin_fn view)
int botan_ec_scalar_destroy (botan_ec_scalar_t ec_scalar)
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_scalar_random (botan_ec_scalar_t *ec_scalar, botan_ec_group_t ec_group, botan_rng_t rng)
int botan_ec_scalar_to_mp (botan_ec_scalar_t ec_scalar, botan_mp_t *mp)

Function Documentation

◆ botan_ec_group_destroy()

int botan_ec_group_destroy ( botan_ec_group_t ec_group)
Returns
negative number on error, or zero on success

Definition at line 21 of file ffi_ec.cpp.

21 {
22 return BOTAN_FFI_CHECKED_DELETE(ec_group);
23}
#define BOTAN_FFI_CHECKED_DELETE(o)
Definition ffi_util.h:188

References BOTAN_FFI_CHECKED_DELETE.

◆ botan_ec_group_equal()

int botan_ec_group_equal ( botan_ec_group_t curve1,
botan_ec_group_t curve2 )
Returns
0 if curve1 != curve2
1 if curve1 == curve2
negative number on error

Definition at line 190 of file ffi_ec.cpp.

190 {
191 return BOTAN_FFI_VISIT(curve1_w, [=](const auto& curve1) -> int { return curve1 == safe_get(curve2_w); });
192}
#define BOTAN_FFI_VISIT(obj, lambda)
Definition ffi_util.h:158
T & safe_get(botan_struct< T, M > *p)
Definition ffi_util.h:79

References BOTAN_FFI_VISIT, and Botan_FFI::safe_get().

◆ botan_ec_group_from_ber()

int botan_ec_group_from_ber ( botan_ec_group_t * ec_group,
const uint8_t * ber,
size_t ber_len )

Decode a BER encoded ECC domain parameter set

Parameters
ec_groupthe new object will be placed here
berencoding
ber_lensize of the encoding in bytes
Returns
negative number on error, or zero on success

Definition at line 72 of file ffi_ec.cpp.

72 {
73 return ffi_guard_thunk(__func__, [=]() -> int {
74 if(ec_group == nullptr || ber == nullptr) {
76 }
77
78 Botan::EC_Group group(ber, ber_len);
79
80 auto group_ptr = std::make_unique<Botan::EC_Group>(std::move(group));
81 return ffi_new_object(ec_group, std::move(group_ptr));
82 });
83}
@ BOTAN_FFI_ERROR_NULL_POINTER
Definition ffi.h:133
BOTAN_FFI_ERROR ffi_new_object(T *obj, Args &&... args)
Definition ffi_util.h:178
int ffi_guard_thunk(const char *func_name, T thunk)
Definition ffi_util.h:95

References BOTAN_FFI_ERROR_NULL_POINTER, Botan_FFI::ffi_guard_thunk(), and Botan_FFI::ffi_new_object().

◆ botan_ec_group_from_name()

int botan_ec_group_from_name ( botan_ec_group_t * ec_group,
const char * name )

Initialize an EC Group from a common group name (eg "secp256r1")

Parameters
ec_groupthe new object will be placed here
namea known group name
Returns
negative number on error, or zero on success

Definition at line 111 of file ffi_ec.cpp.

111 {
112 return ffi_guard_thunk(__func__, [=]() -> int {
113 if(ec_group == nullptr || name == nullptr) {
115 }
116
118
119 auto group_ptr = std::make_unique<Botan::EC_Group>(std::move(group));
120 return ffi_new_object(ec_group, std::move(group_ptr));
121 });
122}
static EC_Group from_name(std::string_view name)
Definition ec_group.cpp:468

References BOTAN_FFI_ERROR_NULL_POINTER, Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), and Botan::EC_Group::from_name().

◆ botan_ec_group_from_oid()

int botan_ec_group_from_oid ( botan_ec_group_t * ec_group,
botan_asn1_oid_t oid )

Initialize an EC Group from a group named by an object identifier

Parameters
ec_groupthe new object will be placed here
oida known OID
Returns
negative number on error, or zero on success

Definition at line 98 of file ffi_ec.cpp.

98 {
99 return ffi_guard_thunk(__func__, [=]() -> int {
100 if(ec_group == nullptr) {
102 }
103
105
106 auto group_ptr = std::make_unique<Botan::EC_Group>(std::move(group));
107 return ffi_new_object(ec_group, std::move(group_ptr));
108 });
109}
static EC_Group from_OID(const OID &oid)
Definition ec_group.cpp:457

References BOTAN_FFI_ERROR_NULL_POINTER, Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), Botan::EC_Group::from_OID(), and Botan_FFI::safe_get().

◆ botan_ec_group_from_params()

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 )

Create a new EC Group from parameters

Warning
use only elliptic curve parameters that you trust
Parameters
ec_groupthe new object will be placed here
pthe elliptic curve prime (at most 521 bits)
athe elliptic curve a param
bthe elliptic curve b param
base_xthe x coordinate of the group generator
base_ythe y coordinate of the group generator
orderthe order of the group
Returns
negative number on error, or zero on success

Definition at line 51 of file ffi_ec.cpp.

58 {
59 return ffi_guard_thunk(__func__, [=]() -> int {
60 if(ec_group == nullptr) {
62 }
63
64 Botan::EC_Group group(
65 safe_get(oid), safe_get(p), safe_get(a), safe_get(b), safe_get(base_x), safe_get(base_y), safe_get(order));
66
67 auto group_ptr = std::make_unique<Botan::EC_Group>(std::move(group));
68 return ffi_new_object(ec_group, std::move(group_ptr));
69 });
70}

References BOTAN_FFI_ERROR_NULL_POINTER, Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), and Botan_FFI::safe_get().

◆ botan_ec_group_from_pem()

int botan_ec_group_from_pem ( botan_ec_group_t * ec_group,
const char * pem )

Initialize an EC Group from the PEM/ASN.1 encoding

Parameters
ec_groupthe new object will be placed here
pemencoding
Returns
negative number on error, or zero on success

Definition at line 85 of file ffi_ec.cpp.

85 {
86 return ffi_guard_thunk(__func__, [=]() -> int {
87 if(ec_group == nullptr || pem == nullptr) {
89 }
90
92
93 auto group_ptr = std::make_unique<Botan::EC_Group>(std::move(group));
94 return ffi_new_object(ec_group, std::move(group_ptr));
95 });
96}
static EC_Group from_PEM(std::string_view pem)
Definition ec_group.cpp:511

References BOTAN_FFI_ERROR_NULL_POINTER, Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), and Botan::EC_Group::from_PEM().

◆ botan_ec_group_get_a()

int botan_ec_group_get_a ( botan_mp_t * a,
botan_ec_group_t ec_group )

Get the a parameter of the elliptic curve equation

Definition at line 167 of file ffi_ec.cpp.

167 {
168 return botan_ec_group_get_component(a, ec_group, [](const auto& g) -> const Botan::BigInt& { return g.get_a(); });
169}

◆ botan_ec_group_get_b()

int botan_ec_group_get_b ( botan_mp_t * b,
botan_ec_group_t ec_group )

Get the b parameter of the elliptic curve equation

Definition at line 171 of file ffi_ec.cpp.

171 {
172 return botan_ec_group_get_component(b, ec_group, [](const auto& g) -> const Botan::BigInt& { return g.get_b(); });
173}

◆ botan_ec_group_get_curve_oid()

int botan_ec_group_get_curve_oid ( botan_asn1_oid_t * oid,
botan_ec_group_t ec_group )

Get the curve OID of an EC Group

Definition at line 139 of file ffi_ec.cpp.

139 {
140 return BOTAN_FFI_VISIT(ec_group, [=](const auto& g) -> int {
141 if(oid == nullptr) {
143 }
144 auto oid_ptr = std::make_unique<Botan::OID>(g.get_curve_oid());
145 return ffi_new_object(oid, std::move(oid_ptr));
146 });
147}

References BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_VISIT, and Botan_FFI::ffi_new_object().

◆ botan_ec_group_get_g_x()

int botan_ec_group_get_g_x ( botan_mp_t * g_x,
botan_ec_group_t ec_group )

Get the x coordinate of the base point

Definition at line 175 of file ffi_ec.cpp.

175 {
176 return botan_ec_group_get_component(
177 g_x, ec_group, [](const auto& g) -> const Botan::BigInt& { return g.get_g_x(); });
178}

◆ botan_ec_group_get_g_y()

int botan_ec_group_get_g_y ( botan_mp_t * g_y,
botan_ec_group_t ec_group )

Get the y coordinate of the base point

Definition at line 180 of file ffi_ec.cpp.

180 {
181 return botan_ec_group_get_component(
182 g_y, ec_group, [](const auto& g) -> const Botan::BigInt& { return g.get_g_y(); });
183}

◆ botan_ec_group_get_order()

int botan_ec_group_get_order ( botan_mp_t * order,
botan_ec_group_t ec_group )

Get the order of the base point

Definition at line 185 of file ffi_ec.cpp.

185 {
186 return botan_ec_group_get_component(
187 order, ec_group, [](const auto& g) -> const Botan::BigInt& { return g.get_order(); });
188}

◆ botan_ec_group_get_p()

int botan_ec_group_get_p ( botan_mp_t * p,
botan_ec_group_t ec_group )

Get the prime modulus of the field

Definition at line 163 of file ffi_ec.cpp.

163 {
164 return botan_ec_group_get_component(p, ec_group, [](const auto& g) -> const Botan::BigInt& { return g.get_p(); });
165}

◆ botan_ec_group_supports_application_specific_group()

int botan_ec_group_supports_application_specific_group ( int * out)

Checks if in this build configuration it is possible to register an application specific elliptic curve and sets

Parameters
outto 1 if so, 0 otherwise
Returns
0 on success, a negative value on failure

Definition at line 25 of file ffi_ec.cpp.

25 {
26 if(out == nullptr) {
28 }
30 *out = 1;
31 } else {
32 *out = 0;
33 }
34 return BOTAN_FFI_SUCCESS;
35}
static bool supports_application_specific_group()
Definition ec_group.cpp:439
@ BOTAN_FFI_SUCCESS
Definition ffi.h:116

References BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, and Botan::EC_Group::supports_application_specific_group().

◆ botan_ec_group_supports_named_group()

int botan_ec_group_supports_named_group ( const char * name,
int * out )

Checks if in this build configuration botan_ec_group_from_name(group_ptr, name) will succeed and sets

Parameters
outto 1 if so, 0 otherwise.
Returns
negative number on error, or zero on success

Definition at line 37 of file ffi_ec.cpp.

37 {
38 return ffi_guard_thunk(__func__, [=]() -> int {
39 if(name == nullptr || out == nullptr) {
41 }
43 *out = 1;
44 } else {
45 *out = 0;
46 }
47 return BOTAN_FFI_SUCCESS;
48 });
49}
static bool supports_named_group(std::string_view name)
Definition ec_group.cpp:412

References BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, Botan_FFI::ffi_guard_thunk(), and Botan::EC_Group::supports_named_group().

◆ botan_ec_group_unregister()

int botan_ec_group_unregister ( botan_asn1_oid_t oid)

Unregister a previously registered group.

Parameters
oidthe oid associated with the group to unregister
Returns
1 if the group was found and unregistered, else 0

Using this is discouraged for normal use. This is only useful or necessary if you are registering a very large number of distinct groups, and need to worry about memory constraints.

Definition at line 124 of file ffi_ec.cpp.

124 {
125 return BOTAN_FFI_VISIT(oid, [=](const auto& o) -> int { return Botan::EC_Group::unregister(o) ? 1 : 0; });
126}
static bool unregister(const OID &oid)
Definition ec_group.cpp:612

References BOTAN_FFI_VISIT, and Botan::EC_Group::unregister().

◆ botan_ec_group_view_der()

int botan_ec_group_view_der ( botan_ec_group_t ec_group,
botan_view_ctx ctx,
botan_view_bin_fn view )

View an EC Group in DER encoding

Definition at line 128 of file ffi_ec.cpp.

128 {
129 return BOTAN_FFI_VISIT(ec_group,
130 [=](const auto& g) -> int { return invoke_view_callback(view, ctx, g.DER_encode()); });
131}
int invoke_view_callback(botan_view_bin_fn view, botan_view_ctx ctx, std::span< const uint8_t > buf)
Definition ffi_util.h:190

References BOTAN_FFI_VISIT, and Botan_FFI::invoke_view_callback().

◆ botan_ec_group_view_pem()

int botan_ec_group_view_pem ( botan_ec_group_t ec_group,
botan_view_ctx ctx,
botan_view_str_fn view )

View an EC Group in PEM encoding

Definition at line 133 of file ffi_ec.cpp.

133 {
134 return BOTAN_FFI_VISIT(ec_group, [=](const auto& g) -> int {
135 return invoke_view_callback(view, ctx, g.PEM_encode(Botan::EC_Group_Encoding::NamedCurve));
136 });
137}

References BOTAN_FFI_VISIT, Botan_FFI::invoke_view_callback(), and Botan::NamedCurve.

◆ botan_ec_point_add()

int botan_ec_point_add ( botan_ec_point_t * result,
botan_ec_point_t x_w,
botan_ec_point_t y_w )

Definition at line 346 of file ffi_ec.cpp.

346 {
347 if(Botan::any_null_pointers(result)) {
349 }
350 return BOTAN_FFI_VISIT(x_w, [=](auto& x) -> int {
351 Botan::EC_AffinePoint res = x.add(safe_get(y_w));
352 return ffi_new_object(result, std::make_unique<Botan::EC_AffinePoint>(std::move(res)));
353 });
354}
EC_AffinePoint add(const EC_AffinePoint &q) const
bool any_null_pointers(Ptrs... ptr)
Definition mem_utils.h:54

References Botan::EC_AffinePoint::add(), Botan::any_null_pointers(), BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_VISIT, Botan_FFI::ffi_new_object(), and Botan_FFI::safe_get().

◆ botan_ec_point_destroy()

int botan_ec_point_destroy ( botan_ec_point_t ec_point)

Definition at line 230 of file ffi_ec.cpp.

230 {
231 return BOTAN_FFI_CHECKED_DELETE(ec_point);
232}

References BOTAN_FFI_CHECKED_DELETE.

◆ botan_ec_point_equal()

int botan_ec_point_equal ( botan_ec_point_t x,
botan_ec_point_t y )
Returns
1 if
Parameters
x==
yelse 0 otherwise
Returns
negative number on error

Definition at line 319 of file ffi_ec.cpp.

319 {
320 return BOTAN_FFI_VISIT(x_w, [=](const auto& x) -> int { return x == safe_get(y_w) ? 1 : 0; });
321}

References BOTAN_FFI_VISIT, and Botan_FFI::safe_get().

◆ botan_ec_point_from_bytes()

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 )

Create a point from a SEC1 compressed or uncompressed format.

Returns
negative number on error

Definition at line 267 of file ffi_ec.cpp.

270 {
271 if(Botan::any_null_pointers(ec_point, bytes)) {
273 }
274 return BOTAN_FFI_VISIT(ec_group, [=](const auto& g) -> int {
275 Botan::EC_AffinePoint pt(g, std::span{bytes, bytes_len});
276 return ffi_new_object(ec_point, std::make_unique<Botan::EC_AffinePoint>(std::move(pt)));
277 });
278}

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_VISIT, and Botan_FFI::ffi_new_object().

◆ botan_ec_point_from_xy()

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 )

Create a point from a pair (x,y) of integers The integers must be within the field and must satisfy the curve equation

Definition at line 252 of file ffi_ec.cpp.

252 {
253 if(Botan::any_null_pointers(ec_point)) {
255 }
256 return ffi_guard_thunk(__func__, [=]() -> int {
257 std::optional<Botan::EC_AffinePoint> pt =
259 if(!pt.has_value()) {
261 }
262
263 return ffi_new_object(ec_point, std::make_unique<Botan::EC_AffinePoint>(pt.value()));
264 });
265}
static std::optional< EC_AffinePoint > from_bigint_xy(const EC_Group &group, const BigInt &x, const BigInt &y)
Definition ec_apoint.cpp:93
@ BOTAN_FFI_ERROR_BAD_PARAMETER
Definition ffi.h:134

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_ERROR_NULL_POINTER, Botan_FFI::ffi_guard_thunk(), Botan_FFI::ffi_new_object(), Botan::EC_AffinePoint::from_bigint_xy(), and Botan_FFI::safe_get().

◆ botan_ec_point_generator()

int botan_ec_point_generator ( botan_ec_point_t * ec_point,
botan_ec_group_t ec_group )

Create a point set to the standard group generator

Definition at line 243 of file ffi_ec.cpp.

243 {
244 if(Botan::any_null_pointers(ec_point)) {
246 }
247 return BOTAN_FFI_VISIT(ec_group, [=](const auto& g) -> int {
248 return ffi_new_object(ec_point, std::make_unique<Botan::EC_AffinePoint>(Botan::EC_AffinePoint::generator(g)));
249 });
250}
static EC_AffinePoint generator(const EC_Group &group)
Return the standard group generator.
Definition ec_apoint.cpp:84

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_VISIT, Botan_FFI::ffi_new_object(), and Botan::EC_AffinePoint::generator().

◆ botan_ec_point_identity()

int botan_ec_point_identity ( botan_ec_point_t * ec_point,
botan_ec_group_t ec_group )

Create a point set to the identity element of the group

Definition at line 234 of file ffi_ec.cpp.

234 {
235 if(Botan::any_null_pointers(ec_point)) {
237 }
238 return BOTAN_FFI_VISIT(ec_group, [=](const auto& g) -> int {
239 return ffi_new_object(ec_point, std::make_unique<Botan::EC_AffinePoint>(Botan::EC_AffinePoint::identity(g)));
240 });
241}
static EC_AffinePoint identity(const EC_Group &group)
Return the identity element.
Definition ec_apoint.cpp:79

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_VISIT, Botan_FFI::ffi_new_object(), and Botan::EC_AffinePoint::identity().

◆ botan_ec_point_is_identity()

int botan_ec_point_is_identity ( botan_ec_point_t ec_point)
Returns
1 if
Parameters
ec_pointis the identity element, else 0
Returns
negative number on error

Definition at line 315 of file ffi_ec.cpp.

315 {
316 return BOTAN_FFI_VISIT(ec_point, [=](const auto& p) -> int { return p.is_identity() ? 1 : 0; });
317}

References BOTAN_FFI_VISIT.

◆ botan_ec_point_mul()

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 )

Definition at line 323 of file ffi_ec.cpp.

326 {
327 if(Botan::any_null_pointers(result)) {
329 }
330 return BOTAN_FFI_VISIT(ec_point, [=](auto& pt) -> int {
331 Botan::EC_AffinePoint res = pt.mul(safe_get(ec_scalar), safe_get(rng));
332 return ffi_new_object(result, std::make_unique<Botan::EC_AffinePoint>(std::move(res)));
333 });
334}
EC_AffinePoint mul(const EC_Scalar &scalar, RandomNumberGenerator &rng) const
Multiply a point by a scalar returning a complete point.

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_VISIT, Botan_FFI::ffi_new_object(), Botan::EC_AffinePoint::mul(), and Botan_FFI::safe_get().

◆ botan_ec_point_negate()

int botan_ec_point_negate ( botan_ec_point_t * result,
botan_ec_point_t ec_point )
Parameters
ec_pointpoint to negate
resultcontains the result

Definition at line 336 of file ffi_ec.cpp.

336 {
337 if(Botan::any_null_pointers(result)) {
339 }
340 return BOTAN_FFI_VISIT(ec_point, [=](auto& pt) -> int {
341 Botan::EC_AffinePoint res = pt.negate();
342 return ffi_new_object(result, std::make_unique<Botan::EC_AffinePoint>(std::move(res)));
343 });
344}
EC_AffinePoint negate() const
Point negation.

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_VISIT, Botan_FFI::ffi_new_object(), and Botan::EC_AffinePoint::negate().

◆ botan_ec_point_view_compressed()

int botan_ec_point_view_compressed ( botan_ec_point_t ec_point,
botan_view_ctx ctx,
botan_view_bin_fn view )

View the fixed length SEC1 compressed encoding

Returns
negative number on error

Definition at line 308 of file ffi_ec.cpp.

308 {
309 return BOTAN_FFI_VISIT(ec_point, [=](const auto& p) -> int {
310 auto bytes = p.serialize_compressed();
311 return invoke_view_callback(view, ctx, bytes);
312 });
313}

References BOTAN_FFI_VISIT, and Botan_FFI::invoke_view_callback().

◆ botan_ec_point_view_uncompressed()

int botan_ec_point_view_uncompressed ( botan_ec_point_t ec_point,
botan_view_ctx ctx,
botan_view_bin_fn view )

View the fixed length SEC1 uncompressed encoding

Returns
negative number on error

Definition at line 301 of file ffi_ec.cpp.

301 {
302 return BOTAN_FFI_VISIT(ec_point, [=](const auto& p) -> int {
303 auto bytes = p.serialize_uncompressed();
304 return invoke_view_callback(view, ctx, bytes);
305 });
306}

References BOTAN_FFI_VISIT, and Botan_FFI::invoke_view_callback().

◆ botan_ec_point_view_x_bytes()

int botan_ec_point_view_x_bytes ( botan_ec_point_t ec_point,
botan_view_ctx ctx,
botan_view_bin_fn view )

View the fixed length encoding of the affine x coordinate

Returns
negative number on error

Definition at line 280 of file ffi_ec.cpp.

280 {
281 return BOTAN_FFI_VISIT(ec_point, [=](const auto& p) -> int {
282 auto bytes = p.x_bytes();
283 return invoke_view_callback(view, ctx, bytes);
284 });
285}

References BOTAN_FFI_VISIT, and Botan_FFI::invoke_view_callback().

◆ botan_ec_point_view_xy_bytes()

int botan_ec_point_view_xy_bytes ( botan_ec_point_t ec_point,
botan_view_ctx ctx,
botan_view_bin_fn view )

View the fixed length encoding of the affine x and y coordinates

Returns
negative number on error

Definition at line 294 of file ffi_ec.cpp.

294 {
295 return BOTAN_FFI_VISIT(ec_point, [=](const auto& p) -> int {
296 auto bytes = p.xy_bytes();
297 return invoke_view_callback(view, ctx, bytes);
298 });
299}

References BOTAN_FFI_VISIT, and Botan_FFI::invoke_view_callback().

◆ botan_ec_point_view_y_bytes()

int botan_ec_point_view_y_bytes ( botan_ec_point_t ec_point,
botan_view_ctx ctx,
botan_view_bin_fn view )

View the fixed length encoding of the affine y coordinate

Returns
negative number on error

Definition at line 287 of file ffi_ec.cpp.

287 {
288 return BOTAN_FFI_VISIT(ec_point, [=](const auto& p) -> int {
289 auto bytes = p.y_bytes();
290 return invoke_view_callback(view, ctx, bytes);
291 });
292}

References BOTAN_FFI_VISIT, and Botan_FFI::invoke_view_callback().

◆ botan_ec_scalar_destroy()

int botan_ec_scalar_destroy ( botan_ec_scalar_t ec_scalar)

Definition at line 196 of file ffi_ec.cpp.

196 {
197 return BOTAN_FFI_CHECKED_DELETE(ec_scalar);
198}

References BOTAN_FFI_CHECKED_DELETE.

◆ botan_ec_scalar_from_mp()

int botan_ec_scalar_from_mp ( botan_ec_scalar_t * ec_scalar,
botan_ec_group_t ec_group,
botan_mp_t mp )

Convert from an MPI to a scalar

Returns
a negative number if the provided MPI is negative or too large, 0 on success

Definition at line 209 of file ffi_ec.cpp.

209 {
210 if(Botan::any_null_pointers(ec_scalar)) {
212 }
213 return BOTAN_FFI_VISIT(ec_group, [=](const auto& g) -> int {
214 return ffi_new_object(ec_scalar,
215 std::make_unique<Botan::EC_Scalar>(Botan::EC_Scalar::from_bigint(g, safe_get(mp))));
216 });
217}
static EC_Scalar from_bigint(const EC_Group &group, const BigInt &bn)
Definition ec_scalar.cpp:69

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_VISIT, Botan_FFI::ffi_new_object(), Botan::EC_Scalar::from_bigint(), and Botan_FFI::safe_get().

◆ botan_ec_scalar_random()

int botan_ec_scalar_random ( botan_ec_scalar_t * ec_scalar,
botan_ec_group_t ec_group,
botan_rng_t rng )

Create a new random scalar value

Definition at line 200 of file ffi_ec.cpp.

200 {
201 if(Botan::any_null_pointers(ec_scalar)) {
203 }
204 return BOTAN_FFI_VISIT(ec_group, [=](const auto& g) -> int {
205 return ffi_new_object(ec_scalar, std::make_unique<Botan::EC_Scalar>(Botan::EC_Scalar::random(g, safe_get(rng))));
206 });
207}
static EC_Scalar random(const EC_Group &group, RandomNumberGenerator &rng)
Definition ec_scalar.cpp:61

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_VISIT, Botan_FFI::ffi_new_object(), Botan::EC_Scalar::random(), and Botan_FFI::safe_get().

◆ botan_ec_scalar_to_mp()

int botan_ec_scalar_to_mp ( botan_ec_scalar_t ec_scalar,
botan_mp_t * mp )

Convert from a scalar to an MPI

Returns
a negative number on failure, 0 on success

Definition at line 219 of file ffi_ec.cpp.

219 {
222 }
223 return BOTAN_FFI_VISIT(ec_scalar, [=](const auto& sc) -> int {
224 return ffi_new_object(mp, std::make_unique<Botan::BigInt>(sc.to_bigint()));
225 });
226}

References Botan::any_null_pointers(), BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_VISIT, and Botan_FFI::ffi_new_object().