summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lib/libcrypto/aes/aes_wrap.c12
-rw-r--r--src/lib/libcrypto/aes/asm/aes-armv4.pl397
-rw-r--r--src/lib/libcrypto/alphacpuid.pl126
-rw-r--r--src/lib/libcrypto/asn1/ameth_lib.c2
-rw-r--r--src/lib/libcrypto/asn1/bio_ndef.c3
-rw-r--r--src/lib/libcrypto/bn/asm/alpha-mont.pl36
-rw-r--r--src/lib/libcrypto/bn/asm/s390x-mont.pl4
-rwxr-xr-xsrc/lib/libcrypto/bn/asm/s390x.S86
-rw-r--r--src/lib/libcrypto/doc/EVP_PKEY_verify.pod2
-rw-r--r--src/lib/libcrypto/dsa/dsa_pmeth.c1
-rw-r--r--src/lib/libcrypto/ec/ec2_mult.c13
-rw-r--r--src/lib/libcrypto/ec/ec_key.c8
-rw-r--r--src/lib/libcrypto/ecdh/ech_lib.c3
-rw-r--r--src/lib/libcrypto/ecdsa/ecs_lib.c2
-rw-r--r--src/lib/libcrypto/ecdsa/ecs_ossl.c8
-rw-r--r--src/lib/libcrypto/evp/m_sigver.c4
-rw-r--r--src/lib/libcrypto/evp/pmeth_lib.c2
-rw-r--r--src/lib/libcrypto/hmac/hm_pmeth.c2
-rw-r--r--src/lib/libcrypto/pem/pvkfmt.c10
-rw-r--r--src/lib/libcrypto/sha/asm/sha1-armv4-large.pl76
-rw-r--r--src/lib/libcrypto/sha/asm/sha1-sparcv9.pl1
-rw-r--r--src/lib/libcrypto/sha/asm/sha1-sparcv9a.pl1
-rw-r--r--src/lib/libcrypto/sha/asm/sha256-armv4.pl33
-rw-r--r--src/lib/libcrypto/sha/asm/sha512-armv4.pl32
-rw-r--r--src/lib/libcrypto/sha/asm/sha512-sparcv9.pl1
-rw-r--r--src/lib/libcrypto/sparccpuid.S84
-rw-r--r--src/lib/libcrypto/sparcv9cap.c97
-rw-r--r--src/lib/libcrypto/ts/ts_verify_ctx.c5
-rw-r--r--src/lib/libcrypto/x509v3/v3_ncons.c1
-rw-r--r--src/lib/libssl/d1_both.c28
-rw-r--r--src/lib/libssl/d1_enc.c6
-rw-r--r--src/lib/libssl/d1_lib.c65
-rw-r--r--src/lib/libssl/test/cms-test.pl94
33 files changed, 799 insertions, 446 deletions
diff --git a/src/lib/libcrypto/aes/aes_wrap.c b/src/lib/libcrypto/aes/aes_wrap.c
index 9feacd65d8..e2d73d37ce 100644
--- a/src/lib/libcrypto/aes/aes_wrap.c
+++ b/src/lib/libcrypto/aes/aes_wrap.c
@@ -85,9 +85,9 @@ int AES_wrap_key(AES_KEY *key, const unsigned char *iv,
85 A[7] ^= (unsigned char)(t & 0xff); 85 A[7] ^= (unsigned char)(t & 0xff);
86 if (t > 0xff) 86 if (t > 0xff)
87 { 87 {
88 A[6] ^= (unsigned char)((t & 0xff) >> 8); 88 A[6] ^= (unsigned char)((t >> 8) & 0xff);
89 A[5] ^= (unsigned char)((t & 0xff) >> 16); 89 A[5] ^= (unsigned char)((t >> 16) & 0xff);
90 A[4] ^= (unsigned char)((t & 0xff) >> 24); 90 A[4] ^= (unsigned char)((t >> 24) & 0xff);
91 } 91 }
92 memcpy(R, B + 8, 8); 92 memcpy(R, B + 8, 8);
93 } 93 }
@@ -119,9 +119,9 @@ int AES_unwrap_key(AES_KEY *key, const unsigned char *iv,
119 A[7] ^= (unsigned char)(t & 0xff); 119 A[7] ^= (unsigned char)(t & 0xff);
120 if (t > 0xff) 120 if (t > 0xff)
121 { 121 {
122 A[6] ^= (unsigned char)((t & 0xff) >> 8); 122 A[6] ^= (unsigned char)((t >> 8) & 0xff);
123 A[5] ^= (unsigned char)((t & 0xff) >> 16); 123 A[5] ^= (unsigned char)((t >> 16) & 0xff);
124 A[4] ^= (unsigned char)((t & 0xff) >> 24); 124 A[4] ^= (unsigned char)((t >> 24) & 0xff);
125 } 125 }
126 memcpy(B + 8, R, 8); 126 memcpy(B + 8, R, 8);
127 AES_decrypt(B, B, key); 127 AES_decrypt(B, B, key);
diff --git a/src/lib/libcrypto/aes/asm/aes-armv4.pl b/src/lib/libcrypto/aes/asm/aes-armv4.pl
index 690244111a..c51ee1fbf6 100644
--- a/src/lib/libcrypto/aes/asm/aes-armv4.pl
+++ b/src/lib/libcrypto/aes/asm/aes-armv4.pl
@@ -16,12 +16,20 @@
16# allows to merge logical or arithmetic operation with shift or rotate 16# allows to merge logical or arithmetic operation with shift or rotate
17# in one instruction and emit combined result every cycle. The module 17# in one instruction and emit combined result every cycle. The module
18# is endian-neutral. The performance is ~42 cycles/byte for 128-bit 18# is endian-neutral. The performance is ~42 cycles/byte for 128-bit
19# key. 19# key [on single-issue Xscale PXA250 core].
20 20
21# May 2007. 21# May 2007.
22# 22#
23# AES_set_[en|de]crypt_key is added. 23# AES_set_[en|de]crypt_key is added.
24 24
25# July 2010.
26#
27# Rescheduling for dual-issue pipeline resulted in 12% improvement on
28# Cortex A8 core and ~25 cycles per byte processed with 128-bit key.
29
30while (($output=shift) && ($output!~/^\w[\w\-]*\.\w+$/)) {}
31open STDOUT,">$output";
32
25$s0="r0"; 33$s0="r0";
26$s1="r1"; 34$s1="r1";
27$s2="r2"; 35$s2="r2";
@@ -164,24 +172,24 @@ AES_encrypt:
164 ldrb $t2,[$rounds,#1] 172 ldrb $t2,[$rounds,#1]
165 ldrb $t3,[$rounds,#0] 173 ldrb $t3,[$rounds,#0]
166 orr $s0,$s0,$t1,lsl#8 174 orr $s0,$s0,$t1,lsl#8
167 orr $s0,$s0,$t2,lsl#16
168 orr $s0,$s0,$t3,lsl#24
169 ldrb $s1,[$rounds,#7] 175 ldrb $s1,[$rounds,#7]
176 orr $s0,$s0,$t2,lsl#16
170 ldrb $t1,[$rounds,#6] 177 ldrb $t1,[$rounds,#6]
178 orr $s0,$s0,$t3,lsl#24
171 ldrb $t2,[$rounds,#5] 179 ldrb $t2,[$rounds,#5]
172 ldrb $t3,[$rounds,#4] 180 ldrb $t3,[$rounds,#4]
173 orr $s1,$s1,$t1,lsl#8 181 orr $s1,$s1,$t1,lsl#8
174 orr $s1,$s1,$t2,lsl#16
175 orr $s1,$s1,$t3,lsl#24
176 ldrb $s2,[$rounds,#11] 182 ldrb $s2,[$rounds,#11]
183 orr $s1,$s1,$t2,lsl#16
177 ldrb $t1,[$rounds,#10] 184 ldrb $t1,[$rounds,#10]
185 orr $s1,$s1,$t3,lsl#24
178 ldrb $t2,[$rounds,#9] 186 ldrb $t2,[$rounds,#9]
179 ldrb $t3,[$rounds,#8] 187 ldrb $t3,[$rounds,#8]
180 orr $s2,$s2,$t1,lsl#8 188 orr $s2,$s2,$t1,lsl#8
181 orr $s2,$s2,$t2,lsl#16
182 orr $s2,$s2,$t3,lsl#24
183 ldrb $s3,[$rounds,#15] 189 ldrb $s3,[$rounds,#15]
190 orr $s2,$s2,$t2,lsl#16
184 ldrb $t1,[$rounds,#14] 191 ldrb $t1,[$rounds,#14]
192 orr $s2,$s2,$t3,lsl#24
185 ldrb $t2,[$rounds,#13] 193 ldrb $t2,[$rounds,#13]
186 ldrb $t3,[$rounds,#12] 194 ldrb $t3,[$rounds,#12]
187 orr $s3,$s3,$t1,lsl#8 195 orr $s3,$s3,$t1,lsl#8
@@ -196,24 +204,24 @@ AES_encrypt:
196 mov $t3,$s0,lsr#8 204 mov $t3,$s0,lsr#8
197 strb $t1,[$rounds,#0] 205 strb $t1,[$rounds,#0]
198 strb $t2,[$rounds,#1] 206 strb $t2,[$rounds,#1]
199 strb $t3,[$rounds,#2]
200 strb $s0,[$rounds,#3]
201 mov $t1,$s1,lsr#24 207 mov $t1,$s1,lsr#24
208 strb $t3,[$rounds,#2]
202 mov $t2,$s1,lsr#16 209 mov $t2,$s1,lsr#16
210 strb $s0,[$rounds,#3]
203 mov $t3,$s1,lsr#8 211 mov $t3,$s1,lsr#8
204 strb $t1,[$rounds,#4] 212 strb $t1,[$rounds,#4]
205 strb $t2,[$rounds,#5] 213 strb $t2,[$rounds,#5]
206 strb $t3,[$rounds,#6]
207 strb $s1,[$rounds,#7]
208 mov $t1,$s2,lsr#24 214 mov $t1,$s2,lsr#24
215 strb $t3,[$rounds,#6]
209 mov $t2,$s2,lsr#16 216 mov $t2,$s2,lsr#16
217 strb $s1,[$rounds,#7]
210 mov $t3,$s2,lsr#8 218 mov $t3,$s2,lsr#8
211 strb $t1,[$rounds,#8] 219 strb $t1,[$rounds,#8]
212 strb $t2,[$rounds,#9] 220 strb $t2,[$rounds,#9]
213 strb $t3,[$rounds,#10]
214 strb $s2,[$rounds,#11]
215 mov $t1,$s3,lsr#24 221 mov $t1,$s3,lsr#24
222 strb $t3,[$rounds,#10]
216 mov $t2,$s3,lsr#16 223 mov $t2,$s3,lsr#16
224 strb $s2,[$rounds,#11]
217 mov $t3,$s3,lsr#8 225 mov $t3,$s3,lsr#8
218 strb $t1,[$rounds,#12] 226 strb $t1,[$rounds,#12]
219 strb $t2,[$rounds,#13] 227 strb $t2,[$rounds,#13]
@@ -230,141 +238,137 @@ AES_encrypt:
230.align 2 238.align 2
231_armv4_AES_encrypt: 239_armv4_AES_encrypt:
232 str lr,[sp,#-4]! @ push lr 240 str lr,[sp,#-4]! @ push lr
233 ldr $t1,[$key],#16 241 ldmia $key!,{$t1-$i1}
234 ldr $t2,[$key,#-12]
235 ldr $t3,[$key,#-8]
236 ldr $i1,[$key,#-4]
237 ldr $rounds,[$key,#240-16]
238 eor $s0,$s0,$t1 242 eor $s0,$s0,$t1
243 ldr $rounds,[$key,#240-16]
239 eor $s1,$s1,$t2 244 eor $s1,$s1,$t2
240 eor $s2,$s2,$t3 245 eor $s2,$s2,$t3
241 eor $s3,$s3,$i1 246 eor $s3,$s3,$i1
242 sub $rounds,$rounds,#1 247 sub $rounds,$rounds,#1
243 mov lr,#255 248 mov lr,#255
244 249
245.Lenc_loop: 250 and $i1,lr,$s0
246 and $i2,lr,$s0,lsr#8 251 and $i2,lr,$s0,lsr#8
247 and $i3,lr,$s0,lsr#16 252 and $i3,lr,$s0,lsr#16
248 and $i1,lr,$s0
249 mov $s0,$s0,lsr#24 253 mov $s0,$s0,lsr#24
254.Lenc_loop:
250 ldr $t1,[$tbl,$i1,lsl#2] @ Te3[s0>>0] 255 ldr $t1,[$tbl,$i1,lsl#2] @ Te3[s0>>0]
251 ldr $s0,[$tbl,$s0,lsl#2] @ Te0[s0>>24]
252 ldr $t2,[$tbl,$i2,lsl#2] @ Te2[s0>>8]
253 ldr $t3,[$tbl,$i3,lsl#2] @ Te1[s0>>16]
254
255 and $i1,lr,$s1,lsr#16 @ i0 256 and $i1,lr,$s1,lsr#16 @ i0
257 ldr $t2,[$tbl,$i2,lsl#2] @ Te2[s0>>8]
256 and $i2,lr,$s1 258 and $i2,lr,$s1
259 ldr $t3,[$tbl,$i3,lsl#2] @ Te1[s0>>16]
257 and $i3,lr,$s1,lsr#8 260 and $i3,lr,$s1,lsr#8
261 ldr $s0,[$tbl,$s0,lsl#2] @ Te0[s0>>24]
258 mov $s1,$s1,lsr#24 262 mov $s1,$s1,lsr#24
263
259 ldr $i1,[$tbl,$i1,lsl#2] @ Te1[s1>>16] 264 ldr $i1,[$tbl,$i1,lsl#2] @ Te1[s1>>16]
260 ldr $s1,[$tbl,$s1,lsl#2] @ Te0[s1>>24]
261 ldr $i2,[$tbl,$i2,lsl#2] @ Te3[s1>>0] 265 ldr $i2,[$tbl,$i2,lsl#2] @ Te3[s1>>0]
262 ldr $i3,[$tbl,$i3,lsl#2] @ Te2[s1>>8] 266 ldr $i3,[$tbl,$i3,lsl#2] @ Te2[s1>>8]
263 eor $s0,$s0,$i1,ror#8 267 eor $s0,$s0,$i1,ror#8
264 eor $s1,$s1,$t1,ror#24 268 ldr $s1,[$tbl,$s1,lsl#2] @ Te0[s1>>24]
265 eor $t2,$t2,$i2,ror#8
266 eor $t3,$t3,$i3,ror#8
267
268 and $i1,lr,$s2,lsr#8 @ i0 269 and $i1,lr,$s2,lsr#8 @ i0
270 eor $t2,$t2,$i2,ror#8
269 and $i2,lr,$s2,lsr#16 @ i1 271 and $i2,lr,$s2,lsr#16 @ i1
272 eor $t3,$t3,$i3,ror#8
270 and $i3,lr,$s2 273 and $i3,lr,$s2
271 mov $s2,$s2,lsr#24 274 eor $s1,$s1,$t1,ror#24
272 ldr $i1,[$tbl,$i1,lsl#2] @ Te2[s2>>8] 275 ldr $i1,[$tbl,$i1,lsl#2] @ Te2[s2>>8]
276 mov $s2,$s2,lsr#24
277
273 ldr $i2,[$tbl,$i2,lsl#2] @ Te1[s2>>16] 278 ldr $i2,[$tbl,$i2,lsl#2] @ Te1[s2>>16]
274 ldr $s2,[$tbl,$s2,lsl#2] @ Te0[s2>>24]
275 ldr $i3,[$tbl,$i3,lsl#2] @ Te3[s2>>0] 279 ldr $i3,[$tbl,$i3,lsl#2] @ Te3[s2>>0]
276 eor $s0,$s0,$i1,ror#16 280 eor $s0,$s0,$i1,ror#16
277 eor $s1,$s1,$i2,ror#8 281 ldr $s2,[$tbl,$s2,lsl#2] @ Te0[s2>>24]
278 eor $s2,$s2,$t2,ror#16
279 eor $t3,$t3,$i3,ror#16
280
281 and $i1,lr,$s3 @ i0 282 and $i1,lr,$s3 @ i0
283 eor $s1,$s1,$i2,ror#8
282 and $i2,lr,$s3,lsr#8 @ i1 284 and $i2,lr,$s3,lsr#8 @ i1
285 eor $t3,$t3,$i3,ror#16
283 and $i3,lr,$s3,lsr#16 @ i2 286 and $i3,lr,$s3,lsr#16 @ i2
284 mov $s3,$s3,lsr#24 287 eor $s2,$s2,$t2,ror#16
285 ldr $i1,[$tbl,$i1,lsl#2] @ Te3[s3>>0] 288 ldr $i1,[$tbl,$i1,lsl#2] @ Te3[s3>>0]
289 mov $s3,$s3,lsr#24
290
286 ldr $i2,[$tbl,$i2,lsl#2] @ Te2[s3>>8] 291 ldr $i2,[$tbl,$i2,lsl#2] @ Te2[s3>>8]
287 ldr $i3,[$tbl,$i3,lsl#2] @ Te1[s3>>16] 292 ldr $i3,[$tbl,$i3,lsl#2] @ Te1[s3>>16]
288 ldr $s3,[$tbl,$s3,lsl#2] @ Te0[s3>>24]
289 eor $s0,$s0,$i1,ror#24 293 eor $s0,$s0,$i1,ror#24
294 ldr $s3,[$tbl,$s3,lsl#2] @ Te0[s3>>24]
290 eor $s1,$s1,$i2,ror#16 295 eor $s1,$s1,$i2,ror#16
296 ldr $i1,[$key],#16
291 eor $s2,$s2,$i3,ror#8 297 eor $s2,$s2,$i3,ror#8
298 ldr $t1,[$key,#-12]
292 eor $s3,$s3,$t3,ror#8 299 eor $s3,$s3,$t3,ror#8
293 300
294 ldr $t1,[$key],#16 301 ldr $t2,[$key,#-8]
295 ldr $t2,[$key,#-12] 302 eor $s0,$s0,$i1
296 ldr $t3,[$key,#-8] 303 ldr $t3,[$key,#-4]
297 ldr $i1,[$key,#-4] 304 and $i1,lr,$s0
298 eor $s0,$s0,$t1 305 eor $s1,$s1,$t1
299 eor $s1,$s1,$t2 306 and $i2,lr,$s0,lsr#8
300 eor $s2,$s2,$t3 307 eor $s2,$s2,$t2
301 eor $s3,$s3,$i1 308 and $i3,lr,$s0,lsr#16
309 eor $s3,$s3,$t3
310 mov $s0,$s0,lsr#24
302 311
303 subs $rounds,$rounds,#1 312 subs $rounds,$rounds,#1
304 bne .Lenc_loop 313 bne .Lenc_loop
305 314
306 add $tbl,$tbl,#2 315 add $tbl,$tbl,#2
307 316
308 and $i1,lr,$s0
309 and $i2,lr,$s0,lsr#8
310 and $i3,lr,$s0,lsr#16
311 mov $s0,$s0,lsr#24
312 ldrb $t1,[$tbl,$i1,lsl#2] @ Te4[s0>>0] 317 ldrb $t1,[$tbl,$i1,lsl#2] @ Te4[s0>>0]
313 ldrb $s0,[$tbl,$s0,lsl#2] @ Te4[s0>>24]
314 ldrb $t2,[$tbl,$i2,lsl#2] @ Te4[s0>>8]
315 ldrb $t3,[$tbl,$i3,lsl#2] @ Te4[s0>>16]
316
317 and $i1,lr,$s1,lsr#16 @ i0 318 and $i1,lr,$s1,lsr#16 @ i0
319 ldrb $t2,[$tbl,$i2,lsl#2] @ Te4[s0>>8]
318 and $i2,lr,$s1 320 and $i2,lr,$s1
321 ldrb $t3,[$tbl,$i3,lsl#2] @ Te4[s0>>16]
319 and $i3,lr,$s1,lsr#8 322 and $i3,lr,$s1,lsr#8
323 ldrb $s0,[$tbl,$s0,lsl#2] @ Te4[s0>>24]
320 mov $s1,$s1,lsr#24 324 mov $s1,$s1,lsr#24
325
321 ldrb $i1,[$tbl,$i1,lsl#2] @ Te4[s1>>16] 326 ldrb $i1,[$tbl,$i1,lsl#2] @ Te4[s1>>16]
322 ldrb $s1,[$tbl,$s1,lsl#2] @ Te4[s1>>24]
323 ldrb $i2,[$tbl,$i2,lsl#2] @ Te4[s1>>0] 327 ldrb $i2,[$tbl,$i2,lsl#2] @ Te4[s1>>0]
324 ldrb $i3,[$tbl,$i3,lsl#2] @ Te4[s1>>8] 328 ldrb $i3,[$tbl,$i3,lsl#2] @ Te4[s1>>8]
325 eor $s0,$i1,$s0,lsl#8 329 eor $s0,$i1,$s0,lsl#8
326 eor $s1,$t1,$s1,lsl#24 330 ldrb $s1,[$tbl,$s1,lsl#2] @ Te4[s1>>24]
327 eor $t2,$i2,$t2,lsl#8
328 eor $t3,$i3,$t3,lsl#8
329
330 and $i1,lr,$s2,lsr#8 @ i0 331 and $i1,lr,$s2,lsr#8 @ i0
332 eor $t2,$i2,$t2,lsl#8
331 and $i2,lr,$s2,lsr#16 @ i1 333 and $i2,lr,$s2,lsr#16 @ i1
334 eor $t3,$i3,$t3,lsl#8
332 and $i3,lr,$s2 335 and $i3,lr,$s2
333 mov $s2,$s2,lsr#24 336 eor $s1,$t1,$s1,lsl#24
334 ldrb $i1,[$tbl,$i1,lsl#2] @ Te4[s2>>8] 337 ldrb $i1,[$tbl,$i1,lsl#2] @ Te4[s2>>8]
338 mov $s2,$s2,lsr#24
339
335 ldrb $i2,[$tbl,$i2,lsl#2] @ Te4[s2>>16] 340 ldrb $i2,[$tbl,$i2,lsl#2] @ Te4[s2>>16]
336 ldrb $s2,[$tbl,$s2,lsl#2] @ Te4[s2>>24]
337 ldrb $i3,[$tbl,$i3,lsl#2] @ Te4[s2>>0] 341 ldrb $i3,[$tbl,$i3,lsl#2] @ Te4[s2>>0]
338 eor $s0,$i1,$s0,lsl#8 342 eor $s0,$i1,$s0,lsl#8
339 eor $s1,$s1,$i2,lsl#16 343 ldrb $s2,[$tbl,$s2,lsl#2] @ Te4[s2>>24]
340 eor $s2,$t2,$s2,lsl#24
341 eor $t3,$i3,$t3,lsl#8
342
343 and $i1,lr,$s3 @ i0 344 and $i1,lr,$s3 @ i0
345 eor $s1,$s1,$i2,lsl#16
344 and $i2,lr,$s3,lsr#8 @ i1 346 and $i2,lr,$s3,lsr#8 @ i1
347 eor $t3,$i3,$t3,lsl#8
345 and $i3,lr,$s3,lsr#16 @ i2 348 and $i3,lr,$s3,lsr#16 @ i2
346 mov $s3,$s3,lsr#24 349 eor $s2,$t2,$s2,lsl#24
347 ldrb $i1,[$tbl,$i1,lsl#2] @ Te4[s3>>0] 350 ldrb $i1,[$tbl,$i1,lsl#2] @ Te4[s3>>0]
351 mov $s3,$s3,lsr#24
352
348 ldrb $i2,[$tbl,$i2,lsl#2] @ Te4[s3>>8] 353 ldrb $i2,[$tbl,$i2,lsl#2] @ Te4[s3>>8]
349 ldrb $i3,[$tbl,$i3,lsl#2] @ Te4[s3>>16] 354 ldrb $i3,[$tbl,$i3,lsl#2] @ Te4[s3>>16]
350 ldrb $s3,[$tbl,$s3,lsl#2] @ Te4[s3>>24]
351 eor $s0,$i1,$s0,lsl#8 355 eor $s0,$i1,$s0,lsl#8
356 ldrb $s3,[$tbl,$s3,lsl#2] @ Te4[s3>>24]
357 ldr $i1,[$key,#0]
352 eor $s1,$s1,$i2,lsl#8 358 eor $s1,$s1,$i2,lsl#8
359 ldr $t1,[$key,#4]
353 eor $s2,$s2,$i3,lsl#16 360 eor $s2,$s2,$i3,lsl#16
361 ldr $t2,[$key,#8]
354 eor $s3,$t3,$s3,lsl#24 362 eor $s3,$t3,$s3,lsl#24
363 ldr $t3,[$key,#12]
355 364
356 ldr lr,[sp],#4 @ pop lr 365 eor $s0,$s0,$i1
357 ldr $t1,[$key,#0] 366 eor $s1,$s1,$t1
358 ldr $t2,[$key,#4] 367 eor $s2,$s2,$t2
359 ldr $t3,[$key,#8] 368 eor $s3,$s3,$t3
360 ldr $i1,[$key,#12]
361 eor $s0,$s0,$t1
362 eor $s1,$s1,$t2
363 eor $s2,$s2,$t3
364 eor $s3,$s3,$i1
365 369
366 sub $tbl,$tbl,#2 370 sub $tbl,$tbl,#2
367 mov pc,lr @ return 371 ldr pc,[sp],#4 @ pop and return
368.size _armv4_AES_encrypt,.-_armv4_AES_encrypt 372.size _armv4_AES_encrypt,.-_armv4_AES_encrypt
369 373
370.global AES_set_encrypt_key 374.global AES_set_encrypt_key
@@ -399,31 +403,31 @@ AES_set_encrypt_key:
399 ldrb $t2,[$rounds,#1] 403 ldrb $t2,[$rounds,#1]
400 ldrb $t3,[$rounds,#0] 404 ldrb $t3,[$rounds,#0]
401 orr $s0,$s0,$t1,lsl#8 405 orr $s0,$s0,$t1,lsl#8
402 orr $s0,$s0,$t2,lsl#16
403 orr $s0,$s0,$t3,lsl#24
404 ldrb $s1,[$rounds,#7] 406 ldrb $s1,[$rounds,#7]
407 orr $s0,$s0,$t2,lsl#16
405 ldrb $t1,[$rounds,#6] 408 ldrb $t1,[$rounds,#6]
409 orr $s0,$s0,$t3,lsl#24
406 ldrb $t2,[$rounds,#5] 410 ldrb $t2,[$rounds,#5]
407 ldrb $t3,[$rounds,#4] 411 ldrb $t3,[$rounds,#4]
408 orr $s1,$s1,$t1,lsl#8 412 orr $s1,$s1,$t1,lsl#8
409 orr $s1,$s1,$t2,lsl#16
410 orr $s1,$s1,$t3,lsl#24
411 ldrb $s2,[$rounds,#11] 413 ldrb $s2,[$rounds,#11]
414 orr $s1,$s1,$t2,lsl#16
412 ldrb $t1,[$rounds,#10] 415 ldrb $t1,[$rounds,#10]
416 orr $s1,$s1,$t3,lsl#24
413 ldrb $t2,[$rounds,#9] 417 ldrb $t2,[$rounds,#9]
414 ldrb $t3,[$rounds,#8] 418 ldrb $t3,[$rounds,#8]
415 orr $s2,$s2,$t1,lsl#8 419 orr $s2,$s2,$t1,lsl#8
416 orr $s2,$s2,$t2,lsl#16
417 orr $s2,$s2,$t3,lsl#24
418 ldrb $s3,[$rounds,#15] 420 ldrb $s3,[$rounds,#15]
421 orr $s2,$s2,$t2,lsl#16
419 ldrb $t1,[$rounds,#14] 422 ldrb $t1,[$rounds,#14]
423 orr $s2,$s2,$t3,lsl#24
420 ldrb $t2,[$rounds,#13] 424 ldrb $t2,[$rounds,#13]
421 ldrb $t3,[$rounds,#12] 425 ldrb $t3,[$rounds,#12]
422 orr $s3,$s3,$t1,lsl#8 426 orr $s3,$s3,$t1,lsl#8
423 orr $s3,$s3,$t2,lsl#16
424 orr $s3,$s3,$t3,lsl#24
425 str $s0,[$key],#16 427 str $s0,[$key],#16
428 orr $s3,$s3,$t2,lsl#16
426 str $s1,[$key,#-12] 429 str $s1,[$key,#-12]
430 orr $s3,$s3,$t3,lsl#24
427 str $s2,[$key,#-8] 431 str $s2,[$key,#-8]
428 str $s3,[$key,#-4] 432 str $s3,[$key,#-4]
429 433
@@ -437,27 +441,26 @@ AES_set_encrypt_key:
437.L128_loop: 441.L128_loop:
438 and $t2,lr,$s3,lsr#24 442 and $t2,lr,$s3,lsr#24
439 and $i1,lr,$s3,lsr#16 443 and $i1,lr,$s3,lsr#16
440 and $i2,lr,$s3,lsr#8
441 and $i3,lr,$s3
442 ldrb $t2,[$tbl,$t2] 444 ldrb $t2,[$tbl,$t2]
445 and $i2,lr,$s3,lsr#8
443 ldrb $i1,[$tbl,$i1] 446 ldrb $i1,[$tbl,$i1]
447 and $i3,lr,$s3
444 ldrb $i2,[$tbl,$i2] 448 ldrb $i2,[$tbl,$i2]
445 ldrb $i3,[$tbl,$i3]
446 ldr $t1,[$t3],#4 @ rcon[i++]
447 orr $t2,$t2,$i1,lsl#24 449 orr $t2,$t2,$i1,lsl#24
450 ldrb $i3,[$tbl,$i3]
448 orr $t2,$t2,$i2,lsl#16 451 orr $t2,$t2,$i2,lsl#16
452 ldr $t1,[$t3],#4 @ rcon[i++]
449 orr $t2,$t2,$i3,lsl#8 453 orr $t2,$t2,$i3,lsl#8
450 eor $t2,$t2,$t1 454 eor $t2,$t2,$t1
451 eor $s0,$s0,$t2 @ rk[4]=rk[0]^... 455 eor $s0,$s0,$t2 @ rk[4]=rk[0]^...
452 eor $s1,$s1,$s0 @ rk[5]=rk[1]^rk[4] 456 eor $s1,$s1,$s0 @ rk[5]=rk[1]^rk[4]
453 eor $s2,$s2,$s1 @ rk[6]=rk[2]^rk[5]
454 eor $s3,$s3,$s2 @ rk[7]=rk[3]^rk[6]
455 str $s0,[$key],#16 457 str $s0,[$key],#16
458 eor $s2,$s2,$s1 @ rk[6]=rk[2]^rk[5]
456 str $s1,[$key,#-12] 459 str $s1,[$key,#-12]
460 eor $s3,$s3,$s2 @ rk[7]=rk[3]^rk[6]
457 str $s2,[$key,#-8] 461 str $s2,[$key,#-8]
458 str $s3,[$key,#-4]
459
460 subs $rounds,$rounds,#1 462 subs $rounds,$rounds,#1
463 str $s3,[$key,#-4]
461 bne .L128_loop 464 bne .L128_loop
462 sub r2,$key,#176 465 sub r2,$key,#176
463 b .Ldone 466 b .Ldone
@@ -468,16 +471,16 @@ AES_set_encrypt_key:
468 ldrb $t2,[$rounds,#17] 471 ldrb $t2,[$rounds,#17]
469 ldrb $t3,[$rounds,#16] 472 ldrb $t3,[$rounds,#16]
470 orr $i2,$i2,$t1,lsl#8 473 orr $i2,$i2,$t1,lsl#8
471 orr $i2,$i2,$t2,lsl#16
472 orr $i2,$i2,$t3,lsl#24
473 ldrb $i3,[$rounds,#23] 474 ldrb $i3,[$rounds,#23]
475 orr $i2,$i2,$t2,lsl#16
474 ldrb $t1,[$rounds,#22] 476 ldrb $t1,[$rounds,#22]
477 orr $i2,$i2,$t3,lsl#24
475 ldrb $t2,[$rounds,#21] 478 ldrb $t2,[$rounds,#21]
476 ldrb $t3,[$rounds,#20] 479 ldrb $t3,[$rounds,#20]
477 orr $i3,$i3,$t1,lsl#8 480 orr $i3,$i3,$t1,lsl#8
478 orr $i3,$i3,$t2,lsl#16 481 orr $i3,$i3,$t2,lsl#16
479 orr $i3,$i3,$t3,lsl#24
480 str $i2,[$key],#8 482 str $i2,[$key],#8
483 orr $i3,$i3,$t3,lsl#24
481 str $i3,[$key,#-4] 484 str $i3,[$key,#-4]
482 485
483 teq lr,#192 486 teq lr,#192
@@ -491,27 +494,26 @@ AES_set_encrypt_key:
491.L192_loop: 494.L192_loop:
492 and $t2,lr,$i3,lsr#24 495 and $t2,lr,$i3,lsr#24
493 and $i1,lr,$i3,lsr#16 496 and $i1,lr,$i3,lsr#16
494 and $i2,lr,$i3,lsr#8
495 and $i3,lr,$i3
496 ldrb $t2,[$tbl,$t2] 497 ldrb $t2,[$tbl,$t2]
498 and $i2,lr,$i3,lsr#8
497 ldrb $i1,[$tbl,$i1] 499 ldrb $i1,[$tbl,$i1]
500 and $i3,lr,$i3
498 ldrb $i2,[$tbl,$i2] 501 ldrb $i2,[$tbl,$i2]
499 ldrb $i3,[$tbl,$i3]
500 ldr $t1,[$t3],#4 @ rcon[i++]
501 orr $t2,$t2,$i1,lsl#24 502 orr $t2,$t2,$i1,lsl#24
503 ldrb $i3,[$tbl,$i3]
502 orr $t2,$t2,$i2,lsl#16 504 orr $t2,$t2,$i2,lsl#16
505 ldr $t1,[$t3],#4 @ rcon[i++]
503 orr $t2,$t2,$i3,lsl#8 506 orr $t2,$t2,$i3,lsl#8
504 eor $i3,$t2,$t1 507 eor $i3,$t2,$t1
505 eor $s0,$s0,$i3 @ rk[6]=rk[0]^... 508 eor $s0,$s0,$i3 @ rk[6]=rk[0]^...
506 eor $s1,$s1,$s0 @ rk[7]=rk[1]^rk[6] 509 eor $s1,$s1,$s0 @ rk[7]=rk[1]^rk[6]
507 eor $s2,$s2,$s1 @ rk[8]=rk[2]^rk[7]
508 eor $s3,$s3,$s2 @ rk[9]=rk[3]^rk[8]
509 str $s0,[$key],#24 510 str $s0,[$key],#24
511 eor $s2,$s2,$s1 @ rk[8]=rk[2]^rk[7]
510 str $s1,[$key,#-20] 512 str $s1,[$key,#-20]
513 eor $s3,$s3,$s2 @ rk[9]=rk[3]^rk[8]
511 str $s2,[$key,#-16] 514 str $s2,[$key,#-16]
512 str $s3,[$key,#-12]
513
514 subs $rounds,$rounds,#1 515 subs $rounds,$rounds,#1
516 str $s3,[$key,#-12]
515 subeq r2,$key,#216 517 subeq r2,$key,#216
516 beq .Ldone 518 beq .Ldone
517 519
@@ -529,16 +531,16 @@ AES_set_encrypt_key:
529 ldrb $t2,[$rounds,#25] 531 ldrb $t2,[$rounds,#25]
530 ldrb $t3,[$rounds,#24] 532 ldrb $t3,[$rounds,#24]
531 orr $i2,$i2,$t1,lsl#8 533 orr $i2,$i2,$t1,lsl#8
532 orr $i2,$i2,$t2,lsl#16
533 orr $i2,$i2,$t3,lsl#24
534 ldrb $i3,[$rounds,#31] 534 ldrb $i3,[$rounds,#31]
535 orr $i2,$i2,$t2,lsl#16
535 ldrb $t1,[$rounds,#30] 536 ldrb $t1,[$rounds,#30]
537 orr $i2,$i2,$t3,lsl#24
536 ldrb $t2,[$rounds,#29] 538 ldrb $t2,[$rounds,#29]
537 ldrb $t3,[$rounds,#28] 539 ldrb $t3,[$rounds,#28]
538 orr $i3,$i3,$t1,lsl#8 540 orr $i3,$i3,$t1,lsl#8
539 orr $i3,$i3,$t2,lsl#16 541 orr $i3,$i3,$t2,lsl#16
540 orr $i3,$i3,$t3,lsl#24
541 str $i2,[$key],#8 542 str $i2,[$key],#8
543 orr $i3,$i3,$t3,lsl#24
542 str $i3,[$key,#-4] 544 str $i3,[$key,#-4]
543 545
544 mov $rounds,#14 546 mov $rounds,#14
@@ -550,52 +552,51 @@ AES_set_encrypt_key:
550.L256_loop: 552.L256_loop:
551 and $t2,lr,$i3,lsr#24 553 and $t2,lr,$i3,lsr#24
552 and $i1,lr,$i3,lsr#16 554 and $i1,lr,$i3,lsr#16
553 and $i2,lr,$i3,lsr#8
554 and $i3,lr,$i3
555 ldrb $t2,[$tbl,$t2] 555 ldrb $t2,[$tbl,$t2]
556 and $i2,lr,$i3,lsr#8
556 ldrb $i1,[$tbl,$i1] 557 ldrb $i1,[$tbl,$i1]
558 and $i3,lr,$i3
557 ldrb $i2,[$tbl,$i2] 559 ldrb $i2,[$tbl,$i2]
558 ldrb $i3,[$tbl,$i3]
559 ldr $t1,[$t3],#4 @ rcon[i++]
560 orr $t2,$t2,$i1,lsl#24 560 orr $t2,$t2,$i1,lsl#24
561 ldrb $i3,[$tbl,$i3]
561 orr $t2,$t2,$i2,lsl#16 562 orr $t2,$t2,$i2,lsl#16
563 ldr $t1,[$t3],#4 @ rcon[i++]
562 orr $t2,$t2,$i3,lsl#8 564 orr $t2,$t2,$i3,lsl#8
563 eor $i3,$t2,$t1 565 eor $i3,$t2,$t1
564 eor $s0,$s0,$i3 @ rk[8]=rk[0]^... 566 eor $s0,$s0,$i3 @ rk[8]=rk[0]^...
565 eor $s1,$s1,$s0 @ rk[9]=rk[1]^rk[8] 567 eor $s1,$s1,$s0 @ rk[9]=rk[1]^rk[8]
566 eor $s2,$s2,$s1 @ rk[10]=rk[2]^rk[9]
567 eor $s3,$s3,$s2 @ rk[11]=rk[3]^rk[10]
568 str $s0,[$key],#32 568 str $s0,[$key],#32
569 eor $s2,$s2,$s1 @ rk[10]=rk[2]^rk[9]
569 str $s1,[$key,#-28] 570 str $s1,[$key,#-28]
571 eor $s3,$s3,$s2 @ rk[11]=rk[3]^rk[10]
570 str $s2,[$key,#-24] 572 str $s2,[$key,#-24]
571 str $s3,[$key,#-20]
572
573 subs $rounds,$rounds,#1 573 subs $rounds,$rounds,#1
574 str $s3,[$key,#-20]
574 subeq r2,$key,#256 575 subeq r2,$key,#256
575 beq .Ldone 576 beq .Ldone
576 577
577 and $t2,lr,$s3 578 and $t2,lr,$s3
578 and $i1,lr,$s3,lsr#8 579 and $i1,lr,$s3,lsr#8
579 and $i2,lr,$s3,lsr#16
580 and $i3,lr,$s3,lsr#24
581 ldrb $t2,[$tbl,$t2] 580 ldrb $t2,[$tbl,$t2]
581 and $i2,lr,$s3,lsr#16
582 ldrb $i1,[$tbl,$i1] 582 ldrb $i1,[$tbl,$i1]
583 and $i3,lr,$s3,lsr#24
583 ldrb $i2,[$tbl,$i2] 584 ldrb $i2,[$tbl,$i2]
584 ldrb $i3,[$tbl,$i3]
585 orr $t2,$t2,$i1,lsl#8 585 orr $t2,$t2,$i1,lsl#8
586 ldrb $i3,[$tbl,$i3]
586 orr $t2,$t2,$i2,lsl#16 587 orr $t2,$t2,$i2,lsl#16
588 ldr $t1,[$key,#-48]
587 orr $t2,$t2,$i3,lsl#24 589 orr $t2,$t2,$i3,lsl#24
588 590
589 ldr $t1,[$key,#-48]
590 ldr $i1,[$key,#-44] 591 ldr $i1,[$key,#-44]
591 ldr $i2,[$key,#-40] 592 ldr $i2,[$key,#-40]
592 ldr $i3,[$key,#-36]
593 eor $t1,$t1,$t2 @ rk[12]=rk[4]^... 593 eor $t1,$t1,$t2 @ rk[12]=rk[4]^...
594 ldr $i3,[$key,#-36]
594 eor $i1,$i1,$t1 @ rk[13]=rk[5]^rk[12] 595 eor $i1,$i1,$t1 @ rk[13]=rk[5]^rk[12]
595 eor $i2,$i2,$i1 @ rk[14]=rk[6]^rk[13]
596 eor $i3,$i3,$i2 @ rk[15]=rk[7]^rk[14]
597 str $t1,[$key,#-16] 596 str $t1,[$key,#-16]
597 eor $i2,$i2,$i1 @ rk[14]=rk[6]^rk[13]
598 str $i1,[$key,#-12] 598 str $i1,[$key,#-12]
599 eor $i3,$i3,$i2 @ rk[15]=rk[7]^rk[14]
599 str $i2,[$key,#-8] 600 str $i2,[$key,#-8]
600 str $i3,[$key,#-4] 601 str $i3,[$key,#-4]
601 b .L256_loop 602 b .L256_loop
@@ -816,24 +817,24 @@ AES_decrypt:
816 ldrb $t2,[$rounds,#1] 817 ldrb $t2,[$rounds,#1]
817 ldrb $t3,[$rounds,#0] 818 ldrb $t3,[$rounds,#0]
818 orr $s0,$s0,$t1,lsl#8 819 orr $s0,$s0,$t1,lsl#8
819 orr $s0,$s0,$t2,lsl#16
820 orr $s0,$s0,$t3,lsl#24
821 ldrb $s1,[$rounds,#7] 820 ldrb $s1,[$rounds,#7]
821 orr $s0,$s0,$t2,lsl#16
822 ldrb $t1,[$rounds,#6] 822 ldrb $t1,[$rounds,#6]
823 orr $s0,$s0,$t3,lsl#24
823 ldrb $t2,[$rounds,#5] 824 ldrb $t2,[$rounds,#5]
824 ldrb $t3,[$rounds,#4] 825 ldrb $t3,[$rounds,#4]
825 orr $s1,$s1,$t1,lsl#8 826 orr $s1,$s1,$t1,lsl#8
826 orr $s1,$s1,$t2,lsl#16
827 orr $s1,$s1,$t3,lsl#24
828 ldrb $s2,[$rounds,#11] 827 ldrb $s2,[$rounds,#11]
828 orr $s1,$s1,$t2,lsl#16
829 ldrb $t1,[$rounds,#10] 829 ldrb $t1,[$rounds,#10]
830 orr $s1,$s1,$t3,lsl#24
830 ldrb $t2,[$rounds,#9] 831 ldrb $t2,[$rounds,#9]
831 ldrb $t3,[$rounds,#8] 832 ldrb $t3,[$rounds,#8]
832 orr $s2,$s2,$t1,lsl#8 833 orr $s2,$s2,$t1,lsl#8
833 orr $s2,$s2,$t2,lsl#16
834 orr $s2,$s2,$t3,lsl#24
835 ldrb $s3,[$rounds,#15] 834 ldrb $s3,[$rounds,#15]
835 orr $s2,$s2,$t2,lsl#16
836 ldrb $t1,[$rounds,#14] 836 ldrb $t1,[$rounds,#14]
837 orr $s2,$s2,$t3,lsl#24
837 ldrb $t2,[$rounds,#13] 838 ldrb $t2,[$rounds,#13]
838 ldrb $t3,[$rounds,#12] 839 ldrb $t3,[$rounds,#12]
839 orr $s3,$s3,$t1,lsl#8 840 orr $s3,$s3,$t1,lsl#8
@@ -848,24 +849,24 @@ AES_decrypt:
848 mov $t3,$s0,lsr#8 849 mov $t3,$s0,lsr#8
849 strb $t1,[$rounds,#0] 850 strb $t1,[$rounds,#0]
850 strb $t2,[$rounds,#1] 851 strb $t2,[$rounds,#1]
851 strb $t3,[$rounds,#2]
852 strb $s0,[$rounds,#3]
853 mov $t1,$s1,lsr#24 852 mov $t1,$s1,lsr#24
853 strb $t3,[$rounds,#2]
854 mov $t2,$s1,lsr#16 854 mov $t2,$s1,lsr#16
855 strb $s0,[$rounds,#3]
855 mov $t3,$s1,lsr#8 856 mov $t3,$s1,lsr#8
856 strb $t1,[$rounds,#4] 857 strb $t1,[$rounds,#4]
857 strb $t2,[$rounds,#5] 858 strb $t2,[$rounds,#5]
858 strb $t3,[$rounds,#6]
859 strb $s1,[$rounds,#7]
860 mov $t1,$s2,lsr#24 859 mov $t1,$s2,lsr#24
860 strb $t3,[$rounds,#6]
861 mov $t2,$s2,lsr#16 861 mov $t2,$s2,lsr#16
862 strb $s1,[$rounds,#7]
862 mov $t3,$s2,lsr#8 863 mov $t3,$s2,lsr#8
863 strb $t1,[$rounds,#8] 864 strb $t1,[$rounds,#8]
864 strb $t2,[$rounds,#9] 865 strb $t2,[$rounds,#9]
865 strb $t3,[$rounds,#10]
866 strb $s2,[$rounds,#11]
867 mov $t1,$s3,lsr#24 866 mov $t1,$s3,lsr#24
867 strb $t3,[$rounds,#10]
868 mov $t2,$s3,lsr#16 868 mov $t2,$s3,lsr#16
869 strb $s2,[$rounds,#11]
869 mov $t3,$s3,lsr#8 870 mov $t3,$s3,lsr#8
870 strb $t1,[$rounds,#12] 871 strb $t1,[$rounds,#12]
871 strb $t2,[$rounds,#13] 872 strb $t2,[$rounds,#13]
@@ -882,146 +883,143 @@ AES_decrypt:
882.align 2 883.align 2
883_armv4_AES_decrypt: 884_armv4_AES_decrypt:
884 str lr,[sp,#-4]! @ push lr 885 str lr,[sp,#-4]! @ push lr
885 ldr $t1,[$key],#16 886 ldmia $key!,{$t1-$i1}
886 ldr $t2,[$key,#-12]
887 ldr $t3,[$key,#-8]
888 ldr $i1,[$key,#-4]
889 ldr $rounds,[$key,#240-16]
890 eor $s0,$s0,$t1 887 eor $s0,$s0,$t1
888 ldr $rounds,[$key,#240-16]
891 eor $s1,$s1,$t2 889 eor $s1,$s1,$t2
892 eor $s2,$s2,$t3 890 eor $s2,$s2,$t3
893 eor $s3,$s3,$i1 891 eor $s3,$s3,$i1
894 sub $rounds,$rounds,#1 892 sub $rounds,$rounds,#1
895 mov lr,#255 893 mov lr,#255
896 894
897.Ldec_loop:
898 and $i1,lr,$s0,lsr#16 895 and $i1,lr,$s0,lsr#16
899 and $i2,lr,$s0,lsr#8 896 and $i2,lr,$s0,lsr#8
900 and $i3,lr,$s0 897 and $i3,lr,$s0
901 mov $s0,$s0,lsr#24 898 mov $s0,$s0,lsr#24
899.Ldec_loop:
902 ldr $t1,[$tbl,$i1,lsl#2] @ Td1[s0>>16] 900 ldr $t1,[$tbl,$i1,lsl#2] @ Td1[s0>>16]
903 ldr $s0,[$tbl,$s0,lsl#2] @ Td0[s0>>24]
904 ldr $t2,[$tbl,$i2,lsl#2] @ Td2[s0>>8]
905 ldr $t3,[$tbl,$i3,lsl#2] @ Td3[s0>>0]
906
907 and $i1,lr,$s1 @ i0 901 and $i1,lr,$s1 @ i0
902 ldr $t2,[$tbl,$i2,lsl#2] @ Td2[s0>>8]
908 and $i2,lr,$s1,lsr#16 903 and $i2,lr,$s1,lsr#16
904 ldr $t3,[$tbl,$i3,lsl#2] @ Td3[s0>>0]
909 and $i3,lr,$s1,lsr#8 905 and $i3,lr,$s1,lsr#8
906 ldr $s0,[$tbl,$s0,lsl#2] @ Td0[s0>>24]
910 mov $s1,$s1,lsr#24 907 mov $s1,$s1,lsr#24
908
911 ldr $i1,[$tbl,$i1,lsl#2] @ Td3[s1>>0] 909 ldr $i1,[$tbl,$i1,lsl#2] @ Td3[s1>>0]
912 ldr $s1,[$tbl,$s1,lsl#2] @ Td0[s1>>24]
913 ldr $i2,[$tbl,$i2,lsl#2] @ Td1[s1>>16] 910 ldr $i2,[$tbl,$i2,lsl#2] @ Td1[s1>>16]
914 ldr $i3,[$tbl,$i3,lsl#2] @ Td2[s1>>8] 911 ldr $i3,[$tbl,$i3,lsl#2] @ Td2[s1>>8]
915 eor $s0,$s0,$i1,ror#24 912 eor $s0,$s0,$i1,ror#24
916 eor $s1,$s1,$t1,ror#8 913 ldr $s1,[$tbl,$s1,lsl#2] @ Td0[s1>>24]
917 eor $t2,$i2,$t2,ror#8
918 eor $t3,$i3,$t3,ror#8
919
920 and $i1,lr,$s2,lsr#8 @ i0 914 and $i1,lr,$s2,lsr#8 @ i0
915 eor $t2,$i2,$t2,ror#8
921 and $i2,lr,$s2 @ i1 916 and $i2,lr,$s2 @ i1
917 eor $t3,$i3,$t3,ror#8
922 and $i3,lr,$s2,lsr#16 918 and $i3,lr,$s2,lsr#16
923 mov $s2,$s2,lsr#24 919 eor $s1,$s1,$t1,ror#8
924 ldr $i1,[$tbl,$i1,lsl#2] @ Td2[s2>>8] 920 ldr $i1,[$tbl,$i1,lsl#2] @ Td2[s2>>8]
921 mov $s2,$s2,lsr#24
922
925 ldr $i2,[$tbl,$i2,lsl#2] @ Td3[s2>>0] 923 ldr $i2,[$tbl,$i2,lsl#2] @ Td3[s2>>0]
926 ldr $s2,[$tbl,$s2,lsl#2] @ Td0[s2>>24]
927 ldr $i3,[$tbl,$i3,lsl#2] @ Td1[s2>>16] 924 ldr $i3,[$tbl,$i3,lsl#2] @ Td1[s2>>16]
928 eor $s0,$s0,$i1,ror#16 925 eor $s0,$s0,$i1,ror#16
929 eor $s1,$s1,$i2,ror#24 926 ldr $s2,[$tbl,$s2,lsl#2] @ Td0[s2>>24]
930 eor $s2,$s2,$t2,ror#8
931 eor $t3,$i3,$t3,ror#8
932
933 and $i1,lr,$s3,lsr#16 @ i0 927 and $i1,lr,$s3,lsr#16 @ i0
928 eor $s1,$s1,$i2,ror#24
934 and $i2,lr,$s3,lsr#8 @ i1 929 and $i2,lr,$s3,lsr#8 @ i1
930 eor $t3,$i3,$t3,ror#8
935 and $i3,lr,$s3 @ i2 931 and $i3,lr,$s3 @ i2
936 mov $s3,$s3,lsr#24 932 eor $s2,$s2,$t2,ror#8
937 ldr $i1,[$tbl,$i1,lsl#2] @ Td1[s3>>16] 933 ldr $i1,[$tbl,$i1,lsl#2] @ Td1[s3>>16]
934 mov $s3,$s3,lsr#24
935
938 ldr $i2,[$tbl,$i2,lsl#2] @ Td2[s3>>8] 936 ldr $i2,[$tbl,$i2,lsl#2] @ Td2[s3>>8]
939 ldr $i3,[$tbl,$i3,lsl#2] @ Td3[s3>>0] 937 ldr $i3,[$tbl,$i3,lsl#2] @ Td3[s3>>0]
940 ldr $s3,[$tbl,$s3,lsl#2] @ Td0[s3>>24]
941 eor $s0,$s0,$i1,ror#8 938 eor $s0,$s0,$i1,ror#8
939 ldr $s3,[$tbl,$s3,lsl#2] @ Td0[s3>>24]
942 eor $s1,$s1,$i2,ror#16 940 eor $s1,$s1,$i2,ror#16
943 eor $s2,$s2,$i3,ror#24 941 eor $s2,$s2,$i3,ror#24
942 ldr $i1,[$key],#16
944 eor $s3,$s3,$t3,ror#8 943 eor $s3,$s3,$t3,ror#8
945 944
946 ldr $t1,[$key],#16 945 ldr $t1,[$key,#-12]
947 ldr $t2,[$key,#-12] 946 ldr $t2,[$key,#-8]
948 ldr $t3,[$key,#-8] 947 eor $s0,$s0,$i1
949 ldr $i1,[$key,#-4] 948 ldr $t3,[$key,#-4]
950 eor $s0,$s0,$t1 949 and $i1,lr,$s0,lsr#16
951 eor $s1,$s1,$t2 950 eor $s1,$s1,$t1
952 eor $s2,$s2,$t3 951 and $i2,lr,$s0,lsr#8
953 eor $s3,$s3,$i1 952 eor $s2,$s2,$t2
953 and $i3,lr,$s0
954 eor $s3,$s3,$t3
955 mov $s0,$s0,lsr#24
954 956
955 subs $rounds,$rounds,#1 957 subs $rounds,$rounds,#1
956 bne .Ldec_loop 958 bne .Ldec_loop
957 959
958 add $tbl,$tbl,#1024 960 add $tbl,$tbl,#1024
959 961
960 ldr $t1,[$tbl,#0] @ prefetch Td4 962 ldr $t2,[$tbl,#0] @ prefetch Td4
961 ldr $t2,[$tbl,#32] 963 ldr $t3,[$tbl,#32]
962 ldr $t3,[$tbl,#64] 964 ldr $t1,[$tbl,#64]
963 ldr $i1,[$tbl,#96] 965 ldr $t2,[$tbl,#96]
964 ldr $i2,[$tbl,#128] 966 ldr $t3,[$tbl,#128]
965 ldr $i3,[$tbl,#160] 967 ldr $t1,[$tbl,#160]
966 ldr $t1,[$tbl,#192] 968 ldr $t2,[$tbl,#192]
967 ldr $t2,[$tbl,#224] 969 ldr $t3,[$tbl,#224]
968 970
969 and $i1,lr,$s0,lsr#16 971 ldrb $s0,[$tbl,$s0] @ Td4[s0>>24]
970 and $i2,lr,$s0,lsr#8
971 and $i3,lr,$s0
972 ldrb $s0,[$tbl,$s0,lsr#24] @ Td4[s0>>24]
973 ldrb $t1,[$tbl,$i1] @ Td4[s0>>16] 972 ldrb $t1,[$tbl,$i1] @ Td4[s0>>16]
974 ldrb $t2,[$tbl,$i2] @ Td4[s0>>8]
975 ldrb $t3,[$tbl,$i3] @ Td4[s0>>0]
976
977 and $i1,lr,$s1 @ i0 973 and $i1,lr,$s1 @ i0
974 ldrb $t2,[$tbl,$i2] @ Td4[s0>>8]
978 and $i2,lr,$s1,lsr#16 975 and $i2,lr,$s1,lsr#16
976 ldrb $t3,[$tbl,$i3] @ Td4[s0>>0]
979 and $i3,lr,$s1,lsr#8 977 and $i3,lr,$s1,lsr#8
978
980 ldrb $i1,[$tbl,$i1] @ Td4[s1>>0] 979 ldrb $i1,[$tbl,$i1] @ Td4[s1>>0]
981 ldrb $s1,[$tbl,$s1,lsr#24] @ Td4[s1>>24] 980 ldrb $s1,[$tbl,$s1,lsr#24] @ Td4[s1>>24]
982 ldrb $i2,[$tbl,$i2] @ Td4[s1>>16] 981 ldrb $i2,[$tbl,$i2] @ Td4[s1>>16]
983 ldrb $i3,[$tbl,$i3] @ Td4[s1>>8]
984 eor $s0,$i1,$s0,lsl#24 982 eor $s0,$i1,$s0,lsl#24
983 ldrb $i3,[$tbl,$i3] @ Td4[s1>>8]
985 eor $s1,$t1,$s1,lsl#8 984 eor $s1,$t1,$s1,lsl#8
986 eor $t2,$t2,$i2,lsl#8
987 eor $t3,$t3,$i3,lsl#8
988
989 and $i1,lr,$s2,lsr#8 @ i0 985 and $i1,lr,$s2,lsr#8 @ i0
986 eor $t2,$t2,$i2,lsl#8
990 and $i2,lr,$s2 @ i1 987 and $i2,lr,$s2 @ i1
991 and $i3,lr,$s2,lsr#16 988 eor $t3,$t3,$i3,lsl#8
992 ldrb $i1,[$tbl,$i1] @ Td4[s2>>8] 989 ldrb $i1,[$tbl,$i1] @ Td4[s2>>8]
990 and $i3,lr,$s2,lsr#16
991
993 ldrb $i2,[$tbl,$i2] @ Td4[s2>>0] 992 ldrb $i2,[$tbl,$i2] @ Td4[s2>>0]
994 ldrb $s2,[$tbl,$s2,lsr#24] @ Td4[s2>>24] 993 ldrb $s2,[$tbl,$s2,lsr#24] @ Td4[s2>>24]
995 ldrb $i3,[$tbl,$i3] @ Td4[s2>>16]
996 eor $s0,$s0,$i1,lsl#8 994 eor $s0,$s0,$i1,lsl#8
995 ldrb $i3,[$tbl,$i3] @ Td4[s2>>16]
997 eor $s1,$i2,$s1,lsl#16 996 eor $s1,$i2,$s1,lsl#16
998 eor $s2,$t2,$s2,lsl#16
999 eor $t3,$t3,$i3,lsl#16
1000
1001 and $i1,lr,$s3,lsr#16 @ i0 997 and $i1,lr,$s3,lsr#16 @ i0
998 eor $s2,$t2,$s2,lsl#16
1002 and $i2,lr,$s3,lsr#8 @ i1 999 and $i2,lr,$s3,lsr#8 @ i1
1003 and $i3,lr,$s3 @ i2 1000 eor $t3,$t3,$i3,lsl#16
1004 ldrb $i1,[$tbl,$i1] @ Td4[s3>>16] 1001 ldrb $i1,[$tbl,$i1] @ Td4[s3>>16]
1002 and $i3,lr,$s3 @ i2
1003
1005 ldrb $i2,[$tbl,$i2] @ Td4[s3>>8] 1004 ldrb $i2,[$tbl,$i2] @ Td4[s3>>8]
1006 ldrb $i3,[$tbl,$i3] @ Td4[s3>>0] 1005 ldrb $i3,[$tbl,$i3] @ Td4[s3>>0]
1007 ldrb $s3,[$tbl,$s3,lsr#24] @ Td4[s3>>24] 1006 ldrb $s3,[$tbl,$s3,lsr#24] @ Td4[s3>>24]
1008 eor $s0,$s0,$i1,lsl#16 1007 eor $s0,$s0,$i1,lsl#16
1008 ldr $i1,[$key,#0]
1009 eor $s1,$s1,$i2,lsl#8 1009 eor $s1,$s1,$i2,lsl#8
1010 ldr $t1,[$key,#4]
1010 eor $s2,$i3,$s2,lsl#8 1011 eor $s2,$i3,$s2,lsl#8
1012 ldr $t2,[$key,#8]
1011 eor $s3,$t3,$s3,lsl#24 1013 eor $s3,$t3,$s3,lsl#24
1014 ldr $t3,[$key,#12]
1012 1015
1013 ldr lr,[sp],#4 @ pop lr 1016 eor $s0,$s0,$i1
1014 ldr $t1,[$key,#0] 1017 eor $s1,$s1,$t1
1015 ldr $t2,[$key,#4] 1018 eor $s2,$s2,$t2
1016 ldr $t3,[$key,#8] 1019 eor $s3,$s3,$t3
1017 ldr $i1,[$key,#12]
1018 eor $s0,$s0,$t1
1019 eor $s1,$s1,$t2
1020 eor $s2,$s2,$t3
1021 eor $s3,$s3,$i1
1022 1020
1023 sub $tbl,$tbl,#1024 1021 sub $tbl,$tbl,#1024
1024 mov pc,lr @ return 1022 ldr pc,[sp],#4 @ pop and return
1025.size _armv4_AES_decrypt,.-_armv4_AES_decrypt 1023.size _armv4_AES_decrypt,.-_armv4_AES_decrypt
1026.asciz "AES for ARMv4, CRYPTOGAMS by <appro\@openssl.org>" 1024.asciz "AES for ARMv4, CRYPTOGAMS by <appro\@openssl.org>"
1027.align 2 1025.align 2
@@ -1029,3 +1027,4 @@ ___
1029 1027
1030$code =~ s/\bbx\s+lr\b/.word\t0xe12fff1e/gm; # make it possible to compile with -march=armv4 1028$code =~ s/\bbx\s+lr\b/.word\t0xe12fff1e/gm; # make it possible to compile with -march=armv4
1031print $code; 1029print $code;
1030close STDOUT; # enforce flush
diff --git a/src/lib/libcrypto/alphacpuid.pl b/src/lib/libcrypto/alphacpuid.pl
new file mode 100644
index 0000000000..4b3cbb9827
--- /dev/null
+++ b/src/lib/libcrypto/alphacpuid.pl
@@ -0,0 +1,126 @@
1#!/usr/bin/env perl
2print <<'___';
3.text
4
5.set noat
6
7.globl OPENSSL_cpuid_setup
8.ent OPENSSL_cpuid_setup
9OPENSSL_cpuid_setup:
10 .frame $30,0,$26
11 .prologue 0
12 ret ($26)
13.end OPENSSL_cpuid_setup
14
15.globl OPENSSL_wipe_cpu
16.ent OPENSSL_wipe_cpu
17OPENSSL_wipe_cpu:
18 .frame $30,0,$26
19 .prologue 0
20 clr $1
21 clr $2
22 clr $3
23 clr $4
24 clr $5
25 clr $6
26 clr $7
27 clr $8
28 clr $16
29 clr $17
30 clr $18
31 clr $19
32 clr $20
33 clr $21
34 clr $22
35 clr $23
36 clr $24
37 clr $25
38 clr $27
39 clr $at
40 clr $29
41 fclr $f0
42 fclr $f1
43 fclr $f10
44 fclr $f11
45 fclr $f12
46 fclr $f13
47 fclr $f14
48 fclr $f15
49 fclr $f16
50 fclr $f17
51 fclr $f18
52 fclr $f19
53 fclr $f20
54 fclr $f21
55 fclr $f22
56 fclr $f23
57 fclr $f24
58 fclr $f25
59 fclr $f26
60 fclr $f27
61 fclr $f28
62 fclr $f29
63 fclr $f30
64 mov $sp,$0
65 ret ($26)
66.end OPENSSL_wipe_cpu
67
68.globl OPENSSL_atomic_add
69.ent OPENSSL_atomic_add
70OPENSSL_atomic_add:
71 .frame $30,0,$26
72 .prologue 0
731: ldl_l $0,0($16)
74 addl $0,$17,$1
75 stl_c $1,0($16)
76 beq $1,1b
77 addl $0,$17,$0
78 ret ($26)
79.end OPENSSL_atomic_add
80
81.globl OPENSSL_rdtsc
82.ent OPENSSL_rdtsc
83OPENSSL_rdtsc:
84 .frame $30,0,$26
85 .prologue 0
86 rpcc $0
87 ret ($26)
88.end OPENSSL_rdtsc
89
90.globl OPENSSL_cleanse
91.ent OPENSSL_cleanse
92OPENSSL_cleanse:
93 .frame $30,0,$26
94 .prologue 0
95 beq $17,.Ldone
96 and $16,7,$0
97 bic $17,7,$at
98 beq $at,.Little
99 beq $0,.Laligned
100
101.Little:
102 subq $0,8,$0
103 ldq_u $1,0($16)
104 mov $16,$2
105.Lalign:
106 mskbl $1,$16,$1
107 lda $16,1($16)
108 subq $17,1,$17
109 addq $0,1,$0
110 beq $17,.Lout
111 bne $0,.Lalign
112.Lout: stq_u $1,0($2)
113 beq $17,.Ldone
114 bic $17,7,$at
115 beq $at,.Little
116
117.Laligned:
118 stq $31,0($16)
119 subq $17,8,$17
120 lda $16,8($16)
121 bic $17,7,$at
122 bne $at,.Laligned
123 bne $17,.Little
124.Ldone: ret ($26)
125.end OPENSSL_cleanse
126___
diff --git a/src/lib/libcrypto/asn1/ameth_lib.c b/src/lib/libcrypto/asn1/ameth_lib.c
index 9a8b6cc222..5a581b90ea 100644
--- a/src/lib/libcrypto/asn1/ameth_lib.c
+++ b/src/lib/libcrypto/asn1/ameth_lib.c
@@ -172,7 +172,6 @@ static const EVP_PKEY_ASN1_METHOD *pkey_asn1_find(int type)
172const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_find(ENGINE **pe, int type) 172const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_find(ENGINE **pe, int type)
173 { 173 {
174 const EVP_PKEY_ASN1_METHOD *t; 174 const EVP_PKEY_ASN1_METHOD *t;
175 ENGINE *e;
176 175
177 for (;;) 176 for (;;)
178 { 177 {
@@ -184,6 +183,7 @@ const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_find(ENGINE **pe, int type)
184 if (pe) 183 if (pe)
185 { 184 {
186#ifndef OPENSSL_NO_ENGINE 185#ifndef OPENSSL_NO_ENGINE
186 ENGINE *e;
187 /* type will contain the final unaliased type */ 187 /* type will contain the final unaliased type */
188 e = ENGINE_get_pkey_asn1_meth_engine(type); 188 e = ENGINE_get_pkey_asn1_meth_engine(type);
189 if (e) 189 if (e)
diff --git a/src/lib/libcrypto/asn1/bio_ndef.c b/src/lib/libcrypto/asn1/bio_ndef.c
index 370389b1e6..b91f97a1b1 100644
--- a/src/lib/libcrypto/asn1/bio_ndef.c
+++ b/src/lib/libcrypto/asn1/bio_ndef.c
@@ -57,9 +57,6 @@
57#include <openssl/bio.h> 57#include <openssl/bio.h>
58#include <openssl/err.h> 58#include <openssl/err.h>
59 59
60#ifndef OPENSSL_SYSNAME_NETWARE
61#include <memory.h>
62#endif
63#include <stdio.h> 60#include <stdio.h>
64 61
65/* Experimental NDEF ASN1 BIO support routines */ 62/* Experimental NDEF ASN1 BIO support routines */
diff --git a/src/lib/libcrypto/bn/asm/alpha-mont.pl b/src/lib/libcrypto/bn/asm/alpha-mont.pl
index f7e0ca1646..03596e2014 100644
--- a/src/lib/libcrypto/bn/asm/alpha-mont.pl
+++ b/src/lib/libcrypto/bn/asm/alpha-mont.pl
@@ -41,8 +41,12 @@ $j="s4";
41$m1="s5"; 41$m1="s5";
42 42
43$code=<<___; 43$code=<<___;
44#ifdef __linux__
45#include <asm/regdef.h>
46#else
44#include <asm.h> 47#include <asm.h>
45#include <regdef.h> 48#include <regdef.h>
49#endif
46 50
47.text 51.text
48 52
@@ -76,7 +80,7 @@ bn_mul_mont:
76 ldq $aj,8($ap) 80 ldq $aj,8($ap)
77 subq sp,AT,sp 81 subq sp,AT,sp
78 ldq $bi,0($bp) # bp[0] 82 ldq $bi,0($bp) # bp[0]
79 mov -4096,AT 83 lda AT,-4096(zero) # mov -4096,AT
80 ldq $n0,0($n0) 84 ldq $n0,0($n0)
81 and sp,AT,sp 85 and sp,AT,sp
82 86
@@ -106,9 +110,9 @@ bn_mul_mont:
106.align 4 110.align 4
107.L1st: 111.L1st:
108 .set noreorder 112 .set noreorder
109 ldq $aj,($aj) 113 ldq $aj,0($aj)
110 addl $j,1,$j 114 addl $j,1,$j
111 ldq $nj,($nj) 115 ldq $nj,0($nj)
112 lda $tp,8($tp) 116 lda $tp,8($tp)
113 117
114 addq $alo,$hi0,$lo0 118 addq $alo,$hi0,$lo0
@@ -159,12 +163,12 @@ bn_mul_mont:
159.align 4 163.align 4
160.Louter: 164.Louter:
161 s8addq $i,$bp,$bi 165 s8addq $i,$bp,$bi
162 ldq $hi0,($ap) 166 ldq $hi0,0($ap)
163 ldq $aj,8($ap) 167 ldq $aj,8($ap)
164 ldq $bi,($bi) 168 ldq $bi,0($bi)
165 ldq $hi1,($np) 169 ldq $hi1,0($np)
166 ldq $nj,8($np) 170 ldq $nj,8($np)
167 ldq $tj,(sp) 171 ldq $tj,0(sp)
168 172
169 mulq $hi0,$bi,$lo0 173 mulq $hi0,$bi,$lo0
170 umulh $hi0,$bi,$hi0 174 umulh $hi0,$bi,$hi0
@@ -195,10 +199,10 @@ bn_mul_mont:
195 .set noreorder 199 .set noreorder
196 ldq $tj,8($tp) #L0 200 ldq $tj,8($tp) #L0
197 nop #U1 201 nop #U1
198 ldq $aj,($aj) #L1 202 ldq $aj,0($aj) #L1
199 s8addq $j,$np,$nj #U0 203 s8addq $j,$np,$nj #U0
200 204
201 ldq $nj,($nj) #L0 205 ldq $nj,0($nj) #L0
202 nop #U1 206 nop #U1
203 addq $alo,$hi0,$lo0 #L1 207 addq $alo,$hi0,$lo0 #L1
204 lda $tp,8($tp) 208 lda $tp,8($tp)
@@ -247,7 +251,7 @@ bn_mul_mont:
247 addq $hi1,v0,$hi1 251 addq $hi1,v0,$hi1
248 252
249 addq $hi1,$hi0,$lo1 253 addq $hi1,$hi0,$lo1
250 stq $j,($tp) 254 stq $j,0($tp)
251 cmpult $lo1,$hi0,$hi1 255 cmpult $lo1,$hi0,$hi1
252 addq $lo1,$tj,$lo1 256 addq $lo1,$tj,$lo1
253 cmpult $lo1,$tj,AT 257 cmpult $lo1,$tj,AT
@@ -265,8 +269,8 @@ bn_mul_mont:
265 mov 0,$hi0 # clear borrow bit 269 mov 0,$hi0 # clear borrow bit
266 270
267.align 4 271.align 4
268.Lsub: ldq $lo0,($tp) 272.Lsub: ldq $lo0,0($tp)
269 ldq $lo1,($np) 273 ldq $lo1,0($np)
270 lda $tp,8($tp) 274 lda $tp,8($tp)
271 lda $np,8($np) 275 lda $np,8($np)
272 subq $lo0,$lo1,$lo1 # tp[i]-np[i] 276 subq $lo0,$lo1,$lo1 # tp[i]-np[i]
@@ -274,7 +278,7 @@ bn_mul_mont:
274 subq $lo1,$hi0,$lo0 278 subq $lo1,$hi0,$lo0
275 cmpult $lo1,$lo0,$hi0 279 cmpult $lo1,$lo0,$hi0
276 or $hi0,AT,$hi0 280 or $hi0,AT,$hi0
277 stq $lo0,($rp) 281 stq $lo0,0($rp)
278 cmpult $tp,$tj,v0 282 cmpult $tp,$tj,v0
279 lda $rp,8($rp) 283 lda $rp,8($rp)
280 bne v0,.Lsub 284 bne v0,.Lsub
@@ -288,7 +292,7 @@ bn_mul_mont:
288 bis $bp,$ap,$ap # ap=borrow?tp:rp 292 bis $bp,$ap,$ap # ap=borrow?tp:rp
289 293
290.align 4 294.align 4
291.Lcopy: ldq $aj,($ap) # copy or in-place refresh 295.Lcopy: ldq $aj,0($ap) # copy or in-place refresh
292 lda $tp,8($tp) 296 lda $tp,8($tp)
293 lda $rp,8($rp) 297 lda $rp,8($rp)
294 lda $ap,8($ap) 298 lda $ap,8($ap)
@@ -309,8 +313,8 @@ bn_mul_mont:
309 lda sp,48(sp) 313 lda sp,48(sp)
310 ret (ra) 314 ret (ra)
311.end bn_mul_mont 315.end bn_mul_mont
312.rdata 316.ascii "Montgomery Multiplication for Alpha, CRYPTOGAMS by <appro\@openssl.org>"
313.asciiz "Montgomery Multiplication for Alpha, CRYPTOGAMS by <appro\@openssl.org>" 317.align 2
314___ 318___
315 319
316print $code; 320print $code;
diff --git a/src/lib/libcrypto/bn/asm/s390x-mont.pl b/src/lib/libcrypto/bn/asm/s390x-mont.pl
index d23251033b..f61246f5b6 100644
--- a/src/lib/libcrypto/bn/asm/s390x-mont.pl
+++ b/src/lib/libcrypto/bn/asm/s390x-mont.pl
@@ -69,8 +69,8 @@ bn_mul_mont:
69 cghi $num,16 # 69 cghi $num,16 #
70 lghi %r2,0 # 70 lghi %r2,0 #
71 blr %r14 # if($num<16) return 0; 71 blr %r14 # if($num<16) return 0;
72 cghi $num,128 # 72 cghi $num,96 #
73 bhr %r14 # if($num>128) return 0; 73 bhr %r14 # if($num>96) return 0;
74 74
75 stmg %r3,%r15,24($sp) 75 stmg %r3,%r15,24($sp)
76 76
diff --git a/src/lib/libcrypto/bn/asm/s390x.S b/src/lib/libcrypto/bn/asm/s390x.S
index 8f45f5d513..43fcb79bc0 100755
--- a/src/lib/libcrypto/bn/asm/s390x.S
+++ b/src/lib/libcrypto/bn/asm/s390x.S
@@ -1,4 +1,4 @@
1.ident "s390x.S, version 1.0" 1.ident "s390x.S, version 1.1"
2// ==================================================================== 2// ====================================================================
3// Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL 3// Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
4// project. 4// project.
@@ -24,67 +24,67 @@ bn_mul_add_words:
24 bler %r14 // if (len<=0) return 0; 24 bler %r14 // if (len<=0) return 0;
25 25
26 stmg %r6,%r10,48(%r15) 26 stmg %r6,%r10,48(%r15)
27 lghi %r10,3
27 lghi %r8,0 // carry = 0 28 lghi %r8,0 // carry = 0
28 srag %r10,%r4,2 // cnt=len/4 29 nr %r10,%r4 // len%4
29 jz .Loop1_madd 30 sra %r4,2 // cnt=len/4
31 jz .Loop1_madd // carry is incidentally cleared if branch taken
32 algr zero,zero // clear carry
30 33
31.Loop4_madd: 34.Loop4_madd:
32 lg %r7,0(%r2,%r3) // ap[i] 35 lg %r7,0(%r2,%r3) // ap[i]
33 mlgr %r6,%r5 // *=w 36 mlgr %r6,%r5 // *=w
34 algr %r7,%r8 // +=carry 37 alcgr %r7,%r8 // +=carry
35 alcgr %r6,zero 38 alcgr %r6,zero
36 alg %r7,0(%r2,%r1) // +=rp[i] 39 alg %r7,0(%r2,%r1) // +=rp[i]
37 alcgr %r6,zero
38 stg %r7,0(%r2,%r1) // rp[i]= 40 stg %r7,0(%r2,%r1) // rp[i]=
39 41
40 lg %r9,8(%r2,%r3) 42 lg %r9,8(%r2,%r3)
41 mlgr %r8,%r5 43 mlgr %r8,%r5
42 algr %r9,%r6 44 alcgr %r9,%r6
43 alcgr %r8,zero 45 alcgr %r8,zero
44 alg %r9,8(%r2,%r1) 46 alg %r9,8(%r2,%r1)
45 alcgr %r8,zero
46 stg %r9,8(%r2,%r1) 47 stg %r9,8(%r2,%r1)
47 48
48 lg %r7,16(%r2,%r3) 49 lg %r7,16(%r2,%r3)
49 mlgr %r6,%r5 50 mlgr %r6,%r5
50 algr %r7,%r8 51 alcgr %r7,%r8
51 alcgr %r6,zero 52 alcgr %r6,zero
52 alg %r7,16(%r2,%r1) 53 alg %r7,16(%r2,%r1)
53 alcgr %r6,zero
54 stg %r7,16(%r2,%r1) 54 stg %r7,16(%r2,%r1)
55 55
56 lg %r9,24(%r2,%r3) 56 lg %r9,24(%r2,%r3)
57 mlgr %r8,%r5 57 mlgr %r8,%r5
58 algr %r9,%r6 58 alcgr %r9,%r6
59 alcgr %r8,zero 59 alcgr %r8,zero
60 alg %r9,24(%r2,%r1) 60 alg %r9,24(%r2,%r1)
61 alcgr %r8,zero
62 stg %r9,24(%r2,%r1) 61 stg %r9,24(%r2,%r1)
63 62
64 la %r2,32(%r2) // i+=4 63 la %r2,32(%r2) // i+=4
65 brct %r10,.Loop4_madd 64 brct %r4,.Loop4_madd
66 65
67 lghi %r10,3 66 la %r10,1(%r10) // see if len%4 is zero ...
68 nr %r4,%r10 // cnt=len%4 67 brct %r10,.Loop1_madd // without touching condition code:-)
69 jz .Lend_madd 68
69.Lend_madd:
70 alcgr %r8,zero // collect carry bit
71 lgr %r2,%r8
72 lmg %r6,%r10,48(%r15)
73 br %r14
70 74
71.Loop1_madd: 75.Loop1_madd:
72 lg %r7,0(%r2,%r3) // ap[i] 76 lg %r7,0(%r2,%r3) // ap[i]
73 mlgr %r6,%r5 // *=w 77 mlgr %r6,%r5 // *=w
74 algr %r7,%r8 // +=carry 78 alcgr %r7,%r8 // +=carry
75 alcgr %r6,zero 79 alcgr %r6,zero
76 alg %r7,0(%r2,%r1) // +=rp[i] 80 alg %r7,0(%r2,%r1) // +=rp[i]
77 alcgr %r6,zero
78 stg %r7,0(%r2,%r1) // rp[i]= 81 stg %r7,0(%r2,%r1) // rp[i]=
79 82
80 lgr %r8,%r6 83 lgr %r8,%r6
81 la %r2,8(%r2) // i++ 84 la %r2,8(%r2) // i++
82 brct %r4,.Loop1_madd 85 brct %r10,.Loop1_madd
83 86
84.Lend_madd: 87 j .Lend_madd
85 lgr %r2,%r8
86 lmg %r6,%r10,48(%r15)
87 br %r14
88.size bn_mul_add_words,.-bn_mul_add_words 88.size bn_mul_add_words,.-bn_mul_add_words
89 89
90// BN_ULONG bn_mul_words(BN_ULONG *r2,BN_ULONG *r3,int r4,BN_ULONG r5); 90// BN_ULONG bn_mul_words(BN_ULONG *r2,BN_ULONG *r3,int r4,BN_ULONG r5);
@@ -99,57 +99,57 @@ bn_mul_words:
99 bler %r14 // if (len<=0) return 0; 99 bler %r14 // if (len<=0) return 0;
100 100
101 stmg %r6,%r10,48(%r15) 101 stmg %r6,%r10,48(%r15)
102 lghi %r10,3
102 lghi %r8,0 // carry = 0 103 lghi %r8,0 // carry = 0
103 srag %r10,%r4,2 // cnt=len/4 104 nr %r10,%r4 // len%4
104 jz .Loop1_mul 105 sra %r4,2 // cnt=len/4
106 jz .Loop1_mul // carry is incidentally cleared if branch taken
107 algr zero,zero // clear carry
105 108
106.Loop4_mul: 109.Loop4_mul:
107 lg %r7,0(%r2,%r3) // ap[i] 110 lg %r7,0(%r2,%r3) // ap[i]
108 mlgr %r6,%r5 // *=w 111 mlgr %r6,%r5 // *=w
109 algr %r7,%r8 // +=carry 112 alcgr %r7,%r8 // +=carry
110 alcgr %r6,zero
111 stg %r7,0(%r2,%r1) // rp[i]= 113 stg %r7,0(%r2,%r1) // rp[i]=
112 114
113 lg %r9,8(%r2,%r3) 115 lg %r9,8(%r2,%r3)
114 mlgr %r8,%r5 116 mlgr %r8,%r5
115 algr %r9,%r6 117 alcgr %r9,%r6
116 alcgr %r8,zero
117 stg %r9,8(%r2,%r1) 118 stg %r9,8(%r2,%r1)
118 119
119 lg %r7,16(%r2,%r3) 120 lg %r7,16(%r2,%r3)
120 mlgr %r6,%r5 121 mlgr %r6,%r5
121 algr %r7,%r8 122 alcgr %r7,%r8
122 alcgr %r6,zero
123 stg %r7,16(%r2,%r1) 123 stg %r7,16(%r2,%r1)
124 124
125 lg %r9,24(%r2,%r3) 125 lg %r9,24(%r2,%r3)
126 mlgr %r8,%r5 126 mlgr %r8,%r5
127 algr %r9,%r6 127 alcgr %r9,%r6
128 alcgr %r8,zero
129 stg %r9,24(%r2,%r1) 128 stg %r9,24(%r2,%r1)
130 129
131 la %r2,32(%r2) // i+=4 130 la %r2,32(%r2) // i+=4
132 brct %r10,.Loop4_mul 131 brct %r4,.Loop4_mul
133 132
134 lghi %r10,3 133 la %r10,1(%r10) // see if len%4 is zero ...
135 nr %r4,%r10 // cnt=len%4 134 brct %r10,.Loop1_mul // without touching condition code:-)
136 jz .Lend_mul 135
136.Lend_mul:
137 alcgr %r8,zero // collect carry bit
138 lgr %r2,%r8
139 lmg %r6,%r10,48(%r15)
140 br %r14
137 141
138.Loop1_mul: 142.Loop1_mul:
139 lg %r7,0(%r2,%r3) // ap[i] 143 lg %r7,0(%r2,%r3) // ap[i]
140 mlgr %r6,%r5 // *=w 144 mlgr %r6,%r5 // *=w
141 algr %r7,%r8 // +=carry 145 alcgr %r7,%r8 // +=carry
142 alcgr %r6,zero
143 stg %r7,0(%r2,%r1) // rp[i]= 146 stg %r7,0(%r2,%r1) // rp[i]=
144 147
145 lgr %r8,%r6 148 lgr %r8,%r6
146 la %r2,8(%r2) // i++ 149 la %r2,8(%r2) // i++
147 brct %r4,.Loop1_mul 150 brct %r10,.Loop1_mul
148 151
149.Lend_mul: 152 j .Lend_mul
150 lgr %r2,%r8
151 lmg %r6,%r10,48(%r15)
152 br %r14
153.size bn_mul_words,.-bn_mul_words 153.size bn_mul_words,.-bn_mul_words
154 154
155// void bn_sqr_words(BN_ULONG *r2,BN_ULONG *r2,int r4) 155// void bn_sqr_words(BN_ULONG *r2,BN_ULONG *r2,int r4)
diff --git a/src/lib/libcrypto/doc/EVP_PKEY_verify.pod b/src/lib/libcrypto/doc/EVP_PKEY_verify.pod
index 10633da3f2..f93e5fc6c3 100644
--- a/src/lib/libcrypto/doc/EVP_PKEY_verify.pod
+++ b/src/lib/libcrypto/doc/EVP_PKEY_verify.pod
@@ -69,7 +69,7 @@ Verify signature using PKCS#1 and SHA256 digest:
69 /* Error */ 69 /* Error */
70 70
71 /* Perform operation */ 71 /* Perform operation */
72 ret = EVP_PKEY_verify(ctx, md, mdlen, sig, siglen); 72 ret = EVP_PKEY_verify(ctx, sig, siglen, md, mdlen);
73 73
74 /* ret == 1 indicates success, 0 verify failure and < 0 for some 74 /* ret == 1 indicates success, 0 verify failure and < 0 for some
75 * other error. 75 * other error.
diff --git a/src/lib/libcrypto/dsa/dsa_pmeth.c b/src/lib/libcrypto/dsa/dsa_pmeth.c
index 4ce91e20c6..e2df54fec6 100644
--- a/src/lib/libcrypto/dsa/dsa_pmeth.c
+++ b/src/lib/libcrypto/dsa/dsa_pmeth.c
@@ -187,6 +187,7 @@ static int pkey_dsa_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)
187 case EVP_PKEY_CTRL_MD: 187 case EVP_PKEY_CTRL_MD:
188 if (EVP_MD_type((const EVP_MD *)p2) != NID_sha1 && 188 if (EVP_MD_type((const EVP_MD *)p2) != NID_sha1 &&
189 EVP_MD_type((const EVP_MD *)p2) != NID_dsa && 189 EVP_MD_type((const EVP_MD *)p2) != NID_dsa &&
190 EVP_MD_type((const EVP_MD *)p2) != NID_dsaWithSHA &&
190 EVP_MD_type((const EVP_MD *)p2) != NID_sha224 && 191 EVP_MD_type((const EVP_MD *)p2) != NID_sha224 &&
191 EVP_MD_type((const EVP_MD *)p2) != NID_sha256) 192 EVP_MD_type((const EVP_MD *)p2) != NID_sha256)
192 { 193 {
diff --git a/src/lib/libcrypto/ec/ec2_mult.c b/src/lib/libcrypto/ec/ec2_mult.c
index ab631a50a2..e12b9b284a 100644
--- a/src/lib/libcrypto/ec/ec2_mult.c
+++ b/src/lib/libcrypto/ec/ec2_mult.c
@@ -319,6 +319,7 @@ int ec_GF2m_simple_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
319 int ret = 0; 319 int ret = 0;
320 size_t i; 320 size_t i;
321 EC_POINT *p=NULL; 321 EC_POINT *p=NULL;
322 EC_POINT *acc = NULL;
322 323
323 if (ctx == NULL) 324 if (ctx == NULL)
324 { 325 {
@@ -338,15 +339,16 @@ int ec_GF2m_simple_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
338 } 339 }
339 340
340 if ((p = EC_POINT_new(group)) == NULL) goto err; 341 if ((p = EC_POINT_new(group)) == NULL) goto err;
342 if ((acc = EC_POINT_new(group)) == NULL) goto err;
341 343
342 if (!EC_POINT_set_to_infinity(group, r)) goto err; 344 if (!EC_POINT_set_to_infinity(group, acc)) goto err;
343 345
344 if (scalar) 346 if (scalar)
345 { 347 {
346 if (!ec_GF2m_montgomery_point_multiply(group, p, scalar, group->generator, ctx)) goto err; 348 if (!ec_GF2m_montgomery_point_multiply(group, p, scalar, group->generator, ctx)) goto err;
347 if (BN_is_negative(scalar)) 349 if (BN_is_negative(scalar))
348 if (!group->meth->invert(group, p, ctx)) goto err; 350 if (!group->meth->invert(group, p, ctx)) goto err;
349 if (!group->meth->add(group, r, r, p, ctx)) goto err; 351 if (!group->meth->add(group, acc, acc, p, ctx)) goto err;
350 } 352 }
351 353
352 for (i = 0; i < num; i++) 354 for (i = 0; i < num; i++)
@@ -354,13 +356,16 @@ int ec_GF2m_simple_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
354 if (!ec_GF2m_montgomery_point_multiply(group, p, scalars[i], points[i], ctx)) goto err; 356 if (!ec_GF2m_montgomery_point_multiply(group, p, scalars[i], points[i], ctx)) goto err;
355 if (BN_is_negative(scalars[i])) 357 if (BN_is_negative(scalars[i]))
356 if (!group->meth->invert(group, p, ctx)) goto err; 358 if (!group->meth->invert(group, p, ctx)) goto err;
357 if (!group->meth->add(group, r, r, p, ctx)) goto err; 359 if (!group->meth->add(group, acc, acc, p, ctx)) goto err;
358 } 360 }
359 361
362 if (!EC_POINT_copy(r, acc)) goto err;
363
360 ret = 1; 364 ret = 1;
361 365
362 err: 366 err:
363 if (p) EC_POINT_free(p); 367 if (p) EC_POINT_free(p);
368 if (acc) EC_POINT_free(acc);
364 if (new_ctx != NULL) 369 if (new_ctx != NULL)
365 BN_CTX_free(new_ctx); 370 BN_CTX_free(new_ctx);
366 return ret; 371 return ret;
diff --git a/src/lib/libcrypto/ec/ec_key.c b/src/lib/libcrypto/ec/ec_key.c
index 12fb0e6d6d..522802c07a 100644
--- a/src/lib/libcrypto/ec/ec_key.c
+++ b/src/lib/libcrypto/ec/ec_key.c
@@ -304,7 +304,13 @@ int EC_KEY_check_key(const EC_KEY *eckey)
304 ECerr(EC_F_EC_KEY_CHECK_KEY, ERR_R_PASSED_NULL_PARAMETER); 304 ECerr(EC_F_EC_KEY_CHECK_KEY, ERR_R_PASSED_NULL_PARAMETER);
305 return 0; 305 return 0;
306 } 306 }
307 307
308 if (EC_POINT_is_at_infinity(eckey->group, eckey->pub_key))
309 {
310 ECerr(EC_F_EC_KEY_CHECK_KEY, EC_R_POINT_AT_INFINITY);
311 goto err;
312 }
313
308 if ((ctx = BN_CTX_new()) == NULL) 314 if ((ctx = BN_CTX_new()) == NULL)
309 goto err; 315 goto err;
310 if ((point = EC_POINT_new(eckey->group)) == NULL) 316 if ((point = EC_POINT_new(eckey->group)) == NULL)
diff --git a/src/lib/libcrypto/ecdh/ech_lib.c b/src/lib/libcrypto/ecdh/ech_lib.c
index e89b1d4772..4d8ea03d3d 100644
--- a/src/lib/libcrypto/ecdh/ech_lib.c
+++ b/src/lib/libcrypto/ecdh/ech_lib.c
@@ -96,7 +96,6 @@ const ECDH_METHOD *ECDH_get_default_method(void)
96 96
97int ECDH_set_method(EC_KEY *eckey, const ECDH_METHOD *meth) 97int ECDH_set_method(EC_KEY *eckey, const ECDH_METHOD *meth)
98 { 98 {
99 const ECDH_METHOD *mtmp;
100 ECDH_DATA *ecdh; 99 ECDH_DATA *ecdh;
101 100
102 ecdh = ecdh_check(eckey); 101 ecdh = ecdh_check(eckey);
@@ -104,8 +103,8 @@ int ECDH_set_method(EC_KEY *eckey, const ECDH_METHOD *meth)
104 if (ecdh == NULL) 103 if (ecdh == NULL)
105 return 0; 104 return 0;
106 105
107 mtmp = ecdh->meth;
108#if 0 106#if 0
107 mtmp = ecdh->meth;
109 if (mtmp->finish) 108 if (mtmp->finish)
110 mtmp->finish(eckey); 109 mtmp->finish(eckey);
111#endif 110#endif
diff --git a/src/lib/libcrypto/ecdsa/ecs_lib.c b/src/lib/libcrypto/ecdsa/ecs_lib.c
index 85e8a3a7ed..2ebae3aa27 100644
--- a/src/lib/libcrypto/ecdsa/ecs_lib.c
+++ b/src/lib/libcrypto/ecdsa/ecs_lib.c
@@ -83,7 +83,6 @@ const ECDSA_METHOD *ECDSA_get_default_method(void)
83 83
84int ECDSA_set_method(EC_KEY *eckey, const ECDSA_METHOD *meth) 84int ECDSA_set_method(EC_KEY *eckey, const ECDSA_METHOD *meth)
85{ 85{
86 const ECDSA_METHOD *mtmp;
87 ECDSA_DATA *ecdsa; 86 ECDSA_DATA *ecdsa;
88 87
89 ecdsa = ecdsa_check(eckey); 88 ecdsa = ecdsa_check(eckey);
@@ -91,7 +90,6 @@ int ECDSA_set_method(EC_KEY *eckey, const ECDSA_METHOD *meth)
91 if (ecdsa == NULL) 90 if (ecdsa == NULL)
92 return 0; 91 return 0;
93 92
94 mtmp = ecdsa->meth;
95#ifndef OPENSSL_NO_ENGINE 93#ifndef OPENSSL_NO_ENGINE
96 if (ecdsa->engine) 94 if (ecdsa->engine)
97 { 95 {
diff --git a/src/lib/libcrypto/ecdsa/ecs_ossl.c b/src/lib/libcrypto/ecdsa/ecs_ossl.c
index 551cf5068f..1bbf328de5 100644
--- a/src/lib/libcrypto/ecdsa/ecs_ossl.c
+++ b/src/lib/libcrypto/ecdsa/ecs_ossl.c
@@ -144,6 +144,14 @@ static int ecdsa_sign_setup(EC_KEY *eckey, BN_CTX *ctx_in, BIGNUM **kinvp,
144 } 144 }
145 while (BN_is_zero(k)); 145 while (BN_is_zero(k));
146 146
147 /* We do not want timing information to leak the length of k,
148 * so we compute G*k using an equivalent scalar of fixed
149 * bit-length. */
150
151 if (!BN_add(k, k, order)) goto err;
152 if (BN_num_bits(k) <= BN_num_bits(order))
153 if (!BN_add(k, k, order)) goto err;
154
147 /* compute r the x-coordinate of generator * k */ 155 /* compute r the x-coordinate of generator * k */
148 if (!EC_POINT_mul(group, tmp_point, k, NULL, NULL, ctx)) 156 if (!EC_POINT_mul(group, tmp_point, k, NULL, NULL, ctx))
149 { 157 {
diff --git a/src/lib/libcrypto/evp/m_sigver.c b/src/lib/libcrypto/evp/m_sigver.c
index f0b7f95059..7e2731f4a4 100644
--- a/src/lib/libcrypto/evp/m_sigver.c
+++ b/src/lib/libcrypto/evp/m_sigver.c
@@ -137,7 +137,7 @@ int EVP_DigestSignFinal(EVP_MD_CTX *ctx, unsigned char *sigret, size_t *siglen)
137 sctx = 0; 137 sctx = 0;
138 if (sigret) 138 if (sigret)
139 { 139 {
140 MS_STATIC EVP_MD_CTX tmp_ctx; 140 EVP_MD_CTX tmp_ctx;
141 unsigned char md[EVP_MAX_MD_SIZE]; 141 unsigned char md[EVP_MAX_MD_SIZE];
142 unsigned int mdlen; 142 unsigned int mdlen;
143 EVP_MD_CTX_init(&tmp_ctx); 143 EVP_MD_CTX_init(&tmp_ctx);
@@ -173,7 +173,7 @@ int EVP_DigestSignFinal(EVP_MD_CTX *ctx, unsigned char *sigret, size_t *siglen)
173 173
174int EVP_DigestVerifyFinal(EVP_MD_CTX *ctx, unsigned char *sig, size_t siglen) 174int EVP_DigestVerifyFinal(EVP_MD_CTX *ctx, unsigned char *sig, size_t siglen)
175 { 175 {
176 MS_STATIC EVP_MD_CTX tmp_ctx; 176 EVP_MD_CTX tmp_ctx;
177 unsigned char md[EVP_MAX_MD_SIZE]; 177 unsigned char md[EVP_MAX_MD_SIZE];
178 int r; 178 int r;
179 unsigned int mdlen; 179 unsigned int mdlen;
diff --git a/src/lib/libcrypto/evp/pmeth_lib.c b/src/lib/libcrypto/evp/pmeth_lib.c
index b2d8de3a8d..5481d4b8a5 100644
--- a/src/lib/libcrypto/evp/pmeth_lib.c
+++ b/src/lib/libcrypto/evp/pmeth_lib.c
@@ -134,6 +134,8 @@ static EVP_PKEY_CTX *int_ctx_new(EVP_PKEY *pkey, ENGINE *e, int id)
134 id = pkey->ameth->pkey_id; 134 id = pkey->ameth->pkey_id;
135 } 135 }
136#ifndef OPENSSL_NO_ENGINE 136#ifndef OPENSSL_NO_ENGINE
137 if (pkey && pkey->engine)
138 e = pkey->engine;
137 /* Try to find an ENGINE which implements this method */ 139 /* Try to find an ENGINE which implements this method */
138 if (e) 140 if (e)
139 { 141 {
diff --git a/src/lib/libcrypto/hmac/hm_pmeth.c b/src/lib/libcrypto/hmac/hm_pmeth.c
index 985921ca1a..71e8567a14 100644
--- a/src/lib/libcrypto/hmac/hm_pmeth.c
+++ b/src/lib/libcrypto/hmac/hm_pmeth.c
@@ -147,6 +147,8 @@ static int int_update(EVP_MD_CTX *ctx,const void *data,size_t count)
147 147
148static int hmac_signctx_init(EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx) 148static int hmac_signctx_init(EVP_PKEY_CTX *ctx, EVP_MD_CTX *mctx)
149 { 149 {
150 HMAC_PKEY_CTX *hctx = ctx->data;
151 HMAC_CTX_set_flags(&hctx->ctx, mctx->flags & ~EVP_MD_CTX_FLAG_NO_INIT);
150 EVP_MD_CTX_set_flags(mctx, EVP_MD_CTX_FLAG_NO_INIT); 152 EVP_MD_CTX_set_flags(mctx, EVP_MD_CTX_FLAG_NO_INIT);
151 mctx->update = int_update; 153 mctx->update = int_update;
152 return 1; 154 return 1;
diff --git a/src/lib/libcrypto/pem/pvkfmt.c b/src/lib/libcrypto/pem/pvkfmt.c
index d998a67fa5..5f130c4528 100644
--- a/src/lib/libcrypto/pem/pvkfmt.c
+++ b/src/lib/libcrypto/pem/pvkfmt.c
@@ -662,7 +662,7 @@ static int do_PVK_header(const unsigned char **in, unsigned int length,
662 662
663 { 663 {
664 const unsigned char *p = *in; 664 const unsigned char *p = *in;
665 unsigned int pvk_magic, keytype, is_encrypted; 665 unsigned int pvk_magic, is_encrypted;
666 if (skip_magic) 666 if (skip_magic)
667 { 667 {
668 if (length < 20) 668 if (length < 20)
@@ -689,7 +689,7 @@ static int do_PVK_header(const unsigned char **in, unsigned int length,
689 } 689 }
690 /* Skip reserved */ 690 /* Skip reserved */
691 p += 4; 691 p += 4;
692 keytype = read_ledword(&p); 692 /*keytype = */read_ledword(&p);
693 is_encrypted = read_ledword(&p); 693 is_encrypted = read_ledword(&p);
694 *psaltlen = read_ledword(&p); 694 *psaltlen = read_ledword(&p);
695 *pkeylen = read_ledword(&p); 695 *pkeylen = read_ledword(&p);
@@ -839,7 +839,7 @@ EVP_PKEY *b2i_PVK_bio(BIO *in, pem_password_cb *cb, void *u)
839static int i2b_PVK(unsigned char **out, EVP_PKEY*pk, int enclevel, 839static int i2b_PVK(unsigned char **out, EVP_PKEY*pk, int enclevel,
840 pem_password_cb *cb, void *u) 840 pem_password_cb *cb, void *u)
841 { 841 {
842 int outlen = 24, noinc, pklen; 842 int outlen = 24, pklen;
843 unsigned char *p, *salt = NULL; 843 unsigned char *p, *salt = NULL;
844 if (enclevel) 844 if (enclevel)
845 outlen += PVK_SALTLEN; 845 outlen += PVK_SALTLEN;
@@ -850,10 +850,7 @@ static int i2b_PVK(unsigned char **out, EVP_PKEY*pk, int enclevel,
850 if (!out) 850 if (!out)
851 return outlen; 851 return outlen;
852 if (*out) 852 if (*out)
853 {
854 p = *out; 853 p = *out;
855 noinc = 0;
856 }
857 else 854 else
858 { 855 {
859 p = OPENSSL_malloc(outlen); 856 p = OPENSSL_malloc(outlen);
@@ -863,7 +860,6 @@ static int i2b_PVK(unsigned char **out, EVP_PKEY*pk, int enclevel,
863 return -1; 860 return -1;
864 } 861 }
865 *out = p; 862 *out = p;
866 noinc = 1;
867 } 863 }
868 864
869 write_ledword(&p, MS_PVKMAGIC); 865 write_ledword(&p, MS_PVKMAGIC);
diff --git a/src/lib/libcrypto/sha/asm/sha1-armv4-large.pl b/src/lib/libcrypto/sha/asm/sha1-armv4-large.pl
index 88861af641..6e65fe3e01 100644
--- a/src/lib/libcrypto/sha/asm/sha1-armv4-large.pl
+++ b/src/lib/libcrypto/sha/asm/sha1-armv4-large.pl
@@ -37,9 +37,18 @@
37# modes are limited. As result it takes more instructions to do 37# modes are limited. As result it takes more instructions to do
38# the same job in Thumb, therefore the code is never twice as 38# the same job in Thumb, therefore the code is never twice as
39# small and always slower. 39# small and always slower.
40# [***] which is also ~35% better than compiler generated code. 40# [***] which is also ~35% better than compiler generated code. Dual-
41# issue Cortex A8 core was measured to process input block in
42# ~990 cycles.
41 43
42$output=shift; 44# August 2010.
45#
46# Rescheduling for dual-issue pipeline resulted in 13% improvement on
47# Cortex A8 core and in absolute terms ~870 cycles per input block
48# [or 13.6 cycles per byte].
49
50
51while (($output=shift) && ($output!~/^\w[\w\-]*\.\w+$/)) {}
43open STDOUT,">$output"; 52open STDOUT,">$output";
44 53
45$ctx="r0"; 54$ctx="r0";
@@ -58,43 +67,22 @@ $t3="r12";
58$Xi="r14"; 67$Xi="r14";
59@V=($a,$b,$c,$d,$e); 68@V=($a,$b,$c,$d,$e);
60 69
61# One can optimize this for aligned access on big-endian architecture,
62# but code's endian neutrality makes it too pretty:-)
63sub Xload {
64my ($a,$b,$c,$d,$e)=@_;
65$code.=<<___;
66 ldrb $t0,[$inp],#4
67 ldrb $t1,[$inp,#-3]
68 ldrb $t2,[$inp,#-2]
69 ldrb $t3,[$inp,#-1]
70 add $e,$K,$e,ror#2 @ E+=K_00_19
71 orr $t0,$t1,$t0,lsl#8
72 add $e,$e,$a,ror#27 @ E+=ROR(A,27)
73 orr $t0,$t2,$t0,lsl#8
74 eor $t1,$c,$d @ F_xx_xx
75 orr $t0,$t3,$t0,lsl#8
76 add $e,$e,$t0 @ E+=X[i]
77 str $t0,[$Xi,#-4]!
78___
79}
80sub Xupdate { 70sub Xupdate {
81my ($a,$b,$c,$d,$e,$flag)=@_; 71my ($a,$b,$c,$d,$e,$opt1,$opt2)=@_;
82$code.=<<___; 72$code.=<<___;
83 ldr $t0,[$Xi,#15*4] 73 ldr $t0,[$Xi,#15*4]
84 ldr $t1,[$Xi,#13*4] 74 ldr $t1,[$Xi,#13*4]
85 ldr $t2,[$Xi,#7*4] 75 ldr $t2,[$Xi,#7*4]
86 ldr $t3,[$Xi,#2*4]
87 add $e,$K,$e,ror#2 @ E+=K_xx_xx 76 add $e,$K,$e,ror#2 @ E+=K_xx_xx
77 ldr $t3,[$Xi,#2*4]
88 eor $t0,$t0,$t1 78 eor $t0,$t0,$t1
89 eor $t0,$t0,$t2 79 eor $t2,$t2,$t3
90 eor $t0,$t0,$t3 80 eor $t1,$c,$d @ F_xx_xx
91 add $e,$e,$a,ror#27 @ E+=ROR(A,27)
92___
93$code.=<<___ if (!defined($flag));
94 eor $t1,$c,$d @ F_xx_xx, but not in 40_59
95___
96$code.=<<___;
97 mov $t0,$t0,ror#31 81 mov $t0,$t0,ror#31
82 add $e,$e,$a,ror#27 @ E+=ROR(A,27)
83 eor $t0,$t0,$t2,ror#31
84 $opt1 @ F_xx_xx
85 $opt2 @ F_xx_xx
98 add $e,$e,$t0 @ E+=X[i] 86 add $e,$e,$t0 @ E+=X[i]
99 str $t0,[$Xi,#-4]! 87 str $t0,[$Xi,#-4]!
100___ 88___
@@ -102,19 +90,29 @@ ___
102 90
103sub BODY_00_15 { 91sub BODY_00_15 {
104my ($a,$b,$c,$d,$e)=@_; 92my ($a,$b,$c,$d,$e)=@_;
105 &Xload(@_);
106$code.=<<___; 93$code.=<<___;
94 ldrb $t0,[$inp],#4
95 ldrb $t1,[$inp,#-1]
96 ldrb $t2,[$inp,#-2]
97 add $e,$K,$e,ror#2 @ E+=K_00_19
98 ldrb $t3,[$inp,#-3]
99 add $e,$e,$a,ror#27 @ E+=ROR(A,27)
100 orr $t0,$t1,$t0,lsl#24
101 eor $t1,$c,$d @ F_xx_xx
102 orr $t0,$t0,$t2,lsl#8
103 orr $t0,$t0,$t3,lsl#16
107 and $t1,$b,$t1,ror#2 104 and $t1,$b,$t1,ror#2
105 add $e,$e,$t0 @ E+=X[i]
108 eor $t1,$t1,$d,ror#2 @ F_00_19(B,C,D) 106 eor $t1,$t1,$d,ror#2 @ F_00_19(B,C,D)
107 str $t0,[$Xi,#-4]!
109 add $e,$e,$t1 @ E+=F_00_19(B,C,D) 108 add $e,$e,$t1 @ E+=F_00_19(B,C,D)
110___ 109___
111} 110}
112 111
113sub BODY_16_19 { 112sub BODY_16_19 {
114my ($a,$b,$c,$d,$e)=@_; 113my ($a,$b,$c,$d,$e)=@_;
115 &Xupdate(@_); 114 &Xupdate(@_,"and $t1,$b,$t1,ror#2");
116$code.=<<___; 115$code.=<<___;
117 and $t1,$b,$t1,ror#2
118 eor $t1,$t1,$d,ror#2 @ F_00_19(B,C,D) 116 eor $t1,$t1,$d,ror#2 @ F_00_19(B,C,D)
119 add $e,$e,$t1 @ E+=F_00_19(B,C,D) 117 add $e,$e,$t1 @ E+=F_00_19(B,C,D)
120___ 118___
@@ -122,22 +120,18 @@ ___
122 120
123sub BODY_20_39 { 121sub BODY_20_39 {
124my ($a,$b,$c,$d,$e)=@_; 122my ($a,$b,$c,$d,$e)=@_;
125 &Xupdate(@_); 123 &Xupdate(@_,"eor $t1,$b,$t1,ror#2");
126$code.=<<___; 124$code.=<<___;
127 eor $t1,$b,$t1,ror#2 @ F_20_39(B,C,D)
128 add $e,$e,$t1 @ E+=F_20_39(B,C,D) 125 add $e,$e,$t1 @ E+=F_20_39(B,C,D)
129___ 126___
130} 127}
131 128
132sub BODY_40_59 { 129sub BODY_40_59 {
133my ($a,$b,$c,$d,$e)=@_; 130my ($a,$b,$c,$d,$e)=@_;
134 &Xupdate(@_,1); 131 &Xupdate(@_,"and $t1,$b,$t1,ror#2","and $t2,$c,$d");
135$code.=<<___; 132$code.=<<___;
136 and $t1,$b,$c,ror#2
137 orr $t2,$b,$c,ror#2
138 and $t2,$t2,$d,ror#2
139 orr $t1,$t1,$t2 @ F_40_59(B,C,D)
140 add $e,$e,$t1 @ E+=F_40_59(B,C,D) 133 add $e,$e,$t1 @ E+=F_40_59(B,C,D)
134 add $e,$e,$t2,ror#2
141___ 135___
142} 136}
143 137
diff --git a/src/lib/libcrypto/sha/asm/sha1-sparcv9.pl b/src/lib/libcrypto/sha/asm/sha1-sparcv9.pl
index 8306fc88cc..5c161cecd6 100644
--- a/src/lib/libcrypto/sha/asm/sha1-sparcv9.pl
+++ b/src/lib/libcrypto/sha/asm/sha1-sparcv9.pl
@@ -276,6 +276,7 @@ $code.=<<___;
276.type sha1_block_data_order,#function 276.type sha1_block_data_order,#function
277.size sha1_block_data_order,(.-sha1_block_data_order) 277.size sha1_block_data_order,(.-sha1_block_data_order)
278.asciz "SHA1 block transform for SPARCv9, CRYPTOGAMS by <appro\@openssl.org>" 278.asciz "SHA1 block transform for SPARCv9, CRYPTOGAMS by <appro\@openssl.org>"
279.align 4
279___ 280___
280 281
281$code =~ s/\`([^\`]*)\`/eval $1/gem; 282$code =~ s/\`([^\`]*)\`/eval $1/gem;
diff --git a/src/lib/libcrypto/sha/asm/sha1-sparcv9a.pl b/src/lib/libcrypto/sha/asm/sha1-sparcv9a.pl
index 15eb854bad..85e8d68086 100644
--- a/src/lib/libcrypto/sha/asm/sha1-sparcv9a.pl
+++ b/src/lib/libcrypto/sha/asm/sha1-sparcv9a.pl
@@ -539,6 +539,7 @@ $code.=<<___;
539.type sha1_block_data_order,#function 539.type sha1_block_data_order,#function
540.size sha1_block_data_order,(.-sha1_block_data_order) 540.size sha1_block_data_order,(.-sha1_block_data_order)
541.asciz "SHA1 block transform for SPARCv9a, CRYPTOGAMS by <appro\@openssl.org>" 541.asciz "SHA1 block transform for SPARCv9a, CRYPTOGAMS by <appro\@openssl.org>"
542.align 4
542___ 543___
543 544
544# Purpose of these subroutines is to explicitly encode VIS instructions, 545# Purpose of these subroutines is to explicitly encode VIS instructions,
diff --git a/src/lib/libcrypto/sha/asm/sha256-armv4.pl b/src/lib/libcrypto/sha/asm/sha256-armv4.pl
index 48d846deec..492cb62bc0 100644
--- a/src/lib/libcrypto/sha/asm/sha256-armv4.pl
+++ b/src/lib/libcrypto/sha/asm/sha256-armv4.pl
@@ -11,9 +11,14 @@
11 11
12# Performance is ~2x better than gcc 3.4 generated code and in "abso- 12# Performance is ~2x better than gcc 3.4 generated code and in "abso-
13# lute" terms is ~2250 cycles per 64-byte block or ~35 cycles per 13# lute" terms is ~2250 cycles per 64-byte block or ~35 cycles per
14# byte. 14# byte [on single-issue Xscale PXA250 core].
15 15
16$output=shift; 16# July 2010.
17#
18# Rescheduling for dual-issue pipeline resulted in 22% improvement on
19# Cortex A8 core and ~20 cycles per processed byte.
20
21while (($output=shift) && ($output!~/^\w[\w\-]*\.\w+$/)) {}
17open STDOUT,">$output"; 22open STDOUT,">$output";
18 23
19$ctx="r0"; $t0="r0"; 24$ctx="r0"; $t0="r0";
@@ -52,27 +57,27 @@ $code.=<<___ if ($i<16);
52___ 57___
53$code.=<<___; 58$code.=<<___;
54 ldr $t2,[$Ktbl],#4 @ *K256++ 59 ldr $t2,[$Ktbl],#4 @ *K256++
55 str $T1,[sp,#`$i%16`*4]
56 mov $t0,$e,ror#$Sigma1[0] 60 mov $t0,$e,ror#$Sigma1[0]
61 str $T1,[sp,#`$i%16`*4]
57 eor $t0,$t0,$e,ror#$Sigma1[1] 62 eor $t0,$t0,$e,ror#$Sigma1[1]
58 eor $t0,$t0,$e,ror#$Sigma1[2] @ Sigma1(e)
59 add $T1,$T1,$t0
60 eor $t1,$f,$g 63 eor $t1,$f,$g
64 eor $t0,$t0,$e,ror#$Sigma1[2] @ Sigma1(e)
61 and $t1,$t1,$e 65 and $t1,$t1,$e
66 add $T1,$T1,$t0
62 eor $t1,$t1,$g @ Ch(e,f,g) 67 eor $t1,$t1,$g @ Ch(e,f,g)
63 add $T1,$T1,$t1
64 add $T1,$T1,$h 68 add $T1,$T1,$h
65 add $T1,$T1,$t2
66 mov $h,$a,ror#$Sigma0[0] 69 mov $h,$a,ror#$Sigma0[0]
70 add $T1,$T1,$t1
67 eor $h,$h,$a,ror#$Sigma0[1] 71 eor $h,$h,$a,ror#$Sigma0[1]
72 add $T1,$T1,$t2
68 eor $h,$h,$a,ror#$Sigma0[2] @ Sigma0(a) 73 eor $h,$h,$a,ror#$Sigma0[2] @ Sigma0(a)
69 orr $t0,$a,$b 74 orr $t0,$a,$b
70 and $t0,$t0,$c
71 and $t1,$a,$b 75 and $t1,$a,$b
76 and $t0,$t0,$c
77 add $h,$h,$T1
72 orr $t0,$t0,$t1 @ Maj(a,b,c) 78 orr $t0,$t0,$t1 @ Maj(a,b,c)
73 add $h,$h,$t0
74 add $d,$d,$T1 79 add $d,$d,$T1
75 add $h,$h,$T1 80 add $h,$h,$t0
76___ 81___
77} 82}
78 83
@@ -80,19 +85,19 @@ sub BODY_16_XX {
80my ($i,$a,$b,$c,$d,$e,$f,$g,$h) = @_; 85my ($i,$a,$b,$c,$d,$e,$f,$g,$h) = @_;
81 86
82$code.=<<___; 87$code.=<<___;
83 ldr $t1,[sp,#`($i+1)%16`*4] @ $i 88 ldr $t1,[sp,#`($i+1)%16`*4] @ $i
84 ldr $t2,[sp,#`($i+14)%16`*4] 89 ldr $t2,[sp,#`($i+14)%16`*4]
85 ldr $T1,[sp,#`($i+0)%16`*4] 90 ldr $T1,[sp,#`($i+0)%16`*4]
86 ldr $inp,[sp,#`($i+9)%16`*4]
87 mov $t0,$t1,ror#$sigma0[0] 91 mov $t0,$t1,ror#$sigma0[0]
92 ldr $inp,[sp,#`($i+9)%16`*4]
88 eor $t0,$t0,$t1,ror#$sigma0[1] 93 eor $t0,$t0,$t1,ror#$sigma0[1]
89 eor $t0,$t0,$t1,lsr#$sigma0[2] @ sigma0(X[i+1]) 94 eor $t0,$t0,$t1,lsr#$sigma0[2] @ sigma0(X[i+1])
90 mov $t1,$t2,ror#$sigma1[0] 95 mov $t1,$t2,ror#$sigma1[0]
96 add $T1,$T1,$t0
91 eor $t1,$t1,$t2,ror#$sigma1[1] 97 eor $t1,$t1,$t2,ror#$sigma1[1]
98 add $T1,$T1,$inp
92 eor $t1,$t1,$t2,lsr#$sigma1[2] @ sigma1(X[i+14]) 99 eor $t1,$t1,$t2,lsr#$sigma1[2] @ sigma1(X[i+14])
93 add $T1,$T1,$t0
94 add $T1,$T1,$t1 100 add $T1,$T1,$t1
95 add $T1,$T1,$inp
96___ 101___
97 &BODY_00_15(@_); 102 &BODY_00_15(@_);
98} 103}
diff --git a/src/lib/libcrypto/sha/asm/sha512-armv4.pl b/src/lib/libcrypto/sha/asm/sha512-armv4.pl
index 4fbb94a914..3a35861ac6 100644
--- a/src/lib/libcrypto/sha/asm/sha512-armv4.pl
+++ b/src/lib/libcrypto/sha/asm/sha512-armv4.pl
@@ -10,7 +10,13 @@
10# SHA512 block procedure for ARMv4. September 2007. 10# SHA512 block procedure for ARMv4. September 2007.
11 11
12# This code is ~4.5 (four and a half) times faster than code generated 12# This code is ~4.5 (four and a half) times faster than code generated
13# by gcc 3.4 and it spends ~72 clock cycles per byte. 13# by gcc 3.4 and it spends ~72 clock cycles per byte [on single-issue
14# Xscale PXA250 core].
15#
16# July 2010.
17#
18# Rescheduling for dual-issue pipeline resulted in 6% improvement on
19# Cortex A8 core and ~40 cycles per processed byte.
14 20
15# Byte order [in]dependence. ========================================= 21# Byte order [in]dependence. =========================================
16# 22#
@@ -22,7 +28,7 @@ $hi=0;
22$lo=4; 28$lo=4;
23# ==================================================================== 29# ====================================================================
24 30
25$output=shift; 31while (($output=shift) && ($output!~/^\w[\w\-]*\.\w+$/)) {}
26open STDOUT,">$output"; 32open STDOUT,">$output";
27 33
28$ctx="r0"; 34$ctx="r0";
@@ -73,33 +79,31 @@ $code.=<<___;
73 eor $t0,$t0,$Elo,lsl#23 79 eor $t0,$t0,$Elo,lsl#23
74 eor $t1,$t1,$Ehi,lsl#23 @ Sigma1(e) 80 eor $t1,$t1,$Ehi,lsl#23 @ Sigma1(e)
75 adds $Tlo,$Tlo,$t0 81 adds $Tlo,$Tlo,$t0
76 adc $Thi,$Thi,$t1 @ T += Sigma1(e)
77 adds $Tlo,$Tlo,$t2
78 adc $Thi,$Thi,$t3 @ T += h
79
80 ldr $t0,[sp,#$Foff+0] @ f.lo 82 ldr $t0,[sp,#$Foff+0] @ f.lo
83 adc $Thi,$Thi,$t1 @ T += Sigma1(e)
81 ldr $t1,[sp,#$Foff+4] @ f.hi 84 ldr $t1,[sp,#$Foff+4] @ f.hi
85 adds $Tlo,$Tlo,$t2
82 ldr $t2,[sp,#$Goff+0] @ g.lo 86 ldr $t2,[sp,#$Goff+0] @ g.lo
87 adc $Thi,$Thi,$t3 @ T += h
83 ldr $t3,[sp,#$Goff+4] @ g.hi 88 ldr $t3,[sp,#$Goff+4] @ g.hi
84 str $Elo,[sp,#$Eoff+0]
85 str $Ehi,[sp,#$Eoff+4]
86 str $Alo,[sp,#$Aoff+0]
87 str $Ahi,[sp,#$Aoff+4]
88 89
89 eor $t0,$t0,$t2 90 eor $t0,$t0,$t2
91 str $Elo,[sp,#$Eoff+0]
90 eor $t1,$t1,$t3 92 eor $t1,$t1,$t3
93 str $Ehi,[sp,#$Eoff+4]
91 and $t0,$t0,$Elo 94 and $t0,$t0,$Elo
95 str $Alo,[sp,#$Aoff+0]
92 and $t1,$t1,$Ehi 96 and $t1,$t1,$Ehi
97 str $Ahi,[sp,#$Aoff+4]
93 eor $t0,$t0,$t2 98 eor $t0,$t0,$t2
94 eor $t1,$t1,$t3 @ Ch(e,f,g)
95
96 ldr $t2,[$Ktbl,#4] @ K[i].lo 99 ldr $t2,[$Ktbl,#4] @ K[i].lo
100 eor $t1,$t1,$t3 @ Ch(e,f,g)
97 ldr $t3,[$Ktbl,#0] @ K[i].hi 101 ldr $t3,[$Ktbl,#0] @ K[i].hi
98 ldr $Elo,[sp,#$Doff+0] @ d.lo
99 ldr $Ehi,[sp,#$Doff+4] @ d.hi
100 102
101 adds $Tlo,$Tlo,$t0 103 adds $Tlo,$Tlo,$t0
104 ldr $Elo,[sp,#$Doff+0] @ d.lo
102 adc $Thi,$Thi,$t1 @ T += Ch(e,f,g) 105 adc $Thi,$Thi,$t1 @ T += Ch(e,f,g)
106 ldr $Ehi,[sp,#$Doff+4] @ d.hi
103 adds $Tlo,$Tlo,$t2 107 adds $Tlo,$Tlo,$t2
104 adc $Thi,$Thi,$t3 @ T += K[i] 108 adc $Thi,$Thi,$t3 @ T += K[i]
105 adds $Elo,$Elo,$Tlo 109 adds $Elo,$Elo,$Tlo
diff --git a/src/lib/libcrypto/sha/asm/sha512-sparcv9.pl b/src/lib/libcrypto/sha/asm/sha512-sparcv9.pl
index 54241aab50..ec5d78135e 100644
--- a/src/lib/libcrypto/sha/asm/sha512-sparcv9.pl
+++ b/src/lib/libcrypto/sha/asm/sha512-sparcv9.pl
@@ -586,6 +586,7 @@ $code.=<<___;
586.type sha${label}_block_data_order,#function 586.type sha${label}_block_data_order,#function
587.size sha${label}_block_data_order,(.-sha${label}_block_data_order) 587.size sha${label}_block_data_order,(.-sha${label}_block_data_order)
588.asciz "SHA${label} block transform for SPARCv9, CRYPTOGAMS by <appro\@openssl.org>" 588.asciz "SHA${label} block transform for SPARCv9, CRYPTOGAMS by <appro\@openssl.org>"
589.align 4
589___ 590___
590 591
591$code =~ s/\`([^\`]*)\`/eval $1/gem; 592$code =~ s/\`([^\`]*)\`/eval $1/gem;
diff --git a/src/lib/libcrypto/sparccpuid.S b/src/lib/libcrypto/sparccpuid.S
index aa8b11efc9..ae61f7f5ce 100644
--- a/src/lib/libcrypto/sparccpuid.S
+++ b/src/lib/libcrypto/sparccpuid.S
@@ -225,13 +225,95 @@ _sparcv9_rdtick:
225 xor %o0,%o0,%o0 225 xor %o0,%o0,%o0
226 .word 0x91410000 !rd %tick,%o0 226 .word 0x91410000 !rd %tick,%o0
227 retl 227 retl
228 .word 0x93323020 !srlx %o2,32,%o1 228 .word 0x93323020 !srlx %o0,32,%o1
229.notick: 229.notick:
230 retl 230 retl
231 xor %o1,%o1,%o1 231 xor %o1,%o1,%o1
232.type _sparcv9_rdtick,#function 232.type _sparcv9_rdtick,#function
233.size _sparcv9_rdtick,.-_sparcv9_rdtick 233.size _sparcv9_rdtick,.-_sparcv9_rdtick
234 234
235.global _sparcv9_vis1_probe
236.align 8
237_sparcv9_vis1_probe:
238 .word 0x81b00d80 !fxor %f0,%f0,%f0
239 add %sp,BIAS+2,%o1
240 retl
241 .word 0xc19a5a40 !ldda [%o1]ASI_FP16_P,%f0
242.type _sparcv9_vis1_probe,#function
243.size _sparcv9_vis1_probe,.-_sparcv9_vis1_probe
244
245! Probe and instrument VIS1 instruction. Output is number of cycles it
246! takes to execute rdtick and pair of VIS1 instructions. US-Tx VIS unit
247! is slow (documented to be 6 cycles on T2) and the core is in-order
248! single-issue, it should be possible to distinguish Tx reliably...
249! Observed return values are:
250!
251! UltraSPARC IIe 7
252! UltraSPARC III 7
253! UltraSPARC T1 24
254!
255! Numbers for T2 and SPARC64 V-VII are more than welcomed.
256!
257! It would be possible to detect specifically US-T1 by instrumenting
258! fmul8ulx16, which is emulated on T1 and as such accounts for quite
259! a lot of %tick-s, couple of thousand on Linux...
260.global _sparcv9_vis1_instrument
261.align 8
262_sparcv9_vis1_instrument:
263 .word 0x91410000 !rd %tick,%o0
264 .word 0x81b00d80 !fxor %f0,%f0,%f0
265 .word 0x85b08d82 !fxor %f2,%f2,%f2
266 .word 0x93410000 !rd %tick,%o1
267 .word 0x81b00d80 !fxor %f0,%f0,%f0
268 .word 0x85b08d82 !fxor %f2,%f2,%f2
269 .word 0x95410000 !rd %tick,%o2
270 .word 0x81b00d80 !fxor %f0,%f0,%f0
271 .word 0x85b08d82 !fxor %f2,%f2,%f2
272 .word 0x97410000 !rd %tick,%o3
273 .word 0x81b00d80 !fxor %f0,%f0,%f0
274 .word 0x85b08d82 !fxor %f2,%f2,%f2
275 .word 0x99410000 !rd %tick,%o4
276
277 ! calculate intervals
278 sub %o1,%o0,%o0
279 sub %o2,%o1,%o1
280 sub %o3,%o2,%o2
281 sub %o4,%o3,%o3
282
283 ! find minumum value
284 cmp %o0,%o1
285 .word 0x38680002 !bgu,a %xcc,.+8
286 mov %o1,%o0
287 cmp %o0,%o2
288 .word 0x38680002 !bgu,a %xcc,.+8
289 mov %o2,%o0
290 cmp %o0,%o3
291 .word 0x38680002 !bgu,a %xcc,.+8
292 mov %o3,%o0
293
294 retl
295 nop
296.type _sparcv9_vis1_instrument,#function
297.size _sparcv9_vis1_instrument,.-_sparcv9_vis1_instrument
298
299.global _sparcv9_vis2_probe
300.align 8
301_sparcv9_vis2_probe:
302 retl
303 .word 0x81b00980 !bshuffle %f0,%f0,%f0
304.type _sparcv9_vis2_probe,#function
305.size _sparcv9_vis2_probe,.-_sparcv9_vis2_probe
306
307.global _sparcv9_fmadd_probe
308.align 8
309_sparcv9_fmadd_probe:
310 .word 0x81b00d80 !fxor %f0,%f0,%f0
311 .word 0x85b08d82 !fxor %f2,%f2,%f2
312 retl
313 .word 0x81b80440 !fmaddd %f0,%f0,%f2,%f0
314.type _sparcv9_fmadd_probe,#function
315.size _sparcv9_fmadd_probe,.-_sparcv9_fmadd_probe
316
235.global OPENSSL_cleanse 317.global OPENSSL_cleanse
236.align 32 318.align 32
237OPENSSL_cleanse: 319OPENSSL_cleanse:
diff --git a/src/lib/libcrypto/sparcv9cap.c b/src/lib/libcrypto/sparcv9cap.c
index 5f31d20bd0..ed195ab402 100644
--- a/src/lib/libcrypto/sparcv9cap.c
+++ b/src/lib/libcrypto/sparcv9cap.c
@@ -1,6 +1,8 @@
1#include <stdio.h> 1#include <stdio.h>
2#include <stdlib.h> 2#include <stdlib.h>
3#include <string.h> 3#include <string.h>
4#include <setjmp.h>
5#include <signal.h>
4#include <sys/time.h> 6#include <sys/time.h>
5#include <openssl/bn.h> 7#include <openssl/bn.h>
6 8
@@ -9,6 +11,7 @@
9#define SPARCV9_VIS1 (1<<2) 11#define SPARCV9_VIS1 (1<<2)
10#define SPARCV9_VIS2 (1<<3) /* reserved */ 12#define SPARCV9_VIS2 (1<<3) /* reserved */
11#define SPARCV9_FMADD (1<<4) /* reserved for SPARC64 V */ 13#define SPARCV9_FMADD (1<<4) /* reserved for SPARC64 V */
14
12static int OPENSSL_sparcv9cap_P=SPARCV9_TICK_PRIVILEGED; 15static int OPENSSL_sparcv9cap_P=SPARCV9_TICK_PRIVILEGED;
13 16
14int bn_mul_mont(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp, const BN_ULONG *np,const BN_ULONG *n0, int num) 17int bn_mul_mont(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp, const BN_ULONG *np,const BN_ULONG *n0, int num)
@@ -23,10 +26,14 @@ int bn_mul_mont(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp, const BN_U
23 return bn_mul_mont_int(rp,ap,bp,np,n0,num); 26 return bn_mul_mont_int(rp,ap,bp,np,n0,num);
24 } 27 }
25 28
29unsigned long _sparcv9_rdtick(void);
30void _sparcv9_vis1_probe(void);
31unsigned long _sparcv9_vis1_instrument(void);
32void _sparcv9_vis2_probe(void);
33void _sparcv9_fmadd_probe(void);
34
26unsigned long OPENSSL_rdtsc(void) 35unsigned long OPENSSL_rdtsc(void)
27 { 36 {
28 unsigned long _sparcv9_rdtick(void);
29
30 if (OPENSSL_sparcv9cap_P&SPARCV9_TICK_PRIVILEGED) 37 if (OPENSSL_sparcv9cap_P&SPARCV9_TICK_PRIVILEGED)
31#if defined(__sun) && defined(__SVR4) 38#if defined(__sun) && defined(__SVR4)
32 return gethrtime(); 39 return gethrtime();
@@ -37,8 +44,11 @@ unsigned long OPENSSL_rdtsc(void)
37 return _sparcv9_rdtick(); 44 return _sparcv9_rdtick();
38 } 45 }
39 46
40#if defined(__sun) && defined(__SVR4) 47#if 0 && defined(__sun) && defined(__SVR4)
41 48/* This code path is disabled, because of incompatibility of
49 * libdevinfo.so.1 and libmalloc.so.1 (see below for details)
50 */
51#include <malloc.h>
42#include <dlfcn.h> 52#include <dlfcn.h>
43#include <libdevinfo.h> 53#include <libdevinfo.h>
44#include <sys/systeminfo.h> 54#include <sys/systeminfo.h>
@@ -110,7 +120,21 @@ void OPENSSL_cpuid_setup(void)
110 return; 120 return;
111 } 121 }
112 } 122 }
113 123#ifdef M_KEEP
124 /*
125 * Solaris libdevinfo.so.1 is effectively incomatible with
126 * libmalloc.so.1. Specifically, if application is linked with
127 * -lmalloc, it crashes upon startup with SIGSEGV in
128 * free(3LIBMALLOC) called by di_fini. Prior call to
129 * mallopt(M_KEEP,0) somehow helps... But not always...
130 */
131 if ((h = dlopen(NULL,RTLD_LAZY)))
132 {
133 union { void *p; int (*f)(int,int); } sym;
134 if ((sym.p = dlsym(h,"mallopt"))) (*sym.f)(M_KEEP,0);
135 dlclose(h);
136 }
137#endif
114 if ((h = dlopen("libdevinfo.so.1",RTLD_LAZY))) do 138 if ((h = dlopen("libdevinfo.so.1",RTLD_LAZY))) do
115 { 139 {
116 di_init_t di_init; 140 di_init_t di_init;
@@ -137,9 +161,19 @@ void OPENSSL_cpuid_setup(void)
137 161
138#else 162#else
139 163
164static sigjmp_buf common_jmp;
165static void common_handler(int sig) { siglongjmp(common_jmp,sig); }
166
140void OPENSSL_cpuid_setup(void) 167void OPENSSL_cpuid_setup(void)
141 { 168 {
142 char *e; 169 char *e;
170 struct sigaction common_act,ill_oact,bus_oact;
171 sigset_t all_masked,oset;
172 int sig;
173 static int trigger=0;
174
175 if (trigger) return;
176 trigger=1;
143 177
144 if ((e=getenv("OPENSSL_sparcv9cap"))) 178 if ((e=getenv("OPENSSL_sparcv9cap")))
145 { 179 {
@@ -147,8 +181,57 @@ void OPENSSL_cpuid_setup(void)
147 return; 181 return;
148 } 182 }
149 183
150 /* For now we assume that the rest supports UltraSPARC-I* only */ 184 /* Initial value, fits UltraSPARC-I&II... */
151 OPENSSL_sparcv9cap_P |= SPARCV9_PREFER_FPU|SPARCV9_VIS1; 185 OPENSSL_sparcv9cap_P = SPARCV9_PREFER_FPU|SPARCV9_TICK_PRIVILEGED;
186
187 sigfillset(&all_masked);
188 sigdelset(&all_masked,SIGILL);
189 sigdelset(&all_masked,SIGTRAP);
190#ifdef SIGEMT
191 sigdelset(&all_masked,SIGEMT);
192#endif
193 sigdelset(&all_masked,SIGFPE);
194 sigdelset(&all_masked,SIGBUS);
195 sigdelset(&all_masked,SIGSEGV);
196 sigprocmask(SIG_SETMASK,&all_masked,&oset);
197
198 memset(&common_act,0,sizeof(common_act));
199 common_act.sa_handler = common_handler;
200 common_act.sa_mask = all_masked;
201
202 sigaction(SIGILL,&common_act,&ill_oact);
203 sigaction(SIGBUS,&common_act,&bus_oact);/* T1 fails 16-bit ldda [on Linux] */
204
205 if (sigsetjmp(common_jmp,1) == 0)
206 {
207 _sparcv9_rdtick();
208 OPENSSL_sparcv9cap_P &= ~SPARCV9_TICK_PRIVILEGED;
209 }
210
211 if (sigsetjmp(common_jmp,1) == 0)
212 {
213 _sparcv9_vis1_probe();
214 OPENSSL_sparcv9cap_P |= SPARCV9_VIS1;
215 /* detect UltraSPARC-Tx, see sparccpud.S for details... */
216 if (_sparcv9_vis1_instrument() >= 12)
217 OPENSSL_sparcv9cap_P &= ~(SPARCV9_VIS1|SPARCV9_PREFER_FPU);
218 else
219 {
220 _sparcv9_vis2_probe();
221 OPENSSL_sparcv9cap_P |= SPARCV9_VIS2;
222 }
223 }
224
225 if (sigsetjmp(common_jmp,1) == 0)
226 {
227 _sparcv9_fmadd_probe();
228 OPENSSL_sparcv9cap_P |= SPARCV9_FMADD;
229 }
230
231 sigaction(SIGBUS,&bus_oact,NULL);
232 sigaction(SIGILL,&ill_oact,NULL);
233
234 sigprocmask(SIG_SETMASK,&oset,NULL);
152 } 235 }
153 236
154#endif 237#endif
diff --git a/src/lib/libcrypto/ts/ts_verify_ctx.c b/src/lib/libcrypto/ts/ts_verify_ctx.c
index b079b50fc3..609b7735d4 100644
--- a/src/lib/libcrypto/ts/ts_verify_ctx.c
+++ b/src/lib/libcrypto/ts/ts_verify_ctx.c
@@ -56,7 +56,6 @@
56 * 56 *
57 */ 57 */
58 58
59#include <assert.h>
60#include "cryptlib.h" 59#include "cryptlib.h"
61#include <openssl/objects.h> 60#include <openssl/objects.h>
62#include <openssl/ts.h> 61#include <openssl/ts.h>
@@ -74,7 +73,7 @@ TS_VERIFY_CTX *TS_VERIFY_CTX_new(void)
74 73
75void TS_VERIFY_CTX_init(TS_VERIFY_CTX *ctx) 74void TS_VERIFY_CTX_init(TS_VERIFY_CTX *ctx)
76 { 75 {
77 assert(ctx != NULL); 76 OPENSSL_assert(ctx != NULL);
78 memset(ctx, 0, sizeof(TS_VERIFY_CTX)); 77 memset(ctx, 0, sizeof(TS_VERIFY_CTX));
79 } 78 }
80 79
@@ -116,7 +115,7 @@ TS_VERIFY_CTX *TS_REQ_to_TS_VERIFY_CTX(TS_REQ *req, TS_VERIFY_CTX *ctx)
116 ASN1_OCTET_STRING *msg; 115 ASN1_OCTET_STRING *msg;
117 const ASN1_INTEGER *nonce; 116 const ASN1_INTEGER *nonce;
118 117
119 assert(req != NULL); 118 OPENSSL_assert(req != NULL);
120 if (ret) 119 if (ret)
121 TS_VERIFY_CTX_cleanup(ret); 120 TS_VERIFY_CTX_cleanup(ret);
122 else 121 else
diff --git a/src/lib/libcrypto/x509v3/v3_ncons.c b/src/lib/libcrypto/x509v3/v3_ncons.c
index 689df46acd..a01dc64dd2 100644
--- a/src/lib/libcrypto/x509v3/v3_ncons.c
+++ b/src/lib/libcrypto/x509v3/v3_ncons.c
@@ -189,7 +189,6 @@ static int do_i2r_name_constraints(const X509V3_EXT_METHOD *method,
189 print_nc_ipadd(bp, tree->base->d.ip); 189 print_nc_ipadd(bp, tree->base->d.ip);
190 else 190 else
191 GENERAL_NAME_print(bp, tree->base); 191 GENERAL_NAME_print(bp, tree->base);
192 tree = sk_GENERAL_SUBTREE_value(trees, i);
193 BIO_puts(bp, "\n"); 192 BIO_puts(bp, "\n");
194 } 193 }
195 return 1; 194 return 1;
diff --git a/src/lib/libssl/d1_both.c b/src/lib/libssl/d1_both.c
index 4ce4064cc9..2180c6d4da 100644
--- a/src/lib/libssl/d1_both.c
+++ b/src/lib/libssl/d1_both.c
@@ -153,7 +153,7 @@
153#endif 153#endif
154 154
155static unsigned char bitmask_start_values[] = {0xff, 0xfe, 0xfc, 0xf8, 0xf0, 0xe0, 0xc0, 0x80}; 155static unsigned char bitmask_start_values[] = {0xff, 0xfe, 0xfc, 0xf8, 0xf0, 0xe0, 0xc0, 0x80};
156static unsigned char bitmask_end_values[] = {0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f}; 156static unsigned char bitmask_end_values[] = {0xff, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f};
157 157
158/* XDTLS: figure out the right values */ 158/* XDTLS: figure out the right values */
159static unsigned int g_probable_mtu[] = {1500 - 28, 512 - 28, 256 - 28}; 159static unsigned int g_probable_mtu[] = {1500 - 28, 512 - 28, 256 - 28};
@@ -464,20 +464,9 @@ again:
464 464
465 memset(msg_hdr, 0x00, sizeof(struct hm_header_st)); 465 memset(msg_hdr, 0x00, sizeof(struct hm_header_st));
466 466
467 s->d1->handshake_read_seq++; 467 /* Don't change sequence numbers while listening */
468 /* we just read a handshake message from the other side: 468 if (!s->d1->listen)
469 * this means that we don't need to retransmit of the 469 s->d1->handshake_read_seq++;
470 * buffered messages.
471 * XDTLS: may be able clear out this
472 * buffer a little sooner (i.e if an out-of-order
473 * handshake message/record is received at the record
474 * layer.
475 * XDTLS: exception is that the server needs to
476 * know that change cipher spec and finished messages
477 * have been received by the client before clearing this
478 * buffer. this can simply be done by waiting for the
479 * first data segment, but is there a better way? */
480 dtls1_clear_record_buffer(s);
481 470
482 s->init_msg = s->init_buf->data + DTLS1_HM_HEADER_LENGTH; 471 s->init_msg = s->init_buf->data + DTLS1_HM_HEADER_LENGTH;
483 return s->init_num; 472 return s->init_num;
@@ -813,9 +802,11 @@ dtls1_get_message_fragment(SSL *s, int st1, int stn, long max, int *ok)
813 802
814 /* 803 /*
815 * if this is a future (or stale) message it gets buffered 804 * if this is a future (or stale) message it gets buffered
816 * (or dropped)--no further processing at this time 805 * (or dropped)--no further processing at this time
806 * While listening, we accept seq 1 (ClientHello with cookie)
807 * although we're still expecting seq 0 (ClientHello)
817 */ 808 */
818 if ( msg_hdr.seq != s->d1->handshake_read_seq) 809 if (msg_hdr.seq != s->d1->handshake_read_seq && !(s->d1->listen && msg_hdr.seq == 1))
819 return dtls1_process_out_of_seq_message(s, &msg_hdr, ok); 810 return dtls1_process_out_of_seq_message(s, &msg_hdr, ok);
820 811
821 len = msg_hdr.msg_len; 812 len = msg_hdr.msg_len;
@@ -1322,7 +1313,8 @@ unsigned char *
1322dtls1_set_message_header(SSL *s, unsigned char *p, unsigned char mt, 1313dtls1_set_message_header(SSL *s, unsigned char *p, unsigned char mt,
1323 unsigned long len, unsigned long frag_off, unsigned long frag_len) 1314 unsigned long len, unsigned long frag_off, unsigned long frag_len)
1324 { 1315 {
1325 if ( frag_off == 0) 1316 /* Don't change sequence numbers while listening */
1317 if (frag_off == 0 && !s->d1->listen)
1326 { 1318 {
1327 s->d1->handshake_write_seq = s->d1->next_handshake_write_seq; 1319 s->d1->handshake_write_seq = s->d1->next_handshake_write_seq;
1328 s->d1->next_handshake_write_seq++; 1320 s->d1->next_handshake_write_seq++;
diff --git a/src/lib/libssl/d1_enc.c b/src/lib/libssl/d1_enc.c
index 8fa57347a9..becbab91c2 100644
--- a/src/lib/libssl/d1_enc.c
+++ b/src/lib/libssl/d1_enc.c
@@ -231,11 +231,7 @@ int dtls1_enc(SSL *s, int send)
231 if (!send) 231 if (!send)
232 { 232 {
233 if (l == 0 || l%bs != 0) 233 if (l == 0 || l%bs != 0)
234 { 234 return -1;
235 SSLerr(SSL_F_DTLS1_ENC,SSL_R_BLOCK_CIPHER_PAD_IS_WRONG);
236 ssl3_send_alert(s,SSL3_AL_FATAL,SSL_AD_DECRYPTION_FAILED);
237 return 0;
238 }
239 } 235 }
240 236
241 EVP_Cipher(ds,rec->data,rec->input,l); 237 EVP_Cipher(ds,rec->data,rec->input,l);
diff --git a/src/lib/libssl/d1_lib.c b/src/lib/libssl/d1_lib.c
index 96b220e87c..48e8b6ffbb 100644
--- a/src/lib/libssl/d1_lib.c
+++ b/src/lib/libssl/d1_lib.c
@@ -129,26 +129,33 @@ int dtls1_new(SSL *s)
129 return(1); 129 return(1);
130 } 130 }
131 131
132void dtls1_free(SSL *s) 132static void dtls1_clear_queues(SSL *s)
133 { 133 {
134 pitem *item = NULL; 134 pitem *item = NULL;
135 hm_fragment *frag = NULL; 135 hm_fragment *frag = NULL;
136 136 DTLS1_RECORD_DATA *rdata;
137 ssl3_free(s);
138 137
139 while( (item = pqueue_pop(s->d1->unprocessed_rcds.q)) != NULL) 138 while( (item = pqueue_pop(s->d1->unprocessed_rcds.q)) != NULL)
140 { 139 {
140 rdata = (DTLS1_RECORD_DATA *) item->data;
141 if (rdata->rbuf.buf)
142 {
143 OPENSSL_free(rdata->rbuf.buf);
144 }
141 OPENSSL_free(item->data); 145 OPENSSL_free(item->data);
142 pitem_free(item); 146 pitem_free(item);
143 } 147 }
144 pqueue_free(s->d1->unprocessed_rcds.q);
145 148
146 while( (item = pqueue_pop(s->d1->processed_rcds.q)) != NULL) 149 while( (item = pqueue_pop(s->d1->processed_rcds.q)) != NULL)
147 { 150 {
151 rdata = (DTLS1_RECORD_DATA *) item->data;
152 if (rdata->rbuf.buf)
153 {
154 OPENSSL_free(rdata->rbuf.buf);
155 }
148 OPENSSL_free(item->data); 156 OPENSSL_free(item->data);
149 pitem_free(item); 157 pitem_free(item);
150 } 158 }
151 pqueue_free(s->d1->processed_rcds.q);
152 159
153 while( (item = pqueue_pop(s->d1->buffered_messages)) != NULL) 160 while( (item = pqueue_pop(s->d1->buffered_messages)) != NULL)
154 { 161 {
@@ -157,7 +164,6 @@ void dtls1_free(SSL *s)
157 OPENSSL_free(frag); 164 OPENSSL_free(frag);
158 pitem_free(item); 165 pitem_free(item);
159 } 166 }
160 pqueue_free(s->d1->buffered_messages);
161 167
162 while ( (item = pqueue_pop(s->d1->sent_messages)) != NULL) 168 while ( (item = pqueue_pop(s->d1->sent_messages)) != NULL)
163 { 169 {
@@ -166,7 +172,6 @@ void dtls1_free(SSL *s)
166 OPENSSL_free(frag); 172 OPENSSL_free(frag);
167 pitem_free(item); 173 pitem_free(item);
168 } 174 }
169 pqueue_free(s->d1->sent_messages);
170 175
171 while ( (item = pqueue_pop(s->d1->buffered_app_data.q)) != NULL) 176 while ( (item = pqueue_pop(s->d1->buffered_app_data.q)) != NULL)
172 { 177 {
@@ -175,6 +180,18 @@ void dtls1_free(SSL *s)
175 OPENSSL_free(frag); 180 OPENSSL_free(frag);
176 pitem_free(item); 181 pitem_free(item);
177 } 182 }
183 }
184
185void dtls1_free(SSL *s)
186 {
187 ssl3_free(s);
188
189 dtls1_clear_queues(s);
190
191 pqueue_free(s->d1->unprocessed_rcds.q);
192 pqueue_free(s->d1->processed_rcds.q);
193 pqueue_free(s->d1->buffered_messages);
194 pqueue_free(s->d1->sent_messages);
178 pqueue_free(s->d1->buffered_app_data.q); 195 pqueue_free(s->d1->buffered_app_data.q);
179 196
180 OPENSSL_free(s->d1); 197 OPENSSL_free(s->d1);
@@ -182,6 +199,36 @@ void dtls1_free(SSL *s)
182 199
183void dtls1_clear(SSL *s) 200void dtls1_clear(SSL *s)
184 { 201 {
202 pqueue unprocessed_rcds;
203 pqueue processed_rcds;
204 pqueue buffered_messages;
205 pqueue sent_messages;
206 pqueue buffered_app_data;
207
208 if (s->d1)
209 {
210 unprocessed_rcds = s->d1->unprocessed_rcds.q;
211 processed_rcds = s->d1->processed_rcds.q;
212 buffered_messages = s->d1->buffered_messages;
213 sent_messages = s->d1->sent_messages;
214 buffered_app_data = s->d1->buffered_app_data.q;
215
216 dtls1_clear_queues(s);
217
218 memset(s->d1, 0, sizeof(*(s->d1)));
219
220 if (s->server)
221 {
222 s->d1->cookie_len = sizeof(s->d1->cookie);
223 }
224
225 s->d1->unprocessed_rcds.q = unprocessed_rcds;
226 s->d1->processed_rcds.q = processed_rcds;
227 s->d1->buffered_messages = buffered_messages;
228 s->d1->sent_messages = sent_messages;
229 s->d1->buffered_app_data.q = buffered_app_data;
230 }
231
185 ssl3_clear(s); 232 ssl3_clear(s);
186 if (s->options & SSL_OP_CISCO_ANYCONNECT) 233 if (s->options & SSL_OP_CISCO_ANYCONNECT)
187 s->version=DTLS1_BAD_VER; 234 s->version=DTLS1_BAD_VER;
@@ -330,6 +377,8 @@ void dtls1_stop_timer(SSL *s)
330 memset(&(s->d1->next_timeout), 0, sizeof(struct timeval)); 377 memset(&(s->d1->next_timeout), 0, sizeof(struct timeval));
331 s->d1->timeout_duration = 1; 378 s->d1->timeout_duration = 1;
332 BIO_ctrl(SSL_get_rbio(s), BIO_CTRL_DGRAM_SET_NEXT_TIMEOUT, 0, &(s->d1->next_timeout)); 379 BIO_ctrl(SSL_get_rbio(s), BIO_CTRL_DGRAM_SET_NEXT_TIMEOUT, 0, &(s->d1->next_timeout));
380 /* Clear retransmission buffer */
381 dtls1_clear_record_buffer(s);
333 } 382 }
334 383
335int dtls1_handle_timeout(SSL *s) 384int dtls1_handle_timeout(SSL *s)
@@ -349,7 +398,7 @@ int dtls1_handle_timeout(SSL *s)
349 { 398 {
350 /* fail the connection, enough alerts have been sent */ 399 /* fail the connection, enough alerts have been sent */
351 SSLerr(SSL_F_DTLS1_HANDLE_TIMEOUT,SSL_R_READ_TIMEOUT_EXPIRED); 400 SSLerr(SSL_F_DTLS1_HANDLE_TIMEOUT,SSL_R_READ_TIMEOUT_EXPIRED);
352 return 0; 401 return -1;
353 } 402 }
354 403
355 state->timeout.read_timeouts++; 404 state->timeout.read_timeouts++;
diff --git a/src/lib/libssl/test/cms-test.pl b/src/lib/libssl/test/cms-test.pl
index 9c50dff3e9..c938bcf00d 100644
--- a/src/lib/libssl/test/cms-test.pl
+++ b/src/lib/libssl/test/cms-test.pl
@@ -54,9 +54,13 @@
54# OpenSSL PKCS#7 and CMS implementations. 54# OpenSSL PKCS#7 and CMS implementations.
55 55
56my $ossl_path; 56my $ossl_path;
57my $redir = " 2>cms.err 1>cms.out"; 57my $redir = " 2> cms.err > cms.out";
58# Make VMS work
59if ( $^O eq "VMS" && -f "OSSLX:openssl.exe" ) {
60 $ossl_path = "pipe mcr OSSLX:openssl";
61}
58# Make MSYS work 62# Make MSYS work
59if ( $^O eq "MSWin32" && -f "../apps/openssl.exe" ) { 63elsif ( $^O eq "MSWin32" && -f "../apps/openssl.exe" ) {
60 $ossl_path = "cmd /c ..\\apps\\openssl"; 64 $ossl_path = "cmd /c ..\\apps\\openssl";
61} 65}
62elsif ( -f "../apps/openssl$ENV{EXE_EXT}" ) { 66elsif ( -f "../apps/openssl$ENV{EXE_EXT}" ) {
@@ -84,79 +88,79 @@ my @smime_pkcs7_tests = (
84 88
85 [ 89 [
86 "signed content DER format, RSA key", 90 "signed content DER format, RSA key",
87 "-sign -in smcont.txt -outform DER -nodetach" 91 "-sign -in smcont.txt -outform \"DER\" -nodetach"
88 . " -certfile $smdir/smroot.pem" 92 . " -certfile $smdir/smroot.pem"
89 . " -signer $smdir/smrsa1.pem -out test.cms", 93 . " -signer $smdir/smrsa1.pem -out test.cms",
90 "-verify -in test.cms -inform DER " 94 "-verify -in test.cms -inform \"DER\" "
91 . " -CAfile $smdir/smroot.pem -out smtst.txt" 95 . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
92 ], 96 ],
93 97
94 [ 98 [
95 "signed detached content DER format, RSA key", 99 "signed detached content DER format, RSA key",
96 "-sign -in smcont.txt -outform DER" 100 "-sign -in smcont.txt -outform \"DER\""
97 . " -signer $smdir/smrsa1.pem -out test.cms", 101 . " -signer $smdir/smrsa1.pem -out test.cms",
98 "-verify -in test.cms -inform DER " 102 "-verify -in test.cms -inform \"DER\" "
99 . " -CAfile $smdir/smroot.pem -out smtst.txt -content smcont.txt" 103 . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt -content smcont.txt"
100 ], 104 ],
101 105
102 [ 106 [
103 "signed content test streaming BER format, RSA", 107 "signed content test streaming BER format, RSA",
104 "-sign -in smcont.txt -outform DER -nodetach" 108 "-sign -in smcont.txt -outform \"DER\" -nodetach"
105 . " -stream -signer $smdir/smrsa1.pem -out test.cms", 109 . " -stream -signer $smdir/smrsa1.pem -out test.cms",
106 "-verify -in test.cms -inform DER " 110 "-verify -in test.cms -inform \"DER\" "
107 . " -CAfile $smdir/smroot.pem -out smtst.txt" 111 . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
108 ], 112 ],
109 113
110 [ 114 [
111 "signed content DER format, DSA key", 115 "signed content DER format, DSA key",
112 "-sign -in smcont.txt -outform DER -nodetach" 116 "-sign -in smcont.txt -outform \"DER\" -nodetach"
113 . " -signer $smdir/smdsa1.pem -out test.cms", 117 . " -signer $smdir/smdsa1.pem -out test.cms",
114 "-verify -in test.cms -inform DER " 118 "-verify -in test.cms -inform \"DER\" "
115 . " -CAfile $smdir/smroot.pem -out smtst.txt" 119 . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
116 ], 120 ],
117 121
118 [ 122 [
119 "signed detached content DER format, DSA key", 123 "signed detached content DER format, DSA key",
120 "-sign -in smcont.txt -outform DER" 124 "-sign -in smcont.txt -outform \"DER\""
121 . " -signer $smdir/smdsa1.pem -out test.cms", 125 . " -signer $smdir/smdsa1.pem -out test.cms",
122 "-verify -in test.cms -inform DER " 126 "-verify -in test.cms -inform \"DER\" "
123 . " -CAfile $smdir/smroot.pem -out smtst.txt -content smcont.txt" 127 . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt -content smcont.txt"
124 ], 128 ],
125 129
126 [ 130 [
127 "signed detached content DER format, add RSA signer", 131 "signed detached content DER format, add RSA signer",
128 "-resign -inform DER -in test.cms -outform DER" 132 "-resign -inform \"DER\" -in test.cms -outform \"DER\""
129 . " -signer $smdir/smrsa1.pem -out test2.cms", 133 . " -signer $smdir/smrsa1.pem -out test2.cms",
130 "-verify -in test2.cms -inform DER " 134 "-verify -in test2.cms -inform \"DER\" "
131 . " -CAfile $smdir/smroot.pem -out smtst.txt -content smcont.txt" 135 . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt -content smcont.txt"
132 ], 136 ],
133 137
134 [ 138 [
135 "signed content test streaming BER format, DSA key", 139 "signed content test streaming BER format, DSA key",
136 "-sign -in smcont.txt -outform DER -nodetach" 140 "-sign -in smcont.txt -outform \"DER\" -nodetach"
137 . " -stream -signer $smdir/smdsa1.pem -out test.cms", 141 . " -stream -signer $smdir/smdsa1.pem -out test.cms",
138 "-verify -in test.cms -inform DER " 142 "-verify -in test.cms -inform \"DER\" "
139 . " -CAfile $smdir/smroot.pem -out smtst.txt" 143 . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
140 ], 144 ],
141 145
142 [ 146 [
143 "signed content test streaming BER format, 2 DSA and 2 RSA keys", 147 "signed content test streaming BER format, 2 DSA and 2 RSA keys",
144 "-sign -in smcont.txt -outform DER -nodetach" 148 "-sign -in smcont.txt -outform \"DER\" -nodetach"
145 . " -signer $smdir/smrsa1.pem -signer $smdir/smrsa2.pem" 149 . " -signer $smdir/smrsa1.pem -signer $smdir/smrsa2.pem"
146 . " -signer $smdir/smdsa1.pem -signer $smdir/smdsa2.pem" 150 . " -signer $smdir/smdsa1.pem -signer $smdir/smdsa2.pem"
147 . " -stream -out test.cms", 151 . " -stream -out test.cms",
148 "-verify -in test.cms -inform DER " 152 "-verify -in test.cms -inform \"DER\" "
149 . " -CAfile $smdir/smroot.pem -out smtst.txt" 153 . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
150 ], 154 ],
151 155
152 [ 156 [
153"signed content test streaming BER format, 2 DSA and 2 RSA keys, no attributes", 157"signed content test streaming BER format, 2 DSA and 2 RSA keys, no attributes",
154 "-sign -in smcont.txt -outform DER -noattr -nodetach" 158 "-sign -in smcont.txt -outform \"DER\" -noattr -nodetach"
155 . " -signer $smdir/smrsa1.pem -signer $smdir/smrsa2.pem" 159 . " -signer $smdir/smrsa1.pem -signer $smdir/smrsa2.pem"
156 . " -signer $smdir/smdsa1.pem -signer $smdir/smdsa2.pem" 160 . " -signer $smdir/smdsa1.pem -signer $smdir/smdsa2.pem"
157 . " -stream -out test.cms", 161 . " -stream -out test.cms",
158 "-verify -in test.cms -inform DER " 162 "-verify -in test.cms -inform \"DER\" "
159 . " -CAfile $smdir/smroot.pem -out smtst.txt" 163 . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
160 ], 164 ],
161 165
162 [ 166 [
@@ -165,7 +169,7 @@ my @smime_pkcs7_tests = (
165 . " -signer $smdir/smrsa1.pem -signer $smdir/smrsa2.pem" 169 . " -signer $smdir/smrsa1.pem -signer $smdir/smrsa2.pem"
166 . " -signer $smdir/smdsa1.pem -signer $smdir/smdsa2.pem" 170 . " -signer $smdir/smdsa1.pem -signer $smdir/smdsa2.pem"
167 . " -stream -out test.cms", 171 . " -stream -out test.cms",
168 "-verify -in test.cms " . " -CAfile $smdir/smroot.pem -out smtst.txt" 172 "-verify -in test.cms " . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
169 ], 173 ],
170 174
171 [ 175 [
@@ -174,7 +178,7 @@ my @smime_pkcs7_tests = (
174 . " -signer $smdir/smrsa1.pem -signer $smdir/smrsa2.pem" 178 . " -signer $smdir/smrsa1.pem -signer $smdir/smrsa2.pem"
175 . " -signer $smdir/smdsa1.pem -signer $smdir/smdsa2.pem" 179 . " -signer $smdir/smdsa1.pem -signer $smdir/smdsa2.pem"
176 . " -stream -out test.cms", 180 . " -stream -out test.cms",
177 "-verify -in test.cms " . " -CAfile $smdir/smroot.pem -out smtst.txt" 181 "-verify -in test.cms " . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
178 ], 182 ],
179 183
180 [ 184 [
@@ -215,12 +219,12 @@ my @smime_cms_tests = (
215 219
216 [ 220 [
217 "signed content test streaming BER format, 2 DSA and 2 RSA keys, keyid", 221 "signed content test streaming BER format, 2 DSA and 2 RSA keys, keyid",
218 "-sign -in smcont.txt -outform DER -nodetach -keyid" 222 "-sign -in smcont.txt -outform \"DER\" -nodetach -keyid"
219 . " -signer $smdir/smrsa1.pem -signer $smdir/smrsa2.pem" 223 . " -signer $smdir/smrsa1.pem -signer $smdir/smrsa2.pem"
220 . " -signer $smdir/smdsa1.pem -signer $smdir/smdsa2.pem" 224 . " -signer $smdir/smdsa1.pem -signer $smdir/smdsa2.pem"
221 . " -stream -out test.cms", 225 . " -stream -out test.cms",
222 "-verify -in test.cms -inform DER " 226 "-verify -in test.cms -inform \"DER\" "
223 . " -CAfile $smdir/smroot.pem -out smtst.txt" 227 . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
224 ], 228 ],
225 229
226 [ 230 [
@@ -230,7 +234,7 @@ my @smime_cms_tests = (
230 . " -signer $smdir/smdsa1.pem -signer $smdir/smdsa2.pem" 234 . " -signer $smdir/smdsa1.pem -signer $smdir/smdsa2.pem"
231 . " -stream -out test.cms", 235 . " -stream -out test.cms",
232 "-verify -in test.cms -inform PEM " 236 "-verify -in test.cms -inform PEM "
233 . " -CAfile $smdir/smroot.pem -out smtst.txt" 237 . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
234 ], 238 ],
235 239
236 [ 240 [
@@ -239,7 +243,7 @@ my @smime_cms_tests = (
239 . " -receipt_request_to test\@openssl.org -receipt_request_all" 243 . " -receipt_request_to test\@openssl.org -receipt_request_all"
240 . " -out test.cms", 244 . " -out test.cms",
241 "-verify -in test.cms " 245 "-verify -in test.cms "
242 . " -CAfile $smdir/smroot.pem -out smtst.txt" 246 . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
243 ], 247 ],
244 248
245 [ 249 [
@@ -248,7 +252,7 @@ my @smime_cms_tests = (
248 . " -signer $smdir/smrsa2.pem" 252 . " -signer $smdir/smrsa2.pem"
249 . " -out test2.cms", 253 . " -out test2.cms",
250 "-verify_receipt test2.cms -in test.cms" 254 "-verify_receipt test2.cms -in test.cms"
251 . " -CAfile $smdir/smroot.pem" 255 . " \"-CAfile\" $smdir/smroot.pem"
252 ], 256 ],
253 257
254 [ 258 [
@@ -289,38 +293,38 @@ my @smime_cms_tests = (
289 293
290 [ 294 [
291 "encrypted content test streaming PEM format, 128 bit RC2 key", 295 "encrypted content test streaming PEM format, 128 bit RC2 key",
292 "-EncryptedData_encrypt -in smcont.txt -outform PEM" 296 "\"-EncryptedData_encrypt\" -in smcont.txt -outform PEM"
293 . " -rc2 -secretkey 000102030405060708090A0B0C0D0E0F" 297 . " -rc2 -secretkey 000102030405060708090A0B0C0D0E0F"
294 . " -stream -out test.cms", 298 . " -stream -out test.cms",
295 "-EncryptedData_decrypt -in test.cms -inform PEM " 299 "\"-EncryptedData_decrypt\" -in test.cms -inform PEM "
296 . " -secretkey 000102030405060708090A0B0C0D0E0F -out smtst.txt" 300 . " -secretkey 000102030405060708090A0B0C0D0E0F -out smtst.txt"
297 ], 301 ],
298 302
299 [ 303 [
300 "encrypted content test streaming PEM format, 40 bit RC2 key", 304 "encrypted content test streaming PEM format, 40 bit RC2 key",
301 "-EncryptedData_encrypt -in smcont.txt -outform PEM" 305 "\"-EncryptedData_encrypt\" -in smcont.txt -outform PEM"
302 . " -rc2 -secretkey 0001020304" 306 . " -rc2 -secretkey 0001020304"
303 . " -stream -out test.cms", 307 . " -stream -out test.cms",
304 "-EncryptedData_decrypt -in test.cms -inform PEM " 308 "\"-EncryptedData_decrypt\" -in test.cms -inform PEM "
305 . " -secretkey 0001020304 -out smtst.txt" 309 . " -secretkey 0001020304 -out smtst.txt"
306 ], 310 ],
307 311
308 [ 312 [
309 "encrypted content test streaming PEM format, triple DES key", 313 "encrypted content test streaming PEM format, triple DES key",
310 "-EncryptedData_encrypt -in smcont.txt -outform PEM" 314 "\"-EncryptedData_encrypt\" -in smcont.txt -outform PEM"
311 . " -des3 -secretkey 000102030405060708090A0B0C0D0E0F1011121314151617" 315 . " -des3 -secretkey 000102030405060708090A0B0C0D0E0F1011121314151617"
312 . " -stream -out test.cms", 316 . " -stream -out test.cms",
313 "-EncryptedData_decrypt -in test.cms -inform PEM " 317 "\"-EncryptedData_decrypt\" -in test.cms -inform PEM "
314 . " -secretkey 000102030405060708090A0B0C0D0E0F1011121314151617" 318 . " -secretkey 000102030405060708090A0B0C0D0E0F1011121314151617"
315 . " -out smtst.txt" 319 . " -out smtst.txt"
316 ], 320 ],
317 321
318 [ 322 [
319 "encrypted content test streaming PEM format, 128 bit AES key", 323 "encrypted content test streaming PEM format, 128 bit AES key",
320 "-EncryptedData_encrypt -in smcont.txt -outform PEM" 324 "\"-EncryptedData_encrypt\" -in smcont.txt -outform PEM"
321 . " -aes128 -secretkey 000102030405060708090A0B0C0D0E0F" 325 . " -aes128 -secretkey 000102030405060708090A0B0C0D0E0F"
322 . " -stream -out test.cms", 326 . " -stream -out test.cms",
323 "-EncryptedData_decrypt -in test.cms -inform PEM " 327 "\"-EncryptedData_decrypt\" -in test.cms -inform PEM "
324 . " -secretkey 000102030405060708090A0B0C0D0E0F -out smtst.txt" 328 . " -secretkey 000102030405060708090A0B0C0D0E0F -out smtst.txt"
325 ], 329 ],
326 330