Go to the documentation of this file.
25 #ifndef __DECAF_POINT_255_HXX__
26 #define __DECAF_POINT_255_HXX__ 1
30 #define _XOPEN_SOURCE 600
39 #include <sys/types.h>
43 #if __cplusplus >= 201103L
44 #define DECAF_NOEXCEPT noexcept
46 #define DECAF_NOEXCEPT throw()
58 static inline const char *
name() {
return "Ristretto"; }
61 static inline int bits() {
return 255; }
95 inline Scalar(uint64_t w) DECAF_NOEXCEPT { *
this = w; }
98 inline Scalar(int64_t w) DECAF_NOEXCEPT { *
this = w; }
101 inline Scalar(
unsigned int w) DECAF_NOEXCEPT { *
this = w; }
104 inline Scalar(
int w) DECAF_NOEXCEPT { *
this = w; }
119 inline Scalar(
const Block &buffer) DECAF_NOEXCEPT { *
this = buffer; }
138 Scalar t(-(uint64_t)INT_MIN);
145 inline Scalar&
operator=(
unsigned int w) DECAF_NOEXCEPT {
return *
this = (uint64_t)w; }
243 )
const DECAF_NOEXCEPT;
302 inline explicit Point(
Rng &rng,
bool uniform =
true) DECAF_NOEXCEPT {
410 memcpy(b.data(), s.data(), s.size());
416 memcpy(b.data(), s.data(), s.size());
490 )
const DECAF_NOEXCEPT {
539 )
const DECAF_NOEXCEPT {
541 memset(buf2,0,
sizeof(buf2));
552 for (
size_t i=0; i<buf.size() && i<
HASH_BYTES; i++) {
553 buf[i] = (buf[i] & ~ret) | (buf2[i] &ret);
556 return decaf_succeed_if(ret);
567 for (
int i=0; i<4; i++) { hint |= uint32_t(out[
HASH_BYTES-4+i])<<(8*i); }
569 }
while (!decaf_successful(done));
592 :
protected OwnedOrUnowned<Precomputed,Precomputed_U>
613 ) DECAF_NOEXCEPT : OwnedOrUnowned<Precomputed,Precomputed_U>(yours) {}
616 #if __cplusplus >= 201103L
619 OwnedOrUnowned<Precomputed,Precomputed_U>::operator= (it);
630 OwnedOrUnowned<Precomputed,Precomputed_U>::operator= (it);
648 : OwnedOrUnowned<
Precomputed,Precomputed_U>() { *
this = it; }
654 : OwnedOrUnowned<
Precomputed,Precomputed_U>() { *
this = it; }
667 friend class OwnedOrUnowned<
Precomputed,Precomputed_U>;
669 static inline size_t alignment() DECAF_NOEXCEPT {
return decaf_255_alignof_precomputed_s; }
707 return decaf_x25519(out.data(), pk.data(), scalar.data());
763 const FixedBlock<Ristretto::Point::SER_BYTES> &in,
771 throw CryptoException();
777 FixedBuffer<Ristretto::Point::SER_BYTES> &out,
778 const FixedBlock<Ristretto::Point::SER_BYTES> &in,
781 )
const DECAF_NOEXCEPT {
790 #undef DECAF_NOEXCEPT
Namespace for all libdecaf C++ objects.
Definition: ed255.hxx:41
decaf_bool_t DECAF_API_VIS decaf_memeq(const void *data1, const void *data2, size_t size) DECAF_NONNULL DECAF_WARN_UNUSED
Compare two buffers, returning DECAF_TRUE if they are equal.
static void generate_key_noexcept(FixedBuffer< PUBLIC_BYTES > &out, const FixedBlock< PRIVATE_BYTES > &scalar) DECAF_NOEXCEPT
Calculate and return a public key into a fixed buffer; equivalent to shared_secret(base_point(),...
Definition: point_255.hxx:751
static const size_t PRIVATE_BYTES
Bytes in an X25519 private key.
Definition: point_255.hxx:681
decaf_error_t DECAF_WARN_UNUSED direct_scalarmul_noexcept(FixedBuffer< SER_BYTES > &out, const FixedBlock< SER_BYTES > &in, decaf_bool_t allow_identity=DECAF_FALSE, decaf_bool_t short_circuit=DECAF_TRUE) const DECAF_NOEXCEPT
Direct scalar multiplication.
Scalar & operator+=(const Scalar &q) DECAF_NOEXCEPT
Add to this.
Definition: point_255.hxx:172
Wrapped s
access to the underlying scalar object
Definition: point_255.hxx:87
static const Precomputed base() DECAF_NOEXCEPT
Return the table for the base point.
Definition: point_255.hxx:663
decaf_error_t DECAF_API_VIS decaf_255_scalar_decode(decaf_255_scalar_t out, const unsigned char ser[DECAF_255_SCALAR_BYTES]) DECAF_WARN_UNUSED DECAF_NONNULL DECAF_NOINLINE
Read a scalar from wire format or from bytes.
Scalar(const Scalar &x) DECAF_NOEXCEPT
Copy constructor.
Definition: point_255.hxx:116
static const int LADDER_ENCODE_RATIO
Ratio due to ladder decoding.
Definition: point_255.hxx:271
Scalar & operator=(int64_t w) DECAF_NOEXCEPT
Assign from signed int.
Definition: point_255.hxx:137
Point operator-() const DECAF_NOEXCEPT
Point negate.
Definition: point_255.hxx:451
const DECAF_API_VIS size_t decaf_255_sizeof_precomputed_s
Size and alignment of precomputed point tables.
#define DECAF_255_INVERT_ELLIGATOR_WHICH_BITS
Number of bits in the "which" field of an elligator inverse.
Definition: point_255.h:53
static const size_t STEG_BYTES
Size of a steganographically-encoded curve element.
Definition: point_255.hxx:276
A group of prime order p, based on Curve25519.
Precomputed table of points.
Definition: point_255.hxx:590
void mul_by_ratio_and_encode_like_eddsa(FixedBuffer< DECAF_EDDSA_25519_PUBLIC_BYTES > &out) const
Multiply by EDDSA_ENCODE_RATIO and encode like EdDSA.
Definition: point_255.hxx:373
decaf_error_t DECAF_API_VIS decaf_255_invert_elligator_nonuniform(unsigned char recovered_hash[DECAF_255_HASH_BYTES], const decaf_255_point_t pt, uint32_t which) DECAF_NONNULL DECAF_NOINLINE DECAF_WARN_UNUSED
Inverse of elligator-like hash to curve.
void DECAF_API_VIS decaf_255_precomputed_scalarmul(decaf_255_point_t scaled, const decaf_255_precomputed_s *base, const decaf_255_scalar_t scalar) DECAF_NONNULL DECAF_NOINLINE
Multiply a precomputed base point by a scalar: scaled = scalar*base.
void DECAF_API_VIS decaf_255_point_negate(decaf_255_point_t nega, const decaf_255_point_t a) DECAF_NONNULL
Negate a point to produce another point.
void DECAF_API_VIS decaf_255_point_from_hash_uniform(decaf_255_point_t pt, const unsigned char hashed_data[2 *DECAF_255_HASH_BYTES]) DECAF_NONNULL DECAF_NOINLINE
Indifferentiable hash function encoding to curve.
#define DECAF_EDDSA_25519_PUBLIC_BYTES
Number of bytes in an EdDSA public key.
Definition: ed255.h:27
bool validate() const DECAF_NOEXCEPT
Validate / sanity check.
Definition: point_255.hxx:478
struct decaf_255_precomputed_s decaf_255_precomputed_s
Precomputed table based on a point.
Definition: point_255.h:78
decaf_255_scalar_t Wrapped
wrapped C type
Definition: point_255.hxx:81
#define DECAF_255_SCALAR_BYTES
Number of bytes in a serialized scalar.
Definition: point_255.h:50
static const Point identity() DECAF_NOEXCEPT
Return the identity point of the curve.
Definition: point_255.hxx:577
static SecureBuffer derive_public_key(const FixedBlock< PRIVATE_BYTES > &scalar)
Calculate and return a public key; equivalent to shared_secret(base_point(),scalar) but possibly fast...
Definition: point_255.hxx:726
static const FixedBlock< PUBLIC_BYTES > base_point() DECAF_NOEXCEPT
Base point for a scalar multiplication.
Definition: point_255.hxx:684
#define DECAF_255_EDDSA_DECODE_RATIO
EdDSA decoding ratio.
Definition: ed255.h:62
bool operator!=(const Scalar &q) const DECAF_NOEXCEPT
Compare in constant time.
Definition: point_255.hxx:217
static Point from_hash(const Block &s) DECAF_NOEXCEPT
Map uniformly to the curve from a hash buffer.
Definition: point_255.hxx:397
Wrapped p
The c-level object.
Definition: point_255.hxx:282
uint32_t decaf_bool_t
"Boolean" type, will be set to all-zero or all-one (i.e.
Definition: common.h:89
Scalar operator*(const Scalar &q) const DECAF_NOEXCEPT
Multiply.
Definition: point_255.hxx:181
void mul_by_ratio_and_encode_like_ladder(FixedBuffer< LADDER_BYTES > &out) const
Multiply by LADDER_ENCODE_RATIO and encode like X25519/X448.
Definition: point_255.hxx:387
bool operator!=(const Point &q) const DECAF_NOEXCEPT
Constant-time compare.
Definition: point_255.hxx:460
Precomputed(const Precomputed_U &yours= *decaf_255_precomputed_base) DECAF_NOEXCEPT
Initialize from underlying type, declared as a reference to prevent it from being called with 0,...
Definition: point_255.hxx:611
decaf_bool_t DECAF_API_VIS decaf_255_point_valid(const decaf_255_point_t to_test) DECAF_WARN_UNUSED DECAF_NONNULL DECAF_NOINLINE
Test that a point is valid, for debugging purposes.
static SecureBuffer shared_secret(const FixedBlock< PUBLIC_BYTES > &pk, const FixedBlock< PRIVATE_BYTES > &scalar)
Calculate and return a shared secret with public key.
Definition: point_255.hxx:689
static decaf_error_t DECAF_WARN_UNUSED decode(Scalar &sc, const FixedBlock< SER_BYTES > buffer) DECAF_NOEXCEPT
Decode from correct-length little-endian byte sequence.
Definition: point_255.hxx:162
Scalar(unsigned int w) DECAF_NOEXCEPT
Set to an unsigned word.
Definition: point_255.hxx:101
Scalar operator/(const Scalar &q) const
Return this/q.
Definition: point_255.hxx:208
Precomputed(const Point &it)
Constructor which initializes from point.
Definition: point_255.hxx:653
void DECAF_API_VIS decaf_255_point_double_scalarmul(decaf_255_point_t combo, const decaf_255_point_t base1, const decaf_255_scalar_t scalar1, const decaf_255_point_t base2, const decaf_255_scalar_t scalar2) DECAF_NONNULL DECAF_NOINLINE
Multiply two base points by two scalars: scaled = scalar1*base1 + scalar2*base2.
static Point double_scalarmul(const Scalar &qs, const Point &q, const Scalar &rs, const Point &r) DECAF_NOEXCEPT
Double-scalar multiply, equivalent to q*qs + r*rs but faster.
Definition: point_255.hxx:498
Scalar & operator=(unsigned int w) DECAF_NOEXCEPT
Assign from unsigned int.
Definition: point_255.hxx:145
@ DECAF_SUCCESS
The operation succeeded.
Definition: common.h:121
const unsigned char * data() const DECAF_NOEXCEPT
Get const data.
Definition: secure_buffer.hxx:276
void DECAF_API_VIS decaf_255_point_dual_scalarmul(decaf_255_point_t a1, decaf_255_point_t a2, const decaf_255_point_t base1, const decaf_255_scalar_t scalar1, const decaf_255_scalar_t scalar2) DECAF_NONNULL DECAF_NOINLINE
Multiply one base point by two scalars:
Scalar & operator*=(const Scalar &q) DECAF_NOEXCEPT
Multiply into this.
Definition: point_255.hxx:184
Scalar operator+(const Scalar &q) const DECAF_NOEXCEPT
Add.
Definition: point_255.hxx:169
const uint8_t decaf_x25519_base_point[DECAF_X25519_PUBLIC_BYTES]
The base point for X25519 Diffie-Hellman.
Definition: decaf.c:66
void serialize_into(unsigned char *buffer) const DECAF_NOEXCEPT
Serializable instance.
Definition: point_255.hxx:125
bool operator==(const Point &q) const DECAF_NOEXCEPT
Constant-time compare.
Definition: point_255.hxx:463
bool operator==(const Scalar &q) const DECAF_NOEXCEPT
Compare in constant time.
Definition: point_255.hxx:220
std::vector< unsigned char, SanitizingAllocator< unsigned char, 0 > > SecureBuffer
A variant of std::vector which securely zerozes its state when destructed.
Definition: secure_buffer.hxx:79
Scalar(int64_t w) DECAF_NOEXCEPT
Set to a signed word.
Definition: point_255.hxx:98
A fixed-size block.
Definition: secure_buffer.hxx:247
Point & operator=(const Point &q) DECAF_NOEXCEPT
Assignment.
Definition: point_255.hxx:296
Scalar operator-() const DECAF_NOEXCEPT
Negate.
Definition: point_255.hxx:187
A fixed-size stack-allocated buffer (for DECAF_NOEXCEPT semantics)
Definition: secure_buffer.hxx:331
SecureBuffer direct_scalarmul(const FixedBlock< SER_BYTES > &in, decaf_bool_t allow_identity=DECAF_FALSE, decaf_bool_t short_circuit=DECAF_TRUE) const
Direct scalar multiplication.
decaf_error_t DECAF_API_VIS decaf_255_point_decode_like_eddsa_and_mul_by_ratio(decaf_255_point_t p, const uint8_t enc[DECAF_EDDSA_25519_PUBLIC_BYTES]) DECAF_NONNULL DECAF_NOINLINE
EdDSA point decoding.
decaf_error_t invert_elligator(Buffer buf, uint32_t hint) const DECAF_NOEXCEPT
Modify buffer so that Point::from_hash(Buffer) == *this, and return DECAF_SUCCESS; or leave buf unmod...
Definition: point_255.hxx:537
Scalar inverse() const
Return 1/this.
Definition: point_255.hxx:192
Point operator/(const Scalar &s) const
Multiply by s.inverse().
Definition: point_255.hxx:472
Scalar half() const
Return half this scalar.
Definition: point_255.hxx:214
void DECAF_API_VIS decaf_255_precompute(decaf_255_precomputed_s *a, const decaf_255_point_t b) DECAF_NONNULL DECAF_NOINLINE
Precompute a table for fast scalar multiplication.
A group of prime order p, based on Curve25519.
static const size_t EDDSA_BYTES
Bytes required for EdDSA encoding.
Definition: point_255.hxx:259
Point debugging_pscale(const FixedBlock< SER_BYTES > factor) const DECAF_NOEXCEPT
Return a point equal to *this, whose internal data has a modified representation.
Definition: point_255.hxx:521
Scalar(const Wrapped &t=decaf_255_scalar_zero) DECAF_NOEXCEPT
Construct from decaf_scalar_t object.
Definition: point_255.hxx:113
#define DECAF_255_HASH_BYTES
Number of bytes in an elligated point.
Definition: point_255.h:47
decaf_error_t
Another boolean type used to indicate success or failure.
Definition: common.h:120
Point & operator/=(const Scalar &s)
Multiply by s.inverse().
Definition: point_255.hxx:475
Point(Rng &rng, bool uniform=true) DECAF_NOEXCEPT
Construct from RNG.
Definition: point_255.hxx:302
decaf_error_t DECAF_WARN_UNUSED decode(const FixedBlock< SER_BYTES > &buffer, bool allow_identity=true) DECAF_NOEXCEPT
Initialize from C++ fixed-length byte string.
Definition: point_255.hxx:334
void serialize_into(unsigned char *buffer) const DECAF_NOEXCEPT
Serializable instance.
Definition: point_255.hxx:434
SecureBuffer mul_by_ratio_and_encode_like_eddsa() const
Multiply by EDDSA_ENCODE_RATIO and encode like EdDSA.
Definition: point_255.hxx:366
static Point double_scalarmul(const Point &q, const Scalar &qs, const Point &r, const Scalar &rs) DECAF_NOEXCEPT
Double-scalar multiply, equivalent to q*qs + r*rs but faster.
Definition: point_255.hxx:481
size_t ser_size() const DECAF_NOEXCEPT
Serializable instance.
Definition: point_255.hxx:122
static decaf_error_t DECAF_WARN_UNUSED shared_secret_noexcept(FixedBuffer< PUBLIC_BYTES > &out, const FixedBlock< PUBLIC_BYTES > &pk, const FixedBlock< PRIVATE_BYTES > &scalar) DECAF_NOEXCEPT
Calculate and write into out a shared secret with public key, noexcept version.
Definition: point_255.hxx:702
Passed to constructors to avoid (conservative) initialization.
Definition: secure_buffer.hxx:133
void DECAF_API_VIS decaf_255_point_sub(decaf_255_point_t diff, const decaf_255_point_t a, const decaf_255_point_t b) DECAF_NONNULL
Subtract two points to produce a third point.
static int bits()
The name of the curve.
Definition: point_255.hxx:61
Ristretto IsoEd25519
Alternative name for Ristretto, for backwards compatibility.
Definition: point_255.hxx:787
Prototype of a random number generator.
Definition: secure_buffer.hxx:138
~Point() DECAF_NOEXCEPT
Destructor securely zeorizes the point.
Definition: point_255.hxx:299
decaf_error_t DECAF_API_VIS decaf_255_invert_elligator_uniform(unsigned char recovered_hash[2 *DECAF_255_HASH_BYTES], const decaf_255_point_t pt, uint32_t which) DECAF_NONNULL DECAF_NOINLINE DECAF_WARN_UNUSED
Inverse of elligator-like hash to curve.
void DECAF_API_VIS decaf_255_scalar_add(decaf_255_scalar_t out, const decaf_255_scalar_t a, const decaf_255_scalar_t b) DECAF_NONNULL DECAF_NOINLINE
Add two scalars.
A reference to a block of data, which (when accessed through this base class) is const.
Definition: secure_buffer.hxx:159
void DECAF_API_VIS decaf_x25519_derive_public_key(uint8_t out[DECAF_X25519_PUBLIC_BYTES], const uint8_t scalar[DECAF_X25519_PRIVATE_BYTES]) DECAF_NONNULL DECAF_NOINLINE
RFC 7748 Diffie-Hellman base point scalarmul.
X-only Diffie-Hellman ladder functions.
Definition: point_255.hxx:675
const DECAF_API_VIS decaf_255_scalar_t decaf_255_scalar_zero
The scalar 0.
void DECAF_API_VIS decaf_255_point_from_hash_nonuniform(decaf_255_point_t pt, const unsigned char hashed_data[DECAF_255_HASH_BYTES]) DECAF_NONNULL DECAF_NOINLINE
Almost-Elligator-like hash to curve.
Scalar & operator=(int w) DECAF_NOEXCEPT
Assign from signed int.
Definition: point_255.hxx:148
static const char * name()
The name of the curve.
Definition: point_255.hxx:58
Scalar & operator-=(const Scalar &q) DECAF_NOEXCEPT
Subtract from this.
Definition: point_255.hxx:178
void DECAF_API_VIS decaf_255_point_encode(uint8_t ser[DECAF_255_SER_BYTES], const decaf_255_point_t pt) DECAF_NONNULL DECAF_NOINLINE
Encode a point as a sequence of bytes.
static const size_t PUBLIC_BYTES
Bytes in an X25519 public key.
Definition: point_255.hxx:678
static const int REMOVED_COFACTOR
The curve's cofactor (removed, but useful for testing)
Definition: point_255.hxx:64
A scalar modulo the curve order.
Definition: point_255.hxx:78
void decode_like_eddsa_and_mul_by_ratio(const FixedBlock< DECAF_EDDSA_25519_PUBLIC_BYTES > &buffer)
Decode from EDDSA, multiply by EDDSA_DECODE_RATIO, and ignore any remaining cofactor information.
Definition: point_255.hxx:359
static void derive_public_key_noexcept(FixedBuffer< PUBLIC_BYTES > &out, const FixedBlock< PRIVATE_BYTES > &scalar) DECAF_NOEXCEPT
Calculate and return a public key into a fixed buffer; equivalent to shared_secret(base_point(),...
Definition: point_255.hxx:738
Point operator/(const Scalar &s) const
Multiply by s.inverse().
Definition: point_255.hxx:660
Precomputed(const Precomputed &it)
Copy constructor.
Definition: point_255.hxx:647
void DECAF_API_VIS decaf_255_scalar_decode_long(decaf_255_scalar_t out, const unsigned char *ser, size_t ser_len) DECAF_NONNULL DECAF_NOINLINE
Read a scalar from wire format or from bytes.
#define DECAF_X25519_PUBLIC_BYTES
Number of bytes in an x25519 public key.
Definition: point_255.h:62
void dual_scalarmul(Point &q1, Point &q2, const Scalar &r1, const Scalar &r2) const DECAF_NOEXCEPT
Dual-scalar multiply, equivalent to this*r1, this*r2 but faster.
Definition: point_255.hxx:488
decaf_error_t DECAF_API_VIS decaf_255_scalar_invert(decaf_255_scalar_t out, const decaf_255_scalar_t a) DECAF_WARN_UNUSED DECAF_NONNULL DECAF_NOINLINE
Invert a scalar.
decaf_255_point_t Wrapped
Wrapped C type.
Definition: point_255.hxx:250
SecureBuffer steg_encode(Rng &rng, size_t size=STEG_BYTES) const
Steganographically encode this.
Definition: point_255.hxx:560
void DECAF_API_VIS decaf_255_point_mul_by_ratio_and_encode_like_x25519(uint8_t out[DECAF_X25519_PUBLIC_BYTES], const decaf_255_point_t p) DECAF_NONNULL
Multiply a point by DECAF_X25519_ENCODE_RATIO, then encode it like RFC 7748.
Point operator*(const Scalar &s) const DECAF_NOEXCEPT
Scalar multiply.
Definition: point_255.hxx:466
Scalar & operator=(const Scalar &x) DECAF_NOEXCEPT
Assignment.
Definition: point_255.hxx:130
C++ self-zeroizing buffer.
Point & operator-=(const Point &q) DECAF_NOEXCEPT
Point subtract.
Definition: point_255.hxx:448
Point debugging_pscale(Rng &r) const DECAF_NOEXCEPT
Return a point equal to *this, whose internal data has a randomized representation.
Definition: point_255.hxx:528
void DECAF_API_VIS decaf_255_scalar_set_unsigned(decaf_255_scalar_t out, uint64_t a) DECAF_NONNULL
Set a scalar to an unsigned 64-bit integer.
static SecureBuffer DECAF_DEPRECATED("Renamed to derive_public_key") generate_key(const FixedBlock< PRIVATE_BYTES > &scalar)
Calculate and return a public key; equivalent to shared_secret(base_point(),scalar) but possibly fast...
Definition: point_255.hxx:714
void DECAF_API_VIS decaf_bzero(void *data, size_t size) DECAF_NONNULL
Overwrite data with zeros.
static const size_t SER_BYTES
Size of a serialized element.
Definition: point_255.hxx:253
decaf_error_t DECAF_WARN_UNUSED decode_like_eddsa_and_mul_by_ratio_noexcept(const FixedBlock< DECAF_EDDSA_25519_PUBLIC_BYTES > &buffer) DECAF_NOEXCEPT
Initialize from C++ fixed-length byte string, like EdDSA.
Definition: point_255.hxx:348
Precomputed & operator=(const Point &it)
Initilaize from point.
Definition: point_255.hxx:638
#define DECAF_255_SER_BYTES
Number of bytes in a serialized point.
Definition: point_255.h:42
void DECAF_API_VIS decaf_255_point_double(decaf_255_point_t two_a, const decaf_255_point_t a) DECAF_NONNULL
Double a point.
Point & operator+=(const Point &q) DECAF_NOEXCEPT
Point add.
Definition: point_255.hxx:442
decaf_error_t DECAF_API_VIS decaf_255_point_decode(decaf_255_point_t pt, const uint8_t ser[DECAF_255_SER_BYTES], decaf_bool_t allow_identity) DECAF_WARN_UNUSED DECAF_NONNULL DECAF_NOINLINE
Decode a point from a sequence of bytes.
struct decaf_255_scalar_s decaf_255_scalar_t[1]
Representation of an element of the scalar field.
void DECAF_API_VIS decaf_255_point_debugging_pscale(decaf_255_point_t q, const decaf_255_point_t p, const unsigned char factor[DECAF_255_SER_BYTES]) DECAF_NONNULL DECAF_NOINLINE
Projectively scale a point, for debugging purposes.
A fixed-size block.
Definition: secure_buffer.hxx:304
decaf_bool_t DECAF_API_VIS decaf_255_point_eq(const decaf_255_point_t a, const decaf_255_point_t b) DECAF_WARN_UNUSED DECAF_NONNULL DECAF_NOINLINE
Test whether two points are equal.
Point(const Point &q) DECAF_NOEXCEPT
Copy constructor.
Definition: point_255.hxx:293
Point operator*(const Scalar &s) const DECAF_NOEXCEPT
Fixed base scalarmul.
Definition: point_255.hxx:657
A reference to a writable block of data.
Definition: secure_buffer.hxx:264
void DECAF_API_VIS decaf_255_scalar_destroy(decaf_255_scalar_t scalar) DECAF_NONNULL
Securely erase a scalar.
Element of prime-order elliptic curve group.
Definition: point_255.hxx:247
static const int FIELD_MODULUS_TYPE
Residue class of field modulus: p == this mod 2*(this-1)
Definition: point_255.hxx:67
Point non_secret_combo_with_base(const Scalar &s, const Scalar &s_base) DECAF_NOEXCEPT
Double-scalar multiply: this point by the first scalar and base by the second scalar.
Definition: point_255.hxx:509
static const int EDDSA_DECODE_RATIO
Ratio due to EdDSA decoding.
Definition: point_255.hxx:268
void set_to_hash(const Block &s) DECAF_NOEXCEPT
Map to the curve from a hash buffer.
Definition: point_255.hxx:407
void DECAF_API_VIS decaf_255_base_double_scalarmul_non_secret(decaf_255_point_t combo, const decaf_255_scalar_t scalar1, const decaf_255_point_t base2, const decaf_255_scalar_t scalar2) DECAF_NONNULL DECAF_NOINLINE
Multiply two base points by two scalars: scaled = scalar1*decaf_255_point_base + scalar2*base2.
static const int EDDSA_ENCODE_RATIO
Ratio due to EdDSA encoding.
Definition: point_255.hxx:265
Curve25519/Decaf instantiation of group.
Definition: point_255.hxx:55
Base class of objects which support serialization.
Definition: secure_buffer.hxx:89
Scalar & operator/=(const Scalar &q)
Set this to this/q.
Definition: point_255.hxx:211
Point times_two() const DECAF_NOEXCEPT
Double the point out of place.
Definition: point_255.hxx:454
struct decaf_255_point_s decaf_255_point_t[1]
Representation of a point on the elliptic curve.
Point debugging_torque() const DECAF_NOEXCEPT
Return a point equal to *this, whose internal data is rotated by a torsion element.
Definition: point_255.hxx:514
Scalar & operator=(uint64_t w) DECAF_NOEXCEPT
Assign from unsigned 64-bit integer.
Definition: point_255.hxx:133
decaf_error_t DECAF_WARN_UNUSED inverse_noexcept(Scalar &r) const DECAF_NOEXCEPT
Invert with Fermat's Little Theorem (slow!).
Definition: point_255.hxx:203
decaf_bool_t DECAF_API_VIS decaf_255_scalar_eq(const decaf_255_scalar_t a, const decaf_255_scalar_t b) DECAF_WARN_UNUSED DECAF_NONNULL DECAF_NOINLINE
Compare two scalars.
const unsigned char * data() const DECAF_NOEXCEPT
Get const data.
Definition: secure_buffer.hxx:193
void DECAF_API_VIS decaf_255_point_destroy(decaf_255_point_t point) DECAF_NONNULL
Securely erase a point by overwriting it with zeros.
SecureBuffer mul_by_ratio_and_encode_like_ladder() const
Multiply by LADDER_ENCODE_RATIO and encode like X25519/X448.
Definition: point_255.hxx:380
Point operator+(const Point &q) const DECAF_NOEXCEPT
Point add.
Definition: point_255.hxx:439
Point & double_in_place() DECAF_NOEXCEPT
Double the point in place.
Definition: point_255.hxx:457
#define DECAF_X25519_PRIVATE_BYTES
Number of bytes in an x25519 private key.
Definition: point_255.h:65
void DECAF_API_VIS decaf_255_scalar_mul(decaf_255_scalar_t out, const decaf_255_scalar_t a, const decaf_255_scalar_t b) DECAF_NONNULL DECAF_NOINLINE
Multiply two scalars.
void DECAF_API_VIS decaf_255_point_debugging_torque(decaf_255_point_t q, const decaf_255_point_t p) DECAF_NONNULL DECAF_NOINLINE
Torque a point, for debugging purposes.
void DECAF_API_VIS decaf_255_point_scalarmul(decaf_255_point_t scaled, const decaf_255_point_t base, const decaf_255_scalar_t scalar) DECAF_NONNULL DECAF_NOINLINE
Multiply a base point by a scalar: scaled = scalar*base.
Point & operator*=(const Scalar &s) DECAF_NOEXCEPT
Scalar multiply in place.
Definition: point_255.hxx:469
Scalar & operator=(const Block &bl) DECAF_NOEXCEPT
Assign from arbitrary-length little-endian byte sequence in a Block.
Definition: point_255.hxx:154
void DECAF_API_VIS decaf_255_point_add(decaf_255_point_t sum, const decaf_255_point_t a, const decaf_255_point_t b) DECAF_NONNULL
Add two points to produce a third point.
Scalar(Rng &rng) DECAF_NOEXCEPT
Construct from RNG.
Definition: point_255.hxx:107
An exception for when crypto (ie point decode) has failed.
Definition: secure_buffer.hxx:126
void DECAF_API_VIS decaf_255_scalar_sub(decaf_255_scalar_t out, const decaf_255_scalar_t a, const decaf_255_scalar_t b) DECAF_NONNULL DECAF_NOINLINE
Subtract two scalars.
static const Point base() DECAF_NOEXCEPT
Return the base point of the curve.
Definition: point_255.hxx:574
Scalar(const Block &buffer) DECAF_NOEXCEPT
Construct from arbitrary-length little-endian byte sequence.
Definition: point_255.hxx:119
Scalar(int w) DECAF_NOEXCEPT
Set to a signed word.
Definition: point_255.hxx:104
void DECAF_API_VIS decaf_255_point_mul_by_ratio_and_encode_like_eddsa(uint8_t enc[DECAF_EDDSA_25519_PUBLIC_BYTES], const decaf_255_point_t p) DECAF_NONNULL DECAF_NOINLINE
EdDSA point encoding.
~Scalar() DECAF_NOEXCEPT
Destructor securely zeorizes the scalar.
Definition: point_255.hxx:151
static const size_t HASH_BYTES
Bytes required for hash.
Definition: point_255.hxx:256
static const size_t SER_BYTES
Size of a serialized element.
Definition: point_255.hxx:84
static const unsigned int INVERT_ELLIGATOR_WHICH_BITS
Number of bits in invert_elligator which are actually used.
Definition: point_255.hxx:279
const DECAF_API_VIS decaf_255_point_t decaf_255_point_identity
The identity (zero) point on the curve.
#define DECAF_X25519_ENCODE_RATIO
X25519 encoding ratio.
Definition: point_255.h:59
void DECAF_API_VIS decaf_255_scalar_encode(unsigned char ser[DECAF_255_SCALAR_BYTES], const decaf_255_scalar_t s) DECAF_NONNULL DECAF_NOINLINE DECAF_NOINLINE
Serialize a scalar to wire format.
#define DECAF_255_EDDSA_ENCODE_RATIO
EdDSA encoding ratio.
Definition: ed255.h:59
decaf_error_t DECAF_API_VIS decaf_x25519(uint8_t shared[DECAF_X25519_PUBLIC_BYTES], const uint8_t base[DECAF_X25519_PUBLIC_BYTES], const uint8_t scalar[DECAF_X25519_PRIVATE_BYTES]) DECAF_NONNULL DECAF_WARN_UNUSED DECAF_NOINLINE
RFC 7748 Diffie-Hellman scalarmul, used to compute shared secrets.
const DECAF_API_VIS decaf_255_point_t decaf_255_point_base
An arbitrarily-chosen base point on the curve.
void DECAF_API_VIS decaf_255_scalar_halve(decaf_255_scalar_t out, const decaf_255_scalar_t a) DECAF_NONNULL DECAF_NOINLINE
Halve a scalar.
An exception for when crypto (ie point decode) has failed.
Definition: secure_buffer.hxx:119
~Precomputed() DECAF_NOEXCEPT
Destructor securely zeorizes the memory.
Definition: point_255.hxx:598
Point(const FixedBlock< SER_BYTES > &buffer, bool allow_identity=true)
Initialize from a fixed-length byte string.
Definition: point_255.hxx:319
static const size_t LADDER_BYTES
Bytes required for EdDSA encoding.
Definition: point_255.hxx:262
decaf_error_t DECAF_API_VIS decaf_255_direct_scalarmul(uint8_t scaled[DECAF_255_SER_BYTES], const uint8_t base[DECAF_255_SER_BYTES], const decaf_255_scalar_t scalar, decaf_bool_t allow_identity, decaf_bool_t short_circuit) DECAF_NONNULL DECAF_WARN_UNUSED DECAF_NOINLINE
Multiply a base point by a scalar: scaled = scalar*base.
Scalar(uint64_t w) DECAF_NOEXCEPT
Set to an unsigned word.
Definition: point_255.hxx:95
Point(const Wrapped &q=decaf_255_point_identity) DECAF_NOEXCEPT
Constructor sets to identity by default.
Definition: point_255.hxx:290
size_t ser_size() const DECAF_NOEXCEPT
Serializable instance.
Definition: point_255.hxx:431
DECAF_API_VIS const struct decaf_255_precomputed_s * decaf_255_precomputed_base
Precomputed table of multiples of the base point on the curve.