6#ifndef SECP256K1_MODULE_ELLSWIFT_MAIN_H
7#define SECP256K1_MODULE_ELLSWIFT_MAIN_H
269 ret = secp256k1_fe_sqrt(&r, &q);
290 ret = secp256k1_fe_sqrt(&
m, &s);
294 if ((c & 5) == 0 || (c & 5) == 5) {
312 unsigned char buf4[4];
314 size_t blocks = hash.
bytes >> 6;
335 unsigned char branch_hash[32];
337 int branches_left = 0;
348 if (branches_left == 0) {
354 branch = (branch_hash[branches_left >> 1] >> ((branches_left & 1) << 2)) & 7;
387 hash->
s[0] = 0xd1a6524bul;
388 hash->
s[1] = 0x028594b3ul;
389 hash->
s[2] = 0x96e42f4eul;
390 hash->
s[3] = 0x1037a177ul;
391 hash->
s[4] = 0x1b8fcb8bul;
392 hash->
s[5] = 0x56023885ul;
393 hash->
s[6] = 0x2560ede1ul;
394 hash->
s[7] = 0xd626b715ul;
406 if (secp256k1_pubkey_load(ctx, &p, pubkey)) {
408 unsigned char p64[64] = {0};
424 memset(ell64, 0, 64);
431 hash->
s[0] = 0xd29e1bf5ul;
432 hash->
s[1] = 0xf7025f42ul;
433 hash->
s[2] = 0x9b024773ul;
434 hash->
s[3] = 0x094cb7d5ul;
435 hash->
s[4] = 0xe59ed789ul;
436 hash->
s[5] = 0x03bc9786ul;
437 hash->
s[6] = 0x68335b35ul;
438 hash->
s[7] = 0x4e363b53ul;
449 static const unsigned char zero32[32] = {0};
454 memset(ell64, 0, 64);
459 ret = secp256k1_ec_pubkey_create_helper(&ctx->
ecmult_gen_ctx, &seckey_scalar, &p, seckey32);
460 secp256k1_declassify(ctx, &p,
sizeof(p));
469 secp256k1_declassify(ctx, &hash,
sizeof(hash));
477 secp256k1_scalar_clear(&seckey_scalar);
493 secp256k1_pubkey_save(pubkey, &p);
514 hash->
s[0] = 0x8c12d730ul;
515 hash->
s[1] = 0x827bd392ul;
516 hash->
s[2] = 0x9e4fb2eeul;
517 hash->
s[3] = 0x207b373eul;
518 hash->
s[4] = 0x2292bd7aul;
519 hash->
s[5] = 0xaa5441bcul;
520 hash->
s[6] = 0x15c3779ful;
521 hash->
s[7] = 0xcfb52549ul;
549 unsigned char sx[32];
550 const unsigned char* theirs64;
560 theirs64 = party ? ell_a64 : ell_b64;
566 secp256k1_scalar_set_b32(&s, seckey32, &overflow);
567 overflow = secp256k1_scalar_is_zero(&s);
568 secp256k1_scalar_cmov(&s, &secp256k1_scalar_one, overflow);
571 secp256k1_ecmult_const_xonly(&px, &xn, &xd, &s, 1);
576 ret = hashfp(output, sx, ell_a64, ell_b64, data);
579 secp256k1_fe_clear(&px);
580 secp256k1_scalar_clear(&s);
582 return !!
ret & !overflow;
static void secp256k1_eckey_pubkey_serialize33(secp256k1_ge *elem, unsigned char *pub33)
Serialize a group element (that is not allowed to be infinity) to a compressed public key (33 bytes).
static int secp256k1_ecmult_gen_context_is_built(const secp256k1_ecmult_gen_context *ctx)
static void secp256k1_ellswift_swiftec_var(secp256k1_ge *p, const secp256k1_fe *u, const secp256k1_fe *t)
Decode ElligatorSwift encoding (u, t) to point P.
static const secp256k1_fe secp256k1_ellswift_c3
c3 = (-sqrt(-3)+1)/2 = -c1 = c2+1
static const secp256k1_fe secp256k1_ellswift_c4
c4 = (sqrt(-3)+1)/2 = -c2 = c1+1
static void secp256k1_ellswift_xswiftec_var(secp256k1_fe *x, const secp256k1_fe *u, const secp256k1_fe *t)
Decode ElligatorSwift encoding (u, t) to X coordinate.
static void secp256k1_ellswift_sha256_init_create(secp256k1_sha256 *hash)
Set hash state to the BIP340 tagged hash midstate for "secp256k1_ellswift_create".
static const secp256k1_fe secp256k1_ellswift_c2
c2 = (-sqrt(-3)-1)/2 = -(c1+1)
static void secp256k1_ellswift_xelligatorswift_var(unsigned char *u32, secp256k1_fe *t, const secp256k1_fe *x, const secp256k1_sha256 *hasher)
Find an ElligatorSwift encoding (u, t) for X coordinate x, and random Y coordinate.
static int ellswift_xdh_hash_function_prefix(unsigned char *output, const unsigned char *x32, const unsigned char *ell_a64, const unsigned char *ell_b64, void *data)
static void secp256k1_ellswift_xswiftec_frac_var(secp256k1_fe *xn, secp256k1_fe *xd, const secp256k1_fe *u, const secp256k1_fe *t)
Decode ElligatorSwift encoding (u, t) to a fraction xn/xd representing a curve X coordinate.
static void secp256k1_ellswift_elligatorswift_var(unsigned char *u32, secp256k1_fe *t, const secp256k1_ge *p, const secp256k1_sha256 *hasher)
Find an ElligatorSwift encoding (u, t) for point P.
static int secp256k1_ellswift_xswiftec_inv_var(secp256k1_fe *t, const secp256k1_fe *x_in, const secp256k1_fe *u_in, int c)
static void secp256k1_ellswift_sha256_init_bip324(secp256k1_sha256 *hash)
Set hash state to the BIP340 tagged hash midstate for "bip324_ellswift_xonly_ecdh".
static int ellswift_xdh_hash_function_bip324(unsigned char *output, const unsigned char *x32, const unsigned char *ell_a64, const unsigned char *ell_b64, void *data)
static void secp256k1_ellswift_sha256_init_encode(secp256k1_sha256 *hash)
Set hash state to the BIP340 tagged hash midstate for "secp256k1_ellswift_encode".
static void secp256k1_ellswift_prng(unsigned char *out32, const secp256k1_sha256 *hasher, uint32_t cnt)
Use SHA256 as a PRNG, returning SHA256(hasher || cnt).
static const secp256k1_fe secp256k1_ellswift_c1
c1 = (sqrt(-3)-1)/2
#define secp256k1_fe_negate(r, a, m)
Negate a field element.
#define secp256k1_fe_mul_int(r, a)
Multiply a field element with a small integer.
#define secp256k1_fe_normalizes_to_zero_var
#define secp256k1_fe_normalize_weak
#define secp256k1_fe_is_odd
#define secp256k1_fe_normalize_var
#define secp256k1_fe_half
#define SECP256K1_FE_CONST(d7, d6, d5, d4, d3, d2, d1, d0)
This expands to an initializer for a secp256k1_fe valued sum((i*32) * d_i, i=0..7) mod p.
#define secp256k1_fe_inv_var
#define secp256k1_fe_is_square_var
#define secp256k1_fe_set_b32_mod
#define secp256k1_fe_get_b32
#define secp256k1_fe_normalize
#define secp256k1_fe_add_int
static int secp256k1_ge_x_on_curve_var(const secp256k1_fe *x)
Determine whether x is a valid X coordinate on the curve.
static int secp256k1_ge_x_frac_on_curve_var(const secp256k1_fe *xn, const secp256k1_fe *xd)
Determine whether fraction xn/xd is a valid X coordinate on the curve (xd != 0).
static void secp256k1_sha256_initialize(secp256k1_sha256 *hash)
static void secp256k1_sha256_finalize(secp256k1_sha256 *hash, unsigned char *out32)
static void secp256k1_sha256_write(secp256k1_sha256 *hash, const unsigned char *data, size_t size)
static void secp256k1_sha256_clear(secp256k1_sha256 *hash)
static SECP256K1_INLINE void secp256k1_memclear_explicit(void *ptr, size_t len)
#define VERIFY_CHECK(cond)
static SECP256K1_INLINE void secp256k1_memczero(void *s, size_t len, int flag)
struct secp256k1_context_struct secp256k1_context
Unless explicitly stated all pointer arguments must not be NULL.
SECP256K1_API const secp256k1_ellswift_xdh_hash_function secp256k1_ellswift_xdh_hash_function_prefix
An implementation of an secp256k1_ellswift_xdh_hash_function which uses SHA256(prefix64 || ell_a64 ||...
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ellswift_create(const secp256k1_context *ctx, unsigned char *ell64, const unsigned char *seckey32, const unsigned char *auxrnd32) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3)
Compute an ElligatorSwift public key for a secret key.
SECP256K1_API int secp256k1_ellswift_decode(const secp256k1_context *ctx, secp256k1_pubkey *pubkey, const unsigned char *ell64) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3)
Decode a 64-bytes ElligatorSwift encoded public key.
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ellswift_xdh(const secp256k1_context *ctx, unsigned char *output, const unsigned char *ell_a64, const unsigned char *ell_b64, const unsigned char *seckey32, int party, secp256k1_ellswift_xdh_hash_function hashfp, void *data) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4) SECP256K1_ARG_NONNULL(5) SECP256K1_ARG_NONNULL(7)
Given a private key, and ElligatorSwift public keys sent in both directions, compute a shared secret ...
int(*) secp256k1_ellswift_xdh_hash_function(unsigned char *output, const unsigned char *x32, const unsigned char *ell_a64, const unsigned char *ell_b64, void *data)
A pointer to a function used by secp256k1_ellswift_xdh to hash the shared X coordinate along with the...
SECP256K1_API const secp256k1_ellswift_xdh_hash_function secp256k1_ellswift_xdh_hash_function_bip324
An implementation of an secp256k1_ellswift_xdh_hash_function compatible with BIP324.
SECP256K1_API int secp256k1_ellswift_encode(const secp256k1_context *ctx, unsigned char *ell64, const secp256k1_pubkey *pubkey, const unsigned char *rnd32) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4)
Construct a 64-byte ElligatorSwift encoding of a given pubkey.
secp256k1_ecmult_gen_context ecmult_gen_ctx
This field implementation represents the value as 10 uint32_t limbs in base 2^26.
A group element in affine coordinates on the secp256k1 curve, or occasionally on an isomorphic curve ...
Opaque data structure that holds a parsed and valid public key.
A scalar modulo the group order of the secp256k1 curve.