1 #ifndef _SECP256K1_NUM_
2 #define _SECP256K1_NUM_
4 #if defined(USE_NUM_GMPN)
6 #elif defined(USE_NUM_GMP)
8 #elif defined(USE_NUM_OPENSSL)
9 #include "num_openssl.h"
11 #error "Please select num implementation"
14 /** Initialize a number. */
15 void static secp256k1_num_init(secp256k1_num_t *r);
18 void static secp256k1_num_free(secp256k1_num_t *r);
21 void static secp256k1_num_copy(secp256k1_num_t *r, const secp256k1_num_t *a);
23 /** Convert a number's absolute value to a binary big-endian string.
24 * There must be enough place. */
25 void static secp256k1_num_get_bin(unsigned char *r, unsigned int rlen, const secp256k1_num_t *a);
27 /** Set a number to the value of a binary big-endian string. */
28 void static secp256k1_num_set_bin(secp256k1_num_t *r, const unsigned char *a, unsigned int alen);
30 /** Set a number equal to a (signed) integer. */
31 void static secp256k1_num_set_int(secp256k1_num_t *r, int a);
33 /** Compute a modular inverse. The input must be less than the modulus. */
34 void static secp256k1_num_mod_inverse(secp256k1_num_t *r, const secp256k1_num_t *a, const secp256k1_num_t *m);
36 /** Multiply two numbers modulo another. */
37 void static secp256k1_num_mod_mul(secp256k1_num_t *r, const secp256k1_num_t *a, const secp256k1_num_t *b, const secp256k1_num_t *m);
39 /** Compare the absolute value of two numbers. */
40 int static secp256k1_num_cmp(const secp256k1_num_t *a, const secp256k1_num_t *b);
42 /** Add two (signed) numbers. */
43 void static secp256k1_num_add(secp256k1_num_t *r, const secp256k1_num_t *a, const secp256k1_num_t *b);
45 /** Subtract two (signed) numbers. */
46 void static secp256k1_num_sub(secp256k1_num_t *r, const secp256k1_num_t *a, const secp256k1_num_t *b);
48 /** Multiply two (signed) numbers. */
49 void static secp256k1_num_mul(secp256k1_num_t *r, const secp256k1_num_t *a, const secp256k1_num_t *b);
51 /** Divide two (signed) numbers. */
52 void static secp256k1_num_div(secp256k1_num_t *r, const secp256k1_num_t *a, const secp256k1_num_t *b);
54 /** Replace a number by its modulus. */
55 void static secp256k1_num_mod(secp256k1_num_t *r, const secp256k1_num_t *m);
57 /** Calculate the number of bits in (the absolute value of) a number. */
58 int static secp256k1_num_bits(const secp256k1_num_t *a);
60 /** Right-shift the passed number by bits bits, and return those bits. */
61 int static secp256k1_num_shift(secp256k1_num_t *r, int bits);
63 /** Check whether a number is zero. */
64 int static secp256k1_num_is_zero(const secp256k1_num_t *a);
66 /** Check whether a number is odd. */
67 int static secp256k1_num_is_odd(const secp256k1_num_t *a);
69 /** Check whether a number is strictly negative. */
70 int static secp256k1_num_is_neg(const secp256k1_num_t *a);
72 /** Check whether a particular bit is set in a number. */
73 int static secp256k1_num_get_bit(const secp256k1_num_t *a, int pos);
75 /** Increase a number by 1. */
76 void static secp256k1_num_inc(secp256k1_num_t *r);
78 /** Set a number equal to the value of a hex string (unsigned). */
79 void static secp256k1_num_set_hex(secp256k1_num_t *r, const char *a, int alen);
81 /** Convert (the absolute value of) a number to a hexadecimal string. */
82 void static secp256k1_num_get_hex(char *r, int rlen, const secp256k1_num_t *a);
84 /** Split a number into a low and high part. */
85 void static secp256k1_num_split(secp256k1_num_t *rl, secp256k1_num_t *rh, const secp256k1_num_t *a, int bits);
87 /** Change a number's sign. */
88 void static secp256k1_num_negate(secp256k1_num_t *r);