Mercurial > dropbear
annotate libtommath/tommath_private.h @ 1655:f52919ffd3b1
update ltm to 1.1.0 and enable FIPS 186.4 compliant key-generation (#79)
* make key-generation compliant to FIPS 186.4
* fix includes in tommath_class.h
* update fuzzcorpus instead of error-out
* fixup fuzzing make-targets
* update Makefile.in
* apply necessary patches to ltm sources
* clean-up not required ltm files
* update to vanilla ltm 1.1.0
this already only contains the required files
* remove set/get double
author | Steffen Jaeckel <s_jaeckel@gmx.de> |
---|---|
date | Mon, 16 Sep 2019 15:50:38 +0200 |
parents | 8bba51a55704 |
children | 1051e4eea25a |
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 * | |
1655
f52919ffd3b1
update ltm to 1.1.0 and enable FIPS 186.4 compliant key-generation (#79)
Steffen Jaeckel <s_jaeckel@gmx.de>
parents:
1470
diff
changeset
|
10 * SPDX-License-Identifier: Unlicense |
1436 | 11 */ |
12 #ifndef TOMMATH_PRIV_H_ | |
13 #define TOMMATH_PRIV_H_ | |
14 | |
1655
f52919ffd3b1
update ltm to 1.1.0 and enable FIPS 186.4 compliant key-generation (#79)
Steffen Jaeckel <s_jaeckel@gmx.de>
parents:
1470
diff
changeset
|
15 #include "tommath.h" |
1436 | 16 #include <ctype.h> |
17 | |
1470
8bba51a55704
Update to libtommath v1.0.1
Matt Johnston <matt@ucc.asn.au>
parents:
1436
diff
changeset
|
18 #ifndef MIN |
1655
f52919ffd3b1
update ltm to 1.1.0 and enable FIPS 186.4 compliant key-generation (#79)
Steffen Jaeckel <s_jaeckel@gmx.de>
parents:
1470
diff
changeset
|
19 #define MIN(x, y) (((x) < (y)) ? (x) : (y)) |
1470
8bba51a55704
Update to libtommath v1.0.1
Matt Johnston <matt@ucc.asn.au>
parents:
1436
diff
changeset
|
20 #endif |
1436 | 21 |
1470
8bba51a55704
Update to libtommath v1.0.1
Matt Johnston <matt@ucc.asn.au>
parents:
1436
diff
changeset
|
22 #ifndef MAX |
1655
f52919ffd3b1
update ltm to 1.1.0 and enable FIPS 186.4 compliant key-generation (#79)
Steffen Jaeckel <s_jaeckel@gmx.de>
parents:
1470
diff
changeset
|
23 #define MAX(x, y) (((x) > (y)) ? (x) : (y)) |
1470
8bba51a55704
Update to libtommath v1.0.1
Matt Johnston <matt@ucc.asn.au>
parents:
1436
diff
changeset
|
24 #endif |
1436 | 25 |
26 #ifdef __cplusplus | |
27 extern "C" { | |
28 | |
29 /* C++ compilers don't like assigning void * to mp_digit * */ | |
1655
f52919ffd3b1
update ltm to 1.1.0 and enable FIPS 186.4 compliant key-generation (#79)
Steffen Jaeckel <s_jaeckel@gmx.de>
parents:
1470
diff
changeset
|
30 #define OPT_CAST(x) (x *) |
1436 | 31 |
32 #else | |
33 | |
34 /* C on the other hand doesn't care */ | |
1655
f52919ffd3b1
update ltm to 1.1.0 and enable FIPS 186.4 compliant key-generation (#79)
Steffen Jaeckel <s_jaeckel@gmx.de>
parents:
1470
diff
changeset
|
35 #define OPT_CAST(x) |
1436 | 36 |
37 #endif | |
38 | |
39 /* define heap macros */ | |
40 #ifndef XMALLOC | |
1655
f52919ffd3b1
update ltm to 1.1.0 and enable FIPS 186.4 compliant key-generation (#79)
Steffen Jaeckel <s_jaeckel@gmx.de>
parents:
1470
diff
changeset
|
41 /* default to libc stuff */ |
f52919ffd3b1
update ltm to 1.1.0 and enable FIPS 186.4 compliant key-generation (#79)
Steffen Jaeckel <s_jaeckel@gmx.de>
parents:
1470
diff
changeset
|
42 # define XMALLOC malloc |
f52919ffd3b1
update ltm to 1.1.0 and enable FIPS 186.4 compliant key-generation (#79)
Steffen Jaeckel <s_jaeckel@gmx.de>
parents:
1470
diff
changeset
|
43 # define XFREE free |
f52919ffd3b1
update ltm to 1.1.0 and enable FIPS 186.4 compliant key-generation (#79)
Steffen Jaeckel <s_jaeckel@gmx.de>
parents:
1470
diff
changeset
|
44 # define XREALLOC realloc |
f52919ffd3b1
update ltm to 1.1.0 and enable FIPS 186.4 compliant key-generation (#79)
Steffen Jaeckel <s_jaeckel@gmx.de>
parents:
1470
diff
changeset
|
45 # define XCALLOC calloc |
1436 | 46 #else |
1655
f52919ffd3b1
update ltm to 1.1.0 and enable FIPS 186.4 compliant key-generation (#79)
Steffen Jaeckel <s_jaeckel@gmx.de>
parents:
1470
diff
changeset
|
47 /* prototypes for our heap functions */ |
f52919ffd3b1
update ltm to 1.1.0 and enable FIPS 186.4 compliant key-generation (#79)
Steffen Jaeckel <s_jaeckel@gmx.de>
parents:
1470
diff
changeset
|
48 extern void *XMALLOC(size_t n); |
f52919ffd3b1
update ltm to 1.1.0 and enable FIPS 186.4 compliant key-generation (#79)
Steffen Jaeckel <s_jaeckel@gmx.de>
parents:
1470
diff
changeset
|
49 extern void *XREALLOC(void *p, size_t n); |
f52919ffd3b1
update ltm to 1.1.0 and enable FIPS 186.4 compliant key-generation (#79)
Steffen Jaeckel <s_jaeckel@gmx.de>
parents:
1470
diff
changeset
|
50 extern void *XCALLOC(size_t n, size_t s); |
f52919ffd3b1
update ltm to 1.1.0 and enable FIPS 186.4 compliant key-generation (#79)
Steffen Jaeckel <s_jaeckel@gmx.de>
parents:
1470
diff
changeset
|
51 extern void XFREE(void *p); |
1436 | 52 #endif |
53 | |
54 /* lowlevel functions, do not call! */ | |
1655
f52919ffd3b1
update ltm to 1.1.0 and enable FIPS 186.4 compliant key-generation (#79)
Steffen Jaeckel <s_jaeckel@gmx.de>
parents:
1470
diff
changeset
|
55 int s_mp_add(const mp_int *a, const mp_int *b, mp_int *c); |
f52919ffd3b1
update ltm to 1.1.0 and enable FIPS 186.4 compliant key-generation (#79)
Steffen Jaeckel <s_jaeckel@gmx.de>
parents:
1470
diff
changeset
|
56 int s_mp_sub(const mp_int *a, const mp_int *b, mp_int *c); |
1436 | 57 #define s_mp_mul(a, b, c) s_mp_mul_digs(a, b, c, (a)->used + (b)->used + 1) |
1655
f52919ffd3b1
update ltm to 1.1.0 and enable FIPS 186.4 compliant key-generation (#79)
Steffen Jaeckel <s_jaeckel@gmx.de>
parents:
1470
diff
changeset
|
58 int fast_s_mp_mul_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs); |
f52919ffd3b1
update ltm to 1.1.0 and enable FIPS 186.4 compliant key-generation (#79)
Steffen Jaeckel <s_jaeckel@gmx.de>
parents:
1470
diff
changeset
|
59 int s_mp_mul_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs); |
f52919ffd3b1
update ltm to 1.1.0 and enable FIPS 186.4 compliant key-generation (#79)
Steffen Jaeckel <s_jaeckel@gmx.de>
parents:
1470
diff
changeset
|
60 int fast_s_mp_mul_high_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs); |
f52919ffd3b1
update ltm to 1.1.0 and enable FIPS 186.4 compliant key-generation (#79)
Steffen Jaeckel <s_jaeckel@gmx.de>
parents:
1470
diff
changeset
|
61 int s_mp_mul_high_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs); |
f52919ffd3b1
update ltm to 1.1.0 and enable FIPS 186.4 compliant key-generation (#79)
Steffen Jaeckel <s_jaeckel@gmx.de>
parents:
1470
diff
changeset
|
62 int fast_s_mp_sqr(const mp_int *a, mp_int *b); |
f52919ffd3b1
update ltm to 1.1.0 and enable FIPS 186.4 compliant key-generation (#79)
Steffen Jaeckel <s_jaeckel@gmx.de>
parents:
1470
diff
changeset
|
63 int s_mp_sqr(const mp_int *a, mp_int *b); |
f52919ffd3b1
update ltm to 1.1.0 and enable FIPS 186.4 compliant key-generation (#79)
Steffen Jaeckel <s_jaeckel@gmx.de>
parents:
1470
diff
changeset
|
64 int mp_karatsuba_mul(const mp_int *a, const mp_int *b, mp_int *c); |
f52919ffd3b1
update ltm to 1.1.0 and enable FIPS 186.4 compliant key-generation (#79)
Steffen Jaeckel <s_jaeckel@gmx.de>
parents:
1470
diff
changeset
|
65 int mp_toom_mul(const mp_int *a, const mp_int *b, mp_int *c); |
f52919ffd3b1
update ltm to 1.1.0 and enable FIPS 186.4 compliant key-generation (#79)
Steffen Jaeckel <s_jaeckel@gmx.de>
parents:
1470
diff
changeset
|
66 int mp_karatsuba_sqr(const mp_int *a, mp_int *b); |
f52919ffd3b1
update ltm to 1.1.0 and enable FIPS 186.4 compliant key-generation (#79)
Steffen Jaeckel <s_jaeckel@gmx.de>
parents:
1470
diff
changeset
|
67 int mp_toom_sqr(const mp_int *a, mp_int *b); |
f52919ffd3b1
update ltm to 1.1.0 and enable FIPS 186.4 compliant key-generation (#79)
Steffen Jaeckel <s_jaeckel@gmx.de>
parents:
1470
diff
changeset
|
68 int fast_mp_invmod(const mp_int *a, const mp_int *b, mp_int *c); |
f52919ffd3b1
update ltm to 1.1.0 and enable FIPS 186.4 compliant key-generation (#79)
Steffen Jaeckel <s_jaeckel@gmx.de>
parents:
1470
diff
changeset
|
69 int mp_invmod_slow(const mp_int *a, const mp_int *b, mp_int *c); |
f52919ffd3b1
update ltm to 1.1.0 and enable FIPS 186.4 compliant key-generation (#79)
Steffen Jaeckel <s_jaeckel@gmx.de>
parents:
1470
diff
changeset
|
70 int fast_mp_montgomery_reduce(mp_int *x, const mp_int *n, mp_digit rho); |
f52919ffd3b1
update ltm to 1.1.0 and enable FIPS 186.4 compliant key-generation (#79)
Steffen Jaeckel <s_jaeckel@gmx.de>
parents:
1470
diff
changeset
|
71 int mp_exptmod_fast(const mp_int *G, const mp_int *X, const mp_int *P, mp_int *Y, int redmode); |
f52919ffd3b1
update ltm to 1.1.0 and enable FIPS 186.4 compliant key-generation (#79)
Steffen Jaeckel <s_jaeckel@gmx.de>
parents:
1470
diff
changeset
|
72 int s_mp_exptmod(const mp_int *G, const mp_int *X, const mp_int *P, mp_int *Y, int redmode); |
1436 | 73 void bn_reverse(unsigned char *s, int len); |
74 | |
1655
f52919ffd3b1
update ltm to 1.1.0 and enable FIPS 186.4 compliant key-generation (#79)
Steffen Jaeckel <s_jaeckel@gmx.de>
parents:
1470
diff
changeset
|
75 extern const char *const mp_s_rmap; |
f52919ffd3b1
update ltm to 1.1.0 and enable FIPS 186.4 compliant key-generation (#79)
Steffen Jaeckel <s_jaeckel@gmx.de>
parents:
1470
diff
changeset
|
76 extern const uint8_t mp_s_rmap_reverse[]; |
f52919ffd3b1
update ltm to 1.1.0 and enable FIPS 186.4 compliant key-generation (#79)
Steffen Jaeckel <s_jaeckel@gmx.de>
parents:
1470
diff
changeset
|
77 extern const size_t mp_s_rmap_reverse_sz; |
1436 | 78 |
79 /* Fancy macro to set an MPI from another type. | |
80 * There are several things assumed: | |
81 * x is the counter and unsigned | |
82 * a is the pointer to the MPI | |
83 * b is the original value that should be set in the MPI. | |
84 */ | |
85 #define MP_SET_XLONG(func_name, type) \ | |
86 int func_name (mp_int * a, type b) \ | |
87 { \ | |
88 unsigned int x; \ | |
89 int res; \ | |
90 \ | |
91 mp_zero (a); \ | |
92 \ | |
93 /* set four bits at a time */ \ | |
94 for (x = 0; x < (sizeof(type) * 2u); x++) { \ | |
95 /* shift the number up four bits */ \ | |
96 if ((res = mp_mul_2d (a, 4, a)) != MP_OKAY) { \ | |
97 return res; \ | |
98 } \ | |
99 \ | |
100 /* OR in the top four bits of the source */ \ | |
1655
f52919ffd3b1
update ltm to 1.1.0 and enable FIPS 186.4 compliant key-generation (#79)
Steffen Jaeckel <s_jaeckel@gmx.de>
parents:
1470
diff
changeset
|
101 a->dp[0] |= (mp_digit)(b >> ((sizeof(type) * 8u) - 4u)) & 15uL;\ |
1436 | 102 \ |
103 /* shift the source up to the next four bits */ \ | |
104 b <<= 4; \ | |
105 \ | |
106 /* ensure that digits are not clamped off */ \ | |
107 a->used += 1; \ | |
108 } \ | |
109 mp_clamp (a); \ | |
110 return MP_OKAY; \ | |
111 } | |
112 | |
113 #ifdef __cplusplus | |
1655
f52919ffd3b1
update ltm to 1.1.0 and enable FIPS 186.4 compliant key-generation (#79)
Steffen Jaeckel <s_jaeckel@gmx.de>
parents:
1470
diff
changeset
|
114 } |
1436 | 115 #endif |
116 | |
117 #endif | |
118 | |
119 | |
1655
f52919ffd3b1
update ltm to 1.1.0 and enable FIPS 186.4 compliant key-generation (#79)
Steffen Jaeckel <s_jaeckel@gmx.de>
parents:
1470
diff
changeset
|
120 /* ref: HEAD -> master, tag: v1.1.0 */ |
f52919ffd3b1
update ltm to 1.1.0 and enable FIPS 186.4 compliant key-generation (#79)
Steffen Jaeckel <s_jaeckel@gmx.de>
parents:
1470
diff
changeset
|
121 /* git commit: 08549ad6bc8b0cede0b357a9c341c5c6473a9c55 */ |
f52919ffd3b1
update ltm to 1.1.0 and enable FIPS 186.4 compliant key-generation (#79)
Steffen Jaeckel <s_jaeckel@gmx.de>
parents:
1470
diff
changeset
|
122 /* commit time: 2019-01-28 20:32:32 +0100 */ |