Mercurial > dropbear
annotate libtommath/tommath_private.h @ 1584:cdfab509c392
use random keyblob from the fuzzer instead
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Sun, 04 Mar 2018 19:19:45 +0800 |
parents | 8bba51a55704 |
children | f52919ffd3b1 |
rev | line source |
---|---|
1436 | 1 /* LibTomMath, multiple-precision integer library -- Tom St Denis |
2 * | |
3 * LibTomMath is a library that provides multiple-precision | |
4 * integer arithmetic as well as number theoretic functionality. | |
5 * | |
6 * The library was designed directly after the MPI library by | |
7 * Michael Fromberger but has been written from scratch with | |
8 * additional optimizations in place. | |
9 * | |
10 * The library is free for all purposes without any express | |
11 * guarantee it works. | |
12 * | |
13 * Tom St Denis, [email protected], http://math.libtomcrypt.com | |
14 */ | |
15 #ifndef TOMMATH_PRIV_H_ | |
16 #define TOMMATH_PRIV_H_ | |
17 | |
18 #include <tommath.h> | |
19 #include <ctype.h> | |
20 | |
1470
8bba51a55704
Update to libtommath v1.0.1
Matt Johnston <matt@ucc.asn.au>
parents:
1436
diff
changeset
|
21 #ifndef MIN |
8bba51a55704
Update to libtommath v1.0.1
Matt Johnston <matt@ucc.asn.au>
parents:
1436
diff
changeset
|
22 #define MIN(x,y) (((x) < (y)) ? (x) : (y)) |
8bba51a55704
Update to libtommath v1.0.1
Matt Johnston <matt@ucc.asn.au>
parents:
1436
diff
changeset
|
23 #endif |
1436 | 24 |
1470
8bba51a55704
Update to libtommath v1.0.1
Matt Johnston <matt@ucc.asn.au>
parents:
1436
diff
changeset
|
25 #ifndef MAX |
8bba51a55704
Update to libtommath v1.0.1
Matt Johnston <matt@ucc.asn.au>
parents:
1436
diff
changeset
|
26 #define MAX(x,y) (((x) > (y)) ? (x) : (y)) |
8bba51a55704
Update to libtommath v1.0.1
Matt Johnston <matt@ucc.asn.au>
parents:
1436
diff
changeset
|
27 #endif |
1436 | 28 |
29 #ifdef __cplusplus | |
30 extern "C" { | |
31 | |
32 /* C++ compilers don't like assigning void * to mp_digit * */ | |
33 #define OPT_CAST(x) (x *) | |
34 | |
35 #else | |
36 | |
37 /* C on the other hand doesn't care */ | |
38 #define OPT_CAST(x) | |
39 | |
40 #endif | |
41 | |
42 /* define heap macros */ | |
43 #ifndef XMALLOC | |
44 /* default to libc stuff */ | |
45 #define XMALLOC malloc | |
46 #define XFREE free | |
47 #define XREALLOC realloc | |
48 #define XCALLOC calloc | |
49 #else | |
50 /* prototypes for our heap functions */ | |
51 extern void *XMALLOC(size_t n); | |
52 extern void *XREALLOC(void *p, size_t n); | |
53 extern void *XCALLOC(size_t n, size_t s); | |
54 extern void XFREE(void *p); | |
55 #endif | |
56 | |
57 /* lowlevel functions, do not call! */ | |
58 int s_mp_add(mp_int *a, mp_int *b, mp_int *c); | |
59 int s_mp_sub(mp_int *a, mp_int *b, mp_int *c); | |
60 #define s_mp_mul(a, b, c) s_mp_mul_digs(a, b, c, (a)->used + (b)->used + 1) | |
61 int fast_s_mp_mul_digs(mp_int *a, mp_int *b, mp_int *c, int digs); | |
62 int s_mp_mul_digs(mp_int *a, mp_int *b, mp_int *c, int digs); | |
63 int fast_s_mp_mul_high_digs(mp_int *a, mp_int *b, mp_int *c, int digs); | |
64 int s_mp_mul_high_digs(mp_int *a, mp_int *b, mp_int *c, int digs); | |
65 int fast_s_mp_sqr(mp_int *a, mp_int *b); | |
66 int s_mp_sqr(mp_int *a, mp_int *b); | |
67 int mp_karatsuba_mul(mp_int *a, mp_int *b, mp_int *c); | |
68 int mp_toom_mul(mp_int *a, mp_int *b, mp_int *c); | |
69 int mp_karatsuba_sqr(mp_int *a, mp_int *b); | |
70 int mp_toom_sqr(mp_int *a, mp_int *b); | |
71 int fast_mp_invmod(mp_int *a, mp_int *b, mp_int *c); | |
72 int mp_invmod_slow (mp_int * a, mp_int * b, mp_int * c); | |
73 int fast_mp_montgomery_reduce(mp_int *x, mp_int *n, mp_digit rho); | |
74 int mp_exptmod_fast(mp_int *G, mp_int *X, mp_int *P, mp_int *Y, int redmode); | |
75 int s_mp_exptmod (mp_int * G, mp_int * X, mp_int * P, mp_int * Y, int redmode); | |
76 void bn_reverse(unsigned char *s, int len); | |
77 | |
78 extern const char *mp_s_rmap; | |
79 | |
80 /* Fancy macro to set an MPI from another type. | |
81 * There are several things assumed: | |
82 * x is the counter and unsigned | |
83 * a is the pointer to the MPI | |
84 * b is the original value that should be set in the MPI. | |
85 */ | |
86 #define MP_SET_XLONG(func_name, type) \ | |
87 int func_name (mp_int * a, type b) \ | |
88 { \ | |
89 unsigned int x; \ | |
90 int res; \ | |
91 \ | |
92 mp_zero (a); \ | |
93 \ | |
94 /* set four bits at a time */ \ | |
95 for (x = 0; x < (sizeof(type) * 2u); x++) { \ | |
96 /* shift the number up four bits */ \ | |
97 if ((res = mp_mul_2d (a, 4, a)) != MP_OKAY) { \ | |
98 return res; \ | |
99 } \ | |
100 \ | |
101 /* OR in the top four bits of the source */ \ | |
102 a->dp[0] |= (b >> ((sizeof(type) * 8u) - 4u)) & 15u; \ | |
103 \ | |
104 /* shift the source up to the next four bits */ \ | |
105 b <<= 4; \ | |
106 \ | |
107 /* ensure that digits are not clamped off */ \ | |
108 a->used += 1; \ | |
109 } \ | |
110 mp_clamp (a); \ | |
111 return MP_OKAY; \ | |
112 } | |
113 | |
114 #ifdef __cplusplus | |
115 } | |
116 #endif | |
117 | |
118 #endif | |
119 | |
120 | |
1470
8bba51a55704
Update to libtommath v1.0.1
Matt Johnston <matt@ucc.asn.au>
parents:
1436
diff
changeset
|
121 /* ref: $Format:%D$ */ |
8bba51a55704
Update to libtommath v1.0.1
Matt Johnston <matt@ucc.asn.au>
parents:
1436
diff
changeset
|
122 /* git commit: $Format:%H$ */ |
8bba51a55704
Update to libtommath v1.0.1
Matt Johnston <matt@ucc.asn.au>
parents:
1436
diff
changeset
|
123 /* commit time: $Format:%ai$ */ |