diff options
author | miod <> | 2014-04-24 21:31:02 +0000 |
---|---|---|
committer | miod <> | 2014-04-24 21:31:02 +0000 |
commit | b2e9d1eed3ec4424b18ce3ee98e78f0030ca2cf3 (patch) | |
tree | e53472b5e8d9eec9f62ca322e053d1c8f66dc1cc /src | |
parent | d436f60f68787eee6620cab3a227f119e7813894 (diff) | |
download | openbsd-b2e9d1eed3ec4424b18ce3ee98e78f0030ca2cf3.tar.gz openbsd-b2e9d1eed3ec4424b18ce3ee98e78f0030ca2cf3.tar.bz2 openbsd-b2e9d1eed3ec4424b18ce3ee98e78f0030ca2cf3.zip |
Try to clean the maze of <openssl/bn.h> defines regarding the BN internals.
The intent of this change is to only keep support for two kind of architectures:
- those with 32-bit int and long, and 64-bit long long, where
``long * long -> long long'' multiplication routines are available.
- those with 64-bit int and long, and no 128-bit long long type.
This gets rid of the SIXTY_FOUR_BIT_LONG, SIXTY_FOUR_BIT (not the same!),
THIRTY_TWO_BIT, SIXTEEN_BIT and EIGHT_BIT defines.
After this change, the types and defines are as follows:
arch: 64bit 32bit rationale
BN_LLONG undefined defined defined if l * l -> ll
BN_ULLONG undefined u long long result of BN_LONG * BN_LONG
BN_ULONG u long u int native register size
BN_LONG long int the same, signed
BN_BITS 128 64 size of 2*BN_ULONG in bits
BN_BYTES 8 4 size of 2*BN_ULONG in bytes
BN_BITS2 64 32 BN_BITS / 2
Tested on various 32-bit and 64-bit OpenBSD systems of various endianness.
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/libcrypto/bn/asm/parisc-mont.pl | 10 | ||||
-rw-r--r-- | src/lib/libcrypto/bn/bn.h | 53 | ||||
-rw-r--r-- | src/lib/libcrypto/bn/bn_div.c | 71 | ||||
-rw-r--r-- | src/lib/libcrypto/bn/bn_gf2m.c | 15 | ||||
-rw-r--r-- | src/lib/libcrypto/bn/bn_lcl.h | 27 | ||||
-rw-r--r-- | src/lib/libcrypto/bn/bn_lib.c | 29 | ||||
-rw-r--r-- | src/lib/libcrypto/bn/bn_mod.c | 9 | ||||
-rw-r--r-- | src/lib/libcrypto/bn/bn_nist.c | 8 | ||||
-rw-r--r-- | src/lib/libcrypto/bn/bn_prime.h | 10 | ||||
-rw-r--r-- | src/lib/libcrypto/bn/bn_prime.pl | 20 | ||||
-rw-r--r-- | src/lib/libssl/src/apps/genrsa.c | 2 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/bn/asm/parisc-mont.pl | 10 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/bn/bn.h | 53 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/bn/bn_div.c | 71 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/bn/bn_gf2m.c | 15 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/bn/bn_lcl.h | 27 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/bn/bn_lib.c | 29 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/bn/bn_mod.c | 9 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/bn/bn_nist.c | 8 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/bn/bn_prime.h | 10 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/bn/bn_prime.pl | 20 |
21 files changed, 51 insertions, 455 deletions
diff --git a/src/lib/libcrypto/bn/asm/parisc-mont.pl b/src/lib/libcrypto/bn/asm/parisc-mont.pl index c02ef6f014..c38cebd156 100644 --- a/src/lib/libcrypto/bn/asm/parisc-mont.pl +++ b/src/lib/libcrypto/bn/asm/parisc-mont.pl | |||
@@ -87,16 +87,6 @@ if ($flavour =~ /64/) { | |||
87 | $POP ="ldw"; | 87 | $POP ="ldw"; |
88 | $POPMB ="ldwm"; | 88 | $POPMB ="ldwm"; |
89 | $BN_SZ =$SIZE_T; | 89 | $BN_SZ =$SIZE_T; |
90 | if (open CONF,"<${dir}../../opensslconf.h") { | ||
91 | while(<CONF>) { | ||
92 | if (m/#\s*define\s+SIXTY_FOUR_BIT/) { | ||
93 | $BN_SZ=8; | ||
94 | $LEVEL="2.0"; | ||
95 | last; | ||
96 | } | ||
97 | } | ||
98 | close CONF; | ||
99 | } | ||
100 | } | 90 | } |
101 | 91 | ||
102 | $FRAME=8*$SIZE_T+$FRAME_MARKER; # 8 saved regs + frame marker | 92 | $FRAME=8*$SIZE_T+$FRAME_MARKER; # 8 saved regs + frame marker |
diff --git a/src/lib/libcrypto/bn/bn.h b/src/lib/libcrypto/bn/bn.h index 4959232179..74005ed254 100644 --- a/src/lib/libcrypto/bn/bn.h +++ b/src/lib/libcrypto/bn/bn.h | |||
@@ -167,18 +167,14 @@ extern "C" { | |||
167 | * using "long long's", are 32bit, and are not using my assembler code. */ | 167 | * using "long long's", are 32bit, and are not using my assembler code. */ |
168 | /* #define BN_DIV2W */ | 168 | /* #define BN_DIV2W */ |
169 | 169 | ||
170 | /* assuming long is 64bit - this is the DEC Alpha | 170 | #ifdef _LP64 |
171 | * unsigned long long is only 64 bits :-(, don't define | 171 | #undef BN_LLONG |
172 | * BN_LLONG for the DEC Alpha */ | ||
173 | #ifdef SIXTY_FOUR_BIT_LONG | ||
174 | #define BN_ULLONG unsigned long long | ||
175 | #define BN_ULONG unsigned long | 172 | #define BN_ULONG unsigned long |
176 | #define BN_LONG long | 173 | #define BN_LONG long |
177 | #define BN_BITS 128 | 174 | #define BN_BITS 128 |
178 | #define BN_BYTES 8 | 175 | #define BN_BYTES 8 |
179 | #define BN_BITS2 64 | 176 | #define BN_BITS2 64 |
180 | #define BN_BITS4 32 | 177 | #define BN_BITS4 32 |
181 | #define BN_MASK (0xffffffffffffffffffffffffffffffffLL) | ||
182 | #define BN_MASK2 (0xffffffffffffffffL) | 178 | #define BN_MASK2 (0xffffffffffffffffL) |
183 | #define BN_MASK2l (0xffffffffL) | 179 | #define BN_MASK2l (0xffffffffL) |
184 | #define BN_MASK2h (0xffffffff00000000L) | 180 | #define BN_MASK2h (0xffffffff00000000L) |
@@ -190,51 +186,16 @@ extern "C" { | |||
190 | #define BN_DEC_NUM 19 | 186 | #define BN_DEC_NUM 19 |
191 | #define BN_HEX_FMT1 "%lX" | 187 | #define BN_HEX_FMT1 "%lX" |
192 | #define BN_HEX_FMT2 "%016lX" | 188 | #define BN_HEX_FMT2 "%016lX" |
193 | #endif | 189 | #else |
194 | 190 | #define BN_ULLONG unsigned long long | |
195 | /* This is where the long long data type is 64 bits, but long is 32. | 191 | #define BN_LLONG |
196 | * For machines where there are 64bit registers, this is the mode to use. | ||
197 | * IRIX, on R4000 and above should use this mode, along with the relevant | ||
198 | * assembler code :-). Do NOT define BN_LLONG. | ||
199 | */ | ||
200 | #ifdef SIXTY_FOUR_BIT | ||
201 | #undef BN_LLONG | ||
202 | #undef BN_ULLONG | ||
203 | #define BN_ULONG unsigned long long | ||
204 | #define BN_LONG long long | ||
205 | #define BN_BITS 128 | ||
206 | #define BN_BYTES 8 | ||
207 | #define BN_BITS2 64 | ||
208 | #define BN_BITS4 32 | ||
209 | #define BN_MASK2 (0xffffffffffffffffLL) | ||
210 | #define BN_MASK2l (0xffffffffL) | ||
211 | #define BN_MASK2h (0xffffffff00000000LL) | ||
212 | #define BN_MASK2h1 (0xffffffff80000000LL) | ||
213 | #define BN_TBIT (0x8000000000000000LL) | ||
214 | #define BN_DEC_CONV (10000000000000000000ULL) | ||
215 | #define BN_DEC_FMT1 "%llu" | ||
216 | #define BN_DEC_FMT2 "%019llu" | ||
217 | #define BN_DEC_NUM 19 | ||
218 | #define BN_HEX_FMT1 "%llX" | ||
219 | #define BN_HEX_FMT2 "%016llX" | ||
220 | #endif | ||
221 | |||
222 | #ifdef THIRTY_TWO_BIT | ||
223 | #ifdef BN_LLONG | ||
224 | # if defined(_WIN32) && !defined(__GNUC__) | ||
225 | # define BN_ULLONG unsigned __int64 | ||
226 | # define BN_MASK (0xffffffffffffffffI64) | ||
227 | # else | ||
228 | # define BN_ULLONG unsigned long long | ||
229 | # define BN_MASK (0xffffffffffffffffLL) | ||
230 | # endif | ||
231 | #endif | ||
232 | #define BN_ULONG unsigned int | 192 | #define BN_ULONG unsigned int |
233 | #define BN_LONG int | 193 | #define BN_LONG int |
234 | #define BN_BITS 64 | 194 | #define BN_BITS 64 |
235 | #define BN_BYTES 4 | 195 | #define BN_BYTES 4 |
236 | #define BN_BITS2 32 | 196 | #define BN_BITS2 32 |
237 | #define BN_BITS4 16 | 197 | #define BN_BITS4 16 |
198 | #define BN_MASK (0xffffffffffffffffLL) | ||
238 | #define BN_MASK2 (0xffffffffL) | 199 | #define BN_MASK2 (0xffffffffL) |
239 | #define BN_MASK2l (0xffff) | 200 | #define BN_MASK2l (0xffff) |
240 | #define BN_MASK2h1 (0xffff8000L) | 201 | #define BN_MASK2h1 (0xffff8000L) |
@@ -248,8 +209,6 @@ extern "C" { | |||
248 | #define BN_HEX_FMT2 "%08X" | 209 | #define BN_HEX_FMT2 "%08X" |
249 | #endif | 210 | #endif |
250 | 211 | ||
251 | #define BN_DEFAULT_BITS 1280 | ||
252 | |||
253 | #define BN_FLG_MALLOCED 0x01 | 212 | #define BN_FLG_MALLOCED 0x01 |
254 | #define BN_FLG_STATIC_DATA 0x02 | 213 | #define BN_FLG_STATIC_DATA 0x02 |
255 | #define BN_FLG_CONSTTIME 0x04 /* avoid leaking exponent information through timing, | 214 | #define BN_FLG_CONSTTIME 0x04 /* avoid leaking exponent information through timing, |
diff --git a/src/lib/libcrypto/bn/bn_div.c b/src/lib/libcrypto/bn/bn_div.c index 871f29e34f..e3e06ac054 100644 --- a/src/lib/libcrypto/bn/bn_div.c +++ b/src/lib/libcrypto/bn/bn_div.c | |||
@@ -61,72 +61,6 @@ | |||
61 | #include "cryptlib.h" | 61 | #include "cryptlib.h" |
62 | #include "bn_lcl.h" | 62 | #include "bn_lcl.h" |
63 | 63 | ||
64 | |||
65 | /* The old slow way */ | ||
66 | #if 0 | ||
67 | int BN_div(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m, const BIGNUM *d, | ||
68 | BN_CTX *ctx) | ||
69 | { | ||
70 | int i,nm,nd; | ||
71 | int ret = 0; | ||
72 | BIGNUM *D; | ||
73 | |||
74 | bn_check_top(m); | ||
75 | bn_check_top(d); | ||
76 | if (BN_is_zero(d)) | ||
77 | { | ||
78 | BNerr(BN_F_BN_DIV,BN_R_DIV_BY_ZERO); | ||
79 | return(0); | ||
80 | } | ||
81 | |||
82 | if (BN_ucmp(m,d) < 0) | ||
83 | { | ||
84 | if (rem != NULL) | ||
85 | { if (BN_copy(rem,m) == NULL) return(0); } | ||
86 | if (dv != NULL) BN_zero(dv); | ||
87 | return(1); | ||
88 | } | ||
89 | |||
90 | BN_CTX_start(ctx); | ||
91 | D = BN_CTX_get(ctx); | ||
92 | if (dv == NULL) dv = BN_CTX_get(ctx); | ||
93 | if (rem == NULL) rem = BN_CTX_get(ctx); | ||
94 | if (D == NULL || dv == NULL || rem == NULL) | ||
95 | goto end; | ||
96 | |||
97 | nd=BN_num_bits(d); | ||
98 | nm=BN_num_bits(m); | ||
99 | if (BN_copy(D,d) == NULL) goto end; | ||
100 | if (BN_copy(rem,m) == NULL) goto end; | ||
101 | |||
102 | /* The next 2 are needed so we can do a dv->d[0]|=1 later | ||
103 | * since BN_lshift1 will only work once there is a value :-) */ | ||
104 | BN_zero(dv); | ||
105 | if(bn_wexpand(dv,1) == NULL) goto end; | ||
106 | dv->top=1; | ||
107 | |||
108 | if (!BN_lshift(D,D,nm-nd)) goto end; | ||
109 | for (i=nm-nd; i>=0; i--) | ||
110 | { | ||
111 | if (!BN_lshift1(dv,dv)) goto end; | ||
112 | if (BN_ucmp(rem,D) >= 0) | ||
113 | { | ||
114 | dv->d[0]|=1; | ||
115 | if (!BN_usub(rem,rem,D)) goto end; | ||
116 | } | ||
117 | /* CAN IMPROVE (and have now :=) */ | ||
118 | if (!BN_rshift1(D,D)) goto end; | ||
119 | } | ||
120 | rem->neg=BN_is_zero(rem)?0:m->neg; | ||
121 | dv->neg=m->neg^d->neg; | ||
122 | ret = 1; | ||
123 | end: | ||
124 | BN_CTX_end(ctx); | ||
125 | return(ret); | ||
126 | } | ||
127 | |||
128 | #else | ||
129 | |||
130 | #if !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_NO_INLINE_ASM) \ | 64 | #if !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_NO_INLINE_ASM) \ |
131 | && !defined(BN_DIV3W) | 65 | && !defined(BN_DIV3W) |
132 | # if defined(__GNUC__) && __GNUC__>=2 | 66 | # if defined(__GNUC__) && __GNUC__>=2 |
@@ -151,7 +85,7 @@ int BN_div(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m, const BIGNUM *d, | |||
151 | q; \ | 85 | q; \ |
152 | }) | 86 | }) |
153 | # define REMAINDER_IS_ALREADY_CALCULATED | 87 | # define REMAINDER_IS_ALREADY_CALCULATED |
154 | # elif defined(__x86_64) && defined(SIXTY_FOUR_BIT_LONG) | 88 | # elif defined(__x86_64) |
155 | /* | 89 | /* |
156 | * Same story here, but it's 128-bit by 64-bit division. Wow! | 90 | * Same story here, but it's 128-bit by 64-bit division. Wow! |
157 | * <appro@fy.chalmers.se> | 91 | * <appro@fy.chalmers.se> |
@@ -333,7 +267,7 @@ int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor, | |||
333 | #ifdef BN_LLONG | 267 | #ifdef BN_LLONG |
334 | BN_ULLONG t2; | 268 | BN_ULLONG t2; |
335 | 269 | ||
336 | #if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words) | 270 | #if defined(BN_DIV2W) && !defined(bn_div_words) |
337 | q=(BN_ULONG)(((((BN_ULLONG)n0)<<BN_BITS2)|n1)/d0); | 271 | q=(BN_ULONG)(((((BN_ULLONG)n0)<<BN_BITS2)|n1)/d0); |
338 | #else | 272 | #else |
339 | q=bn_div_words(n0,n1,d0); | 273 | q=bn_div_words(n0,n1,d0); |
@@ -435,4 +369,3 @@ err: | |||
435 | BN_CTX_end(ctx); | 369 | BN_CTX_end(ctx); |
436 | return(0); | 370 | return(0); |
437 | } | 371 | } |
438 | #endif | ||
diff --git a/src/lib/libcrypto/bn/bn_gf2m.c b/src/lib/libcrypto/bn/bn_gf2m.c index 68a5faa52d..a75c98ac0e 100644 --- a/src/lib/libcrypto/bn/bn_gf2m.c +++ b/src/lib/libcrypto/bn/bn_gf2m.c | |||
@@ -103,7 +103,7 @@ static const BN_ULONG SQR_tb[16] = | |||
103 | { 0, 1, 4, 5, 16, 17, 20, 21, | 103 | { 0, 1, 4, 5, 16, 17, 20, 21, |
104 | 64, 65, 68, 69, 80, 81, 84, 85 }; | 104 | 64, 65, 68, 69, 80, 81, 84, 85 }; |
105 | /* Platform-specific macros to accelerate squaring. */ | 105 | /* Platform-specific macros to accelerate squaring. */ |
106 | #if defined(SIXTY_FOUR_BIT) || defined(SIXTY_FOUR_BIT_LONG) | 106 | #ifdef _LP64 |
107 | #define SQR1(w) \ | 107 | #define SQR1(w) \ |
108 | SQR_tb[(w) >> 60 & 0xF] << 56 | SQR_tb[(w) >> 56 & 0xF] << 48 | \ | 108 | SQR_tb[(w) >> 60 & 0xF] << 56 | SQR_tb[(w) >> 56 & 0xF] << 48 | \ |
109 | SQR_tb[(w) >> 52 & 0xF] << 40 | SQR_tb[(w) >> 48 & 0xF] << 32 | \ | 109 | SQR_tb[(w) >> 52 & 0xF] << 40 | SQR_tb[(w) >> 48 & 0xF] << 32 | \ |
@@ -114,8 +114,7 @@ static const BN_ULONG SQR_tb[16] = | |||
114 | SQR_tb[(w) >> 20 & 0xF] << 40 | SQR_tb[(w) >> 16 & 0xF] << 32 | \ | 114 | SQR_tb[(w) >> 20 & 0xF] << 40 | SQR_tb[(w) >> 16 & 0xF] << 32 | \ |
115 | SQR_tb[(w) >> 12 & 0xF] << 24 | SQR_tb[(w) >> 8 & 0xF] << 16 | \ | 115 | SQR_tb[(w) >> 12 & 0xF] << 24 | SQR_tb[(w) >> 8 & 0xF] << 16 | \ |
116 | SQR_tb[(w) >> 4 & 0xF] << 8 | SQR_tb[(w) & 0xF] | 116 | SQR_tb[(w) >> 4 & 0xF] << 8 | SQR_tb[(w) & 0xF] |
117 | #endif | 117 | #else |
118 | #ifdef THIRTY_TWO_BIT | ||
119 | #define SQR1(w) \ | 118 | #define SQR1(w) \ |
120 | SQR_tb[(w) >> 28 & 0xF] << 24 | SQR_tb[(w) >> 24 & 0xF] << 16 | \ | 119 | SQR_tb[(w) >> 28 & 0xF] << 24 | SQR_tb[(w) >> 24 & 0xF] << 16 | \ |
121 | SQR_tb[(w) >> 20 & 0xF] << 8 | SQR_tb[(w) >> 16 & 0xF] | 120 | SQR_tb[(w) >> 20 & 0xF] << 8 | SQR_tb[(w) >> 16 & 0xF] |
@@ -130,9 +129,9 @@ static const BN_ULONG SQR_tb[16] = | |||
130 | * The caller MUST ensure that the variables have the right amount | 129 | * The caller MUST ensure that the variables have the right amount |
131 | * of space allocated. | 130 | * of space allocated. |
132 | */ | 131 | */ |
133 | #ifdef THIRTY_TWO_BIT | ||
134 | static void bn_GF2m_mul_1x1(BN_ULONG *r1, BN_ULONG *r0, const BN_ULONG a, const BN_ULONG b) | 132 | static void bn_GF2m_mul_1x1(BN_ULONG *r1, BN_ULONG *r0, const BN_ULONG a, const BN_ULONG b) |
135 | { | 133 | { |
134 | #ifndef _LP64 | ||
136 | register BN_ULONG h, l, s; | 135 | register BN_ULONG h, l, s; |
137 | BN_ULONG tab[8], top2b = a >> 30; | 136 | BN_ULONG tab[8], top2b = a >> 30; |
138 | register BN_ULONG a1, a2, a4; | 137 | register BN_ULONG a1, a2, a4; |
@@ -160,11 +159,7 @@ static void bn_GF2m_mul_1x1(BN_ULONG *r1, BN_ULONG *r0, const BN_ULONG a, const | |||
160 | if (top2b & 02) { l ^= b << 31; h ^= b >> 1; } | 159 | if (top2b & 02) { l ^= b << 31; h ^= b >> 1; } |
161 | 160 | ||
162 | *r1 = h; *r0 = l; | 161 | *r1 = h; *r0 = l; |
163 | } | 162 | #else |
164 | #endif | ||
165 | #if defined(SIXTY_FOUR_BIT) || defined(SIXTY_FOUR_BIT_LONG) | ||
166 | static void bn_GF2m_mul_1x1(BN_ULONG *r1, BN_ULONG *r0, const BN_ULONG a, const BN_ULONG b) | ||
167 | { | ||
168 | register BN_ULONG h, l, s; | 163 | register BN_ULONG h, l, s; |
169 | BN_ULONG tab[16], top3b = a >> 61; | 164 | BN_ULONG tab[16], top3b = a >> 61; |
170 | register BN_ULONG a1, a2, a4, a8; | 165 | register BN_ULONG a1, a2, a4, a8; |
@@ -200,8 +195,8 @@ static void bn_GF2m_mul_1x1(BN_ULONG *r1, BN_ULONG *r0, const BN_ULONG a, const | |||
200 | if (top3b & 04) { l ^= b << 63; h ^= b >> 1; } | 195 | if (top3b & 04) { l ^= b << 63; h ^= b >> 1; } |
201 | 196 | ||
202 | *r1 = h; *r0 = l; | 197 | *r1 = h; *r0 = l; |
203 | } | ||
204 | #endif | 198 | #endif |
199 | } | ||
205 | 200 | ||
206 | /* Product of two polynomials a, b each with degree < 2 * BN_BITS2 - 1, | 201 | /* Product of two polynomials a, b each with degree < 2 * BN_BITS2 - 1, |
207 | * result is a polynomial r with degree < 4 * BN_BITS2 - 1 | 202 | * result is a polynomial r with degree < 4 * BN_BITS2 - 1 |
diff --git a/src/lib/libcrypto/bn/bn_lcl.h b/src/lib/libcrypto/bn/bn_lcl.h index e46cbc2ef8..c3aa584066 100644 --- a/src/lib/libcrypto/bn/bn_lcl.h +++ b/src/lib/libcrypto/bn/bn_lcl.h | |||
@@ -144,26 +144,14 @@ extern "C" { | |||
144 | * (with draws in between). Very small exponents are often selected | 144 | * (with draws in between). Very small exponents are often selected |
145 | * with low Hamming weight, so we use w = 1 for b <= 23. | 145 | * with low Hamming weight, so we use w = 1 for b <= 23. |
146 | */ | 146 | */ |
147 | #if 1 | ||
148 | #define BN_window_bits_for_exponent_size(b) \ | 147 | #define BN_window_bits_for_exponent_size(b) \ |
149 | ((b) > 671 ? 6 : \ | 148 | ((b) > 671 ? 6 : \ |
150 | (b) > 239 ? 5 : \ | 149 | (b) > 239 ? 5 : \ |
151 | (b) > 79 ? 4 : \ | 150 | (b) > 79 ? 4 : \ |
152 | (b) > 23 ? 3 : 1) | 151 | (b) > 23 ? 3 : 1) |
153 | #else | ||
154 | /* Old SSLeay/OpenSSL table. | ||
155 | * Maximum window size was 5, so this table differs for b==1024; | ||
156 | * but it coincides for other interesting values (b==160, b==512). | ||
157 | */ | ||
158 | #define BN_window_bits_for_exponent_size(b) \ | ||
159 | ((b) > 255 ? 5 : \ | ||
160 | (b) > 127 ? 4 : \ | ||
161 | (b) > 17 ? 3 : 1) | ||
162 | #endif | ||
163 | 152 | ||
164 | 153 | ||
165 | 154 | /* BN_mod_exp_mont_consttime is based on the assumption that the | |
166 | /* BN_mod_exp_mont_conttime is based on the assumption that the | ||
167 | * L1 data cache line width of the target processor is at least | 155 | * L1 data cache line width of the target processor is at least |
168 | * the following value. | 156 | * the following value. |
169 | */ | 157 | */ |
@@ -234,7 +222,7 @@ extern "C" { | |||
234 | * | 222 | * |
235 | * <appro@fy.chalmers.se> | 223 | * <appro@fy.chalmers.se> |
236 | */ | 224 | */ |
237 | # if defined(__alpha) && (defined(SIXTY_FOUR_BIT_LONG) || defined(SIXTY_FOUR_BIT)) | 225 | # if defined(__alpha) |
238 | # if defined(__GNUC__) && __GNUC__>=2 | 226 | # if defined(__GNUC__) && __GNUC__>=2 |
239 | # define BN_UMULT_HIGH(a,b) ({ \ | 227 | # define BN_UMULT_HIGH(a,b) ({ \ |
240 | register BN_ULONG ret; \ | 228 | register BN_ULONG ret; \ |
@@ -243,7 +231,7 @@ extern "C" { | |||
243 | : "r"(a), "r"(b)); \ | 231 | : "r"(a), "r"(b)); \ |
244 | ret; }) | 232 | ret; }) |
245 | # endif /* compiler */ | 233 | # endif /* compiler */ |
246 | # elif defined(_ARCH_PPC) && defined(__64BIT__) && defined(SIXTY_FOUR_BIT_LONG) | 234 | # elif defined(_ARCH_PPC) && defined(_LP64) |
247 | # if defined(__GNUC__) && __GNUC__>=2 | 235 | # if defined(__GNUC__) && __GNUC__>=2 |
248 | # define BN_UMULT_HIGH(a,b) ({ \ | 236 | # define BN_UMULT_HIGH(a,b) ({ \ |
249 | register BN_ULONG ret; \ | 237 | register BN_ULONG ret; \ |
@@ -252,8 +240,7 @@ extern "C" { | |||
252 | : "r"(a), "r"(b)); \ | 240 | : "r"(a), "r"(b)); \ |
253 | ret; }) | 241 | ret; }) |
254 | # endif /* compiler */ | 242 | # endif /* compiler */ |
255 | # elif (defined(__x86_64) || defined(__x86_64__)) && \ | 243 | # elif defined(__x86_64) || defined(__x86_64__) |
256 | (defined(SIXTY_FOUR_BIT_LONG) || defined(SIXTY_FOUR_BIT)) | ||
257 | # if defined(__GNUC__) && __GNUC__>=2 | 244 | # if defined(__GNUC__) && __GNUC__>=2 |
258 | # define BN_UMULT_HIGH(a,b) ({ \ | 245 | # define BN_UMULT_HIGH(a,b) ({ \ |
259 | register BN_ULONG ret,discard; \ | 246 | register BN_ULONG ret,discard; \ |
@@ -268,7 +255,7 @@ extern "C" { | |||
268 | : "a"(a),"g"(b) \ | 255 | : "a"(a),"g"(b) \ |
269 | : "cc"); | 256 | : "cc"); |
270 | # endif | 257 | # endif |
271 | # elif defined(__mips) && (defined(SIXTY_FOUR_BIT) || defined(SIXTY_FOUR_BIT_LONG)) | 258 | # elif defined(__mips) && defined(_LP64) |
272 | # if defined(__GNUC__) && __GNUC__>=2 | 259 | # if defined(__GNUC__) && __GNUC__>=2 |
273 | # if __GNUC__>=4 && __GNUC_MINOR__>=4 /* "h" constraint is no more since 4.4 */ | 260 | # if __GNUC__>=4 && __GNUC_MINOR__>=4 /* "h" constraint is no more since 4.4 */ |
274 | # define BN_UMULT_HIGH(a,b) (((__uint128_t)(a)*(b))>>64) | 261 | # define BN_UMULT_HIGH(a,b) (((__uint128_t)(a)*(b))>>64) |
@@ -397,10 +384,6 @@ extern "C" { | |||
397 | #define HBITS(a) (((a)>>BN_BITS4)&BN_MASK2l) | 384 | #define HBITS(a) (((a)>>BN_BITS4)&BN_MASK2l) |
398 | #define L2HBITS(a) (((a)<<BN_BITS4)&BN_MASK2) | 385 | #define L2HBITS(a) (((a)<<BN_BITS4)&BN_MASK2) |
399 | 386 | ||
400 | #define LLBITS(a) ((a)&BN_MASKl) | ||
401 | #define LHBITS(a) (((a)>>BN_BITS2)&BN_MASKl) | ||
402 | #define LL2HBITS(a) ((BN_ULLONG)((a)&BN_MASKl)<<BN_BITS2) | ||
403 | |||
404 | #define mul64(l,h,bl,bh) \ | 387 | #define mul64(l,h,bl,bh) \ |
405 | { \ | 388 | { \ |
406 | BN_ULONG m,m1,lt,ht; \ | 389 | BN_ULONG m,m1,lt,ht; \ |
diff --git a/src/lib/libcrypto/bn/bn_lib.c b/src/lib/libcrypto/bn/bn_lib.c index c8de547ba5..9787a31dbb 100644 --- a/src/lib/libcrypto/bn/bn_lib.c +++ b/src/lib/libcrypto/bn/bn_lib.c | |||
@@ -160,7 +160,7 @@ int BN_num_bits_word(BN_ULONG l) | |||
160 | 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, | 160 | 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, |
161 | }; | 161 | }; |
162 | 162 | ||
163 | #if defined(SIXTY_FOUR_BIT_LONG) | 163 | #ifdef _LP64 |
164 | if (l & 0xffffffff00000000L) | 164 | if (l & 0xffffffff00000000L) |
165 | { | 165 | { |
166 | if (l & 0xffff000000000000L) | 166 | if (l & 0xffff000000000000L) |
@@ -181,32 +181,8 @@ int BN_num_bits_word(BN_ULONG l) | |||
181 | } | 181 | } |
182 | } | 182 | } |
183 | else | 183 | else |
184 | #else | ||
185 | #ifdef SIXTY_FOUR_BIT | ||
186 | if (l & 0xffffffff00000000LL) | ||
187 | { | ||
188 | if (l & 0xffff000000000000LL) | ||
189 | { | ||
190 | if (l & 0xff00000000000000LL) | ||
191 | { | ||
192 | return(bits[(int)(l>>56)]+56); | ||
193 | } | ||
194 | else return(bits[(int)(l>>48)]+48); | ||
195 | } | ||
196 | else | ||
197 | { | ||
198 | if (l & 0x0000ff0000000000LL) | ||
199 | { | ||
200 | return(bits[(int)(l>>40)]+40); | ||
201 | } | ||
202 | else return(bits[(int)(l>>32)]+32); | ||
203 | } | ||
204 | } | ||
205 | else | ||
206 | #endif | ||
207 | #endif | 184 | #endif |
208 | { | 185 | { |
209 | #if defined(THIRTY_TWO_BIT) || defined(SIXTY_FOUR_BIT) || defined(SIXTY_FOUR_BIT_LONG) | ||
210 | if (l & 0xffff0000L) | 186 | if (l & 0xffff0000L) |
211 | { | 187 | { |
212 | if (l & 0xff000000L) | 188 | if (l & 0xff000000L) |
@@ -214,13 +190,10 @@ int BN_num_bits_word(BN_ULONG l) | |||
214 | else return(bits[(int)(l>>16L)]+16); | 190 | else return(bits[(int)(l>>16L)]+16); |
215 | } | 191 | } |
216 | else | 192 | else |
217 | #endif | ||
218 | { | 193 | { |
219 | #if defined(THIRTY_TWO_BIT) || defined(SIXTY_FOUR_BIT) || defined(SIXTY_FOUR_BIT_LONG) | ||
220 | if (l & 0xff00L) | 194 | if (l & 0xff00L) |
221 | return(bits[(int)(l>>8)]+8); | 195 | return(bits[(int)(l>>8)]+8); |
222 | else | 196 | else |
223 | #endif | ||
224 | return(bits[(int)(l )] ); | 197 | return(bits[(int)(l )] ); |
225 | } | 198 | } |
226 | } | 199 | } |
diff --git a/src/lib/libcrypto/bn/bn_mod.c b/src/lib/libcrypto/bn/bn_mod.c index 77d6ddb91a..6c439402dd 100644 --- a/src/lib/libcrypto/bn/bn_mod.c +++ b/src/lib/libcrypto/bn/bn_mod.c | |||
@@ -115,15 +115,6 @@ | |||
115 | #include "bn_lcl.h" | 115 | #include "bn_lcl.h" |
116 | 116 | ||
117 | 117 | ||
118 | #if 0 /* now just a #define */ | ||
119 | int BN_mod(BIGNUM *rem, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx) | ||
120 | { | ||
121 | return(BN_div(NULL,rem,m,d,ctx)); | ||
122 | /* note that rem->neg == m->neg (unless the remainder is zero) */ | ||
123 | } | ||
124 | #endif | ||
125 | |||
126 | |||
127 | int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx) | 118 | int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx) |
128 | { | 119 | { |
129 | /* like BN_mod, but returns non-negative remainder | 120 | /* like BN_mod, but returns non-negative remainder |
diff --git a/src/lib/libcrypto/bn/bn_nist.c b/src/lib/libcrypto/bn/bn_nist.c index 4d4a7b86df..d793644e27 100644 --- a/src/lib/libcrypto/bn/bn_nist.c +++ b/src/lib/libcrypto/bn/bn_nist.c | |||
@@ -321,7 +321,7 @@ static void nist_cp_bn(BN_ULONG *dst, const BN_ULONG *src, int top) | |||
321 | #define bn_32_set_0(to, n) (((n)&1)?(to[(n)/2]&=BN_MASK2l):(to[(n)/2]=0)); | 321 | #define bn_32_set_0(to, n) (((n)&1)?(to[(n)/2]&=BN_MASK2l):(to[(n)/2]=0)); |
322 | #define bn_cp_32(to,n,from,m) ((m)>=0)?bn_cp_32_naked(to,n,from,m):bn_32_set_0(to,n) | 322 | #define bn_cp_32(to,n,from,m) ((m)>=0)?bn_cp_32_naked(to,n,from,m):bn_32_set_0(to,n) |
323 | # if _BYTE_ORDER == _LITTLE_ENDIAN | 323 | # if _BYTE_ORDER == _LITTLE_ENDIAN |
324 | # if defined(__arch64__) | 324 | # if defined(_LP64) |
325 | # define NIST_INT64 long | 325 | # define NIST_INT64 long |
326 | # else | 326 | # else |
327 | # define NIST_INT64 long long | 327 | # define NIST_INT64 long long |
@@ -340,9 +340,7 @@ static void nist_cp_bn(BN_ULONG *dst, const BN_ULONG *src, int top) | |||
340 | } | 340 | } |
341 | #define bn_cp_32(to, n, from, m) (to)[n] = (m>=0)?((from)[m]):0; | 341 | #define bn_cp_32(to, n, from, m) (to)[n] = (m>=0)?((from)[m]):0; |
342 | #define bn_32_set_0(to, n) (to)[n] = (BN_ULONG)0; | 342 | #define bn_32_set_0(to, n) (to)[n] = (BN_ULONG)0; |
343 | # if defined(_WIN32) && !defined(__GNUC__) | 343 | # if defined(BN_LLONG) |
344 | # define NIST_INT64 __int64 | ||
345 | # elif defined(BN_LLONG) | ||
346 | # define NIST_INT64 long long | 344 | # define NIST_INT64 long long |
347 | # endif | 345 | # endif |
348 | #endif /* BN_BITS2 != 64 */ | 346 | #endif /* BN_BITS2 != 64 */ |
@@ -594,7 +592,7 @@ int BN_nist_mod_224(BIGNUM *r, const BIGNUM *a, const BIGNUM *field, | |||
594 | } | 592 | } |
595 | else if (carry < 0) | 593 | else if (carry < 0) |
596 | { | 594 | { |
597 | /* it's a bit more comlicated logic in this case. | 595 | /* it's a bit more complicated logic in this case. |
598 | * if bn_add_words yields no carry, then result | 596 | * if bn_add_words yields no carry, then result |
599 | * has to be adjusted by unconditionally *adding* | 597 | * has to be adjusted by unconditionally *adding* |
600 | * the modulus. but if it does, then result has | 598 | * the modulus. but if it does, then result has |
diff --git a/src/lib/libcrypto/bn/bn_prime.h b/src/lib/libcrypto/bn/bn_prime.h index 51d2194feb..ccdeca5afa 100644 --- a/src/lib/libcrypto/bn/bn_prime.h +++ b/src/lib/libcrypto/bn/bn_prime.h | |||
@@ -56,13 +56,8 @@ | |||
56 | * [including the GNU Public Licence.] | 56 | * [including the GNU Public Licence.] |
57 | */ | 57 | */ |
58 | 58 | ||
59 | #ifndef EIGHT_BIT | ||
60 | #define NUMPRIMES 2048 | 59 | #define NUMPRIMES 2048 |
61 | typedef unsigned short prime_t; | 60 | typedef unsigned short prime_t; |
62 | #else | ||
63 | #define NUMPRIMES 54 | ||
64 | typedef unsigned char prime_t; | ||
65 | #endif | ||
66 | static const prime_t primes[NUMPRIMES]= | 61 | static const prime_t primes[NUMPRIMES]= |
67 | { | 62 | { |
68 | 2, 3, 5, 7, 11, 13, 17, 19, | 63 | 2, 3, 5, 7, 11, 13, 17, 19, |
@@ -71,9 +66,7 @@ static const prime_t primes[NUMPRIMES]= | |||
71 | 97, 101, 103, 107, 109, 113, 127, 131, | 66 | 97, 101, 103, 107, 109, 113, 127, 131, |
72 | 137, 139, 149, 151, 157, 163, 167, 173, | 67 | 137, 139, 149, 151, 157, 163, 167, 173, |
73 | 179, 181, 191, 193, 197, 199, 211, 223, | 68 | 179, 181, 191, 193, 197, 199, 211, 223, |
74 | 227, 229, 233, 239, 241, 251, | 69 | 227, 229, 233, 239, 241, 251, 257, 263, |
75 | #ifndef EIGHT_BIT | ||
76 | 257, 263, | ||
77 | 269, 271, 277, 281, 283, 293, 307, 311, | 70 | 269, 271, 277, 281, 283, 293, 307, 311, |
78 | 313, 317, 331, 337, 347, 349, 353, 359, | 71 | 313, 317, 331, 337, 347, 349, 353, 359, |
79 | 367, 373, 379, 383, 389, 397, 401, 409, | 72 | 367, 373, 379, 383, 389, 397, 401, 409, |
@@ -323,5 +316,4 @@ static const prime_t primes[NUMPRIMES]= | |||
323 | 17609,17623,17627,17657,17659,17669,17681,17683, | 316 | 17609,17623,17627,17657,17659,17669,17681,17683, |
324 | 17707,17713,17729,17737,17747,17749,17761,17783, | 317 | 17707,17713,17729,17737,17747,17749,17761,17783, |
325 | 17789,17791,17807,17827,17837,17839,17851,17863, | 318 | 17789,17791,17807,17827,17837,17839,17851,17863, |
326 | #endif | ||
327 | }; | 319 | }; |
diff --git a/src/lib/libcrypto/bn/bn_prime.pl b/src/lib/libcrypto/bn/bn_prime.pl index 3fafb6f3e9..eb73f0bfa6 100644 --- a/src/lib/libcrypto/bn/bn_prime.pl +++ b/src/lib/libcrypto/bn/bn_prime.pl | |||
@@ -90,30 +90,14 @@ print <<\EOF; | |||
90 | 90 | ||
91 | EOF | 91 | EOF |
92 | 92 | ||
93 | for ($i=0; $i <= $#primes; $i++) | ||
94 | { | ||
95 | if ($primes[$i] > 256) | ||
96 | { | ||
97 | $eight=$i; | ||
98 | last; | ||
99 | } | ||
100 | } | ||
101 | |||
102 | printf "#ifndef EIGHT_BIT\n"; | ||
103 | printf "#define NUMPRIMES %d\n",$num; | 93 | printf "#define NUMPRIMES %d\n",$num; |
104 | printf "typedef unsigned short prime_t;\n"; | 94 | printf "typedef unsigned short prime_t;\n"; |
105 | printf "#else\n"; | 95 | print "static const prime_t primes[NUMPRIMES]=\n{\n\t"; |
106 | printf "#define NUMPRIMES %d\n",$eight; | ||
107 | printf "typedef unsigned char prime_t;\n"; | ||
108 | printf "#endif\n"; | ||
109 | print "static const prime_t primes[NUMPRIMES]=\n\t{\n\t"; | ||
110 | $init=0; | ||
111 | for ($i=0; $i <= $#primes; $i++) | 96 | for ($i=0; $i <= $#primes; $i++) |
112 | { | 97 | { |
113 | printf "\n#ifndef EIGHT_BIT\n\t" if ($primes[$i] > 256) && !($init++); | ||
114 | printf("\n\t") if (($i%8) == 0) && ($i != 0); | 98 | printf("\n\t") if (($i%8) == 0) && ($i != 0); |
115 | printf("%4d,",$primes[$i]); | 99 | printf("%4d,",$primes[$i]); |
116 | } | 100 | } |
117 | print "\n#endif\n\t};\n"; | 101 | print "\n};\n"; |
118 | 102 | ||
119 | 103 | ||
diff --git a/src/lib/libssl/src/apps/genrsa.c b/src/lib/libssl/src/apps/genrsa.c index 68e939ca99..c658828299 100644 --- a/src/lib/libssl/src/apps/genrsa.c +++ b/src/lib/libssl/src/apps/genrsa.c | |||
@@ -256,7 +256,7 @@ bad: | |||
256 | */ | 256 | */ |
257 | l = 0L; | 257 | l = 0L; |
258 | for (i = 0; i < rsa->e->top; i++) { | 258 | for (i = 0; i < rsa->e->top; i++) { |
259 | #ifndef SIXTY_FOUR_BIT | 259 | #ifndef _LP64 |
260 | l <<= BN_BITS4; | 260 | l <<= BN_BITS4; |
261 | l <<= BN_BITS4; | 261 | l <<= BN_BITS4; |
262 | #endif | 262 | #endif |
diff --git a/src/lib/libssl/src/crypto/bn/asm/parisc-mont.pl b/src/lib/libssl/src/crypto/bn/asm/parisc-mont.pl index c02ef6f014..c38cebd156 100644 --- a/src/lib/libssl/src/crypto/bn/asm/parisc-mont.pl +++ b/src/lib/libssl/src/crypto/bn/asm/parisc-mont.pl | |||
@@ -87,16 +87,6 @@ if ($flavour =~ /64/) { | |||
87 | $POP ="ldw"; | 87 | $POP ="ldw"; |
88 | $POPMB ="ldwm"; | 88 | $POPMB ="ldwm"; |
89 | $BN_SZ =$SIZE_T; | 89 | $BN_SZ =$SIZE_T; |
90 | if (open CONF,"<${dir}../../opensslconf.h") { | ||
91 | while(<CONF>) { | ||
92 | if (m/#\s*define\s+SIXTY_FOUR_BIT/) { | ||
93 | $BN_SZ=8; | ||
94 | $LEVEL="2.0"; | ||
95 | last; | ||
96 | } | ||
97 | } | ||
98 | close CONF; | ||
99 | } | ||
100 | } | 90 | } |
101 | 91 | ||
102 | $FRAME=8*$SIZE_T+$FRAME_MARKER; # 8 saved regs + frame marker | 92 | $FRAME=8*$SIZE_T+$FRAME_MARKER; # 8 saved regs + frame marker |
diff --git a/src/lib/libssl/src/crypto/bn/bn.h b/src/lib/libssl/src/crypto/bn/bn.h index 4959232179..74005ed254 100644 --- a/src/lib/libssl/src/crypto/bn/bn.h +++ b/src/lib/libssl/src/crypto/bn/bn.h | |||
@@ -167,18 +167,14 @@ extern "C" { | |||
167 | * using "long long's", are 32bit, and are not using my assembler code. */ | 167 | * using "long long's", are 32bit, and are not using my assembler code. */ |
168 | /* #define BN_DIV2W */ | 168 | /* #define BN_DIV2W */ |
169 | 169 | ||
170 | /* assuming long is 64bit - this is the DEC Alpha | 170 | #ifdef _LP64 |
171 | * unsigned long long is only 64 bits :-(, don't define | 171 | #undef BN_LLONG |
172 | * BN_LLONG for the DEC Alpha */ | ||
173 | #ifdef SIXTY_FOUR_BIT_LONG | ||
174 | #define BN_ULLONG unsigned long long | ||
175 | #define BN_ULONG unsigned long | 172 | #define BN_ULONG unsigned long |
176 | #define BN_LONG long | 173 | #define BN_LONG long |
177 | #define BN_BITS 128 | 174 | #define BN_BITS 128 |
178 | #define BN_BYTES 8 | 175 | #define BN_BYTES 8 |
179 | #define BN_BITS2 64 | 176 | #define BN_BITS2 64 |
180 | #define BN_BITS4 32 | 177 | #define BN_BITS4 32 |
181 | #define BN_MASK (0xffffffffffffffffffffffffffffffffLL) | ||
182 | #define BN_MASK2 (0xffffffffffffffffL) | 178 | #define BN_MASK2 (0xffffffffffffffffL) |
183 | #define BN_MASK2l (0xffffffffL) | 179 | #define BN_MASK2l (0xffffffffL) |
184 | #define BN_MASK2h (0xffffffff00000000L) | 180 | #define BN_MASK2h (0xffffffff00000000L) |
@@ -190,51 +186,16 @@ extern "C" { | |||
190 | #define BN_DEC_NUM 19 | 186 | #define BN_DEC_NUM 19 |
191 | #define BN_HEX_FMT1 "%lX" | 187 | #define BN_HEX_FMT1 "%lX" |
192 | #define BN_HEX_FMT2 "%016lX" | 188 | #define BN_HEX_FMT2 "%016lX" |
193 | #endif | 189 | #else |
194 | 190 | #define BN_ULLONG unsigned long long | |
195 | /* This is where the long long data type is 64 bits, but long is 32. | 191 | #define BN_LLONG |
196 | * For machines where there are 64bit registers, this is the mode to use. | ||
197 | * IRIX, on R4000 and above should use this mode, along with the relevant | ||
198 | * assembler code :-). Do NOT define BN_LLONG. | ||
199 | */ | ||
200 | #ifdef SIXTY_FOUR_BIT | ||
201 | #undef BN_LLONG | ||
202 | #undef BN_ULLONG | ||
203 | #define BN_ULONG unsigned long long | ||
204 | #define BN_LONG long long | ||
205 | #define BN_BITS 128 | ||
206 | #define BN_BYTES 8 | ||
207 | #define BN_BITS2 64 | ||
208 | #define BN_BITS4 32 | ||
209 | #define BN_MASK2 (0xffffffffffffffffLL) | ||
210 | #define BN_MASK2l (0xffffffffL) | ||
211 | #define BN_MASK2h (0xffffffff00000000LL) | ||
212 | #define BN_MASK2h1 (0xffffffff80000000LL) | ||
213 | #define BN_TBIT (0x8000000000000000LL) | ||
214 | #define BN_DEC_CONV (10000000000000000000ULL) | ||
215 | #define BN_DEC_FMT1 "%llu" | ||
216 | #define BN_DEC_FMT2 "%019llu" | ||
217 | #define BN_DEC_NUM 19 | ||
218 | #define BN_HEX_FMT1 "%llX" | ||
219 | #define BN_HEX_FMT2 "%016llX" | ||
220 | #endif | ||
221 | |||
222 | #ifdef THIRTY_TWO_BIT | ||
223 | #ifdef BN_LLONG | ||
224 | # if defined(_WIN32) && !defined(__GNUC__) | ||
225 | # define BN_ULLONG unsigned __int64 | ||
226 | # define BN_MASK (0xffffffffffffffffI64) | ||
227 | # else | ||
228 | # define BN_ULLONG unsigned long long | ||
229 | # define BN_MASK (0xffffffffffffffffLL) | ||
230 | # endif | ||
231 | #endif | ||
232 | #define BN_ULONG unsigned int | 192 | #define BN_ULONG unsigned int |
233 | #define BN_LONG int | 193 | #define BN_LONG int |
234 | #define BN_BITS 64 | 194 | #define BN_BITS 64 |
235 | #define BN_BYTES 4 | 195 | #define BN_BYTES 4 |
236 | #define BN_BITS2 32 | 196 | #define BN_BITS2 32 |
237 | #define BN_BITS4 16 | 197 | #define BN_BITS4 16 |
198 | #define BN_MASK (0xffffffffffffffffLL) | ||
238 | #define BN_MASK2 (0xffffffffL) | 199 | #define BN_MASK2 (0xffffffffL) |
239 | #define BN_MASK2l (0xffff) | 200 | #define BN_MASK2l (0xffff) |
240 | #define BN_MASK2h1 (0xffff8000L) | 201 | #define BN_MASK2h1 (0xffff8000L) |
@@ -248,8 +209,6 @@ extern "C" { | |||
248 | #define BN_HEX_FMT2 "%08X" | 209 | #define BN_HEX_FMT2 "%08X" |
249 | #endif | 210 | #endif |
250 | 211 | ||
251 | #define BN_DEFAULT_BITS 1280 | ||
252 | |||
253 | #define BN_FLG_MALLOCED 0x01 | 212 | #define BN_FLG_MALLOCED 0x01 |
254 | #define BN_FLG_STATIC_DATA 0x02 | 213 | #define BN_FLG_STATIC_DATA 0x02 |
255 | #define BN_FLG_CONSTTIME 0x04 /* avoid leaking exponent information through timing, | 214 | #define BN_FLG_CONSTTIME 0x04 /* avoid leaking exponent information through timing, |
diff --git a/src/lib/libssl/src/crypto/bn/bn_div.c b/src/lib/libssl/src/crypto/bn/bn_div.c index 871f29e34f..e3e06ac054 100644 --- a/src/lib/libssl/src/crypto/bn/bn_div.c +++ b/src/lib/libssl/src/crypto/bn/bn_div.c | |||
@@ -61,72 +61,6 @@ | |||
61 | #include "cryptlib.h" | 61 | #include "cryptlib.h" |
62 | #include "bn_lcl.h" | 62 | #include "bn_lcl.h" |
63 | 63 | ||
64 | |||
65 | /* The old slow way */ | ||
66 | #if 0 | ||
67 | int BN_div(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m, const BIGNUM *d, | ||
68 | BN_CTX *ctx) | ||
69 | { | ||
70 | int i,nm,nd; | ||
71 | int ret = 0; | ||
72 | BIGNUM *D; | ||
73 | |||
74 | bn_check_top(m); | ||
75 | bn_check_top(d); | ||
76 | if (BN_is_zero(d)) | ||
77 | { | ||
78 | BNerr(BN_F_BN_DIV,BN_R_DIV_BY_ZERO); | ||
79 | return(0); | ||
80 | } | ||
81 | |||
82 | if (BN_ucmp(m,d) < 0) | ||
83 | { | ||
84 | if (rem != NULL) | ||
85 | { if (BN_copy(rem,m) == NULL) return(0); } | ||
86 | if (dv != NULL) BN_zero(dv); | ||
87 | return(1); | ||
88 | } | ||
89 | |||
90 | BN_CTX_start(ctx); | ||
91 | D = BN_CTX_get(ctx); | ||
92 | if (dv == NULL) dv = BN_CTX_get(ctx); | ||
93 | if (rem == NULL) rem = BN_CTX_get(ctx); | ||
94 | if (D == NULL || dv == NULL || rem == NULL) | ||
95 | goto end; | ||
96 | |||
97 | nd=BN_num_bits(d); | ||
98 | nm=BN_num_bits(m); | ||
99 | if (BN_copy(D,d) == NULL) goto end; | ||
100 | if (BN_copy(rem,m) == NULL) goto end; | ||
101 | |||
102 | /* The next 2 are needed so we can do a dv->d[0]|=1 later | ||
103 | * since BN_lshift1 will only work once there is a value :-) */ | ||
104 | BN_zero(dv); | ||
105 | if(bn_wexpand(dv,1) == NULL) goto end; | ||
106 | dv->top=1; | ||
107 | |||
108 | if (!BN_lshift(D,D,nm-nd)) goto end; | ||
109 | for (i=nm-nd; i>=0; i--) | ||
110 | { | ||
111 | if (!BN_lshift1(dv,dv)) goto end; | ||
112 | if (BN_ucmp(rem,D) >= 0) | ||
113 | { | ||
114 | dv->d[0]|=1; | ||
115 | if (!BN_usub(rem,rem,D)) goto end; | ||
116 | } | ||
117 | /* CAN IMPROVE (and have now :=) */ | ||
118 | if (!BN_rshift1(D,D)) goto end; | ||
119 | } | ||
120 | rem->neg=BN_is_zero(rem)?0:m->neg; | ||
121 | dv->neg=m->neg^d->neg; | ||
122 | ret = 1; | ||
123 | end: | ||
124 | BN_CTX_end(ctx); | ||
125 | return(ret); | ||
126 | } | ||
127 | |||
128 | #else | ||
129 | |||
130 | #if !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_NO_INLINE_ASM) \ | 64 | #if !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_NO_INLINE_ASM) \ |
131 | && !defined(BN_DIV3W) | 65 | && !defined(BN_DIV3W) |
132 | # if defined(__GNUC__) && __GNUC__>=2 | 66 | # if defined(__GNUC__) && __GNUC__>=2 |
@@ -151,7 +85,7 @@ int BN_div(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m, const BIGNUM *d, | |||
151 | q; \ | 85 | q; \ |
152 | }) | 86 | }) |
153 | # define REMAINDER_IS_ALREADY_CALCULATED | 87 | # define REMAINDER_IS_ALREADY_CALCULATED |
154 | # elif defined(__x86_64) && defined(SIXTY_FOUR_BIT_LONG) | 88 | # elif defined(__x86_64) |
155 | /* | 89 | /* |
156 | * Same story here, but it's 128-bit by 64-bit division. Wow! | 90 | * Same story here, but it's 128-bit by 64-bit division. Wow! |
157 | * <appro@fy.chalmers.se> | 91 | * <appro@fy.chalmers.se> |
@@ -333,7 +267,7 @@ int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor, | |||
333 | #ifdef BN_LLONG | 267 | #ifdef BN_LLONG |
334 | BN_ULLONG t2; | 268 | BN_ULLONG t2; |
335 | 269 | ||
336 | #if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words) | 270 | #if defined(BN_DIV2W) && !defined(bn_div_words) |
337 | q=(BN_ULONG)(((((BN_ULLONG)n0)<<BN_BITS2)|n1)/d0); | 271 | q=(BN_ULONG)(((((BN_ULLONG)n0)<<BN_BITS2)|n1)/d0); |
338 | #else | 272 | #else |
339 | q=bn_div_words(n0,n1,d0); | 273 | q=bn_div_words(n0,n1,d0); |
@@ -435,4 +369,3 @@ err: | |||
435 | BN_CTX_end(ctx); | 369 | BN_CTX_end(ctx); |
436 | return(0); | 370 | return(0); |
437 | } | 371 | } |
438 | #endif | ||
diff --git a/src/lib/libssl/src/crypto/bn/bn_gf2m.c b/src/lib/libssl/src/crypto/bn/bn_gf2m.c index 68a5faa52d..a75c98ac0e 100644 --- a/src/lib/libssl/src/crypto/bn/bn_gf2m.c +++ b/src/lib/libssl/src/crypto/bn/bn_gf2m.c | |||
@@ -103,7 +103,7 @@ static const BN_ULONG SQR_tb[16] = | |||
103 | { 0, 1, 4, 5, 16, 17, 20, 21, | 103 | { 0, 1, 4, 5, 16, 17, 20, 21, |
104 | 64, 65, 68, 69, 80, 81, 84, 85 }; | 104 | 64, 65, 68, 69, 80, 81, 84, 85 }; |
105 | /* Platform-specific macros to accelerate squaring. */ | 105 | /* Platform-specific macros to accelerate squaring. */ |
106 | #if defined(SIXTY_FOUR_BIT) || defined(SIXTY_FOUR_BIT_LONG) | 106 | #ifdef _LP64 |
107 | #define SQR1(w) \ | 107 | #define SQR1(w) \ |
108 | SQR_tb[(w) >> 60 & 0xF] << 56 | SQR_tb[(w) >> 56 & 0xF] << 48 | \ | 108 | SQR_tb[(w) >> 60 & 0xF] << 56 | SQR_tb[(w) >> 56 & 0xF] << 48 | \ |
109 | SQR_tb[(w) >> 52 & 0xF] << 40 | SQR_tb[(w) >> 48 & 0xF] << 32 | \ | 109 | SQR_tb[(w) >> 52 & 0xF] << 40 | SQR_tb[(w) >> 48 & 0xF] << 32 | \ |
@@ -114,8 +114,7 @@ static const BN_ULONG SQR_tb[16] = | |||
114 | SQR_tb[(w) >> 20 & 0xF] << 40 | SQR_tb[(w) >> 16 & 0xF] << 32 | \ | 114 | SQR_tb[(w) >> 20 & 0xF] << 40 | SQR_tb[(w) >> 16 & 0xF] << 32 | \ |
115 | SQR_tb[(w) >> 12 & 0xF] << 24 | SQR_tb[(w) >> 8 & 0xF] << 16 | \ | 115 | SQR_tb[(w) >> 12 & 0xF] << 24 | SQR_tb[(w) >> 8 & 0xF] << 16 | \ |
116 | SQR_tb[(w) >> 4 & 0xF] << 8 | SQR_tb[(w) & 0xF] | 116 | SQR_tb[(w) >> 4 & 0xF] << 8 | SQR_tb[(w) & 0xF] |
117 | #endif | 117 | #else |
118 | #ifdef THIRTY_TWO_BIT | ||
119 | #define SQR1(w) \ | 118 | #define SQR1(w) \ |
120 | SQR_tb[(w) >> 28 & 0xF] << 24 | SQR_tb[(w) >> 24 & 0xF] << 16 | \ | 119 | SQR_tb[(w) >> 28 & 0xF] << 24 | SQR_tb[(w) >> 24 & 0xF] << 16 | \ |
121 | SQR_tb[(w) >> 20 & 0xF] << 8 | SQR_tb[(w) >> 16 & 0xF] | 120 | SQR_tb[(w) >> 20 & 0xF] << 8 | SQR_tb[(w) >> 16 & 0xF] |
@@ -130,9 +129,9 @@ static const BN_ULONG SQR_tb[16] = | |||
130 | * The caller MUST ensure that the variables have the right amount | 129 | * The caller MUST ensure that the variables have the right amount |
131 | * of space allocated. | 130 | * of space allocated. |
132 | */ | 131 | */ |
133 | #ifdef THIRTY_TWO_BIT | ||
134 | static void bn_GF2m_mul_1x1(BN_ULONG *r1, BN_ULONG *r0, const BN_ULONG a, const BN_ULONG b) | 132 | static void bn_GF2m_mul_1x1(BN_ULONG *r1, BN_ULONG *r0, const BN_ULONG a, const BN_ULONG b) |
135 | { | 133 | { |
134 | #ifndef _LP64 | ||
136 | register BN_ULONG h, l, s; | 135 | register BN_ULONG h, l, s; |
137 | BN_ULONG tab[8], top2b = a >> 30; | 136 | BN_ULONG tab[8], top2b = a >> 30; |
138 | register BN_ULONG a1, a2, a4; | 137 | register BN_ULONG a1, a2, a4; |
@@ -160,11 +159,7 @@ static void bn_GF2m_mul_1x1(BN_ULONG *r1, BN_ULONG *r0, const BN_ULONG a, const | |||
160 | if (top2b & 02) { l ^= b << 31; h ^= b >> 1; } | 159 | if (top2b & 02) { l ^= b << 31; h ^= b >> 1; } |
161 | 160 | ||
162 | *r1 = h; *r0 = l; | 161 | *r1 = h; *r0 = l; |
163 | } | 162 | #else |
164 | #endif | ||
165 | #if defined(SIXTY_FOUR_BIT) || defined(SIXTY_FOUR_BIT_LONG) | ||
166 | static void bn_GF2m_mul_1x1(BN_ULONG *r1, BN_ULONG *r0, const BN_ULONG a, const BN_ULONG b) | ||
167 | { | ||
168 | register BN_ULONG h, l, s; | 163 | register BN_ULONG h, l, s; |
169 | BN_ULONG tab[16], top3b = a >> 61; | 164 | BN_ULONG tab[16], top3b = a >> 61; |
170 | register BN_ULONG a1, a2, a4, a8; | 165 | register BN_ULONG a1, a2, a4, a8; |
@@ -200,8 +195,8 @@ static void bn_GF2m_mul_1x1(BN_ULONG *r1, BN_ULONG *r0, const BN_ULONG a, const | |||
200 | if (top3b & 04) { l ^= b << 63; h ^= b >> 1; } | 195 | if (top3b & 04) { l ^= b << 63; h ^= b >> 1; } |
201 | 196 | ||
202 | *r1 = h; *r0 = l; | 197 | *r1 = h; *r0 = l; |
203 | } | ||
204 | #endif | 198 | #endif |
199 | } | ||
205 | 200 | ||
206 | /* Product of two polynomials a, b each with degree < 2 * BN_BITS2 - 1, | 201 | /* Product of two polynomials a, b each with degree < 2 * BN_BITS2 - 1, |
207 | * result is a polynomial r with degree < 4 * BN_BITS2 - 1 | 202 | * result is a polynomial r with degree < 4 * BN_BITS2 - 1 |
diff --git a/src/lib/libssl/src/crypto/bn/bn_lcl.h b/src/lib/libssl/src/crypto/bn/bn_lcl.h index e46cbc2ef8..c3aa584066 100644 --- a/src/lib/libssl/src/crypto/bn/bn_lcl.h +++ b/src/lib/libssl/src/crypto/bn/bn_lcl.h | |||
@@ -144,26 +144,14 @@ extern "C" { | |||
144 | * (with draws in between). Very small exponents are often selected | 144 | * (with draws in between). Very small exponents are often selected |
145 | * with low Hamming weight, so we use w = 1 for b <= 23. | 145 | * with low Hamming weight, so we use w = 1 for b <= 23. |
146 | */ | 146 | */ |
147 | #if 1 | ||
148 | #define BN_window_bits_for_exponent_size(b) \ | 147 | #define BN_window_bits_for_exponent_size(b) \ |
149 | ((b) > 671 ? 6 : \ | 148 | ((b) > 671 ? 6 : \ |
150 | (b) > 239 ? 5 : \ | 149 | (b) > 239 ? 5 : \ |
151 | (b) > 79 ? 4 : \ | 150 | (b) > 79 ? 4 : \ |
152 | (b) > 23 ? 3 : 1) | 151 | (b) > 23 ? 3 : 1) |
153 | #else | ||
154 | /* Old SSLeay/OpenSSL table. | ||
155 | * Maximum window size was 5, so this table differs for b==1024; | ||
156 | * but it coincides for other interesting values (b==160, b==512). | ||
157 | */ | ||
158 | #define BN_window_bits_for_exponent_size(b) \ | ||
159 | ((b) > 255 ? 5 : \ | ||
160 | (b) > 127 ? 4 : \ | ||
161 | (b) > 17 ? 3 : 1) | ||
162 | #endif | ||
163 | 152 | ||
164 | 153 | ||
165 | 154 | /* BN_mod_exp_mont_consttime is based on the assumption that the | |
166 | /* BN_mod_exp_mont_conttime is based on the assumption that the | ||
167 | * L1 data cache line width of the target processor is at least | 155 | * L1 data cache line width of the target processor is at least |
168 | * the following value. | 156 | * the following value. |
169 | */ | 157 | */ |
@@ -234,7 +222,7 @@ extern "C" { | |||
234 | * | 222 | * |
235 | * <appro@fy.chalmers.se> | 223 | * <appro@fy.chalmers.se> |
236 | */ | 224 | */ |
237 | # if defined(__alpha) && (defined(SIXTY_FOUR_BIT_LONG) || defined(SIXTY_FOUR_BIT)) | 225 | # if defined(__alpha) |
238 | # if defined(__GNUC__) && __GNUC__>=2 | 226 | # if defined(__GNUC__) && __GNUC__>=2 |
239 | # define BN_UMULT_HIGH(a,b) ({ \ | 227 | # define BN_UMULT_HIGH(a,b) ({ \ |
240 | register BN_ULONG ret; \ | 228 | register BN_ULONG ret; \ |
@@ -243,7 +231,7 @@ extern "C" { | |||
243 | : "r"(a), "r"(b)); \ | 231 | : "r"(a), "r"(b)); \ |
244 | ret; }) | 232 | ret; }) |
245 | # endif /* compiler */ | 233 | # endif /* compiler */ |
246 | # elif defined(_ARCH_PPC) && defined(__64BIT__) && defined(SIXTY_FOUR_BIT_LONG) | 234 | # elif defined(_ARCH_PPC) && defined(_LP64) |
247 | # if defined(__GNUC__) && __GNUC__>=2 | 235 | # if defined(__GNUC__) && __GNUC__>=2 |
248 | # define BN_UMULT_HIGH(a,b) ({ \ | 236 | # define BN_UMULT_HIGH(a,b) ({ \ |
249 | register BN_ULONG ret; \ | 237 | register BN_ULONG ret; \ |
@@ -252,8 +240,7 @@ extern "C" { | |||
252 | : "r"(a), "r"(b)); \ | 240 | : "r"(a), "r"(b)); \ |
253 | ret; }) | 241 | ret; }) |
254 | # endif /* compiler */ | 242 | # endif /* compiler */ |
255 | # elif (defined(__x86_64) || defined(__x86_64__)) && \ | 243 | # elif defined(__x86_64) || defined(__x86_64__) |
256 | (defined(SIXTY_FOUR_BIT_LONG) || defined(SIXTY_FOUR_BIT)) | ||
257 | # if defined(__GNUC__) && __GNUC__>=2 | 244 | # if defined(__GNUC__) && __GNUC__>=2 |
258 | # define BN_UMULT_HIGH(a,b) ({ \ | 245 | # define BN_UMULT_HIGH(a,b) ({ \ |
259 | register BN_ULONG ret,discard; \ | 246 | register BN_ULONG ret,discard; \ |
@@ -268,7 +255,7 @@ extern "C" { | |||
268 | : "a"(a),"g"(b) \ | 255 | : "a"(a),"g"(b) \ |
269 | : "cc"); | 256 | : "cc"); |
270 | # endif | 257 | # endif |
271 | # elif defined(__mips) && (defined(SIXTY_FOUR_BIT) || defined(SIXTY_FOUR_BIT_LONG)) | 258 | # elif defined(__mips) && defined(_LP64) |
272 | # if defined(__GNUC__) && __GNUC__>=2 | 259 | # if defined(__GNUC__) && __GNUC__>=2 |
273 | # if __GNUC__>=4 && __GNUC_MINOR__>=4 /* "h" constraint is no more since 4.4 */ | 260 | # if __GNUC__>=4 && __GNUC_MINOR__>=4 /* "h" constraint is no more since 4.4 */ |
274 | # define BN_UMULT_HIGH(a,b) (((__uint128_t)(a)*(b))>>64) | 261 | # define BN_UMULT_HIGH(a,b) (((__uint128_t)(a)*(b))>>64) |
@@ -397,10 +384,6 @@ extern "C" { | |||
397 | #define HBITS(a) (((a)>>BN_BITS4)&BN_MASK2l) | 384 | #define HBITS(a) (((a)>>BN_BITS4)&BN_MASK2l) |
398 | #define L2HBITS(a) (((a)<<BN_BITS4)&BN_MASK2) | 385 | #define L2HBITS(a) (((a)<<BN_BITS4)&BN_MASK2) |
399 | 386 | ||
400 | #define LLBITS(a) ((a)&BN_MASKl) | ||
401 | #define LHBITS(a) (((a)>>BN_BITS2)&BN_MASKl) | ||
402 | #define LL2HBITS(a) ((BN_ULLONG)((a)&BN_MASKl)<<BN_BITS2) | ||
403 | |||
404 | #define mul64(l,h,bl,bh) \ | 387 | #define mul64(l,h,bl,bh) \ |
405 | { \ | 388 | { \ |
406 | BN_ULONG m,m1,lt,ht; \ | 389 | BN_ULONG m,m1,lt,ht; \ |
diff --git a/src/lib/libssl/src/crypto/bn/bn_lib.c b/src/lib/libssl/src/crypto/bn/bn_lib.c index c8de547ba5..9787a31dbb 100644 --- a/src/lib/libssl/src/crypto/bn/bn_lib.c +++ b/src/lib/libssl/src/crypto/bn/bn_lib.c | |||
@@ -160,7 +160,7 @@ int BN_num_bits_word(BN_ULONG l) | |||
160 | 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, | 160 | 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, |
161 | }; | 161 | }; |
162 | 162 | ||
163 | #if defined(SIXTY_FOUR_BIT_LONG) | 163 | #ifdef _LP64 |
164 | if (l & 0xffffffff00000000L) | 164 | if (l & 0xffffffff00000000L) |
165 | { | 165 | { |
166 | if (l & 0xffff000000000000L) | 166 | if (l & 0xffff000000000000L) |
@@ -181,32 +181,8 @@ int BN_num_bits_word(BN_ULONG l) | |||
181 | } | 181 | } |
182 | } | 182 | } |
183 | else | 183 | else |
184 | #else | ||
185 | #ifdef SIXTY_FOUR_BIT | ||
186 | if (l & 0xffffffff00000000LL) | ||
187 | { | ||
188 | if (l & 0xffff000000000000LL) | ||
189 | { | ||
190 | if (l & 0xff00000000000000LL) | ||
191 | { | ||
192 | return(bits[(int)(l>>56)]+56); | ||
193 | } | ||
194 | else return(bits[(int)(l>>48)]+48); | ||
195 | } | ||
196 | else | ||
197 | { | ||
198 | if (l & 0x0000ff0000000000LL) | ||
199 | { | ||
200 | return(bits[(int)(l>>40)]+40); | ||
201 | } | ||
202 | else return(bits[(int)(l>>32)]+32); | ||
203 | } | ||
204 | } | ||
205 | else | ||
206 | #endif | ||
207 | #endif | 184 | #endif |
208 | { | 185 | { |
209 | #if defined(THIRTY_TWO_BIT) || defined(SIXTY_FOUR_BIT) || defined(SIXTY_FOUR_BIT_LONG) | ||
210 | if (l & 0xffff0000L) | 186 | if (l & 0xffff0000L) |
211 | { | 187 | { |
212 | if (l & 0xff000000L) | 188 | if (l & 0xff000000L) |
@@ -214,13 +190,10 @@ int BN_num_bits_word(BN_ULONG l) | |||
214 | else return(bits[(int)(l>>16L)]+16); | 190 | else return(bits[(int)(l>>16L)]+16); |
215 | } | 191 | } |
216 | else | 192 | else |
217 | #endif | ||
218 | { | 193 | { |
219 | #if defined(THIRTY_TWO_BIT) || defined(SIXTY_FOUR_BIT) || defined(SIXTY_FOUR_BIT_LONG) | ||
220 | if (l & 0xff00L) | 194 | if (l & 0xff00L) |
221 | return(bits[(int)(l>>8)]+8); | 195 | return(bits[(int)(l>>8)]+8); |
222 | else | 196 | else |
223 | #endif | ||
224 | return(bits[(int)(l )] ); | 197 | return(bits[(int)(l )] ); |
225 | } | 198 | } |
226 | } | 199 | } |
diff --git a/src/lib/libssl/src/crypto/bn/bn_mod.c b/src/lib/libssl/src/crypto/bn/bn_mod.c index 77d6ddb91a..6c439402dd 100644 --- a/src/lib/libssl/src/crypto/bn/bn_mod.c +++ b/src/lib/libssl/src/crypto/bn/bn_mod.c | |||
@@ -115,15 +115,6 @@ | |||
115 | #include "bn_lcl.h" | 115 | #include "bn_lcl.h" |
116 | 116 | ||
117 | 117 | ||
118 | #if 0 /* now just a #define */ | ||
119 | int BN_mod(BIGNUM *rem, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx) | ||
120 | { | ||
121 | return(BN_div(NULL,rem,m,d,ctx)); | ||
122 | /* note that rem->neg == m->neg (unless the remainder is zero) */ | ||
123 | } | ||
124 | #endif | ||
125 | |||
126 | |||
127 | int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx) | 118 | int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx) |
128 | { | 119 | { |
129 | /* like BN_mod, but returns non-negative remainder | 120 | /* like BN_mod, but returns non-negative remainder |
diff --git a/src/lib/libssl/src/crypto/bn/bn_nist.c b/src/lib/libssl/src/crypto/bn/bn_nist.c index 4d4a7b86df..d793644e27 100644 --- a/src/lib/libssl/src/crypto/bn/bn_nist.c +++ b/src/lib/libssl/src/crypto/bn/bn_nist.c | |||
@@ -321,7 +321,7 @@ static void nist_cp_bn(BN_ULONG *dst, const BN_ULONG *src, int top) | |||
321 | #define bn_32_set_0(to, n) (((n)&1)?(to[(n)/2]&=BN_MASK2l):(to[(n)/2]=0)); | 321 | #define bn_32_set_0(to, n) (((n)&1)?(to[(n)/2]&=BN_MASK2l):(to[(n)/2]=0)); |
322 | #define bn_cp_32(to,n,from,m) ((m)>=0)?bn_cp_32_naked(to,n,from,m):bn_32_set_0(to,n) | 322 | #define bn_cp_32(to,n,from,m) ((m)>=0)?bn_cp_32_naked(to,n,from,m):bn_32_set_0(to,n) |
323 | # if _BYTE_ORDER == _LITTLE_ENDIAN | 323 | # if _BYTE_ORDER == _LITTLE_ENDIAN |
324 | # if defined(__arch64__) | 324 | # if defined(_LP64) |
325 | # define NIST_INT64 long | 325 | # define NIST_INT64 long |
326 | # else | 326 | # else |
327 | # define NIST_INT64 long long | 327 | # define NIST_INT64 long long |
@@ -340,9 +340,7 @@ static void nist_cp_bn(BN_ULONG *dst, const BN_ULONG *src, int top) | |||
340 | } | 340 | } |
341 | #define bn_cp_32(to, n, from, m) (to)[n] = (m>=0)?((from)[m]):0; | 341 | #define bn_cp_32(to, n, from, m) (to)[n] = (m>=0)?((from)[m]):0; |
342 | #define bn_32_set_0(to, n) (to)[n] = (BN_ULONG)0; | 342 | #define bn_32_set_0(to, n) (to)[n] = (BN_ULONG)0; |
343 | # if defined(_WIN32) && !defined(__GNUC__) | 343 | # if defined(BN_LLONG) |
344 | # define NIST_INT64 __int64 | ||
345 | # elif defined(BN_LLONG) | ||
346 | # define NIST_INT64 long long | 344 | # define NIST_INT64 long long |
347 | # endif | 345 | # endif |
348 | #endif /* BN_BITS2 != 64 */ | 346 | #endif /* BN_BITS2 != 64 */ |
@@ -594,7 +592,7 @@ int BN_nist_mod_224(BIGNUM *r, const BIGNUM *a, const BIGNUM *field, | |||
594 | } | 592 | } |
595 | else if (carry < 0) | 593 | else if (carry < 0) |
596 | { | 594 | { |
597 | /* it's a bit more comlicated logic in this case. | 595 | /* it's a bit more complicated logic in this case. |
598 | * if bn_add_words yields no carry, then result | 596 | * if bn_add_words yields no carry, then result |
599 | * has to be adjusted by unconditionally *adding* | 597 | * has to be adjusted by unconditionally *adding* |
600 | * the modulus. but if it does, then result has | 598 | * the modulus. but if it does, then result has |
diff --git a/src/lib/libssl/src/crypto/bn/bn_prime.h b/src/lib/libssl/src/crypto/bn/bn_prime.h index 51d2194feb..ccdeca5afa 100644 --- a/src/lib/libssl/src/crypto/bn/bn_prime.h +++ b/src/lib/libssl/src/crypto/bn/bn_prime.h | |||
@@ -56,13 +56,8 @@ | |||
56 | * [including the GNU Public Licence.] | 56 | * [including the GNU Public Licence.] |
57 | */ | 57 | */ |
58 | 58 | ||
59 | #ifndef EIGHT_BIT | ||
60 | #define NUMPRIMES 2048 | 59 | #define NUMPRIMES 2048 |
61 | typedef unsigned short prime_t; | 60 | typedef unsigned short prime_t; |
62 | #else | ||
63 | #define NUMPRIMES 54 | ||
64 | typedef unsigned char prime_t; | ||
65 | #endif | ||
66 | static const prime_t primes[NUMPRIMES]= | 61 | static const prime_t primes[NUMPRIMES]= |
67 | { | 62 | { |
68 | 2, 3, 5, 7, 11, 13, 17, 19, | 63 | 2, 3, 5, 7, 11, 13, 17, 19, |
@@ -71,9 +66,7 @@ static const prime_t primes[NUMPRIMES]= | |||
71 | 97, 101, 103, 107, 109, 113, 127, 131, | 66 | 97, 101, 103, 107, 109, 113, 127, 131, |
72 | 137, 139, 149, 151, 157, 163, 167, 173, | 67 | 137, 139, 149, 151, 157, 163, 167, 173, |
73 | 179, 181, 191, 193, 197, 199, 211, 223, | 68 | 179, 181, 191, 193, 197, 199, 211, 223, |
74 | 227, 229, 233, 239, 241, 251, | 69 | 227, 229, 233, 239, 241, 251, 257, 263, |
75 | #ifndef EIGHT_BIT | ||
76 | 257, 263, | ||
77 | 269, 271, 277, 281, 283, 293, 307, 311, | 70 | 269, 271, 277, 281, 283, 293, 307, 311, |
78 | 313, 317, 331, 337, 347, 349, 353, 359, | 71 | 313, 317, 331, 337, 347, 349, 353, 359, |
79 | 367, 373, 379, 383, 389, 397, 401, 409, | 72 | 367, 373, 379, 383, 389, 397, 401, 409, |
@@ -323,5 +316,4 @@ static const prime_t primes[NUMPRIMES]= | |||
323 | 17609,17623,17627,17657,17659,17669,17681,17683, | 316 | 17609,17623,17627,17657,17659,17669,17681,17683, |
324 | 17707,17713,17729,17737,17747,17749,17761,17783, | 317 | 17707,17713,17729,17737,17747,17749,17761,17783, |
325 | 17789,17791,17807,17827,17837,17839,17851,17863, | 318 | 17789,17791,17807,17827,17837,17839,17851,17863, |
326 | #endif | ||
327 | }; | 319 | }; |
diff --git a/src/lib/libssl/src/crypto/bn/bn_prime.pl b/src/lib/libssl/src/crypto/bn/bn_prime.pl index 3fafb6f3e9..eb73f0bfa6 100644 --- a/src/lib/libssl/src/crypto/bn/bn_prime.pl +++ b/src/lib/libssl/src/crypto/bn/bn_prime.pl | |||
@@ -90,30 +90,14 @@ print <<\EOF; | |||
90 | 90 | ||
91 | EOF | 91 | EOF |
92 | 92 | ||
93 | for ($i=0; $i <= $#primes; $i++) | ||
94 | { | ||
95 | if ($primes[$i] > 256) | ||
96 | { | ||
97 | $eight=$i; | ||
98 | last; | ||
99 | } | ||
100 | } | ||
101 | |||
102 | printf "#ifndef EIGHT_BIT\n"; | ||
103 | printf "#define NUMPRIMES %d\n",$num; | 93 | printf "#define NUMPRIMES %d\n",$num; |
104 | printf "typedef unsigned short prime_t;\n"; | 94 | printf "typedef unsigned short prime_t;\n"; |
105 | printf "#else\n"; | 95 | print "static const prime_t primes[NUMPRIMES]=\n{\n\t"; |
106 | printf "#define NUMPRIMES %d\n",$eight; | ||
107 | printf "typedef unsigned char prime_t;\n"; | ||
108 | printf "#endif\n"; | ||
109 | print "static const prime_t primes[NUMPRIMES]=\n\t{\n\t"; | ||
110 | $init=0; | ||
111 | for ($i=0; $i <= $#primes; $i++) | 96 | for ($i=0; $i <= $#primes; $i++) |
112 | { | 97 | { |
113 | printf "\n#ifndef EIGHT_BIT\n\t" if ($primes[$i] > 256) && !($init++); | ||
114 | printf("\n\t") if (($i%8) == 0) && ($i != 0); | 98 | printf("\n\t") if (($i%8) == 0) && ($i != 0); |
115 | printf("%4d,",$primes[$i]); | 99 | printf("%4d,",$primes[$i]); |
116 | } | 100 | } |
117 | print "\n#endif\n\t};\n"; | 101 | print "\n};\n"; |
118 | 102 | ||
119 | 103 | ||