purify
C++ Purify implementation with native circuit and BPP support
Loading...
Searching...
No Matches
curve.cpp
Go to the documentation of this file.
1// Copyright (c) 2026 Judica, Inc.
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or https://opensource.org/license/mit/.
4
9
10#include "purify/curve.hpp"
11
12#include <algorithm>
13
14#include "purify/secret.hpp"
15#include "secure_cleanup.hpp"
16#include "curve.h"
17
18namespace purify {
19
20namespace {
21
22using ::purify::detail::WipeOnDestruction;
23
24purify_fe to_core(const FieldElement& value) {
26}
27
28FieldElement from_core(const purify_fe& value) {
30}
31
32purify_jacobian_point to_core(const JacobianPoint& point) {
33 return purify_jacobian_point{to_core(point.x), to_core(point.y), to_core(point.z), point.infinity ? 1 : 0};
34}
35
36JacobianPoint from_core(const purify_jacobian_point& point) {
37 return JacobianPoint{from_core(point.x), from_core(point.y), from_core(point.z), point.infinity != 0};
38}
39
40purify_affine_point to_core(const AffinePoint& point) {
41 return purify_affine_point{to_core(point.x), to_core(point.y), point.infinity ? 1 : 0};
42}
43
44AffinePoint from_core(const purify_affine_point& point) {
45 return AffinePoint{from_core(point.x), from_core(point.y), point.infinity != 0};
46}
47
48UInt256 uint256_from_core(void (*fill)(uint64_t*)) {
49 UInt256 out;
50 fill(out.limbs.data());
51 return out;
52}
53
54UInt320 uint320_from_core(void (*fill)(uint64_t*)) {
55 UInt320 out;
56 fill(out.limbs.data());
57 return out;
58}
59
60UInt512 uint512_from_core(void (*fill)(uint64_t*)) {
61 UInt512 out;
62 fill(out.limbs.data());
63 return out;
64}
65
66FieldElement field_from_core(void (*fill)(purify_fe*)) {
67 purify_fe out{};
68 fill(&out);
69 return from_core(out);
70}
71
72purify_curve make_core_curve(const FieldElement& a, const FieldElement& b, const UInt256& n) {
73 purify_curve out{};
74 out.a = to_core(a);
75 out.b = to_core(b);
76 std::copy(n.limbs.begin(), n.limbs.end(), out.n);
77 return out;
78}
79
80} // namespace
81
87
89 : a_(std::move(a)), b_(std::move(b)), n_(std::move(n)) {}
90
92 purify_curve curve = make_core_curve(a_, b_, n_);
93 purify_jacobian_point in = to_core(point);
95 purify_curve_affine(&out, &curve, &in);
96 return from_core(out);
97}
98
100 purify_jacobian_point in = to_core(point);
102 purify_curve_negate(&out, &in);
103 return from_core(out);
104}
105
107 purify_curve curve = make_core_curve(a_, b_, n_);
108 purify_fe in = to_core(x);
109 return purify_curve_is_x_coord(&curve, &in) != 0;
110}
111
112std::optional<JacobianPoint> EllipticCurve::lift_x(const FieldElement& x) const {
113 purify_curve curve = make_core_curve(a_, b_, n_);
114 purify_fe in = to_core(x);
116 if (purify_curve_lift_x(&out, &curve, &in) == 0) {
117 return std::nullopt;
118 }
119 return from_core(out);
120}
121
123 purify_curve curve = make_core_curve(a_, b_, n_);
124 purify_jacobian_point in = to_core(point);
126 purify_curve_double(&out, &curve, &in);
127 return from_core(out);
128}
129
131 purify_curve curve = make_core_curve(a_, b_, n_);
132 purify_jacobian_point lhs_core = to_core(lhs);
133 purify_affine_point rhs_core = to_core(rhs);
135 purify_curve_add_mixed(&out, &curve, &lhs_core, &rhs_core);
136 return from_core(out);
137}
138
140 purify_curve curve = make_core_curve(a_, b_, n_);
141 purify_jacobian_point lhs_core = to_core(lhs);
142 purify_jacobian_point rhs_core = to_core(rhs);
144 purify_curve_add(&out, &curve, &lhs_core, &rhs_core);
145 return from_core(out);
146}
147
148JacobianPoint EllipticCurve::mul(const JacobianPoint& point, const UInt256& scalar) const {
149 purify_curve curve = make_core_curve(a_, b_, n_);
150 purify_jacobian_point in = to_core(point);
152 purify_curve_mul(&out, &curve, &in, scalar.limbs.data());
153 return from_core(out);
154}
155
157 purify_curve curve = make_core_curve(a_, b_, n_);
158 purify_jacobian_point point_core = to_core(point);
160 WipeOnDestruction out_guard(out);
161 if (purify_curve_mul_secret_affine(&out, &curve, &point_core, scalar.limbs.data()) == 0) {
163 "EllipticCurve::mul_secret_affine:purify_curve_mul_secret_affine");
164 }
165 return from_core(out);
166}
167
168Bytes bytes_from_ascii(std::string_view input) {
169 return Bytes(input.begin(), input.end());
170}
171
172Bytes operator+(Bytes lhs, const Bytes& rhs) {
173 lhs.insert(lhs.end(), rhs.begin(), rhs.end());
174 return lhs;
175}
176
177std::uint64_t ceil_div(std::uint64_t lhs, std::uint64_t rhs) {
178 return (lhs + rhs - 1) / rhs;
179}
180
181Bytes hmac_sha256(const Bytes& key, const Bytes& data) {
182 Bytes out(32);
183 purify_hmac_sha256(out.data(), key.data(), key.size(), data.data(), data.size());
184 return out;
185}
186
187Bytes hkdf(std::size_t length, const Bytes& ikm, const Bytes& salt, const Bytes& info) {
188 constexpr std::size_t hash_len = 32;
189 Bytes zero_salt(hash_len, 0);
190 Bytes prk = hmac_sha256(salt.empty() ? zero_salt : salt, ikm);
191 Bytes t;
192 Bytes okm;
193 for (std::size_t i = 0; i < ceil_div(length, hash_len); ++i) {
194 Bytes input = t;
195 input.insert(input.end(), info.begin(), info.end());
196 input.push_back(static_cast<unsigned char>(i + 1));
197 t = hmac_sha256(prk, input);
198 okm.insert(okm.end(), t.begin(), t.end());
199 }
200 okm.resize(length);
201 return okm;
202}
203
204const UInt256& prime_p() {
205 static const UInt256 value = uint256_from_core(purify_curve_prime_p);
206 return value;
207}
208
210 static const UInt256 value = uint256_from_core(purify_curve_order_n1);
211 return value;
212}
213
215 static const UInt256 value = uint256_from_core(purify_curve_order_n2);
216 return value;
217}
218
219const UInt256& half_n1() {
220 static const UInt256 value = uint256_from_core(purify_curve_half_n1);
221 return value;
222}
223
224const UInt256& half_n2() {
225 static const UInt256 value = uint256_from_core(purify_curve_half_n2);
226 return value;
227}
228
230 static const UInt512 value = uint512_from_core(purify_curve_packed_secret_key_space_size);
231 return value;
232}
233
235 static const UInt512 value = uint512_from_core(purify_curve_packed_public_key_space_size);
236 return value;
237}
238
239const UInt320& two_p() {
240 static const UInt320 value = uint320_from_core(purify_curve_two_p);
241 return value;
242}
243
245 return field_from_core(purify_curve_field_a);
246}
247
249 return field_from_core(purify_curve_field_b);
250}
251
253 return field_from_core(purify_curve_field_d);
254}
255
257 static const FieldElement value = field_from_core(purify_curve_field_di);
258 return value;
259}
260
262 static const EllipticCurve curve(field_a(), field_b(), order_n1());
263 return curve;
264}
265
267 static const EllipticCurve curve(field_a() * field_d() * field_d(),
268 field_b() * field_d() * field_d() * field_d(),
269 order_n2());
270 return curve;
271}
272
274 purify_curve curve_core = make_core_curve(curve.a_, curve.b_, curve.n_);
276 if (purify_curve_hash_to_curve(&out, &curve_core, data.data(), data.size()) == 0) {
277 return unexpected_error(ErrorCode::HashToCurveExhausted, "hash_to_curve:purify_curve_hash_to_curve");
278 }
279 return from_core(out);
280}
281
283 static const JacobianPoint value = [] {
284 Result<JacobianPoint> point_result = hash_to_curve(bytes_from_ascii("Generator/1"), curve1());
285 assert(point_result.has_value() && "generator1() hash_to_curve should not exhaust");
286 JacobianPoint point = *point_result;
287 assert(curve1().mul(point, order_n1()).infinity && "generator1() subgroup order check failed");
288 return point;
289 }();
290 return value;
291}
292
294 static const JacobianPoint value = [] {
295 Result<JacobianPoint> point_result = hash_to_curve(bytes_from_ascii("Generator/2"), curve2());
296 assert(point_result.has_value() && "generator2() hash_to_curve should not exhaust");
297 JacobianPoint point = *point_result;
298 assert(curve2().mul(point, order_n2()).infinity && "generator2() subgroup order check failed");
299 return point;
300 }();
301 return value;
302}
303
305 return purify_curve_is_valid_secret_key(z.limbs.data()) != 0;
306}
307
308bool is_valid_public_key(const UInt512& packed) {
309 return purify_curve_is_valid_public_key(packed.limbs.data()) != 0;
310}
311
313 if (!is_valid_secret_key(z)) {
314 return unexpected_error(ErrorCode::RangeViolation, "validate_secret_key:out_of_range");
315 }
316 return {};
317}
318
320 if (!is_valid_public_key(packed)) {
321 return unexpected_error(ErrorCode::RangeViolation, "validate_public_key:out_of_range");
322 }
323 return {};
324}
325
327 UInt256 first;
328 WipeOnDestruction first_guard(first);
329 UInt256 second;
330 WipeOnDestruction second_guard(second);
331 if (purify_curve_unpack_secret(first.limbs.data(), second.limbs.data(), z.limbs.data()) == 0) {
332 return unexpected_error(ErrorCode::RangeViolation, "unpack_secret:validate_secret_key");
333 }
334 std::pair<UInt256, UInt256> unpacked{first, second};
335 WipeOnDestruction unpacked_guard(unpacked);
336 return unpacked;
337}
338
339Result<UInt512> pack_secret(const UInt256& first, const UInt256& second) {
340 if (first.is_zero() || half_n1() < first ||
341 second.is_zero() || half_n2() < second) {
343 "pack_secret:scalar_range");
344 }
345 auto first_offset = first;
346 WipeOnDestruction first_offset_guard(first_offset);
347 first_offset.sub_assign(UInt256::one());
348 auto second_offset = second;
349 WipeOnDestruction second_offset_guard(second_offset);
350 second_offset.sub_assign(UInt256::one());
351 auto packed = multiply(half_n1(), second_offset);
352 WipeOnDestruction packed_guard(packed);
353 packed.add_assign(widen<8>(first_offset));
354 assert(is_valid_secret_key(packed) &&
355 "pack_secret() output must be canonical");
356 Result<UInt512> result{packed};
357 return result;
358}
359
361 UInt256 first;
362 UInt256 second;
363 if (purify_curve_unpack_public(first.limbs.data(), second.limbs.data(), packed.limbs.data()) == 0) {
364 return unexpected_error(ErrorCode::RangeViolation, "unpack_public:validate_public_key");
365 }
366 return std::make_pair(first, second);
367}
368
371 PURIFY_ASSIGN_OR_RETURN(const auto& coordinates, unpack_public(packed),
372 "unpack_public_points:unpack");
374 const auto& first_x,
375 FieldElement::try_from_uint256(coordinates.first),
376 "unpack_public_points:first_x");
378 const auto& second_x,
379 FieldElement::try_from_uint256(coordinates.second),
380 "unpack_public_points:second_x");
381
382 const auto first = curve1().lift_x(first_x);
383 const auto second = curve2().lift_x(second_x);
384 if (!first || !second || first->infinity || second->infinity ||
385 !curve1().mul(*first, order_n1()).infinity ||
386 !curve2().mul(*second, order_n2()).infinity) {
388 "unpack_public_points:invalid_points");
389 }
390 return std::make_pair(*first, *second);
391}
392
395 "validate_public_points:unpack");
396 return {};
397}
398
399UInt512 pack_public(const UInt256& x1, const UInt256& x2) {
400 UInt512 out;
401 purify_curve_pack_public(out.limbs.data(), x1.limbs.data(), x2.limbs.data());
402 return out;
403}
404
406 purify_fe lhs = to_core(x1);
407 purify_fe rhs = to_core(x2);
408 purify_fe out{};
409 purify_curve_combine(&out, &lhs, &rhs);
410 return from_core(out);
411}
412
414 std::vector<int> out(max_value.bit_length());
415 if (purify_curve_key_to_bits(out.data(), out.size(), n.limbs.data(), max_value.limbs.data()) == 0) {
416 return unexpected_error(ErrorCode::RangeViolation, "key_to_bits:out_of_range");
417 }
418 return out;
419}
420
421} // namespace purify
Minimal elliptic-curve arithmetic over the Purify base field.
Definition curve.hpp:46
JacobianPoint mul(const JacobianPoint &point, const UInt256 &scalar) const
Multiplies a point by a scalar using double-and-add.
Definition curve.cpp:148
AffinePoint affine(const JacobianPoint &point) const
Converts a Jacobian point to affine coordinates.
Definition curve.cpp:91
FieldElement a_
Definition curve.hpp:89
JacobianPoint add_mixed(const JacobianPoint &lhs, const AffinePoint &rhs) const
Adds an affine point to a Jacobian point.
Definition curve.cpp:130
JacobianPoint negate(const JacobianPoint &point) const
Negates a point without changing its projective scale.
Definition curve.cpp:99
bool is_x_coord(const FieldElement &x) const
Returns true if the supplied x-coordinate lifts to a curve point.
Definition curve.cpp:106
std::optional< JacobianPoint > lift_x(const FieldElement &x) const
Lifts an x-coordinate to a Jacobian point when a square root exists.
Definition curve.cpp:112
Result< AffinePoint > mul_secret_affine(const JacobianPoint &point, const UInt256 &scalar) const
Multiplies a public point by a secret scalar using exception-free complete formulas.
Definition curve.cpp:156
EllipticCurve(FieldElement a, FieldElement b, UInt256 n)
Constructs a curve from its Weierstrass coefficients and subgroup order.
Definition curve.cpp:88
JacobianPoint add(const JacobianPoint &lhs, const JacobianPoint &rhs) const
Adds two Jacobian points.
Definition curve.cpp:139
JacobianPoint double_point(const JacobianPoint &point) const
Doubles a Jacobian point.
Definition curve.cpp:122
FieldElement b_
Definition curve.hpp:90
bool has_value() const noexcept
Definition expected.hpp:170
Field element modulo the backend scalar field used by this implementation.
Definition numeric.hpp:834
static Result< FieldElement > try_from_uint256(const UInt256 &value)
Converts a canonical 256-bit unsigned integer into the scalar field representation.
Definition numeric.cpp:69
void purify_curve_half_n1(uint64_t out[4])
Definition curve.c:432
int purify_curve_is_x_coord(const purify_curve *curve, const purify_fe *x)
Definition curve.c:510
void purify_curve_jacobian_infinity(purify_jacobian_point *out)
Definition curve.c:471
void purify_curve_pack_public(uint64_t out[8], const uint64_t x1[4], const uint64_t x2[4])
Definition curve.c:946
int purify_curve_is_valid_public_key(const uint64_t value[8])
Definition curve.c:881
void purify_curve_order_n2(uint64_t out[4])
Definition curve.c:428
void purify_curve_packed_public_key_space_size(uint64_t out[8])
Definition curve.c:444
void purify_curve_order_n1(uint64_t out[4])
Definition curve.c:424
void purify_curve_packed_secret_key_space_size(uint64_t out[8])
Definition curve.c:440
int purify_curve_unpack_public(uint64_t first[4], uint64_t second[4], const uint64_t value[8])
Definition curve.c:927
void purify_curve_double(purify_jacobian_point *out, const purify_curve *curve, const purify_jacobian_point *point)
Definition curve.c:545
int purify_curve_key_to_bits(int *out_bits, size_t out_len, const uint64_t value[4], const uint64_t max_value[4])
Definition curve.c:986
void purify_curve_field_a(purify_fe *out)
Definition curve.c:453
void purify_curve_two_p(uint64_t out[5])
Definition curve.c:448
void purify_curve_negate(purify_jacobian_point *out, const purify_jacobian_point *point)
Definition curve.c:499
void purify_curve_half_n2(uint64_t out[4])
Definition curve.c:436
int purify_curve_lift_x(purify_jacobian_point *out, const purify_curve *curve, const purify_fe *x)
Definition curve.c:524
int purify_curve_is_valid_secret_key(const uint64_t value[8])
Definition curve.c:875
void purify_curve_combine(purify_fe *out, const purify_fe *x1, const purify_fe *x2)
Definition curve.c:953
void purify_curve_field_di(purify_fe *out)
Definition curve.c:465
void purify_curve_field_d(purify_fe *out)
Definition curve.c:461
int purify_curve_hash_to_curve(purify_jacobian_point *out, const purify_curve *curve, const unsigned char *data, size_t data_len)
Definition curve.c:822
void purify_curve_field_b(purify_fe *out)
Definition curve.c:457
int purify_curve_mul_secret_affine(purify_affine_point *out, const purify_curve *curve, const purify_jacobian_point *point, const uint64_t scalar[4])
Definition curve.c:796
void purify_curve_mul(purify_jacobian_point *out, const purify_curve *curve, const purify_jacobian_point *point, const uint64_t scalar[4])
Definition curve.c:725
void purify_curve_add(purify_jacobian_point *out, const purify_curve *curve, const purify_jacobian_point *lhs, const purify_jacobian_point *rhs)
Definition curve.c:647
void purify_curve_add_mixed(purify_jacobian_point *out, const purify_curve *curve, const purify_jacobian_point *lhs, const purify_affine_point *rhs)
Definition curve.c:594
void purify_curve_affine(purify_affine_point *out, const purify_curve *curve, const purify_jacobian_point *point)
Definition curve.c:478
void purify_curve_prime_p(uint64_t out[4])
Definition curve.c:420
int purify_curve_unpack_secret(uint64_t first[4], uint64_t second[4], const uint64_t value[8])
Definition curve.c:912
struct purify_curve purify_curve
struct purify_affine_point purify_affine_point
struct purify_jacobian_point purify_jacobian_point
Elliptic-curve helpers, fixed parameters, and hash-to-curve utilities for Purify.
#define PURIFY_RETURN_IF_ERROR(expr, context)
Evaluates an expected-like expression and returns the wrapped error on failure.
Definition error.hpp:329
#define PURIFY_ASSIGN_OR_RETURN(lhs, expr, context)
Evaluates an expected-like expression, binds the value to lhs, and propagates errors.
Definition error.hpp:338
struct purify_fe purify_fe
BigUInt< LeftWords+RightWords > multiply(const BigUInt< LeftWords > &lhs, const BigUInt< RightWords > &rhs)
Multiplies two fixed-width integers and returns the full-width product.
Definition numeric.hpp:796
BigUInt< OutWords > widen(const BigUInt< InWords > &value)
Widens an integer to a larger limb count by zero-extending high limbs.
Definition numeric.hpp:697
Bytes hmac_sha256(const Bytes &key, const Bytes &data)
Computes an HMAC-SHA256 digest using the secp bridge implementation.
Definition curve.cpp:181
Status validate_secret_key(const UInt512 &z)
Validates the packed secret-key encoding range.
Definition curve.cpp:312
FieldElement field_di()
Returns the inverse of the twist factor in the field.
Definition curve.cpp:256
const UInt256 & half_n1()
Returns floor(order_n1 / 2).
Definition curve.cpp:219
constexpr Unexpected< Error > unexpected_error(ErrorCode code, const char *context=nullptr)
Constructs an unexpected Error value from a machine-readable code.
Definition error.hpp:293
BigUInt< 8 > UInt512
512-bit unsigned integer used for private and packed public keys.
Definition numeric.hpp:821
const UInt256 & prime_p()
Returns the Purify base-field modulus.
Definition curve.cpp:204
Result< std::vector< int > > key_to_bits(UInt256 n, const UInt256 &max_value)
Encodes a scalar into the signed 3-bit window bit schedule used by the circuit.
Definition curve.cpp:413
Result< std::pair< UInt256, UInt256 > > unpack_public(const UInt512 &packed)
Splits a packed public key into its two x-coordinates.
Definition curve.cpp:360
const UInt256 & half_n2()
Returns floor(order_n2 / 2).
Definition curve.cpp:224
Bytes bytes_from_ascii(std::string_view input)
Encodes an ASCII string as a byte vector.
Definition curve.cpp:168
BigUInt< 4 > UInt256
256-bit unsigned integer used for field elements and curve orders.
Definition numeric.hpp:817
std::uint64_t ceil_div(std::uint64_t lhs, std::uint64_t rhs)
Computes ceiling division for unsigned 64-bit values.
Definition curve.cpp:177
Bytes hkdf(std::size_t length, const Bytes &ikm, const Bytes &salt={}, const Bytes &info={})
Expands input key material using HKDF-SHA256.
Definition curve.cpp:187
const UInt256 & order_n2()
Returns the subgroup order for the second curve.
Definition curve.cpp:214
Status validate_public_key(const UInt512 &packed)
Validates the packed public-key encoding range.
Definition curve.cpp:319
bool is_valid_public_key(const UInt512 &packed)
Returns true when a packed public key is encoded canonically.
Definition curve.cpp:308
const UInt320 & two_p()
Returns 2 * prime_p() as a widened integer for hash-to-curve sampling.
Definition curve.cpp:239
FieldElement field_a()
Returns the shared Weierstrass a coefficient used by Purify.
Definition curve.cpp:244
const EllipticCurve & curve1()
Returns the first Purify curve instance.
Definition curve.cpp:261
Expected< T, Error > Result
Expected-returning convenience alias for Purify value-producing APIs.
Definition error.hpp:99
const JacobianPoint & generator1()
Returns the fixed generator for the first curve.
Definition curve.cpp:282
UInt512 pack_public(const UInt256 &x1, const UInt256 &x2)
Packs two x-coordinates into the reference 512-bit public-key encoding.
Definition curve.cpp:399
Result< UInt512 > pack_secret(const UInt256 &first, const UInt256 &second)
Packs scalars in [1, half_n1] and [1, half_n2].
Definition curve.cpp:339
const UInt512 & packed_secret_key_space_size()
Returns the size of the packed secret-key encoding space.
Definition curve.cpp:229
Result< std::pair< UInt256, UInt256 > > unpack_secret(const UInt512 &z)
Splits a packed private key into its two per-curve secret scalars.
Definition curve.cpp:326
BigUInt< 5 > UInt320
320-bit unsigned integer used during hash-to-curve sampling.
Definition numeric.hpp:819
FieldElement field_d()
Returns the twist factor used to derive the second curve.
Definition curve.cpp:252
Expected< void, Error > Status
Expected-returning convenience alias for Purify status-only APIs.
Definition error.hpp:102
Result< JacobianPoint > hash_to_curve(const Bytes &data, const EllipticCurve &curve)
Hashes arbitrary data onto the supplied curve by rejection sampling x-coordinates.
Definition curve.cpp:273
Result< std::pair< JacobianPoint, JacobianPoint > > unpack_public_points(const UInt512 &packed)
Decodes and validates both curve points in a packed public key.
Definition curve.cpp:370
FieldElement field_b()
Returns the shared Weierstrass b coefficient used by Purify.
Definition curve.cpp:248
std::vector< unsigned char > Bytes
Dynamically sized byte string used for messages, serialized witnesses, and proofs.
Definition common.hpp:99
bool is_valid_secret_key(const UInt512 &z)
Returns true when a packed secret is encoded canonically.
Definition curve.cpp:304
const EllipticCurve & curve2()
Returns the second Purify curve instance.
Definition curve.cpp:266
const JacobianPoint & generator2()
Returns the fixed generator for the second curve.
Definition curve.cpp:293
const UInt256 & order_n1()
Returns the subgroup order for the first curve.
Definition curve.cpp:209
FieldElement combine(const FieldElement &x1, const FieldElement &x2)
Applies the Purify curve-combination map to two x-coordinates.
Definition curve.cpp:405
const UInt512 & packed_public_key_space_size()
Returns the size of the packed public-key encoding space.
Definition curve.cpp:234
Status validate_public_points(const UInt512 &packed)
Validates both curve points in a packed public key.
Definition curve.cpp:393
Bytes operator+(Bytes lhs, const Bytes &rhs)
Concatenates two byte vectors.
Definition curve.cpp:172
void purify_hmac_sha256(unsigned char output32[32], const unsigned char *key, size_t key_len, const unsigned char *data, size_t data_len)
Computes HMAC-SHA256 over a byte string.
Secret-owning Purify key material wrappers.
Affine point representation used for serialization and lookup tables.
Definition curve.hpp:28
std::size_t bit_length() const
Returns the index of the highest set bit plus one.
Definition numeric.hpp:493
std::array< std::uint64_t, Words > limbs
Definition numeric.hpp:204
bool is_zero() const
Returns true when all limbs are zero.
Definition numeric.hpp:290
static BigUInt one()
Definition numeric.hpp:216
Jacobian point representation used for curve arithmetic.
Definition curve.hpp:17
static JacobianPoint infinity_point()
Returns the point at infinity in Jacobian coordinates.
Definition curve.cpp:82
static FieldElement from_raw(const purify_scalar &raw) noexcept
Definition numeric.hpp:944
static const purify_scalar & raw(const FieldElement &value) noexcept
Definition numeric.hpp:940
purify_fe y
Definition curve.h:25
purify_fe x
Definition curve.h:24
purify_fe b
Definition curve.h:37
purify_fe a
Definition curve.h:36
uint64_t n[4]
Definition curve.h:38
purify_scalar value
Definition field.h:17