]> Git Repo - secp256k1.git/blob - src/num.h
Builtin random
[secp256k1.git] / src / num.h
1 #ifndef _SECP256K1_NUM_
2 #define _SECP256K1_NUM_
3
4 #if defined(USE_NUM_GMPN)
5 #include "num_gmpn.h"
6 #elif defined(USE_NUM_GMP)
7 #include "num_gmp.h"
8 #elif defined(USE_NUM_OPENSSL)
9 #include "num_openssl.h"
10 #else
11 #error "Please select num implementation"
12 #endif
13
14 /** Initialize a number. */
15 void static secp256k1_num_init(secp256k1_num_t *r);
16
17 /** Free a number. */
18 void static secp256k1_num_free(secp256k1_num_t *r);
19
20 /** Copy a number. */
21 void static secp256k1_num_copy(secp256k1_num_t *r, const secp256k1_num_t *a);
22
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);
26
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);
29
30 /** Set a number equal to a (signed) integer. */
31 void static secp256k1_num_set_int(secp256k1_num_t *r, int a);
32
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);
35
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);
38
39 /** Compare the absolute value of two numbers. */
40 int  static secp256k1_num_cmp(const secp256k1_num_t *a, const secp256k1_num_t *b);
41
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);
44
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);
47
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);
50
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);
53
54 /** Replace a number by its modulus. */
55 void static secp256k1_num_mod(secp256k1_num_t *r, const secp256k1_num_t *m);
56
57 /** Calculate the number of bits in (the absolute value of) a number. */
58 int  static secp256k1_num_bits(const secp256k1_num_t *a);
59
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);
62
63 /** Check whether a number is zero. */
64 int  static secp256k1_num_is_zero(const secp256k1_num_t *a);
65
66 /** Check whether a number is odd. */
67 int  static secp256k1_num_is_odd(const secp256k1_num_t *a);
68
69 /** Check whether a number is strictly negative. */
70 int  static secp256k1_num_is_neg(const secp256k1_num_t *a);
71
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);
74
75 /** Increase a number by 1. */
76 void static secp256k1_num_inc(secp256k1_num_t *r);
77
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);
80
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);
83
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);
86
87 /** Change a number's sign. */
88 void static secp256k1_num_negate(secp256k1_num_t *r);
89
90 #endif
This page took 0.029202 seconds and 4 git commands to generate.