summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordjm <>2005-04-29 05:37:34 +0000
committerdjm <>2005-04-29 05:37:34 +0000
commitf396ed0f5ce0af56bfde2e75e15cf1f52924c779 (patch)
tree32685998ee195b43c649d12fa381164a929e528a
parent411d389aff1d4ca3241d9d89edb4110c1cf05035 (diff)
parenta95585a25ab25668b931a78b7543f707a3354db8 (diff)
downloadopenbsd-f396ed0f5ce0af56bfde2e75e15cf1f52924c779.tar.gz
openbsd-f396ed0f5ce0af56bfde2e75e15cf1f52924c779.tar.bz2
openbsd-f396ed0f5ce0af56bfde2e75e15cf1f52924c779.zip
This commit was generated by cvs2git to track changes on a CVS vendor
branch.
-rw-r--r--src/lib/libcrypto/bn/asm/ppc.pl2081
-rw-r--r--src/lib/libcrypto/bn/asm/x86_64-gcc.c54
-rw-r--r--src/lib/libcrypto/doc/X509_NAME_ENTRY_get_object.pod6
-rw-r--r--src/lib/libcrypto/doc/X509_NAME_add_entry_by_txt.pod6
-rw-r--r--src/lib/libcrypto/doc/X509_NAME_print_ex.pod4
-rw-r--r--src/lib/libcrypto/evp/e_old.c108
-rw-r--r--src/lib/libcrypto/o_str.c96
-rw-r--r--src/lib/libcrypto/sha/asm/sha1-ia64.pl549
-rw-r--r--src/lib/libcrypto/x509v3/v3_pci.c313
-rw-r--r--src/lib/libcrypto/x509v3/v3_pcia.c55
-rw-r--r--src/lib/libssl/test/CAss.cnf8
-rw-r--r--src/lib/libssl/test/P1ss.cnf37
-rw-r--r--src/lib/libssl/test/P2ss.cnf45
-rw-r--r--src/lib/libssl/test/Uss.cnf8
-rw-r--r--src/lib/libssl/test/testsslproxy10
15 files changed, 3356 insertions, 24 deletions
diff --git a/src/lib/libcrypto/bn/asm/ppc.pl b/src/lib/libcrypto/bn/asm/ppc.pl
new file mode 100644
index 0000000000..307c7ccb35
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/ppc.pl
@@ -0,0 +1,2081 @@
1#!/usr/bin/env perl
2#
3# Implemented as a Perl wrapper as we want to support several different
4# architectures with single file. We pick up the target based on the
5# file name we are asked to generate.
6#
7# It should be noted though that this perl code is nothing like
8# <openssl>/crypto/perlasm/x86*. In this case perl is used pretty much
9# as pre-processor to cover for platform differences in name decoration,
10# linker tables, 32-/64-bit instruction sets...
11#
12# As you might know there're several PowerPC ABI in use. Most notably
13# Linux and AIX use different 32-bit ABIs. Good news are that these ABIs
14# are similar enough to implement leaf(!) functions, which would be ABI
15# neutral. And that's what you find here: ABI neutral leaf functions.
16# In case you wonder what that is...
17#
18# AIX performance
19#
20# MEASUREMENTS WITH cc ON a 200 MhZ PowerPC 604e.
21#
22# The following is the performance of 32-bit compiler
23# generated code:
24#
25# OpenSSL 0.9.6c 21 dec 2001
26# built on: Tue Jun 11 11:06:51 EDT 2002
27# options:bn(64,32) ...
28#compiler: cc -DTHREADS -DAIX -DB_ENDIAN -DBN_LLONG -O3
29# sign verify sign/s verify/s
30#rsa 512 bits 0.0098s 0.0009s 102.0 1170.6
31#rsa 1024 bits 0.0507s 0.0026s 19.7 387.5
32#rsa 2048 bits 0.3036s 0.0085s 3.3 117.1
33#rsa 4096 bits 2.0040s 0.0299s 0.5 33.4
34#dsa 512 bits 0.0087s 0.0106s 114.3 94.5
35#dsa 1024 bits 0.0256s 0.0313s 39.0 32.0
36#
37# Same bechmark with this assembler code:
38#
39#rsa 512 bits 0.0056s 0.0005s 178.6 2049.2
40#rsa 1024 bits 0.0283s 0.0015s 35.3 674.1
41#rsa 2048 bits 0.1744s 0.0050s 5.7 201.2
42#rsa 4096 bits 1.1644s 0.0179s 0.9 55.7
43#dsa 512 bits 0.0052s 0.0062s 191.6 162.0
44#dsa 1024 bits 0.0149s 0.0180s 67.0 55.5
45#
46# Number of operations increases by at almost 75%
47#
48# Here are performance numbers for 64-bit compiler
49# generated code:
50#
51# OpenSSL 0.9.6g [engine] 9 Aug 2002
52# built on: Fri Apr 18 16:59:20 EDT 2003
53# options:bn(64,64) ...
54# compiler: cc -DTHREADS -D_REENTRANT -q64 -DB_ENDIAN -O3
55# sign verify sign/s verify/s
56#rsa 512 bits 0.0028s 0.0003s 357.1 3844.4
57#rsa 1024 bits 0.0148s 0.0008s 67.5 1239.7
58#rsa 2048 bits 0.0963s 0.0028s 10.4 353.0
59#rsa 4096 bits 0.6538s 0.0102s 1.5 98.1
60#dsa 512 bits 0.0026s 0.0032s 382.5 313.7
61#dsa 1024 bits 0.0081s 0.0099s 122.8 100.6
62#
63# Same benchmark with this assembler code:
64#
65#rsa 512 bits 0.0020s 0.0002s 510.4 6273.7
66#rsa 1024 bits 0.0088s 0.0005s 114.1 2128.3
67#rsa 2048 bits 0.0540s 0.0016s 18.5 622.5
68#rsa 4096 bits 0.3700s 0.0058s 2.7 171.0
69#dsa 512 bits 0.0016s 0.0020s 610.7 507.1
70#dsa 1024 bits 0.0047s 0.0058s 212.5 173.2
71#
72# Again, performance increases by at about 75%
73#
74# Mac OS X, Apple G5 1.8GHz (Note this is 32 bit code)
75# OpenSSL 0.9.7c 30 Sep 2003
76#
77# Original code.
78#
79#rsa 512 bits 0.0011s 0.0001s 906.1 11012.5
80#rsa 1024 bits 0.0060s 0.0003s 166.6 3363.1
81#rsa 2048 bits 0.0370s 0.0010s 27.1 982.4
82#rsa 4096 bits 0.2426s 0.0036s 4.1 280.4
83#dsa 512 bits 0.0010s 0.0012s 1038.1 841.5
84#dsa 1024 bits 0.0030s 0.0037s 329.6 269.7
85#dsa 2048 bits 0.0101s 0.0127s 98.9 78.6
86#
87# Same benchmark with this assembler code:
88#
89#rsa 512 bits 0.0007s 0.0001s 1416.2 16645.9
90#rsa 1024 bits 0.0036s 0.0002s 274.4 5380.6
91#rsa 2048 bits 0.0222s 0.0006s 45.1 1589.5
92#rsa 4096 bits 0.1469s 0.0022s 6.8 449.6
93#dsa 512 bits 0.0006s 0.0007s 1664.2 1376.2
94#dsa 1024 bits 0.0018s 0.0023s 545.0 442.2
95#dsa 2048 bits 0.0061s 0.0075s 163.5 132.8
96#
97# Performance increase of ~60%
98#
99# If you have comments or suggestions to improve code send
100# me a note at schari@us.ibm.com
101#
102
103$opf = shift;
104
105if ($opf =~ /32\.s/) {
106 $BITS= 32;
107 $BNSZ= $BITS/8;
108 $ISA= "\"ppc\"";
109
110 $LD= "lwz"; # load
111 $LDU= "lwzu"; # load and update
112 $ST= "stw"; # store
113 $STU= "stwu"; # store and update
114 $UMULL= "mullw"; # unsigned multiply low
115 $UMULH= "mulhwu"; # unsigned multiply high
116 $UDIV= "divwu"; # unsigned divide
117 $UCMPI= "cmplwi"; # unsigned compare with immediate
118 $UCMP= "cmplw"; # unsigned compare
119 $COUNTZ="cntlzw"; # count leading zeros
120 $SHL= "slw"; # shift left
121 $SHR= "srw"; # unsigned shift right
122 $SHRI= "srwi"; # unsigned shift right by immediate
123 $SHLI= "slwi"; # shift left by immediate
124 $CLRU= "clrlwi"; # clear upper bits
125 $INSR= "insrwi"; # insert right
126 $ROTL= "rotlwi"; # rotate left by immediate
127} elsif ($opf =~ /64\.s/) {
128 $BITS= 64;
129 $BNSZ= $BITS/8;
130 $ISA= "\"ppc64\"";
131
132 # same as above, but 64-bit mnemonics...
133 $LD= "ld"; # load
134 $LDU= "ldu"; # load and update
135 $ST= "std"; # store
136 $STU= "stdu"; # store and update
137 $UMULL= "mulld"; # unsigned multiply low
138 $UMULH= "mulhdu"; # unsigned multiply high
139 $UDIV= "divdu"; # unsigned divide
140 $UCMPI= "cmpldi"; # unsigned compare with immediate
141 $UCMP= "cmpld"; # unsigned compare
142 $COUNTZ="cntlzd"; # count leading zeros
143 $SHL= "sld"; # shift left
144 $SHR= "srd"; # unsigned shift right
145 $SHRI= "srdi"; # unsigned shift right by immediate
146 $SHLI= "sldi"; # shift left by immediate
147 $CLRU= "clrldi"; # clear upper bits
148 $INSR= "insrdi"; # insert right
149 $ROTL= "rotldi"; # rotate left by immediate
150} else { die "nonsense $opf"; }
151
152( defined shift || open STDOUT,">$opf" ) || die "can't open $opf: $!";
153
154# function entry points from the AIX code
155#
156# There are other, more elegant, ways to handle this. We (IBM) chose
157# this approach as it plays well with scripts we run to 'namespace'
158# OpenSSL .i.e. we add a prefix to all the public symbols so we can
159# co-exist in the same process with other implementations of OpenSSL.
160# 'cleverer' ways of doing these substitutions tend to hide data we
161# need to be obvious.
162#
163my @items = ("bn_sqr_comba4",
164 "bn_sqr_comba8",
165 "bn_mul_comba4",
166 "bn_mul_comba8",
167 "bn_sub_words",
168 "bn_add_words",
169 "bn_div_words",
170 "bn_sqr_words",
171 "bn_mul_words",
172 "bn_mul_add_words");
173
174if ($opf =~ /linux/) { do_linux(); }
175elsif ($opf =~ /aix/) { do_aix(); }
176elsif ($opf =~ /osx/) { do_osx(); }
177else { do_bsd(); }
178
179sub do_linux {
180 $d=&data();
181
182 if ($BITS==64) {
183 foreach $t (@items) {
184 $d =~ s/\.$t:/\
185\t.section\t".opd","aw"\
186\t.align\t3\
187\t.globl\t$t\
188$t:\
189\t.quad\t.$t,.TOC.\@tocbase,0\
190\t.size\t$t,24\
191\t.previous\n\
192\t.type\t.$t,\@function\
193\t.globl\t.$t\
194.$t:/g;
195 }
196 }
197 else {
198 foreach $t (@items) {
199 $d=~s/\.$t/$t/g;
200 }
201 }
202 # hide internal labels to avoid pollution of name table...
203 $d=~s/Lppcasm_/.Lppcasm_/gm;
204 print $d;
205}
206
207sub do_aix {
208 # AIX assembler is smart enough to please the linker without
209 # making us do something special...
210 print &data();
211}
212
213# MacOSX 32 bit
214sub do_osx {
215 $d=&data();
216 # Change the bn symbol prefix from '.' to '_'
217 foreach $t (@items) {
218 $d=~s/\.$t/_$t/g;
219 }
220 # Change .machine to something OS X asm will accept
221 $d=~s/\.machine.*/.text/g;
222 $d=~s/\#/;/g; # change comment from '#' to ';'
223 print $d;
224}
225
226# BSD (Untested)
227sub do_bsd {
228 $d=&data();
229 foreach $t (@items) {
230 $d=~s/\.$t/_$t/g;
231 }
232 print $d;
233}
234
235sub data {
236 local($data)=<<EOF;
237#--------------------------------------------------------------------
238#
239#
240#
241#
242# File: ppc32.s
243#
244# Created by: Suresh Chari
245# IBM Thomas J. Watson Research Library
246# Hawthorne, NY
247#
248#
249# Description: Optimized assembly routines for OpenSSL crypto
250# on the 32 bitPowerPC platform.
251#
252#
253# Version History
254#
255# 2. Fixed bn_add,bn_sub and bn_div_words, added comments,
256# cleaned up code. Also made a single version which can
257# be used for both the AIX and Linux compilers. See NOTE
258# below.
259# 12/05/03 Suresh Chari
260# (with lots of help from) Andy Polyakov
261##
262# 1. Initial version 10/20/02 Suresh Chari
263#
264#
265# The following file works for the xlc,cc
266# and gcc compilers.
267#
268# NOTE: To get the file to link correctly with the gcc compiler
269# you have to change the names of the routines and remove
270# the first .(dot) character. This should automatically
271# be done in the build process.
272#
273# Hand optimized assembly code for the following routines
274#
275# bn_sqr_comba4
276# bn_sqr_comba8
277# bn_mul_comba4
278# bn_mul_comba8
279# bn_sub_words
280# bn_add_words
281# bn_div_words
282# bn_sqr_words
283# bn_mul_words
284# bn_mul_add_words
285#
286# NOTE: It is possible to optimize this code more for
287# specific PowerPC or Power architectures. On the Northstar
288# architecture the optimizations in this file do
289# NOT provide much improvement.
290#
291# If you have comments or suggestions to improve code send
292# me a note at schari\@us.ibm.com
293#
294#--------------------------------------------------------------------------
295#
296# Defines to be used in the assembly code.
297#
298.set r0,0 # we use it as storage for value of 0
299.set SP,1 # preserved
300.set RTOC,2 # preserved
301.set r3,3 # 1st argument/return value
302.set r4,4 # 2nd argument/volatile register
303.set r5,5 # 3rd argument/volatile register
304.set r6,6 # ...
305.set r7,7
306.set r8,8
307.set r9,9
308.set r10,10
309.set r11,11
310.set r12,12
311.set r13,13 # not used, nor any other "below" it...
312
313.set BO_IF_NOT,4
314.set BO_IF,12
315.set BO_dCTR_NZERO,16
316.set BO_dCTR_ZERO,18
317.set BO_ALWAYS,20
318.set CR0_LT,0;
319.set CR0_GT,1;
320.set CR0_EQ,2
321.set CR1_FX,4;
322.set CR1_FEX,5;
323.set CR1_VX,6
324.set LR,8
325
326# Declare function names to be global
327# NOTE: For gcc these names MUST be changed to remove
328# the first . i.e. for example change ".bn_sqr_comba4"
329# to "bn_sqr_comba4". This should be automatically done
330# in the build.
331
332 .globl .bn_sqr_comba4
333 .globl .bn_sqr_comba8
334 .globl .bn_mul_comba4
335 .globl .bn_mul_comba8
336 .globl .bn_sub_words
337 .globl .bn_add_words
338 .globl .bn_div_words
339 .globl .bn_sqr_words
340 .globl .bn_mul_words
341 .globl .bn_mul_add_words
342
343# .text section
344
345 .machine $ISA
346
347#
348# NOTE: The following label name should be changed to
349# "bn_sqr_comba4" i.e. remove the first dot
350# for the gcc compiler. This should be automatically
351# done in the build
352#
353
354.align 4
355.bn_sqr_comba4:
356#
357# Optimized version of bn_sqr_comba4.
358#
359# void bn_sqr_comba4(BN_ULONG *r, BN_ULONG *a)
360# r3 contains r
361# r4 contains a
362#
363# Freely use registers r5,r6,r7,r8,r9,r10,r11 as follows:
364#
365# r5,r6 are the two BN_ULONGs being multiplied.
366# r7,r8 are the results of the 32x32 giving 64 bit multiply.
367# r9,r10, r11 are the equivalents of c1,c2, c3.
368# Here's the assembly
369#
370#
371 xor r0,r0,r0 # set r0 = 0. Used in the addze
372 # instructions below
373
374 #sqr_add_c(a,0,c1,c2,c3)
375 $LD r5,`0*$BNSZ`(r4)
376 $UMULL r9,r5,r5
377 $UMULH r10,r5,r5 #in first iteration. No need
378 #to add since c1=c2=c3=0.
379 # Note c3(r11) is NOT set to 0
380 # but will be.
381
382 $ST r9,`0*$BNSZ`(r3) # r[0]=c1;
383 # sqr_add_c2(a,1,0,c2,c3,c1);
384 $LD r6,`1*$BNSZ`(r4)
385 $UMULL r7,r5,r6
386 $UMULH r8,r5,r6
387
388 addc r7,r7,r7 # compute (r7,r8)=2*(r7,r8)
389 adde r8,r8,r8
390 addze r9,r0 # catch carry if any.
391 # r9= r0(=0) and carry
392
393 addc r10,r7,r10 # now add to temp result.
394 addze r11,r8 # r8 added to r11 which is 0
395 addze r9,r9
396
397 $ST r10,`1*$BNSZ`(r3) #r[1]=c2;
398 #sqr_add_c(a,1,c3,c1,c2)
399 $UMULL r7,r6,r6
400 $UMULH r8,r6,r6
401 addc r11,r7,r11
402 adde r9,r8,r9
403 addze r10,r0
404 #sqr_add_c2(a,2,0,c3,c1,c2)
405 $LD r6,`2*$BNSZ`(r4)
406 $UMULL r7,r5,r6
407 $UMULH r8,r5,r6
408
409 addc r7,r7,r7
410 adde r8,r8,r8
411 addze r10,r10
412
413 addc r11,r7,r11
414 adde r9,r8,r9
415 addze r10,r10
416 $ST r11,`2*$BNSZ`(r3) #r[2]=c3
417 #sqr_add_c2(a,3,0,c1,c2,c3);
418 $LD r6,`3*$BNSZ`(r4)
419 $UMULL r7,r5,r6
420 $UMULH r8,r5,r6
421 addc r7,r7,r7
422 adde r8,r8,r8
423 addze r11,r0
424
425 addc r9,r7,r9
426 adde r10,r8,r10
427 addze r11,r11
428 #sqr_add_c2(a,2,1,c1,c2,c3);
429 $LD r5,`1*$BNSZ`(r4)
430 $LD r6,`2*$BNSZ`(r4)
431 $UMULL r7,r5,r6
432 $UMULH r8,r5,r6
433
434 addc r7,r7,r7
435 adde r8,r8,r8
436 addze r11,r11
437 addc r9,r7,r9
438 adde r10,r8,r10
439 addze r11,r11
440 $ST r9,`3*$BNSZ`(r3) #r[3]=c1
441 #sqr_add_c(a,2,c2,c3,c1);
442 $UMULL r7,r6,r6
443 $UMULH r8,r6,r6
444 addc r10,r7,r10
445 adde r11,r8,r11
446 addze r9,r0
447 #sqr_add_c2(a,3,1,c2,c3,c1);
448 $LD r6,`3*$BNSZ`(r4)
449 $UMULL r7,r5,r6
450 $UMULH r8,r5,r6
451 addc r7,r7,r7
452 adde r8,r8,r8
453 addze r9,r9
454
455 addc r10,r7,r10
456 adde r11,r8,r11
457 addze r9,r9
458 $ST r10,`4*$BNSZ`(r3) #r[4]=c2
459 #sqr_add_c2(a,3,2,c3,c1,c2);
460 $LD r5,`2*$BNSZ`(r4)
461 $UMULL r7,r5,r6
462 $UMULH r8,r5,r6
463 addc r7,r7,r7
464 adde r8,r8,r8
465 addze r10,r0
466
467 addc r11,r7,r11
468 adde r9,r8,r9
469 addze r10,r10
470 $ST r11,`5*$BNSZ`(r3) #r[5] = c3
471 #sqr_add_c(a,3,c1,c2,c3);
472 $UMULL r7,r6,r6
473 $UMULH r8,r6,r6
474 addc r9,r7,r9
475 adde r10,r8,r10
476
477 $ST r9,`6*$BNSZ`(r3) #r[6]=c1
478 $ST r10,`7*$BNSZ`(r3) #r[7]=c2
479 bclr BO_ALWAYS,CR0_LT
480 .long 0x00000000
481
482#
483# NOTE: The following label name should be changed to
484# "bn_sqr_comba8" i.e. remove the first dot
485# for the gcc compiler. This should be automatically
486# done in the build
487#
488
489.align 4
490.bn_sqr_comba8:
491#
492# This is an optimized version of the bn_sqr_comba8 routine.
493# Tightly uses the adde instruction
494#
495#
496# void bn_sqr_comba8(BN_ULONG *r, BN_ULONG *a)
497# r3 contains r
498# r4 contains a
499#
500# Freely use registers r5,r6,r7,r8,r9,r10,r11 as follows:
501#
502# r5,r6 are the two BN_ULONGs being multiplied.
503# r7,r8 are the results of the 32x32 giving 64 bit multiply.
504# r9,r10, r11 are the equivalents of c1,c2, c3.
505#
506# Possible optimization of loading all 8 longs of a into registers
507# doesnt provide any speedup
508#
509
510 xor r0,r0,r0 #set r0 = 0.Used in addze
511 #instructions below.
512
513 #sqr_add_c(a,0,c1,c2,c3);
514 $LD r5,`0*$BNSZ`(r4)
515 $UMULL r9,r5,r5 #1st iteration: no carries.
516 $UMULH r10,r5,r5
517 $ST r9,`0*$BNSZ`(r3) # r[0]=c1;
518 #sqr_add_c2(a,1,0,c2,c3,c1);
519 $LD r6,`1*$BNSZ`(r4)
520 $UMULL r7,r5,r6
521 $UMULH r8,r5,r6
522
523 addc r10,r7,r10 #add the two register number
524 adde r11,r8,r0 # (r8,r7) to the three register
525 addze r9,r0 # number (r9,r11,r10).NOTE:r0=0
526
527 addc r10,r7,r10 #add the two register number
528 adde r11,r8,r11 # (r8,r7) to the three register
529 addze r9,r9 # number (r9,r11,r10).
530
531 $ST r10,`1*$BNSZ`(r3) # r[1]=c2
532
533 #sqr_add_c(a,1,c3,c1,c2);
534 $UMULL r7,r6,r6
535 $UMULH r8,r6,r6
536 addc r11,r7,r11
537 adde r9,r8,r9
538 addze r10,r0
539 #sqr_add_c2(a,2,0,c3,c1,c2);
540 $LD r6,`2*$BNSZ`(r4)
541 $UMULL r7,r5,r6
542 $UMULH r8,r5,r6
543
544 addc r11,r7,r11
545 adde r9,r8,r9
546 addze r10,r10
547
548 addc r11,r7,r11
549 adde r9,r8,r9
550 addze r10,r10
551
552 $ST r11,`2*$BNSZ`(r3) #r[2]=c3
553 #sqr_add_c2(a,3,0,c1,c2,c3);
554 $LD r6,`3*$BNSZ`(r4) #r6 = a[3]. r5 is already a[0].
555 $UMULL r7,r5,r6
556 $UMULH r8,r5,r6
557
558 addc r9,r7,r9
559 adde r10,r8,r10
560 addze r11,r0
561
562 addc r9,r7,r9
563 adde r10,r8,r10
564 addze r11,r11
565 #sqr_add_c2(a,2,1,c1,c2,c3);
566 $LD r5,`1*$BNSZ`(r4)
567 $LD r6,`2*$BNSZ`(r4)
568 $UMULL r7,r5,r6
569 $UMULH r8,r5,r6
570
571 addc r9,r7,r9
572 adde r10,r8,r10
573 addze r11,r11
574
575 addc r9,r7,r9
576 adde r10,r8,r10
577 addze r11,r11
578
579 $ST r9,`3*$BNSZ`(r3) #r[3]=c1;
580 #sqr_add_c(a,2,c2,c3,c1);
581 $UMULL r7,r6,r6
582 $UMULH r8,r6,r6
583
584 addc r10,r7,r10
585 adde r11,r8,r11
586 addze r9,r0
587 #sqr_add_c2(a,3,1,c2,c3,c1);
588 $LD r6,`3*$BNSZ`(r4)
589 $UMULL r7,r5,r6
590 $UMULH r8,r5,r6
591
592 addc r10,r7,r10
593 adde r11,r8,r11
594 addze r9,r9
595
596 addc r10,r7,r10
597 adde r11,r8,r11
598 addze r9,r9
599 #sqr_add_c2(a,4,0,c2,c3,c1);
600 $LD r5,`0*$BNSZ`(r4)
601 $LD r6,`4*$BNSZ`(r4)
602 $UMULL r7,r5,r6
603 $UMULH r8,r5,r6
604
605 addc r10,r7,r10
606 adde r11,r8,r11
607 addze r9,r9
608
609 addc r10,r7,r10
610 adde r11,r8,r11
611 addze r9,r9
612 $ST r10,`4*$BNSZ`(r3) #r[4]=c2;
613 #sqr_add_c2(a,5,0,c3,c1,c2);
614 $LD r6,`5*$BNSZ`(r4)
615 $UMULL r7,r5,r6
616 $UMULH r8,r5,r6
617
618 addc r11,r7,r11
619 adde r9,r8,r9
620 addze r10,r0
621
622 addc r11,r7,r11
623 adde r9,r8,r9
624 addze r10,r10
625 #sqr_add_c2(a,4,1,c3,c1,c2);
626 $LD r5,`1*$BNSZ`(r4)
627 $LD r6,`4*$BNSZ`(r4)
628 $UMULL r7,r5,r6
629 $UMULH r8,r5,r6
630
631 addc r11,r7,r11
632 adde r9,r8,r9
633 addze r10,r10
634
635 addc r11,r7,r11
636 adde r9,r8,r9
637 addze r10,r10
638 #sqr_add_c2(a,3,2,c3,c1,c2);
639 $LD r5,`2*$BNSZ`(r4)
640 $LD r6,`3*$BNSZ`(r4)
641 $UMULL r7,r5,r6
642 $UMULH r8,r5,r6
643
644 addc r11,r7,r11
645 adde r9,r8,r9
646 addze r10,r10
647
648 addc r11,r7,r11
649 adde r9,r8,r9
650 addze r10,r10
651 $ST r11,`5*$BNSZ`(r3) #r[5]=c3;
652 #sqr_add_c(a,3,c1,c2,c3);
653 $UMULL r7,r6,r6
654 $UMULH r8,r6,r6
655 addc r9,r7,r9
656 adde r10,r8,r10
657 addze r11,r0
658 #sqr_add_c2(a,4,2,c1,c2,c3);
659 $LD r6,`4*$BNSZ`(r4)
660 $UMULL r7,r5,r6
661 $UMULH r8,r5,r6
662
663 addc r9,r7,r9
664 adde r10,r8,r10
665 addze r11,r11
666
667 addc r9,r7,r9
668 adde r10,r8,r10
669 addze r11,r11
670 #sqr_add_c2(a,5,1,c1,c2,c3);
671 $LD r5,`1*$BNSZ`(r4)
672 $LD r6,`5*$BNSZ`(r4)
673 $UMULL r7,r5,r6
674 $UMULH r8,r5,r6
675
676 addc r9,r7,r9
677 adde r10,r8,r10
678 addze r11,r11
679
680 addc r9,r7,r9
681 adde r10,r8,r10
682 addze r11,r11
683 #sqr_add_c2(a,6,0,c1,c2,c3);
684 $LD r5,`0*$BNSZ`(r4)
685 $LD r6,`6*$BNSZ`(r4)
686 $UMULL r7,r5,r6
687 $UMULH r8,r5,r6
688 addc r9,r7,r9
689 adde r10,r8,r10
690 addze r11,r11
691 addc r9,r7,r9
692 adde r10,r8,r10
693 addze r11,r11
694 $ST r9,`6*$BNSZ`(r3) #r[6]=c1;
695 #sqr_add_c2(a,7,0,c2,c3,c1);
696 $LD r6,`7*$BNSZ`(r4)
697 $UMULL r7,r5,r6
698 $UMULH r8,r5,r6
699
700 addc r10,r7,r10
701 adde r11,r8,r11
702 addze r9,r0
703 addc r10,r7,r10
704 adde r11,r8,r11
705 addze r9,r9
706 #sqr_add_c2(a,6,1,c2,c3,c1);
707 $LD r5,`1*$BNSZ`(r4)
708 $LD r6,`6*$BNSZ`(r4)
709 $UMULL r7,r5,r6
710 $UMULH r8,r5,r6
711
712 addc r10,r7,r10
713 adde r11,r8,r11
714 addze r9,r9
715 addc r10,r7,r10
716 adde r11,r8,r11
717 addze r9,r9
718 #sqr_add_c2(a,5,2,c2,c3,c1);
719 $LD r5,`2*$BNSZ`(r4)
720 $LD r6,`5*$BNSZ`(r4)
721 $UMULL r7,r5,r6
722 $UMULH r8,r5,r6
723 addc r10,r7,r10
724 adde r11,r8,r11
725 addze r9,r9
726 addc r10,r7,r10
727 adde r11,r8,r11
728 addze r9,r9
729 #sqr_add_c2(a,4,3,c2,c3,c1);
730 $LD r5,`3*$BNSZ`(r4)
731 $LD r6,`4*$BNSZ`(r4)
732 $UMULL r7,r5,r6
733 $UMULH r8,r5,r6
734
735 addc r10,r7,r10
736 adde r11,r8,r11
737 addze r9,r9
738 addc r10,r7,r10
739 adde r11,r8,r11
740 addze r9,r9
741 $ST r10,`7*$BNSZ`(r3) #r[7]=c2;
742 #sqr_add_c(a,4,c3,c1,c2);
743 $UMULL r7,r6,r6
744 $UMULH r8,r6,r6
745 addc r11,r7,r11
746 adde r9,r8,r9
747 addze r10,r0
748 #sqr_add_c2(a,5,3,c3,c1,c2);
749 $LD r6,`5*$BNSZ`(r4)
750 $UMULL r7,r5,r6
751 $UMULH r8,r5,r6
752 addc r11,r7,r11
753 adde r9,r8,r9
754 addze r10,r10
755 addc r11,r7,r11
756 adde r9,r8,r9
757 addze r10,r10
758 #sqr_add_c2(a,6,2,c3,c1,c2);
759 $LD r5,`2*$BNSZ`(r4)
760 $LD r6,`6*$BNSZ`(r4)
761 $UMULL r7,r5,r6
762 $UMULH r8,r5,r6
763 addc r11,r7,r11
764 adde r9,r8,r9
765 addze r10,r10
766
767 addc r11,r7,r11
768 adde r9,r8,r9
769 addze r10,r10
770 #sqr_add_c2(a,7,1,c3,c1,c2);
771 $LD r5,`1*$BNSZ`(r4)
772 $LD r6,`7*$BNSZ`(r4)
773 $UMULL r7,r5,r6
774 $UMULH r8,r5,r6
775 addc r11,r7,r11
776 adde r9,r8,r9
777 addze r10,r10
778 addc r11,r7,r11
779 adde r9,r8,r9
780 addze r10,r10
781 $ST r11,`8*$BNSZ`(r3) #r[8]=c3;
782 #sqr_add_c2(a,7,2,c1,c2,c3);
783 $LD r5,`2*$BNSZ`(r4)
784 $UMULL r7,r5,r6
785 $UMULH r8,r5,r6
786
787 addc r9,r7,r9
788 adde r10,r8,r10
789 addze r11,r0
790 addc r9,r7,r9
791 adde r10,r8,r10
792 addze r11,r11
793 #sqr_add_c2(a,6,3,c1,c2,c3);
794 $LD r5,`3*$BNSZ`(r4)
795 $LD r6,`6*$BNSZ`(r4)
796 $UMULL r7,r5,r6
797 $UMULH r8,r5,r6
798 addc r9,r7,r9
799 adde r10,r8,r10
800 addze r11,r11
801 addc r9,r7,r9
802 adde r10,r8,r10
803 addze r11,r11
804 #sqr_add_c2(a,5,4,c1,c2,c3);
805 $LD r5,`4*$BNSZ`(r4)
806 $LD r6,`5*$BNSZ`(r4)
807 $UMULL r7,r5,r6
808 $UMULH r8,r5,r6
809 addc r9,r7,r9
810 adde r10,r8,r10
811 addze r11,r11
812 addc r9,r7,r9
813 adde r10,r8,r10
814 addze r11,r11
815 $ST r9,`9*$BNSZ`(r3) #r[9]=c1;
816 #sqr_add_c(a,5,c2,c3,c1);
817 $UMULL r7,r6,r6
818 $UMULH r8,r6,r6
819 addc r10,r7,r10
820 adde r11,r8,r11
821 addze r9,r0
822 #sqr_add_c2(a,6,4,c2,c3,c1);
823 $LD r6,`6*$BNSZ`(r4)
824 $UMULL r7,r5,r6
825 $UMULH r8,r5,r6
826 addc r10,r7,r10
827 adde r11,r8,r11
828 addze r9,r9
829 addc r10,r7,r10
830 adde r11,r8,r11
831 addze r9,r9
832 #sqr_add_c2(a,7,3,c2,c3,c1);
833 $LD r5,`3*$BNSZ`(r4)
834 $LD r6,`7*$BNSZ`(r4)
835 $UMULL r7,r5,r6
836 $UMULH r8,r5,r6
837 addc r10,r7,r10
838 adde r11,r8,r11
839 addze r9,r9
840 addc r10,r7,r10
841 adde r11,r8,r11
842 addze r9,r9
843 $ST r10,`10*$BNSZ`(r3) #r[10]=c2;
844 #sqr_add_c2(a,7,4,c3,c1,c2);
845 $LD r5,`4*$BNSZ`(r4)
846 $UMULL r7,r5,r6
847 $UMULH r8,r5,r6
848 addc r11,r7,r11
849 adde r9,r8,r9
850 addze r10,r0
851 addc r11,r7,r11
852 adde r9,r8,r9
853 addze r10,r10
854 #sqr_add_c2(a,6,5,c3,c1,c2);
855 $LD r5,`5*$BNSZ`(r4)
856 $LD r6,`6*$BNSZ`(r4)
857 $UMULL r7,r5,r6
858 $UMULH r8,r5,r6
859 addc r11,r7,r11
860 adde r9,r8,r9
861 addze r10,r10
862 addc r11,r7,r11
863 adde r9,r8,r9
864 addze r10,r10
865 $ST r11,`11*$BNSZ`(r3) #r[11]=c3;
866 #sqr_add_c(a,6,c1,c2,c3);
867 $UMULL r7,r6,r6
868 $UMULH r8,r6,r6
869 addc r9,r7,r9
870 adde r10,r8,r10
871 addze r11,r0
872 #sqr_add_c2(a,7,5,c1,c2,c3)
873 $LD r6,`7*$BNSZ`(r4)
874 $UMULL r7,r5,r6
875 $UMULH r8,r5,r6
876 addc r9,r7,r9
877 adde r10,r8,r10
878 addze r11,r11
879 addc r9,r7,r9
880 adde r10,r8,r10
881 addze r11,r11
882 $ST r9,`12*$BNSZ`(r3) #r[12]=c1;
883
884 #sqr_add_c2(a,7,6,c2,c3,c1)
885 $LD r5,`6*$BNSZ`(r4)
886 $UMULL r7,r5,r6
887 $UMULH r8,r5,r6
888 addc r10,r7,r10
889 adde r11,r8,r11
890 addze r9,r0
891 addc r10,r7,r10
892 adde r11,r8,r11
893 addze r9,r9
894 $ST r10,`13*$BNSZ`(r3) #r[13]=c2;
895 #sqr_add_c(a,7,c3,c1,c2);
896 $UMULL r7,r6,r6
897 $UMULH r8,r6,r6
898 addc r11,r7,r11
899 adde r9,r8,r9
900 $ST r11,`14*$BNSZ`(r3) #r[14]=c3;
901 $ST r9, `15*$BNSZ`(r3) #r[15]=c1;
902
903
904 bclr BO_ALWAYS,CR0_LT
905
906 .long 0x00000000
907
908#
909# NOTE: The following label name should be changed to
910# "bn_mul_comba4" i.e. remove the first dot
911# for the gcc compiler. This should be automatically
912# done in the build
913#
914
915.align 4
916.bn_mul_comba4:
917#
918# This is an optimized version of the bn_mul_comba4 routine.
919#
920# void bn_mul_comba4(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b)
921# r3 contains r
922# r4 contains a
923# r5 contains b
924# r6, r7 are the 2 BN_ULONGs being multiplied.
925# r8, r9 are the results of the 32x32 giving 64 multiply.
926# r10, r11, r12 are the equivalents of c1, c2, and c3.
927#
928 xor r0,r0,r0 #r0=0. Used in addze below.
929 #mul_add_c(a[0],b[0],c1,c2,c3);
930 $LD r6,`0*$BNSZ`(r4)
931 $LD r7,`0*$BNSZ`(r5)
932 $UMULL r10,r6,r7
933 $UMULH r11,r6,r7
934 $ST r10,`0*$BNSZ`(r3) #r[0]=c1
935 #mul_add_c(a[0],b[1],c2,c3,c1);
936 $LD r7,`1*$BNSZ`(r5)
937 $UMULL r8,r6,r7
938 $UMULH r9,r6,r7
939 addc r11,r8,r11
940 adde r12,r9,r0
941 addze r10,r0
942 #mul_add_c(a[1],b[0],c2,c3,c1);
943 $LD r6, `1*$BNSZ`(r4)
944 $LD r7, `0*$BNSZ`(r5)
945 $UMULL r8,r6,r7
946 $UMULH r9,r6,r7
947 addc r11,r8,r11
948 adde r12,r9,r12
949 addze r10,r10
950 $ST r11,`1*$BNSZ`(r3) #r[1]=c2
951 #mul_add_c(a[2],b[0],c3,c1,c2);
952 $LD r6,`2*$BNSZ`(r4)
953 $UMULL r8,r6,r7
954 $UMULH r9,r6,r7
955 addc r12,r8,r12
956 adde r10,r9,r10
957 addze r11,r0
958 #mul_add_c(a[1],b[1],c3,c1,c2);
959 $LD r6,`1*$BNSZ`(r4)
960 $LD r7,`1*$BNSZ`(r5)
961 $UMULL r8,r6,r7
962 $UMULH r9,r6,r7
963 addc r12,r8,r12
964 adde r10,r9,r10
965 addze r11,r11
966 #mul_add_c(a[0],b[2],c3,c1,c2);
967 $LD r6,`0*$BNSZ`(r4)
968 $LD r7,`2*$BNSZ`(r5)
969 $UMULL r8,r6,r7
970 $UMULH r9,r6,r7
971 addc r12,r8,r12
972 adde r10,r9,r10
973 addze r11,r11
974 $ST r12,`2*$BNSZ`(r3) #r[2]=c3
975 #mul_add_c(a[0],b[3],c1,c2,c3);
976 $LD r7,`3*$BNSZ`(r5)
977 $UMULL r8,r6,r7
978 $UMULH r9,r6,r7
979 addc r10,r8,r10
980 adde r11,r9,r11
981 addze r12,r0
982 #mul_add_c(a[1],b[2],c1,c2,c3);
983 $LD r6,`1*$BNSZ`(r4)
984 $LD r7,`2*$BNSZ`(r5)
985 $UMULL r8,r6,r7
986 $UMULH r9,r6,r7
987 addc r10,r8,r10
988 adde r11,r9,r11
989 addze r12,r12
990 #mul_add_c(a[2],b[1],c1,c2,c3);
991 $LD r6,`2*$BNSZ`(r4)
992 $LD r7,`1*$BNSZ`(r5)
993 $UMULL r8,r6,r7
994 $UMULH r9,r6,r7
995 addc r10,r8,r10
996 adde r11,r9,r11
997 addze r12,r12
998 #mul_add_c(a[3],b[0],c1,c2,c3);
999 $LD r6,`3*$BNSZ`(r4)
1000 $LD r7,`0*$BNSZ`(r5)
1001 $UMULL r8,r6,r7
1002 $UMULH r9,r6,r7
1003 addc r10,r8,r10
1004 adde r11,r9,r11
1005 addze r12,r12
1006 $ST r10,`3*$BNSZ`(r3) #r[3]=c1
1007 #mul_add_c(a[3],b[1],c2,c3,c1);
1008 $LD r7,`1*$BNSZ`(r5)
1009 $UMULL r8,r6,r7
1010 $UMULH r9,r6,r7
1011 addc r11,r8,r11
1012 adde r12,r9,r12
1013 addze r10,r0
1014 #mul_add_c(a[2],b[2],c2,c3,c1);
1015 $LD r6,`2*$BNSZ`(r4)
1016 $LD r7,`2*$BNSZ`(r5)
1017 $UMULL r8,r6,r7
1018 $UMULH r9,r6,r7
1019 addc r11,r8,r11
1020 adde r12,r9,r12
1021 addze r10,r10
1022 #mul_add_c(a[1],b[3],c2,c3,c1);
1023 $LD r6,`1*$BNSZ`(r4)
1024 $LD r7,`3*$BNSZ`(r5)
1025 $UMULL r8,r6,r7
1026 $UMULH r9,r6,r7
1027 addc r11,r8,r11
1028 adde r12,r9,r12
1029 addze r10,r10
1030 $ST r11,`4*$BNSZ`(r3) #r[4]=c2
1031 #mul_add_c(a[2],b[3],c3,c1,c2);
1032 $LD r6,`2*$BNSZ`(r4)
1033 $UMULL r8,r6,r7
1034 $UMULH r9,r6,r7
1035 addc r12,r8,r12
1036 adde r10,r9,r10
1037 addze r11,r0
1038 #mul_add_c(a[3],b[2],c3,c1,c2);
1039 $LD r6,`3*$BNSZ`(r4)
1040 $LD r7,`2*$BNSZ`(r4)
1041 $UMULL r8,r6,r7
1042 $UMULH r9,r6,r7
1043 addc r12,r8,r12
1044 adde r10,r9,r10
1045 addze r11,r11
1046 $ST r12,`5*$BNSZ`(r3) #r[5]=c3
1047 #mul_add_c(a[3],b[3],c1,c2,c3);
1048 $LD r7,`3*$BNSZ`(r5)
1049 $UMULL r8,r6,r7
1050 $UMULH r9,r6,r7
1051 addc r10,r8,r10
1052 adde r11,r9,r11
1053
1054 $ST r10,`6*$BNSZ`(r3) #r[6]=c1
1055 $ST r11,`7*$BNSZ`(r3) #r[7]=c2
1056 bclr BO_ALWAYS,CR0_LT
1057 .long 0x00000000
1058
1059#
1060# NOTE: The following label name should be changed to
1061# "bn_mul_comba8" i.e. remove the first dot
1062# for the gcc compiler. This should be automatically
1063# done in the build
1064#
1065
1066.align 4
1067.bn_mul_comba8:
1068#
1069# Optimized version of the bn_mul_comba8 routine.
1070#
1071# void bn_mul_comba8(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b)
1072# r3 contains r
1073# r4 contains a
1074# r5 contains b
1075# r6, r7 are the 2 BN_ULONGs being multiplied.
1076# r8, r9 are the results of the 32x32 giving 64 multiply.
1077# r10, r11, r12 are the equivalents of c1, c2, and c3.
1078#
1079 xor r0,r0,r0 #r0=0. Used in addze below.
1080
1081 #mul_add_c(a[0],b[0],c1,c2,c3);
1082 $LD r6,`0*$BNSZ`(r4) #a[0]
1083 $LD r7,`0*$BNSZ`(r5) #b[0]
1084 $UMULL r10,r6,r7
1085 $UMULH r11,r6,r7
1086 $ST r10,`0*$BNSZ`(r3) #r[0]=c1;
1087 #mul_add_c(a[0],b[1],c2,c3,c1);
1088 $LD r7,`1*$BNSZ`(r5)
1089 $UMULL r8,r6,r7
1090 $UMULH r9,r6,r7
1091 addc r11,r11,r8
1092 addze r12,r9 # since we didnt set r12 to zero before.
1093 addze r10,r0
1094 #mul_add_c(a[1],b[0],c2,c3,c1);
1095 $LD r6,`1*$BNSZ`(r4)
1096 $LD r7,`0*$BNSZ`(r5)
1097 $UMULL r8,r6,r7
1098 $UMULH r9,r6,r7
1099 addc r11,r11,r8
1100 adde r12,r12,r9
1101 addze r10,r10
1102 $ST r11,`1*$BNSZ`(r3) #r[1]=c2;
1103 #mul_add_c(a[2],b[0],c3,c1,c2);
1104 $LD r6,`2*$BNSZ`(r4)
1105 $UMULL r8,r6,r7
1106 $UMULH r9,r6,r7
1107 addc r12,r12,r8
1108 adde r10,r10,r9
1109 addze r11,r0
1110 #mul_add_c(a[1],b[1],c3,c1,c2);
1111 $LD r6,`1*$BNSZ`(r4)
1112 $LD r7,`1*$BNSZ`(r5)
1113 $UMULL r8,r6,r7
1114 $UMULH r9,r6,r7
1115 addc r12,r12,r8
1116 adde r10,r10,r9
1117 addze r11,r11
1118 #mul_add_c(a[0],b[2],c3,c1,c2);
1119 $LD r6,`0*$BNSZ`(r4)
1120 $LD r7,`2*$BNSZ`(r5)
1121 $UMULL r8,r6,r7
1122 $UMULH r9,r6,r7
1123 addc r12,r12,r8
1124 adde r10,r10,r9
1125 addze r11,r11
1126 $ST r12,`2*$BNSZ`(r3) #r[2]=c3;
1127 #mul_add_c(a[0],b[3],c1,c2,c3);
1128 $LD r7,`3*$BNSZ`(r5)
1129 $UMULL r8,r6,r7
1130 $UMULH r9,r6,r7
1131 addc r10,r10,r8
1132 adde r11,r11,r9
1133 addze r12,r0
1134 #mul_add_c(a[1],b[2],c1,c2,c3);
1135 $LD r6,`1*$BNSZ`(r4)
1136 $LD r7,`2*$BNSZ`(r5)
1137 $UMULL r8,r6,r7
1138 $UMULH r9,r6,r7
1139 addc r10,r10,r8
1140 adde r11,r11,r9
1141 addze r12,r12
1142
1143 #mul_add_c(a[2],b[1],c1,c2,c3);
1144 $LD r6,`2*$BNSZ`(r4)
1145 $LD r7,`1*$BNSZ`(r5)
1146 $UMULL r8,r6,r7
1147 $UMULH r9,r6,r7
1148 addc r10,r10,r8
1149 adde r11,r11,r9
1150 addze r12,r12
1151 #mul_add_c(a[3],b[0],c1,c2,c3);
1152 $LD r6,`3*$BNSZ`(r4)
1153 $LD r7,`0*$BNSZ`(r5)
1154 $UMULL r8,r6,r7
1155 $UMULH r9,r6,r7
1156 addc r10,r10,r8
1157 adde r11,r11,r9
1158 addze r12,r12
1159 $ST r10,`3*$BNSZ`(r3) #r[3]=c1;
1160 #mul_add_c(a[4],b[0],c2,c3,c1);
1161 $LD r6,`4*$BNSZ`(r4)
1162 $UMULL r8,r6,r7
1163 $UMULH r9,r6,r7
1164 addc r11,r11,r8
1165 adde r12,r12,r9
1166 addze r10,r0
1167 #mul_add_c(a[3],b[1],c2,c3,c1);
1168 $LD r6,`3*$BNSZ`(r4)
1169 $LD r7,`1*$BNSZ`(r5)
1170 $UMULL r8,r6,r7
1171 $UMULH r9,r6,r7
1172 addc r11,r11,r8
1173 adde r12,r12,r9
1174 addze r10,r10
1175 #mul_add_c(a[2],b[2],c2,c3,c1);
1176 $LD r6,`2*$BNSZ`(r4)
1177 $LD r7,`2*$BNSZ`(r5)
1178 $UMULL r8,r6,r7
1179 $UMULH r9,r6,r7
1180 addc r11,r11,r8
1181 adde r12,r12,r9
1182 addze r10,r10
1183 #mul_add_c(a[1],b[3],c2,c3,c1);
1184 $LD r6,`1*$BNSZ`(r4)
1185 $LD r7,`3*$BNSZ`(r5)
1186 $UMULL r8,r6,r7
1187 $UMULH r9,r6,r7
1188 addc r11,r11,r8
1189 adde r12,r12,r9
1190 addze r10,r10
1191 #mul_add_c(a[0],b[4],c2,c3,c1);
1192 $LD r6,`0*$BNSZ`(r4)
1193 $LD r7,`4*$BNSZ`(r5)
1194 $UMULL r8,r6,r7
1195 $UMULH r9,r6,r7
1196 addc r11,r11,r8
1197 adde r12,r12,r9
1198 addze r10,r10
1199 $ST r11,`4*$BNSZ`(r3) #r[4]=c2;
1200 #mul_add_c(a[0],b[5],c3,c1,c2);
1201 $LD r7,`5*$BNSZ`(r5)
1202 $UMULL r8,r6,r7
1203 $UMULH r9,r6,r7
1204 addc r12,r12,r8
1205 adde r10,r10,r9
1206 addze r11,r0
1207 #mul_add_c(a[1],b[4],c3,c1,c2);
1208 $LD r6,`1*$BNSZ`(r4)
1209 $LD r7,`4*$BNSZ`(r5)
1210 $UMULL r8,r6,r7
1211 $UMULH r9,r6,r7
1212 addc r12,r12,r8
1213 adde r10,r10,r9
1214 addze r11,r11
1215 #mul_add_c(a[2],b[3],c3,c1,c2);
1216 $LD r6,`2*$BNSZ`(r4)
1217 $LD r7,`3*$BNSZ`(r5)
1218 $UMULL r8,r6,r7
1219 $UMULH r9,r6,r7
1220 addc r12,r12,r8
1221 adde r10,r10,r9
1222 addze r11,r11
1223 #mul_add_c(a[3],b[2],c3,c1,c2);
1224 $LD r6,`3*$BNSZ`(r4)
1225 $LD r7,`2*$BNSZ`(r5)
1226 $UMULL r8,r6,r7
1227 $UMULH r9,r6,r7
1228 addc r12,r12,r8
1229 adde r10,r10,r9
1230 addze r11,r11
1231 #mul_add_c(a[4],b[1],c3,c1,c2);
1232 $LD r6,`4*$BNSZ`(r4)
1233 $LD r7,`1*$BNSZ`(r5)
1234 $UMULL r8,r6,r7
1235 $UMULH r9,r6,r7
1236 addc r12,r12,r8
1237 adde r10,r10,r9
1238 addze r11,r11
1239 #mul_add_c(a[5],b[0],c3,c1,c2);
1240 $LD r6,`5*$BNSZ`(r4)
1241 $LD r7,`0*$BNSZ`(r5)
1242 $UMULL r8,r6,r7
1243 $UMULH r9,r6,r7
1244 addc r12,r12,r8
1245 adde r10,r10,r9
1246 addze r11,r11
1247 $ST r12,`5*$BNSZ`(r3) #r[5]=c3;
1248 #mul_add_c(a[6],b[0],c1,c2,c3);
1249 $LD r6,`6*$BNSZ`(r4)
1250 $UMULL r8,r6,r7
1251 $UMULH r9,r6,r7
1252 addc r10,r10,r8
1253 adde r11,r11,r9
1254 addze r12,r0
1255 #mul_add_c(a[5],b[1],c1,c2,c3);
1256 $LD r6,`5*$BNSZ`(r4)
1257 $LD r7,`1*$BNSZ`(r5)
1258 $UMULL r8,r6,r7
1259 $UMULH r9,r6,r7
1260 addc r10,r10,r8
1261 adde r11,r11,r9
1262 addze r12,r12
1263 #mul_add_c(a[4],b[2],c1,c2,c3);
1264 $LD r6,`4*$BNSZ`(r4)
1265 $LD r7,`2*$BNSZ`(r5)
1266 $UMULL r8,r6,r7
1267 $UMULH r9,r6,r7
1268 addc r10,r10,r8
1269 adde r11,r11,r9
1270 addze r12,r12
1271 #mul_add_c(a[3],b[3],c1,c2,c3);
1272 $LD r6,`3*$BNSZ`(r4)
1273 $LD r7,`3*$BNSZ`(r5)
1274 $UMULL r8,r6,r7
1275 $UMULH r9,r6,r7
1276 addc r10,r10,r8
1277 adde r11,r11,r9
1278 addze r12,r12
1279 #mul_add_c(a[2],b[4],c1,c2,c3);
1280 $LD r6,`2*$BNSZ`(r4)
1281 $LD r7,`4*$BNSZ`(r5)
1282 $UMULL r8,r6,r7
1283 $UMULH r9,r6,r7
1284 addc r10,r10,r8
1285 adde r11,r11,r9
1286 addze r12,r12
1287 #mul_add_c(a[1],b[5],c1,c2,c3);
1288 $LD r6,`1*$BNSZ`(r4)
1289 $LD r7,`5*$BNSZ`(r5)
1290 $UMULL r8,r6,r7
1291 $UMULH r9,r6,r7
1292 addc r10,r10,r8
1293 adde r11,r11,r9
1294 addze r12,r12
1295 #mul_add_c(a[0],b[6],c1,c2,c3);
1296 $LD r6,`0*$BNSZ`(r4)
1297 $LD r7,`6*$BNSZ`(r5)
1298 $UMULL r8,r6,r7
1299 $UMULH r9,r6,r7
1300 addc r10,r10,r8
1301 adde r11,r11,r9
1302 addze r12,r12
1303 $ST r10,`6*$BNSZ`(r3) #r[6]=c1;
1304 #mul_add_c(a[0],b[7],c2,c3,c1);
1305 $LD r7,`7*$BNSZ`(r5)
1306 $UMULL r8,r6,r7
1307 $UMULH r9,r6,r7
1308 addc r11,r11,r8
1309 adde r12,r12,r9
1310 addze r10,r0
1311 #mul_add_c(a[1],b[6],c2,c3,c1);
1312 $LD r6,`1*$BNSZ`(r4)
1313 $LD r7,`6*$BNSZ`(r5)
1314 $UMULL r8,r6,r7
1315 $UMULH r9,r6,r7
1316 addc r11,r11,r8
1317 adde r12,r12,r9
1318 addze r10,r10
1319 #mul_add_c(a[2],b[5],c2,c3,c1);
1320 $LD r6,`2*$BNSZ`(r4)
1321 $LD r7,`5*$BNSZ`(r5)
1322 $UMULL r8,r6,r7
1323 $UMULH r9,r6,r7
1324 addc r11,r11,r8
1325 adde r12,r12,r9
1326 addze r10,r10
1327 #mul_add_c(a[3],b[4],c2,c3,c1);
1328 $LD r6,`3*$BNSZ`(r4)
1329 $LD r7,`4*$BNSZ`(r5)
1330 $UMULL r8,r6,r7
1331 $UMULH r9,r6,r7
1332 addc r11,r11,r8
1333 adde r12,r12,r9
1334 addze r10,r10
1335 #mul_add_c(a[4],b[3],c2,c3,c1);
1336 $LD r6,`4*$BNSZ`(r4)
1337 $LD r7,`3*$BNSZ`(r5)
1338 $UMULL r8,r6,r7
1339 $UMULH r9,r6,r7
1340 addc r11,r11,r8
1341 adde r12,r12,r9
1342 addze r10,r10
1343 #mul_add_c(a[5],b[2],c2,c3,c1);
1344 $LD r6,`5*$BNSZ`(r4)
1345 $LD r7,`2*$BNSZ`(r5)
1346 $UMULL r8,r6,r7
1347 $UMULH r9,r6,r7
1348 addc r11,r11,r8
1349 adde r12,r12,r9
1350 addze r10,r10
1351 #mul_add_c(a[6],b[1],c2,c3,c1);
1352 $LD r6,`6*$BNSZ`(r4)
1353 $LD r7,`1*$BNSZ`(r5)
1354 $UMULL r8,r6,r7
1355 $UMULH r9,r6,r7
1356 addc r11,r11,r8
1357 adde r12,r12,r9
1358 addze r10,r10
1359 #mul_add_c(a[7],b[0],c2,c3,c1);
1360 $LD r6,`7*$BNSZ`(r4)
1361 $LD r7,`0*$BNSZ`(r5)
1362 $UMULL r8,r6,r7
1363 $UMULH r9,r6,r7
1364 addc r11,r11,r8
1365 adde r12,r12,r9
1366 addze r10,r10
1367 $ST r11,`7*$BNSZ`(r3) #r[7]=c2;
1368 #mul_add_c(a[7],b[1],c3,c1,c2);
1369 $LD r7,`1*$BNSZ`(r5)
1370 $UMULL r8,r6,r7
1371 $UMULH r9,r6,r7
1372 addc r12,r12,r8
1373 adde r10,r10,r9
1374 addze r11,r0
1375 #mul_add_c(a[6],b[2],c3,c1,c2);
1376 $LD r6,`6*$BNSZ`(r4)
1377 $LD r7,`2*$BNSZ`(r5)
1378 $UMULL r8,r6,r7
1379 $UMULH r9,r6,r7
1380 addc r12,r12,r8
1381 adde r10,r10,r9
1382 addze r11,r11
1383 #mul_add_c(a[5],b[3],c3,c1,c2);
1384 $LD r6,`5*$BNSZ`(r4)
1385 $LD r7,`3*$BNSZ`(r5)
1386 $UMULL r8,r6,r7
1387 $UMULH r9,r6,r7
1388 addc r12,r12,r8
1389 adde r10,r10,r9
1390 addze r11,r11
1391 #mul_add_c(a[4],b[4],c3,c1,c2);
1392 $LD r6,`4*$BNSZ`(r4)
1393 $LD r7,`4*$BNSZ`(r5)
1394 $UMULL r8,r6,r7
1395 $UMULH r9,r6,r7
1396 addc r12,r12,r8
1397 adde r10,r10,r9
1398 addze r11,r11
1399 #mul_add_c(a[3],b[5],c3,c1,c2);
1400 $LD r6,`3*$BNSZ`(r4)
1401 $LD r7,`5*$BNSZ`(r5)
1402 $UMULL r8,r6,r7
1403 $UMULH r9,r6,r7
1404 addc r12,r12,r8
1405 adde r10,r10,r9
1406 addze r11,r11
1407 #mul_add_c(a[2],b[6],c3,c1,c2);
1408 $LD r6,`2*$BNSZ`(r4)
1409 $LD r7,`6*$BNSZ`(r5)
1410 $UMULL r8,r6,r7
1411 $UMULH r9,r6,r7
1412 addc r12,r12,r8
1413 adde r10,r10,r9
1414 addze r11,r11
1415 #mul_add_c(a[1],b[7],c3,c1,c2);
1416 $LD r6,`1*$BNSZ`(r4)
1417 $LD r7,`7*$BNSZ`(r5)
1418 $UMULL r8,r6,r7
1419 $UMULH r9,r6,r7
1420 addc r12,r12,r8
1421 adde r10,r10,r9
1422 addze r11,r11
1423 $ST r12,`8*$BNSZ`(r3) #r[8]=c3;
1424 #mul_add_c(a[2],b[7],c1,c2,c3);
1425 $LD r6,`2*$BNSZ`(r4)
1426 $UMULL r8,r6,r7
1427 $UMULH r9,r6,r7
1428 addc r10,r10,r8
1429 adde r11,r11,r9
1430 addze r12,r0
1431 #mul_add_c(a[3],b[6],c1,c2,c3);
1432 $LD r6,`3*$BNSZ`(r4)
1433 $LD r7,`6*$BNSZ`(r5)
1434 $UMULL r8,r6,r7
1435 $UMULH r9,r6,r7
1436 addc r10,r10,r8
1437 adde r11,r11,r9
1438 addze r12,r12
1439 #mul_add_c(a[4],b[5],c1,c2,c3);
1440 $LD r6,`4*$BNSZ`(r4)
1441 $LD r7,`5*$BNSZ`(r5)
1442 $UMULL r8,r6,r7
1443 $UMULH r9,r6,r7
1444 addc r10,r10,r8
1445 adde r11,r11,r9
1446 addze r12,r12
1447 #mul_add_c(a[5],b[4],c1,c2,c3);
1448 $LD r6,`5*$BNSZ`(r4)
1449 $LD r7,`4*$BNSZ`(r5)
1450 $UMULL r8,r6,r7
1451 $UMULH r9,r6,r7
1452 addc r10,r10,r8
1453 adde r11,r11,r9
1454 addze r12,r12
1455 #mul_add_c(a[6],b[3],c1,c2,c3);
1456 $LD r6,`6*$BNSZ`(r4)
1457 $LD r7,`3*$BNSZ`(r5)
1458 $UMULL r8,r6,r7
1459 $UMULH r9,r6,r7
1460 addc r10,r10,r8
1461 adde r11,r11,r9
1462 addze r12,r12
1463 #mul_add_c(a[7],b[2],c1,c2,c3);
1464 $LD r6,`7*$BNSZ`(r4)
1465 $LD r7,`2*$BNSZ`(r5)
1466 $UMULL r8,r6,r7
1467 $UMULH r9,r6,r7
1468 addc r10,r10,r8
1469 adde r11,r11,r9
1470 addze r12,r12
1471 $ST r10,`9*$BNSZ`(r3) #r[9]=c1;
1472 #mul_add_c(a[7],b[3],c2,c3,c1);
1473 $LD r7,`3*$BNSZ`(r5)
1474 $UMULL r8,r6,r7
1475 $UMULH r9,r6,r7
1476 addc r11,r11,r8
1477 adde r12,r12,r9
1478 addze r10,r0
1479 #mul_add_c(a[6],b[4],c2,c3,c1);
1480 $LD r6,`6*$BNSZ`(r4)
1481 $LD r7,`4*$BNSZ`(r5)
1482 $UMULL r8,r6,r7
1483 $UMULH r9,r6,r7
1484 addc r11,r11,r8
1485 adde r12,r12,r9
1486 addze r10,r10
1487 #mul_add_c(a[5],b[5],c2,c3,c1);
1488 $LD r6,`5*$BNSZ`(r4)
1489 $LD r7,`5*$BNSZ`(r5)
1490 $UMULL r8,r6,r7
1491 $UMULH r9,r6,r7
1492 addc r11,r11,r8
1493 adde r12,r12,r9
1494 addze r10,r10
1495 #mul_add_c(a[4],b[6],c2,c3,c1);
1496 $LD r6,`4*$BNSZ`(r4)
1497 $LD r7,`6*$BNSZ`(r5)
1498 $UMULL r8,r6,r7
1499 $UMULH r9,r6,r7
1500 addc r11,r11,r8
1501 adde r12,r12,r9
1502 addze r10,r10
1503 #mul_add_c(a[3],b[7],c2,c3,c1);
1504 $LD r6,`3*$BNSZ`(r4)
1505 $LD r7,`7*$BNSZ`(r5)
1506 $UMULL r8,r6,r7
1507 $UMULH r9,r6,r7
1508 addc r11,r11,r8
1509 adde r12,r12,r9
1510 addze r10,r10
1511 $ST r11,`10*$BNSZ`(r3) #r[10]=c2;
1512 #mul_add_c(a[4],b[7],c3,c1,c2);
1513 $LD r6,`4*$BNSZ`(r4)
1514 $UMULL r8,r6,r7
1515 $UMULH r9,r6,r7
1516 addc r12,r12,r8
1517 adde r10,r10,r9
1518 addze r11,r0
1519 #mul_add_c(a[5],b[6],c3,c1,c2);
1520 $LD r6,`5*$BNSZ`(r4)
1521 $LD r7,`6*$BNSZ`(r5)
1522 $UMULL r8,r6,r7
1523 $UMULH r9,r6,r7
1524 addc r12,r12,r8
1525 adde r10,r10,r9
1526 addze r11,r11
1527 #mul_add_c(a[6],b[5],c3,c1,c2);
1528 $LD r6,`6*$BNSZ`(r4)
1529 $LD r7,`5*$BNSZ`(r5)
1530 $UMULL r8,r6,r7
1531 $UMULH r9,r6,r7
1532 addc r12,r12,r8
1533 adde r10,r10,r9
1534 addze r11,r11
1535 #mul_add_c(a[7],b[4],c3,c1,c2);
1536 $LD r6,`7*$BNSZ`(r4)
1537 $LD r7,`4*$BNSZ`(r5)
1538 $UMULL r8,r6,r7
1539 $UMULH r9,r6,r7
1540 addc r12,r12,r8
1541 adde r10,r10,r9
1542 addze r11,r11
1543 $ST r12,`11*$BNSZ`(r3) #r[11]=c3;
1544 #mul_add_c(a[7],b[5],c1,c2,c3);
1545 $LD r7,`5*$BNSZ`(r5)
1546 $UMULL r8,r6,r7
1547 $UMULH r9,r6,r7
1548 addc r10,r10,r8
1549 adde r11,r11,r9
1550 addze r12,r0
1551 #mul_add_c(a[6],b[6],c1,c2,c3);
1552 $LD r6,`6*$BNSZ`(r4)
1553 $LD r7,`6*$BNSZ`(r5)
1554 $UMULL r8,r6,r7
1555 $UMULH r9,r6,r7
1556 addc r10,r10,r8
1557 adde r11,r11,r9
1558 addze r12,r12
1559 #mul_add_c(a[5],b[7],c1,c2,c3);
1560 $LD r6,`5*$BNSZ`(r4)
1561 $LD r7,`7*$BNSZ`(r5)
1562 $UMULL r8,r6,r7
1563 $UMULH r9,r6,r7
1564 addc r10,r10,r8
1565 adde r11,r11,r9
1566 addze r12,r12
1567 $ST r10,`12*$BNSZ`(r3) #r[12]=c1;
1568 #mul_add_c(a[6],b[7],c2,c3,c1);
1569 $LD r6,`6*$BNSZ`(r4)
1570 $UMULL r8,r6,r7
1571 $UMULH r9,r6,r7
1572 addc r11,r11,r8
1573 adde r12,r12,r9
1574 addze r10,r0
1575 #mul_add_c(a[7],b[6],c2,c3,c1);
1576 $LD r6,`7*$BNSZ`(r4)
1577 $LD r7,`6*$BNSZ`(r5)
1578 $UMULL r8,r6,r7
1579 $UMULH r9,r6,r7
1580 addc r11,r11,r8
1581 adde r12,r12,r9
1582 addze r10,r10
1583 $ST r11,`13*$BNSZ`(r3) #r[13]=c2;
1584 #mul_add_c(a[7],b[7],c3,c1,c2);
1585 $LD r7,`7*$BNSZ`(r5)
1586 $UMULL r8,r6,r7
1587 $UMULH r9,r6,r7
1588 addc r12,r12,r8
1589 adde r10,r10,r9
1590 $ST r12,`14*$BNSZ`(r3) #r[14]=c3;
1591 $ST r10,`15*$BNSZ`(r3) #r[15]=c1;
1592 bclr BO_ALWAYS,CR0_LT
1593 .long 0x00000000
1594
1595#
1596# NOTE: The following label name should be changed to
1597# "bn_sub_words" i.e. remove the first dot
1598# for the gcc compiler. This should be automatically
1599# done in the build
1600#
1601#
1602.align 4
1603.bn_sub_words:
1604#
1605# Handcoded version of bn_sub_words
1606#
1607#BN_ULONG bn_sub_words(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n)
1608#
1609# r3 = r
1610# r4 = a
1611# r5 = b
1612# r6 = n
1613#
1614# Note: No loop unrolling done since this is not a performance
1615# critical loop.
1616
1617 xor r0,r0,r0 #set r0 = 0
1618#
1619# check for r6 = 0 AND set carry bit.
1620#
1621 subfc. r7,r0,r6 # If r6 is 0 then result is 0.
1622 # if r6 > 0 then result !=0
1623 # In either case carry bit is set.
1624 bc BO_IF,CR0_EQ,Lppcasm_sub_adios
1625 addi r4,r4,-$BNSZ
1626 addi r3,r3,-$BNSZ
1627 addi r5,r5,-$BNSZ
1628 mtctr r6
1629Lppcasm_sub_mainloop:
1630 $LDU r7,$BNSZ(r4)
1631 $LDU r8,$BNSZ(r5)
1632 subfe r6,r8,r7 # r6 = r7+carry bit + onescomplement(r8)
1633 # if carry = 1 this is r7-r8. Else it
1634 # is r7-r8 -1 as we need.
1635 $STU r6,$BNSZ(r3)
1636 bc BO_dCTR_NZERO,CR0_EQ,Lppcasm_sub_mainloop
1637Lppcasm_sub_adios:
1638 subfze r3,r0 # if carry bit is set then r3 = 0 else -1
1639 andi. r3,r3,1 # keep only last bit.
1640 bclr BO_ALWAYS,CR0_LT
1641 .long 0x00000000
1642
1643
1644#
1645# NOTE: The following label name should be changed to
1646# "bn_add_words" i.e. remove the first dot
1647# for the gcc compiler. This should be automatically
1648# done in the build
1649#
1650
1651.align 4
1652.bn_add_words:
1653#
1654# Handcoded version of bn_add_words
1655#
1656#BN_ULONG bn_add_words(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n)
1657#
1658# r3 = r
1659# r4 = a
1660# r5 = b
1661# r6 = n
1662#
1663# Note: No loop unrolling done since this is not a performance
1664# critical loop.
1665
1666 xor r0,r0,r0
1667#
1668# check for r6 = 0. Is this needed?
1669#
1670 addic. r6,r6,0 #test r6 and clear carry bit.
1671 bc BO_IF,CR0_EQ,Lppcasm_add_adios
1672 addi r4,r4,-$BNSZ
1673 addi r3,r3,-$BNSZ
1674 addi r5,r5,-$BNSZ
1675 mtctr r6
1676Lppcasm_add_mainloop:
1677 $LDU r7,$BNSZ(r4)
1678 $LDU r8,$BNSZ(r5)
1679 adde r8,r7,r8
1680 $STU r8,$BNSZ(r3)
1681 bc BO_dCTR_NZERO,CR0_EQ,Lppcasm_add_mainloop
1682Lppcasm_add_adios:
1683 addze r3,r0 #return carry bit.
1684 bclr BO_ALWAYS,CR0_LT
1685 .long 0x00000000
1686
1687#
1688# NOTE: The following label name should be changed to
1689# "bn_div_words" i.e. remove the first dot
1690# for the gcc compiler. This should be automatically
1691# done in the build
1692#
1693
1694.align 4
1695.bn_div_words:
1696#
1697# This is a cleaned up version of code generated by
1698# the AIX compiler. The only optimization is to use
1699# the PPC instruction to count leading zeros instead
1700# of call to num_bits_word. Since this was compiled
1701# only at level -O2 we can possibly squeeze it more?
1702#
1703# r3 = h
1704# r4 = l
1705# r5 = d
1706
1707 $UCMPI 0,r5,0 # compare r5 and 0
1708 bc BO_IF_NOT,CR0_EQ,Lppcasm_div1 # proceed if d!=0
1709 li r3,-1 # d=0 return -1
1710 bclr BO_ALWAYS,CR0_LT
1711Lppcasm_div1:
1712 xor r0,r0,r0 #r0=0
1713 $COUNTZ r7,r5 #r7 = num leading 0s in d.
1714 subfic r8,r7,$BITS #r8 = BN_num_bits_word(d)
1715 cmpi 0,0,r8,$BITS #
1716 bc BO_IF,CR0_EQ,Lppcasm_div2 #proceed if (r8==$BITS)
1717 li r9,1 # r9=1
1718 $SHL r10,r9,r8 # r9<<=r8
1719 $UCMP 0,r3,r10 #
1720 bc BO_IF,CR0_GT,Lppcasm_div2 #or if (h > (1<<r8))
1721 $UDIV r3,r3,r0 #if not assert(0) divide by 0!
1722 #that's how we signal overflow
1723 bclr BO_ALWAYS,CR0_LT #return. NEVER REACHED.
1724Lppcasm_div2:
1725 $UCMP 0,r3,r5 #h>=d?
1726 bc BO_IF,CR0_LT,Lppcasm_div3 #goto Lppcasm_div3 if not
1727 subf r3,r5,r3 #h-=d ;
1728Lppcasm_div3: #r7 = BN_BITS2-i. so r7=i
1729 cmpi 0,0,r7,0 # is (i == 0)?
1730 bc BO_IF,CR0_EQ,Lppcasm_div4
1731 $SHL r3,r3,r7 # h = (h<< i)
1732 $SHR r8,r4,r8 # r8 = (l >> BN_BITS2 -i)
1733 $SHL r5,r5,r7 # d<<=i
1734 or r3,r3,r8 # h = (h<<i)|(l>>(BN_BITS2-i))
1735 $SHL r4,r4,r7 # l <<=i
1736Lppcasm_div4:
1737 $SHRI r9,r5,`$BITS/2` # r9 = dh
1738 # dl will be computed when needed
1739 # as it saves registers.
1740 li r6,2 #r6=2
1741 mtctr r6 #counter will be in count.
1742Lppcasm_divouterloop:
1743 $SHRI r8,r3,`$BITS/2` #r8 = (h>>BN_BITS4)
1744 $SHRI r11,r4,`$BITS/2` #r11= (l&BN_MASK2h)>>BN_BITS4
1745 # compute here for innerloop.
1746 $UCMP 0,r8,r9 # is (h>>BN_BITS4)==dh
1747 bc BO_IF_NOT,CR0_EQ,Lppcasm_div5 # goto Lppcasm_div5 if not
1748
1749 li r8,-1
1750 $CLRU r8,r8,`$BITS/2` #q = BN_MASK2l
1751 b Lppcasm_div6
1752Lppcasm_div5:
1753 $UDIV r8,r3,r9 #q = h/dh
1754Lppcasm_div6:
1755 $UMULL r12,r9,r8 #th = q*dh
1756 $CLRU r10,r5,`$BITS/2` #r10=dl
1757 $UMULL r6,r8,r10 #tl = q*dl
1758
1759Lppcasm_divinnerloop:
1760 subf r10,r12,r3 #t = h -th
1761 $SHRI r7,r10,`$BITS/2` #r7= (t &BN_MASK2H), sort of...
1762 addic. r7,r7,0 #test if r7 == 0. used below.
1763 # now want to compute
1764 # r7 = (t<<BN_BITS4)|((l&BN_MASK2h)>>BN_BITS4)
1765 # the following 2 instructions do that
1766 $SHLI r7,r10,`$BITS/2` # r7 = (t<<BN_BITS4)
1767 or r7,r7,r11 # r7|=((l&BN_MASK2h)>>BN_BITS4)
1768 $UCMP 1,r6,r7 # compare (tl <= r7)
1769 bc BO_IF_NOT,CR0_EQ,Lppcasm_divinnerexit
1770 bc BO_IF_NOT,CR1_FEX,Lppcasm_divinnerexit
1771 addi r8,r8,-1 #q--
1772 subf r12,r9,r12 #th -=dh
1773 $CLRU r10,r5,`$BITS/2` #r10=dl. t is no longer needed in loop.
1774 subf r6,r10,r6 #tl -=dl
1775 b Lppcasm_divinnerloop
1776Lppcasm_divinnerexit:
1777 $SHRI r10,r6,`$BITS/2` #t=(tl>>BN_BITS4)
1778 $SHLI r11,r6,`$BITS/2` #tl=(tl<<BN_BITS4)&BN_MASK2h;
1779 $UCMP 1,r4,r11 # compare l and tl
1780 add r12,r12,r10 # th+=t
1781 bc BO_IF_NOT,CR1_FX,Lppcasm_div7 # if (l>=tl) goto Lppcasm_div7
1782 addi r12,r12,1 # th++
1783Lppcasm_div7:
1784 subf r11,r11,r4 #r11=l-tl
1785 $UCMP 1,r3,r12 #compare h and th
1786 bc BO_IF_NOT,CR1_FX,Lppcasm_div8 #if (h>=th) goto Lppcasm_div8
1787 addi r8,r8,-1 # q--
1788 add r3,r5,r3 # h+=d
1789Lppcasm_div8:
1790 subf r12,r12,r3 #r12 = h-th
1791 $SHLI r4,r11,`$BITS/2` #l=(l&BN_MASK2l)<<BN_BITS4
1792 # want to compute
1793 # h = ((h<<BN_BITS4)|(l>>BN_BITS4))&BN_MASK2
1794 # the following 2 instructions will do this.
1795 $INSR r11,r12,`$BITS/2`,`$BITS/2` # r11 is the value we want rotated $BITS/2.
1796 $ROTL r3,r11,`$BITS/2` # rotate by $BITS/2 and store in r3
1797 bc BO_dCTR_ZERO,CR0_EQ,Lppcasm_div9#if (count==0) break ;
1798 $SHLI r0,r8,`$BITS/2` #ret =q<<BN_BITS4
1799 b Lppcasm_divouterloop
1800Lppcasm_div9:
1801 or r3,r8,r0
1802 bclr BO_ALWAYS,CR0_LT
1803 .long 0x00000000
1804
1805#
1806# NOTE: The following label name should be changed to
1807# "bn_sqr_words" i.e. remove the first dot
1808# for the gcc compiler. This should be automatically
1809# done in the build
1810#
1811.align 4
1812.bn_sqr_words:
1813#
1814# Optimized version of bn_sqr_words
1815#
1816# void bn_sqr_words(BN_ULONG *r, BN_ULONG *a, int n)
1817#
1818# r3 = r
1819# r4 = a
1820# r5 = n
1821#
1822# r6 = a[i].
1823# r7,r8 = product.
1824#
1825# No unrolling done here. Not performance critical.
1826
1827 addic. r5,r5,0 #test r5.
1828 bc BO_IF,CR0_EQ,Lppcasm_sqr_adios
1829 addi r4,r4,-$BNSZ
1830 addi r3,r3,-$BNSZ
1831 mtctr r5
1832Lppcasm_sqr_mainloop:
1833 #sqr(r[0],r[1],a[0]);
1834 $LDU r6,$BNSZ(r4)
1835 $UMULL r7,r6,r6
1836 $UMULH r8,r6,r6
1837 $STU r7,$BNSZ(r3)
1838 $STU r8,$BNSZ(r3)
1839 bc BO_dCTR_NZERO,CR0_EQ,Lppcasm_sqr_mainloop
1840Lppcasm_sqr_adios:
1841 bclr BO_ALWAYS,CR0_LT
1842 .long 0x00000000
1843
1844
1845#
1846# NOTE: The following label name should be changed to
1847# "bn_mul_words" i.e. remove the first dot
1848# for the gcc compiler. This should be automatically
1849# done in the build
1850#
1851
1852.align 4
1853.bn_mul_words:
1854#
1855# BN_ULONG bn_mul_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w)
1856#
1857# r3 = rp
1858# r4 = ap
1859# r5 = num
1860# r6 = w
1861 xor r0,r0,r0
1862 xor r12,r12,r12 # used for carry
1863 rlwinm. r7,r5,30,2,31 # num >> 2
1864 bc BO_IF,CR0_EQ,Lppcasm_mw_REM
1865 mtctr r7
1866Lppcasm_mw_LOOP:
1867 #mul(rp[0],ap[0],w,c1);
1868 $LD r8,`0*$BNSZ`(r4)
1869 $UMULL r9,r6,r8
1870 $UMULH r10,r6,r8
1871 addc r9,r9,r12
1872 #addze r10,r10 #carry is NOT ignored.
1873 #will be taken care of
1874 #in second spin below
1875 #using adde.
1876 $ST r9,`0*$BNSZ`(r3)
1877 #mul(rp[1],ap[1],w,c1);
1878 $LD r8,`1*$BNSZ`(r4)
1879 $UMULL r11,r6,r8
1880 $UMULH r12,r6,r8
1881 adde r11,r11,r10
1882 #addze r12,r12
1883 $ST r11,`1*$BNSZ`(r3)
1884 #mul(rp[2],ap[2],w,c1);
1885 $LD r8,`2*$BNSZ`(r4)
1886 $UMULL r9,r6,r8
1887 $UMULH r10,r6,r8
1888 adde r9,r9,r12
1889 #addze r10,r10
1890 $ST r9,`2*$BNSZ`(r3)
1891 #mul_add(rp[3],ap[3],w,c1);
1892 $LD r8,`3*$BNSZ`(r4)
1893 $UMULL r11,r6,r8
1894 $UMULH r12,r6,r8
1895 adde r11,r11,r10
1896 addze r12,r12 #this spin we collect carry into
1897 #r12
1898 $ST r11,`3*$BNSZ`(r3)
1899
1900 addi r3,r3,`4*$BNSZ`
1901 addi r4,r4,`4*$BNSZ`
1902 bc BO_dCTR_NZERO,CR0_EQ,Lppcasm_mw_LOOP
1903
1904Lppcasm_mw_REM:
1905 andi. r5,r5,0x3
1906 bc BO_IF,CR0_EQ,Lppcasm_mw_OVER
1907 #mul(rp[0],ap[0],w,c1);
1908 $LD r8,`0*$BNSZ`(r4)
1909 $UMULL r9,r6,r8
1910 $UMULH r10,r6,r8
1911 addc r9,r9,r12
1912 addze r10,r10
1913 $ST r9,`0*$BNSZ`(r3)
1914 addi r12,r10,0
1915
1916 addi r5,r5,-1
1917 cmpli 0,0,r5,0
1918 bc BO_IF,CR0_EQ,Lppcasm_mw_OVER
1919
1920
1921 #mul(rp[1],ap[1],w,c1);
1922 $LD r8,`1*$BNSZ`(r4)
1923 $UMULL r9,r6,r8
1924 $UMULH r10,r6,r8
1925 addc r9,r9,r12
1926 addze r10,r10
1927 $ST r9,`1*$BNSZ`(r3)
1928 addi r12,r10,0
1929
1930 addi r5,r5,-1
1931 cmpli 0,0,r5,0
1932 bc BO_IF,CR0_EQ,Lppcasm_mw_OVER
1933
1934 #mul_add(rp[2],ap[2],w,c1);
1935 $LD r8,`2*$BNSZ`(r4)
1936 $UMULL r9,r6,r8
1937 $UMULH r10,r6,r8
1938 addc r9,r9,r12
1939 addze r10,r10
1940 $ST r9,`2*$BNSZ`(r3)
1941 addi r12,r10,0
1942
1943Lppcasm_mw_OVER:
1944 addi r3,r12,0
1945 bclr BO_ALWAYS,CR0_LT
1946 .long 0x00000000
1947
1948#
1949# NOTE: The following label name should be changed to
1950# "bn_mul_add_words" i.e. remove the first dot
1951# for the gcc compiler. This should be automatically
1952# done in the build
1953#
1954
1955.align 4
1956.bn_mul_add_words:
1957#
1958# BN_ULONG bn_mul_add_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w)
1959#
1960# r3 = rp
1961# r4 = ap
1962# r5 = num
1963# r6 = w
1964#
1965# empirical evidence suggests that unrolled version performs best!!
1966#
1967 xor r0,r0,r0 #r0 = 0
1968 xor r12,r12,r12 #r12 = 0 . used for carry
1969 rlwinm. r7,r5,30,2,31 # num >> 2
1970 bc BO_IF,CR0_EQ,Lppcasm_maw_leftover # if (num < 4) go LPPCASM_maw_leftover
1971 mtctr r7
1972Lppcasm_maw_mainloop:
1973 #mul_add(rp[0],ap[0],w,c1);
1974 $LD r8,`0*$BNSZ`(r4)
1975 $LD r11,`0*$BNSZ`(r3)
1976 $UMULL r9,r6,r8
1977 $UMULH r10,r6,r8
1978 addc r9,r9,r12 #r12 is carry.
1979 addze r10,r10
1980 addc r9,r9,r11
1981 #addze r10,r10
1982 #the above instruction addze
1983 #is NOT needed. Carry will NOT
1984 #be ignored. It's not affected
1985 #by multiply and will be collected
1986 #in the next spin
1987 $ST r9,`0*$BNSZ`(r3)
1988
1989 #mul_add(rp[1],ap[1],w,c1);
1990 $LD r8,`1*$BNSZ`(r4)
1991 $LD r9,`1*$BNSZ`(r3)
1992 $UMULL r11,r6,r8
1993 $UMULH r12,r6,r8
1994 adde r11,r11,r10 #r10 is carry.
1995 addze r12,r12
1996 addc r11,r11,r9
1997 #addze r12,r12
1998 $ST r11,`1*$BNSZ`(r3)
1999
2000 #mul_add(rp[2],ap[2],w,c1);
2001 $LD r8,`2*$BNSZ`(r4)
2002 $UMULL r9,r6,r8
2003 $LD r11,`2*$BNSZ`(r3)
2004 $UMULH r10,r6,r8
2005 adde r9,r9,r12
2006 addze r10,r10
2007 addc r9,r9,r11
2008 #addze r10,r10
2009 $ST r9,`2*$BNSZ`(r3)
2010
2011 #mul_add(rp[3],ap[3],w,c1);
2012 $LD r8,`3*$BNSZ`(r4)
2013 $UMULL r11,r6,r8
2014 $LD r9,`3*$BNSZ`(r3)
2015 $UMULH r12,r6,r8
2016 adde r11,r11,r10
2017 addze r12,r12
2018 addc r11,r11,r9
2019 addze r12,r12
2020 $ST r11,`3*$BNSZ`(r3)
2021 addi r3,r3,`4*$BNSZ`
2022 addi r4,r4,`4*$BNSZ`
2023 bc BO_dCTR_NZERO,CR0_EQ,Lppcasm_maw_mainloop
2024
2025Lppcasm_maw_leftover:
2026 andi. r5,r5,0x3
2027 bc BO_IF,CR0_EQ,Lppcasm_maw_adios
2028 addi r3,r3,-$BNSZ
2029 addi r4,r4,-$BNSZ
2030 #mul_add(rp[0],ap[0],w,c1);
2031 mtctr r5
2032 $LDU r8,$BNSZ(r4)
2033 $UMULL r9,r6,r8
2034 $UMULH r10,r6,r8
2035 $LDU r11,$BNSZ(r3)
2036 addc r9,r9,r11
2037 addze r10,r10
2038 addc r9,r9,r12
2039 addze r12,r10
2040 $ST r9,0(r3)
2041
2042 bc BO_dCTR_ZERO,CR0_EQ,Lppcasm_maw_adios
2043 #mul_add(rp[1],ap[1],w,c1);
2044 $LDU r8,$BNSZ(r4)
2045 $UMULL r9,r6,r8
2046 $UMULH r10,r6,r8
2047 $LDU r11,$BNSZ(r3)
2048 addc r9,r9,r11
2049 addze r10,r10
2050 addc r9,r9,r12
2051 addze r12,r10
2052 $ST r9,0(r3)
2053
2054 bc BO_dCTR_ZERO,CR0_EQ,Lppcasm_maw_adios
2055 #mul_add(rp[2],ap[2],w,c1);
2056 $LDU r8,$BNSZ(r4)
2057 $UMULL r9,r6,r8
2058 $UMULH r10,r6,r8
2059 $LDU r11,$BNSZ(r3)
2060 addc r9,r9,r11
2061 addze r10,r10
2062 addc r9,r9,r12
2063 addze r12,r10
2064 $ST r9,0(r3)
2065
2066Lppcasm_maw_adios:
2067 addi r3,r12,0
2068 bclr BO_ALWAYS,CR0_LT
2069 .long 0x00000000
2070 .align 4
2071EOF
2072 $data =~ s/\`([^\`]*)\`/eval $1/gem;
2073
2074 # if some assembler chokes on some simplified mnemonic,
2075 # this is the spot to fix it up, e.g.:
2076 # GNU as doesn't seem to accept cmplw, 32-bit unsigned compare
2077 $data =~ s/^(\s*)cmplw(\s+)([^,]+),(.*)/$1cmpl$2$3,0,$4/gm;
2078 # assembler X doesn't accept li, load immediate value
2079 #$data =~ s/^(\s*)li(\s+)([^,]+),(.*)/$1addi$2$3,0,$4/gm;
2080 return($data);
2081}
diff --git a/src/lib/libcrypto/bn/asm/x86_64-gcc.c b/src/lib/libcrypto/bn/asm/x86_64-gcc.c
index 450e8e4322..7378344251 100644
--- a/src/lib/libcrypto/bn/asm/x86_64-gcc.c
+++ b/src/lib/libcrypto/bn/asm/x86_64-gcc.c
@@ -13,20 +13,42 @@
13 * A. Well, that's because this code is basically a quick-n-dirty 13 * A. Well, that's because this code is basically a quick-n-dirty
14 * proof-of-concept hack. As you can see it's implemented with 14 * proof-of-concept hack. As you can see it's implemented with
15 * inline assembler, which means that you're bound to GCC and that 15 * inline assembler, which means that you're bound to GCC and that
16 * there must be a room for fine-tuning. 16 * there might be enough room for further improvement.
17 * 17 *
18 * Q. Why inline assembler? 18 * Q. Why inline assembler?
19 * A. x86_64 features own ABI I'm not familiar with. Which is why 19 * A. x86_64 features own ABI which I'm not familiar with. This is
20 * I decided to let the compiler take care of subroutine 20 * why I decided to let the compiler take care of subroutine
21 * prologue/epilogue as well as register allocation. 21 * prologue/epilogue as well as register allocation. For reference.
22 * Win64 implements different ABI for AMD64, different from Linux.
22 * 23 *
23 * Q. How much faster does it get? 24 * Q. How much faster does it get?
24 * A. Unfortunately people sitting on x86_64 hardware are prohibited 25 * A. 'apps/openssl speed rsa dsa' output with no-asm:
25 * to disclose the performance numbers, so they (SuSE labs to be 26 *
26 * specific) wouldn't tell me. However! Very similar coding technique 27 * sign verify sign/s verify/s
27 * (reaching out for 128-bit result from 64x64-bit multiplication) 28 * rsa 512 bits 0.0006s 0.0001s 1683.8 18456.2
28 * results in >3 times performance improvement on MIPS and I see no 29 * rsa 1024 bits 0.0028s 0.0002s 356.0 6407.0
29 * reason why gain on x86_64 would be so much different:-) 30 * rsa 2048 bits 0.0172s 0.0005s 58.0 1957.8
31 * rsa 4096 bits 0.1155s 0.0018s 8.7 555.6
32 * sign verify sign/s verify/s
33 * dsa 512 bits 0.0005s 0.0006s 2100.8 1768.3
34 * dsa 1024 bits 0.0014s 0.0018s 692.3 559.2
35 * dsa 2048 bits 0.0049s 0.0061s 204.7 165.0
36 *
37 * 'apps/openssl speed rsa dsa' output with this module:
38 *
39 * sign verify sign/s verify/s
40 * rsa 512 bits 0.0004s 0.0000s 2767.1 33297.9
41 * rsa 1024 bits 0.0012s 0.0001s 867.4 14674.7
42 * rsa 2048 bits 0.0061s 0.0002s 164.0 5270.0
43 * rsa 4096 bits 0.0384s 0.0006s 26.1 1650.8
44 * sign verify sign/s verify/s
45 * dsa 512 bits 0.0002s 0.0003s 4442.2 3786.3
46 * dsa 1024 bits 0.0005s 0.0007s 1835.1 1497.4
47 * dsa 2048 bits 0.0016s 0.0020s 620.4 504.6
48 *
49 * For the reference. IA-32 assembler implementation performs
50 * very much like 64-bit code compiled with no-asm on the same
51 * machine.
30 */ 52 */
31 53
32#define BN_ULONG unsigned long 54#define BN_ULONG unsigned long
@@ -151,7 +173,7 @@ BN_ULONG bn_div_words(BN_ULONG h, BN_ULONG l, BN_ULONG d)
151} 173}
152 174
153BN_ULONG bn_add_words (BN_ULONG *rp, BN_ULONG *ap, BN_ULONG *bp,int n) 175BN_ULONG bn_add_words (BN_ULONG *rp, BN_ULONG *ap, BN_ULONG *bp,int n)
154{ BN_ULONG ret,i; 176{ BN_ULONG ret=0,i=0;
155 177
156 if (n <= 0) return 0; 178 if (n <= 0) return 0;
157 179
@@ -164,7 +186,7 @@ BN_ULONG bn_add_words (BN_ULONG *rp, BN_ULONG *ap, BN_ULONG *bp,int n)
164 " leaq 1(%2),%2 \n" 186 " leaq 1(%2),%2 \n"
165 " loop 1b \n" 187 " loop 1b \n"
166 " sbbq %0,%0 \n" 188 " sbbq %0,%0 \n"
167 : "+a"(ret),"+c"(n),"+r"(i) 189 : "=&a"(ret),"+c"(n),"=&r"(i)
168 : "r"(rp),"r"(ap),"r"(bp) 190 : "r"(rp),"r"(ap),"r"(bp)
169 : "cc" 191 : "cc"
170 ); 192 );
@@ -174,7 +196,7 @@ BN_ULONG bn_add_words (BN_ULONG *rp, BN_ULONG *ap, BN_ULONG *bp,int n)
174 196
175#ifndef SIMICS 197#ifndef SIMICS
176BN_ULONG bn_sub_words (BN_ULONG *rp, BN_ULONG *ap, BN_ULONG *bp,int n) 198BN_ULONG bn_sub_words (BN_ULONG *rp, BN_ULONG *ap, BN_ULONG *bp,int n)
177{ BN_ULONG ret,i; 199{ BN_ULONG ret=0,i=0;
178 200
179 if (n <= 0) return 0; 201 if (n <= 0) return 0;
180 202
@@ -187,7 +209,7 @@ BN_ULONG bn_sub_words (BN_ULONG *rp, BN_ULONG *ap, BN_ULONG *bp,int n)
187 " leaq 1(%2),%2 \n" 209 " leaq 1(%2),%2 \n"
188 " loop 1b \n" 210 " loop 1b \n"
189 " sbbq %0,%0 \n" 211 " sbbq %0,%0 \n"
190 : "+a"(ret),"+c"(n),"+r"(i) 212 : "=&a"(ret),"+c"(n),"=&r"(i)
191 : "r"(rp),"r"(ap),"r"(bp) 213 : "r"(rp),"r"(ap),"r"(bp)
192 : "cc" 214 : "cc"
193 ); 215 );
@@ -318,7 +340,6 @@ BN_ULONG bn_sub_words(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n)
318 340
319void bn_mul_comba8(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b) 341void bn_mul_comba8(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b)
320 { 342 {
321 BN_ULONG bl,bh;
322 BN_ULONG t1,t2; 343 BN_ULONG t1,t2;
323 BN_ULONG c1,c2,c3; 344 BN_ULONG c1,c2,c3;
324 345
@@ -423,7 +444,6 @@ void bn_mul_comba8(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b)
423 444
424void bn_mul_comba4(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b) 445void bn_mul_comba4(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b)
425 { 446 {
426 BN_ULONG bl,bh;
427 BN_ULONG t1,t2; 447 BN_ULONG t1,t2;
428 BN_ULONG c1,c2,c3; 448 BN_ULONG c1,c2,c3;
429 449
@@ -464,7 +484,6 @@ void bn_mul_comba4(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b)
464 484
465void bn_sqr_comba8(BN_ULONG *r, BN_ULONG *a) 485void bn_sqr_comba8(BN_ULONG *r, BN_ULONG *a)
466 { 486 {
467 BN_ULONG bl,bh;
468 BN_ULONG t1,t2; 487 BN_ULONG t1,t2;
469 BN_ULONG c1,c2,c3; 488 BN_ULONG c1,c2,c3;
470 489
@@ -541,7 +560,6 @@ void bn_sqr_comba8(BN_ULONG *r, BN_ULONG *a)
541 560
542void bn_sqr_comba4(BN_ULONG *r, BN_ULONG *a) 561void bn_sqr_comba4(BN_ULONG *r, BN_ULONG *a)
543 { 562 {
544 BN_ULONG bl,bh;
545 BN_ULONG t1,t2; 563 BN_ULONG t1,t2;
546 BN_ULONG c1,c2,c3; 564 BN_ULONG c1,c2,c3;
547 565
diff --git a/src/lib/libcrypto/doc/X509_NAME_ENTRY_get_object.pod b/src/lib/libcrypto/doc/X509_NAME_ENTRY_get_object.pod
index d287c18564..11b35f6fd3 100644
--- a/src/lib/libcrypto/doc/X509_NAME_ENTRY_get_object.pod
+++ b/src/lib/libcrypto/doc/X509_NAME_ENTRY_get_object.pod
@@ -13,11 +13,11 @@ ASN1_OBJECT * X509_NAME_ENTRY_get_object(X509_NAME_ENTRY *ne);
13ASN1_STRING * X509_NAME_ENTRY_get_data(X509_NAME_ENTRY *ne); 13ASN1_STRING * X509_NAME_ENTRY_get_data(X509_NAME_ENTRY *ne);
14 14
15int X509_NAME_ENTRY_set_object(X509_NAME_ENTRY *ne, ASN1_OBJECT *obj); 15int X509_NAME_ENTRY_set_object(X509_NAME_ENTRY *ne, ASN1_OBJECT *obj);
16int X509_NAME_ENTRY_set_data(X509_NAME_ENTRY *ne, int type, unsigned char *bytes, int len); 16int X509_NAME_ENTRY_set_data(X509_NAME_ENTRY *ne, int type, const unsigned char *bytes, int len);
17 17
18X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_txt(X509_NAME_ENTRY **ne, char *field, int type, unsigned char *bytes, int len); 18X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_txt(X509_NAME_ENTRY **ne, const char *field, int type, const unsigned char *bytes, int len);
19X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_NID(X509_NAME_ENTRY **ne, int nid, int type,unsigned char *bytes, int len); 19X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_NID(X509_NAME_ENTRY **ne, int nid, int type,unsigned char *bytes, int len);
20X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_OBJ(X509_NAME_ENTRY **ne, ASN1_OBJECT *obj, int type,unsigned char *bytes, int len); 20X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_OBJ(X509_NAME_ENTRY **ne, ASN1_OBJECT *obj, int type, const unsigned char *bytes, int len);
21 21
22=head1 DESCRIPTION 22=head1 DESCRIPTION
23 23
diff --git a/src/lib/libcrypto/doc/X509_NAME_add_entry_by_txt.pod b/src/lib/libcrypto/doc/X509_NAME_add_entry_by_txt.pod
index 4472a1c5cf..e2ab4b0d2b 100644
--- a/src/lib/libcrypto/doc/X509_NAME_add_entry_by_txt.pod
+++ b/src/lib/libcrypto/doc/X509_NAME_add_entry_by_txt.pod
@@ -7,10 +7,14 @@ X509_NAME_add_entry, X509_NAME_delete_entry - X509_NAME modification functions
7 7
8=head1 SYNOPSIS 8=head1 SYNOPSIS
9 9
10int X509_NAME_add_entry_by_txt(X509_NAME *name, char *field, int type, unsigned char *bytes, int len, int loc, int set); 10int X509_NAME_add_entry_by_txt(X509_NAME *name, const char *field, int type, const unsigned char *bytes, int len, int loc, int set);
11
11int X509_NAME_add_entry_by_OBJ(X509_NAME *name, ASN1_OBJECT *obj, int type, unsigned char *bytes, int len, int loc, int set); 12int X509_NAME_add_entry_by_OBJ(X509_NAME *name, ASN1_OBJECT *obj, int type, unsigned char *bytes, int len, int loc, int set);
13
12int X509_NAME_add_entry_by_NID(X509_NAME *name, int nid, int type, unsigned char *bytes, int len, int loc, int set); 14int X509_NAME_add_entry_by_NID(X509_NAME *name, int nid, int type, unsigned char *bytes, int len, int loc, int set);
15
13int X509_NAME_add_entry(X509_NAME *name,X509_NAME_ENTRY *ne, int loc, int set); 16int X509_NAME_add_entry(X509_NAME *name,X509_NAME_ENTRY *ne, int loc, int set);
17
14X509_NAME_ENTRY *X509_NAME_delete_entry(X509_NAME *name, int loc); 18X509_NAME_ENTRY *X509_NAME_delete_entry(X509_NAME *name, int loc);
15 19
16=head1 DESCRIPTION 20=head1 DESCRIPTION
diff --git a/src/lib/libcrypto/doc/X509_NAME_print_ex.pod b/src/lib/libcrypto/doc/X509_NAME_print_ex.pod
index 907c04f684..919b908919 100644
--- a/src/lib/libcrypto/doc/X509_NAME_print_ex.pod
+++ b/src/lib/libcrypto/doc/X509_NAME_print_ex.pod
@@ -41,8 +41,8 @@ applications.
41Although there are a large number of possible flags for most purposes 41Although there are a large number of possible flags for most purposes
42B<XN_FLAG_ONELINE>, B<XN_FLAG_MULTILINE> or B<XN_FLAG_RFC2253> will suffice. 42B<XN_FLAG_ONELINE>, B<XN_FLAG_MULTILINE> or B<XN_FLAG_RFC2253> will suffice.
43As noted on the L<ASN1_STRING_print_ex(3)|ASN1_STRING_print_ex(3)> manual page 43As noted on the L<ASN1_STRING_print_ex(3)|ASN1_STRING_print_ex(3)> manual page
44for UTF8 terminals the B<ASN1_STRFLAGS_ESC_MSB> should be unset: so for example 44for UTF8 terminals the B<ASN1_STRFLGS_ESC_MSB> should be unset: so for example
45B<XN_FLAG_ONELINE & ~ASN1_STRFLAGS_ESC_MSB> would be used. 45B<XN_FLAG_ONELINE & ~ASN1_STRFLGS_ESC_MSB> would be used.
46 46
47The complete set of the flags supported by X509_NAME_print_ex() is listed below. 47The complete set of the flags supported by X509_NAME_print_ex() is listed below.
48 48
diff --git a/src/lib/libcrypto/evp/e_old.c b/src/lib/libcrypto/evp/e_old.c
new file mode 100644
index 0000000000..92dc498945
--- /dev/null
+++ b/src/lib/libcrypto/evp/e_old.c
@@ -0,0 +1,108 @@
1/* crypto/evp/e_old.c -*- mode:C; c-file-style: "eay" -*- */
2/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
3 * project 2004.
4 */
5/* ====================================================================
6 * Copyright (c) 2004 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * openssl-core@openssl.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <openssl/evp.h>
60
61/* Define some deprecated functions, so older programs
62 don't crash and burn too quickly. On Windows and VMS,
63 these will never be used, since functions and variables
64 in shared libraries are selected by entry point location,
65 not by name. */
66
67#ifndef OPENSSL_NO_BF
68#undef EVP_bf_cfb
69const EVP_CIPHER *EVP_bf_cfb(void) { return EVP_bf_cfb64(); }
70#endif
71
72#ifndef OPENSSL_NO_DES
73#undef EVP_des_cfb
74const EVP_CIPHER *EVP_des_cfb(void) { return EVP_des_cfb64(); }
75#undef EVP_des_ede3_cfb
76const EVP_CIPHER *EVP_des_ede3_cfb(void) { return EVP_des_ede3_cfb64(); }
77#undef EVP_des_ede_cfb
78const EVP_CIPHER *EVP_des_ede_cfb(void) { return EVP_des_ede_cfb64(); }
79#endif
80
81#ifndef OPENSSL_NO_IDEA
82#undef EVP_idea_cfb
83const EVP_CIPHER *EVP_idea_cfb(void) { return EVP_idea_cfb64(); }
84#endif
85
86#ifndef OPENSSL_NO_RC2
87#undef EVP_rc2_cfb
88const EVP_CIPHER *EVP_rc2_cfb(void) { return EVP_rc2_cfb64(); }
89#endif
90
91#ifndef OPENSSL_NO_CAST
92#undef EVP_cast5_cfb
93const EVP_CIPHER *EVP_cast5_cfb(void) { return EVP_cast5_cfb64(); }
94#endif
95
96#ifndef OPENSSL_NO_RC5
97#undef EVP_rc5_32_12_16_cfb
98const EVP_CIPHER *EVP_rc5_32_12_16_cfb(void) { return EVP_rc5_32_12_16_cfb64(); }
99#endif
100
101#ifndef OPENSSL_NO_AES
102#undef EVP_aes_128_cfb
103const EVP_CIPHER *EVP_aes_128_cfb(void) { return EVP_aes_128_cfb128(); }
104#undef EVP_aes_192_cfb
105const EVP_CIPHER *EVP_aes_192_cfb(void) { return EVP_aes_192_cfb128(); }
106#undef EVP_aes_256_cfb
107const EVP_CIPHER *EVP_aes_256_cfb(void) { return EVP_aes_256_cfb128(); }
108#endif
diff --git a/src/lib/libcrypto/o_str.c b/src/lib/libcrypto/o_str.c
new file mode 100644
index 0000000000..da8860491d
--- /dev/null
+++ b/src/lib/libcrypto/o_str.c
@@ -0,0 +1,96 @@
1/* crypto/o_str.c -*- mode:C; c-file-style: "eay" -*- */
2/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
3 * project 2003.
4 */
5/* ====================================================================
6 * Copyright (c) 2003 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * openssl-core@openssl.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <ctype.h>
60#include <e_os.h>
61#include "o_str.h"
62
63int OPENSSL_strncasecmp(const char *str1, const char *str2, size_t n)
64 {
65#if defined(OPENSSL_IMPLEMENTS_strncasecmp)
66 while (*str1 && *str2 && n)
67 {
68 int res = toupper(*str1) - toupper(*str2);
69 if (res) return res < 0 ? -1 : 1;
70 str1++;
71 str2++;
72 n--;
73 }
74 if (n == 0)
75 return 0;
76 if (*str1)
77 return 1;
78 if (*str2)
79 return -1;
80 return 0;
81#else
82 /* Recursion hazard warning! Whenever strncasecmp is #defined as
83 * OPENSSL_strncasecmp, OPENSSL_IMPLEMENTS_strncasecmp must be
84 * defined as well. */
85 return strncasecmp(str1, str2, n);
86#endif
87 }
88int OPENSSL_strcasecmp(const char *str1, const char *str2)
89 {
90#if defined(OPENSSL_IMPLEMENTS_strncasecmp)
91 return OPENSSL_strncasecmp(str1, str2, (size_t)-1);
92#else
93 return strcasecmp(str1, str2);
94#endif
95 }
96
diff --git a/src/lib/libcrypto/sha/asm/sha1-ia64.pl b/src/lib/libcrypto/sha/asm/sha1-ia64.pl
new file mode 100644
index 0000000000..cb9dfad124
--- /dev/null
+++ b/src/lib/libcrypto/sha/asm/sha1-ia64.pl
@@ -0,0 +1,549 @@
1#!/usr/bin/env perl
2#
3# ====================================================================
4# Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
5# project. Rights for redistribution and usage in source and binary
6# forms are granted according to the OpenSSL license.
7# ====================================================================
8#
9# Eternal question is what's wrong with compiler generated code? The
10# trick is that it's possible to reduce the number of shifts required
11# to perform rotations by maintaining copy of 32-bit value in upper
12# bits of 64-bit register. Just follow mux2 and shrp instructions...
13# Performance under big-endian OS such as HP-UX is 179MBps*1GHz, which
14# is >50% better than HP C and >2x better than gcc. As of this moment
15# performance under little-endian OS such as Linux and Windows will be
16# a bit lower, because data has to be picked in reverse byte-order.
17# It's possible to resolve this issue by implementing third function,
18# sha1_block_asm_data_order_aligned, which would temporarily flip
19# BE field in User Mask register...
20
21$code=<<___;
22.ident \"sha1-ia64.s, version 1.0\"
23.ident \"IA-64 ISA artwork by Andy Polyakov <appro\@fy.chalmers.se>\"
24.explicit
25
26___
27
28
29if ($^O eq "hpux") {
30 $ADDP="addp4";
31 for (@ARGV) { $ADDP="add" if (/[\+DD|\-mlp]64/); }
32} else { $ADDP="add"; }
33for (@ARGV) { $big_endian=1 if (/\-DB_ENDIAN/);
34 $big_endian=0 if (/\-DL_ENDIAN/); }
35if (!defined($big_endian))
36 { $big_endian=(unpack('L',pack('N',1))==1); }
37
38#$human=1;
39if ($human) { # useful for visual code auditing...
40 ($A,$B,$C,$D,$E,$T) = ("A","B","C","D","E","T");
41 ($h0,$h1,$h2,$h3,$h4) = ("h0","h1","h2","h3","h4");
42 ($K_00_19, $K_20_39, $K_40_59, $K_60_79) =
43 ( "K_00_19","K_20_39","K_40_59","K_60_79" );
44 @X= ( "X0", "X1", "X2", "X3", "X4", "X5", "X6", "X7",
45 "X8", "X9","X10","X11","X12","X13","X14","X15" );
46}
47else {
48 ($A,$B,$C,$D,$E,$T) = ("loc0","loc1","loc2","loc3","loc4","loc5");
49 ($h0,$h1,$h2,$h3,$h4) = ("loc6","loc7","loc8","loc9","loc10");
50 ($K_00_19, $K_20_39, $K_40_59, $K_60_79) =
51 ( "r14", "r15", "loc11", "loc12" );
52 @X= ( "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
53 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31" );
54}
55
56sub BODY_00_15 {
57local *code=shift;
58local ($i,$a,$b,$c,$d,$e,$f,$unaligned)=@_;
59
60if ($unaligned) {
61 $code.=<<___;
62{ .mmi; ld1 tmp0=[inp],2 // MSB
63 ld1 tmp1=[tmp3],2 };;
64{ .mmi; ld1 tmp2=[inp],2
65 ld1 $X[$i&0xf]=[tmp3],2 // LSB
66 dep tmp1=tmp0,tmp1,8,8 };;
67{ .mii; cmp.ne p16,p0=r0,r0 // no misaligned prefetch
68 dep $X[$i&0xf]=tmp2,$X[$i&0xf],8,8;;
69 dep $X[$i&0xf]=tmp1,$X[$i&0xf],16,16 };;
70{ .mmi; nop.m 0
71___
72 }
73elsif ($i<15) {
74 $code.=<<___;
75{ .mmi; ld4 $X[($i+1)&0xf]=[inp],4 // prefetch
76___
77 }
78else {
79 $code.=<<___;
80{ .mmi; nop.m 0
81___
82 }
83if ($i<15) {
84 $code.=<<___;
85 and tmp0=$c,$b
86 dep.z tmp5=$a,5,27 } // a<<5
87{ .mmi; andcm tmp1=$d,$b
88 add tmp4=$e,$K_00_19 };;
89{ .mmi; or tmp0=tmp0,tmp1 // F_00_19(b,c,d)=(b&c)|(~b&d)
90 add $f=tmp4,$X[$i&0xf] // f=xi+e+K_00_19
91 extr.u tmp1=$a,27,5 };; // a>>27
92{ .mib; add $f=$f,tmp0 // f+=F_00_19(b,c,d)
93 shrp $b=tmp6,tmp6,2 } // b=ROTATE(b,30)
94{ .mib; or tmp1=tmp1,tmp5 // ROTATE(a,5)
95 mux2 tmp6=$a,0x44 };; // see b in next iteration
96{ .mii; add $f=$f,tmp1 // f+=ROTATE(a,5)
97 mux2 $X[$i&0xf]=$X[$i&0xf],0x44
98 nop.i 0 };;
99
100___
101 }
102else {
103 $code.=<<___;
104 and tmp0=$c,$b
105 dep.z tmp5=$a,5,27 } // a<<5 ;;?
106{ .mmi; andcm tmp1=$d,$b
107 add tmp4=$e,$K_00_19 };;
108{ .mmi; or tmp0=tmp0,tmp1 // F_00_19(b,c,d)=(b&c)|(~b&d)
109 add $f=tmp4,$X[$i&0xf] // f=xi+e+K_00_19
110 extr.u tmp1=$a,27,5 } // a>>27
111{ .mmi; xor tmp2=$X[($i+0+1)&0xf],$X[($i+2+1)&0xf] // +1
112 xor tmp3=$X[($i+8+1)&0xf],$X[($i+13+1)&0xf] // +1
113 nop.i 0 };;
114{ .mmi; add $f=$f,tmp0 // f+=F_00_19(b,c,d)
115 xor tmp2=tmp2,tmp3 // +1
116 shrp $b=tmp6,tmp6,2 } // b=ROTATE(b,30)
117{ .mmi; or tmp1=tmp1,tmp5 // ROTATE(a,5)
118 mux2 tmp6=$a,0x44 };; // see b in next iteration
119{ .mii; add $f=$f,tmp1 // f+=ROTATE(a,5)
120 shrp $e=tmp2,tmp2,31 // f+1=ROTATE(x[0]^x[2]^x[8]^x[13],1)
121 mux2 $X[$i&0xf]=$X[$i&0xf],0x44 };;
122
123___
124 }
125}
126
127sub BODY_16_19 {
128local *code=shift;
129local ($i,$a,$b,$c,$d,$e,$f)=@_;
130
131$code.=<<___;
132{ .mmi; mov $X[$i&0xf]=$f // Xupdate
133 and tmp0=$c,$b
134 dep.z tmp5=$a,5,27 } // a<<5
135{ .mmi; andcm tmp1=$d,$b
136 add tmp4=$e,$K_00_19 };;
137{ .mmi; or tmp0=tmp0,tmp1 // F_00_19(b,c,d)=(b&c)|(~b&d)
138 add $f=$f,tmp4 // f+=e+K_00_19
139 extr.u tmp1=$a,27,5 } // a>>27
140{ .mmi; xor tmp2=$X[($i+0+1)&0xf],$X[($i+2+1)&0xf] // +1
141 xor tmp3=$X[($i+8+1)&0xf],$X[($i+13+1)&0xf] // +1
142 nop.i 0 };;
143{ .mmi; add $f=$f,tmp0 // f+=F_00_19(b,c,d)
144 xor tmp2=tmp2,tmp3 // +1
145 shrp $b=tmp6,tmp6,2 } // b=ROTATE(b,30)
146{ .mmi; or tmp1=tmp1,tmp5 // ROTATE(a,5)
147 mux2 tmp6=$a,0x44 };; // see b in next iteration
148{ .mii; add $f=$f,tmp1 // f+=ROTATE(a,5)
149 shrp $e=tmp2,tmp2,31 // f+1=ROTATE(x[0]^x[2]^x[8]^x[13],1)
150 nop.i 0 };;
151
152___
153}
154
155sub BODY_20_39 {
156local *code=shift;
157local ($i,$a,$b,$c,$d,$e,$f,$Konst)=@_;
158 $Konst = $K_20_39 if (!defined($Konst));
159
160if ($i<79) {
161$code.=<<___;
162{ .mib; mov $X[$i&0xf]=$f // Xupdate
163 dep.z tmp5=$a,5,27 } // a<<5
164{ .mib; xor tmp0=$c,$b
165 add tmp4=$e,$Konst };;
166{ .mmi; xor tmp0=tmp0,$d // F_20_39(b,c,d)=b^c^d
167 add $f=$f,tmp4 // f+=e+K_20_39
168 extr.u tmp1=$a,27,5 } // a>>27
169{ .mmi; xor tmp2=$X[($i+0+1)&0xf],$X[($i+2+1)&0xf] // +1
170 xor tmp3=$X[($i+8+1)&0xf],$X[($i+13+1)&0xf] // +1
171 nop.i 0 };;
172{ .mmi; add $f=$f,tmp0 // f+=F_20_39(b,c,d)
173 xor tmp2=tmp2,tmp3 // +1
174 shrp $b=tmp6,tmp6,2 } // b=ROTATE(b,30)
175{ .mmi; or tmp1=tmp1,tmp5 // ROTATE(a,5)
176 mux2 tmp6=$a,0x44 };; // see b in next iteration
177{ .mii; add $f=$f,tmp1 // f+=ROTATE(a,5)
178 shrp $e=tmp2,tmp2,31 // f+1=ROTATE(x[0]^x[2]^x[8]^x[13],1)
179 nop.i 0 };;
180
181___
182}
183else {
184$code.=<<___;
185{ .mib; mov $X[$i&0xf]=$f // Xupdate
186 dep.z tmp5=$a,5,27 } // a<<5
187{ .mib; xor tmp0=$c,$b
188 add tmp4=$e,$Konst };;
189{ .mib; xor tmp0=tmp0,$d // F_20_39(b,c,d)=b^c^d
190 extr.u tmp1=$a,27,5 } // a>>27
191{ .mib; add $f=$f,tmp4 // f+=e+K_20_39
192 add $h1=$h1,$a };; // wrap up
193{ .mmi;
194(p16) ld4.s $X[0]=[inp],4 // non-faulting prefetch
195 add $f=$f,tmp0 // f+=F_20_39(b,c,d)
196 shrp $b=tmp6,tmp6,2 } // b=ROTATE(b,30) ;;?
197{ .mmi; or tmp1=tmp1,tmp5 // ROTATE(a,5)
198 add $h3=$h3,$c };; // wrap up
199{ .mib; add tmp3=1,inp // used in unaligned codepath
200 add $f=$f,tmp1 } // f+=ROTATE(a,5)
201{ .mib; add $h2=$h2,$b // wrap up
202 add $h4=$h4,$d };; // wrap up
203
204___
205}
206}
207
208sub BODY_40_59 {
209local *code=shift;
210local ($i,$a,$b,$c,$d,$e,$f)=@_;
211
212$code.=<<___;
213{ .mmi; mov $X[$i&0xf]=$f // Xupdate
214 and tmp0=$c,$b
215 dep.z tmp5=$a,5,27 } // a<<5
216{ .mmi; and tmp1=$d,$b
217 add tmp4=$e,$K_40_59 };;
218{ .mmi; or tmp0=tmp0,tmp1 // (b&c)|(b&d)
219 add $f=$f,tmp4 // f+=e+K_40_59
220 extr.u tmp1=$a,27,5 } // a>>27
221{ .mmi; and tmp4=$c,$d
222 xor tmp2=$X[($i+0+1)&0xf],$X[($i+2+1)&0xf] // +1
223 xor tmp3=$X[($i+8+1)&0xf],$X[($i+13+1)&0xf] // +1
224 };;
225{ .mmi; or tmp1=tmp1,tmp5 // ROTATE(a,5)
226 xor tmp2=tmp2,tmp3 // +1
227 shrp $b=tmp6,tmp6,2 } // b=ROTATE(b,30)
228{ .mmi; or tmp0=tmp0,tmp4 // F_40_59(b,c,d)=(b&c)|(b&d)|(c&d)
229 mux2 tmp6=$a,0x44 };; // see b in next iteration
230{ .mii; add $f=$f,tmp0 // f+=F_40_59(b,c,d)
231 shrp $e=tmp2,tmp2,31;; // f+1=ROTATE(x[0]^x[2]^x[8]^x[13],1)
232 add $f=$f,tmp1 };; // f+=ROTATE(a,5)
233
234___
235}
236sub BODY_60_79 { &BODY_20_39(@_,$K_60_79); }
237
238$code.=<<___;
239.text
240
241tmp0=r8;
242tmp1=r9;
243tmp2=r10;
244tmp3=r11;
245ctx=r32; // in0
246inp=r33; // in1
247
248// void sha1_block_asm_host_order(SHA_CTX *c,const void *p,size_t num);
249.global sha1_block_asm_host_order#
250.proc sha1_block_asm_host_order#
251.align 32
252sha1_block_asm_host_order:
253 .prologue
254 .fframe 0
255 .save ar.pfs,r0
256 .save ar.lc,r3
257{ .mmi; alloc tmp1=ar.pfs,3,15,0,0
258 $ADDP tmp0=4,ctx
259 mov r3=ar.lc }
260{ .mmi; $ADDP ctx=0,ctx
261 $ADDP inp=0,inp
262 mov r2=pr };;
263tmp4=in2;
264tmp5=loc13;
265tmp6=loc14;
266 .body
267{ .mlx; ld4 $h0=[ctx],8
268 movl $K_00_19=0x5a827999 }
269{ .mlx; ld4 $h1=[tmp0],8
270 movl $K_20_39=0x6ed9eba1 };;
271{ .mlx; ld4 $h2=[ctx],8
272 movl $K_40_59=0x8f1bbcdc }
273{ .mlx; ld4 $h3=[tmp0]
274 movl $K_60_79=0xca62c1d6 };;
275{ .mmi; ld4 $h4=[ctx],-16
276 add in2=-1,in2 // adjust num for ar.lc
277 mov ar.ec=1 };;
278{ .mmi; ld4 $X[0]=[inp],4 // prefetch
279 cmp.ne p16,p0=r0,in2 // prefecth at loop end
280 mov ar.lc=in2 };; // brp.loop.imp: too far
281
282.Lhtop:
283{ .mmi; mov $A=$h0
284 mov $B=$h1
285 mux2 tmp6=$h1,0x44 }
286{ .mmi; mov $C=$h2
287 mov $D=$h3
288 mov $E=$h4 };;
289
290___
291
292 &BODY_00_15(\$code, 0,$A,$B,$C,$D,$E,$T);
293 &BODY_00_15(\$code, 1,$T,$A,$B,$C,$D,$E);
294 &BODY_00_15(\$code, 2,$E,$T,$A,$B,$C,$D);
295 &BODY_00_15(\$code, 3,$D,$E,$T,$A,$B,$C);
296 &BODY_00_15(\$code, 4,$C,$D,$E,$T,$A,$B);
297 &BODY_00_15(\$code, 5,$B,$C,$D,$E,$T,$A);
298 &BODY_00_15(\$code, 6,$A,$B,$C,$D,$E,$T);
299 &BODY_00_15(\$code, 7,$T,$A,$B,$C,$D,$E);
300 &BODY_00_15(\$code, 8,$E,$T,$A,$B,$C,$D);
301 &BODY_00_15(\$code, 9,$D,$E,$T,$A,$B,$C);
302 &BODY_00_15(\$code,10,$C,$D,$E,$T,$A,$B);
303 &BODY_00_15(\$code,11,$B,$C,$D,$E,$T,$A);
304 &BODY_00_15(\$code,12,$A,$B,$C,$D,$E,$T);
305 &BODY_00_15(\$code,13,$T,$A,$B,$C,$D,$E);
306 &BODY_00_15(\$code,14,$E,$T,$A,$B,$C,$D);
307 &BODY_00_15(\$code,15,$D,$E,$T,$A,$B,$C);
308
309 &BODY_16_19(\$code,16,$C,$D,$E,$T,$A,$B);
310 &BODY_16_19(\$code,17,$B,$C,$D,$E,$T,$A);
311 &BODY_16_19(\$code,18,$A,$B,$C,$D,$E,$T);
312 &BODY_16_19(\$code,19,$T,$A,$B,$C,$D,$E);
313
314 &BODY_20_39(\$code,20,$E,$T,$A,$B,$C,$D);
315 &BODY_20_39(\$code,21,$D,$E,$T,$A,$B,$C);
316 &BODY_20_39(\$code,22,$C,$D,$E,$T,$A,$B);
317 &BODY_20_39(\$code,23,$B,$C,$D,$E,$T,$A);
318 &BODY_20_39(\$code,24,$A,$B,$C,$D,$E,$T);
319 &BODY_20_39(\$code,25,$T,$A,$B,$C,$D,$E);
320 &BODY_20_39(\$code,26,$E,$T,$A,$B,$C,$D);
321 &BODY_20_39(\$code,27,$D,$E,$T,$A,$B,$C);
322 &BODY_20_39(\$code,28,$C,$D,$E,$T,$A,$B);
323 &BODY_20_39(\$code,29,$B,$C,$D,$E,$T,$A);
324 &BODY_20_39(\$code,30,$A,$B,$C,$D,$E,$T);
325 &BODY_20_39(\$code,31,$T,$A,$B,$C,$D,$E);
326 &BODY_20_39(\$code,32,$E,$T,$A,$B,$C,$D);
327 &BODY_20_39(\$code,33,$D,$E,$T,$A,$B,$C);
328 &BODY_20_39(\$code,34,$C,$D,$E,$T,$A,$B);
329 &BODY_20_39(\$code,35,$B,$C,$D,$E,$T,$A);
330 &BODY_20_39(\$code,36,$A,$B,$C,$D,$E,$T);
331 &BODY_20_39(\$code,37,$T,$A,$B,$C,$D,$E);
332 &BODY_20_39(\$code,38,$E,$T,$A,$B,$C,$D);
333 &BODY_20_39(\$code,39,$D,$E,$T,$A,$B,$C);
334
335 &BODY_40_59(\$code,40,$C,$D,$E,$T,$A,$B);
336 &BODY_40_59(\$code,41,$B,$C,$D,$E,$T,$A);
337 &BODY_40_59(\$code,42,$A,$B,$C,$D,$E,$T);
338 &BODY_40_59(\$code,43,$T,$A,$B,$C,$D,$E);
339 &BODY_40_59(\$code,44,$E,$T,$A,$B,$C,$D);
340 &BODY_40_59(\$code,45,$D,$E,$T,$A,$B,$C);
341 &BODY_40_59(\$code,46,$C,$D,$E,$T,$A,$B);
342 &BODY_40_59(\$code,47,$B,$C,$D,$E,$T,$A);
343 &BODY_40_59(\$code,48,$A,$B,$C,$D,$E,$T);
344 &BODY_40_59(\$code,49,$T,$A,$B,$C,$D,$E);
345 &BODY_40_59(\$code,50,$E,$T,$A,$B,$C,$D);
346 &BODY_40_59(\$code,51,$D,$E,$T,$A,$B,$C);
347 &BODY_40_59(\$code,52,$C,$D,$E,$T,$A,$B);
348 &BODY_40_59(\$code,53,$B,$C,$D,$E,$T,$A);
349 &BODY_40_59(\$code,54,$A,$B,$C,$D,$E,$T);
350 &BODY_40_59(\$code,55,$T,$A,$B,$C,$D,$E);
351 &BODY_40_59(\$code,56,$E,$T,$A,$B,$C,$D);
352 &BODY_40_59(\$code,57,$D,$E,$T,$A,$B,$C);
353 &BODY_40_59(\$code,58,$C,$D,$E,$T,$A,$B);
354 &BODY_40_59(\$code,59,$B,$C,$D,$E,$T,$A);
355
356 &BODY_60_79(\$code,60,$A,$B,$C,$D,$E,$T);
357 &BODY_60_79(\$code,61,$T,$A,$B,$C,$D,$E);
358 &BODY_60_79(\$code,62,$E,$T,$A,$B,$C,$D);
359 &BODY_60_79(\$code,63,$D,$E,$T,$A,$B,$C);
360 &BODY_60_79(\$code,64,$C,$D,$E,$T,$A,$B);
361 &BODY_60_79(\$code,65,$B,$C,$D,$E,$T,$A);
362 &BODY_60_79(\$code,66,$A,$B,$C,$D,$E,$T);
363 &BODY_60_79(\$code,67,$T,$A,$B,$C,$D,$E);
364 &BODY_60_79(\$code,68,$E,$T,$A,$B,$C,$D);
365 &BODY_60_79(\$code,69,$D,$E,$T,$A,$B,$C);
366 &BODY_60_79(\$code,70,$C,$D,$E,$T,$A,$B);
367 &BODY_60_79(\$code,71,$B,$C,$D,$E,$T,$A);
368 &BODY_60_79(\$code,72,$A,$B,$C,$D,$E,$T);
369 &BODY_60_79(\$code,73,$T,$A,$B,$C,$D,$E);
370 &BODY_60_79(\$code,74,$E,$T,$A,$B,$C,$D);
371 &BODY_60_79(\$code,75,$D,$E,$T,$A,$B,$C);
372 &BODY_60_79(\$code,76,$C,$D,$E,$T,$A,$B);
373 &BODY_60_79(\$code,77,$B,$C,$D,$E,$T,$A);
374 &BODY_60_79(\$code,78,$A,$B,$C,$D,$E,$T);
375 &BODY_60_79(\$code,79,$T,$A,$B,$C,$D,$E);
376
377$code.=<<___;
378{ .mmb; add $h0=$h0,$E
379 nop.m 0
380 br.ctop.dptk.many .Lhtop };;
381.Lhend:
382{ .mmi; add tmp0=4,ctx
383 mov ar.lc=r3 };;
384{ .mmi; st4 [ctx]=$h0,8
385 st4 [tmp0]=$h1,8 };;
386{ .mmi; st4 [ctx]=$h2,8
387 st4 [tmp0]=$h3 };;
388{ .mib; st4 [ctx]=$h4,-16
389 mov pr=r2,0x1ffff
390 br.ret.sptk.many b0 };;
391.endp sha1_block_asm_host_order#
392___
393
394
395$code.=<<___;
396// void sha1_block_asm_data_order(SHA_CTX *c,const void *p,size_t num);
397.global sha1_block_asm_data_order#
398.proc sha1_block_asm_data_order#
399.align 32
400sha1_block_asm_data_order:
401___
402$code.=<<___ if ($big_endian);
403{ .mmi; and r2=3,inp };;
404{ .mib; cmp.eq p6,p0=r0,r2
405(p6) br.dptk.many sha1_block_asm_host_order };;
406___
407$code.=<<___;
408 .prologue
409 .fframe 0
410 .save ar.pfs,r0
411 .save ar.lc,r3
412{ .mmi; alloc tmp1=ar.pfs,3,15,0,0
413 $ADDP tmp0=4,ctx
414 mov r3=ar.lc }
415{ .mmi; $ADDP ctx=0,ctx
416 $ADDP inp=0,inp
417 mov r2=pr };;
418tmp4=in2;
419tmp5=loc13;
420tmp6=loc14;
421 .body
422{ .mlx; ld4 $h0=[ctx],8
423 movl $K_00_19=0x5a827999 }
424{ .mlx; ld4 $h1=[tmp0],8
425 movl $K_20_39=0x6ed9eba1 };;
426{ .mlx; ld4 $h2=[ctx],8
427 movl $K_40_59=0x8f1bbcdc }
428{ .mlx; ld4 $h3=[tmp0]
429 movl $K_60_79=0xca62c1d6 };;
430{ .mmi; ld4 $h4=[ctx],-16
431 add in2=-1,in2 // adjust num for ar.lc
432 mov ar.ec=1 };;
433{ .mmi; nop.m 0
434 add tmp3=1,inp
435 mov ar.lc=in2 };; // brp.loop.imp: too far
436
437.Ldtop:
438{ .mmi; mov $A=$h0
439 mov $B=$h1
440 mux2 tmp6=$h1,0x44 }
441{ .mmi; mov $C=$h2
442 mov $D=$h3
443 mov $E=$h4 };;
444
445___
446
447 &BODY_00_15(\$code, 0,$A,$B,$C,$D,$E,$T,1);
448 &BODY_00_15(\$code, 1,$T,$A,$B,$C,$D,$E,1);
449 &BODY_00_15(\$code, 2,$E,$T,$A,$B,$C,$D,1);
450 &BODY_00_15(\$code, 3,$D,$E,$T,$A,$B,$C,1);
451 &BODY_00_15(\$code, 4,$C,$D,$E,$T,$A,$B,1);
452 &BODY_00_15(\$code, 5,$B,$C,$D,$E,$T,$A,1);
453 &BODY_00_15(\$code, 6,$A,$B,$C,$D,$E,$T,1);
454 &BODY_00_15(\$code, 7,$T,$A,$B,$C,$D,$E,1);
455 &BODY_00_15(\$code, 8,$E,$T,$A,$B,$C,$D,1);
456 &BODY_00_15(\$code, 9,$D,$E,$T,$A,$B,$C,1);
457 &BODY_00_15(\$code,10,$C,$D,$E,$T,$A,$B,1);
458 &BODY_00_15(\$code,11,$B,$C,$D,$E,$T,$A,1);
459 &BODY_00_15(\$code,12,$A,$B,$C,$D,$E,$T,1);
460 &BODY_00_15(\$code,13,$T,$A,$B,$C,$D,$E,1);
461 &BODY_00_15(\$code,14,$E,$T,$A,$B,$C,$D,1);
462 &BODY_00_15(\$code,15,$D,$E,$T,$A,$B,$C,1);
463
464 &BODY_16_19(\$code,16,$C,$D,$E,$T,$A,$B);
465 &BODY_16_19(\$code,17,$B,$C,$D,$E,$T,$A);
466 &BODY_16_19(\$code,18,$A,$B,$C,$D,$E,$T);
467 &BODY_16_19(\$code,19,$T,$A,$B,$C,$D,$E);
468
469 &BODY_20_39(\$code,20,$E,$T,$A,$B,$C,$D);
470 &BODY_20_39(\$code,21,$D,$E,$T,$A,$B,$C);
471 &BODY_20_39(\$code,22,$C,$D,$E,$T,$A,$B);
472 &BODY_20_39(\$code,23,$B,$C,$D,$E,$T,$A);
473 &BODY_20_39(\$code,24,$A,$B,$C,$D,$E,$T);
474 &BODY_20_39(\$code,25,$T,$A,$B,$C,$D,$E);
475 &BODY_20_39(\$code,26,$E,$T,$A,$B,$C,$D);
476 &BODY_20_39(\$code,27,$D,$E,$T,$A,$B,$C);
477 &BODY_20_39(\$code,28,$C,$D,$E,$T,$A,$B);
478 &BODY_20_39(\$code,29,$B,$C,$D,$E,$T,$A);
479 &BODY_20_39(\$code,30,$A,$B,$C,$D,$E,$T);
480 &BODY_20_39(\$code,31,$T,$A,$B,$C,$D,$E);
481 &BODY_20_39(\$code,32,$E,$T,$A,$B,$C,$D);
482 &BODY_20_39(\$code,33,$D,$E,$T,$A,$B,$C);
483 &BODY_20_39(\$code,34,$C,$D,$E,$T,$A,$B);
484 &BODY_20_39(\$code,35,$B,$C,$D,$E,$T,$A);
485 &BODY_20_39(\$code,36,$A,$B,$C,$D,$E,$T);
486 &BODY_20_39(\$code,37,$T,$A,$B,$C,$D,$E);
487 &BODY_20_39(\$code,38,$E,$T,$A,$B,$C,$D);
488 &BODY_20_39(\$code,39,$D,$E,$T,$A,$B,$C);
489
490 &BODY_40_59(\$code,40,$C,$D,$E,$T,$A,$B);
491 &BODY_40_59(\$code,41,$B,$C,$D,$E,$T,$A);
492 &BODY_40_59(\$code,42,$A,$B,$C,$D,$E,$T);
493 &BODY_40_59(\$code,43,$T,$A,$B,$C,$D,$E);
494 &BODY_40_59(\$code,44,$E,$T,$A,$B,$C,$D);
495 &BODY_40_59(\$code,45,$D,$E,$T,$A,$B,$C);
496 &BODY_40_59(\$code,46,$C,$D,$E,$T,$A,$B);
497 &BODY_40_59(\$code,47,$B,$C,$D,$E,$T,$A);
498 &BODY_40_59(\$code,48,$A,$B,$C,$D,$E,$T);
499 &BODY_40_59(\$code,49,$T,$A,$B,$C,$D,$E);
500 &BODY_40_59(\$code,50,$E,$T,$A,$B,$C,$D);
501 &BODY_40_59(\$code,51,$D,$E,$T,$A,$B,$C);
502 &BODY_40_59(\$code,52,$C,$D,$E,$T,$A,$B);
503 &BODY_40_59(\$code,53,$B,$C,$D,$E,$T,$A);
504 &BODY_40_59(\$code,54,$A,$B,$C,$D,$E,$T);
505 &BODY_40_59(\$code,55,$T,$A,$B,$C,$D,$E);
506 &BODY_40_59(\$code,56,$E,$T,$A,$B,$C,$D);
507 &BODY_40_59(\$code,57,$D,$E,$T,$A,$B,$C);
508 &BODY_40_59(\$code,58,$C,$D,$E,$T,$A,$B);
509 &BODY_40_59(\$code,59,$B,$C,$D,$E,$T,$A);
510
511 &BODY_60_79(\$code,60,$A,$B,$C,$D,$E,$T);
512 &BODY_60_79(\$code,61,$T,$A,$B,$C,$D,$E);
513 &BODY_60_79(\$code,62,$E,$T,$A,$B,$C,$D);
514 &BODY_60_79(\$code,63,$D,$E,$T,$A,$B,$C);
515 &BODY_60_79(\$code,64,$C,$D,$E,$T,$A,$B);
516 &BODY_60_79(\$code,65,$B,$C,$D,$E,$T,$A);
517 &BODY_60_79(\$code,66,$A,$B,$C,$D,$E,$T);
518 &BODY_60_79(\$code,67,$T,$A,$B,$C,$D,$E);
519 &BODY_60_79(\$code,68,$E,$T,$A,$B,$C,$D);
520 &BODY_60_79(\$code,69,$D,$E,$T,$A,$B,$C);
521 &BODY_60_79(\$code,70,$C,$D,$E,$T,$A,$B);
522 &BODY_60_79(\$code,71,$B,$C,$D,$E,$T,$A);
523 &BODY_60_79(\$code,72,$A,$B,$C,$D,$E,$T);
524 &BODY_60_79(\$code,73,$T,$A,$B,$C,$D,$E);
525 &BODY_60_79(\$code,74,$E,$T,$A,$B,$C,$D);
526 &BODY_60_79(\$code,75,$D,$E,$T,$A,$B,$C);
527 &BODY_60_79(\$code,76,$C,$D,$E,$T,$A,$B);
528 &BODY_60_79(\$code,77,$B,$C,$D,$E,$T,$A);
529 &BODY_60_79(\$code,78,$A,$B,$C,$D,$E,$T);
530 &BODY_60_79(\$code,79,$T,$A,$B,$C,$D,$E);
531
532$code.=<<___;
533{ .mmb; add $h0=$h0,$E
534 nop.m 0
535 br.ctop.dptk.many .Ldtop };;
536.Ldend:
537{ .mmi; add tmp0=4,ctx
538 mov ar.lc=r3 };;
539{ .mmi; st4 [ctx]=$h0,8
540 st4 [tmp0]=$h1,8 };;
541{ .mmi; st4 [ctx]=$h2,8
542 st4 [tmp0]=$h3 };;
543{ .mib; st4 [ctx]=$h4,-16
544 mov pr=r2,0x1ffff
545 br.ret.sptk.many b0 };;
546.endp sha1_block_asm_data_order#
547___
548
549print $code;
diff --git a/src/lib/libcrypto/x509v3/v3_pci.c b/src/lib/libcrypto/x509v3/v3_pci.c
new file mode 100644
index 0000000000..b32d968619
--- /dev/null
+++ b/src/lib/libcrypto/x509v3/v3_pci.c
@@ -0,0 +1,313 @@
1/* v3_pci.c -*- mode:C; c-file-style: "eay" -*- */
2/* Contributed to the OpenSSL Project 2004
3 * by Richard Levitte (richard@levitte.org)
4 */
5/* Copyright (c) 2004 Kungliga Tekniska Högskolan
6 * (Royal Institute of Technology, Stockholm, Sweden).
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 *
20 * 3. Neither the name of the Institute nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 */
36
37#include <stdio.h>
38#include "cryptlib.h"
39#include <openssl/conf.h>
40#include <openssl/x509v3.h>
41
42static int i2r_pci(X509V3_EXT_METHOD *method, PROXY_CERT_INFO_EXTENSION *ext,
43 BIO *out, int indent);
44static PROXY_CERT_INFO_EXTENSION *r2i_pci(X509V3_EXT_METHOD *method,
45 X509V3_CTX *ctx, char *str);
46
47X509V3_EXT_METHOD v3_pci =
48 { NID_proxyCertInfo, 0, ASN1_ITEM_ref(PROXY_CERT_INFO_EXTENSION),
49 0,0,0,0,
50 0,0,
51 NULL, NULL,
52 (X509V3_EXT_I2R)i2r_pci,
53 (X509V3_EXT_R2I)r2i_pci,
54 NULL,
55 };
56
57static int i2r_pci(X509V3_EXT_METHOD *method, PROXY_CERT_INFO_EXTENSION *pci,
58 BIO *out, int indent)
59 {
60 BIO_printf(out, "%*sPath Length Constraint: ", indent, "");
61 if (pci->pcPathLengthConstraint)
62 i2a_ASN1_INTEGER(out, pci->pcPathLengthConstraint);
63 else
64 BIO_printf(out, "infinite");
65 BIO_puts(out, "\n");
66 BIO_printf(out, "%*sPolicy Language: ", indent, "");
67 i2a_ASN1_OBJECT(out, pci->proxyPolicy->policyLanguage);
68 BIO_puts(out, "\n");
69 if (pci->proxyPolicy->policy && pci->proxyPolicy->policy->data)
70 BIO_printf(out, "%*sPolicy Text: %s\n", indent, "",
71 pci->proxyPolicy->policy->data);
72 return 1;
73 }
74
75static int process_pci_value(CONF_VALUE *val,
76 ASN1_OBJECT **language, ASN1_INTEGER **pathlen,
77 ASN1_OCTET_STRING **policy)
78 {
79 int free_policy = 0;
80
81 if (strcmp(val->name, "language") == 0)
82 {
83 if (*language)
84 {
85 X509V3err(X509V3_F_R2I_PCI,X509V3_R_POLICY_LANGUAGE_ALREADTY_DEFINED);
86 X509V3_conf_err(val);
87 return 0;
88 }
89 if (!(*language = OBJ_txt2obj(val->value, 0)))
90 {
91 X509V3err(X509V3_F_R2I_PCI,X509V3_R_INVALID_OBJECT_IDENTIFIER);
92 X509V3_conf_err(val);
93 return 0;
94 }
95 }
96 else if (strcmp(val->name, "pathlen") == 0)
97 {
98 if (*pathlen)
99 {
100 X509V3err(X509V3_F_R2I_PCI,X509V3_R_POLICY_PATH_LENGTH_ALREADTY_DEFINED);
101 X509V3_conf_err(val);
102 return 0;
103 }
104 if (!X509V3_get_value_int(val, pathlen))
105 {
106 X509V3err(X509V3_F_R2I_PCI,X509V3_R_POLICY_PATH_LENGTH);
107 X509V3_conf_err(val);
108 return 0;
109 }
110 }
111 else if (strcmp(val->name, "policy") == 0)
112 {
113 unsigned char *tmp_data = NULL;
114 long val_len;
115 if (!*policy)
116 {
117 *policy = ASN1_OCTET_STRING_new();
118 if (!*policy)
119 {
120 X509V3err(X509V3_F_R2I_PCI,ERR_R_MALLOC_FAILURE);
121 X509V3_conf_err(val);
122 return 0;
123 }
124 free_policy = 1;
125 }
126 if (strncmp(val->value, "hex:", 4) == 0)
127 {
128 unsigned char *tmp_data2 =
129 string_to_hex(val->value + 4, &val_len);
130
131 if (!tmp_data2) goto err;
132
133 tmp_data = OPENSSL_realloc((*policy)->data,
134 (*policy)->length + val_len + 1);
135 if (tmp_data)
136 {
137 (*policy)->data = tmp_data;
138 memcpy(&(*policy)->data[(*policy)->length],
139 tmp_data2, val_len);
140 (*policy)->length += val_len;
141 (*policy)->data[(*policy)->length] = '\0';
142 }
143 }
144 else if (strncmp(val->value, "file:", 5) == 0)
145 {
146 unsigned char buf[2048];
147 int n;
148 BIO *b = BIO_new_file(val->value + 5, "r");
149 if (!b)
150 {
151 X509V3err(X509V3_F_R2I_PCI,ERR_R_BIO_LIB);
152 X509V3_conf_err(val);
153 goto err;
154 }
155 while((n = BIO_read(b, buf, sizeof(buf))) > 0
156 || (n == 0 && BIO_should_retry(b)))
157 {
158 if (!n) continue;
159
160 tmp_data = OPENSSL_realloc((*policy)->data,
161 (*policy)->length + n + 1);
162
163 if (!tmp_data)
164 break;
165
166 (*policy)->data = tmp_data;
167 memcpy(&(*policy)->data[(*policy)->length],
168 buf, n);
169 (*policy)->length += n;
170 (*policy)->data[(*policy)->length] = '\0';
171 }
172
173 if (n < 0)
174 {
175 X509V3err(X509V3_F_R2I_PCI,ERR_R_BIO_LIB);
176 X509V3_conf_err(val);
177 goto err;
178 }
179 }
180 else if (strncmp(val->value, "text:", 5) == 0)
181 {
182 val_len = strlen(val->value + 5);
183 tmp_data = OPENSSL_realloc((*policy)->data,
184 (*policy)->length + val_len + 1);
185 if (tmp_data)
186 {
187 (*policy)->data = tmp_data;
188 memcpy(&(*policy)->data[(*policy)->length],
189 val->value + 5, val_len);
190 (*policy)->length += val_len;
191 (*policy)->data[(*policy)->length] = '\0';
192 }
193 }
194 else
195 {
196 X509V3err(X509V3_F_R2I_PCI,X509V3_R_INCORRECT_POLICY_SYNTAX_TAG);
197 X509V3_conf_err(val);
198 goto err;
199 }
200 if (!tmp_data)
201 {
202 X509V3err(X509V3_F_R2I_PCI,ERR_R_MALLOC_FAILURE);
203 X509V3_conf_err(val);
204 goto err;
205 }
206 }
207 return 1;
208err:
209 if (free_policy)
210 {
211 ASN1_OCTET_STRING_free(*policy);
212 *policy = NULL;
213 }
214 return 0;
215 }
216
217static PROXY_CERT_INFO_EXTENSION *r2i_pci(X509V3_EXT_METHOD *method,
218 X509V3_CTX *ctx, char *value)
219 {
220 PROXY_CERT_INFO_EXTENSION *pci = NULL;
221 STACK_OF(CONF_VALUE) *vals;
222 ASN1_OBJECT *language = NULL;
223 ASN1_INTEGER *pathlen = NULL;
224 ASN1_OCTET_STRING *policy = NULL;
225 int i, j;
226
227 vals = X509V3_parse_list(value);
228 for (i = 0; i < sk_CONF_VALUE_num(vals); i++)
229 {
230 CONF_VALUE *cnf = sk_CONF_VALUE_value(vals, i);
231 if (!cnf->name || (*cnf->name != '@' && !cnf->value))
232 {
233 X509V3err(X509V3_F_R2I_PCI,X509V3_R_INVALID_PROXY_POLICY_SETTING);
234 X509V3_conf_err(cnf);
235 goto err;
236 }
237 if (*cnf->name == '@')
238 {
239 STACK_OF(CONF_VALUE) *sect;
240 int success_p = 1;
241
242 sect = X509V3_get_section(ctx, cnf->name + 1);
243 if (!sect)
244 {
245 X509V3err(X509V3_F_R2I_PCI,X509V3_R_INVALID_SECTION);
246 X509V3_conf_err(cnf);
247 goto err;
248 }
249 for (j = 0; success_p && j < sk_CONF_VALUE_num(sect); j++)
250 {
251 success_p =
252 process_pci_value(sk_CONF_VALUE_value(sect, j),
253 &language, &pathlen, &policy);
254 }
255 X509V3_section_free(ctx, sect);
256 if (!success_p)
257 goto err;
258 }
259 else
260 {
261 if (!process_pci_value(cnf,
262 &language, &pathlen, &policy))
263 {
264 X509V3_conf_err(cnf);
265 goto err;
266 }
267 }
268 }
269
270 /* Language is mandatory */
271 if (!language)
272 {
273 X509V3err(X509V3_F_R2I_PCI,X509V3_R_NO_PROXY_CERT_POLICY_LANGUAGE_DEFINED);
274 goto err;
275 }
276 i = OBJ_obj2nid(language);
277 if ((i == NID_Independent || i == NID_id_ppl_inheritAll) && policy)
278 {
279 X509V3err(X509V3_F_R2I_PCI,X509V3_R_POLICY_WHEN_PROXY_LANGUAGE_REQUIRES_NO_POLICY);
280 goto err;
281 }
282
283 pci = PROXY_CERT_INFO_EXTENSION_new();
284 if (!pci)
285 {
286 X509V3err(X509V3_F_R2I_PCI,ERR_R_MALLOC_FAILURE);
287 goto err;
288 }
289 pci->proxyPolicy = PROXY_POLICY_new();
290 if (!pci->proxyPolicy)
291 {
292 X509V3err(X509V3_F_R2I_PCI,ERR_R_MALLOC_FAILURE);
293 goto err;
294 }
295
296 pci->proxyPolicy->policyLanguage = language; language = NULL;
297 pci->proxyPolicy->policy = policy; policy = NULL;
298 pci->pcPathLengthConstraint = pathlen; pathlen = NULL;
299 goto end;
300err:
301 if (language) { ASN1_OBJECT_free(language); language = NULL; }
302 if (pathlen) { ASN1_INTEGER_free(pathlen); pathlen = NULL; }
303 if (policy) { ASN1_OCTET_STRING_free(policy); policy = NULL; }
304 if (pci && pci->proxyPolicy)
305 {
306 PROXY_POLICY_free(pci->proxyPolicy);
307 pci->proxyPolicy = NULL;
308 }
309 if (pci) { PROXY_CERT_INFO_EXTENSION_free(pci); pci = NULL; }
310end:
311 sk_CONF_VALUE_pop_free(vals, X509V3_conf_free);
312 return pci;
313 }
diff --git a/src/lib/libcrypto/x509v3/v3_pcia.c b/src/lib/libcrypto/x509v3/v3_pcia.c
new file mode 100644
index 0000000000..bb362e0e5a
--- /dev/null
+++ b/src/lib/libcrypto/x509v3/v3_pcia.c
@@ -0,0 +1,55 @@
1/* v3_pcia.c -*- mode:C; c-file-style: "eay" -*- */
2/* Contributed to the OpenSSL Project 2004
3 * by Richard Levitte (richard@levitte.org)
4 */
5/* Copyright (c) 2004 Kungliga Tekniska Högskolan
6 * (Royal Institute of Technology, Stockholm, Sweden).
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 *
20 * 3. Neither the name of the Institute nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 */
36
37#include <openssl/asn1.h>
38#include <openssl/asn1t.h>
39#include <openssl/x509v3.h>
40
41ASN1_SEQUENCE(PROXY_POLICY) =
42 {
43 ASN1_SIMPLE(PROXY_POLICY,policyLanguage,ASN1_OBJECT),
44 ASN1_OPT(PROXY_POLICY,policy,ASN1_OCTET_STRING)
45} ASN1_SEQUENCE_END(PROXY_POLICY)
46
47IMPLEMENT_ASN1_FUNCTIONS(PROXY_POLICY)
48
49ASN1_SEQUENCE(PROXY_CERT_INFO_EXTENSION) =
50 {
51 ASN1_OPT(PROXY_CERT_INFO_EXTENSION,pcPathLengthConstraint,ASN1_INTEGER),
52 ASN1_SIMPLE(PROXY_CERT_INFO_EXTENSION,proxyPolicy,PROXY_POLICY)
53} ASN1_SEQUENCE_END(PROXY_CERT_INFO_EXTENSION)
54
55IMPLEMENT_ASN1_FUNCTIONS(PROXY_CERT_INFO_EXTENSION)
diff --git a/src/lib/libssl/test/CAss.cnf b/src/lib/libssl/test/CAss.cnf
index b941b7ae15..21da59a73a 100644
--- a/src/lib/libssl/test/CAss.cnf
+++ b/src/lib/libssl/test/CAss.cnf
@@ -23,3 +23,11 @@ organizationName_value = Dodgy Brothers
23 23
24commonName = Common Name (eg, YOUR name) 24commonName = Common Name (eg, YOUR name)
25commonName_value = Dodgy CA 25commonName_value = Dodgy CA
26
27[ v3_ca ]
28subjectKeyIdentifier=hash
29authorityKeyIdentifier=keyid:always,issuer:always
30basicConstraints = CA:true,pathlen:1
31keyUsage = cRLSign, keyCertSign
32issuerAltName=issuer:copy
33
diff --git a/src/lib/libssl/test/P1ss.cnf b/src/lib/libssl/test/P1ss.cnf
new file mode 100644
index 0000000000..876a0d35f8
--- /dev/null
+++ b/src/lib/libssl/test/P1ss.cnf
@@ -0,0 +1,37 @@
1#
2# SSLeay example configuration file.
3# This is mostly being used for generation of certificate requests.
4#
5
6RANDFILE = ./.rnd
7
8####################################################################
9[ req ]
10default_bits = 512
11default_keyfile = keySS.pem
12distinguished_name = req_distinguished_name
13encrypt_rsa_key = no
14default_md = md2
15
16[ req_distinguished_name ]
17countryName = Country Name (2 letter code)
18countryName_default = AU
19countryName_value = AU
20
21organizationName = Organization Name (eg, company)
22organizationName_value = Dodgy Brothers
23
240.commonName = Common Name (eg, YOUR name)
250.commonName_value = Brother 1
26
271.commonName = Common Name (eg, YOUR name)
281.commonName_value = Brother 2
29
302.commonName = Common Name (eg, YOUR name)
312.commonName_value = Proxy 1
32
33[ v3_proxy ]
34basicConstraints=CA:FALSE
35subjectKeyIdentifier=hash
36authorityKeyIdentifier=keyid,issuer:always
37proxyCertInfo=critical,language:id-ppl-anyLanguage,pathlen:1,policy:text:AB
diff --git a/src/lib/libssl/test/P2ss.cnf b/src/lib/libssl/test/P2ss.cnf
new file mode 100644
index 0000000000..373a87e7c2
--- /dev/null
+++ b/src/lib/libssl/test/P2ss.cnf
@@ -0,0 +1,45 @@
1#
2# SSLeay example configuration file.
3# This is mostly being used for generation of certificate requests.
4#
5
6RANDFILE = ./.rnd
7
8####################################################################
9[ req ]
10default_bits = 512
11default_keyfile = keySS.pem
12distinguished_name = req_distinguished_name
13encrypt_rsa_key = no
14default_md = md2
15
16[ req_distinguished_name ]
17countryName = Country Name (2 letter code)
18countryName_default = AU
19countryName_value = AU
20
21organizationName = Organization Name (eg, company)
22organizationName_value = Dodgy Brothers
23
240.commonName = Common Name (eg, YOUR name)
250.commonName_value = Brother 1
26
271.commonName = Common Name (eg, YOUR name)
281.commonName_value = Brother 2
29
302.commonName = Common Name (eg, YOUR name)
312.commonName_value = Proxy 1
32
333.commonName = Common Name (eg, YOUR name)
343.commonName_value = Proxy 2
35
36[ v3_proxy ]
37basicConstraints=CA:FALSE
38subjectKeyIdentifier=hash
39authorityKeyIdentifier=keyid,issuer:always
40proxyCertInfo=critical,@proxy_ext
41
42[ proxy_ext ]
43language=id-ppl-anyLanguage
44pathlen=0
45policy=text:BC
diff --git a/src/lib/libssl/test/Uss.cnf b/src/lib/libssl/test/Uss.cnf
index c89692d519..0c0ebb5f67 100644
--- a/src/lib/libssl/test/Uss.cnf
+++ b/src/lib/libssl/test/Uss.cnf
@@ -26,3 +26,11 @@ organizationName_value = Dodgy Brothers
26 26
271.commonName = Common Name (eg, YOUR name) 271.commonName = Common Name (eg, YOUR name)
281.commonName_value = Brother 2 281.commonName_value = Brother 2
29
30[ v3_ee ]
31subjectKeyIdentifier=hash
32authorityKeyIdentifier=keyid,issuer:always
33basicConstraints = CA:false
34keyUsage = nonRepudiation, digitalSignature, keyEncipherment
35issuerAltName=issuer:copy
36
diff --git a/src/lib/libssl/test/testsslproxy b/src/lib/libssl/test/testsslproxy
new file mode 100644
index 0000000000..58bbda8ab7
--- /dev/null
+++ b/src/lib/libssl/test/testsslproxy
@@ -0,0 +1,10 @@
1#! /bin/sh
2
3echo 'Testing a lot of proxy conditions.'
4echo 'Some of them may turn out being invalid, which is fine.'
5for auth in A B C BC; do
6 for cond in A B C 'A|B&!C'; do
7 sh ./testssl $1 $2 $3 "-proxy -proxy_auth $auth -proxy_cond $cond"
8 if [ $? = 3 ]; then exit 1; fi
9 done
10done