6#ifndef SECP256K1_MODULE_ELLSWIFT_MAIN_H
7#define SECP256K1_MODULE_ELLSWIFT_MAIN_H
9#include "../../../include/secp256k1.h"
10#include "../../../include/secp256k1_ellswift.h"
11#include "../../eckey.h"
12#include "../../hash.h"
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;
408 unsigned char p64[64] = {0};
431 memset(ell64, 0, 64);
438 hash->
s[0] = 0xd29e1bf5ul;
439 hash->
s[1] = 0xf7025f42ul;
440 hash->
s[2] = 0x9b024773ul;
441 hash->
s[3] = 0x094cb7d5ul;
442 hash->
s[4] = 0xe59ed789ul;
443 hash->
s[5] = 0x03bc9786ul;
444 hash->
s[6] = 0x68335b35ul;
445 hash->
s[7] = 0x4e363b53ul;
456 static const unsigned char zero32[32] = {0};
461 memset(ell64, 0, 64);
521 hash->
s[0] = 0x8c12d730ul;
522 hash->
s[1] = 0x827bd392ul;
523 hash->
s[2] = 0x9e4fb2eeul;
524 hash->
s[3] = 0x207b373eul;
525 hash->
s[4] = 0x2292bd7aul;
526 hash->
s[5] = 0xaa5441bcul;
527 hash->
s[6] = 0x15c3779ful;
528 hash->
s[7] = 0xcfb52549ul;
556 unsigned char sx[32];
557 const unsigned char* theirs64;
567 theirs64 = party ? ell_a64 : ell_b64;
583 ret = hashfp(output, sx, ell_a64, ell_b64,
data);
589 return !!
ret & !overflow;
static int secp256k1_eckey_pubkey_serialize(secp256k1_ge *elem, unsigned char *pub, size_t *size, int compressed)
static int secp256k1_ecmult_const_xonly(secp256k1_fe *r, const secp256k1_fe *n, const secp256k1_fe *d, const secp256k1_scalar *q, int known_on_curve)
Same as secp256k1_ecmult_const, but takes in an x coordinate of the base point only,...
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.
const secp256k1_ellswift_xdh_hash_function secp256k1_ellswift_xdh_hash_function_prefix
int secp256k1_ellswift_create(const secp256k1_context *ctx, unsigned char *ell64, const unsigned char *seckey32, const unsigned char *auxrnd32)
Compute an ElligatorSwift public key for a secret key.
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)
Given a private key, and ElligatorSwift public keys sent in both directions, compute a shared secret ...
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)
const secp256k1_ellswift_xdh_hash_function secp256k1_ellswift_xdh_hash_function_bip324
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).
int secp256k1_ellswift_encode(const secp256k1_context *ctx, unsigned char *ell64, const secp256k1_pubkey *pubkey, const unsigned char *rnd32)
Construct a 64-byte ElligatorSwift encoding of a given pubkey.
int secp256k1_ellswift_decode(const secp256k1_context *ctx, secp256k1_pubkey *pubkey, const unsigned char *ell64)
Decode a 64-bytes ElligatorSwift encoded public key.
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
static void secp256k1_fe_clear(secp256k1_fe *a)
Clear a field element to prevent leaking sensitive information.
#define secp256k1_fe_normalize_weak
#define secp256k1_fe_is_odd
static const secp256k1_fe secp256k1_fe_one
static int secp256k1_fe_sqrt(secp256k1_fe *SECP256K1_RESTRICT r, const secp256k1_fe *SECP256K1_RESTRICT a)
Compute a square root of a field element.
#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_set_xo_var(secp256k1_ge *r, const secp256k1_fe *x, int odd)
Set a group element (affine) equal to the point with the given X coordinate, and given oddness for Y.
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_scalar_cmov(secp256k1_scalar *r, const secp256k1_scalar *a, int flag)
If flag is true, set *r equal to *a; otherwise leave it.
static void secp256k1_scalar_set_b32(secp256k1_scalar *r, const unsigned char *bin, int *overflow)
Set a scalar from a big endian byte array.
static int secp256k1_scalar_is_zero(const secp256k1_scalar *a)
Check whether a scalar equals zero.
static void secp256k1_scalar_clear(secp256k1_scalar *r)
Clear a scalar to prevent the leak of sensitive data.
static const secp256k1_scalar secp256k1_scalar_one
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(void *ptr, size_t len)
#define VERIFY_CHECK(cond)
static SECP256K1_INLINE void secp256k1_memczero(void *s, size_t len, int flag)
static int secp256k1_ec_pubkey_create_helper(const secp256k1_ecmult_gen_context *ecmult_gen_ctx, secp256k1_scalar *seckey_scalar, secp256k1_ge *p, const unsigned char *seckey)
static SECP256K1_INLINE void secp256k1_declassify(const secp256k1_context *ctx, const void *p, size_t len)
static int secp256k1_pubkey_load(const secp256k1_context *ctx, secp256k1_ge *ge, const secp256k1_pubkey *pubkey)
static void secp256k1_pubkey_save(secp256k1_pubkey *pubkey, secp256k1_ge *ge)
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_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.