2020-12-29 17:15:51 +00:00
|
|
|
/***********************************************************************
|
|
|
|
* Copyright (c) 2013, 2014 Pieter Wuille *
|
|
|
|
* Distributed under the MIT software license, see the accompanying *
|
|
|
|
* file COPYING or https://www.opensource.org/licenses/mit-license.php.*
|
|
|
|
***********************************************************************/
|
2015-10-26 14:54:21 +00:00
|
|
|
|
2018-07-09 11:17:44 +00:00
|
|
|
#ifndef SECP256K1_NUM_H
|
|
|
|
#define SECP256K1_NUM_H
|
2015-10-26 14:54:21 +00:00
|
|
|
|
|
|
|
#ifndef USE_NUM_NONE
|
|
|
|
|
|
|
|
#if defined HAVE_CONFIG_H
|
|
|
|
#include "libsecp256k1-config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(USE_NUM_GMP)
|
|
|
|
#include "num_gmp.h"
|
|
|
|
#else
|
|
|
|
#error "Please select num implementation"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/** Copy a number. */
|
2020-12-29 17:15:51 +00:00
|
|
|
static void rustsecp256k1_v0_4_0_num_copy(rustsecp256k1_v0_4_0_num *r, const rustsecp256k1_v0_4_0_num *a);
|
2015-10-26 14:54:21 +00:00
|
|
|
|
|
|
|
/** Convert a number's absolute value to a binary big-endian string.
|
|
|
|
* There must be enough place. */
|
2020-12-29 17:15:51 +00:00
|
|
|
static void rustsecp256k1_v0_4_0_num_get_bin(unsigned char *r, unsigned int rlen, const rustsecp256k1_v0_4_0_num *a);
|
2015-10-26 14:54:21 +00:00
|
|
|
|
|
|
|
/** Set a number to the value of a binary big-endian string. */
|
2020-12-29 17:15:51 +00:00
|
|
|
static void rustsecp256k1_v0_4_0_num_set_bin(rustsecp256k1_v0_4_0_num *r, const unsigned char *a, unsigned int alen);
|
2015-10-26 14:54:21 +00:00
|
|
|
|
|
|
|
/** Compute a modular inverse. The input must be less than the modulus. */
|
2020-12-29 17:15:51 +00:00
|
|
|
static void rustsecp256k1_v0_4_0_num_mod_inverse(rustsecp256k1_v0_4_0_num *r, const rustsecp256k1_v0_4_0_num *a, const rustsecp256k1_v0_4_0_num *m);
|
2015-10-26 14:54:21 +00:00
|
|
|
|
2018-07-09 11:17:44 +00:00
|
|
|
/** Compute the jacobi symbol (a|b). b must be positive and odd. */
|
2020-12-29 17:15:51 +00:00
|
|
|
static int rustsecp256k1_v0_4_0_num_jacobi(const rustsecp256k1_v0_4_0_num *a, const rustsecp256k1_v0_4_0_num *b);
|
2018-07-09 11:17:44 +00:00
|
|
|
|
2015-10-26 14:54:21 +00:00
|
|
|
/** Compare the absolute value of two numbers. */
|
2020-12-29 17:15:51 +00:00
|
|
|
static int rustsecp256k1_v0_4_0_num_cmp(const rustsecp256k1_v0_4_0_num *a, const rustsecp256k1_v0_4_0_num *b);
|
2015-10-26 14:54:21 +00:00
|
|
|
|
|
|
|
/** Test whether two number are equal (including sign). */
|
2020-12-29 17:15:51 +00:00
|
|
|
static int rustsecp256k1_v0_4_0_num_eq(const rustsecp256k1_v0_4_0_num *a, const rustsecp256k1_v0_4_0_num *b);
|
2015-10-26 14:54:21 +00:00
|
|
|
|
|
|
|
/** Add two (signed) numbers. */
|
2020-12-29 17:15:51 +00:00
|
|
|
static void rustsecp256k1_v0_4_0_num_add(rustsecp256k1_v0_4_0_num *r, const rustsecp256k1_v0_4_0_num *a, const rustsecp256k1_v0_4_0_num *b);
|
2015-10-26 14:54:21 +00:00
|
|
|
|
|
|
|
/** Subtract two (signed) numbers. */
|
2020-12-29 17:15:51 +00:00
|
|
|
static void rustsecp256k1_v0_4_0_num_sub(rustsecp256k1_v0_4_0_num *r, const rustsecp256k1_v0_4_0_num *a, const rustsecp256k1_v0_4_0_num *b);
|
2015-10-26 14:54:21 +00:00
|
|
|
|
|
|
|
/** Multiply two (signed) numbers. */
|
2020-12-29 17:15:51 +00:00
|
|
|
static void rustsecp256k1_v0_4_0_num_mul(rustsecp256k1_v0_4_0_num *r, const rustsecp256k1_v0_4_0_num *a, const rustsecp256k1_v0_4_0_num *b);
|
2015-10-26 14:54:21 +00:00
|
|
|
|
|
|
|
/** Replace a number by its remainder modulo m. M's sign is ignored. The result is a number between 0 and m-1,
|
|
|
|
even if r was negative. */
|
2020-12-29 17:15:51 +00:00
|
|
|
static void rustsecp256k1_v0_4_0_num_mod(rustsecp256k1_v0_4_0_num *r, const rustsecp256k1_v0_4_0_num *m);
|
2015-10-26 14:54:21 +00:00
|
|
|
|
|
|
|
/** Right-shift the passed number by bits bits. */
|
2020-12-29 17:15:51 +00:00
|
|
|
static void rustsecp256k1_v0_4_0_num_shift(rustsecp256k1_v0_4_0_num *r, int bits);
|
2015-10-26 14:54:21 +00:00
|
|
|
|
|
|
|
/** Check whether a number is zero. */
|
2020-12-29 17:15:51 +00:00
|
|
|
static int rustsecp256k1_v0_4_0_num_is_zero(const rustsecp256k1_v0_4_0_num *a);
|
2015-10-26 14:54:21 +00:00
|
|
|
|
2018-07-09 11:17:44 +00:00
|
|
|
/** Check whether a number is one. */
|
2020-12-29 17:15:51 +00:00
|
|
|
static int rustsecp256k1_v0_4_0_num_is_one(const rustsecp256k1_v0_4_0_num *a);
|
2018-07-09 11:17:44 +00:00
|
|
|
|
2015-10-26 14:54:21 +00:00
|
|
|
/** Check whether a number is strictly negative. */
|
2020-12-29 17:15:51 +00:00
|
|
|
static int rustsecp256k1_v0_4_0_num_is_neg(const rustsecp256k1_v0_4_0_num *a);
|
2015-10-26 14:54:21 +00:00
|
|
|
|
|
|
|
/** Change a number's sign. */
|
2020-12-29 17:15:51 +00:00
|
|
|
static void rustsecp256k1_v0_4_0_num_negate(rustsecp256k1_v0_4_0_num *r);
|
2015-10-26 14:54:21 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2018-07-09 11:17:44 +00:00
|
|
|
#endif /* SECP256K1_NUM_H */
|