summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto
diff options
context:
space:
mode:
authorcvs2svn <admin@example.com>2002-05-15 02:29:23 +0000
committercvs2svn <admin@example.com>2002-05-15 02:29:23 +0000
commitfd9566423b542798f5c8b06e68101a9ea5bb9885 (patch)
treef2cc037857a260afc5aaaaaa6cf62d06923c6273 /src/lib/libcrypto
parent536c76cbb863bab152f19842ab88772c01e922c7 (diff)
downloadopenbsd-fd9566423b542798f5c8b06e68101a9ea5bb9885.tar.gz
openbsd-fd9566423b542798f5c8b06e68101a9ea5bb9885.tar.bz2
openbsd-fd9566423b542798f5c8b06e68101a9ea5bb9885.zip
This commit was manufactured by cvs2git to create branch 'openssl'.
Diffstat (limited to 'src/lib/libcrypto')
-rw-r--r--src/lib/libcrypto/asn1/a_gentm.c224
-rw-r--r--src/lib/libcrypto/asn1/p8_key.c131
-rw-r--r--src/lib/libcrypto/bn/asm/alpha.s.works533
-rw-r--r--src/lib/libcrypto/bn/asm/alpha.works/add.pl119
-rw-r--r--src/lib/libcrypto/bn/asm/alpha.works/div.pl144
-rw-r--r--src/lib/libcrypto/bn/asm/alpha.works/mul.pl116
-rw-r--r--src/lib/libcrypto/bn/asm/alpha.works/mul_add.pl120
-rw-r--r--src/lib/libcrypto/bn/asm/alpha.works/mul_c4.pl213
-rw-r--r--src/lib/libcrypto/bn/asm/alpha.works/mul_c4.works.pl98
-rw-r--r--src/lib/libcrypto/bn/asm/alpha.works/mul_c8.pl177
-rw-r--r--src/lib/libcrypto/bn/asm/alpha.works/sqr.pl113
-rw-r--r--src/lib/libcrypto/bn/asm/alpha.works/sqr_c4.pl109
-rw-r--r--src/lib/libcrypto/bn/asm/alpha.works/sqr_c8.pl132
-rw-r--r--src/lib/libcrypto/bn/asm/alpha.works/sub.pl108
-rw-r--r--src/lib/libcrypto/bn/asm/alpha/add.pl118
-rw-r--r--src/lib/libcrypto/bn/asm/alpha/div.pl144
-rw-r--r--src/lib/libcrypto/bn/asm/alpha/mul.pl104
-rw-r--r--src/lib/libcrypto/bn/asm/alpha/mul_add.pl123
-rw-r--r--src/lib/libcrypto/bn/asm/alpha/mul_c4.pl215
-rw-r--r--src/lib/libcrypto/bn/asm/alpha/mul_c4.works.pl98
-rw-r--r--src/lib/libcrypto/bn/asm/alpha/mul_c8.pl177
-rw-r--r--src/lib/libcrypto/bn/asm/alpha/sqr.pl113
-rw-r--r--src/lib/libcrypto/bn/asm/alpha/sqr_c4.pl109
-rw-r--r--src/lib/libcrypto/bn/asm/alpha/sqr_c8.pl132
-rw-r--r--src/lib/libcrypto/bn/asm/alpha/sub.pl108
-rw-r--r--src/lib/libcrypto/bn/asm/bn-alpha.pl571
-rw-r--r--src/lib/libcrypto/bn/asm/ca.pl33
-rw-r--r--src/lib/libcrypto/bn/asm/co-alpha.pl116
-rw-r--r--src/lib/libcrypto/bn/asm/mips1.s539
-rw-r--r--src/lib/libcrypto/bn/asm/mips3.s2138
-rw-r--r--src/lib/libcrypto/bn/asm/vms.mar6695
-rw-r--r--src/lib/libcrypto/bn/asm/x86/f3
-rw-r--r--src/lib/libcrypto/bn/bn.mul19
-rw-r--r--src/lib/libcrypto/bn/divtest.c41
-rw-r--r--src/lib/libcrypto/bn/exp.c60
-rw-r--r--src/lib/libcrypto/bn/todo3
-rw-r--r--src/lib/libcrypto/bn/vms-helper.c66
-rw-r--r--src/lib/libcrypto/crypto-lib.com1218
-rw-r--r--src/lib/libcrypto/des/des-lib.com1003
-rw-r--r--src/lib/libcrypto/des/des.pod217
-rw-r--r--src/lib/libcrypto/des/des_old.c271
-rw-r--r--src/lib/libcrypto/des/des_old.h437
-rw-r--r--src/lib/libcrypto/des/des_old2.c82
-rw-r--r--src/lib/libcrypto/dso/README24
-rw-r--r--src/lib/libcrypto/dso/dso_dl.c251
-rw-r--r--src/lib/libcrypto/dso/dso_vms.c371
-rw-r--r--src/lib/libcrypto/dso/dso_win32.c273
-rw-r--r--src/lib/libcrypto/ebcdic.c217
-rw-r--r--src/lib/libcrypto/ebcdic.h17
-rw-r--r--src/lib/libcrypto/ec/ecp_recp.c133
-rw-r--r--src/lib/libcrypto/ec/ectest.c634
-rw-r--r--src/lib/libcrypto/engine/enginetest.c251
-rw-r--r--src/lib/libcrypto/engine/hw.ec8
-rw-r--r--src/lib/libcrypto/engine/hw_4758_cca.c950
-rw-r--r--src/lib/libcrypto/engine/hw_4758_cca_err.c149
-rw-r--r--src/lib/libcrypto/engine/hw_4758_cca_err.h93
-rw-r--r--src/lib/libcrypto/engine/hw_aep.c1101
-rw-r--r--src/lib/libcrypto/engine/hw_aep_err.c157
-rw-r--r--src/lib/libcrypto/engine/hw_aep_err.h101
-rw-r--r--src/lib/libcrypto/engine/hw_atalla.c444
-rw-r--r--src/lib/libcrypto/engine/hw_atalla_err.c145
-rw-r--r--src/lib/libcrypto/engine/hw_atalla_err.h89
-rw-r--r--src/lib/libcrypto/engine/hw_cryptodev.c926
-rw-r--r--src/lib/libcrypto/engine/hw_cswift.c807
-rw-r--r--src/lib/libcrypto/engine/hw_cswift_err.c149
-rw-r--r--src/lib/libcrypto/engine/hw_cswift_err.h93
-rw-r--r--src/lib/libcrypto/engine/hw_ncipher.c1019
-rw-r--r--src/lib/libcrypto/engine/hw_ncipher_err.c156
-rw-r--r--src/lib/libcrypto/engine/hw_ncipher_err.h100
-rw-r--r--src/lib/libcrypto/engine/hw_nuron.c399
-rw-r--r--src/lib/libcrypto/engine/hw_nuron_err.c142
-rw-r--r--src/lib/libcrypto/engine/hw_nuron_err.h86
-rw-r--r--src/lib/libcrypto/engine/hw_sureware_err.c150
-rw-r--r--src/lib/libcrypto/engine/hw_sureware_err.h94
-rw-r--r--src/lib/libcrypto/engine/hw_ubsec.c1041
-rw-r--r--src/lib/libcrypto/engine/hw_ubsec_err.c151
-rw-r--r--src/lib/libcrypto/engine/hw_ubsec_err.h95
-rw-r--r--src/lib/libcrypto/engine/vendor_defns/aep.h178
-rw-r--r--src/lib/libcrypto/engine/vendor_defns/atalla.h61
-rw-r--r--src/lib/libcrypto/engine/vendor_defns/cswift.h213
-rw-r--r--src/lib/libcrypto/engine/vendor_defns/hw_4758_cca.h149
-rw-r--r--src/lib/libcrypto/evp/bio_ok.c552
-rw-r--r--src/lib/libcrypto/evp/c_allc.c149
-rw-r--r--src/lib/libcrypto/evp/c_alld.c100
-rw-r--r--src/lib/libcrypto/evp/e_rc5.c118
-rw-r--r--src/lib/libcrypto/evp/evp_acnf.c74
-rw-r--r--src/lib/libcrypto/evp/evp_test.c365
-rw-r--r--src/lib/libcrypto/evp/evptests.txt82
-rw-r--r--src/lib/libcrypto/evp/openbsd_hw.c446
-rw-r--r--src/lib/libcrypto/install.com128
-rw-r--r--src/lib/libcrypto/md2/md2.h91
-rw-r--r--src/lib/libcrypto/md4/md4.c127
-rw-r--r--src/lib/libcrypto/md4/md4s.cpp78
-rw-r--r--src/lib/libcrypto/md4/md4test.c131
-rw-r--r--src/lib/libcrypto/md5/asm/md5-sparcv9.S1029
-rw-r--r--src/lib/libcrypto/objects/obj_mac.h1798
-rw-r--r--src/lib/libcrypto/opensslconf.h.in142
-rw-r--r--src/lib/libcrypto/perlasm/alpha.pl434
-rw-r--r--src/lib/libcrypto/perlasm/x86nasm.pl342
-rw-r--r--src/lib/libcrypto/pkcs7/bio_ber.c450
-rw-r--r--src/lib/libcrypto/pkcs7/dec.c246
-rw-r--r--src/lib/libcrypto/pkcs7/des.pem15
-rw-r--r--src/lib/libcrypto/pkcs7/es1.pem66
-rw-r--r--src/lib/libcrypto/pkcs7/example.c327
-rw-r--r--src/lib/libcrypto/pkcs7/example.h57
-rw-r--r--src/lib/libcrypto/pkcs7/info.pem57
-rw-r--r--src/lib/libcrypto/pkcs7/infokey.pem9
-rw-r--r--src/lib/libcrypto/pkcs7/t/3des.pem16
-rw-r--r--src/lib/libcrypto/pkcs7/t/3dess.pem32
-rw-r--r--src/lib/libcrypto/pkcs7/t/c.pem48
-rw-r--r--src/lib/libcrypto/pkcs7/t/ff32
-rw-r--r--src/lib/libcrypto/pkcs7/t/msie-e20
-rw-r--r--src/lib/libcrypto/pkcs7/t/msie-e.pem22
-rw-r--r--src/lib/libcrypto/pkcs7/t/msie-enc-0162
-rw-r--r--src/lib/libcrypto/pkcs7/t/msie-enc-01.pem66
-rw-r--r--src/lib/libcrypto/pkcs7/t/msie-enc-0290
-rw-r--r--src/lib/libcrypto/pkcs7/t/msie-enc-02.pem106
-rw-r--r--src/lib/libcrypto/pkcs7/t/msie-s-a-e91
-rw-r--r--src/lib/libcrypto/pkcs7/t/msie-s-a-e.pem106
-rw-r--r--src/lib/libcrypto/pkcs7/t/nav-smime157
-rw-r--r--src/lib/libcrypto/pkcs7/t/s.pem57
-rw-r--r--src/lib/libcrypto/pkcs7/t/server.pem57
-rw-r--r--src/lib/libcrypto/rand/rand_egd.c110
-rw-r--r--src/lib/libcrypto/rand/rand_lcl.h184
-rw-r--r--src/lib/libcrypto/rand/rand_os2.c147
-rw-r--r--src/lib/libcrypto/rand/rand_unix.c274
-rw-r--r--src/lib/libcrypto/rand/rand_vms.c135
-rw-r--r--src/lib/libcrypto/rand/rand_win.c732
-rw-r--r--src/lib/libcrypto/rc2/tab.c86
-rw-r--r--src/lib/libcrypto/rsa/rsa_null.c149
-rw-r--r--src/lib/libcrypto/rsa/rsa_test.c314
-rw-r--r--src/lib/libcrypto/symhacks.h154
-rw-r--r--src/lib/libcrypto/threads/README14
-rw-r--r--src/lib/libcrypto/threads/profile.sh4
-rw-r--r--src/lib/libcrypto/threads/ptest.bat4
-rw-r--r--src/lib/libcrypto/threads/pthread.sh9
-rw-r--r--src/lib/libcrypto/threads/pthread2.sh7
-rw-r--r--src/lib/libcrypto/threads/pthreads-vms.com9
-rw-r--r--src/lib/libcrypto/threads/purify.sh4
-rw-r--r--src/lib/libcrypto/threads/solaris.sh4
-rw-r--r--src/lib/libcrypto/threads/win32.bat4
-rw-r--r--src/lib/libcrypto/tmdiff.h81
-rw-r--r--src/lib/libcrypto/ui/ui_compat.c67
-rw-r--r--src/lib/libcrypto/uid.c88
-rw-r--r--src/lib/libcrypto/util/clean-depend.pl38
-rw-r--r--src/lib/libcrypto/util/cygwin.sh125
-rw-r--r--src/lib/libcrypto/util/domd11
-rw-r--r--src/lib/libcrypto/util/mkdir-p.pl33
-rw-r--r--src/lib/libcrypto/util/mkfiles.pl110
-rw-r--r--src/lib/libcrypto/util/mklink.pl55
-rw-r--r--src/lib/libcrypto/util/pl/Mingw32.pl79
-rw-r--r--src/lib/libcrypto/util/pl/OS2-EMX.pl96
-rw-r--r--src/lib/libcrypto/util/pl/ultrix.pl38
-rw-r--r--src/lib/libcrypto/util/pod2man.pl1181
-rw-r--r--src/lib/libcrypto/util/selftest.pl174
-rw-r--r--src/lib/libcrypto/x509v3/tabtest.c88
-rw-r--r--src/lib/libcrypto/x509v3/v3conf.c128
-rw-r--r--src/lib/libcrypto/x509v3/v3prin.c101
158 files changed, 41919 insertions, 0 deletions
diff --git a/src/lib/libcrypto/asn1/a_gentm.c b/src/lib/libcrypto/asn1/a_gentm.c
new file mode 100644
index 0000000000..226474f057
--- /dev/null
+++ b/src/lib/libcrypto/asn1/a_gentm.c
@@ -0,0 +1,224 @@
1/* crypto/asn1/a_gentm.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59/* GENERALIZEDTIME implementation, written by Steve Henson. Based on UTCTIME */
60
61#include <stdio.h>
62#include <time.h>
63#include "cryptlib.h"
64#include <openssl/asn1.h>
65
66int i2d_ASN1_GENERALIZEDTIME(ASN1_GENERALIZEDTIME *a, unsigned char **pp)
67 {
68#ifdef CHARSET_EBCDIC
69 /* KLUDGE! We convert to ascii before writing DER */
70 int len;
71 char tmp[24];
72 ASN1_STRING tmpstr = *(ASN1_STRING *)a;
73
74 len = tmpstr.length;
75 ebcdic2ascii(tmp, tmpstr.data, (len >= sizeof tmp) ? sizeof tmp : len);
76 tmpstr.data = tmp;
77
78 a = (ASN1_GENERALIZEDTIME *) &tmpstr;
79#endif
80 return(i2d_ASN1_bytes((ASN1_STRING *)a,pp,
81 V_ASN1_GENERALIZEDTIME,V_ASN1_UNIVERSAL));
82 }
83
84
85ASN1_GENERALIZEDTIME *d2i_ASN1_GENERALIZEDTIME(ASN1_GENERALIZEDTIME **a,
86 unsigned char **pp, long length)
87 {
88 ASN1_GENERALIZEDTIME *ret=NULL;
89
90 ret=(ASN1_GENERALIZEDTIME *)d2i_ASN1_bytes((ASN1_STRING **)a,pp,length,
91 V_ASN1_GENERALIZEDTIME,V_ASN1_UNIVERSAL);
92 if (ret == NULL)
93 {
94 ASN1err(ASN1_F_D2I_ASN1_GENERALIZEDTIME,ERR_R_NESTED_ASN1_ERROR);
95 return(NULL);
96 }
97#ifdef CHARSET_EBCDIC
98 ascii2ebcdic(ret->data, ret->data, ret->length);
99#endif
100 if (!ASN1_GENERALIZEDTIME_check(ret))
101 {
102 ASN1err(ASN1_F_D2I_ASN1_GENERALIZEDTIME,ASN1_R_INVALID_TIME_FORMAT);
103 goto err;
104 }
105
106 return(ret);
107err:
108 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
109 ASN1_GENERALIZEDTIME_free(ret);
110 return(NULL);
111 }
112
113int ASN1_GENERALIZEDTIME_check(ASN1_GENERALIZEDTIME *d)
114 {
115 static int min[9]={ 0, 0, 1, 1, 0, 0, 0, 0, 0};
116 static int max[9]={99, 99,12,31,23,59,59,12,59};
117 char *a;
118 int n,i,l,o;
119
120 if (d->type != V_ASN1_GENERALIZEDTIME) return(0);
121 l=d->length;
122 a=(char *)d->data;
123 o=0;
124 /* GENERALIZEDTIME is similar to UTCTIME except the year is
125 * represented as YYYY. This stuff treats everything as a two digit
126 * field so make first two fields 00 to 99
127 */
128 if (l < 13) goto err;
129 for (i=0; i<7; i++)
130 {
131 if ((i == 6) && ((a[o] == 'Z') ||
132 (a[o] == '+') || (a[o] == '-')))
133 { i++; break; }
134 if ((a[o] < '0') || (a[o] > '9')) goto err;
135 n= a[o]-'0';
136 if (++o > l) goto err;
137
138 if ((a[o] < '0') || (a[o] > '9')) goto err;
139 n=(n*10)+ a[o]-'0';
140 if (++o > l) goto err;
141
142 if ((n < min[i]) || (n > max[i])) goto err;
143 }
144 if (a[o] == 'Z')
145 o++;
146 else if ((a[o] == '+') || (a[o] == '-'))
147 {
148 o++;
149 if (o+4 > l) goto err;
150 for (i=7; i<9; i++)
151 {
152 if ((a[o] < '0') || (a[o] > '9')) goto err;
153 n= a[o]-'0';
154 o++;
155 if ((a[o] < '0') || (a[o] > '9')) goto err;
156 n=(n*10)+ a[o]-'0';
157 if ((n < min[i]) || (n > max[i])) goto err;
158 o++;
159 }
160 }
161 return(o == l);
162err:
163 return(0);
164 }
165
166int ASN1_GENERALIZEDTIME_set_string(ASN1_GENERALIZEDTIME *s, char *str)
167 {
168 ASN1_GENERALIZEDTIME t;
169
170 t.type=V_ASN1_GENERALIZEDTIME;
171 t.length=strlen(str);
172 t.data=(unsigned char *)str;
173 if (ASN1_GENERALIZEDTIME_check(&t))
174 {
175 if (s != NULL)
176 {
177 ASN1_STRING_set((ASN1_STRING *)s,
178 (unsigned char *)str,t.length);
179 }
180 return(1);
181 }
182 else
183 return(0);
184 }
185
186ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_set(ASN1_GENERALIZEDTIME *s,
187 time_t t)
188 {
189 char *p;
190 struct tm *ts;
191#if defined(THREADS) && !defined(WIN32)
192 struct tm data;
193#endif
194
195 if (s == NULL)
196 s=ASN1_GENERALIZEDTIME_new();
197 if (s == NULL)
198 return(NULL);
199
200#if defined(THREADS) && !defined(WIN32)
201 gmtime_r(&t,&data); /* should return &data, but doesn't on some systems, so we don't even look at the return value */
202 ts=&data;
203#else
204 ts=gmtime(&t);
205#endif
206 p=(char *)s->data;
207 if ((p == NULL) || (s->length < 16))
208 {
209 p=Malloc(20);
210 if (p == NULL) return(NULL);
211 if (s->data != NULL)
212 Free(s->data);
213 s->data=(unsigned char *)p;
214 }
215
216 sprintf(p,"%04d%02d%02d%02d%02d%02dZ",ts->tm_year + 1900,
217 ts->tm_mon+1,ts->tm_mday,ts->tm_hour,ts->tm_min,ts->tm_sec);
218 s->length=strlen(p);
219 s->type=V_ASN1_GENERALIZEDTIME;
220#ifdef CHARSET_EBCDIC_not
221 ebcdic2ascii(s->data, s->data, s->length);
222#endif
223 return(s);
224 }
diff --git a/src/lib/libcrypto/asn1/p8_key.c b/src/lib/libcrypto/asn1/p8_key.c
new file mode 100644
index 0000000000..0b24374627
--- /dev/null
+++ b/src/lib/libcrypto/asn1/p8_key.c
@@ -0,0 +1,131 @@
1/* crypto/asn1/p8_key.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1_mac.h>
62#include <openssl/objects.h>
63
64int i2d_X509_KEY(X509 *a, unsigned char **pp)
65 {
66 M_ASN1_I2D_vars(a);
67
68 M_ASN1_I2D_len(a->cert_info, i2d_X509_CINF);
69 M_ASN1_I2D_len(a->sig_alg, i2d_X509_ALGOR);
70 M_ASN1_I2D_len(a->signature, i2d_ASN1_BIT_STRING);
71
72 M_ASN1_I2D_seq_total();
73
74 M_ASN1_I2D_put(a->cert_info, i2d_X509_CINF);
75 M_ASN1_I2D_put(a->sig_alg, i2d_X509_ALGOR);
76 M_ASN1_I2D_put(a->signature, i2d_ASN1_BIT_STRING);
77
78 M_ASN1_I2D_finish();
79 }
80
81X509 *d2i_X509_KEY(X509 **a, unsigned char **pp, long length)
82 {
83 M_ASN1_D2I_vars(a,X509 *,X509_new);
84
85 M_ASN1_D2I_Init();
86 M_ASN1_D2I_start_sequence();
87 M_ASN1_D2I_get(ret->cert_info,d2i_X509_CINF);
88 M_ASN1_D2I_get(ret->sig_alg,d2i_X509_ALGOR);
89 M_ASN1_D2I_get(ret->signature,d2i_ASN1_BIT_STRING);
90 M_ASN1_D2I_Finish(a,X509_free,ASN1_F_D2I_X509);
91 }
92
93X509 *X509_KEY_new(void)
94 {
95 X509_KEY *ret=NULL;
96
97 M_ASN1_New_Malloc(ret,X509_KEY);
98 ret->references=1;
99 ret->type=NID
100 M_ASN1_New(ret->cert_info,X509_CINF_new);
101 M_ASN1_New(ret->sig_alg,X509_ALGOR_new);
102 M_ASN1_New(ret->signature,ASN1_BIT_STRING_new);
103 return(ret);
104 M_ASN1_New_Error(ASN1_F_X509_NEW);
105 }
106
107void X509_KEY_free(X509 *a)
108 {
109 int i;
110
111 if (a == NULL) return;
112
113 i=CRYPTO_add_lock(&a->references,-1,CRYPTO_LOCK_X509_KEY);
114#ifdef REF_PRINT
115 REF_PRINT("X509_KEY",a);
116#endif
117 if (i > 0) return;
118#ifdef REF_CHECK
119 if (i < 0)
120 {
121 fprintf(stderr,"X509_KEY_free, bad reference count\n");
122 abort();
123 }
124#endif
125
126 X509_CINF_free(a->cert_info);
127 X509_ALGOR_free(a->sig_alg);
128 ASN1_BIT_STRING_free(a->signature);
129 Free(a);
130 }
131
diff --git a/src/lib/libcrypto/bn/asm/alpha.s.works b/src/lib/libcrypto/bn/asm/alpha.s.works
new file mode 100644
index 0000000000..ee6c587809
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/alpha.s.works
@@ -0,0 +1,533 @@
1
2 # DEC Alpha assember
3 # The bn_div64 is actually gcc output but the other parts are hand done.
4 # Thanks to tzeruch@ceddec.com for sending me the gcc output for
5 # bn_div64.
6 # I've gone back and re-done most of routines.
7 # The key thing to remeber for the 164 CPU is that while a
8 # multiply operation takes 8 cycles, another one can only be issued
9 # after 4 cycles have elapsed. I've done modification to help
10 # improve this. Also, normally, a ld instruction will not be available
11 # for about 3 cycles.
12 .file 1 "bn_asm.c"
13 .set noat
14gcc2_compiled.:
15__gnu_compiled_c:
16 .text
17 .align 3
18 .globl bn_mul_add_words
19 .ent bn_mul_add_words
20bn_mul_add_words:
21bn_mul_add_words..ng:
22 .frame $30,0,$26,0
23 .prologue 0
24 .align 5
25 subq $18,4,$18
26 bis $31,$31,$0
27 blt $18,$43 # if we are -1, -2, -3 or -4 goto tail code
28 ldq $20,0($17) # 1 1
29 ldq $1,0($16) # 1 1
30 .align 3
31$42:
32 mulq $20,$19,$5 # 1 2 1 ######
33 ldq $21,8($17) # 2 1
34 ldq $2,8($16) # 2 1
35 umulh $20,$19,$20 # 1 2 ######
36 ldq $27,16($17) # 3 1
37 ldq $3,16($16) # 3 1
38 mulq $21,$19,$6 # 2 2 1 ######
39 ldq $28,24($17) # 4 1
40 addq $1,$5,$1 # 1 2 2
41 ldq $4,24($16) # 4 1
42 umulh $21,$19,$21 # 2 2 ######
43 cmpult $1,$5,$22 # 1 2 3 1
44 addq $20,$22,$20 # 1 3 1
45 addq $1,$0,$1 # 1 2 3 1
46 mulq $27,$19,$7 # 3 2 1 ######
47 cmpult $1,$0,$0 # 1 2 3 2
48 addq $2,$6,$2 # 2 2 2
49 addq $20,$0,$0 # 1 3 2
50 cmpult $2,$6,$23 # 2 2 3 1
51 addq $21,$23,$21 # 2 3 1
52 umulh $27,$19,$27 # 3 2 ######
53 addq $2,$0,$2 # 2 2 3 1
54 cmpult $2,$0,$0 # 2 2 3 2
55 subq $18,4,$18
56 mulq $28,$19,$8 # 4 2 1 ######
57 addq $21,$0,$0 # 2 3 2
58 addq $3,$7,$3 # 3 2 2
59 addq $16,32,$16
60 cmpult $3,$7,$24 # 3 2 3 1
61 stq $1,-32($16) # 1 2 4
62 umulh $28,$19,$28 # 4 2 ######
63 addq $27,$24,$27 # 3 3 1
64 addq $3,$0,$3 # 3 2 3 1
65 stq $2,-24($16) # 2 2 4
66 cmpult $3,$0,$0 # 3 2 3 2
67 stq $3,-16($16) # 3 2 4
68 addq $4,$8,$4 # 4 2 2
69 addq $27,$0,$0 # 3 3 2
70 cmpult $4,$8,$25 # 4 2 3 1
71 addq $17,32,$17
72 addq $28,$25,$28 # 4 3 1
73 addq $4,$0,$4 # 4 2 3 1
74 cmpult $4,$0,$0 # 4 2 3 2
75 stq $4,-8($16) # 4 2 4
76 addq $28,$0,$0 # 4 3 2
77 blt $18,$43
78
79 ldq $20,0($17) # 1 1
80 ldq $1,0($16) # 1 1
81
82 br $42
83
84 .align 4
85$45:
86 ldq $20,0($17) # 4 1
87 ldq $1,0($16) # 4 1
88 mulq $20,$19,$5 # 4 2 1
89 subq $18,1,$18
90 addq $16,8,$16
91 addq $17,8,$17
92 umulh $20,$19,$20 # 4 2
93 addq $1,$5,$1 # 4 2 2
94 cmpult $1,$5,$22 # 4 2 3 1
95 addq $20,$22,$20 # 4 3 1
96 addq $1,$0,$1 # 4 2 3 1
97 cmpult $1,$0,$0 # 4 2 3 2
98 addq $20,$0,$0 # 4 3 2
99 stq $1,-8($16) # 4 2 4
100 bgt $18,$45
101 ret $31,($26),1 # else exit
102
103 .align 4
104$43:
105 addq $18,4,$18
106 bgt $18,$45 # goto tail code
107 ret $31,($26),1 # else exit
108
109 .end bn_mul_add_words
110 .align 3
111 .globl bn_mul_words
112 .ent bn_mul_words
113bn_mul_words:
114bn_mul_words..ng:
115 .frame $30,0,$26,0
116 .prologue 0
117 .align 5
118 subq $18,4,$18
119 bis $31,$31,$0
120 blt $18,$143 # if we are -1, -2, -3 or -4 goto tail code
121 ldq $20,0($17) # 1 1
122 .align 3
123$142:
124
125 mulq $20,$19,$5 # 1 2 1 #####
126 ldq $21,8($17) # 2 1
127 ldq $27,16($17) # 3 1
128 umulh $20,$19,$20 # 1 2 #####
129 ldq $28,24($17) # 4 1
130 mulq $21,$19,$6 # 2 2 1 #####
131 addq $5,$0,$5 # 1 2 3 1
132 subq $18,4,$18
133 cmpult $5,$0,$0 # 1 2 3 2
134 umulh $21,$19,$21 # 2 2 #####
135 addq $20,$0,$0 # 1 3 2
136 addq $17,32,$17
137 addq $6,$0,$6 # 2 2 3 1
138 mulq $27,$19,$7 # 3 2 1 #####
139 cmpult $6,$0,$0 # 2 2 3 2
140 addq $21,$0,$0 # 2 3 2
141 addq $16,32,$16
142 umulh $27,$19,$27 # 3 2 #####
143 stq $5,-32($16) # 1 2 4
144 mulq $28,$19,$8 # 4 2 1 #####
145 addq $7,$0,$7 # 3 2 3 1
146 stq $6,-24($16) # 2 2 4
147 cmpult $7,$0,$0 # 3 2 3 2
148 umulh $28,$19,$28 # 4 2 #####
149 addq $27,$0,$0 # 3 3 2
150 stq $7,-16($16) # 3 2 4
151 addq $8,$0,$8 # 4 2 3 1
152 cmpult $8,$0,$0 # 4 2 3 2
153
154 addq $28,$0,$0 # 4 3 2
155
156 stq $8,-8($16) # 4 2 4
157
158 blt $18,$143
159
160 ldq $20,0($17) # 1 1
161
162 br $142
163
164 .align 4
165$145:
166 ldq $20,0($17) # 4 1
167 mulq $20,$19,$5 # 4 2 1
168 subq $18,1,$18
169 umulh $20,$19,$20 # 4 2
170 addq $5,$0,$5 # 4 2 3 1
171 addq $16,8,$16
172 cmpult $5,$0,$0 # 4 2 3 2
173 addq $17,8,$17
174 addq $20,$0,$0 # 4 3 2
175 stq $5,-8($16) # 4 2 4
176
177 bgt $18,$145
178 ret $31,($26),1 # else exit
179
180 .align 4
181$143:
182 addq $18,4,$18
183 bgt $18,$145 # goto tail code
184 ret $31,($26),1 # else exit
185
186 .end bn_mul_words
187 .align 3
188 .globl bn_sqr_words
189 .ent bn_sqr_words
190bn_sqr_words:
191bn_sqr_words..ng:
192 .frame $30,0,$26,0
193 .prologue 0
194
195 subq $18,4,$18
196 blt $18,$543 # if we are -1, -2, -3 or -4 goto tail code
197 ldq $20,0($17) # 1 1
198 .align 3
199$542:
200 mulq $20,$20,$5 ######
201 ldq $21,8($17) # 1 1
202 subq $18,4
203 umulh $20,$20,$1 ######
204 ldq $27,16($17) # 1 1
205 mulq $21,$21,$6 ######
206 ldq $28,24($17) # 1 1
207 stq $5,0($16) # r[0]
208 umulh $21,$21,$2 ######
209 stq $1,8($16) # r[1]
210 mulq $27,$27,$7 ######
211 stq $6,16($16) # r[0]
212 umulh $27,$27,$3 ######
213 stq $2,24($16) # r[1]
214 mulq $28,$28,$8 ######
215 stq $7,32($16) # r[0]
216 umulh $28,$28,$4 ######
217 stq $3,40($16) # r[1]
218
219 addq $16,64,$16
220 addq $17,32,$17
221 stq $8,-16($16) # r[0]
222 stq $4,-8($16) # r[1]
223
224 blt $18,$543
225 ldq $20,0($17) # 1 1
226 br $542
227
228$442:
229 ldq $20,0($17) # a[0]
230 mulq $20,$20,$5 # a[0]*w low part r2
231 addq $16,16,$16
232 addq $17,8,$17
233 subq $18,1,$18
234 umulh $20,$20,$1 # a[0]*w high part r3
235 stq $5,-16($16) # r[0]
236 stq $1,-8($16) # r[1]
237
238 bgt $18,$442
239 ret $31,($26),1 # else exit
240
241 .align 4
242$543:
243 addq $18,4,$18
244 bgt $18,$442 # goto tail code
245 ret $31,($26),1 # else exit
246 .end bn_sqr_words
247
248 .align 3
249 .globl bn_add_words
250 .ent bn_add_words
251bn_add_words:
252bn_add_words..ng:
253 .frame $30,0,$26,0
254 .prologue 0
255
256 subq $19,4,$19
257 bis $31,$31,$0 # carry = 0
258 blt $19,$900
259 ldq $5,0($17) # a[0]
260 ldq $1,0($18) # b[1]
261 .align 3
262$901:
263 addq $1,$5,$1 # r=a+b;
264 ldq $6,8($17) # a[1]
265 cmpult $1,$5,$22 # did we overflow?
266 ldq $2,8($18) # b[1]
267 addq $1,$0,$1 # c+= overflow
268 ldq $7,16($17) # a[2]
269 cmpult $1,$0,$0 # overflow?
270 ldq $3,16($18) # b[2]
271 addq $0,$22,$0
272 ldq $8,24($17) # a[3]
273 addq $2,$6,$2 # r=a+b;
274 ldq $4,24($18) # b[3]
275 cmpult $2,$6,$23 # did we overflow?
276 addq $3,$7,$3 # r=a+b;
277 addq $2,$0,$2 # c+= overflow
278 cmpult $3,$7,$24 # did we overflow?
279 cmpult $2,$0,$0 # overflow?
280 addq $4,$8,$4 # r=a+b;
281 addq $0,$23,$0
282 cmpult $4,$8,$25 # did we overflow?
283 addq $3,$0,$3 # c+= overflow
284 stq $1,0($16) # r[0]=c
285 cmpult $3,$0,$0 # overflow?
286 stq $2,8($16) # r[1]=c
287 addq $0,$24,$0
288 stq $3,16($16) # r[2]=c
289 addq $4,$0,$4 # c+= overflow
290 subq $19,4,$19 # loop--
291 cmpult $4,$0,$0 # overflow?
292 addq $17,32,$17 # a++
293 addq $0,$25,$0
294 stq $4,24($16) # r[3]=c
295 addq $18,32,$18 # b++
296 addq $16,32,$16 # r++
297
298 blt $19,$900
299 ldq $5,0($17) # a[0]
300 ldq $1,0($18) # b[1]
301 br $901
302 .align 4
303$945:
304 ldq $5,0($17) # a[0]
305 ldq $1,0($18) # b[1]
306 addq $1,$5,$1 # r=a+b;
307 subq $19,1,$19 # loop--
308 addq $1,$0,$1 # c+= overflow
309 addq $17,8,$17 # a++
310 cmpult $1,$5,$22 # did we overflow?
311 cmpult $1,$0,$0 # overflow?
312 addq $18,8,$18 # b++
313 stq $1,0($16) # r[0]=c
314 addq $0,$22,$0
315 addq $16,8,$16 # r++
316
317 bgt $19,$945
318 ret $31,($26),1 # else exit
319
320$900:
321 addq $19,4,$19
322 bgt $19,$945 # goto tail code
323 ret $31,($26),1 # else exit
324 .end bn_add_words
325
326 #
327 # What follows was taken directly from the C compiler with a few
328 # hacks to redo the lables.
329 #
330.text
331 .align 3
332 .globl bn_div64
333 .ent bn_div64
334bn_div64:
335 ldgp $29,0($27)
336bn_div64..ng:
337 lda $30,-48($30)
338 .frame $30,48,$26,0
339 stq $26,0($30)
340 stq $9,8($30)
341 stq $10,16($30)
342 stq $11,24($30)
343 stq $12,32($30)
344 stq $13,40($30)
345 .mask 0x4003e00,-48
346 .prologue 1
347 bis $16,$16,$9
348 bis $17,$17,$10
349 bis $18,$18,$11
350 bis $31,$31,$13
351 bis $31,2,$12
352 bne $11,$119
353 lda $0,-1
354 br $31,$136
355 .align 4
356$119:
357 bis $11,$11,$16
358 jsr $26,BN_num_bits_word
359 ldgp $29,0($26)
360 subq $0,64,$1
361 beq $1,$120
362 bis $31,1,$1
363 sll $1,$0,$1
364 cmpule $9,$1,$1
365 bne $1,$120
366 # lda $16,_IO_stderr_
367 # lda $17,$C32
368 # bis $0,$0,$18
369 # jsr $26,fprintf
370 # ldgp $29,0($26)
371 jsr $26,abort
372 ldgp $29,0($26)
373 .align 4
374$120:
375 bis $31,64,$3
376 cmpult $9,$11,$2
377 subq $3,$0,$1
378 addl $1,$31,$0
379 subq $9,$11,$1
380 cmoveq $2,$1,$9
381 beq $0,$122
382 zapnot $0,15,$2
383 subq $3,$0,$1
384 sll $11,$2,$11
385 sll $9,$2,$3
386 srl $10,$1,$1
387 sll $10,$2,$10
388 bis $3,$1,$9
389$122:
390 srl $11,32,$5
391 zapnot $11,15,$6
392 lda $7,-1
393 .align 5
394$123:
395 srl $9,32,$1
396 subq $1,$5,$1
397 bne $1,$126
398 zapnot $7,15,$27
399 br $31,$127
400 .align 4
401$126:
402 bis $9,$9,$24
403 bis $5,$5,$25
404 divqu $24,$25,$27
405$127:
406 srl $10,32,$4
407 .align 5
408$128:
409 mulq $27,$5,$1
410 subq $9,$1,$3
411 zapnot $3,240,$1
412 bne $1,$129
413 mulq $6,$27,$2
414 sll $3,32,$1
415 addq $1,$4,$1
416 cmpule $2,$1,$2
417 bne $2,$129
418 subq $27,1,$27
419 br $31,$128
420 .align 4
421$129:
422 mulq $27,$6,$1
423 mulq $27,$5,$4
424 srl $1,32,$3
425 sll $1,32,$1
426 addq $4,$3,$4
427 cmpult $10,$1,$2
428 subq $10,$1,$10
429 addq $2,$4,$2
430 cmpult $9,$2,$1
431 bis $2,$2,$4
432 beq $1,$134
433 addq $9,$11,$9
434 subq $27,1,$27
435$134:
436 subl $12,1,$12
437 subq $9,$4,$9
438 beq $12,$124
439 sll $27,32,$13
440 sll $9,32,$2
441 srl $10,32,$1
442 sll $10,32,$10
443 bis $2,$1,$9
444 br $31,$123
445 .align 4
446$124:
447 bis $13,$27,$0
448$136:
449 ldq $26,0($30)
450 ldq $9,8($30)
451 ldq $10,16($30)
452 ldq $11,24($30)
453 ldq $12,32($30)
454 ldq $13,40($30)
455 addq $30,48,$30
456 ret $31,($26),1
457 .end bn_div64
458
459 .set noat
460 .text
461 .align 3
462 .globl bn_sub_words
463 .ent bn_sub_words
464bn_sub_words:
465bn_sub_words..ng:
466 .frame $30,0,$26,0
467 .prologue 0
468
469 subq $19, 4, $19
470 bis $31, $31, $0
471 blt $19, $100
472 ldq $1, 0($17)
473 ldq $2, 0($18)
474$101:
475 ldq $3, 8($17)
476 cmpult $1, $2, $4
477 ldq $5, 8($18)
478 subq $1, $2, $1
479 ldq $6, 16($17)
480 cmpult $1, $0, $2
481 ldq $7, 16($18)
482 subq $1, $0, $23
483 ldq $8, 24($17)
484 addq $2, $4, $0
485 cmpult $3, $5, $24
486 subq $3, $5, $3
487 ldq $22, 24($18)
488 cmpult $3, $0, $5
489 subq $3, $0, $25
490 addq $5, $24, $0
491 cmpult $6, $7, $27
492 subq $6, $7, $6
493 stq $23, 0($16)
494 cmpult $6, $0, $7
495 subq $6, $0, $28
496 addq $7, $27, $0
497 cmpult $8, $22, $21
498 subq $8, $22, $8
499 stq $25, 8($16)
500 cmpult $8, $0, $22
501 subq $8, $0, $20
502 addq $22, $21, $0
503 stq $28, 16($16)
504 subq $19, 4, $19
505 stq $20, 24($16)
506 addq $17, 32, $17
507 addq $18, 32, $18
508 addq $16, 32, $16
509 blt $19, $100
510 ldq $1, 0($17)
511 ldq $2, 0($18)
512 br $101
513$102:
514 ldq $1, 0($17)
515 ldq $2, 0($18)
516 cmpult $1, $2, $27
517 subq $1, $2, $1
518 cmpult $1, $0, $2
519 subq $1, $0, $1
520 stq $1, 0($16)
521 addq $2, $27, $0
522 addq $17, 8, $17
523 addq $18, 8, $18
524 addq $16, 8, $16
525 subq $19, 1, $19
526 bgt $19, $102
527 ret $31,($26),1
528$100:
529 addq $19, 4, $19
530 bgt $19, $102
531$103:
532 ret $31,($26),1
533 .end bn_sub_words
diff --git a/src/lib/libcrypto/bn/asm/alpha.works/add.pl b/src/lib/libcrypto/bn/asm/alpha.works/add.pl
new file mode 100644
index 0000000000..4dc76e6b69
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/alpha.works/add.pl
@@ -0,0 +1,119 @@
1#!/usr/local/bin/perl
2# alpha assember
3
4sub bn_add_words
5 {
6 local($name)=@_;
7 local($cc,$a,$b,$r);
8
9 &init_pool(4);
10 ($cc)=GR("r0");
11
12 $rp=&wparam(0);
13 $ap=&wparam(1);
14 $bp=&wparam(2);
15 $count=&wparam(3);
16
17 &function_begin($name,"");
18
19 &comment("");
20 &sub($count,4,$count);
21 &mov("zero",$cc);
22 &br(&label("finish"));
23 &blt($count,&label("finish"));
24
25 ($a0,$b0)=&NR(2);
26 &ld($a0,&QWPw(0,$ap));
27 &ld($b0,&QWPw(0,$bp));
28
29##########################################################
30 &set_label("loop");
31
32 ($a1)=&NR(1); &ld($a1,&QWPw(1,$ap));
33 ($b1)=&NR(1); &ld($b1,&QWPw(1,$bp));
34 ($a2)=&NR(1); &ld($a2,&QWPw(2,$ap));
35 ($b2)=&NR(1); &ld($b2,&QWPw(2,$bp));
36 ($a3)=&NR(1); &ld($a3,&QWPw(3,$ap));
37 ($b3)=&NR(1); &ld($b3,&QWPw(3,$bp));
38
39 ($o0,$t0)=&NR(2);
40 &add($a0,$b0,$o0);
41 &cmpult($o0,$b0,$t0);
42 &add($o0,$cc,$o0);
43 &cmpult($o0,$cc,$cc);
44 &add($cc,$t0,$cc); &FR($t0);
45
46 ($t1,$o1)=&NR(2);
47
48 &add($a1,$b1,$o1); &FR($a1);
49 &cmpult($o1,$b1,$t1); &FR($b1);
50 &add($o1,$cc,$o1);
51 &cmpult($o1,$cc,$cc);
52 &add($cc,$t1,$cc); &FR($t1);
53
54 ($t2,$o2)=&NR(2);
55
56 &add($a2,$b2,$o2); &FR($a2);
57 &cmpult($o2,$b2,$t2); &FR($b2);
58 &add($o2,$cc,$o2);
59 &cmpult($o2,$cc,$cc);
60 &add($cc,$t2,$cc); &FR($t2);
61
62 ($t3,$o3)=&NR(2);
63
64 &add($a3,$b3,$o3); &FR($a3);
65 &cmpult($o3,$b3,$t3); &FR($b3);
66 &add($o3,$cc,$o3);
67 &cmpult($o3,$cc,$cc);
68 &add($cc,$t3,$cc); &FR($t3);
69
70 &st($o0,&QWPw(0,$rp)); &FR($o0);
71 &st($o1,&QWPw(0,$rp)); &FR($o1);
72 &st($o2,&QWPw(0,$rp)); &FR($o2);
73 &st($o3,&QWPw(0,$rp)); &FR($o3);
74
75 &sub($count,4,$count); # count-=4
76 &add($ap,4*$QWS,$ap); # count+=4
77 &add($bp,4*$QWS,$bp); # count+=4
78 &add($rp,4*$QWS,$rp); # count+=4
79
80 &blt($count,&label("finish"));
81 &ld($a0,&QWPw(0,$ap));
82 &ld($b0,&QWPw(0,$bp));
83 &br(&label("loop"));
84##################################################
85 # Do the last 0..3 words
86
87 ($t0,$o0)=&NR(2);
88 &set_label("last_loop");
89
90 &ld($a0,&QWPw(0,$ap)); # get a
91 &ld($b0,&QWPw(0,$bp)); # get b
92
93 &add($a0,$b0,$o0);
94 &cmpult($o0,$b0,$t0); # will we borrow?
95 &add($o0,$cc,$o0); # will we borrow?
96 &cmpult($o0,$cc,$cc); # will we borrow?
97 &add($cc,$t0,$cc); # add the borrows
98 &st($o0,&QWPw(0,$rp)); # save
99
100 &add($ap,$QWS,$ap);
101 &add($bp,$QWS,$bp);
102 &add($rp,$QWS,$rp);
103 &sub($count,1,$count);
104 &bgt($count,&label("last_loop"));
105 &function_end_A($name);
106
107######################################################
108 &set_label("finish");
109 &add($count,4,$count);
110 &bgt($count,&label("last_loop"));
111
112 &FR($o0,$t0,$a0,$b0);
113 &set_label("end");
114 &function_end($name);
115
116 &fin_pool;
117 }
118
1191;
diff --git a/src/lib/libcrypto/bn/asm/alpha.works/div.pl b/src/lib/libcrypto/bn/asm/alpha.works/div.pl
new file mode 100644
index 0000000000..7ec144377f
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/alpha.works/div.pl
@@ -0,0 +1,144 @@
1#!/usr/local/bin/perl
2
3sub bn_div64
4 {
5 local($data)=<<'EOF';
6 #
7 # What follows was taken directly from the C compiler with a few
8 # hacks to redo the lables.
9 #
10.text
11 .set noreorder
12 .set volatile
13 .align 3
14 .globl bn_div64
15 .ent bn_div64
16bn_div64:
17 ldgp $29,0($27)
18bn_div64..ng:
19 lda $30,-48($30)
20 .frame $30,48,$26,0
21 stq $26,0($30)
22 stq $9,8($30)
23 stq $10,16($30)
24 stq $11,24($30)
25 stq $12,32($30)
26 stq $13,40($30)
27 .mask 0x4003e00,-48
28 .prologue 1
29 bis $16,$16,$9
30 bis $17,$17,$10
31 bis $18,$18,$11
32 bis $31,$31,$13
33 bis $31,2,$12
34 bne $11,$9119
35 lda $0,-1
36 br $31,$9136
37 .align 4
38$9119:
39 bis $11,$11,$16
40 jsr $26,BN_num_bits_word
41 ldgp $29,0($26)
42 subq $0,64,$1
43 beq $1,$9120
44 bis $31,1,$1
45 sll $1,$0,$1
46 cmpule $9,$1,$1
47 bne $1,$9120
48 # lda $16,_IO_stderr_
49 # lda $17,$C32
50 # bis $0,$0,$18
51 # jsr $26,fprintf
52 # ldgp $29,0($26)
53 jsr $26,abort
54 ldgp $29,0($26)
55 .align 4
56$9120:
57 bis $31,64,$3
58 cmpult $9,$11,$2
59 subq $3,$0,$1
60 addl $1,$31,$0
61 subq $9,$11,$1
62 cmoveq $2,$1,$9
63 beq $0,$9122
64 zapnot $0,15,$2
65 subq $3,$0,$1
66 sll $11,$2,$11
67 sll $9,$2,$3
68 srl $10,$1,$1
69 sll $10,$2,$10
70 bis $3,$1,$9
71$9122:
72 srl $11,32,$5
73 zapnot $11,15,$6
74 lda $7,-1
75 .align 5
76$9123:
77 srl $9,32,$1
78 subq $1,$5,$1
79 bne $1,$9126
80 zapnot $7,15,$27
81 br $31,$9127
82 .align 4
83$9126:
84 bis $9,$9,$24
85 bis $5,$5,$25
86 divqu $24,$25,$27
87$9127:
88 srl $10,32,$4
89 .align 5
90$9128:
91 mulq $27,$5,$1
92 subq $9,$1,$3
93 zapnot $3,240,$1
94 bne $1,$9129
95 mulq $6,$27,$2
96 sll $3,32,$1
97 addq $1,$4,$1
98 cmpule $2,$1,$2
99 bne $2,$9129
100 subq $27,1,$27
101 br $31,$9128
102 .align 4
103$9129:
104 mulq $27,$6,$1
105 mulq $27,$5,$4
106 srl $1,32,$3
107 sll $1,32,$1
108 addq $4,$3,$4
109 cmpult $10,$1,$2
110 subq $10,$1,$10
111 addq $2,$4,$2
112 cmpult $9,$2,$1
113 bis $2,$2,$4
114 beq $1,$9134
115 addq $9,$11,$9
116 subq $27,1,$27
117$9134:
118 subl $12,1,$12
119 subq $9,$4,$9
120 beq $12,$9124
121 sll $27,32,$13
122 sll $9,32,$2
123 srl $10,32,$1
124 sll $10,32,$10
125 bis $2,$1,$9
126 br $31,$9123
127 .align 4
128$9124:
129 bis $13,$27,$0
130$9136:
131 ldq $26,0($30)
132 ldq $9,8($30)
133 ldq $10,16($30)
134 ldq $11,24($30)
135 ldq $12,32($30)
136 ldq $13,40($30)
137 addq $30,48,$30
138 ret $31,($26),1
139 .end bn_div64
140EOF
141 &asm_add($data);
142 }
143
1441;
diff --git a/src/lib/libcrypto/bn/asm/alpha.works/mul.pl b/src/lib/libcrypto/bn/asm/alpha.works/mul.pl
new file mode 100644
index 0000000000..b182bae452
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/alpha.works/mul.pl
@@ -0,0 +1,116 @@
1#!/usr/local/bin/perl
2# alpha assember
3
4sub bn_mul_words
5 {
6 local($name)=@_;
7 local($cc,$a,$b,$r,$couny);
8
9 &init_pool(4);
10 ($cc)=GR("r0");
11
12 $rp=&wparam(0);
13 $ap=&wparam(1);
14 $count=&wparam(2);
15 $word=&wparam(3);
16
17 &function_begin($name,"");
18
19 &comment("");
20 &sub($count,4,$count);
21 &mov("zero",$cc);
22 &br(&label("finish"));
23 &blt($count,&label("finish"));
24
25 ($a0,$r0)=&NR(2);
26 &ld($a0,&QWPw(0,$ap));
27 &ld($r0,&QWPw(0,$rp));
28
29$a=<<'EOF';
30##########################################################
31 &set_label("loop");
32
33 ($a1)=&NR(1); &ld($a1,&QWPw(1,$ap));
34 ($b1)=&NR(1); &ld($b1,&QWPw(1,$bp));
35 ($a2)=&NR(1); &ld($a2,&QWPw(2,$ap));
36 ($b2)=&NR(1); &ld($b2,&QWPw(2,$bp));
37 ($a3)=&NR(1); &ld($a3,&QWPw(3,$ap));
38 ($b3)=&NR(1); &ld($b3,&QWPw(3,$bp));
39
40 ($o0,$t0)=&NR(2);
41 &add($a0,$b0,$o0);
42 &cmpult($o0,$b0,$t0);
43 &add($o0,$cc,$o0);
44 &cmpult($o0,$cc,$cc);
45 &add($cc,$t0,$cc); &FR($t0);
46
47 ($t1,$o1)=&NR(2);
48
49 &add($a1,$b1,$o1); &FR($a1);
50 &cmpult($o1,$b1,$t1); &FR($b1);
51 &add($o1,$cc,$o1);
52 &cmpult($o1,$cc,$cc);
53 &add($cc,$t1,$cc); &FR($t1);
54
55 ($t2,$o2)=&NR(2);
56
57 &add($a2,$b2,$o2); &FR($a2);
58 &cmpult($o2,$b2,$t2); &FR($b2);
59 &add($o2,$cc,$o2);
60 &cmpult($o2,$cc,$cc);
61 &add($cc,$t2,$cc); &FR($t2);
62
63 ($t3,$o3)=&NR(2);
64
65 &add($a3,$b3,$o3); &FR($a3);
66 &cmpult($o3,$b3,$t3); &FR($b3);
67 &add($o3,$cc,$o3);
68 &cmpult($o3,$cc,$cc);
69 &add($cc,$t3,$cc); &FR($t3);
70
71 &st($o0,&QWPw(0,$rp)); &FR($o0);
72 &st($o1,&QWPw(0,$rp)); &FR($o1);
73 &st($o2,&QWPw(0,$rp)); &FR($o2);
74 &st($o3,&QWPw(0,$rp)); &FR($o3);
75
76 &sub($count,4,$count); # count-=4
77 &add($ap,4*$QWS,$ap); # count+=4
78 &add($bp,4*$QWS,$bp); # count+=4
79 &add($rp,4*$QWS,$rp); # count+=4
80
81 &blt($count,&label("finish"));
82 &ld($a0,&QWPw(0,$ap));
83 &ld($b0,&QWPw(0,$bp));
84 &br(&label("loop"));
85EOF
86##################################################
87 # Do the last 0..3 words
88
89 &set_label("last_loop");
90
91 &ld(($a0)=&NR(1),&QWPw(0,$ap)); # get a
92 &mul($a0,$word,($l0)=&NR(1));
93 &add($ap,$QWS,$ap);
94 &muh($a0,$word,($h0)=&NR(1)); &FR($a0);
95 &add($l0,$cc,$l0);
96 &add($rp,$QWS,$rp);
97 &sub($count,1,$count);
98 &cmpult($l0,$cc,$cc);
99 &st($l0,&QWPw(-1,$rp)); &FR($l0);
100 &add($h0,$cc,$cc); &FR($h0);
101
102 &bgt($count,&label("last_loop"));
103 &function_end_A($name);
104
105######################################################
106 &set_label("finish");
107 &add($count,4,$count);
108 &bgt($count,&label("last_loop"));
109
110 &set_label("end");
111 &function_end($name);
112
113 &fin_pool;
114 }
115
1161;
diff --git a/src/lib/libcrypto/bn/asm/alpha.works/mul_add.pl b/src/lib/libcrypto/bn/asm/alpha.works/mul_add.pl
new file mode 100644
index 0000000000..e37f6315fb
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/alpha.works/mul_add.pl
@@ -0,0 +1,120 @@
1#!/usr/local/bin/perl
2# alpha assember
3
4sub bn_mul_add_words
5 {
6 local($name)=@_;
7 local($cc,$a,$b,$r,$couny);
8
9 &init_pool(4);
10 ($cc)=GR("r0");
11
12 $rp=&wparam(0);
13 $ap=&wparam(1);
14 $count=&wparam(2);
15 $word=&wparam(3);
16
17 &function_begin($name,"");
18
19 &comment("");
20 &sub($count,4,$count);
21 &mov("zero",$cc);
22 &br(&label("finish"));
23 &blt($count,&label("finish"));
24
25 ($a0,$r0)=&NR(2);
26 &ld($a0,&QWPw(0,$ap));
27 &ld($r0,&QWPw(0,$rp));
28
29$a=<<'EOF';
30##########################################################
31 &set_label("loop");
32
33 ($a1)=&NR(1); &ld($a1,&QWPw(1,$ap));
34 ($b1)=&NR(1); &ld($b1,&QWPw(1,$bp));
35 ($a2)=&NR(1); &ld($a2,&QWPw(2,$ap));
36 ($b2)=&NR(1); &ld($b2,&QWPw(2,$bp));
37 ($a3)=&NR(1); &ld($a3,&QWPw(3,$ap));
38 ($b3)=&NR(1); &ld($b3,&QWPw(3,$bp));
39
40 ($o0,$t0)=&NR(2);
41 &add($a0,$b0,$o0);
42 &cmpult($o0,$b0,$t0);
43 &add($o0,$cc,$o0);
44 &cmpult($o0,$cc,$cc);
45 &add($cc,$t0,$cc); &FR($t0);
46
47 ($t1,$o1)=&NR(2);
48
49 &add($a1,$b1,$o1); &FR($a1);
50 &cmpult($o1,$b1,$t1); &FR($b1);
51 &add($o1,$cc,$o1);
52 &cmpult($o1,$cc,$cc);
53 &add($cc,$t1,$cc); &FR($t1);
54
55 ($t2,$o2)=&NR(2);
56
57 &add($a2,$b2,$o2); &FR($a2);
58 &cmpult($o2,$b2,$t2); &FR($b2);
59 &add($o2,$cc,$o2);
60 &cmpult($o2,$cc,$cc);
61 &add($cc,$t2,$cc); &FR($t2);
62
63 ($t3,$o3)=&NR(2);
64
65 &add($a3,$b3,$o3); &FR($a3);
66 &cmpult($o3,$b3,$t3); &FR($b3);
67 &add($o3,$cc,$o3);
68 &cmpult($o3,$cc,$cc);
69 &add($cc,$t3,$cc); &FR($t3);
70
71 &st($o0,&QWPw(0,$rp)); &FR($o0);
72 &st($o1,&QWPw(0,$rp)); &FR($o1);
73 &st($o2,&QWPw(0,$rp)); &FR($o2);
74 &st($o3,&QWPw(0,$rp)); &FR($o3);
75
76 &sub($count,4,$count); # count-=4
77 &add($ap,4*$QWS,$ap); # count+=4
78 &add($bp,4*$QWS,$bp); # count+=4
79 &add($rp,4*$QWS,$rp); # count+=4
80
81 &blt($count,&label("finish"));
82 &ld($a0,&QWPw(0,$ap));
83 &ld($b0,&QWPw(0,$bp));
84 &br(&label("loop"));
85EOF
86##################################################
87 # Do the last 0..3 words
88
89 &set_label("last_loop");
90
91 &ld(($a0)=&NR(1),&QWPw(0,$ap)); # get a
92 &ld(($r0)=&NR(1),&QWPw(0,$rp)); # get b
93 &mul($a0,$word,($l0)=&NR(1));
94 &sub($count,1,$count);
95 &add($ap,$QWS,$ap);
96 &muh($a0,$word,($h0)=&NR(1)); &FR($a0);
97 &add($r0,$l0,$r0);
98 &add($rp,$QWS,$rp);
99 &cmpult($r0,$l0,($t0)=&NR(1)); &FR($l0);
100 &add($r0,$cc,$r0);
101 &add($h0,$t0,$h0); &FR($t0);
102 &cmpult($r0,$cc,$cc);
103 &st($r0,&QWPw(-1,$rp)); &FR($r0);
104 &add($h0,$cc,$cc); &FR($h0);
105
106 &bgt($count,&label("last_loop"));
107 &function_end_A($name);
108
109######################################################
110 &set_label("finish");
111 &add($count,4,$count);
112 &bgt($count,&label("last_loop"));
113
114 &set_label("end");
115 &function_end($name);
116
117 &fin_pool;
118 }
119
1201;
diff --git a/src/lib/libcrypto/bn/asm/alpha.works/mul_c4.pl b/src/lib/libcrypto/bn/asm/alpha.works/mul_c4.pl
new file mode 100644
index 0000000000..5efd201281
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/alpha.works/mul_c4.pl
@@ -0,0 +1,213 @@
1#!/usr/local/bin/perl
2# alpha assember
3
4sub mul_add_c
5 {
6 local($a,$b,$c0,$c1,$c2)=@_;
7 local($l1,$h1,$t1,$t2);
8
9 &mul($a,$b,($l1)=&NR(1));
10 &muh($a,$b,($h1)=&NR(1));
11 &add($c0,$l1,$c0);
12 &cmpult($c0,$l1,($t1)=&NR(1)); &FR($l1);
13 &add($t1,$h1,$h1); &FR($t1);
14 &add($c1,$h1,$c1);
15 &cmpult($c1,$h1,($t2)=&NR(1)); &FR($h1);
16 &add($c2,$t2,$c2); &FR($t2);
17 }
18
19sub bn_mul_comba4
20 {
21 local($name)=@_;
22 local(@a,@b,$r,$c0,$c1,$c2);
23
24 $cnt=1;
25 &init_pool(3);
26
27 $rp=&wparam(0);
28 $ap=&wparam(1);
29 $bp=&wparam(2);
30
31 &function_begin($name,"");
32
33 &comment("");
34
35 &ld(($a[0])=&NR(1),&QWPw(0,$ap));
36 &ld(($b[0])=&NR(1),&QWPw(0,$bp));
37 &ld(($a[1])=&NR(1),&QWPw(1,$ap));
38 &ld(($b[1])=&NR(1),&QWPw(1,$bp));
39 &mul($a[0],$b[0],($r00)=&NR(1));
40 &ld(($a[2])=&NR(1),&QWPw(2,$ap));
41 &ld(($b[2])=&NR(1),&QWPw(2,$bp));
42 &muh($a[0],$b[0],($r01)=&NR(1));
43 &FR($ap); &ld(($a[3])=&NR(1),&QWPw(3,$ap));
44 &FR($bp); &ld(($b[3])=&NR(1),&QWPw(3,$bp));
45 &mul($a[0],$b[1],($r02)=&NR(1));
46
47 ($R,$H1,$H2)=&NR(3);
48
49 &st($r00,&QWPw(0,$rp)); &FR($r00);
50
51 &mov("zero",$R);
52 &mul($a[1],$b[0],($r03)=&NR(1));
53
54 &mov("zero",$H1);
55 &mov("zero",$H0);
56 &add($R,$r01,$R);
57 &muh($a[0],$b[1],($r04)=&NR(1));
58 &cmpult($R,$r01,($t01)=&NR(1)); &FR($r01);
59 &add($R,$r02,$R);
60 &add($H1,$t01,$H1) &FR($t01);
61 &muh($a[1],$b[0],($r05)=&NR(1));
62 &cmpult($R,$r02,($t02)=&NR(1)); &FR($r02);
63 &add($R,$r03,$R);
64 &add($H2,$t02,$H2) &FR($t02);
65 &mul($a[0],$b[2],($r06)=&NR(1));
66 &cmpult($R,$r03,($t03)=&NR(1)); &FR($r03);
67 &add($H1,$t03,$H1) &FR($t03);
68 &st($R,&QWPw(1,$rp));
69 &add($H1,$H2,$R);
70
71 &mov("zero",$H1);
72 &add($R,$r04,$R);
73 &mov("zero",$H2);
74 &mul($a[1],$b[1],($r07)=&NR(1));
75 &cmpult($R,$r04,($t04)=&NR(1)); &FR($r04);
76 &add($R,$r05,$R);
77 &add($H1,$t04,$H1) &FR($t04);
78 &mul($a[2],$b[0],($r08)=&NR(1));
79 &cmpult($R,$r05,($t05)=&NR(1)); &FR($r05);
80 &add($R,$r01,$R);
81 &add($H2,$t05,$H2) &FR($t05);
82 &muh($a[0],$b[2],($r09)=&NR(1));
83 &cmpult($R,$r06,($t06)=&NR(1)); &FR($r06);
84 &add($R,$r07,$R);
85 &add($H1,$t06,$H1) &FR($t06);
86 &muh($a[1],$b[1],($r10)=&NR(1));
87 &cmpult($R,$r07,($t07)=&NR(1)); &FR($r07);
88 &add($R,$r08,$R);
89 &add($H2,$t07,$H2) &FR($t07);
90 &muh($a[2],$b[0],($r11)=&NR(1));
91 &cmpult($R,$r08,($t08)=&NR(1)); &FR($r08);
92 &add($H1,$t08,$H1) &FR($t08);
93 &st($R,&QWPw(2,$rp));
94 &add($H1,$H2,$R);
95
96 &mov("zero",$H1);
97 &add($R,$r09,$R);
98 &mov("zero",$H2);
99 &mul($a[0],$b[3],($r12)=&NR(1));
100 &cmpult($R,$r09,($t09)=&NR(1)); &FR($r09);
101 &add($R,$r10,$R);
102 &add($H1,$t09,$H1) &FR($t09);
103 &mul($a[1],$b[2],($r13)=&NR(1));
104 &cmpult($R,$r10,($t10)=&NR(1)); &FR($r10);
105 &add($R,$r11,$R);
106 &add($H1,$t10,$H1) &FR($t10);
107 &mul($a[2],$b[1],($r14)=&NR(1));
108 &cmpult($R,$r11,($t11)=&NR(1)); &FR($r11);
109 &add($R,$r12,$R);
110 &add($H1,$t11,$H1) &FR($t11);
111 &mul($a[3],$b[0],($r15)=&NR(1));
112 &cmpult($R,$r12,($t12)=&NR(1)); &FR($r12);
113 &add($R,$r13,$R);
114 &add($H1,$t12,$H1) &FR($t12);
115 &muh($a[0],$b[3],($r16)=&NR(1));
116 &cmpult($R,$r13,($t13)=&NR(1)); &FR($r13);
117 &add($R,$r14,$R);
118 &add($H1,$t13,$H1) &FR($t13);
119 &muh($a[1],$b[2],($r17)=&NR(1));
120 &cmpult($R,$r14,($t14)=&NR(1)); &FR($r14);
121 &add($R,$r15,$R);
122 &add($H1,$t14,$H1) &FR($t14);
123 &muh($a[2],$b[1],($r18)=&NR(1));
124 &cmpult($R,$r15,($t15)=&NR(1)); &FR($r15);
125 &add($H1,$t15,$H1) &FR($t15);
126 &st($R,&QWPw(3,$rp));
127 &add($H1,$H2,$R);
128
129 &mov("zero",$H1);
130 &add($R,$r16,$R);
131 &mov("zero",$H2);
132 &muh($a[3],$b[0],($r19)=&NR(1));
133 &cmpult($R,$r16,($t16)=&NR(1)); &FR($r16);
134 &add($R,$r17,$R);
135 &add($H1,$t16,$H1) &FR($t16);
136 &mul($a[1],$b[3],($r20)=&NR(1));
137 &cmpult($R,$r17,($t17)=&NR(1)); &FR($r17);
138 &add($R,$r18,$R);
139 &add($H1,$t17,$H1) &FR($t17);
140 &mul($a[2],$b[2],($r21)=&NR(1));
141 &cmpult($R,$r18,($t18)=&NR(1)); &FR($r18);
142 &add($R,$r19,$R);
143 &add($H1,$t18,$H1) &FR($t18);
144 &mul($a[3],$b[1],($r22)=&NR(1));
145 &cmpult($R,$r19,($t19)=&NR(1)); &FR($r19);
146 &add($R,$r20,$R);
147 &add($H1,$t19,$H1) &FR($t19);
148 &muh($a[1],$b[3],($r23)=&NR(1));
149 &cmpult($R,$r20,($t20)=&NR(1)); &FR($r20);
150 &add($R,$r21,$R);
151 &add($H1,$t20,$H1) &FR($t20);
152 &muh($a[2],$b[2],($r24)=&NR(1));
153 &cmpult($R,$r21,($t21)=&NR(1)); &FR($r21);
154 &add($R,$r22,$R);
155 &add($H1,$t21,$H1) &FR($t21);
156 &muh($a[3],$b[1],($r25)=&NR(1));
157 &cmpult($R,$r22,($t22)=&NR(1)); &FR($r22);
158 &add($H1,$t22,$H1) &FR($t22);
159 &st($R,&QWPw(4,$rp));
160 &add($H1,$H2,$R);
161
162 &mov("zero",$H1);
163 &add($R,$r23,$R);
164 &mov("zero",$H2);
165 &mul($a[2],$b[3],($r26)=&NR(1));
166 &cmpult($R,$r23,($t23)=&NR(1)); &FR($r23);
167 &add($R,$r24,$R);
168 &add($H1,$t23,$H1) &FR($t23);
169 &mul($a[3],$b[2],($r27)=&NR(1));
170 &cmpult($R,$r24,($t24)=&NR(1)); &FR($r24);
171 &add($R,$r25,$R);
172 &add($H1,$t24,$H1) &FR($t24);
173 &muh($a[2],$b[3],($r28)=&NR(1));
174 &cmpult($R,$r25,($t25)=&NR(1)); &FR($r25);
175 &add($R,$r26,$R);
176 &add($H1,$t25,$H1) &FR($t25);
177 &muh($a[3],$b[2],($r29)=&NR(1));
178 &cmpult($R,$r26,($t26)=&NR(1)); &FR($r26);
179 &add($R,$r27,$R);
180 &add($H1,$t26,$H1) &FR($t26);
181 &mul($a[3],$b[3],($r30)=&NR(1));
182 &cmpult($R,$r27,($t27)=&NR(1)); &FR($r27);
183 &add($H1,$t27,$H1) &FR($t27);
184 &st($R,&QWPw(5,$rp));
185 &add($H1,$H2,$R);
186
187 &mov("zero",$H1);
188 &add($R,$r28,$R);
189 &mov("zero",$H2);
190 &muh($a[3],$b[3],($r31)=&NR(1));
191 &cmpult($R,$r28,($t28)=&NR(1)); &FR($r28);
192 &add($R,$r29,$R);
193 &add($H1,$t28,$H1) &FR($t28);
194 ############
195 &cmpult($R,$r29,($t29)=&NR(1)); &FR($r29);
196 &add($R,$r30,$R);
197 &add($H1,$t29,$H1) &FR($t29);
198 ############
199 &cmpult($R,$r30,($t30)=&NR(1)); &FR($r30);
200 &add($H1,$t30,$H1) &FR($t30);
201 &st($R,&QWPw(6,$rp));
202 &add($H1,$H2,$R);
203
204 &add($R,$r31,$R); &FR($r31);
205 &st($R,&QWPw(7,$rp));
206
207 &FR($R,$H1,$H2);
208 &function_end($name);
209
210 &fin_pool;
211 }
212
2131;
diff --git a/src/lib/libcrypto/bn/asm/alpha.works/mul_c4.works.pl b/src/lib/libcrypto/bn/asm/alpha.works/mul_c4.works.pl
new file mode 100644
index 0000000000..79d86dd25c
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/alpha.works/mul_c4.works.pl
@@ -0,0 +1,98 @@
1#!/usr/local/bin/perl
2# alpha assember
3
4sub mul_add_c
5 {
6 local($a,$b,$c0,$c1,$c2)=@_;
7 local($l1,$h1,$t1,$t2);
8
9print STDERR "count=$cnt\n"; $cnt++;
10 &mul($a,$b,($l1)=&NR(1));
11 &muh($a,$b,($h1)=&NR(1));
12 &add($c0,$l1,$c0);
13 &cmpult($c0,$l1,($t1)=&NR(1)); &FR($l1);
14 &add($t1,$h1,$h1); &FR($t1);
15 &add($c1,$h1,$c1);
16 &cmpult($c1,$h1,($t2)=&NR(1)); &FR($h1);
17 &add($c2,$t2,$c2); &FR($t2);
18 }
19
20sub bn_mul_comba4
21 {
22 local($name)=@_;
23 local(@a,@b,$r,$c0,$c1,$c2);
24
25 $cnt=1;
26 &init_pool(3);
27
28 $rp=&wparam(0);
29 $ap=&wparam(1);
30 $bp=&wparam(2);
31
32 &function_begin($name,"");
33
34 &comment("");
35
36 &ld(($a[0])=&NR(1),&QWPw(0,$ap));
37 &ld(($b[0])=&NR(1),&QWPw(0,$bp));
38 &ld(($a[1])=&NR(1),&QWPw(1,$ap));
39 &ld(($b[1])=&NR(1),&QWPw(1,$bp));
40 &ld(($a[2])=&NR(1),&QWPw(2,$ap));
41 &ld(($b[2])=&NR(1),&QWPw(2,$bp));
42 &ld(($a[3])=&NR(1),&QWPw(3,$ap)); &FR($ap);
43 &ld(($b[3])=&NR(1),&QWPw(3,$bp)); &FR($bp);
44
45 ($c0,$c1,$c2)=&NR(3);
46 &mov("zero",$c2);
47 &mul($a[0],$b[0],$c0);
48 &muh($a[0],$b[0],$c1);
49 &st($c0,&QWPw(0,$rp)); &FR($c0); ($c0)=&NR($c0);
50 ($c0,$c1,$c2)=($c1,$c2,$c0);
51 &mov("zero",$c2);
52
53 &mul_add_c($a[0],$b[1],$c0,$c1,$c2);
54 &mul_add_c($a[1],$b[0],$c0,$c1,$c2);
55 &st($c0,&QWPw(1,$rp)); &FR($c0); ($c0)=&NR($c0);
56 ($c0,$c1,$c2)=($c1,$c2,$c0);
57 &mov("zero",$c2);
58
59 &mul_add_c($a[1],$b[1],$c0,$c1,$c2);
60 &mul_add_c($a[0],$b[2],$c0,$c1,$c2);
61 &mul_add_c($a[2],$b[0],$c0,$c1,$c2);
62 &st($c0,&QWPw(2,$rp)); &FR($c0); ($c0)=&NR($c0);
63 ($c0,$c1,$c2)=($c1,$c2,$c0);
64 &mov("zero",$c2);
65
66 &mul_add_c($a[0],$b[3],$c0,$c1,$c2); &FR($a[0]);
67 &mul_add_c($a[1],$b[2],$c0,$c1,$c2);
68 &mul_add_c($a[2],$b[1],$c0,$c1,$c2);
69 &mul_add_c($a[3],$b[0],$c0,$c1,$c2); &FR($b[0]);
70 &st($c0,&QWPw(3,$rp)); &FR($c0); ($c0)=&NR($c0);
71 ($c0,$c1,$c2)=($c1,$c2,$c0);
72 &mov("zero",$c2);
73
74 &mul_add_c($a[1],$b[3],$c0,$c1,$c2); &FR($a[1]);
75 &mul_add_c($a[2],$b[2],$c0,$c1,$c2);
76 &mul_add_c($a[3],$b[1],$c0,$c1,$c2); &FR($b[1]);
77 &st($c0,&QWPw(4,$rp)); &FR($c0); ($c0)=&NR($c0);
78 ($c0,$c1,$c2)=($c1,$c2,$c0);
79 &mov("zero",$c2);
80
81 &mul_add_c($a[2],$b[3],$c0,$c1,$c2); &FR($a[2]);
82 &mul_add_c($a[3],$b[2],$c0,$c1,$c2); &FR($b[2]);
83 &st($c0,&QWPw(5,$rp)); &FR($c0); ($c0)=&NR($c0);
84 ($c0,$c1,$c2)=($c1,$c2,$c0);
85 &mov("zero",$c2);
86
87 &mul_add_c($a[3],$b[3],$c0,$c1,$c2); &FR($a[3],$b[3]);
88 &st($c0,&QWPw(6,$rp));
89 &st($c1,&QWPw(7,$rp));
90
91 &FR($c0,$c1,$c2);
92
93 &function_end($name);
94
95 &fin_pool;
96 }
97
981;
diff --git a/src/lib/libcrypto/bn/asm/alpha.works/mul_c8.pl b/src/lib/libcrypto/bn/asm/alpha.works/mul_c8.pl
new file mode 100644
index 0000000000..525ca7494b
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/alpha.works/mul_c8.pl
@@ -0,0 +1,177 @@
1#!/usr/local/bin/perl
2# alpha assember
3
4sub bn_mul_comba8
5 {
6 local($name)=@_;
7 local(@a,@b,$r,$c0,$c1,$c2);
8
9 $cnt=1;
10 &init_pool(3);
11
12 $rp=&wparam(0);
13 $ap=&wparam(1);
14 $bp=&wparam(2);
15
16 &function_begin($name,"");
17
18 &comment("");
19
20 &stack_push(2);
21 &ld(($a[0])=&NR(1),&QWPw(0,$ap));
22 &ld(($b[0])=&NR(1),&QWPw(0,$bp));
23 &st($reg_s0,&swtmp(0)); &FR($reg_s0);
24 &st($reg_s1,&swtmp(1)); &FR($reg_s1);
25 &ld(($a[1])=&NR(1),&QWPw(1,$ap));
26 &ld(($b[1])=&NR(1),&QWPw(1,$bp));
27 &ld(($a[2])=&NR(1),&QWPw(2,$ap));
28 &ld(($b[2])=&NR(1),&QWPw(2,$bp));
29 &ld(($a[3])=&NR(1),&QWPw(3,$ap));
30 &ld(($b[3])=&NR(1),&QWPw(3,$bp));
31 &ld(($a[4])=&NR(1),&QWPw(1,$ap));
32 &ld(($b[4])=&NR(1),&QWPw(1,$bp));
33 &ld(($a[5])=&NR(1),&QWPw(1,$ap));
34 &ld(($b[5])=&NR(1),&QWPw(1,$bp));
35 &ld(($a[6])=&NR(1),&QWPw(1,$ap));
36 &ld(($b[6])=&NR(1),&QWPw(1,$bp));
37 &ld(($a[7])=&NR(1),&QWPw(1,$ap)); &FR($ap);
38 &ld(($b[7])=&NR(1),&QWPw(1,$bp)); &FR($bp);
39
40 ($c0,$c1,$c2)=&NR(3);
41 &mov("zero",$c2);
42 &mul($a[0],$b[0],$c0);
43 &muh($a[0],$b[0],$c1);
44 &st($c0,&QWPw(0,$rp)); &FR($c0); ($c0)=&NR(1);
45 ($c0,$c1,$c2)=($c1,$c2,$c0);
46 &mov("zero",$c2);
47
48 &mul_add_c($a[0],$b[1],$c0,$c1,$c2);
49 &mul_add_c($a[1],$b[0],$c0,$c1,$c2);
50 &st($c0,&QWPw(1,$rp)); &FR($c0); ($c0)=&NR(1);
51 ($c0,$c1,$c2)=($c1,$c2,$c0);
52 &mov("zero",$c2);
53
54 &mul_add_c($a[0],$b[2],$c0,$c1,$c2);
55 &mul_add_c($a[1],$b[1],$c0,$c1,$c2);
56 &mul_add_c($a[2],$b[0],$c0,$c1,$c2);
57 &st($c0,&QWPw(2,$rp)); &FR($c0); ($c0)=&NR(1);
58 ($c0,$c1,$c2)=($c1,$c2,$c0);
59 &mov("zero",$c2);
60
61 &mul_add_c($a[0],$b[3],$c0,$c1,$c2);
62 &mul_add_c($a[1],$b[2],$c0,$c1,$c2);
63 &mul_add_c($a[2],$b[1],$c0,$c1,$c2);
64 &mul_add_c($a[3],$b[0],$c0,$c1,$c2);
65 &st($c0,&QWPw(3,$rp)); &FR($c0); ($c0)=&NR(1);
66 ($c0,$c1,$c2)=($c1,$c2,$c0);
67 &mov("zero",$c2);
68
69 &mul_add_c($a[0],$b[4],$c0,$c1,$c2);
70 &mul_add_c($a[1],$b[3],$c0,$c1,$c2);
71 &mul_add_c($a[2],$b[2],$c0,$c1,$c2);
72 &mul_add_c($a[3],$b[1],$c0,$c1,$c2);
73 &mul_add_c($a[4],$b[0],$c0,$c1,$c2);
74 &st($c0,&QWPw(4,$rp)); &FR($c0); ($c0)=&NR(1);
75 ($c0,$c1,$c2)=($c1,$c2,$c0);
76 &mov("zero",$c2);
77
78 &mul_add_c($a[0],$b[5],$c0,$c1,$c2);
79 &mul_add_c($a[1],$b[4],$c0,$c1,$c2);
80 &mul_add_c($a[2],$b[3],$c0,$c1,$c2);
81 &mul_add_c($a[3],$b[2],$c0,$c1,$c2);
82 &mul_add_c($a[4],$b[1],$c0,$c1,$c2);
83 &mul_add_c($a[5],$b[0],$c0,$c1,$c2);
84 &st($c0,&QWPw(5,$rp)); &FR($c0); ($c0)=&NR(1);
85 ($c0,$c1,$c2)=($c1,$c2,$c0);
86 &mov("zero",$c2);
87
88 &mul_add_c($a[0],$b[6],$c0,$c1,$c2);
89 &mul_add_c($a[1],$b[5],$c0,$c1,$c2);
90 &mul_add_c($a[2],$b[4],$c0,$c1,$c2);
91 &mul_add_c($a[3],$b[3],$c0,$c1,$c2);
92 &mul_add_c($a[4],$b[2],$c0,$c1,$c2);
93 &mul_add_c($a[5],$b[1],$c0,$c1,$c2);
94 &mul_add_c($a[6],$b[0],$c0,$c1,$c2);
95 &st($c0,&QWPw(6,$rp)); &FR($c0); ($c0)=&NR(1);
96 ($c0,$c1,$c2)=($c1,$c2,$c0);
97 &mov("zero",$c2);
98
99 &mul_add_c($a[0],$b[7],$c0,$c1,$c2); &FR($a[0]);
100 &mul_add_c($a[1],$b[6],$c0,$c1,$c2);
101 &mul_add_c($a[2],$b[5],$c0,$c1,$c2);
102 &mul_add_c($a[3],$b[4],$c0,$c1,$c2);
103 &mul_add_c($a[4],$b[3],$c0,$c1,$c2);
104 &mul_add_c($a[5],$b[2],$c0,$c1,$c2);
105 &mul_add_c($a[6],$b[1],$c0,$c1,$c2);
106 &mul_add_c($a[7],$b[0],$c0,$c1,$c2); &FR($b[0]);
107 &st($c0,&QWPw(7,$rp)); &FR($c0); ($c0)=&NR(1);
108 ($c0,$c1,$c2)=($c1,$c2,$c0);
109 &mov("zero",$c2);
110
111 &mul_add_c($a[1],$b[7],$c0,$c1,$c2); &FR($a[1]);
112 &mul_add_c($a[2],$b[6],$c0,$c1,$c2);
113 &mul_add_c($a[3],$b[5],$c0,$c1,$c2);
114 &mul_add_c($a[4],$b[4],$c0,$c1,$c2);
115 &mul_add_c($a[5],$b[3],$c0,$c1,$c2);
116 &mul_add_c($a[6],$b[2],$c0,$c1,$c2);
117 &mul_add_c($a[7],$b[1],$c0,$c1,$c2); &FR($b[1]);
118 &st($c0,&QWPw(8,$rp)); &FR($c0); ($c0)=&NR(1);
119 ($c0,$c1,$c2)=($c1,$c2,$c0);
120 &mov("zero",$c2);
121
122 &mul_add_c($a[2],$b[7],$c0,$c1,$c2); &FR($a[2]);
123 &mul_add_c($a[3],$b[6],$c0,$c1,$c2);
124 &mul_add_c($a[4],$b[5],$c0,$c1,$c2);
125 &mul_add_c($a[5],$b[4],$c0,$c1,$c2);
126 &mul_add_c($a[6],$b[3],$c0,$c1,$c2);
127 &mul_add_c($a[7],$b[2],$c0,$c1,$c2); &FR($b[2]);
128 &st($c0,&QWPw(9,$rp)); &FR($c0); ($c0)=&NR(1);
129 ($c0,$c1,$c2)=($c1,$c2,$c0);
130 &mov("zero",$c2);
131
132 &mul_add_c($a[3],$b[7],$c0,$c1,$c2); &FR($a[3]);
133 &mul_add_c($a[4],$b[6],$c0,$c1,$c2);
134 &mul_add_c($a[5],$b[5],$c0,$c1,$c2);
135 &mul_add_c($a[6],$b[4],$c0,$c1,$c2);
136 &mul_add_c($a[7],$b[3],$c0,$c1,$c2); &FR($b[3]);
137 &st($c0,&QWPw(10,$rp)); &FR($c0); ($c0)=&NR(1);
138 ($c0,$c1,$c2)=($c1,$c2,$c0);
139 &mov("zero",$c2);
140
141 &mul_add_c($a[4],$b[7],$c0,$c1,$c2); &FR($a[4]);
142 &mul_add_c($a[5],$b[6],$c0,$c1,$c2);
143 &mul_add_c($a[6],$b[5],$c0,$c1,$c2);
144 &mul_add_c($a[7],$b[4],$c0,$c1,$c2); &FR($b[4]);
145 &st($c0,&QWPw(11,$rp)); &FR($c0); ($c0)=&NR(1);
146 ($c0,$c1,$c2)=($c1,$c2,$c0);
147 &mov("zero",$c2);
148
149 &mul_add_c($a[5],$b[7],$c0,$c1,$c2); &FR($a[5]);
150 &mul_add_c($a[6],$b[6],$c0,$c1,$c2);
151 &mul_add_c($a[7],$b[5],$c0,$c1,$c2); &FR($b[5]);
152 &st($c0,&QWPw(12,$rp)); &FR($c0); ($c0)=&NR(1);
153 ($c0,$c1,$c2)=($c1,$c2,$c0);
154 &mov("zero",$c2);
155
156 &mul_add_c($a[6],$b[7],$c0,$c1,$c2); &FR($a[6]);
157 &mul_add_c($a[7],$b[6],$c0,$c1,$c2); &FR($b[6]);
158 &st($c0,&QWPw(13,$rp)); &FR($c0); ($c0)=&NR(1);
159 ($c0,$c1,$c2)=($c1,$c2,$c0);
160 &mov("zero",$c2);
161
162 &mul_add_c($a[7],$b[7],$c0,$c1,$c2); &FR($a[7],$b[7]);
163 &st($c0,&QWPw(14,$rp));
164 &st($c1,&QWPw(15,$rp));
165
166 &FR($c0,$c1,$c2);
167
168 &ld($reg_s0,&swtmp(0));
169 &ld($reg_s1,&swtmp(1));
170 &stack_pop(2);
171
172 &function_end($name);
173
174 &fin_pool;
175 }
176
1771;
diff --git a/src/lib/libcrypto/bn/asm/alpha.works/sqr.pl b/src/lib/libcrypto/bn/asm/alpha.works/sqr.pl
new file mode 100644
index 0000000000..a55b696906
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/alpha.works/sqr.pl
@@ -0,0 +1,113 @@
1#!/usr/local/bin/perl
2# alpha assember
3
4sub bn_sqr_words
5 {
6 local($name)=@_;
7 local($cc,$a,$b,$r,$couny);
8
9 &init_pool(3);
10 ($cc)=GR("r0");
11
12 $rp=&wparam(0);
13 $ap=&wparam(1);
14 $count=&wparam(2);
15
16 &function_begin($name,"");
17
18 &comment("");
19 &sub($count,4,$count);
20 &mov("zero",$cc);
21 &br(&label("finish"));
22 &blt($count,&label("finish"));
23
24 ($a0,$r0)=&NR(2);
25 &ld($a0,&QWPw(0,$ap));
26 &ld($r0,&QWPw(0,$rp));
27
28$a=<<'EOF';
29##########################################################
30 &set_label("loop");
31
32 ($a1)=&NR(1); &ld($a1,&QWPw(1,$ap));
33 ($b1)=&NR(1); &ld($b1,&QWPw(1,$bp));
34 ($a2)=&NR(1); &ld($a2,&QWPw(2,$ap));
35 ($b2)=&NR(1); &ld($b2,&QWPw(2,$bp));
36 ($a3)=&NR(1); &ld($a3,&QWPw(3,$ap));
37 ($b3)=&NR(1); &ld($b3,&QWPw(3,$bp));
38
39 ($o0,$t0)=&NR(2);
40 &add($a0,$b0,$o0);
41 &cmpult($o0,$b0,$t0);
42 &add($o0,$cc,$o0);
43 &cmpult($o0,$cc,$cc);
44 &add($cc,$t0,$cc); &FR($t0);
45
46 ($t1,$o1)=&NR(2);
47
48 &add($a1,$b1,$o1); &FR($a1);
49 &cmpult($o1,$b1,$t1); &FR($b1);
50 &add($o1,$cc,$o1);
51 &cmpult($o1,$cc,$cc);
52 &add($cc,$t1,$cc); &FR($t1);
53
54 ($t2,$o2)=&NR(2);
55
56 &add($a2,$b2,$o2); &FR($a2);
57 &cmpult($o2,$b2,$t2); &FR($b2);
58 &add($o2,$cc,$o2);
59 &cmpult($o2,$cc,$cc);
60 &add($cc,$t2,$cc); &FR($t2);
61
62 ($t3,$o3)=&NR(2);
63
64 &add($a3,$b3,$o3); &FR($a3);
65 &cmpult($o3,$b3,$t3); &FR($b3);
66 &add($o3,$cc,$o3);
67 &cmpult($o3,$cc,$cc);
68 &add($cc,$t3,$cc); &FR($t3);
69
70 &st($o0,&QWPw(0,$rp)); &FR($o0);
71 &st($o1,&QWPw(0,$rp)); &FR($o1);
72 &st($o2,&QWPw(0,$rp)); &FR($o2);
73 &st($o3,&QWPw(0,$rp)); &FR($o3);
74
75 &sub($count,4,$count); # count-=4
76 &add($ap,4*$QWS,$ap); # count+=4
77 &add($bp,4*$QWS,$bp); # count+=4
78 &add($rp,4*$QWS,$rp); # count+=4
79
80 &blt($count,&label("finish"));
81 &ld($a0,&QWPw(0,$ap));
82 &ld($b0,&QWPw(0,$bp));
83 &br(&label("loop"));
84EOF
85##################################################
86 # Do the last 0..3 words
87
88 &set_label("last_loop");
89
90 &ld(($a0)=&NR(1),&QWPw(0,$ap)); # get a
91 &mul($a0,$a0,($l0)=&NR(1));
92 &add($ap,$QWS,$ap);
93 &add($rp,2*$QWS,$rp);
94 &sub($count,1,$count);
95 &muh($a0,$a0,($h0)=&NR(1)); &FR($a0);
96 &st($l0,&QWPw(-2,$rp)); &FR($l0);
97 &st($h0,&QWPw(-1,$rp)); &FR($h0);
98
99 &bgt($count,&label("last_loop"));
100 &function_end_A($name);
101
102######################################################
103 &set_label("finish");
104 &add($count,4,$count);
105 &bgt($count,&label("last_loop"));
106
107 &set_label("end");
108 &function_end($name);
109
110 &fin_pool;
111 }
112
1131;
diff --git a/src/lib/libcrypto/bn/asm/alpha.works/sqr_c4.pl b/src/lib/libcrypto/bn/asm/alpha.works/sqr_c4.pl
new file mode 100644
index 0000000000..bf33f5b503
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/alpha.works/sqr_c4.pl
@@ -0,0 +1,109 @@
1#!/usr/local/bin/perl
2# alpha assember
3
4sub sqr_add_c
5 {
6 local($a,$c0,$c1,$c2)=@_;
7 local($l1,$h1,$t1,$t2);
8
9 &mul($a,$a,($l1)=&NR(1));
10 &muh($a,$a,($h1)=&NR(1));
11 &add($c0,$l1,$c0);
12 &add($c1,$h1,$c1);
13 &cmpult($c0,$l1,($t1)=&NR(1)); &FR($l1);
14 &cmpult($c1,$h1,($t2)=&NR(1)); &FR($h1);
15 &add($c1,$t1,$c1); &FR($t1);
16 &add($c2,$t2,$c2); &FR($t2);
17 }
18
19sub sqr_add_c2
20 {
21 local($a,$b,$c0,$c1,$c2)=@_;
22 local($l1,$h1,$t1,$t2);
23
24 &mul($a,$b,($l1)=&NR(1));
25 &muh($a,$b,($h1)=&NR(1));
26 &cmplt($l1,"zero",($lc1)=&NR(1));
27 &cmplt($h1,"zero",($hc1)=&NR(1));
28 &add($l1,$l1,$l1);
29 &add($h1,$h1,$h1);
30 &add($h1,$lc1,$h1); &FR($lc1);
31 &add($c2,$hc1,$c2); &FR($hc1);
32
33 &add($c0,$l1,$c0);
34 &add($c1,$h1,$c1);
35 &cmpult($c0,$l1,($lc1)=&NR(1)); &FR($l1);
36 &cmpult($c1,$h1,($hc1)=&NR(1)); &FR($h1);
37
38 &add($c1,$lc1,$c1); &FR($lc1);
39 &add($c2,$hc1,$c2); &FR($hc1);
40 }
41
42
43sub bn_sqr_comba4
44 {
45 local($name)=@_;
46 local(@a,@b,$r,$c0,$c1,$c2);
47
48 $cnt=1;
49 &init_pool(2);
50
51 $rp=&wparam(0);
52 $ap=&wparam(1);
53
54 &function_begin($name,"");
55
56 &comment("");
57
58 &ld(($a[0])=&NR(1),&QWPw(0,$ap));
59 &ld(($a[1])=&NR(1),&QWPw(1,$ap));
60 &ld(($a[2])=&NR(1),&QWPw(2,$ap));
61 &ld(($a[3])=&NR(1),&QWPw(3,$ap)); &FR($ap);
62
63 ($c0,$c1,$c2)=&NR(3);
64
65 &mov("zero",$c2);
66 &mul($a[0],$a[0],$c0);
67 &muh($a[0],$a[0],$c1);
68 &st($c0,&QWPw(0,$rp));
69 ($c0,$c1,$c2)=($c1,$c2,$c0);
70 &mov("zero",$c2);
71
72 &sqr_add_c2($a[0],$a[1],$c0,$c1,$c2);
73 &st($c0,&QWPw(1,$rp));
74 ($c0,$c1,$c2)=($c1,$c2,$c0);
75 &mov("zero",$c2);
76
77 &sqr_add_c($a[1],$c0,$c1,$c2);
78 &sqr_add_c2($a[2],$a[0],$c0,$c1,$c2);
79 &st($c0,&QWPw(2,$rp));
80 ($c0,$c1,$c2)=($c1,$c2,$c0);
81 &mov("zero",$c2);
82
83 &sqr_add_c2($a[3],$a[0],$c0,$c1,$c2);
84 &sqr_add_c2($a[2],$a[1],$c0,$c1,$c2);
85 &st($c0,&QWPw(3,$rp));
86 ($c0,$c1,$c2)=($c1,$c2,$c0);
87 &mov("zero",$c2);
88
89 &sqr_add_c($a[2],$c0,$c1,$c2);
90 &sqr_add_c2($a[3],$a[1],$c0,$c1,$c2);
91 &st($c0,&QWPw(4,$rp));
92 ($c0,$c1,$c2)=($c1,$c2,$c0);
93 &mov("zero",$c2);
94
95 &sqr_add_c2($a[3],$a[2],$c0,$c1,$c2);
96 &st($c0,&QWPw(5,$rp));
97 ($c0,$c1,$c2)=($c1,$c2,$c0);
98 &mov("zero",$c2);
99
100 &sqr_add_c($a[3],$c0,$c1,$c2);
101 &st($c0,&QWPw(6,$rp));
102 &st($c1,&QWPw(7,$rp));
103
104 &function_end($name);
105
106 &fin_pool;
107 }
108
1091;
diff --git a/src/lib/libcrypto/bn/asm/alpha.works/sqr_c8.pl b/src/lib/libcrypto/bn/asm/alpha.works/sqr_c8.pl
new file mode 100644
index 0000000000..b4afe085f1
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/alpha.works/sqr_c8.pl
@@ -0,0 +1,132 @@
1#!/usr/local/bin/perl
2# alpha assember
3
4sub bn_sqr_comba8
5 {
6 local($name)=@_;
7 local(@a,@b,$r,$c0,$c1,$c2);
8
9 $cnt=1;
10 &init_pool(2);
11
12 $rp=&wparam(0);
13 $ap=&wparam(1);
14
15 &function_begin($name,"");
16
17 &comment("");
18
19 &ld(($a[0])=&NR(1),&QWPw(0,$ap));
20 &ld(($a[1])=&NR(1),&QWPw(1,$ap));
21 &ld(($a[2])=&NR(1),&QWPw(2,$ap));
22 &ld(($a[3])=&NR(1),&QWPw(3,$ap));
23 &ld(($a[4])=&NR(1),&QWPw(4,$ap));
24 &ld(($a[5])=&NR(1),&QWPw(5,$ap));
25 &ld(($a[6])=&NR(1),&QWPw(6,$ap));
26 &ld(($a[7])=&NR(1),&QWPw(7,$ap)); &FR($ap);
27
28 ($c0,$c1,$c2)=&NR(3);
29
30 &mov("zero",$c2);
31 &mul($a[0],$a[0],$c0);
32 &muh($a[0],$a[0],$c1);
33 &st($c0,&QWPw(0,$rp));
34 ($c0,$c1,$c2)=($c1,$c2,$c0);
35 &mov("zero",$c2);
36
37 &sqr_add_c2($a[1],$a[0],$c0,$c1,$c2);
38 &st($c0,&QWPw(1,$rp));
39 ($c0,$c1,$c2)=($c1,$c2,$c0);
40 &mov("zero",$c2);
41
42 &sqr_add_c($a[1],$c0,$c1,$c2);
43 &sqr_add_c2($a[2],$a[0],$c0,$c1,$c2);
44 &st($c0,&QWPw(2,$rp));
45 ($c0,$c1,$c2)=($c1,$c2,$c0);
46 &mov("zero",$c2);
47
48 &sqr_add_c2($a[2],$a[1],$c0,$c1,$c2);
49 &sqr_add_c2($a[3],$a[0],$c0,$c1,$c2);
50 &st($c0,&QWPw(3,$rp));
51 ($c0,$c1,$c2)=($c1,$c2,$c0);
52 &mov("zero",$c2);
53
54 &sqr_add_c($a[2],$c0,$c1,$c2);
55 &sqr_add_c2($a[3],$a[1],$c0,$c1,$c2);
56 &sqr_add_c2($a[4],$a[0],$c0,$c1,$c2);
57 &st($c0,&QWPw(4,$rp));
58 ($c0,$c1,$c2)=($c1,$c2,$c0);
59 &mov("zero",$c2);
60
61 &sqr_add_c2($a[3],$a[2],$c0,$c1,$c2);
62 &sqr_add_c2($a[4],$a[1],$c0,$c1,$c2);
63 &sqr_add_c2($a[5],$a[0],$c0,$c1,$c2);
64 &st($c0,&QWPw(5,$rp));
65 ($c0,$c1,$c2)=($c1,$c2,$c0);
66 &mov("zero",$c2);
67
68 &sqr_add_c($a[3],$c0,$c1,$c2);
69 &sqr_add_c2($a[4],$a[2],$c0,$c1,$c2);
70 &sqr_add_c2($a[5],$a[1],$c0,$c1,$c2);
71 &sqr_add_c2($a[6],$a[0],$c0,$c1,$c2);
72 &st($c0,&QWPw(6,$rp));
73 ($c0,$c1,$c2)=($c1,$c2,$c0);
74 &mov("zero",$c2);
75
76 &sqr_add_c2($a[4],$a[3],$c0,$c1,$c2);
77 &sqr_add_c2($a[5],$a[2],$c0,$c1,$c2);
78 &sqr_add_c2($a[6],$a[1],$c0,$c1,$c2);
79 &sqr_add_c2($a[7],$a[0],$c0,$c1,$c2);
80 &st($c0,&QWPw(7,$rp));
81 ($c0,$c1,$c2)=($c1,$c2,$c0);
82 &mov("zero",$c2);
83
84 &sqr_add_c($a[4],$c0,$c1,$c2);
85 &sqr_add_c2($a[5],$a[3],$c0,$c1,$c2);
86 &sqr_add_c2($a[6],$a[2],$c0,$c1,$c2);
87 &sqr_add_c2($a[7],$a[1],$c0,$c1,$c2);
88 &st($c0,&QWPw(8,$rp));
89 ($c0,$c1,$c2)=($c1,$c2,$c0);
90 &mov("zero",$c2);
91
92 &sqr_add_c2($a[5],$a[4],$c0,$c1,$c2);
93 &sqr_add_c2($a[6],$a[3],$c0,$c1,$c2);
94 &sqr_add_c2($a[7],$a[2],$c0,$c1,$c2);
95 &st($c0,&QWPw(9,$rp));
96 ($c0,$c1,$c2)=($c1,$c2,$c0);
97 &mov("zero",$c2);
98
99 &sqr_add_c($a[5],$c0,$c1,$c2);
100 &sqr_add_c2($a[6],$a[4],$c0,$c1,$c2);
101 &sqr_add_c2($a[7],$a[3],$c0,$c1,$c2);
102 &st($c0,&QWPw(10,$rp));
103 ($c0,$c1,$c2)=($c1,$c2,$c0);
104 &mov("zero",$c2);
105
106 &sqr_add_c2($a[6],$a[5],$c0,$c1,$c2);
107 &sqr_add_c2($a[7],$a[4],$c0,$c1,$c2);
108 &st($c0,&QWPw(11,$rp));
109 ($c0,$c1,$c2)=($c1,$c2,$c0);
110 &mov("zero",$c2);
111
112 &sqr_add_c($a[6],$c0,$c1,$c2);
113 &sqr_add_c2($a[7],$a[5],$c0,$c1,$c2);
114 &st($c0,&QWPw(12,$rp));
115 ($c0,$c1,$c2)=($c1,$c2,$c0);
116 &mov("zero",$c2);
117
118 &sqr_add_c2($a[7],$a[6],$c0,$c1,$c2);
119 &st($c0,&QWPw(13,$rp));
120 ($c0,$c1,$c2)=($c1,$c2,$c0);
121 &mov("zero",$c2);
122
123 &sqr_add_c($a[7],$c0,$c1,$c2);
124 &st($c0,&QWPw(14,$rp));
125 &st($c1,&QWPw(15,$rp));
126
127 &function_end($name);
128
129 &fin_pool;
130 }
131
1321;
diff --git a/src/lib/libcrypto/bn/asm/alpha.works/sub.pl b/src/lib/libcrypto/bn/asm/alpha.works/sub.pl
new file mode 100644
index 0000000000..d998da5c21
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/alpha.works/sub.pl
@@ -0,0 +1,108 @@
1#!/usr/local/bin/perl
2# alpha assember
3
4sub bn_sub_words
5 {
6 local($name)=@_;
7 local($cc,$a,$b,$r);
8
9 &init_pool(4);
10 ($cc)=GR("r0");
11
12 $rp=&wparam(0);
13 $ap=&wparam(1);
14 $bp=&wparam(2);
15 $count=&wparam(3);
16
17 &function_begin($name,"");
18
19 &comment("");
20 &sub($count,4,$count);
21 &mov("zero",$cc);
22 &blt($count,&label("finish"));
23
24 ($a0,$b0)=&NR(2);
25 &ld($a0,&QWPw(0,$ap));
26 &ld($b0,&QWPw(0,$bp));
27
28##########################################################
29 &set_label("loop");
30
31 ($a1,$tmp,$b1,$a2,$b2,$a3,$b3,$o0)=&NR(8);
32 &ld($a1,&QWPw(1,$ap));
33 &cmpult($a0,$b0,$tmp); # will we borrow?
34 &ld($b1,&QWPw(1,$bp));
35 &sub($a0,$b0,$a0); # do the subtract
36 &ld($a2,&QWPw(2,$ap));
37 &cmpult($a0,$cc,$b0); # will we borrow?
38 &ld($b2,&QWPw(2,$bp));
39 &sub($a0,$cc,$o0); # will we borrow?
40 &ld($a3,&QWPw(3,$ap));
41 &add($b0,$tmp,$cc); ($t1,$o1)=&NR(2); &FR($tmp);
42
43 &cmpult($a1,$b1,$t1); # will we borrow?
44 &sub($a1,$b1,$a1); # do the subtract
45 &ld($b3,&QWPw(3,$bp));
46 &cmpult($a1,$cc,$b1); # will we borrow?
47 &sub($a1,$cc,$o1); # will we borrow?
48 &add($b1,$t1,$cc); ($tmp,$o2)=&NR(2); &FR($t1,$a1,$b1);
49
50 &cmpult($a2,$b2,$tmp); # will we borrow?
51 &sub($a2,$b2,$a2); # do the subtract
52 &st($o0,&QWPw(0,$rp)); &FR($o0); # save
53 &cmpult($a2,$cc,$b2); # will we borrow?
54 &sub($a2,$cc,$o2); # will we borrow?
55 &add($b2,$tmp,$cc); ($t3,$o3)=&NR(2); &FR($tmp,$a2,$b2);
56
57 &cmpult($a3,$b3,$t3); # will we borrow?
58 &sub($a3,$b3,$a3); # do the subtract
59 &st($o1,&QWPw(1,$rp)); &FR($o1);
60 &cmpult($a3,$cc,$b3); # will we borrow?
61 &sub($a3,$cc,$o3); # will we borrow?
62 &add($b3,$t3,$cc); &FR($t3,$a3,$b3);
63
64 &st($o2,&QWPw(2,$rp)); &FR($o2);
65 &sub($count,4,$count); # count-=4
66 &st($o3,&QWPw(3,$rp)); &FR($o3);
67 &add($ap,4*$QWS,$ap); # count+=4
68 &add($bp,4*$QWS,$bp); # count+=4
69 &add($rp,4*$QWS,$rp); # count+=4
70
71 &blt($count,&label("finish"));
72 &ld($a0,&QWPw(0,$ap));
73 &ld($b0,&QWPw(0,$bp));
74 &br(&label("loop"));
75##################################################
76 # Do the last 0..3 words
77
78 &set_label("last_loop");
79
80 &ld($a0,&QWPw(0,$ap)); # get a
81 &ld($b0,&QWPw(0,$bp)); # get b
82 &cmpult($a0,$b0,$tmp); # will we borrow?
83 &sub($a0,$b0,$a0); # do the subtract
84 &cmpult($a0,$cc,$b0); # will we borrow?
85 &sub($a0,$cc,$a0); # will we borrow?
86 &st($a0,&QWPw(0,$rp)); # save
87 &add($b0,$tmp,$cc); # add the borrows
88
89 &add($ap,$QWS,$ap);
90 &add($bp,$QWS,$bp);
91 &add($rp,$QWS,$rp);
92 &sub($count,1,$count);
93 &bgt($count,&label("last_loop"));
94 &function_end_A($name);
95
96######################################################
97 &set_label("finish");
98 &add($count,4,$count);
99 &bgt($count,&label("last_loop"));
100
101 &FR($a0,$b0);
102 &set_label("end");
103 &function_end($name);
104
105 &fin_pool;
106 }
107
1081;
diff --git a/src/lib/libcrypto/bn/asm/alpha/add.pl b/src/lib/libcrypto/bn/asm/alpha/add.pl
new file mode 100644
index 0000000000..13bf516428
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/alpha/add.pl
@@ -0,0 +1,118 @@
1#!/usr/local/bin/perl
2# alpha assember
3
4sub bn_add_words
5 {
6 local($name)=@_;
7 local($cc,$a,$b,$r);
8
9 &init_pool(4);
10 ($cc)=GR("r0");
11
12 $rp=&wparam(0);
13 $ap=&wparam(1);
14 $bp=&wparam(2);
15 $count=&wparam(3);
16
17 &function_begin($name,"");
18
19 &comment("");
20 &sub($count,4,$count);
21 &mov("zero",$cc);
22 &blt($count,&label("finish"));
23
24 ($a0,$b0)=&NR(2);
25
26##########################################################
27 &set_label("loop");
28
29 &ld(($a0)=&NR(1),&QWPw(0,$ap));
30 &ld(($b0)=&NR(1),&QWPw(0,$bp));
31 &ld(($a1)=&NR(1),&QWPw(1,$ap));
32 &ld(($b1)=&NR(1),&QWPw(1,$bp));
33
34 ($o0,$t0)=&NR(2);
35 &add($a0,$b0,$o0);
36 &ld(($a2)=&NR(1),&QWPw(2,$ap));
37 &cmpult($o0,$b0,$t0);
38 &add($o0,$cc,$o0);
39 &cmpult($o0,$cc,$cc);
40 &ld(($b2)=&NR(1),&QWPw(2,$bp));
41 &add($cc,$t0,$cc); &FR($t0);
42
43 ($t1,$o1)=&NR(2);
44
45 &add($a1,$b1,$o1); &FR($a1);
46 &cmpult($o1,$b1,$t1); &FR($b1);
47 &add($o1,$cc,$o1);
48 &cmpult($o1,$cc,$cc);
49 &ld(($a3)=&NR(1),&QWPw(3,$ap));
50 &add($cc,$t1,$cc); &FR($t1);
51
52 ($t2,$o2)=&NR(2);
53
54 &add($a2,$b2,$o2); &FR($a2);
55 &cmpult($o2,$b2,$t2); &FR($b2);
56 &add($o2,$cc,$o2);
57 &cmpult($o2,$cc,$cc);
58 &ld(($b3)=&NR(1),&QWPw(3,$bp));
59 &st($o0,&QWPw(0,$rp)); &FR($o0);
60 &add($cc,$t2,$cc); &FR($t2);
61
62 ($t3,$o3)=&NR(2);
63
64 &st($o1,&QWPw(0,$rp)); &FR($o1);
65 &add($a3,$b3,$o3); &FR($a3);
66 &cmpult($o3,$b3,$t3); &FR($b3);
67 &add($o3,$cc,$o3);
68 &st($o2,&QWPw(0,$rp)); &FR($o2);
69 &cmpult($o3,$cc,$cc);
70 &st($o3,&QWPw(0,$rp)); &FR($o3);
71 &add($cc,$t3,$cc); &FR($t3);
72
73
74 &sub($count,4,$count); # count-=4
75 &add($ap,4*$QWS,$ap); # count+=4
76 &add($bp,4*$QWS,$bp); # count+=4
77 &add($rp,4*$QWS,$rp); # count+=4
78
79 ###
80 &bge($count,&label("loop"));
81 ###
82 &br(&label("finish"));
83##################################################
84 # Do the last 0..3 words
85
86 ($t0,$o0)=&NR(2);
87 &set_label("last_loop");
88
89 &ld($a0,&QWPw(0,$ap)); # get a
90 &ld($b0,&QWPw(0,$bp)); # get b
91 &add($ap,$QWS,$ap);
92 &add($bp,$QWS,$bp);
93 &add($a0,$b0,$o0);
94 &sub($count,1,$count);
95 &cmpult($o0,$b0,$t0); # will we borrow?
96 &add($o0,$cc,$o0); # will we borrow?
97 &cmpult($o0,$cc,$cc); # will we borrow?
98 &add($rp,$QWS,$rp);
99 &st($o0,&QWPw(-1,$rp)); # save
100 &add($cc,$t0,$cc); # add the borrows
101
102 ###
103 &bgt($count,&label("last_loop"));
104 &function_end_A($name);
105
106######################################################
107 &set_label("finish");
108 &add($count,4,$count);
109 &bgt($count,&label("last_loop"));
110
111 &FR($o0,$t0,$a0,$b0);
112 &set_label("end");
113 &function_end($name);
114
115 &fin_pool;
116 }
117
1181;
diff --git a/src/lib/libcrypto/bn/asm/alpha/div.pl b/src/lib/libcrypto/bn/asm/alpha/div.pl
new file mode 100644
index 0000000000..e9e680897a
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/alpha/div.pl
@@ -0,0 +1,144 @@
1#!/usr/local/bin/perl
2
3sub bn_div_words
4 {
5 local($data)=<<'EOF';
6 #
7 # What follows was taken directly from the C compiler with a few
8 # hacks to redo the lables.
9 #
10.text
11 .set noreorder
12 .set volatile
13 .align 3
14 .globl bn_div_words
15 .ent bn_div_words
16bn_div_words
17 ldgp $29,0($27)
18bn_div_words.ng:
19 lda $30,-48($30)
20 .frame $30,48,$26,0
21 stq $26,0($30)
22 stq $9,8($30)
23 stq $10,16($30)
24 stq $11,24($30)
25 stq $12,32($30)
26 stq $13,40($30)
27 .mask 0x4003e00,-48
28 .prologue 1
29 bis $16,$16,$9
30 bis $17,$17,$10
31 bis $18,$18,$11
32 bis $31,$31,$13
33 bis $31,2,$12
34 bne $11,$9119
35 lda $0,-1
36 br $31,$9136
37 .align 4
38$9119:
39 bis $11,$11,$16
40 jsr $26,BN_num_bits_word
41 ldgp $29,0($26)
42 subq $0,64,$1
43 beq $1,$9120
44 bis $31,1,$1
45 sll $1,$0,$1
46 cmpule $9,$1,$1
47 bne $1,$9120
48 # lda $16,_IO_stderr_
49 # lda $17,$C32
50 # bis $0,$0,$18
51 # jsr $26,fprintf
52 # ldgp $29,0($26)
53 jsr $26,abort
54 ldgp $29,0($26)
55 .align 4
56$9120:
57 bis $31,64,$3
58 cmpult $9,$11,$2
59 subq $3,$0,$1
60 addl $1,$31,$0
61 subq $9,$11,$1
62 cmoveq $2,$1,$9
63 beq $0,$9122
64 zapnot $0,15,$2
65 subq $3,$0,$1
66 sll $11,$2,$11
67 sll $9,$2,$3
68 srl $10,$1,$1
69 sll $10,$2,$10
70 bis $3,$1,$9
71$9122:
72 srl $11,32,$5
73 zapnot $11,15,$6
74 lda $7,-1
75 .align 5
76$9123:
77 srl $9,32,$1
78 subq $1,$5,$1
79 bne $1,$9126
80 zapnot $7,15,$27
81 br $31,$9127
82 .align 4
83$9126:
84 bis $9,$9,$24
85 bis $5,$5,$25
86 divqu $24,$25,$27
87$9127:
88 srl $10,32,$4
89 .align 5
90$9128:
91 mulq $27,$5,$1
92 subq $9,$1,$3
93 zapnot $3,240,$1
94 bne $1,$9129
95 mulq $6,$27,$2
96 sll $3,32,$1
97 addq $1,$4,$1
98 cmpule $2,$1,$2
99 bne $2,$9129
100 subq $27,1,$27
101 br $31,$9128
102 .align 4
103$9129:
104 mulq $27,$6,$1
105 mulq $27,$5,$4
106 srl $1,32,$3
107 sll $1,32,$1
108 addq $4,$3,$4
109 cmpult $10,$1,$2
110 subq $10,$1,$10
111 addq $2,$4,$2
112 cmpult $9,$2,$1
113 bis $2,$2,$4
114 beq $1,$9134
115 addq $9,$11,$9
116 subq $27,1,$27
117$9134:
118 subl $12,1,$12
119 subq $9,$4,$9
120 beq $12,$9124
121 sll $27,32,$13
122 sll $9,32,$2
123 srl $10,32,$1
124 sll $10,32,$10
125 bis $2,$1,$9
126 br $31,$9123
127 .align 4
128$9124:
129 bis $13,$27,$0
130$9136:
131 ldq $26,0($30)
132 ldq $9,8($30)
133 ldq $10,16($30)
134 ldq $11,24($30)
135 ldq $12,32($30)
136 ldq $13,40($30)
137 addq $30,48,$30
138 ret $31,($26),1
139 .end bn_div_words
140EOF
141 &asm_add($data);
142 }
143
1441;
diff --git a/src/lib/libcrypto/bn/asm/alpha/mul.pl b/src/lib/libcrypto/bn/asm/alpha/mul.pl
new file mode 100644
index 0000000000..76c926566c
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/alpha/mul.pl
@@ -0,0 +1,104 @@
1#!/usr/local/bin/perl
2# alpha assember
3
4sub bn_mul_words
5 {
6 local($name)=@_;
7 local($cc,$a,$b,$r,$couny);
8
9 &init_pool(4);
10 ($cc)=GR("r0");
11
12 $rp=&wparam(0);
13 $ap=&wparam(1);
14 $count=&wparam(2);
15 $word=&wparam(3);
16
17 &function_begin($name,"");
18
19 &comment("");
20 &sub($count,4,$count);
21 &mov("zero",$cc);
22 ###
23 &blt($count,&label("finish"));
24
25 ($a0)=&NR(1); &ld($a0,&QWPw(0,$ap));
26
27 &set_label("loop");
28
29 ($a1)=&NR(1); &ld($a1,&QWPw(1,$ap));
30 ($a2)=&NR(1); &ld($a2,&QWPw(2,$ap));
31
32 &muh($a0,$word,($h0)=&NR(1)); &FR($a0);
33 ($a3)=&NR(1); &ld($a3,&QWPw(3,$ap));
34 ### wait 8
35 &mul($a0,$word,($l0)=&NR(1)); &FR($a0);
36 ### wait 8
37 &muh($a1,$word,($h1)=&NR(1)); &FR($a1);
38 &add($l0,$cc,$l0); ### wait 8
39 &mul($a1,$word,($l1)=&NR(1)); &FR($a1);
40 &cmpult($l0,$cc,$cc); ### wait 8
41 &muh($a2,$word,($h2)=&NR(1)); &FR($a2);
42 &add($h0,$cc,$cc); &FR($h0); ### wait 8
43 &mul($a2,$word,($l2)=&NR(1)); &FR($a2);
44 &add($l1,$cc,$l1); ### wait 8
45 &st($l0,&QWPw(0,$rp)); &FR($l0);
46 &cmpult($l1,$cc,$cc); ### wait 8
47 &muh($a3,$word,($h3)=&NR(1)); &FR($a3);
48 &add($h1,$cc,$cc); &FR($h1);
49 &mul($a3,$word,($l3)=&NR(1)); &FR($a3);
50 &add($l2,$cc,$l2);
51 &st($l1,&QWPw(1,$rp)); &FR($l1);
52 &cmpult($l2,$cc,$cc);
53 &add($h2,$cc,$cc); &FR($h2);
54 &sub($count,4,$count); # count-=4
55 &st($l2,&QWPw(2,$rp)); &FR($l2);
56 &add($l3,$cc,$l3);
57 &cmpult($l3,$cc,$cc);
58 &add($bp,4*$QWS,$bp); # count+=4
59 &add($h3,$cc,$cc); &FR($h3);
60 &add($ap,4*$QWS,$ap); # count+=4
61 &st($l3,&QWPw(3,$rp)); &FR($l3);
62 &add($rp,4*$QWS,$rp); # count+=4
63 ###
64 &blt($count,&label("finish"));
65 ($a0)=&NR(1); &ld($a0,&QWPw(0,$ap));
66 &br(&label("finish"));
67##################################################
68
69##################################################
70 # Do the last 0..3 words
71
72 &set_label("last_loop");
73
74 &ld(($a0)=&NR(1),&QWPw(0,$ap)); # get a
75 ###
76 ###
77 ###
78 &muh($a0,$word,($h0)=&NR(1));
79 ### Wait 8 for next mul issue
80 &mul($a0,$word,($l0)=&NR(1)); &FR($a0)
81 &add($ap,$QWS,$ap);
82 ### Loose 12 until result is available
83 &add($rp,$QWS,$rp);
84 &sub($count,1,$count);
85 &add($l0,$cc,$l0);
86 ###
87 &st($l0,&QWPw(-1,$rp)); &FR($l0);
88 &cmpult($l0,$cc,$cc);
89 &add($h0,$cc,$cc); &FR($h0);
90 &bgt($count,&label("last_loop"));
91 &function_end_A($name);
92
93######################################################
94 &set_label("finish");
95 &add($count,4,$count);
96 &bgt($count,&label("last_loop"));
97
98 &set_label("end");
99 &function_end($name);
100
101 &fin_pool;
102 }
103
1041;
diff --git a/src/lib/libcrypto/bn/asm/alpha/mul_add.pl b/src/lib/libcrypto/bn/asm/alpha/mul_add.pl
new file mode 100644
index 0000000000..0d6df69bc4
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/alpha/mul_add.pl
@@ -0,0 +1,123 @@
1#!/usr/local/bin/perl
2# alpha assember
3
4sub bn_mul_add_words
5 {
6 local($name)=@_;
7 local($cc,$a,$b,$r,$couny);
8
9 &init_pool(4);
10 ($cc)=GR("r0");
11
12 $rp=&wparam(0);
13 $ap=&wparam(1);
14 $count=&wparam(2);
15 $word=&wparam(3);
16
17 &function_begin($name,"");
18
19 &comment("");
20 &sub($count,4,$count);
21 &mov("zero",$cc);
22 ###
23 &blt($count,&label("finish"));
24
25 &ld(($a0)=&NR(1),&QWPw(0,$ap));
26
27$a=<<'EOF';
28##########################################################
29 &set_label("loop");
30
31 &ld(($r0)=&NR(1),&QWPw(0,$rp));
32 &ld(($a1)=&NR(1),&QWPw(1,$ap));
33 &muh($a0,$word,($h0)=&NR(1));
34 &ld(($r1)=&NR(1),&QWPw(1,$rp));
35 &ld(($a2)=&NR(1),&QWPw(2,$ap));
36 ###
37 &mul($a0,$word,($l0)=&NR(1)); &FR($a0);
38 &ld(($r2)=&NR(1),&QWPw(2,$rp));
39 &muh($a1,$word,($h1)=&NR(1));
40 &ld(($a3)=&NR(1),&QWPw(3,$ap));
41 &mul($a1,$word,($l1)=&NR(1)); &FR($a1);
42 &ld(($r3)=&NR(1),&QWPw(3,$rp));
43 &add($r0,$l0,$r0);
44 &add($r1,$l1,$r1);
45 &cmpult($r0,$l0,($t0)=&NR(1)); &FR($l0);
46 &cmpult($r1,$l1,($t1)=&NR(1)); &FR($l1);
47 &muh($a2,$word,($h2)=&NR(1));
48 &add($r0,$cc,$r0);
49 &add($h0,$t0,$h0); &FR($t0);
50 &cmpult($r0,$cc,$cc);
51 &add($h1,$t1,$h1); &FR($t1);
52 &add($h0,$cc,$cc); &FR($h0);
53 &mul($a2,$word,($l2)=&NR(1)); &FR($a2);
54 &add($r1,$cc,$r1);
55 &cmpult($r1,$cc,$cc);
56 &add($r2,$l2,$r2);
57 &add($h1,$cc,$cc); &FR($h1);
58 &cmpult($r2,$l2,($t2)=&NR(1)); &FR($l2);
59 &muh($a3,$word,($h3)=&NR(1));
60 &add($r2,$cc,$r2);
61 &st($r0,&QWPw(0,$rp)); &FR($r0);
62 &add($h2,$t2,$h2); &FR($t2);
63 &st($r1,&QWPw(1,$rp)); &FR($r1);
64 &cmpult($r2,$cc,$cc);
65 &mul($a3,$word,($l3)=&NR(1)); &FR($a3);
66 &add($h2,$cc,$cc); &FR($h2);
67 &st($r2,&QWPw(2,$rp)); &FR($r2);
68 &sub($count,4,$count); # count-=4
69 &add($rp,4*$QWS,$rp); # count+=4
70 &add($r3,$l3,$r3);
71 &add($ap,4*$QWS,$ap); # count+=4
72 &cmpult($r3,$l3,($t3)=&NR(1)); &FR($l3);
73 &add($r3,$cc,$r3);
74 &add($h3,$t3,$h3); &FR($t3);
75 &cmpult($r3,$cc,$cc);
76 &st($r3,&QWPw(-1,$rp)); &FR($r3);
77 &add($h3,$cc,$cc); &FR($h3);
78
79 ###
80 &blt($count,&label("finish"));
81 &ld(($a0)=&NR(1),&QWPw(0,$ap));
82 &br(&label("loop"));
83EOF
84##################################################
85 # Do the last 0..3 words
86
87 &set_label("last_loop");
88
89 &ld(($a0)=&NR(1),&QWPw(0,$ap)); # get a
90 &ld(($r0)=&NR(1),&QWPw(0,$rp)); # get b
91 ###
92 ###
93 &muh($a0,$word,($h0)=&NR(1)); &FR($a0);
94 ### wait 8
95 &mul($a0,$word,($l0)=&NR(1)); &FR($a0);
96 &add($rp,$QWS,$rp);
97 &add($ap,$QWS,$ap);
98 &sub($count,1,$count);
99 ### wait 3 until l0 is available
100 &add($r0,$l0,$r0);
101 ###
102 &cmpult($r0,$l0,($t0)=&NR(1)); &FR($l0);
103 &add($r0,$cc,$r0);
104 &add($h0,$t0,$h0); &FR($t0);
105 &cmpult($r0,$cc,$cc);
106 &add($h0,$cc,$cc); &FR($h0);
107
108 &st($r0,&QWPw(-1,$rp)); &FR($r0);
109 &bgt($count,&label("last_loop"));
110 &function_end_A($name);
111
112######################################################
113 &set_label("finish");
114 &add($count,4,$count);
115 &bgt($count,&label("last_loop"));
116
117 &set_label("end");
118 &function_end($name);
119
120 &fin_pool;
121 }
122
1231;
diff --git a/src/lib/libcrypto/bn/asm/alpha/mul_c4.pl b/src/lib/libcrypto/bn/asm/alpha/mul_c4.pl
new file mode 100644
index 0000000000..9cc876ded4
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/alpha/mul_c4.pl
@@ -0,0 +1,215 @@
1#!/usr/local/bin/perl
2# alpha assember
3
4# upto
5
6sub mul_add_c
7 {
8 local($a,$b,$c0,$c1,$c2)=@_;
9 local($l1,$h1,$t1,$t2);
10
11 &mul($a,$b,($l1)=&NR(1));
12 &muh($a,$b,($h1)=&NR(1));
13 &add($c0,$l1,$c0);
14 &cmpult($c0,$l1,($t1)=&NR(1)); &FR($l1);
15 &add($t1,$h1,$h1); &FR($t1);
16 &add($c1,$h1,$c1);
17 &cmpult($c1,$h1,($t2)=&NR(1)); &FR($h1);
18 &add($c2,$t2,$c2); &FR($t2);
19 }
20
21sub bn_mul_comba4
22 {
23 local($name)=@_;
24 local(@a,@b,$r,$c0,$c1,$c2);
25
26 $cnt=1;
27 &init_pool(3);
28
29 $rp=&wparam(0);
30 $ap=&wparam(1);
31 $bp=&wparam(2);
32
33 &function_begin($name,"");
34
35 &comment("");
36
37 &ld(($a[0])=&NR(1),&QWPw(0,$ap));
38 &ld(($b[0])=&NR(1),&QWPw(0,$bp));
39 &ld(($a[1])=&NR(1),&QWPw(1,$ap));
40 &ld(($b[1])=&NR(1),&QWPw(1,$bp));
41 &mul($a[0],$b[0],($r00)=&NR(1));
42 &ld(($a[2])=&NR(1),&QWPw(2,$ap));
43 &ld(($b[2])=&NR(1),&QWPw(2,$bp));
44 &muh($a[0],$b[0],($r01)=&NR(1));
45 &FR($ap); &ld(($a[3])=&NR(1),&QWPw(3,$ap));
46 &FR($bp); &ld(($b[3])=&NR(1),&QWPw(3,$bp));
47 &mul($a[0],$b[1],($r02)=&NR(1));
48
49 ($R,$H1,$H2)=&NR(3);
50
51 &st($r00,&QWPw(0,$rp)); &FR($r00);
52
53 &mov("zero",$R);
54 &mul($a[1],$b[0],($r03)=&NR(1));
55
56 &mov("zero",$H1);
57 &mov("zero",$H0);
58 &add($R,$r01,$R);
59 &muh($a[0],$b[1],($r04)=&NR(1));
60 &cmpult($R,$r01,($t01)=&NR(1)); &FR($r01);
61 &add($R,$r02,$R);
62 &add($H1,$t01,$H1) &FR($t01);
63 &muh($a[1],$b[0],($r05)=&NR(1));
64 &cmpult($R,$r02,($t02)=&NR(1)); &FR($r02);
65 &add($R,$r03,$R);
66 &add($H2,$t02,$H2) &FR($t02);
67 &mul($a[0],$b[2],($r06)=&NR(1));
68 &cmpult($R,$r03,($t03)=&NR(1)); &FR($r03);
69 &add($H1,$t03,$H1) &FR($t03);
70 &st($R,&QWPw(1,$rp));
71 &add($H1,$H2,$R);
72
73 &mov("zero",$H1);
74 &add($R,$r04,$R);
75 &mov("zero",$H2);
76 &mul($a[1],$b[1],($r07)=&NR(1));
77 &cmpult($R,$r04,($t04)=&NR(1)); &FR($r04);
78 &add($R,$r05,$R);
79 &add($H1,$t04,$H1) &FR($t04);
80 &mul($a[2],$b[0],($r08)=&NR(1));
81 &cmpult($R,$r05,($t05)=&NR(1)); &FR($r05);
82 &add($R,$r01,$R);
83 &add($H2,$t05,$H2) &FR($t05);
84 &muh($a[0],$b[2],($r09)=&NR(1));
85 &cmpult($R,$r06,($t06)=&NR(1)); &FR($r06);
86 &add($R,$r07,$R);
87 &add($H1,$t06,$H1) &FR($t06);
88 &muh($a[1],$b[1],($r10)=&NR(1));
89 &cmpult($R,$r07,($t07)=&NR(1)); &FR($r07);
90 &add($R,$r08,$R);
91 &add($H2,$t07,$H2) &FR($t07);
92 &muh($a[2],$b[0],($r11)=&NR(1));
93 &cmpult($R,$r08,($t08)=&NR(1)); &FR($r08);
94 &add($H1,$t08,$H1) &FR($t08);
95 &st($R,&QWPw(2,$rp));
96 &add($H1,$H2,$R);
97
98 &mov("zero",$H1);
99 &add($R,$r09,$R);
100 &mov("zero",$H2);
101 &mul($a[0],$b[3],($r12)=&NR(1));
102 &cmpult($R,$r09,($t09)=&NR(1)); &FR($r09);
103 &add($R,$r10,$R);
104 &add($H1,$t09,$H1) &FR($t09);
105 &mul($a[1],$b[2],($r13)=&NR(1));
106 &cmpult($R,$r10,($t10)=&NR(1)); &FR($r10);
107 &add($R,$r11,$R);
108 &add($H1,$t10,$H1) &FR($t10);
109 &mul($a[2],$b[1],($r14)=&NR(1));
110 &cmpult($R,$r11,($t11)=&NR(1)); &FR($r11);
111 &add($R,$r12,$R);
112 &add($H1,$t11,$H1) &FR($t11);
113 &mul($a[3],$b[0],($r15)=&NR(1));
114 &cmpult($R,$r12,($t12)=&NR(1)); &FR($r12);
115 &add($R,$r13,$R);
116 &add($H1,$t12,$H1) &FR($t12);
117 &muh($a[0],$b[3],($r16)=&NR(1));
118 &cmpult($R,$r13,($t13)=&NR(1)); &FR($r13);
119 &add($R,$r14,$R);
120 &add($H1,$t13,$H1) &FR($t13);
121 &muh($a[1],$b[2],($r17)=&NR(1));
122 &cmpult($R,$r14,($t14)=&NR(1)); &FR($r14);
123 &add($R,$r15,$R);
124 &add($H1,$t14,$H1) &FR($t14);
125 &muh($a[2],$b[1],($r18)=&NR(1));
126 &cmpult($R,$r15,($t15)=&NR(1)); &FR($r15);
127 &add($H1,$t15,$H1) &FR($t15);
128 &st($R,&QWPw(3,$rp));
129 &add($H1,$H2,$R);
130
131 &mov("zero",$H1);
132 &add($R,$r16,$R);
133 &mov("zero",$H2);
134 &muh($a[3],$b[0],($r19)=&NR(1));
135 &cmpult($R,$r16,($t16)=&NR(1)); &FR($r16);
136 &add($R,$r17,$R);
137 &add($H1,$t16,$H1) &FR($t16);
138 &mul($a[1],$b[3],($r20)=&NR(1));
139 &cmpult($R,$r17,($t17)=&NR(1)); &FR($r17);
140 &add($R,$r18,$R);
141 &add($H1,$t17,$H1) &FR($t17);
142 &mul($a[2],$b[2],($r21)=&NR(1));
143 &cmpult($R,$r18,($t18)=&NR(1)); &FR($r18);
144 &add($R,$r19,$R);
145 &add($H1,$t18,$H1) &FR($t18);
146 &mul($a[3],$b[1],($r22)=&NR(1));
147 &cmpult($R,$r19,($t19)=&NR(1)); &FR($r19);
148 &add($R,$r20,$R);
149 &add($H1,$t19,$H1) &FR($t19);
150 &muh($a[1],$b[3],($r23)=&NR(1));
151 &cmpult($R,$r20,($t20)=&NR(1)); &FR($r20);
152 &add($R,$r21,$R);
153 &add($H1,$t20,$H1) &FR($t20);
154 &muh($a[2],$b[2],($r24)=&NR(1));
155 &cmpult($R,$r21,($t21)=&NR(1)); &FR($r21);
156 &add($R,$r22,$R);
157 &add($H1,$t21,$H1) &FR($t21);
158 &muh($a[3],$b[1],($r25)=&NR(1));
159 &cmpult($R,$r22,($t22)=&NR(1)); &FR($r22);
160 &add($H1,$t22,$H1) &FR($t22);
161 &st($R,&QWPw(4,$rp));
162 &add($H1,$H2,$R);
163
164 &mov("zero",$H1);
165 &add($R,$r23,$R);
166 &mov("zero",$H2);
167 &mul($a[2],$b[3],($r26)=&NR(1));
168 &cmpult($R,$r23,($t23)=&NR(1)); &FR($r23);
169 &add($R,$r24,$R);
170 &add($H1,$t23,$H1) &FR($t23);
171 &mul($a[3],$b[2],($r27)=&NR(1));
172 &cmpult($R,$r24,($t24)=&NR(1)); &FR($r24);
173 &add($R,$r25,$R);
174 &add($H1,$t24,$H1) &FR($t24);
175 &muh($a[2],$b[3],($r28)=&NR(1));
176 &cmpult($R,$r25,($t25)=&NR(1)); &FR($r25);
177 &add($R,$r26,$R);
178 &add($H1,$t25,$H1) &FR($t25);
179 &muh($a[3],$b[2],($r29)=&NR(1));
180 &cmpult($R,$r26,($t26)=&NR(1)); &FR($r26);
181 &add($R,$r27,$R);
182 &add($H1,$t26,$H1) &FR($t26);
183 &mul($a[3],$b[3],($r30)=&NR(1));
184 &cmpult($R,$r27,($t27)=&NR(1)); &FR($r27);
185 &add($H1,$t27,$H1) &FR($t27);
186 &st($R,&QWPw(5,$rp));
187 &add($H1,$H2,$R);
188
189 &mov("zero",$H1);
190 &add($R,$r28,$R);
191 &mov("zero",$H2);
192 &muh($a[3],$b[3],($r31)=&NR(1));
193 &cmpult($R,$r28,($t28)=&NR(1)); &FR($r28);
194 &add($R,$r29,$R);
195 &add($H1,$t28,$H1) &FR($t28);
196 ############
197 &cmpult($R,$r29,($t29)=&NR(1)); &FR($r29);
198 &add($R,$r30,$R);
199 &add($H1,$t29,$H1) &FR($t29);
200 ############
201 &cmpult($R,$r30,($t30)=&NR(1)); &FR($r30);
202 &add($H1,$t30,$H1) &FR($t30);
203 &st($R,&QWPw(6,$rp));
204 &add($H1,$H2,$R);
205
206 &add($R,$r31,$R); &FR($r31);
207 &st($R,&QWPw(7,$rp));
208
209 &FR($R,$H1,$H2);
210 &function_end($name);
211
212 &fin_pool;
213 }
214
2151;
diff --git a/src/lib/libcrypto/bn/asm/alpha/mul_c4.works.pl b/src/lib/libcrypto/bn/asm/alpha/mul_c4.works.pl
new file mode 100644
index 0000000000..79d86dd25c
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/alpha/mul_c4.works.pl
@@ -0,0 +1,98 @@
1#!/usr/local/bin/perl
2# alpha assember
3
4sub mul_add_c
5 {
6 local($a,$b,$c0,$c1,$c2)=@_;
7 local($l1,$h1,$t1,$t2);
8
9print STDERR "count=$cnt\n"; $cnt++;
10 &mul($a,$b,($l1)=&NR(1));
11 &muh($a,$b,($h1)=&NR(1));
12 &add($c0,$l1,$c0);
13 &cmpult($c0,$l1,($t1)=&NR(1)); &FR($l1);
14 &add($t1,$h1,$h1); &FR($t1);
15 &add($c1,$h1,$c1);
16 &cmpult($c1,$h1,($t2)=&NR(1)); &FR($h1);
17 &add($c2,$t2,$c2); &FR($t2);
18 }
19
20sub bn_mul_comba4
21 {
22 local($name)=@_;
23 local(@a,@b,$r,$c0,$c1,$c2);
24
25 $cnt=1;
26 &init_pool(3);
27
28 $rp=&wparam(0);
29 $ap=&wparam(1);
30 $bp=&wparam(2);
31
32 &function_begin($name,"");
33
34 &comment("");
35
36 &ld(($a[0])=&NR(1),&QWPw(0,$ap));
37 &ld(($b[0])=&NR(1),&QWPw(0,$bp));
38 &ld(($a[1])=&NR(1),&QWPw(1,$ap));
39 &ld(($b[1])=&NR(1),&QWPw(1,$bp));
40 &ld(($a[2])=&NR(1),&QWPw(2,$ap));
41 &ld(($b[2])=&NR(1),&QWPw(2,$bp));
42 &ld(($a[3])=&NR(1),&QWPw(3,$ap)); &FR($ap);
43 &ld(($b[3])=&NR(1),&QWPw(3,$bp)); &FR($bp);
44
45 ($c0,$c1,$c2)=&NR(3);
46 &mov("zero",$c2);
47 &mul($a[0],$b[0],$c0);
48 &muh($a[0],$b[0],$c1);
49 &st($c0,&QWPw(0,$rp)); &FR($c0); ($c0)=&NR($c0);
50 ($c0,$c1,$c2)=($c1,$c2,$c0);
51 &mov("zero",$c2);
52
53 &mul_add_c($a[0],$b[1],$c0,$c1,$c2);
54 &mul_add_c($a[1],$b[0],$c0,$c1,$c2);
55 &st($c0,&QWPw(1,$rp)); &FR($c0); ($c0)=&NR($c0);
56 ($c0,$c1,$c2)=($c1,$c2,$c0);
57 &mov("zero",$c2);
58
59 &mul_add_c($a[1],$b[1],$c0,$c1,$c2);
60 &mul_add_c($a[0],$b[2],$c0,$c1,$c2);
61 &mul_add_c($a[2],$b[0],$c0,$c1,$c2);
62 &st($c0,&QWPw(2,$rp)); &FR($c0); ($c0)=&NR($c0);
63 ($c0,$c1,$c2)=($c1,$c2,$c0);
64 &mov("zero",$c2);
65
66 &mul_add_c($a[0],$b[3],$c0,$c1,$c2); &FR($a[0]);
67 &mul_add_c($a[1],$b[2],$c0,$c1,$c2);
68 &mul_add_c($a[2],$b[1],$c0,$c1,$c2);
69 &mul_add_c($a[3],$b[0],$c0,$c1,$c2); &FR($b[0]);
70 &st($c0,&QWPw(3,$rp)); &FR($c0); ($c0)=&NR($c0);
71 ($c0,$c1,$c2)=($c1,$c2,$c0);
72 &mov("zero",$c2);
73
74 &mul_add_c($a[1],$b[3],$c0,$c1,$c2); &FR($a[1]);
75 &mul_add_c($a[2],$b[2],$c0,$c1,$c2);
76 &mul_add_c($a[3],$b[1],$c0,$c1,$c2); &FR($b[1]);
77 &st($c0,&QWPw(4,$rp)); &FR($c0); ($c0)=&NR($c0);
78 ($c0,$c1,$c2)=($c1,$c2,$c0);
79 &mov("zero",$c2);
80
81 &mul_add_c($a[2],$b[3],$c0,$c1,$c2); &FR($a[2]);
82 &mul_add_c($a[3],$b[2],$c0,$c1,$c2); &FR($b[2]);
83 &st($c0,&QWPw(5,$rp)); &FR($c0); ($c0)=&NR($c0);
84 ($c0,$c1,$c2)=($c1,$c2,$c0);
85 &mov("zero",$c2);
86
87 &mul_add_c($a[3],$b[3],$c0,$c1,$c2); &FR($a[3],$b[3]);
88 &st($c0,&QWPw(6,$rp));
89 &st($c1,&QWPw(7,$rp));
90
91 &FR($c0,$c1,$c2);
92
93 &function_end($name);
94
95 &fin_pool;
96 }
97
981;
diff --git a/src/lib/libcrypto/bn/asm/alpha/mul_c8.pl b/src/lib/libcrypto/bn/asm/alpha/mul_c8.pl
new file mode 100644
index 0000000000..525ca7494b
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/alpha/mul_c8.pl
@@ -0,0 +1,177 @@
1#!/usr/local/bin/perl
2# alpha assember
3
4sub bn_mul_comba8
5 {
6 local($name)=@_;
7 local(@a,@b,$r,$c0,$c1,$c2);
8
9 $cnt=1;
10 &init_pool(3);
11
12 $rp=&wparam(0);
13 $ap=&wparam(1);
14 $bp=&wparam(2);
15
16 &function_begin($name,"");
17
18 &comment("");
19
20 &stack_push(2);
21 &ld(($a[0])=&NR(1),&QWPw(0,$ap));
22 &ld(($b[0])=&NR(1),&QWPw(0,$bp));
23 &st($reg_s0,&swtmp(0)); &FR($reg_s0);
24 &st($reg_s1,&swtmp(1)); &FR($reg_s1);
25 &ld(($a[1])=&NR(1),&QWPw(1,$ap));
26 &ld(($b[1])=&NR(1),&QWPw(1,$bp));
27 &ld(($a[2])=&NR(1),&QWPw(2,$ap));
28 &ld(($b[2])=&NR(1),&QWPw(2,$bp));
29 &ld(($a[3])=&NR(1),&QWPw(3,$ap));
30 &ld(($b[3])=&NR(1),&QWPw(3,$bp));
31 &ld(($a[4])=&NR(1),&QWPw(1,$ap));
32 &ld(($b[4])=&NR(1),&QWPw(1,$bp));
33 &ld(($a[5])=&NR(1),&QWPw(1,$ap));
34 &ld(($b[5])=&NR(1),&QWPw(1,$bp));
35 &ld(($a[6])=&NR(1),&QWPw(1,$ap));
36 &ld(($b[6])=&NR(1),&QWPw(1,$bp));
37 &ld(($a[7])=&NR(1),&QWPw(1,$ap)); &FR($ap);
38 &ld(($b[7])=&NR(1),&QWPw(1,$bp)); &FR($bp);
39
40 ($c0,$c1,$c2)=&NR(3);
41 &mov("zero",$c2);
42 &mul($a[0],$b[0],$c0);
43 &muh($a[0],$b[0],$c1);
44 &st($c0,&QWPw(0,$rp)); &FR($c0); ($c0)=&NR(1);
45 ($c0,$c1,$c2)=($c1,$c2,$c0);
46 &mov("zero",$c2);
47
48 &mul_add_c($a[0],$b[1],$c0,$c1,$c2);
49 &mul_add_c($a[1],$b[0],$c0,$c1,$c2);
50 &st($c0,&QWPw(1,$rp)); &FR($c0); ($c0)=&NR(1);
51 ($c0,$c1,$c2)=($c1,$c2,$c0);
52 &mov("zero",$c2);
53
54 &mul_add_c($a[0],$b[2],$c0,$c1,$c2);
55 &mul_add_c($a[1],$b[1],$c0,$c1,$c2);
56 &mul_add_c($a[2],$b[0],$c0,$c1,$c2);
57 &st($c0,&QWPw(2,$rp)); &FR($c0); ($c0)=&NR(1);
58 ($c0,$c1,$c2)=($c1,$c2,$c0);
59 &mov("zero",$c2);
60
61 &mul_add_c($a[0],$b[3],$c0,$c1,$c2);
62 &mul_add_c($a[1],$b[2],$c0,$c1,$c2);
63 &mul_add_c($a[2],$b[1],$c0,$c1,$c2);
64 &mul_add_c($a[3],$b[0],$c0,$c1,$c2);
65 &st($c0,&QWPw(3,$rp)); &FR($c0); ($c0)=&NR(1);
66 ($c0,$c1,$c2)=($c1,$c2,$c0);
67 &mov("zero",$c2);
68
69 &mul_add_c($a[0],$b[4],$c0,$c1,$c2);
70 &mul_add_c($a[1],$b[3],$c0,$c1,$c2);
71 &mul_add_c($a[2],$b[2],$c0,$c1,$c2);
72 &mul_add_c($a[3],$b[1],$c0,$c1,$c2);
73 &mul_add_c($a[4],$b[0],$c0,$c1,$c2);
74 &st($c0,&QWPw(4,$rp)); &FR($c0); ($c0)=&NR(1);
75 ($c0,$c1,$c2)=($c1,$c2,$c0);
76 &mov("zero",$c2);
77
78 &mul_add_c($a[0],$b[5],$c0,$c1,$c2);
79 &mul_add_c($a[1],$b[4],$c0,$c1,$c2);
80 &mul_add_c($a[2],$b[3],$c0,$c1,$c2);
81 &mul_add_c($a[3],$b[2],$c0,$c1,$c2);
82 &mul_add_c($a[4],$b[1],$c0,$c1,$c2);
83 &mul_add_c($a[5],$b[0],$c0,$c1,$c2);
84 &st($c0,&QWPw(5,$rp)); &FR($c0); ($c0)=&NR(1);
85 ($c0,$c1,$c2)=($c1,$c2,$c0);
86 &mov("zero",$c2);
87
88 &mul_add_c($a[0],$b[6],$c0,$c1,$c2);
89 &mul_add_c($a[1],$b[5],$c0,$c1,$c2);
90 &mul_add_c($a[2],$b[4],$c0,$c1,$c2);
91 &mul_add_c($a[3],$b[3],$c0,$c1,$c2);
92 &mul_add_c($a[4],$b[2],$c0,$c1,$c2);
93 &mul_add_c($a[5],$b[1],$c0,$c1,$c2);
94 &mul_add_c($a[6],$b[0],$c0,$c1,$c2);
95 &st($c0,&QWPw(6,$rp)); &FR($c0); ($c0)=&NR(1);
96 ($c0,$c1,$c2)=($c1,$c2,$c0);
97 &mov("zero",$c2);
98
99 &mul_add_c($a[0],$b[7],$c0,$c1,$c2); &FR($a[0]);
100 &mul_add_c($a[1],$b[6],$c0,$c1,$c2);
101 &mul_add_c($a[2],$b[5],$c0,$c1,$c2);
102 &mul_add_c($a[3],$b[4],$c0,$c1,$c2);
103 &mul_add_c($a[4],$b[3],$c0,$c1,$c2);
104 &mul_add_c($a[5],$b[2],$c0,$c1,$c2);
105 &mul_add_c($a[6],$b[1],$c0,$c1,$c2);
106 &mul_add_c($a[7],$b[0],$c0,$c1,$c2); &FR($b[0]);
107 &st($c0,&QWPw(7,$rp)); &FR($c0); ($c0)=&NR(1);
108 ($c0,$c1,$c2)=($c1,$c2,$c0);
109 &mov("zero",$c2);
110
111 &mul_add_c($a[1],$b[7],$c0,$c1,$c2); &FR($a[1]);
112 &mul_add_c($a[2],$b[6],$c0,$c1,$c2);
113 &mul_add_c($a[3],$b[5],$c0,$c1,$c2);
114 &mul_add_c($a[4],$b[4],$c0,$c1,$c2);
115 &mul_add_c($a[5],$b[3],$c0,$c1,$c2);
116 &mul_add_c($a[6],$b[2],$c0,$c1,$c2);
117 &mul_add_c($a[7],$b[1],$c0,$c1,$c2); &FR($b[1]);
118 &st($c0,&QWPw(8,$rp)); &FR($c0); ($c0)=&NR(1);
119 ($c0,$c1,$c2)=($c1,$c2,$c0);
120 &mov("zero",$c2);
121
122 &mul_add_c($a[2],$b[7],$c0,$c1,$c2); &FR($a[2]);
123 &mul_add_c($a[3],$b[6],$c0,$c1,$c2);
124 &mul_add_c($a[4],$b[5],$c0,$c1,$c2);
125 &mul_add_c($a[5],$b[4],$c0,$c1,$c2);
126 &mul_add_c($a[6],$b[3],$c0,$c1,$c2);
127 &mul_add_c($a[7],$b[2],$c0,$c1,$c2); &FR($b[2]);
128 &st($c0,&QWPw(9,$rp)); &FR($c0); ($c0)=&NR(1);
129 ($c0,$c1,$c2)=($c1,$c2,$c0);
130 &mov("zero",$c2);
131
132 &mul_add_c($a[3],$b[7],$c0,$c1,$c2); &FR($a[3]);
133 &mul_add_c($a[4],$b[6],$c0,$c1,$c2);
134 &mul_add_c($a[5],$b[5],$c0,$c1,$c2);
135 &mul_add_c($a[6],$b[4],$c0,$c1,$c2);
136 &mul_add_c($a[7],$b[3],$c0,$c1,$c2); &FR($b[3]);
137 &st($c0,&QWPw(10,$rp)); &FR($c0); ($c0)=&NR(1);
138 ($c0,$c1,$c2)=($c1,$c2,$c0);
139 &mov("zero",$c2);
140
141 &mul_add_c($a[4],$b[7],$c0,$c1,$c2); &FR($a[4]);
142 &mul_add_c($a[5],$b[6],$c0,$c1,$c2);
143 &mul_add_c($a[6],$b[5],$c0,$c1,$c2);
144 &mul_add_c($a[7],$b[4],$c0,$c1,$c2); &FR($b[4]);
145 &st($c0,&QWPw(11,$rp)); &FR($c0); ($c0)=&NR(1);
146 ($c0,$c1,$c2)=($c1,$c2,$c0);
147 &mov("zero",$c2);
148
149 &mul_add_c($a[5],$b[7],$c0,$c1,$c2); &FR($a[5]);
150 &mul_add_c($a[6],$b[6],$c0,$c1,$c2);
151 &mul_add_c($a[7],$b[5],$c0,$c1,$c2); &FR($b[5]);
152 &st($c0,&QWPw(12,$rp)); &FR($c0); ($c0)=&NR(1);
153 ($c0,$c1,$c2)=($c1,$c2,$c0);
154 &mov("zero",$c2);
155
156 &mul_add_c($a[6],$b[7],$c0,$c1,$c2); &FR($a[6]);
157 &mul_add_c($a[7],$b[6],$c0,$c1,$c2); &FR($b[6]);
158 &st($c0,&QWPw(13,$rp)); &FR($c0); ($c0)=&NR(1);
159 ($c0,$c1,$c2)=($c1,$c2,$c0);
160 &mov("zero",$c2);
161
162 &mul_add_c($a[7],$b[7],$c0,$c1,$c2); &FR($a[7],$b[7]);
163 &st($c0,&QWPw(14,$rp));
164 &st($c1,&QWPw(15,$rp));
165
166 &FR($c0,$c1,$c2);
167
168 &ld($reg_s0,&swtmp(0));
169 &ld($reg_s1,&swtmp(1));
170 &stack_pop(2);
171
172 &function_end($name);
173
174 &fin_pool;
175 }
176
1771;
diff --git a/src/lib/libcrypto/bn/asm/alpha/sqr.pl b/src/lib/libcrypto/bn/asm/alpha/sqr.pl
new file mode 100644
index 0000000000..a55b696906
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/alpha/sqr.pl
@@ -0,0 +1,113 @@
1#!/usr/local/bin/perl
2# alpha assember
3
4sub bn_sqr_words
5 {
6 local($name)=@_;
7 local($cc,$a,$b,$r,$couny);
8
9 &init_pool(3);
10 ($cc)=GR("r0");
11
12 $rp=&wparam(0);
13 $ap=&wparam(1);
14 $count=&wparam(2);
15
16 &function_begin($name,"");
17
18 &comment("");
19 &sub($count,4,$count);
20 &mov("zero",$cc);
21 &br(&label("finish"));
22 &blt($count,&label("finish"));
23
24 ($a0,$r0)=&NR(2);
25 &ld($a0,&QWPw(0,$ap));
26 &ld($r0,&QWPw(0,$rp));
27
28$a=<<'EOF';
29##########################################################
30 &set_label("loop");
31
32 ($a1)=&NR(1); &ld($a1,&QWPw(1,$ap));
33 ($b1)=&NR(1); &ld($b1,&QWPw(1,$bp));
34 ($a2)=&NR(1); &ld($a2,&QWPw(2,$ap));
35 ($b2)=&NR(1); &ld($b2,&QWPw(2,$bp));
36 ($a3)=&NR(1); &ld($a3,&QWPw(3,$ap));
37 ($b3)=&NR(1); &ld($b3,&QWPw(3,$bp));
38
39 ($o0,$t0)=&NR(2);
40 &add($a0,$b0,$o0);
41 &cmpult($o0,$b0,$t0);
42 &add($o0,$cc,$o0);
43 &cmpult($o0,$cc,$cc);
44 &add($cc,$t0,$cc); &FR($t0);
45
46 ($t1,$o1)=&NR(2);
47
48 &add($a1,$b1,$o1); &FR($a1);
49 &cmpult($o1,$b1,$t1); &FR($b1);
50 &add($o1,$cc,$o1);
51 &cmpult($o1,$cc,$cc);
52 &add($cc,$t1,$cc); &FR($t1);
53
54 ($t2,$o2)=&NR(2);
55
56 &add($a2,$b2,$o2); &FR($a2);
57 &cmpult($o2,$b2,$t2); &FR($b2);
58 &add($o2,$cc,$o2);
59 &cmpult($o2,$cc,$cc);
60 &add($cc,$t2,$cc); &FR($t2);
61
62 ($t3,$o3)=&NR(2);
63
64 &add($a3,$b3,$o3); &FR($a3);
65 &cmpult($o3,$b3,$t3); &FR($b3);
66 &add($o3,$cc,$o3);
67 &cmpult($o3,$cc,$cc);
68 &add($cc,$t3,$cc); &FR($t3);
69
70 &st($o0,&QWPw(0,$rp)); &FR($o0);
71 &st($o1,&QWPw(0,$rp)); &FR($o1);
72 &st($o2,&QWPw(0,$rp)); &FR($o2);
73 &st($o3,&QWPw(0,$rp)); &FR($o3);
74
75 &sub($count,4,$count); # count-=4
76 &add($ap,4*$QWS,$ap); # count+=4
77 &add($bp,4*$QWS,$bp); # count+=4
78 &add($rp,4*$QWS,$rp); # count+=4
79
80 &blt($count,&label("finish"));
81 &ld($a0,&QWPw(0,$ap));
82 &ld($b0,&QWPw(0,$bp));
83 &br(&label("loop"));
84EOF
85##################################################
86 # Do the last 0..3 words
87
88 &set_label("last_loop");
89
90 &ld(($a0)=&NR(1),&QWPw(0,$ap)); # get a
91 &mul($a0,$a0,($l0)=&NR(1));
92 &add($ap,$QWS,$ap);
93 &add($rp,2*$QWS,$rp);
94 &sub($count,1,$count);
95 &muh($a0,$a0,($h0)=&NR(1)); &FR($a0);
96 &st($l0,&QWPw(-2,$rp)); &FR($l0);
97 &st($h0,&QWPw(-1,$rp)); &FR($h0);
98
99 &bgt($count,&label("last_loop"));
100 &function_end_A($name);
101
102######################################################
103 &set_label("finish");
104 &add($count,4,$count);
105 &bgt($count,&label("last_loop"));
106
107 &set_label("end");
108 &function_end($name);
109
110 &fin_pool;
111 }
112
1131;
diff --git a/src/lib/libcrypto/bn/asm/alpha/sqr_c4.pl b/src/lib/libcrypto/bn/asm/alpha/sqr_c4.pl
new file mode 100644
index 0000000000..bf33f5b503
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/alpha/sqr_c4.pl
@@ -0,0 +1,109 @@
1#!/usr/local/bin/perl
2# alpha assember
3
4sub sqr_add_c
5 {
6 local($a,$c0,$c1,$c2)=@_;
7 local($l1,$h1,$t1,$t2);
8
9 &mul($a,$a,($l1)=&NR(1));
10 &muh($a,$a,($h1)=&NR(1));
11 &add($c0,$l1,$c0);
12 &add($c1,$h1,$c1);
13 &cmpult($c0,$l1,($t1)=&NR(1)); &FR($l1);
14 &cmpult($c1,$h1,($t2)=&NR(1)); &FR($h1);
15 &add($c1,$t1,$c1); &FR($t1);
16 &add($c2,$t2,$c2); &FR($t2);
17 }
18
19sub sqr_add_c2
20 {
21 local($a,$b,$c0,$c1,$c2)=@_;
22 local($l1,$h1,$t1,$t2);
23
24 &mul($a,$b,($l1)=&NR(1));
25 &muh($a,$b,($h1)=&NR(1));
26 &cmplt($l1,"zero",($lc1)=&NR(1));
27 &cmplt($h1,"zero",($hc1)=&NR(1));
28 &add($l1,$l1,$l1);
29 &add($h1,$h1,$h1);
30 &add($h1,$lc1,$h1); &FR($lc1);
31 &add($c2,$hc1,$c2); &FR($hc1);
32
33 &add($c0,$l1,$c0);
34 &add($c1,$h1,$c1);
35 &cmpult($c0,$l1,($lc1)=&NR(1)); &FR($l1);
36 &cmpult($c1,$h1,($hc1)=&NR(1)); &FR($h1);
37
38 &add($c1,$lc1,$c1); &FR($lc1);
39 &add($c2,$hc1,$c2); &FR($hc1);
40 }
41
42
43sub bn_sqr_comba4
44 {
45 local($name)=@_;
46 local(@a,@b,$r,$c0,$c1,$c2);
47
48 $cnt=1;
49 &init_pool(2);
50
51 $rp=&wparam(0);
52 $ap=&wparam(1);
53
54 &function_begin($name,"");
55
56 &comment("");
57
58 &ld(($a[0])=&NR(1),&QWPw(0,$ap));
59 &ld(($a[1])=&NR(1),&QWPw(1,$ap));
60 &ld(($a[2])=&NR(1),&QWPw(2,$ap));
61 &ld(($a[3])=&NR(1),&QWPw(3,$ap)); &FR($ap);
62
63 ($c0,$c1,$c2)=&NR(3);
64
65 &mov("zero",$c2);
66 &mul($a[0],$a[0],$c0);
67 &muh($a[0],$a[0],$c1);
68 &st($c0,&QWPw(0,$rp));
69 ($c0,$c1,$c2)=($c1,$c2,$c0);
70 &mov("zero",$c2);
71
72 &sqr_add_c2($a[0],$a[1],$c0,$c1,$c2);
73 &st($c0,&QWPw(1,$rp));
74 ($c0,$c1,$c2)=($c1,$c2,$c0);
75 &mov("zero",$c2);
76
77 &sqr_add_c($a[1],$c0,$c1,$c2);
78 &sqr_add_c2($a[2],$a[0],$c0,$c1,$c2);
79 &st($c0,&QWPw(2,$rp));
80 ($c0,$c1,$c2)=($c1,$c2,$c0);
81 &mov("zero",$c2);
82
83 &sqr_add_c2($a[3],$a[0],$c0,$c1,$c2);
84 &sqr_add_c2($a[2],$a[1],$c0,$c1,$c2);
85 &st($c0,&QWPw(3,$rp));
86 ($c0,$c1,$c2)=($c1,$c2,$c0);
87 &mov("zero",$c2);
88
89 &sqr_add_c($a[2],$c0,$c1,$c2);
90 &sqr_add_c2($a[3],$a[1],$c0,$c1,$c2);
91 &st($c0,&QWPw(4,$rp));
92 ($c0,$c1,$c2)=($c1,$c2,$c0);
93 &mov("zero",$c2);
94
95 &sqr_add_c2($a[3],$a[2],$c0,$c1,$c2);
96 &st($c0,&QWPw(5,$rp));
97 ($c0,$c1,$c2)=($c1,$c2,$c0);
98 &mov("zero",$c2);
99
100 &sqr_add_c($a[3],$c0,$c1,$c2);
101 &st($c0,&QWPw(6,$rp));
102 &st($c1,&QWPw(7,$rp));
103
104 &function_end($name);
105
106 &fin_pool;
107 }
108
1091;
diff --git a/src/lib/libcrypto/bn/asm/alpha/sqr_c8.pl b/src/lib/libcrypto/bn/asm/alpha/sqr_c8.pl
new file mode 100644
index 0000000000..b4afe085f1
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/alpha/sqr_c8.pl
@@ -0,0 +1,132 @@
1#!/usr/local/bin/perl
2# alpha assember
3
4sub bn_sqr_comba8
5 {
6 local($name)=@_;
7 local(@a,@b,$r,$c0,$c1,$c2);
8
9 $cnt=1;
10 &init_pool(2);
11
12 $rp=&wparam(0);
13 $ap=&wparam(1);
14
15 &function_begin($name,"");
16
17 &comment("");
18
19 &ld(($a[0])=&NR(1),&QWPw(0,$ap));
20 &ld(($a[1])=&NR(1),&QWPw(1,$ap));
21 &ld(($a[2])=&NR(1),&QWPw(2,$ap));
22 &ld(($a[3])=&NR(1),&QWPw(3,$ap));
23 &ld(($a[4])=&NR(1),&QWPw(4,$ap));
24 &ld(($a[5])=&NR(1),&QWPw(5,$ap));
25 &ld(($a[6])=&NR(1),&QWPw(6,$ap));
26 &ld(($a[7])=&NR(1),&QWPw(7,$ap)); &FR($ap);
27
28 ($c0,$c1,$c2)=&NR(3);
29
30 &mov("zero",$c2);
31 &mul($a[0],$a[0],$c0);
32 &muh($a[0],$a[0],$c1);
33 &st($c0,&QWPw(0,$rp));
34 ($c0,$c1,$c2)=($c1,$c2,$c0);
35 &mov("zero",$c2);
36
37 &sqr_add_c2($a[1],$a[0],$c0,$c1,$c2);
38 &st($c0,&QWPw(1,$rp));
39 ($c0,$c1,$c2)=($c1,$c2,$c0);
40 &mov("zero",$c2);
41
42 &sqr_add_c($a[1],$c0,$c1,$c2);
43 &sqr_add_c2($a[2],$a[0],$c0,$c1,$c2);
44 &st($c0,&QWPw(2,$rp));
45 ($c0,$c1,$c2)=($c1,$c2,$c0);
46 &mov("zero",$c2);
47
48 &sqr_add_c2($a[2],$a[1],$c0,$c1,$c2);
49 &sqr_add_c2($a[3],$a[0],$c0,$c1,$c2);
50 &st($c0,&QWPw(3,$rp));
51 ($c0,$c1,$c2)=($c1,$c2,$c0);
52 &mov("zero",$c2);
53
54 &sqr_add_c($a[2],$c0,$c1,$c2);
55 &sqr_add_c2($a[3],$a[1],$c0,$c1,$c2);
56 &sqr_add_c2($a[4],$a[0],$c0,$c1,$c2);
57 &st($c0,&QWPw(4,$rp));
58 ($c0,$c1,$c2)=($c1,$c2,$c0);
59 &mov("zero",$c2);
60
61 &sqr_add_c2($a[3],$a[2],$c0,$c1,$c2);
62 &sqr_add_c2($a[4],$a[1],$c0,$c1,$c2);
63 &sqr_add_c2($a[5],$a[0],$c0,$c1,$c2);
64 &st($c0,&QWPw(5,$rp));
65 ($c0,$c1,$c2)=($c1,$c2,$c0);
66 &mov("zero",$c2);
67
68 &sqr_add_c($a[3],$c0,$c1,$c2);
69 &sqr_add_c2($a[4],$a[2],$c0,$c1,$c2);
70 &sqr_add_c2($a[5],$a[1],$c0,$c1,$c2);
71 &sqr_add_c2($a[6],$a[0],$c0,$c1,$c2);
72 &st($c0,&QWPw(6,$rp));
73 ($c0,$c1,$c2)=($c1,$c2,$c0);
74 &mov("zero",$c2);
75
76 &sqr_add_c2($a[4],$a[3],$c0,$c1,$c2);
77 &sqr_add_c2($a[5],$a[2],$c0,$c1,$c2);
78 &sqr_add_c2($a[6],$a[1],$c0,$c1,$c2);
79 &sqr_add_c2($a[7],$a[0],$c0,$c1,$c2);
80 &st($c0,&QWPw(7,$rp));
81 ($c0,$c1,$c2)=($c1,$c2,$c0);
82 &mov("zero",$c2);
83
84 &sqr_add_c($a[4],$c0,$c1,$c2);
85 &sqr_add_c2($a[5],$a[3],$c0,$c1,$c2);
86 &sqr_add_c2($a[6],$a[2],$c0,$c1,$c2);
87 &sqr_add_c2($a[7],$a[1],$c0,$c1,$c2);
88 &st($c0,&QWPw(8,$rp));
89 ($c0,$c1,$c2)=($c1,$c2,$c0);
90 &mov("zero",$c2);
91
92 &sqr_add_c2($a[5],$a[4],$c0,$c1,$c2);
93 &sqr_add_c2($a[6],$a[3],$c0,$c1,$c2);
94 &sqr_add_c2($a[7],$a[2],$c0,$c1,$c2);
95 &st($c0,&QWPw(9,$rp));
96 ($c0,$c1,$c2)=($c1,$c2,$c0);
97 &mov("zero",$c2);
98
99 &sqr_add_c($a[5],$c0,$c1,$c2);
100 &sqr_add_c2($a[6],$a[4],$c0,$c1,$c2);
101 &sqr_add_c2($a[7],$a[3],$c0,$c1,$c2);
102 &st($c0,&QWPw(10,$rp));
103 ($c0,$c1,$c2)=($c1,$c2,$c0);
104 &mov("zero",$c2);
105
106 &sqr_add_c2($a[6],$a[5],$c0,$c1,$c2);
107 &sqr_add_c2($a[7],$a[4],$c0,$c1,$c2);
108 &st($c0,&QWPw(11,$rp));
109 ($c0,$c1,$c2)=($c1,$c2,$c0);
110 &mov("zero",$c2);
111
112 &sqr_add_c($a[6],$c0,$c1,$c2);
113 &sqr_add_c2($a[7],$a[5],$c0,$c1,$c2);
114 &st($c0,&QWPw(12,$rp));
115 ($c0,$c1,$c2)=($c1,$c2,$c0);
116 &mov("zero",$c2);
117
118 &sqr_add_c2($a[7],$a[6],$c0,$c1,$c2);
119 &st($c0,&QWPw(13,$rp));
120 ($c0,$c1,$c2)=($c1,$c2,$c0);
121 &mov("zero",$c2);
122
123 &sqr_add_c($a[7],$c0,$c1,$c2);
124 &st($c0,&QWPw(14,$rp));
125 &st($c1,&QWPw(15,$rp));
126
127 &function_end($name);
128
129 &fin_pool;
130 }
131
1321;
diff --git a/src/lib/libcrypto/bn/asm/alpha/sub.pl b/src/lib/libcrypto/bn/asm/alpha/sub.pl
new file mode 100644
index 0000000000..d998da5c21
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/alpha/sub.pl
@@ -0,0 +1,108 @@
1#!/usr/local/bin/perl
2# alpha assember
3
4sub bn_sub_words
5 {
6 local($name)=@_;
7 local($cc,$a,$b,$r);
8
9 &init_pool(4);
10 ($cc)=GR("r0");
11
12 $rp=&wparam(0);
13 $ap=&wparam(1);
14 $bp=&wparam(2);
15 $count=&wparam(3);
16
17 &function_begin($name,"");
18
19 &comment("");
20 &sub($count,4,$count);
21 &mov("zero",$cc);
22 &blt($count,&label("finish"));
23
24 ($a0,$b0)=&NR(2);
25 &ld($a0,&QWPw(0,$ap));
26 &ld($b0,&QWPw(0,$bp));
27
28##########################################################
29 &set_label("loop");
30
31 ($a1,$tmp,$b1,$a2,$b2,$a3,$b3,$o0)=&NR(8);
32 &ld($a1,&QWPw(1,$ap));
33 &cmpult($a0,$b0,$tmp); # will we borrow?
34 &ld($b1,&QWPw(1,$bp));
35 &sub($a0,$b0,$a0); # do the subtract
36 &ld($a2,&QWPw(2,$ap));
37 &cmpult($a0,$cc,$b0); # will we borrow?
38 &ld($b2,&QWPw(2,$bp));
39 &sub($a0,$cc,$o0); # will we borrow?
40 &ld($a3,&QWPw(3,$ap));
41 &add($b0,$tmp,$cc); ($t1,$o1)=&NR(2); &FR($tmp);
42
43 &cmpult($a1,$b1,$t1); # will we borrow?
44 &sub($a1,$b1,$a1); # do the subtract
45 &ld($b3,&QWPw(3,$bp));
46 &cmpult($a1,$cc,$b1); # will we borrow?
47 &sub($a1,$cc,$o1); # will we borrow?
48 &add($b1,$t1,$cc); ($tmp,$o2)=&NR(2); &FR($t1,$a1,$b1);
49
50 &cmpult($a2,$b2,$tmp); # will we borrow?
51 &sub($a2,$b2,$a2); # do the subtract
52 &st($o0,&QWPw(0,$rp)); &FR($o0); # save
53 &cmpult($a2,$cc,$b2); # will we borrow?
54 &sub($a2,$cc,$o2); # will we borrow?
55 &add($b2,$tmp,$cc); ($t3,$o3)=&NR(2); &FR($tmp,$a2,$b2);
56
57 &cmpult($a3,$b3,$t3); # will we borrow?
58 &sub($a3,$b3,$a3); # do the subtract
59 &st($o1,&QWPw(1,$rp)); &FR($o1);
60 &cmpult($a3,$cc,$b3); # will we borrow?
61 &sub($a3,$cc,$o3); # will we borrow?
62 &add($b3,$t3,$cc); &FR($t3,$a3,$b3);
63
64 &st($o2,&QWPw(2,$rp)); &FR($o2);
65 &sub($count,4,$count); # count-=4
66 &st($o3,&QWPw(3,$rp)); &FR($o3);
67 &add($ap,4*$QWS,$ap); # count+=4
68 &add($bp,4*$QWS,$bp); # count+=4
69 &add($rp,4*$QWS,$rp); # count+=4
70
71 &blt($count,&label("finish"));
72 &ld($a0,&QWPw(0,$ap));
73 &ld($b0,&QWPw(0,$bp));
74 &br(&label("loop"));
75##################################################
76 # Do the last 0..3 words
77
78 &set_label("last_loop");
79
80 &ld($a0,&QWPw(0,$ap)); # get a
81 &ld($b0,&QWPw(0,$bp)); # get b
82 &cmpult($a0,$b0,$tmp); # will we borrow?
83 &sub($a0,$b0,$a0); # do the subtract
84 &cmpult($a0,$cc,$b0); # will we borrow?
85 &sub($a0,$cc,$a0); # will we borrow?
86 &st($a0,&QWPw(0,$rp)); # save
87 &add($b0,$tmp,$cc); # add the borrows
88
89 &add($ap,$QWS,$ap);
90 &add($bp,$QWS,$bp);
91 &add($rp,$QWS,$rp);
92 &sub($count,1,$count);
93 &bgt($count,&label("last_loop"));
94 &function_end_A($name);
95
96######################################################
97 &set_label("finish");
98 &add($count,4,$count);
99 &bgt($count,&label("last_loop"));
100
101 &FR($a0,$b0);
102 &set_label("end");
103 &function_end($name);
104
105 &fin_pool;
106 }
107
1081;
diff --git a/src/lib/libcrypto/bn/asm/bn-alpha.pl b/src/lib/libcrypto/bn/asm/bn-alpha.pl
new file mode 100644
index 0000000000..302edf2376
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/bn-alpha.pl
@@ -0,0 +1,571 @@
1#!/usr/local/bin/perl
2# I have this in perl so I can use more usefull register names and then convert
3# them into alpha registers.
4#
5
6$d=&data();
7$d =~ s/CC/0/g;
8$d =~ s/R1/1/g;
9$d =~ s/R2/2/g;
10$d =~ s/R3/3/g;
11$d =~ s/R4/4/g;
12$d =~ s/L1/5/g;
13$d =~ s/L2/6/g;
14$d =~ s/L3/7/g;
15$d =~ s/L4/8/g;
16$d =~ s/O1/22/g;
17$d =~ s/O2/23/g;
18$d =~ s/O3/24/g;
19$d =~ s/O4/25/g;
20$d =~ s/A1/20/g;
21$d =~ s/A2/21/g;
22$d =~ s/A3/27/g;
23$d =~ s/A4/28/g;
24if (0){
25}
26
27print $d;
28
29sub data
30 {
31 local($data)=<<'EOF';
32
33 # DEC Alpha assember
34 # The bn_div_words is actually gcc output but the other parts are hand done.
35 # Thanks to tzeruch@ceddec.com for sending me the gcc output for
36 # bn_div_words.
37 # I've gone back and re-done most of routines.
38 # The key thing to remeber for the 164 CPU is that while a
39 # multiply operation takes 8 cycles, another one can only be issued
40 # after 4 cycles have elapsed. I've done modification to help
41 # improve this. Also, normally, a ld instruction will not be available
42 # for about 3 cycles.
43 .file 1 "bn_asm.c"
44 .set noat
45gcc2_compiled.:
46__gnu_compiled_c:
47 .text
48 .align 3
49 .globl bn_mul_add_words
50 .ent bn_mul_add_words
51bn_mul_add_words:
52bn_mul_add_words..ng:
53 .frame $30,0,$26,0
54 .prologue 0
55 .align 5
56 subq $18,4,$18
57 bis $31,$31,$CC
58 blt $18,$43 # if we are -1, -2, -3 or -4 goto tail code
59 ldq $A1,0($17) # 1 1
60 ldq $R1,0($16) # 1 1
61 .align 3
62$42:
63 mulq $A1,$19,$L1 # 1 2 1 ######
64 ldq $A2,8($17) # 2 1
65 ldq $R2,8($16) # 2 1
66 umulh $A1,$19,$A1 # 1 2 ######
67 ldq $A3,16($17) # 3 1
68 ldq $R3,16($16) # 3 1
69 mulq $A2,$19,$L2 # 2 2 1 ######
70 ldq $A4,24($17) # 4 1
71 addq $R1,$L1,$R1 # 1 2 2
72 ldq $R4,24($16) # 4 1
73 umulh $A2,$19,$A2 # 2 2 ######
74 cmpult $R1,$L1,$O1 # 1 2 3 1
75 addq $A1,$O1,$A1 # 1 3 1
76 addq $R1,$CC,$R1 # 1 2 3 1
77 mulq $A3,$19,$L3 # 3 2 1 ######
78 cmpult $R1,$CC,$CC # 1 2 3 2
79 addq $R2,$L2,$R2 # 2 2 2
80 addq $A1,$CC,$CC # 1 3 2
81 cmpult $R2,$L2,$O2 # 2 2 3 1
82 addq $A2,$O2,$A2 # 2 3 1
83 umulh $A3,$19,$A3 # 3 2 ######
84 addq $R2,$CC,$R2 # 2 2 3 1
85 cmpult $R2,$CC,$CC # 2 2 3 2
86 subq $18,4,$18
87 mulq $A4,$19,$L4 # 4 2 1 ######
88 addq $A2,$CC,$CC # 2 3 2
89 addq $R3,$L3,$R3 # 3 2 2
90 addq $16,32,$16
91 cmpult $R3,$L3,$O3 # 3 2 3 1
92 stq $R1,-32($16) # 1 2 4
93 umulh $A4,$19,$A4 # 4 2 ######
94 addq $A3,$O3,$A3 # 3 3 1
95 addq $R3,$CC,$R3 # 3 2 3 1
96 stq $R2,-24($16) # 2 2 4
97 cmpult $R3,$CC,$CC # 3 2 3 2
98 stq $R3,-16($16) # 3 2 4
99 addq $R4,$L4,$R4 # 4 2 2
100 addq $A3,$CC,$CC # 3 3 2
101 cmpult $R4,$L4,$O4 # 4 2 3 1
102 addq $17,32,$17
103 addq $A4,$O4,$A4 # 4 3 1
104 addq $R4,$CC,$R4 # 4 2 3 1
105 cmpult $R4,$CC,$CC # 4 2 3 2
106 stq $R4,-8($16) # 4 2 4
107 addq $A4,$CC,$CC # 4 3 2
108 blt $18,$43
109
110 ldq $A1,0($17) # 1 1
111 ldq $R1,0($16) # 1 1
112
113 br $42
114
115 .align 4
116$45:
117 ldq $A1,0($17) # 4 1
118 ldq $R1,0($16) # 4 1
119 mulq $A1,$19,$L1 # 4 2 1
120 subq $18,1,$18
121 addq $16,8,$16
122 addq $17,8,$17
123 umulh $A1,$19,$A1 # 4 2
124 addq $R1,$L1,$R1 # 4 2 2
125 cmpult $R1,$L1,$O1 # 4 2 3 1
126 addq $A1,$O1,$A1 # 4 3 1
127 addq $R1,$CC,$R1 # 4 2 3 1
128 cmpult $R1,$CC,$CC # 4 2 3 2
129 addq $A1,$CC,$CC # 4 3 2
130 stq $R1,-8($16) # 4 2 4
131 bgt $18,$45
132 ret $31,($26),1 # else exit
133
134 .align 4
135$43:
136 addq $18,4,$18
137 bgt $18,$45 # goto tail code
138 ret $31,($26),1 # else exit
139
140 .end bn_mul_add_words
141 .align 3
142 .globl bn_mul_words
143 .ent bn_mul_words
144bn_mul_words:
145bn_mul_words..ng:
146 .frame $30,0,$26,0
147 .prologue 0
148 .align 5
149 subq $18,4,$18
150 bis $31,$31,$CC
151 blt $18,$143 # if we are -1, -2, -3 or -4 goto tail code
152 ldq $A1,0($17) # 1 1
153 .align 3
154$142:
155
156 mulq $A1,$19,$L1 # 1 2 1 #####
157 ldq $A2,8($17) # 2 1
158 ldq $A3,16($17) # 3 1
159 umulh $A1,$19,$A1 # 1 2 #####
160 ldq $A4,24($17) # 4 1
161 mulq $A2,$19,$L2 # 2 2 1 #####
162 addq $L1,$CC,$L1 # 1 2 3 1
163 subq $18,4,$18
164 cmpult $L1,$CC,$CC # 1 2 3 2
165 umulh $A2,$19,$A2 # 2 2 #####
166 addq $A1,$CC,$CC # 1 3 2
167 addq $17,32,$17
168 addq $L2,$CC,$L2 # 2 2 3 1
169 mulq $A3,$19,$L3 # 3 2 1 #####
170 cmpult $L2,$CC,$CC # 2 2 3 2
171 addq $A2,$CC,$CC # 2 3 2
172 addq $16,32,$16
173 umulh $A3,$19,$A3 # 3 2 #####
174 stq $L1,-32($16) # 1 2 4
175 mulq $A4,$19,$L4 # 4 2 1 #####
176 addq $L3,$CC,$L3 # 3 2 3 1
177 stq $L2,-24($16) # 2 2 4
178 cmpult $L3,$CC,$CC # 3 2 3 2
179 umulh $A4,$19,$A4 # 4 2 #####
180 addq $A3,$CC,$CC # 3 3 2
181 stq $L3,-16($16) # 3 2 4
182 addq $L4,$CC,$L4 # 4 2 3 1
183 cmpult $L4,$CC,$CC # 4 2 3 2
184
185 addq $A4,$CC,$CC # 4 3 2
186
187 stq $L4,-8($16) # 4 2 4
188
189 blt $18,$143
190
191 ldq $A1,0($17) # 1 1
192
193 br $142
194
195 .align 4
196$145:
197 ldq $A1,0($17) # 4 1
198 mulq $A1,$19,$L1 # 4 2 1
199 subq $18,1,$18
200 umulh $A1,$19,$A1 # 4 2
201 addq $L1,$CC,$L1 # 4 2 3 1
202 addq $16,8,$16
203 cmpult $L1,$CC,$CC # 4 2 3 2
204 addq $17,8,$17
205 addq $A1,$CC,$CC # 4 3 2
206 stq $L1,-8($16) # 4 2 4
207
208 bgt $18,$145
209 ret $31,($26),1 # else exit
210
211 .align 4
212$143:
213 addq $18,4,$18
214 bgt $18,$145 # goto tail code
215 ret $31,($26),1 # else exit
216
217 .end bn_mul_words
218 .align 3
219 .globl bn_sqr_words
220 .ent bn_sqr_words
221bn_sqr_words:
222bn_sqr_words..ng:
223 .frame $30,0,$26,0
224 .prologue 0
225
226 subq $18,4,$18
227 blt $18,$543 # if we are -1, -2, -3 or -4 goto tail code
228 ldq $A1,0($17) # 1 1
229 .align 3
230$542:
231 mulq $A1,$A1,$L1 ######
232 ldq $A2,8($17) # 1 1
233 subq $18,4
234 umulh $A1,$A1,$R1 ######
235 ldq $A3,16($17) # 1 1
236 mulq $A2,$A2,$L2 ######
237 ldq $A4,24($17) # 1 1
238 stq $L1,0($16) # r[0]
239 umulh $A2,$A2,$R2 ######
240 stq $R1,8($16) # r[1]
241 mulq $A3,$A3,$L3 ######
242 stq $L2,16($16) # r[0]
243 umulh $A3,$A3,$R3 ######
244 stq $R2,24($16) # r[1]
245 mulq $A4,$A4,$L4 ######
246 stq $L3,32($16) # r[0]
247 umulh $A4,$A4,$R4 ######
248 stq $R3,40($16) # r[1]
249
250 addq $16,64,$16
251 addq $17,32,$17
252 stq $L4,-16($16) # r[0]
253 stq $R4,-8($16) # r[1]
254
255 blt $18,$543
256 ldq $A1,0($17) # 1 1
257 br $542
258
259$442:
260 ldq $A1,0($17) # a[0]
261 mulq $A1,$A1,$L1 # a[0]*w low part r2
262 addq $16,16,$16
263 addq $17,8,$17
264 subq $18,1,$18
265 umulh $A1,$A1,$R1 # a[0]*w high part r3
266 stq $L1,-16($16) # r[0]
267 stq $R1,-8($16) # r[1]
268
269 bgt $18,$442
270 ret $31,($26),1 # else exit
271
272 .align 4
273$543:
274 addq $18,4,$18
275 bgt $18,$442 # goto tail code
276 ret $31,($26),1 # else exit
277 .end bn_sqr_words
278
279 .align 3
280 .globl bn_add_words
281 .ent bn_add_words
282bn_add_words:
283bn_add_words..ng:
284 .frame $30,0,$26,0
285 .prologue 0
286
287 subq $19,4,$19
288 bis $31,$31,$CC # carry = 0
289 blt $19,$900
290 ldq $L1,0($17) # a[0]
291 ldq $R1,0($18) # b[1]
292 .align 3
293$901:
294 addq $R1,$L1,$R1 # r=a+b;
295 ldq $L2,8($17) # a[1]
296 cmpult $R1,$L1,$O1 # did we overflow?
297 ldq $R2,8($18) # b[1]
298 addq $R1,$CC,$R1 # c+= overflow
299 ldq $L3,16($17) # a[2]
300 cmpult $R1,$CC,$CC # overflow?
301 ldq $R3,16($18) # b[2]
302 addq $CC,$O1,$CC
303 ldq $L4,24($17) # a[3]
304 addq $R2,$L2,$R2 # r=a+b;
305 ldq $R4,24($18) # b[3]
306 cmpult $R2,$L2,$O2 # did we overflow?
307 addq $R3,$L3,$R3 # r=a+b;
308 addq $R2,$CC,$R2 # c+= overflow
309 cmpult $R3,$L3,$O3 # did we overflow?
310 cmpult $R2,$CC,$CC # overflow?
311 addq $R4,$L4,$R4 # r=a+b;
312 addq $CC,$O2,$CC
313 cmpult $R4,$L4,$O4 # did we overflow?
314 addq $R3,$CC,$R3 # c+= overflow
315 stq $R1,0($16) # r[0]=c
316 cmpult $R3,$CC,$CC # overflow?
317 stq $R2,8($16) # r[1]=c
318 addq $CC,$O3,$CC
319 stq $R3,16($16) # r[2]=c
320 addq $R4,$CC,$R4 # c+= overflow
321 subq $19,4,$19 # loop--
322 cmpult $R4,$CC,$CC # overflow?
323 addq $17,32,$17 # a++
324 addq $CC,$O4,$CC
325 stq $R4,24($16) # r[3]=c
326 addq $18,32,$18 # b++
327 addq $16,32,$16 # r++
328
329 blt $19,$900
330 ldq $L1,0($17) # a[0]
331 ldq $R1,0($18) # b[1]
332 br $901
333 .align 4
334$945:
335 ldq $L1,0($17) # a[0]
336 ldq $R1,0($18) # b[1]
337 addq $R1,$L1,$R1 # r=a+b;
338 subq $19,1,$19 # loop--
339 addq $R1,$CC,$R1 # c+= overflow
340 addq $17,8,$17 # a++
341 cmpult $R1,$L1,$O1 # did we overflow?
342 cmpult $R1,$CC,$CC # overflow?
343 addq $18,8,$18 # b++
344 stq $R1,0($16) # r[0]=c
345 addq $CC,$O1,$CC
346 addq $16,8,$16 # r++
347
348 bgt $19,$945
349 ret $31,($26),1 # else exit
350
351$900:
352 addq $19,4,$19
353 bgt $19,$945 # goto tail code
354 ret $31,($26),1 # else exit
355 .end bn_add_words
356
357 .align 3
358 .globl bn_sub_words
359 .ent bn_sub_words
360bn_sub_words:
361bn_sub_words..ng:
362 .frame $30,0,$26,0
363 .prologue 0
364
365 subq $19,4,$19
366 bis $31,$31,$CC # carry = 0
367 br $800
368 blt $19,$800
369 ldq $L1,0($17) # a[0]
370 ldq $R1,0($18) # b[1]
371 .align 3
372$801:
373 addq $R1,$L1,$R1 # r=a+b;
374 ldq $L2,8($17) # a[1]
375 cmpult $R1,$L1,$O1 # did we overflow?
376 ldq $R2,8($18) # b[1]
377 addq $R1,$CC,$R1 # c+= overflow
378 ldq $L3,16($17) # a[2]
379 cmpult $R1,$CC,$CC # overflow?
380 ldq $R3,16($18) # b[2]
381 addq $CC,$O1,$CC
382 ldq $L4,24($17) # a[3]
383 addq $R2,$L2,$R2 # r=a+b;
384 ldq $R4,24($18) # b[3]
385 cmpult $R2,$L2,$O2 # did we overflow?
386 addq $R3,$L3,$R3 # r=a+b;
387 addq $R2,$CC,$R2 # c+= overflow
388 cmpult $R3,$L3,$O3 # did we overflow?
389 cmpult $R2,$CC,$CC # overflow?
390 addq $R4,$L4,$R4 # r=a+b;
391 addq $CC,$O2,$CC
392 cmpult $R4,$L4,$O4 # did we overflow?
393 addq $R3,$CC,$R3 # c+= overflow
394 stq $R1,0($16) # r[0]=c
395 cmpult $R3,$CC,$CC # overflow?
396 stq $R2,8($16) # r[1]=c
397 addq $CC,$O3,$CC
398 stq $R3,16($16) # r[2]=c
399 addq $R4,$CC,$R4 # c+= overflow
400 subq $19,4,$19 # loop--
401 cmpult $R4,$CC,$CC # overflow?
402 addq $17,32,$17 # a++
403 addq $CC,$O4,$CC
404 stq $R4,24($16) # r[3]=c
405 addq $18,32,$18 # b++
406 addq $16,32,$16 # r++
407
408 blt $19,$800
409 ldq $L1,0($17) # a[0]
410 ldq $R1,0($18) # b[1]
411 br $801
412 .align 4
413$845:
414 ldq $L1,0($17) # a[0]
415 ldq $R1,0($18) # b[1]
416 cmpult $L1,$R1,$O1 # will we borrow?
417 subq $L1,$R1,$R1 # r=a-b;
418 subq $19,1,$19 # loop--
419 cmpult $R1,$CC,$O2 # will we borrow?
420 subq $R1,$CC,$R1 # c+= overflow
421 addq $17,8,$17 # a++
422 addq $18,8,$18 # b++
423 stq $R1,0($16) # r[0]=c
424 addq $O2,$O1,$CC
425 addq $16,8,$16 # r++
426
427 bgt $19,$845
428 ret $31,($26),1 # else exit
429
430$800:
431 addq $19,4,$19
432 bgt $19,$845 # goto tail code
433 ret $31,($26),1 # else exit
434 .end bn_sub_words
435
436 #
437 # What follows was taken directly from the C compiler with a few
438 # hacks to redo the lables.
439 #
440.text
441 .align 3
442 .globl bn_div_words
443 .ent bn_div_words
444bn_div_words:
445 ldgp $29,0($27)
446bn_div_words..ng:
447 lda $30,-48($30)
448 .frame $30,48,$26,0
449 stq $26,0($30)
450 stq $9,8($30)
451 stq $10,16($30)
452 stq $11,24($30)
453 stq $12,32($30)
454 stq $13,40($30)
455 .mask 0x4003e00,-48
456 .prologue 1
457 bis $16,$16,$9
458 bis $17,$17,$10
459 bis $18,$18,$11
460 bis $31,$31,$13
461 bis $31,2,$12
462 bne $11,$119
463 lda $0,-1
464 br $31,$136
465 .align 4
466$119:
467 bis $11,$11,$16
468 jsr $26,BN_num_bits_word
469 ldgp $29,0($26)
470 subq $0,64,$1
471 beq $1,$120
472 bis $31,1,$1
473 sll $1,$0,$1
474 cmpule $9,$1,$1
475 bne $1,$120
476 # lda $16,_IO_stderr_
477 # lda $17,$C32
478 # bis $0,$0,$18
479 # jsr $26,fprintf
480 # ldgp $29,0($26)
481 jsr $26,abort
482 ldgp $29,0($26)
483 .align 4
484$120:
485 bis $31,64,$3
486 cmpult $9,$11,$2
487 subq $3,$0,$1
488 addl $1,$31,$0
489 subq $9,$11,$1
490 cmoveq $2,$1,$9
491 beq $0,$122
492 zapnot $0,15,$2
493 subq $3,$0,$1
494 sll $11,$2,$11
495 sll $9,$2,$3
496 srl $10,$1,$1
497 sll $10,$2,$10
498 bis $3,$1,$9
499$122:
500 srl $11,32,$5
501 zapnot $11,15,$6
502 lda $7,-1
503 .align 5
504$123:
505 srl $9,32,$1
506 subq $1,$5,$1
507 bne $1,$126
508 zapnot $7,15,$27
509 br $31,$127
510 .align 4
511$126:
512 bis $9,$9,$24
513 bis $5,$5,$25
514 divqu $24,$25,$27
515$127:
516 srl $10,32,$4
517 .align 5
518$128:
519 mulq $27,$5,$1
520 subq $9,$1,$3
521 zapnot $3,240,$1
522 bne $1,$129
523 mulq $6,$27,$2
524 sll $3,32,$1
525 addq $1,$4,$1
526 cmpule $2,$1,$2
527 bne $2,$129
528 subq $27,1,$27
529 br $31,$128
530 .align 4
531$129:
532 mulq $27,$6,$1
533 mulq $27,$5,$4
534 srl $1,32,$3
535 sll $1,32,$1
536 addq $4,$3,$4
537 cmpult $10,$1,$2
538 subq $10,$1,$10
539 addq $2,$4,$2
540 cmpult $9,$2,$1
541 bis $2,$2,$4
542 beq $1,$134
543 addq $9,$11,$9
544 subq $27,1,$27
545$134:
546 subl $12,1,$12
547 subq $9,$4,$9
548 beq $12,$124
549 sll $27,32,$13
550 sll $9,32,$2
551 srl $10,32,$1
552 sll $10,32,$10
553 bis $2,$1,$9
554 br $31,$123
555 .align 4
556$124:
557 bis $13,$27,$0
558$136:
559 ldq $26,0($30)
560 ldq $9,8($30)
561 ldq $10,16($30)
562 ldq $11,24($30)
563 ldq $12,32($30)
564 ldq $13,40($30)
565 addq $30,48,$30
566 ret $31,($26),1
567 .end bn_div_words
568EOF
569 return($data);
570 }
571
diff --git a/src/lib/libcrypto/bn/asm/ca.pl b/src/lib/libcrypto/bn/asm/ca.pl
new file mode 100644
index 0000000000..c1ce67a6b4
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/ca.pl
@@ -0,0 +1,33 @@
1#!/usr/local/bin/perl
2# I have this in perl so I can use more usefull register names and then convert
3# them into alpha registers.
4#
5
6push(@INC,"perlasm","../../perlasm");
7require "alpha.pl";
8require "alpha/mul_add.pl";
9require "alpha/mul.pl";
10require "alpha/sqr.pl";
11require "alpha/add.pl";
12require "alpha/sub.pl";
13require "alpha/mul_c8.pl";
14require "alpha/mul_c4.pl";
15require "alpha/sqr_c4.pl";
16require "alpha/sqr_c8.pl";
17require "alpha/div.pl";
18
19&asm_init($ARGV[0],$0);
20
21&bn_mul_words("bn_mul_words");
22&bn_sqr_words("bn_sqr_words");
23&bn_mul_add_words("bn_mul_add_words");
24&bn_add_words("bn_add_words");
25&bn_sub_words("bn_sub_words");
26&bn_div_words("bn_div_words");
27&bn_mul_comba8("bn_mul_comba8");
28&bn_mul_comba4("bn_mul_comba4");
29&bn_sqr_comba4("bn_sqr_comba4");
30&bn_sqr_comba8("bn_sqr_comba8");
31
32&asm_finish();
33
diff --git a/src/lib/libcrypto/bn/asm/co-alpha.pl b/src/lib/libcrypto/bn/asm/co-alpha.pl
new file mode 100644
index 0000000000..67dad3e3d5
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/co-alpha.pl
@@ -0,0 +1,116 @@
1#!/usr/local/bin/perl
2# I have this in perl so I can use more usefull register names and then convert
3# them into alpha registers.
4#
5
6push(@INC,"perlasm","../../perlasm");
7require "alpha.pl";
8
9&asm_init($ARGV[0],$0);
10
11print &bn_sub_words("bn_sub_words");
12
13&asm_finish();
14
15sub bn_sub_words
16 {
17 local($name)=@_;
18 local($cc,$a,$b,$r);
19
20 $cc="r0";
21 $a0="r1"; $b0="r5"; $r0="r9"; $tmp="r13";
22 $a1="r2"; $b1="r6"; $r1="r10"; $t1="r14";
23 $a2="r3"; $b2="r7"; $r2="r11";
24 $a3="r4"; $b3="r8"; $r3="r12"; $t3="r15";
25
26 $rp=&wparam(0);
27 $ap=&wparam(1);
28 $bp=&wparam(2);
29 $count=&wparam(3);
30
31 &function_begin($name,"");
32
33 &comment("");
34 &sub($count,4,$count);
35 &mov("zero",$cc);
36 &blt($count,&label("finish"));
37
38 &ld($a0,&QWPw(0,$ap));
39 &ld($b0,&QWPw(0,$bp));
40
41##########################################################
42 &set_label("loop");
43
44 &ld($a1,&QWPw(1,$ap));
45 &cmpult($a0,$b0,$tmp); # will we borrow?
46 &ld($b1,&QWPw(1,$bp));
47 &sub($a0,$b0,$a0); # do the subtract
48 &ld($a2,&QWPw(2,$ap));
49 &cmpult($a0,$cc,$b0); # will we borrow?
50 &ld($b2,&QWPw(2,$bp));
51 &sub($a0,$cc,$a0); # will we borrow?
52 &ld($a3,&QWPw(3,$ap));
53 &add($b0,$tmp,$cc); # add the borrows
54
55 &cmpult($a1,$b1,$t1); # will we borrow?
56 &sub($a1,$b1,$a1); # do the subtract
57 &ld($b3,&QWPw(3,$bp));
58 &cmpult($a1,$cc,$b1); # will we borrow?
59 &sub($a1,$cc,$a1); # will we borrow?
60 &add($b1,$t1,$cc); # add the borrows
61
62 &cmpult($a2,$b2,$tmp); # will we borrow?
63 &sub($a2,$b2,$a2); # do the subtract
64 &st($a0,&QWPw(0,$rp)); # save
65 &cmpult($a2,$cc,$b2); # will we borrow?
66 &sub($a2,$cc,$a2); # will we borrow?
67 &add($b2,$tmp,$cc); # add the borrows
68
69 &cmpult($a3,$b3,$t3); # will we borrow?
70 &sub($a3,$b3,$a3); # do the subtract
71 &st($a1,&QWPw(1,$rp)); # save
72 &cmpult($a3,$cc,$b3); # will we borrow?
73 &sub($a3,$cc,$a3); # will we borrow?
74 &add($b3,$t3,$cc); # add the borrows
75
76 &st($a2,&QWPw(2,$rp)); # save
77 &sub($count,4,$count); # count-=4
78 &st($a3,&QWPw(3,$rp)); # save
79 &add($ap,4*$QWS,$ap); # count+=4
80 &add($bp,4*$QWS,$bp); # count+=4
81 &add($rp,4*$QWS,$rp); # count+=4
82
83 &blt($count,&label("finish"));
84 &ld($a0,&QWPw(0,$ap));
85 &ld($b0,&QWPw(0,$bp));
86 &br(&label("loop"));
87##################################################
88 # Do the last 0..3 words
89
90 &set_label("last_loop");
91
92 &ld($a0,&QWPw(0,$ap)); # get a
93 &ld($b0,&QWPw(0,$bp)); # get b
94 &cmpult($a0,$b0,$tmp); # will we borrow?
95 &sub($a0,$b0,$a0); # do the subtract
96 &cmpult($a0,$cc,$b0); # will we borrow?
97 &sub($a0,$cc,$a0); # will we borrow?
98 &st($a0,&QWPw(0,$rp)); # save
99 &add($b0,$tmp,$cc); # add the borrows
100
101 &add($ap,$QWS,$ap);
102 &add($bp,$QWS,$bp);
103 &add($rp,$QWS,$rp);
104 &sub($count,1,$count);
105 &bgt($count,&label("last_loop"));
106 &function_end_A($name);
107
108######################################################
109 &set_label("finish");
110 &add($count,4,$count);
111 &bgt($count,&label("last_loop"));
112
113 &set_label("end");
114 &function_end($name);
115 }
116
diff --git a/src/lib/libcrypto/bn/asm/mips1.s b/src/lib/libcrypto/bn/asm/mips1.s
new file mode 100644
index 0000000000..44fa1254c7
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/mips1.s
@@ -0,0 +1,539 @@
1/* This assember is for R2000/R3000 machines, or higher ones that do
2 * no want to do any 64 bit arithmatic.
3 * Make sure that the SSLeay bignum library is compiled with
4 * THIRTY_TWO_BIT set.
5 * This must either be compiled with the system CC, or, if you use GNU gas,
6 * cc -E mips1.s|gas -o mips1.o
7 */
8 .set reorder
9 .set noat
10
11#define R1 $1
12#define CC $2
13#define R2 $3
14#define R3 $8
15#define R4 $9
16#define L1 $10
17#define L2 $11
18#define L3 $12
19#define L4 $13
20#define H1 $14
21#define H2 $15
22#define H3 $24
23#define H4 $25
24
25#define P1 $4
26#define P2 $5
27#define P3 $6
28#define P4 $7
29
30 .align 2
31 .ent bn_mul_add_words
32 .globl bn_mul_add_words
33.text
34bn_mul_add_words:
35 .frame $sp,0,$31
36 .mask 0x00000000,0
37 .fmask 0x00000000,0
38
39 #blt P3,4,$lab34
40
41 subu R1,P3,4
42 move CC,$0
43 bltz R1,$lab34
44$lab2:
45 lw R1,0(P1)
46 lw L1,0(P2)
47 lw R2,4(P1)
48 lw L2,4(P2)
49 lw R3,8(P1)
50 lw L3,8(P2)
51 lw R4,12(P1)
52 lw L4,12(P2)
53 multu L1,P4
54 addu R1,R1,CC
55 mflo L1
56 sltu CC,R1,CC
57 addu R1,R1,L1
58 mfhi H1
59 sltu L1,R1,L1
60 sw R1,0(P1)
61 addu CC,CC,L1
62 multu L2,P4
63 addu CC,H1,CC
64 mflo L2
65 addu R2,R2,CC
66 sltu CC,R2,CC
67 mfhi H2
68 addu R2,R2,L2
69 addu P2,P2,16
70 sltu L2,R2,L2
71 sw R2,4(P1)
72 addu CC,CC,L2
73 multu L3,P4
74 addu CC,H2,CC
75 mflo L3
76 addu R3,R3,CC
77 sltu CC,R3,CC
78 mfhi H3
79 addu R3,R3,L3
80 addu P1,P1,16
81 sltu L3,R3,L3
82 sw R3,-8(P1)
83 addu CC,CC,L3
84 multu L4,P4
85 addu CC,H3,CC
86 mflo L4
87 addu R4,R4,CC
88 sltu CC,R4,CC
89 mfhi H4
90 addu R4,R4,L4
91 subu P3,P3,4
92 sltu L4,R4,L4
93 addu CC,CC,L4
94 addu CC,H4,CC
95
96 subu R1,P3,4
97 sw R4,-4(P1) # delay slot
98 bgez R1,$lab2
99
100 bleu P3,0,$lab3
101 .align 2
102$lab33:
103 lw L1,0(P2)
104 lw R1,0(P1)
105 multu L1,P4
106 addu R1,R1,CC
107 sltu CC,R1,CC
108 addu P1,P1,4
109 mflo L1
110 mfhi H1
111 addu R1,R1,L1
112 addu P2,P2,4
113 sltu L1,R1,L1
114 subu P3,P3,1
115 addu CC,CC,L1
116 sw R1,-4(P1)
117 addu CC,H1,CC
118 bgtz P3,$lab33
119 j $31
120 .align 2
121$lab3:
122 j $31
123 .align 2
124$lab34:
125 bgt P3,0,$lab33
126 j $31
127 .end bn_mul_add_words
128
129 .align 2
130 # Program Unit: bn_mul_words
131 .ent bn_mul_words
132 .globl bn_mul_words
133.text
134bn_mul_words:
135 .frame $sp,0,$31
136 .mask 0x00000000,0
137 .fmask 0x00000000,0
138
139 subu P3,P3,4
140 move CC,$0
141 bltz P3,$lab45
142$lab44:
143 lw L1,0(P2)
144 lw L2,4(P2)
145 lw L3,8(P2)
146 lw L4,12(P2)
147 multu L1,P4
148 subu P3,P3,4
149 mflo L1
150 mfhi H1
151 addu L1,L1,CC
152 multu L2,P4
153 sltu CC,L1,CC
154 sw L1,0(P1)
155 addu CC,H1,CC
156 mflo L2
157 mfhi H2
158 addu L2,L2,CC
159 multu L3,P4
160 sltu CC,L2,CC
161 sw L2,4(P1)
162 addu CC,H2,CC
163 mflo L3
164 mfhi H3
165 addu L3,L3,CC
166 multu L4,P4
167 sltu CC,L3,CC
168 sw L3,8(P1)
169 addu CC,H3,CC
170 mflo L4
171 mfhi H4
172 addu L4,L4,CC
173 addu P1,P1,16
174 sltu CC,L4,CC
175 addu P2,P2,16
176 addu CC,H4,CC
177 sw L4,-4(P1)
178
179 bgez P3,$lab44
180 b $lab45
181$lab46:
182 lw L1,0(P2)
183 addu P1,P1,4
184 multu L1,P4
185 addu P2,P2,4
186 mflo L1
187 mfhi H1
188 addu L1,L1,CC
189 subu P3,P3,1
190 sltu CC,L1,CC
191 sw L1,-4(P1)
192 addu CC,H1,CC
193 bgtz P3,$lab46
194 j $31
195$lab45:
196 addu P3,P3,4
197 bgtz P3,$lab46
198 j $31
199 .align 2
200 .end bn_mul_words
201
202 # Program Unit: bn_sqr_words
203 .ent bn_sqr_words
204 .globl bn_sqr_words
205.text
206bn_sqr_words:
207 .frame $sp,0,$31
208 .mask 0x00000000,0
209 .fmask 0x00000000,0
210
211 subu P3,P3,4
212 bltz P3,$lab55
213$lab54:
214 lw L1,0(P2)
215 lw L2,4(P2)
216 lw L3,8(P2)
217 lw L4,12(P2)
218
219 multu L1,L1
220 subu P3,P3,4
221 mflo L1
222 mfhi H1
223 sw L1,0(P1)
224 sw H1,4(P1)
225
226 multu L2,L2
227 addu P1,P1,32
228 mflo L2
229 mfhi H2
230 sw L2,-24(P1)
231 sw H2,-20(P1)
232
233 multu L3,L3
234 addu P2,P2,16
235 mflo L3
236 mfhi H3
237 sw L3,-16(P1)
238 sw H3,-12(P1)
239
240 multu L4,L4
241
242 mflo L4
243 mfhi H4
244 sw L4,-8(P1)
245 sw H4,-4(P1)
246
247 bgtz P3,$lab54
248 b $lab55
249$lab56:
250 lw L1,0(P2)
251 addu P1,P1,8
252 multu L1,L1
253 addu P2,P2,4
254 subu P3,P3,1
255 mflo L1
256 mfhi H1
257 sw L1,-8(P1)
258 sw H1,-4(P1)
259
260 bgtz P3,$lab56
261 j $31
262$lab55:
263 addu P3,P3,4
264 bgtz P3,$lab56
265 j $31
266 .align 2
267 .end bn_sqr_words
268
269 # Program Unit: bn_add_words
270 .ent bn_add_words
271 .globl bn_add_words
272.text
273bn_add_words: # 0x590
274 .frame $sp,0,$31
275 .mask 0x00000000,0
276 .fmask 0x00000000,0
277
278 subu P4,P4,4
279 move CC,$0
280 bltz P4,$lab65
281$lab64:
282 lw L1,0(P2)
283 lw R1,0(P3)
284 lw L2,4(P2)
285 lw R2,4(P3)
286
287 addu L1,L1,CC
288 lw L3,8(P2)
289 sltu CC,L1,CC
290 addu L1,L1,R1
291 sltu R1,L1,R1
292 lw R3,8(P3)
293 addu CC,CC,R1
294 lw L4,12(P2)
295
296 addu L2,L2,CC
297 lw R4,12(P3)
298 sltu CC,L2,CC
299 addu L2,L2,R2
300 sltu R2,L2,R2
301 sw L1,0(P1)
302 addu CC,CC,R2
303 addu P1,P1,16
304 addu L3,L3,CC
305 sw L2,-12(P1)
306
307 sltu CC,L3,CC
308 addu L3,L3,R3
309 sltu R3,L3,R3
310 addu P2,P2,16
311 addu CC,CC,R3
312
313 addu L4,L4,CC
314 addu P3,P3,16
315 sltu CC,L4,CC
316 addu L4,L4,R4
317 subu P4,P4,4
318 sltu R4,L4,R4
319 sw L3,-8(P1)
320 addu CC,CC,R4
321 sw L4,-4(P1)
322
323 bgtz P4,$lab64
324 b $lab65
325$lab66:
326 lw L1,0(P2)
327 lw R1,0(P3)
328 addu L1,L1,CC
329 addu P1,P1,4
330 sltu CC,L1,CC
331 addu P2,P2,4
332 addu P3,P3,4
333 addu L1,L1,R1
334 subu P4,P4,1
335 sltu R1,L1,R1
336 sw L1,-4(P1)
337 addu CC,CC,R1
338
339 bgtz P4,$lab66
340 j $31
341$lab65:
342 addu P4,P4,4
343 bgtz P4,$lab66
344 j $31
345 .end bn_add_words
346
347 # Program Unit: bn_div64
348 .set at
349 .set reorder
350 .text
351 .align 2
352 .globl bn_div64
353 # 321 {
354 .ent bn_div64 2
355bn_div64:
356 subu $sp, 64
357 sw $31, 56($sp)
358 sw $16, 48($sp)
359 .mask 0x80010000, -56
360 .frame $sp, 64, $31
361 move $9, $4
362 move $12, $5
363 move $16, $6
364 # 322 BN_ULONG dh,dl,q,ret=0,th,tl,t;
365 move $31, $0
366 # 323 int i,count=2;
367 li $13, 2
368 # 324
369 # 325 if (d == 0) return(BN_MASK2);
370 bne $16, 0, $80
371 li $2, -1
372 b $93
373$80:
374 # 326
375 # 327 i=BN_num_bits_word(d);
376 move $4, $16
377 sw $31, 16($sp)
378 sw $9, 24($sp)
379 sw $12, 32($sp)
380 sw $13, 40($sp)
381 .livereg 0x800ff0e,0xfff
382 jal BN_num_bits_word
383 li $4, 32
384 lw $31, 16($sp)
385 lw $9, 24($sp)
386 lw $12, 32($sp)
387 lw $13, 40($sp)
388 move $3, $2
389 # 328 if ((i != BN_BITS2) && (h > (BN_ULONG)1<<i))
390 beq $2, $4, $81
391 li $14, 1
392 sll $15, $14, $2
393 bleu $9, $15, $81
394 # 329 {
395 # 330 #if !defined(NO_STDIO) && !defined(WIN16)
396 # 331 fprintf(stderr,"Division would overflow (%d)\n",i);
397 # 332 #endif
398 # 333 abort();
399 sw $3, 8($sp)
400 sw $9, 24($sp)
401 sw $12, 32($sp)
402 sw $13, 40($sp)
403 sw $31, 26($sp)
404 .livereg 0xff0e,0xfff
405 jal abort
406 lw $3, 8($sp)
407 li $4, 32
408 lw $9, 24($sp)
409 lw $12, 32($sp)
410 lw $13, 40($sp)
411 lw $31, 26($sp)
412 # 334 }
413$81:
414 # 335 i=BN_BITS2-i;
415 subu $3, $4, $3
416 # 336 if (h >= d) h-=d;
417 bltu $9, $16, $82
418 subu $9, $9, $16
419$82:
420 # 337
421 # 338 if (i)
422 beq $3, 0, $83
423 # 339 {
424 # 340 d<<=i;
425 sll $16, $16, $3
426 # 341 h=(h<<i)|(l>>(BN_BITS2-i));
427 sll $24, $9, $3
428 subu $25, $4, $3
429 srl $14, $12, $25
430 or $9, $24, $14
431 # 342 l<<=i;
432 sll $12, $12, $3
433 # 343 }
434$83:
435 # 344 dh=(d&BN_MASK2h)>>BN_BITS4;
436 # 345 dl=(d&BN_MASK2l);
437 and $8, $16, -65536
438 srl $8, $8, 16
439 and $10, $16, 65535
440 li $6, -65536
441$84:
442 # 346 for (;;)
443 # 347 {
444 # 348 if ((h>>BN_BITS4) == dh)
445 srl $15, $9, 16
446 bne $8, $15, $85
447 # 349 q=BN_MASK2l;
448 li $5, 65535
449 b $86
450$85:
451 # 350 else
452 # 351 q=h/dh;
453 divu $5, $9, $8
454$86:
455 # 352
456 # 353 for (;;)
457 # 354 {
458 # 355 t=(h-q*dh);
459 mul $4, $5, $8
460 subu $2, $9, $4
461 move $3, $2
462 # 356 if ((t&BN_MASK2h) ||
463 # 357 ((dl*q) <= (
464 # 358 (t<<BN_BITS4)+
465 # 359 ((l&BN_MASK2h)>>BN_BITS4))))
466 and $25, $2, $6
467 bne $25, $0, $87
468 mul $24, $10, $5
469 sll $14, $3, 16
470 and $15, $12, $6
471 srl $25, $15, 16
472 addu $15, $14, $25
473 bgtu $24, $15, $88
474$87:
475 # 360 break;
476 mul $3, $10, $5
477 b $89
478$88:
479 # 361 q--;
480 addu $5, $5, -1
481 # 362 }
482 b $86
483$89:
484 # 363 th=q*dh;
485 # 364 tl=q*dl;
486 # 365 t=(tl>>BN_BITS4);
487 # 366 tl=(tl<<BN_BITS4)&BN_MASK2h;
488 sll $14, $3, 16
489 and $2, $14, $6
490 move $11, $2
491 # 367 th+=t;
492 srl $25, $3, 16
493 addu $7, $4, $25
494 # 368
495 # 369 if (l < tl) th++;
496 bgeu $12, $2, $90
497 addu $7, $7, 1
498$90:
499 # 370 l-=tl;
500 subu $12, $12, $11
501 # 371 if (h < th)
502 bgeu $9, $7, $91
503 # 372 {
504 # 373 h+=d;
505 addu $9, $9, $16
506 # 374 q--;
507 addu $5, $5, -1
508 # 375 }
509$91:
510 # 376 h-=th;
511 subu $9, $9, $7
512 # 377
513 # 378 if (--count == 0) break;
514 addu $13, $13, -1
515 beq $13, 0, $92
516 # 379
517 # 380 ret=q<<BN_BITS4;
518 sll $31, $5, 16
519 # 381 h=((h<<BN_BITS4)|(l>>BN_BITS4))&BN_MASK2;
520 sll $24, $9, 16
521 srl $15, $12, 16
522 or $9, $24, $15
523 # 382 l=(l&BN_MASK2l)<<BN_BITS4;
524 and $12, $12, 65535
525 sll $12, $12, 16
526 # 383 }
527 b $84
528$92:
529 # 384 ret|=q;
530 or $31, $31, $5
531 # 385 return(ret);
532 move $2, $31
533$93:
534 lw $16, 48($sp)
535 lw $31, 56($sp)
536 addu $sp, 64
537 j $31
538 .end bn_div64
539
diff --git a/src/lib/libcrypto/bn/asm/mips3.s b/src/lib/libcrypto/bn/asm/mips3.s
new file mode 100644
index 0000000000..191345d920
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/mips3.s
@@ -0,0 +1,2138 @@
1.rdata
2.asciiz "mips3.s, Version 1.0"
3.asciiz "MIPS III/IV ISA artwork by Andy Polyakov <appro@fy.chalmers.se>"
4
5/*
6 * ====================================================================
7 * Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
8 * project.
9 *
10 * Rights for redistribution and usage in source and binary forms are
11 * granted according to the OpenSSL license. Warranty of any kind is
12 * disclaimed.
13 * ====================================================================
14 */
15
16/*
17 * This is my modest contributon to the OpenSSL project (see
18 * http://www.openssl.org/ for more information about it) and is
19 * a drop-in MIPS III/IV ISA replacement for crypto/bn/bn_asm.c
20 * module. For updates see http://fy.chalmers.se/~appro/hpe/.
21 *
22 * The module is designed to work with either of the "new" MIPS ABI(5),
23 * namely N32 or N64, offered by IRIX 6.x. It's not ment to work under
24 * IRIX 5.x not only because it doesn't support new ABIs but also
25 * because 5.x kernels put R4x00 CPU into 32-bit mode and all those
26 * 64-bit instructions (daddu, dmultu, etc.) found below gonna only
27 * cause illegal instruction exception:-(
28 *
29 * In addition the code depends on preprocessor flags set up by MIPSpro
30 * compiler driver (either as or cc) and therefore (probably?) can't be
31 * compiled by the GNU assembler. GNU C driver manages fine though...
32 * I mean as long as -mmips-as is specified or is the default option,
33 * because then it simply invokes /usr/bin/as which in turn takes
34 * perfect care of the preprocessor definitions. Another neat feature
35 * offered by the MIPSpro assembler is an optimization pass. This gave
36 * me the opportunity to have the code looking more regular as all those
37 * architecture dependent instruction rescheduling details were left to
38 * the assembler. Cool, huh?
39 *
40 * Performance improvement is astonishing! 'apps/openssl speed rsa dsa'
41 * goes way over 3 times faster!
42 *
43 * <appro@fy.chalmers.se>
44 */
45#include <asm.h>
46#include <regdef.h>
47
48#if _MIPS_ISA>=4
49#define MOVNZ(cond,dst,src) \
50 movn dst,src,cond
51#else
52#define MOVNZ(cond,dst,src) \
53 .set noreorder; \
54 bnezl cond,.+8; \
55 move dst,src; \
56 .set reorder
57#endif
58
59.text
60
61.set noat
62.set reorder
63
64#define MINUS4 v1
65
66.align 5
67LEAF(bn_mul_add_words)
68 .set noreorder
69 bgtzl a2,.L_bn_mul_add_words_proceed
70 ld t0,0(a1)
71 jr ra
72 move v0,zero
73 .set reorder
74
75.L_bn_mul_add_words_proceed:
76 li MINUS4,-4
77 and ta0,a2,MINUS4
78 move v0,zero
79 beqz ta0,.L_bn_mul_add_words_tail
80
81.L_bn_mul_add_words_loop:
82 dmultu t0,a3
83 ld t1,0(a0)
84 ld t2,8(a1)
85 ld t3,8(a0)
86 ld ta0,16(a1)
87 ld ta1,16(a0)
88 daddu t1,v0
89 sltu v0,t1,v0 /* All manuals say it "compares 32-bit
90 * values", but it seems to work fine
91 * even on 64-bit registers. */
92 mflo AT
93 mfhi t0
94 daddu t1,AT
95 daddu v0,t0
96 sltu AT,t1,AT
97 sd t1,0(a0)
98 daddu v0,AT
99
100 dmultu t2,a3
101 ld ta2,24(a1)
102 ld ta3,24(a0)
103 daddu t3,v0
104 sltu v0,t3,v0
105 mflo AT
106 mfhi t2
107 daddu t3,AT
108 daddu v0,t2
109 sltu AT,t3,AT
110 sd t3,8(a0)
111 daddu v0,AT
112
113 dmultu ta0,a3
114 subu a2,4
115 PTR_ADD a0,32
116 PTR_ADD a1,32
117 daddu ta1,v0
118 sltu v0,ta1,v0
119 mflo AT
120 mfhi ta0
121 daddu ta1,AT
122 daddu v0,ta0
123 sltu AT,ta1,AT
124 sd ta1,-16(a0)
125 daddu v0,AT
126
127
128 dmultu ta2,a3
129 and ta0,a2,MINUS4
130 daddu ta3,v0
131 sltu v0,ta3,v0
132 mflo AT
133 mfhi ta2
134 daddu ta3,AT
135 daddu v0,ta2
136 sltu AT,ta3,AT
137 sd ta3,-8(a0)
138 daddu v0,AT
139 .set noreorder
140 bgtzl ta0,.L_bn_mul_add_words_loop
141 ld t0,0(a1)
142
143 bnezl a2,.L_bn_mul_add_words_tail
144 ld t0,0(a1)
145 .set reorder
146
147.L_bn_mul_add_words_return:
148 jr ra
149
150.L_bn_mul_add_words_tail:
151 dmultu t0,a3
152 ld t1,0(a0)
153 subu a2,1
154 daddu t1,v0
155 sltu v0,t1,v0
156 mflo AT
157 mfhi t0
158 daddu t1,AT
159 daddu v0,t0
160 sltu AT,t1,AT
161 sd t1,0(a0)
162 daddu v0,AT
163 beqz a2,.L_bn_mul_add_words_return
164
165 ld t0,8(a1)
166 dmultu t0,a3
167 ld t1,8(a0)
168 subu a2,1
169 daddu t1,v0
170 sltu v0,t1,v0
171 mflo AT
172 mfhi t0
173 daddu t1,AT
174 daddu v0,t0
175 sltu AT,t1,AT
176 sd t1,8(a0)
177 daddu v0,AT
178 beqz a2,.L_bn_mul_add_words_return
179
180 ld t0,16(a1)
181 dmultu t0,a3
182 ld t1,16(a0)
183 daddu t1,v0
184 sltu v0,t1,v0
185 mflo AT
186 mfhi t0
187 daddu t1,AT
188 daddu v0,t0
189 sltu AT,t1,AT
190 sd t1,16(a0)
191 daddu v0,AT
192 jr ra
193END(bn_mul_add_words)
194
195.align 5
196LEAF(bn_mul_words)
197 .set noreorder
198 bgtzl a2,.L_bn_mul_words_proceed
199 ld t0,0(a1)
200 jr ra
201 move v0,zero
202 .set reorder
203
204.L_bn_mul_words_proceed:
205 li MINUS4,-4
206 and ta0,a2,MINUS4
207 move v0,zero
208 beqz ta0,.L_bn_mul_words_tail
209
210.L_bn_mul_words_loop:
211 dmultu t0,a3
212 ld t2,8(a1)
213 ld ta0,16(a1)
214 ld ta2,24(a1)
215 mflo AT
216 mfhi t0
217 daddu v0,AT
218 sltu t1,v0,AT
219 sd v0,0(a0)
220 daddu v0,t1,t0
221
222 dmultu t2,a3
223 subu a2,4
224 PTR_ADD a0,32
225 PTR_ADD a1,32
226 mflo AT
227 mfhi t2
228 daddu v0,AT
229 sltu t3,v0,AT
230 sd v0,-24(a0)
231 daddu v0,t3,t2
232
233 dmultu ta0,a3
234 mflo AT
235 mfhi ta0
236 daddu v0,AT
237 sltu ta1,v0,AT
238 sd v0,-16(a0)
239 daddu v0,ta1,ta0
240
241
242 dmultu ta2,a3
243 and ta0,a2,MINUS4
244 mflo AT
245 mfhi ta2
246 daddu v0,AT
247 sltu ta3,v0,AT
248 sd v0,-8(a0)
249 daddu v0,ta3,ta2
250 .set noreorder
251 bgtzl ta0,.L_bn_mul_words_loop
252 ld t0,0(a1)
253
254 bnezl a2,.L_bn_mul_words_tail
255 ld t0,0(a1)
256 .set reorder
257
258.L_bn_mul_words_return:
259 jr ra
260
261.L_bn_mul_words_tail:
262 dmultu t0,a3
263 subu a2,1
264 mflo AT
265 mfhi t0
266 daddu v0,AT
267 sltu t1,v0,AT
268 sd v0,0(a0)
269 daddu v0,t1,t0
270 beqz a2,.L_bn_mul_words_return
271
272 ld t0,8(a1)
273 dmultu t0,a3
274 subu a2,1
275 mflo AT
276 mfhi t0
277 daddu v0,AT
278 sltu t1,v0,AT
279 sd v0,8(a0)
280 daddu v0,t1,t0
281 beqz a2,.L_bn_mul_words_return
282
283 ld t0,16(a1)
284 dmultu t0,a3
285 mflo AT
286 mfhi t0
287 daddu v0,AT
288 sltu t1,v0,AT
289 sd v0,16(a0)
290 daddu v0,t1,t0
291 jr ra
292END(bn_mul_words)
293
294.align 5
295LEAF(bn_sqr_words)
296 .set noreorder
297 bgtzl a2,.L_bn_sqr_words_proceed
298 ld t0,0(a1)
299 jr ra
300 move v0,zero
301 .set reorder
302
303.L_bn_sqr_words_proceed:
304 li MINUS4,-4
305 and ta0,a2,MINUS4
306 move v0,zero
307 beqz ta0,.L_bn_sqr_words_tail
308
309.L_bn_sqr_words_loop:
310 dmultu t0,t0
311 ld t2,8(a1)
312 ld ta0,16(a1)
313 ld ta2,24(a1)
314 mflo t1
315 mfhi t0
316 sd t1,0(a0)
317 sd t0,8(a0)
318
319 dmultu t2,t2
320 subu a2,4
321 PTR_ADD a0,64
322 PTR_ADD a1,32
323 mflo t3
324 mfhi t2
325 sd t3,-48(a0)
326 sd t2,-40(a0)
327
328 dmultu ta0,ta0
329 mflo ta1
330 mfhi ta0
331 sd ta1,-32(a0)
332 sd ta0,-24(a0)
333
334
335 dmultu ta2,ta2
336 and ta0,a2,MINUS4
337 mflo ta3
338 mfhi ta2
339 sd ta3,-16(a0)
340 sd ta2,-8(a0)
341
342 .set noreorder
343 bgtzl ta0,.L_bn_sqr_words_loop
344 ld t0,0(a1)
345
346 bnezl a2,.L_bn_sqr_words_tail
347 ld t0,0(a1)
348 .set reorder
349
350.L_bn_sqr_words_return:
351 move v0,zero
352 jr ra
353
354.L_bn_sqr_words_tail:
355 dmultu t0,t0
356 subu a2,1
357 mflo t1
358 mfhi t0
359 sd t1,0(a0)
360 sd t0,8(a0)
361 beqz a2,.L_bn_sqr_words_return
362
363 ld t0,8(a1)
364 dmultu t0,t0
365 subu a2,1
366 mflo t1
367 mfhi t0
368 sd t1,16(a0)
369 sd t0,24(a0)
370 beqz a2,.L_bn_sqr_words_return
371
372 ld t0,16(a1)
373 dmultu t0,t0
374 mflo t1
375 mfhi t0
376 sd t1,32(a0)
377 sd t0,40(a0)
378 jr ra
379END(bn_sqr_words)
380
381.align 5
382LEAF(bn_add_words)
383 .set noreorder
384 bgtzl a3,.L_bn_add_words_proceed
385 ld t0,0(a1)
386 jr ra
387 move v0,zero
388 .set reorder
389
390.L_bn_add_words_proceed:
391 li MINUS4,-4
392 and AT,a3,MINUS4
393 move v0,zero
394 beqz AT,.L_bn_add_words_tail
395
396.L_bn_add_words_loop:
397 ld ta0,0(a2)
398 ld t1,8(a1)
399 ld ta1,8(a2)
400 ld t2,16(a1)
401 ld ta2,16(a2)
402 ld t3,24(a1)
403 ld ta3,24(a2)
404 daddu ta0,t0
405 subu a3,4
406 sltu t8,ta0,t0
407 daddu t0,ta0,v0
408 PTR_ADD a0,32
409 sltu v0,t0,ta0
410 sd t0,-32(a0)
411 daddu v0,t8
412
413 daddu ta1,t1
414 PTR_ADD a1,32
415 sltu t9,ta1,t1
416 daddu t1,ta1,v0
417 PTR_ADD a2,32
418 sltu v0,t1,ta1
419 sd t1,-24(a0)
420 daddu v0,t9
421
422 daddu ta2,t2
423 and AT,a3,MINUS4
424 sltu t8,ta2,t2
425 daddu t2,ta2,v0
426 sltu v0,t2,ta2
427 sd t2,-16(a0)
428 daddu v0,t8
429
430 daddu ta3,t3
431 sltu t9,ta3,t3
432 daddu t3,ta3,v0
433 sltu v0,t3,ta3
434 sd t3,-8(a0)
435 daddu v0,t9
436
437 .set noreorder
438 bgtzl AT,.L_bn_add_words_loop
439 ld t0,0(a1)
440
441 bnezl a3,.L_bn_add_words_tail
442 ld t0,0(a1)
443 .set reorder
444
445.L_bn_add_words_return:
446 jr ra
447
448.L_bn_add_words_tail:
449 ld ta0,0(a2)
450 daddu ta0,t0
451 subu a3,1
452 sltu t8,ta0,t0
453 daddu t0,ta0,v0
454 sltu v0,t0,ta0
455 sd t0,0(a0)
456 daddu v0,t8
457 beqz a3,.L_bn_add_words_return
458
459 ld t1,8(a1)
460 ld ta1,8(a2)
461 daddu ta1,t1
462 subu a3,1
463 sltu t9,ta1,t1
464 daddu t1,ta1,v0
465 sltu v0,t1,ta1
466 sd t1,8(a0)
467 daddu v0,t9
468 beqz a3,.L_bn_add_words_return
469
470 ld t2,16(a1)
471 ld ta2,16(a2)
472 daddu ta2,t2
473 sltu t8,ta2,t2
474 daddu t2,ta2,v0
475 sltu v0,t2,ta2
476 sd t2,16(a0)
477 daddu v0,t8
478 jr ra
479END(bn_add_words)
480
481.align 5
482LEAF(bn_sub_words)
483 .set noreorder
484 bgtzl a3,.L_bn_sub_words_proceed
485 ld t0,0(a1)
486 jr ra
487 move v0,zero
488 .set reorder
489
490.L_bn_sub_words_proceed:
491 li MINUS4,-4
492 and AT,a3,MINUS4
493 move v0,zero
494 beqz AT,.L_bn_sub_words_tail
495
496.L_bn_sub_words_loop:
497 ld ta0,0(a2)
498 ld t1,8(a1)
499 ld ta1,8(a2)
500 ld t2,16(a1)
501 ld ta2,16(a2)
502 ld t3,24(a1)
503 ld ta3,24(a2)
504 sltu t8,t0,ta0
505 dsubu t0,ta0
506 subu a3,4
507 dsubu ta0,t0,v0
508 and AT,a3,MINUS4
509 sd ta0,0(a0)
510 MOVNZ (t0,v0,t8)
511
512 sltu t9,t1,ta1
513 dsubu t1,ta1
514 PTR_ADD a0,32
515 dsubu ta1,t1,v0
516 PTR_ADD a1,32
517 sd ta1,-24(a0)
518 MOVNZ (t1,v0,t9)
519
520
521 sltu t8,t2,ta2
522 dsubu t2,ta2
523 dsubu ta2,t2,v0
524 PTR_ADD a2,32
525 sd ta2,-16(a0)
526 MOVNZ (t2,v0,t8)
527
528 sltu t9,t3,ta3
529 dsubu t3,ta3
530 dsubu ta3,t3,v0
531 sd ta3,-8(a0)
532 MOVNZ (t3,v0,t9)
533
534 .set noreorder
535 bgtzl AT,.L_bn_sub_words_loop
536 ld t0,0(a1)
537
538 bnezl a3,.L_bn_sub_words_tail
539 ld t0,0(a1)
540 .set reorder
541
542.L_bn_sub_words_return:
543 jr ra
544
545.L_bn_sub_words_tail:
546 ld ta0,0(a2)
547 subu a3,1
548 sltu t8,t0,ta0
549 dsubu t0,ta0
550 dsubu ta0,t0,v0
551 MOVNZ (t0,v0,t8)
552 sd ta0,0(a0)
553 beqz a3,.L_bn_sub_words_return
554
555 ld t1,8(a1)
556 subu a3,1
557 ld ta1,8(a2)
558 sltu t9,t1,ta1
559 dsubu t1,ta1
560 dsubu ta1,t1,v0
561 MOVNZ (t1,v0,t9)
562 sd ta1,8(a0)
563 beqz a3,.L_bn_sub_words_return
564
565 ld t2,16(a1)
566 ld ta2,16(a2)
567 sltu t8,t2,ta2
568 dsubu t2,ta2
569 dsubu ta2,t2,v0
570 MOVNZ (t2,v0,t8)
571 sd ta2,16(a0)
572 jr ra
573END(bn_sub_words)
574
575#undef MINUS4
576
577.align 5
578LEAF(bn_div_words)
579 .set noreorder
580 bnezl a2,.L_bn_div_words_proceed
581 move v1,zero
582 jr ra
583 li v0,-1 /* I'd rather signal div-by-zero
584 * which can be done with 'break 7' */
585
586.L_bn_div_words_proceed:
587 bltz a2,.L_bn_div_words_body
588 move t9,v1
589 dsll a2,1
590 bgtz a2,.-4
591 addu t9,1
592
593 .set reorder
594 negu t1,t9
595 li t2,-1
596 dsll t2,t1
597 and t2,a0
598 dsrl AT,a1,t1
599 .set noreorder
600 bnezl t2,.+8
601 break 6 /* signal overflow */
602 .set reorder
603 dsll a0,t9
604 dsll a1,t9
605 or a0,AT
606
607#define QT ta0
608#define HH ta1
609#define DH v1
610.L_bn_div_words_body:
611 dsrl DH,a2,32
612 sgeu AT,a0,a2
613 .set noreorder
614 bnezl AT,.+8
615 dsubu a0,a2
616 .set reorder
617
618 li QT,-1
619 dsrl HH,a0,32
620 dsrl QT,32 /* q=0xffffffff */
621 beq DH,HH,.L_bn_div_words_skip_div1
622 ddivu zero,a0,DH
623 mflo QT
624.L_bn_div_words_skip_div1:
625 dmultu a2,QT
626 dsll t3,a0,32
627 dsrl AT,a1,32
628 or t3,AT
629 mflo t0
630 mfhi t1
631.L_bn_div_words_inner_loop1:
632 sltu t2,t3,t0
633 seq t8,HH,t1
634 sltu AT,HH,t1
635 and t2,t8
636 or AT,t2
637 .set noreorder
638 beqz AT,.L_bn_div_words_inner_loop1_done
639 sltu t2,t0,a2
640 .set reorder
641 dsubu QT,1
642 dsubu t0,a2
643 dsubu t1,t2
644 b .L_bn_div_words_inner_loop1
645.L_bn_div_words_inner_loop1_done:
646
647 dsll a1,32
648 dsubu a0,t3,t0
649 dsll v0,QT,32
650
651 li QT,-1
652 dsrl HH,a0,32
653 dsrl QT,32 /* q=0xffffffff */
654 beq DH,HH,.L_bn_div_words_skip_div2
655 ddivu zero,a0,DH
656 mflo QT
657.L_bn_div_words_skip_div2:
658 dmultu a2,QT
659 dsll t3,a0,32
660 dsrl AT,a1,32
661 or t3,AT
662 mflo t0
663 mfhi t1
664.L_bn_div_words_inner_loop2:
665 sltu t2,t3,t0
666 seq t8,HH,t1
667 sltu AT,HH,t1
668 and t2,t8
669 or AT,t2
670 .set noreorder
671 beqz AT,.L_bn_div_words_inner_loop2_done
672 sltu t2,t0,a2
673 .set reorder
674 dsubu QT,1
675 dsubu t0,a2
676 dsubu t1,t2
677 b .L_bn_div_words_inner_loop2
678.L_bn_div_words_inner_loop2_done:
679
680 dsubu a0,t3,t0
681 or v0,QT
682 dsrl v1,a0,t9 /* v1 contains remainder if anybody wants it */
683 dsrl a2,t9 /* restore a2 */
684 jr ra
685#undef HH
686#undef DH
687#undef QT
688END(bn_div_words)
689
690.align 5
691LEAF(bn_div_3_words)
692 .set reorder
693 move a3,a0 /* we know that bn_div_words doesn't
694 * touch a3, ta2, ta3 and preserves a2
695 * so that we can save two arguments
696 * and return address in registers
697 * instead of stack:-)
698 */
699 ld a0,(a3)
700 move ta2,a2
701 move a2,a1
702 ld a1,-8(a3)
703 move ta3,ra
704 move v1,zero
705 li v0,-1
706 beq a0,a2,.L_bn_div_3_words_skip_div
707 jal bn_div_words
708 move ra,ta3
709.L_bn_div_3_words_skip_div:
710 dmultu ta2,v0
711 ld t2,-16(a3)
712 mflo t0
713 mfhi t1
714.L_bn_div_3_words_inner_loop:
715 sgeu AT,t2,t0
716 seq t9,t1,v1
717 sltu t8,t1,v1
718 and AT,t9
719 or AT,t8
720 bnez AT,.L_bn_div_3_words_inner_loop_done
721 daddu v1,a2
722 sltu t3,t0,ta2
723 sltu AT,v1,a2
724 dsubu v0,1
725 dsubu t0,ta2
726 dsubu t1,t3
727 beqz AT,.L_bn_div_3_words_inner_loop
728.L_bn_div_3_words_inner_loop_done:
729 jr ra
730END(bn_div_3_words)
731
732#define a_0 t0
733#define a_1 t1
734#define a_2 t2
735#define a_3 t3
736#define b_0 ta0
737#define b_1 ta1
738#define b_2 ta2
739#define b_3 ta3
740
741#define a_4 s0
742#define a_5 s2
743#define a_6 s4
744#define a_7 a1 /* once we load a[7] we don't need a anymore */
745#define b_4 s1
746#define b_5 s3
747#define b_6 s5
748#define b_7 a2 /* once we load b[7] we don't need b anymore */
749
750#define t_1 t8
751#define t_2 t9
752
753#define c_1 v0
754#define c_2 v1
755#define c_3 a3
756
757#define FRAME_SIZE 48
758
759.align 5
760LEAF(bn_mul_comba8)
761 .set noreorder
762 PTR_SUB sp,FRAME_SIZE
763 .frame sp,64,ra
764 .set reorder
765 ld a_0,0(a1) /* If compiled with -mips3 option on
766 * R5000 box assembler barks on this
767 * line with "shouldn't have mult/div
768 * as last instruction in bb (R10K
769 * bug)" warning. If anybody out there
770 * has a clue about how to circumvent
771 * this do send me a note.
772 * <appro@fy.chalmers.se>
773 */
774 ld b_0,0(a2)
775 ld a_1,8(a1)
776 ld a_2,16(a1)
777 ld a_3,24(a1)
778 ld b_1,8(a2)
779 ld b_2,16(a2)
780 ld b_3,24(a2)
781 dmultu a_0,b_0 /* mul_add_c(a[0],b[0],c1,c2,c3); */
782 sd s0,0(sp)
783 sd s1,8(sp)
784 sd s2,16(sp)
785 sd s3,24(sp)
786 sd s4,32(sp)
787 sd s5,40(sp)
788 mflo c_1
789 mfhi c_2
790
791 dmultu a_0,b_1 /* mul_add_c(a[0],b[1],c2,c3,c1); */
792 ld a_4,32(a1)
793 ld a_5,40(a1)
794 ld a_6,48(a1)
795 ld a_7,56(a1)
796 ld b_4,32(a2)
797 ld b_5,40(a2)
798 mflo t_1
799 mfhi t_2
800 daddu c_2,t_1
801 sltu AT,c_2,t_1
802 daddu c_3,t_2,AT
803 dmultu a_1,b_0 /* mul_add_c(a[1],b[0],c2,c3,c1); */
804 ld b_6,48(a2)
805 ld b_7,56(a2)
806 sd c_1,0(a0) /* r[0]=c1; */
807 mflo t_1
808 mfhi t_2
809 daddu c_2,t_1
810 sltu AT,c_2,t_1
811 daddu t_2,AT
812 daddu c_3,t_2
813 sltu c_1,c_3,t_2
814 sd c_2,8(a0) /* r[1]=c2; */
815
816 dmultu a_2,b_0 /* mul_add_c(a[2],b[0],c3,c1,c2); */
817 mflo t_1
818 mfhi t_2
819 daddu c_3,t_1
820 sltu AT,c_3,t_1
821 daddu t_2,AT
822 daddu c_1,t_2
823 dmultu a_1,b_1 /* mul_add_c(a[1],b[1],c3,c1,c2); */
824 mflo t_1
825 mfhi t_2
826 daddu c_3,t_1
827 sltu AT,c_3,t_1
828 daddu t_2,AT
829 daddu c_1,t_2
830 sltu c_2,c_1,t_2
831 dmultu a_0,b_2 /* mul_add_c(a[0],b[2],c3,c1,c2); */
832 mflo t_1
833 mfhi t_2
834 daddu c_3,t_1
835 sltu AT,c_3,t_1
836 daddu t_2,AT
837 daddu c_1,t_2
838 sltu AT,c_1,t_2
839 daddu c_2,AT
840 sd c_3,16(a0) /* r[2]=c3; */
841
842 dmultu a_0,b_3 /* mul_add_c(a[0],b[3],c1,c2,c3); */
843 mflo t_1
844 mfhi t_2
845 daddu c_1,t_1
846 sltu AT,c_1,t_1
847 daddu t_2,AT
848 daddu c_2,t_2
849 dmultu a_1,b_2 /* mul_add_c(a[1],b[2],c1,c2,c3); */
850 mflo t_1
851 mfhi t_2
852 daddu c_1,t_1
853 sltu AT,c_1,t_1
854 daddu t_2,AT
855 daddu c_2,t_2
856 sltu c_3,c_2,t_2
857 dmultu a_2,b_1 /* mul_add_c(a[2],b[1],c1,c2,c3); */
858 mflo t_1
859 mfhi t_2
860 daddu c_1,t_1
861 sltu AT,c_1,t_1
862 daddu t_2,AT
863 daddu c_2,t_2
864 sltu AT,c_2,t_2
865 daddu c_3,AT
866 dmultu a_3,b_0 /* mul_add_c(a[3],b[0],c1,c2,c3); */
867 mflo t_1
868 mfhi t_2
869 daddu c_1,t_1
870 sltu AT,c_1,t_1
871 daddu t_2,AT
872 daddu c_2,t_2
873 sltu AT,c_2,t_2
874 daddu c_3,AT
875 sd c_1,24(a0) /* r[3]=c1; */
876
877 dmultu a_4,b_0 /* mul_add_c(a[4],b[0],c2,c3,c1); */
878 mflo t_1
879 mfhi t_2
880 daddu c_2,t_1
881 sltu AT,c_2,t_1
882 daddu t_2,AT
883 daddu c_3,t_2
884 dmultu a_3,b_1 /* mul_add_c(a[3],b[1],c2,c3,c1); */
885 mflo t_1
886 mfhi t_2
887 daddu c_2,t_1
888 sltu AT,c_2,t_1
889 daddu t_2,AT
890 daddu c_3,t_2
891 sltu c_1,c_3,t_2
892 dmultu a_2,b_2 /* mul_add_c(a[2],b[2],c2,c3,c1); */
893 mflo t_1
894 mfhi t_2
895 daddu c_2,t_1
896 sltu AT,c_2,t_1
897 daddu t_2,AT
898 daddu c_3,t_2
899 sltu AT,c_3,t_2
900 daddu c_1,AT
901 dmultu a_1,b_3 /* mul_add_c(a[1],b[3],c2,c3,c1); */
902 mflo t_1
903 mfhi t_2
904 daddu c_2,t_1
905 sltu AT,c_2,t_1
906 daddu t_2,AT
907 daddu c_3,t_2
908 sltu AT,c_3,t_2
909 daddu c_1,AT
910 dmultu a_0,b_4 /* mul_add_c(a[0],b[4],c2,c3,c1); */
911 mflo t_1
912 mfhi t_2
913 daddu c_2,t_1
914 sltu AT,c_2,t_1
915 daddu t_2,AT
916 daddu c_3,t_2
917 sltu AT,c_3,t_2
918 daddu c_1,AT
919 sd c_2,32(a0) /* r[4]=c2; */
920
921 dmultu a_0,b_5 /* mul_add_c(a[0],b[5],c3,c1,c2); */
922 mflo t_1
923 mfhi t_2
924 daddu c_3,t_1
925 sltu AT,c_3,t_1
926 daddu t_2,AT
927 daddu c_1,t_2
928 dmultu a_1,b_4 /* mul_add_c(a[1],b[4],c3,c1,c2); */
929 mflo t_1
930 mfhi t_2
931 daddu c_3,t_1
932 sltu AT,c_3,t_1
933 daddu t_2,AT
934 daddu c_1,t_2
935 sltu c_2,c_1,t_2
936 dmultu a_2,b_3 /* mul_add_c(a[2],b[3],c3,c1,c2); */
937 mflo t_1
938 mfhi t_2
939 daddu c_3,t_1
940 sltu AT,c_3,t_1
941 daddu t_2,AT
942 daddu c_1,t_2
943 sltu AT,c_1,t_2
944 daddu c_2,AT
945 dmultu a_3,b_2 /* mul_add_c(a[3],b[2],c3,c1,c2); */
946 mflo t_1
947 mfhi t_2
948 daddu c_3,t_1
949 sltu AT,c_3,t_1
950 daddu t_2,AT
951 daddu c_1,t_2
952 sltu AT,c_1,t_2
953 daddu c_2,AT
954 dmultu a_4,b_1 /* mul_add_c(a[4],b[1],c3,c1,c2); */
955 mflo t_1
956 mfhi t_2
957 daddu c_3,t_1
958 sltu AT,c_3,t_1
959 daddu t_2,AT
960 daddu c_1,t_2
961 sltu AT,c_1,t_2
962 daddu c_2,AT
963 dmultu a_5,b_0 /* mul_add_c(a[5],b[0],c3,c1,c2); */
964 mflo t_1
965 mfhi t_2
966 daddu c_3,t_1
967 sltu AT,c_3,t_1
968 daddu t_2,AT
969 daddu c_1,t_2
970 sltu AT,c_1,t_2
971 daddu c_2,AT
972 sd c_3,40(a0) /* r[5]=c3; */
973
974 dmultu a_6,b_0 /* mul_add_c(a[6],b[0],c1,c2,c3); */
975 mflo t_1
976 mfhi t_2
977 daddu c_1,t_1
978 sltu AT,c_1,t_1
979 daddu t_2,AT
980 daddu c_2,t_2
981 dmultu a_5,b_1 /* mul_add_c(a[5],b[1],c1,c2,c3); */
982 mflo t_1
983 mfhi t_2
984 daddu c_1,t_1
985 sltu AT,c_1,t_1
986 daddu t_2,AT
987 daddu c_2,t_2
988 sltu c_3,c_2,t_2
989 dmultu a_4,b_2 /* mul_add_c(a[4],b[2],c1,c2,c3); */
990 mflo t_1
991 mfhi t_2
992 daddu c_1,t_1
993 sltu AT,c_1,t_1
994 daddu t_2,AT
995 daddu c_2,t_2
996 sltu AT,c_2,t_2
997 daddu c_3,AT
998 dmultu a_3,b_3 /* mul_add_c(a[3],b[3],c1,c2,c3); */
999 mflo t_1
1000 mfhi t_2
1001 daddu c_1,t_1
1002 sltu AT,c_1,t_1
1003 daddu t_2,AT
1004 daddu c_2,t_2
1005 sltu AT,c_2,t_2
1006 daddu c_3,AT
1007 dmultu a_2,b_4 /* mul_add_c(a[2],b[4],c1,c2,c3); */
1008 mflo t_1
1009 mfhi t_2
1010 daddu c_1,t_1
1011 sltu AT,c_1,t_1
1012 daddu t_2,AT
1013 daddu c_2,t_2
1014 sltu AT,c_2,t_2
1015 daddu c_3,AT
1016 dmultu a_1,b_5 /* mul_add_c(a[1],b[5],c1,c2,c3); */
1017 mflo t_1
1018 mfhi t_2
1019 daddu c_1,t_1
1020 sltu AT,c_1,t_1
1021 daddu t_2,AT
1022 daddu c_2,t_2
1023 sltu AT,c_2,t_2
1024 daddu c_3,AT
1025 dmultu a_0,b_6 /* mul_add_c(a[0],b[6],c1,c2,c3); */
1026 mflo t_1
1027 mfhi t_2
1028 daddu c_1,t_1
1029 sltu AT,c_1,t_1
1030 daddu t_2,AT
1031 daddu c_2,t_2
1032 sltu AT,c_2,t_2
1033 daddu c_3,AT
1034 sd c_1,48(a0) /* r[6]=c1; */
1035
1036 dmultu a_0,b_7 /* mul_add_c(a[0],b[7],c2,c3,c1); */
1037 mflo t_1
1038 mfhi t_2
1039 daddu c_2,t_1
1040 sltu AT,c_2,t_1
1041 daddu t_2,AT
1042 daddu c_3,t_2
1043 dmultu a_1,b_6 /* mul_add_c(a[1],b[6],c2,c3,c1); */
1044 mflo t_1
1045 mfhi t_2
1046 daddu c_2,t_1
1047 sltu AT,c_2,t_1
1048 daddu t_2,AT
1049 daddu c_3,t_2
1050 sltu c_1,c_3,t_2
1051 dmultu a_2,b_5 /* mul_add_c(a[2],b[5],c2,c3,c1); */
1052 mflo t_1
1053 mfhi t_2
1054 daddu c_2,t_1
1055 sltu AT,c_2,t_1
1056 daddu t_2,AT
1057 daddu c_3,t_2
1058 sltu AT,c_3,t_2
1059 daddu c_1,AT
1060 dmultu a_3,b_4 /* mul_add_c(a[3],b[4],c2,c3,c1); */
1061 mflo t_1
1062 mfhi t_2
1063 daddu c_2,t_1
1064 sltu AT,c_2,t_1
1065 daddu t_2,AT
1066 daddu c_3,t_2
1067 sltu AT,c_3,t_2
1068 daddu c_1,AT
1069 dmultu a_4,b_3 /* mul_add_c(a[4],b[3],c2,c3,c1); */
1070 mflo t_1
1071 mfhi t_2
1072 daddu c_2,t_1
1073 sltu AT,c_2,t_1
1074 daddu t_2,AT
1075 daddu c_3,t_2
1076 sltu AT,c_3,t_2
1077 daddu c_1,AT
1078 dmultu a_5,b_2 /* mul_add_c(a[5],b[2],c2,c3,c1); */
1079 mflo t_1
1080 mfhi t_2
1081 daddu c_2,t_1
1082 sltu AT,c_2,t_1
1083 daddu t_2,AT
1084 daddu c_3,t_2
1085 sltu AT,c_3,t_2
1086 daddu c_1,AT
1087 dmultu a_6,b_1 /* mul_add_c(a[6],b[1],c2,c3,c1); */
1088 mflo t_1
1089 mfhi t_2
1090 daddu c_2,t_1
1091 sltu AT,c_2,t_1
1092 daddu t_2,AT
1093 daddu c_3,t_2
1094 sltu AT,c_3,t_2
1095 daddu c_1,AT
1096 dmultu a_7,b_0 /* mul_add_c(a[7],b[0],c2,c3,c1); */
1097 mflo t_1
1098 mfhi t_2
1099 daddu c_2,t_1
1100 sltu AT,c_2,t_1
1101 daddu t_2,AT
1102 daddu c_3,t_2
1103 sltu AT,c_3,t_2
1104 daddu c_1,AT
1105 sd c_2,56(a0) /* r[7]=c2; */
1106
1107 dmultu a_7,b_1 /* mul_add_c(a[7],b[1],c3,c1,c2); */
1108 mflo t_1
1109 mfhi t_2
1110 daddu c_3,t_1
1111 sltu AT,c_3,t_1
1112 daddu t_2,AT
1113 daddu c_1,t_2
1114 dmultu a_6,b_2 /* mul_add_c(a[6],b[2],c3,c1,c2); */
1115 mflo t_1
1116 mfhi t_2
1117 daddu c_3,t_1
1118 sltu AT,c_3,t_1
1119 daddu t_2,AT
1120 daddu c_1,t_2
1121 sltu c_2,c_1,t_2
1122 dmultu a_5,b_3 /* mul_add_c(a[5],b[3],c3,c1,c2); */
1123 mflo t_1
1124 mfhi t_2
1125 daddu c_3,t_1
1126 sltu AT,c_3,t_1
1127 daddu t_2,AT
1128 daddu c_1,t_2
1129 sltu AT,c_1,t_2
1130 daddu c_2,AT
1131 dmultu a_4,b_4 /* mul_add_c(a[4],b[4],c3,c1,c2); */
1132 mflo t_1
1133 mfhi t_2
1134 daddu c_3,t_1
1135 sltu AT,c_3,t_1
1136 daddu t_2,AT
1137 daddu c_1,t_2
1138 sltu AT,c_1,t_2
1139 daddu c_2,AT
1140 dmultu a_3,b_5 /* mul_add_c(a[3],b[5],c3,c1,c2); */
1141 mflo t_1
1142 mfhi t_2
1143 daddu c_3,t_1
1144 sltu AT,c_3,t_1
1145 daddu t_2,AT
1146 daddu c_1,t_2
1147 sltu AT,c_1,t_2
1148 daddu c_2,AT
1149 dmultu a_2,b_6 /* mul_add_c(a[2],b[6],c3,c1,c2); */
1150 mflo t_1
1151 mfhi t_2
1152 daddu c_3,t_1
1153 sltu AT,c_3,t_1
1154 daddu t_2,AT
1155 daddu c_1,t_2
1156 sltu AT,c_1,t_2
1157 daddu c_2,AT
1158 dmultu a_1,b_7 /* mul_add_c(a[1],b[7],c3,c1,c2); */
1159 mflo t_1
1160 mfhi t_2
1161 daddu c_3,t_1
1162 sltu AT,c_3,t_1
1163 daddu t_2,AT
1164 daddu c_1,t_2
1165 sltu AT,c_1,t_2
1166 daddu c_2,AT
1167 sd c_3,64(a0) /* r[8]=c3; */
1168
1169 dmultu a_2,b_7 /* mul_add_c(a[2],b[7],c1,c2,c3); */
1170 mflo t_1
1171 mfhi t_2
1172 daddu c_1,t_1
1173 sltu AT,c_1,t_1
1174 daddu t_2,AT
1175 daddu c_2,t_2
1176 dmultu a_3,b_6 /* mul_add_c(a[3],b[6],c1,c2,c3); */
1177 mflo t_1
1178 mfhi t_2
1179 daddu c_1,t_1
1180 sltu AT,c_1,t_1
1181 daddu t_2,AT
1182 daddu c_2,t_2
1183 sltu c_3,c_2,t_2
1184 dmultu a_4,b_5 /* mul_add_c(a[4],b[5],c1,c2,c3); */
1185 mflo t_1
1186 mfhi t_2
1187 daddu c_1,t_1
1188 sltu AT,c_1,t_1
1189 daddu t_2,AT
1190 daddu c_2,t_2
1191 sltu AT,c_2,t_2
1192 daddu c_3,AT
1193 dmultu a_5,b_4 /* mul_add_c(a[5],b[4],c1,c2,c3); */
1194 mflo t_1
1195 mfhi t_2
1196 daddu c_1,t_1
1197 sltu AT,c_1,t_1
1198 daddu t_2,AT
1199 daddu c_2,t_2
1200 sltu AT,c_2,t_2
1201 daddu c_3,AT
1202 dmultu a_6,b_3 /* mul_add_c(a[6],b[3],c1,c2,c3); */
1203 mflo t_1
1204 mfhi t_2
1205 daddu c_1,t_1
1206 sltu AT,c_1,t_1
1207 daddu t_2,AT
1208 daddu c_2,t_2
1209 sltu AT,c_2,t_2
1210 daddu c_3,AT
1211 dmultu a_7,b_2 /* mul_add_c(a[7],b[2],c1,c2,c3); */
1212 mflo t_1
1213 mfhi t_2
1214 daddu c_1,t_1
1215 sltu AT,c_1,t_1
1216 daddu t_2,AT
1217 daddu c_2,t_2
1218 sltu AT,c_2,t_2
1219 daddu c_3,AT
1220 sd c_1,72(a0) /* r[9]=c1; */
1221
1222 dmultu a_7,b_3 /* mul_add_c(a[7],b[3],c2,c3,c1); */
1223 mflo t_1
1224 mfhi t_2
1225 daddu c_2,t_1
1226 sltu AT,c_2,t_1
1227 daddu t_2,AT
1228 daddu c_3,t_2
1229 dmultu a_6,b_4 /* mul_add_c(a[6],b[4],c2,c3,c1); */
1230 mflo t_1
1231 mfhi t_2
1232 daddu c_2,t_1
1233 sltu AT,c_2,t_1
1234 daddu t_2,AT
1235 daddu c_3,t_2
1236 sltu c_1,c_3,t_2
1237 dmultu a_5,b_5 /* mul_add_c(a[5],b[5],c2,c3,c1); */
1238 mflo t_1
1239 mfhi t_2
1240 daddu c_2,t_1
1241 sltu AT,c_2,t_1
1242 daddu t_2,AT
1243 daddu c_3,t_2
1244 sltu AT,c_3,t_2
1245 daddu c_1,AT
1246 dmultu a_4,b_6 /* mul_add_c(a[4],b[6],c2,c3,c1); */
1247 mflo t_1
1248 mfhi t_2
1249 daddu c_2,t_1
1250 sltu AT,c_2,t_1
1251 daddu t_2,AT
1252 daddu c_3,t_2
1253 sltu AT,c_3,t_2
1254 daddu c_1,AT
1255 dmultu a_3,b_7 /* mul_add_c(a[3],b[7],c2,c3,c1); */
1256 mflo t_1
1257 mfhi t_2
1258 daddu c_2,t_1
1259 sltu AT,c_2,t_1
1260 daddu t_2,AT
1261 daddu c_3,t_2
1262 sltu AT,c_3,t_2
1263 daddu c_1,AT
1264 sd c_2,80(a0) /* r[10]=c2; */
1265
1266 dmultu a_4,b_7 /* mul_add_c(a[4],b[7],c3,c1,c2); */
1267 mflo t_1
1268 mfhi t_2
1269 daddu c_3,t_1
1270 sltu AT,c_3,t_1
1271 daddu t_2,AT
1272 daddu c_1,t_2
1273 dmultu a_5,b_6 /* mul_add_c(a[5],b[6],c3,c1,c2); */
1274 mflo t_1
1275 mfhi t_2
1276 daddu c_3,t_1
1277 sltu AT,c_3,t_1
1278 daddu t_2,AT
1279 daddu c_1,t_2
1280 sltu c_2,c_1,t_2
1281 dmultu a_6,b_5 /* mul_add_c(a[6],b[5],c3,c1,c2); */
1282 mflo t_1
1283 mfhi t_2
1284 daddu c_3,t_1
1285 sltu AT,c_3,t_1
1286 daddu t_2,AT
1287 daddu c_1,t_2
1288 sltu AT,c_1,t_2
1289 daddu c_2,AT
1290 dmultu a_7,b_4 /* mul_add_c(a[7],b[4],c3,c1,c2); */
1291 mflo t_1
1292 mfhi t_2
1293 daddu c_3,t_1
1294 sltu AT,c_3,t_1
1295 daddu t_2,AT
1296 daddu c_1,t_2
1297 sltu AT,c_1,t_2
1298 daddu c_2,AT
1299 sd c_3,88(a0) /* r[11]=c3; */
1300
1301 dmultu a_7,b_5 /* mul_add_c(a[7],b[5],c1,c2,c3); */
1302 mflo t_1
1303 mfhi t_2
1304 daddu c_1,t_1
1305 sltu AT,c_1,t_1
1306 daddu t_2,AT
1307 daddu c_2,t_2
1308 dmultu a_6,b_6 /* mul_add_c(a[6],b[6],c1,c2,c3); */
1309 mflo t_1
1310 mfhi t_2
1311 daddu c_1,t_1
1312 sltu AT,c_1,t_1
1313 daddu t_2,AT
1314 daddu c_2,t_2
1315 sltu c_3,c_2,t_2
1316 dmultu a_5,b_7 /* mul_add_c(a[5],b[7],c1,c2,c3); */
1317 mflo t_1
1318 mfhi t_2
1319 daddu c_1,t_1
1320 sltu AT,c_1,t_1
1321 daddu t_2,AT
1322 daddu c_2,t_2
1323 sltu AT,c_2,t_2
1324 daddu c_3,AT
1325 sd c_1,96(a0) /* r[12]=c1; */
1326
1327 dmultu a_6,b_7 /* mul_add_c(a[6],b[7],c2,c3,c1); */
1328 mflo t_1
1329 mfhi t_2
1330 daddu c_2,t_1
1331 sltu AT,c_2,t_1
1332 daddu t_2,AT
1333 daddu c_3,t_2
1334 dmultu a_7,b_6 /* mul_add_c(a[7],b[6],c2,c3,c1); */
1335 mflo t_1
1336 mfhi t_2
1337 daddu c_2,t_1
1338 sltu AT,c_2,t_1
1339 daddu t_2,AT
1340 daddu c_3,t_2
1341 sltu c_1,c_3,t_2
1342 sd c_2,104(a0) /* r[13]=c2; */
1343
1344 dmultu a_7,b_7 /* mul_add_c(a[7],b[7],c3,c1,c2); */
1345 ld s0,0(sp)
1346 ld s1,8(sp)
1347 ld s2,16(sp)
1348 ld s3,24(sp)
1349 ld s4,32(sp)
1350 ld s5,40(sp)
1351 mflo t_1
1352 mfhi t_2
1353 daddu c_3,t_1
1354 sltu AT,c_3,t_1
1355 daddu t_2,AT
1356 daddu c_1,t_2
1357 sd c_3,112(a0) /* r[14]=c3; */
1358 sd c_1,120(a0) /* r[15]=c1; */
1359
1360 PTR_ADD sp,FRAME_SIZE
1361
1362 jr ra
1363END(bn_mul_comba8)
1364
1365.align 5
1366LEAF(bn_mul_comba4)
1367 .set reorder
1368 ld a_0,0(a1)
1369 ld b_0,0(a2)
1370 ld a_1,8(a1)
1371 ld a_2,16(a1)
1372 dmultu a_0,b_0 /* mul_add_c(a[0],b[0],c1,c2,c3); */
1373 ld a_3,24(a1)
1374 ld b_1,8(a2)
1375 ld b_2,16(a2)
1376 ld b_3,24(a2)
1377 mflo c_1
1378 mfhi c_2
1379 sd c_1,0(a0)
1380
1381 dmultu a_0,b_1 /* mul_add_c(a[0],b[1],c2,c3,c1); */
1382 mflo t_1
1383 mfhi t_2
1384 daddu c_2,t_1
1385 sltu AT,c_2,t_1
1386 daddu c_3,t_2,AT
1387 dmultu a_1,b_0 /* mul_add_c(a[1],b[0],c2,c3,c1); */
1388 mflo t_1
1389 mfhi t_2
1390 daddu c_2,t_1
1391 sltu AT,c_2,t_1
1392 daddu t_2,AT
1393 daddu c_3,t_2
1394 sltu c_1,c_3,t_2
1395 sd c_2,8(a0)
1396
1397 dmultu a_2,b_0 /* mul_add_c(a[2],b[0],c3,c1,c2); */
1398 mflo t_1
1399 mfhi t_2
1400 daddu c_3,t_1
1401 sltu AT,c_3,t_1
1402 daddu t_2,AT
1403 daddu c_1,t_2
1404 dmultu a_1,b_1 /* mul_add_c(a[1],b[1],c3,c1,c2); */
1405 mflo t_1
1406 mfhi t_2
1407 daddu c_3,t_1
1408 sltu AT,c_3,t_1
1409 daddu t_2,AT
1410 daddu c_1,t_2
1411 sltu c_2,c_1,t_2
1412 dmultu a_0,b_2 /* mul_add_c(a[0],b[2],c3,c1,c2); */
1413 mflo t_1
1414 mfhi t_2
1415 daddu c_3,t_1
1416 sltu AT,c_3,t_1
1417 daddu t_2,AT
1418 daddu c_1,t_2
1419 sltu AT,c_1,t_2
1420 daddu c_2,AT
1421 sd c_3,16(a0)
1422
1423 dmultu a_0,b_3 /* mul_add_c(a[0],b[3],c1,c2,c3); */
1424 mflo t_1
1425 mfhi t_2
1426 daddu c_1,t_1
1427 sltu AT,c_1,t_1
1428 daddu t_2,AT
1429 daddu c_2,t_2
1430 dmultu a_1,b_2 /* mul_add_c(a[1],b[2],c1,c2,c3); */
1431 mflo t_1
1432 mfhi t_2
1433 daddu c_1,t_1
1434 sltu AT,c_1,t_1
1435 daddu t_2,AT
1436 daddu c_2,t_2
1437 sltu c_3,c_2,t_2
1438 dmultu a_2,b_1 /* mul_add_c(a[2],b[1],c1,c2,c3); */
1439 mflo t_1
1440 mfhi t_2
1441 daddu c_1,t_1
1442 sltu AT,c_1,t_1
1443 daddu t_2,AT
1444 daddu c_2,t_2
1445 sltu AT,c_2,t_2
1446 daddu c_3,AT
1447 dmultu a_3,b_0 /* mul_add_c(a[3],b[0],c1,c2,c3); */
1448 mflo t_1
1449 mfhi t_2
1450 daddu c_1,t_1
1451 sltu AT,c_1,t_1
1452 daddu t_2,AT
1453 daddu c_2,t_2
1454 sltu AT,c_2,t_2
1455 daddu c_3,AT
1456 sd c_1,24(a0)
1457
1458 dmultu a_3,b_1 /* mul_add_c(a[3],b[1],c2,c3,c1); */
1459 mflo t_1
1460 mfhi t_2
1461 daddu c_2,t_1
1462 sltu AT,c_2,t_1
1463 daddu t_2,AT
1464 daddu c_3,t_2
1465 dmultu a_2,b_2 /* mul_add_c(a[2],b[2],c2,c3,c1); */
1466 mflo t_1
1467 mfhi t_2
1468 daddu c_2,t_1
1469 sltu AT,c_2,t_1
1470 daddu t_2,AT
1471 daddu c_3,t_2
1472 sltu c_1,c_3,t_2
1473 dmultu a_1,b_3 /* mul_add_c(a[1],b[3],c2,c3,c1); */
1474 mflo t_1
1475 mfhi t_2
1476 daddu c_2,t_1
1477 sltu AT,c_2,t_1
1478 daddu t_2,AT
1479 daddu c_3,t_2
1480 sltu AT,c_3,t_2
1481 daddu c_1,AT
1482 sd c_2,32(a0)
1483
1484 dmultu a_2,b_3 /* mul_add_c(a[2],b[3],c3,c1,c2); */
1485 mflo t_1
1486 mfhi t_2
1487 daddu c_3,t_1
1488 sltu AT,c_3,t_1
1489 daddu t_2,AT
1490 daddu c_1,t_2
1491 dmultu a_3,b_2 /* mul_add_c(a[3],b[2],c3,c1,c2); */
1492 mflo t_1
1493 mfhi t_2
1494 daddu c_3,t_1
1495 sltu AT,c_3,t_1
1496 daddu t_2,AT
1497 daddu c_1,t_2
1498 sltu c_2,c_1,t_2
1499 sd c_3,40(a0)
1500
1501 dmultu a_3,b_3 /* mul_add_c(a[3],b[3],c1,c2,c3); */
1502 mflo t_1
1503 mfhi t_2
1504 daddu c_1,t_1
1505 sltu AT,c_1,t_1
1506 daddu t_2,AT
1507 daddu c_2,t_2
1508 sd c_1,48(a0)
1509 sd c_2,56(a0)
1510
1511 jr ra
1512END(bn_mul_comba4)
1513
1514#undef a_4
1515#undef a_5
1516#undef a_6
1517#undef a_7
1518#define a_4 b_0
1519#define a_5 b_1
1520#define a_6 b_2
1521#define a_7 b_3
1522
1523.align 5
1524LEAF(bn_sqr_comba8)
1525 .set reorder
1526 ld a_0,0(a1)
1527 ld a_1,8(a1)
1528 ld a_2,16(a1)
1529 ld a_3,24(a1)
1530
1531 dmultu a_0,a_0 /* mul_add_c(a[0],b[0],c1,c2,c3); */
1532 ld a_4,32(a1)
1533 ld a_5,40(a1)
1534 ld a_6,48(a1)
1535 ld a_7,56(a1)
1536 mflo c_1
1537 mfhi c_2
1538 sd c_1,0(a0)
1539
1540 dmultu a_0,a_1 /* mul_add_c2(a[0],b[1],c2,c3,c1); */
1541 mflo t_1
1542 mfhi t_2
1543 daddu c_2,t_1
1544 sltu AT,c_2,t_1
1545 daddu c_3,t_2,AT
1546 daddu c_2,t_1
1547 sltu AT,c_2,t_1
1548 daddu t_2,AT
1549 daddu c_3,t_2
1550 sltu c_1,c_3,t_2
1551 sd c_2,8(a0)
1552
1553 dmultu a_2,a_0 /* mul_add_c2(a[2],b[0],c3,c1,c2); */
1554 mflo t_1
1555 mfhi t_2
1556 daddu c_3,t_1
1557 sltu AT,c_3,t_1
1558 daddu a2,t_2,AT
1559 daddu c_1,a2
1560 daddu c_3,t_1
1561 sltu AT,c_3,t_1
1562 daddu t_2,AT
1563 daddu c_1,t_2
1564 sltu c_2,c_1,t_2
1565 dmultu a_1,a_1 /* mul_add_c(a[1],b[1],c3,c1,c2); */
1566 mflo t_1
1567 mfhi t_2
1568 daddu c_3,t_1
1569 sltu AT,c_3,t_1
1570 daddu t_2,AT
1571 daddu c_1,t_2
1572 sltu AT,c_1,t_2
1573 daddu c_2,AT
1574 sd c_3,16(a0)
1575
1576 dmultu a_0,a_3 /* mul_add_c2(a[0],b[3],c1,c2,c3); */
1577 mflo t_1
1578 mfhi t_2
1579 daddu c_1,t_1
1580 sltu AT,c_1,t_1
1581 daddu a2,t_2,AT
1582 daddu c_2,a2
1583 daddu c_1,t_1
1584 sltu AT,c_1,t_1
1585 daddu t_2,AT
1586 daddu c_2,t_2
1587 sltu c_3,c_2,t_2
1588 dmultu a_1,a_2 /* mul_add_c2(a[1],b[2],c1,c2,c3); */
1589 mflo t_1
1590 mfhi t_2
1591 daddu c_1,t_1
1592 sltu AT,c_1,t_1
1593 daddu a2,t_2,AT
1594 daddu c_2,a2
1595 sltu AT,c_2,a2
1596 daddu c_3,AT
1597 daddu c_1,t_1
1598 sltu AT,c_1,t_1
1599 daddu t_2,AT
1600 daddu c_2,t_2
1601 sltu AT,c_2,t_2
1602 daddu c_3,AT
1603 sd c_1,24(a0)
1604
1605 dmultu a_4,a_0 /* mul_add_c2(a[4],b[0],c2,c3,c1); */
1606 mflo t_1
1607 mfhi t_2
1608 daddu c_2,t_1
1609 sltu AT,c_2,t_1
1610 daddu a2,t_2,AT
1611 daddu c_3,a2
1612 daddu c_2,t_1
1613 sltu AT,c_2,t_1
1614 daddu t_2,AT
1615 daddu c_3,t_2
1616 sltu c_1,c_3,t_2
1617 dmultu a_3,a_1 /* mul_add_c2(a[3],b[1],c2,c3,c1); */
1618 mflo t_1
1619 mfhi t_2
1620 daddu c_2,t_1
1621 sltu AT,c_2,t_1
1622 daddu a2,t_2,AT
1623 daddu c_3,a2
1624 sltu AT,c_3,a2
1625 daddu c_1,AT
1626 daddu c_2,t_1
1627 sltu AT,c_2,t_1
1628 daddu t_2,AT
1629 daddu c_3,t_2
1630 sltu AT,c_3,t_2
1631 daddu c_1,AT
1632 dmultu a_2,a_2 /* mul_add_c(a[2],b[2],c2,c3,c1); */
1633 mflo t_1
1634 mfhi t_2
1635 daddu c_2,t_1
1636 sltu AT,c_2,t_1
1637 daddu t_2,AT
1638 daddu c_3,t_2
1639 sltu AT,c_3,t_2
1640 daddu c_1,AT
1641 sd c_2,32(a0)
1642
1643 dmultu a_0,a_5 /* mul_add_c2(a[0],b[5],c3,c1,c2); */
1644 mflo t_1
1645 mfhi t_2
1646 daddu c_3,t_1
1647 sltu AT,c_3,t_1
1648 daddu a2,t_2,AT
1649 daddu c_1,a2
1650 daddu c_3,t_1
1651 sltu AT,c_3,t_1
1652 daddu t_2,AT
1653 daddu c_1,t_2
1654 sltu c_2,c_1,t_2
1655 dmultu a_1,a_4 /* mul_add_c2(a[1],b[4],c3,c1,c2); */
1656 mflo t_1
1657 mfhi t_2
1658 daddu c_3,t_1
1659 sltu AT,c_3,t_1
1660 daddu a2,t_2,AT
1661 daddu c_1,a2
1662 sltu AT,c_1,a2
1663 daddu c_2,AT
1664 daddu c_3,t_1
1665 sltu AT,c_3,t_1
1666 daddu t_2,AT
1667 daddu c_1,t_2
1668 sltu AT,c_1,t_2
1669 daddu c_2,AT
1670 dmultu a_2,a_3 /* mul_add_c2(a[2],b[3],c3,c1,c2); */
1671 mflo t_1
1672 mfhi t_2
1673 daddu c_3,t_1
1674 sltu AT,c_3,t_1
1675 daddu a2,t_2,AT
1676 daddu c_1,a2
1677 sltu AT,c_1,a2
1678 daddu c_2,AT
1679 daddu c_3,t_1
1680 sltu AT,c_3,t_1
1681 daddu t_2,AT
1682 daddu c_1,t_2
1683 sltu AT,c_1,t_2
1684 daddu c_2,AT
1685 sd c_3,40(a0)
1686
1687 dmultu a_6,a_0 /* mul_add_c2(a[6],b[0],c1,c2,c3); */
1688 mflo t_1
1689 mfhi t_2
1690 daddu c_1,t_1
1691 sltu AT,c_1,t_1
1692 daddu a2,t_2,AT
1693 daddu c_2,a2
1694 daddu c_1,t_1
1695 sltu AT,c_1,t_1
1696 daddu t_2,AT
1697 daddu c_2,t_2
1698 sltu c_3,c_2,t_2
1699 dmultu a_5,a_1 /* mul_add_c2(a[5],b[1],c1,c2,c3); */
1700 mflo t_1
1701 mfhi t_2
1702 daddu c_1,t_1
1703 sltu AT,c_1,t_1
1704 daddu a2,t_2,AT
1705 daddu c_2,a2
1706 sltu AT,c_2,a2
1707 daddu c_3,AT
1708 daddu c_1,t_1
1709 sltu AT,c_1,t_1
1710 daddu t_2,AT
1711 daddu c_2,t_2
1712 sltu AT,c_2,t_2
1713 daddu c_3,AT
1714 dmultu a_4,a_2 /* mul_add_c2(a[4],b[2],c1,c2,c3); */
1715 mflo t_1
1716 mfhi t_2
1717 daddu c_1,t_1
1718 sltu AT,c_1,t_1
1719 daddu a2,t_2,AT
1720 daddu c_2,a2
1721 sltu AT,c_2,a2
1722 daddu c_3,AT
1723 daddu c_1,t_1
1724 sltu AT,c_1,t_1
1725 daddu t_2,AT
1726 daddu c_2,t_2
1727 sltu AT,c_2,t_2
1728 daddu c_3,AT
1729 dmultu a_3,a_3 /* mul_add_c(a[3],b[3],c1,c2,c3); */
1730 mflo t_1
1731 mfhi t_2
1732 daddu c_1,t_1
1733 sltu AT,c_1,t_1
1734 daddu t_2,AT
1735 daddu c_2,t_2
1736 sltu AT,c_2,t_2
1737 daddu c_3,AT
1738 sd c_1,48(a0)
1739
1740 dmultu a_0,a_7 /* mul_add_c2(a[0],b[7],c2,c3,c1); */
1741 mflo t_1
1742 mfhi t_2
1743 daddu c_2,t_1
1744 sltu AT,c_2,t_1
1745 daddu a2,t_2,AT
1746 daddu c_3,a2
1747 daddu c_2,t_1
1748 sltu AT,c_2,t_1
1749 daddu t_2,AT
1750 daddu c_3,t_2
1751 sltu c_1,c_3,t_2
1752 dmultu a_1,a_6 /* mul_add_c2(a[1],b[6],c2,c3,c1); */
1753 mflo t_1
1754 mfhi t_2
1755 daddu c_2,t_1
1756 sltu AT,c_2,t_1
1757 daddu a2,t_2,AT
1758 daddu c_3,a2
1759 sltu AT,c_3,a2
1760 daddu c_1,AT
1761 daddu c_2,t_1
1762 sltu AT,c_2,t_1
1763 daddu t_2,AT
1764 daddu c_3,t_2
1765 sltu AT,c_3,t_2
1766 daddu c_1,AT
1767 dmultu a_2,a_5 /* mul_add_c2(a[2],b[5],c2,c3,c1); */
1768 mflo t_1
1769 mfhi t_2
1770 daddu c_2,t_1
1771 sltu AT,c_2,t_1
1772 daddu a2,t_2,AT
1773 daddu c_3,a2
1774 sltu AT,c_3,a2
1775 daddu c_1,AT
1776 daddu c_2,t_1
1777 sltu AT,c_2,t_1
1778 daddu t_2,AT
1779 daddu c_3,t_2
1780 sltu AT,c_3,t_2
1781 daddu c_1,AT
1782 dmultu a_3,a_4 /* mul_add_c2(a[3],b[4],c2,c3,c1); */
1783 mflo t_1
1784 mfhi t_2
1785 daddu c_2,t_1
1786 sltu AT,c_2,t_1
1787 daddu a2,t_2,AT
1788 daddu c_3,a2
1789 sltu AT,c_3,a2
1790 daddu c_1,AT
1791 daddu c_2,t_1
1792 sltu AT,c_2,t_1
1793 daddu t_2,AT
1794 daddu c_3,t_2
1795 sltu AT,c_3,t_2
1796 daddu c_1,AT
1797 sd c_2,56(a0)
1798
1799 dmultu a_7,a_1 /* mul_add_c2(a[7],b[1],c3,c1,c2); */
1800 mflo t_1
1801 mfhi t_2
1802 daddu c_3,t_1
1803 sltu AT,c_3,t_1
1804 daddu a2,t_2,AT
1805 daddu c_1,a2
1806 daddu c_3,t_1
1807 sltu AT,c_3,t_1
1808 daddu t_2,AT
1809 daddu c_1,t_2
1810 sltu c_2,c_1,t_2
1811 dmultu a_6,a_2 /* mul_add_c2(a[6],b[2],c3,c1,c2); */
1812 mflo t_1
1813 mfhi t_2
1814 daddu c_3,t_1
1815 sltu AT,c_3,t_1
1816 daddu a2,t_2,AT
1817 daddu c_1,a2
1818 sltu AT,c_1,a2
1819 daddu c_2,AT
1820 daddu c_3,t_1
1821 sltu AT,c_3,t_1
1822 daddu t_2,AT
1823 daddu c_1,t_2
1824 sltu AT,c_1,t_2
1825 daddu c_2,AT
1826 dmultu a_5,a_3 /* mul_add_c2(a[5],b[3],c3,c1,c2); */
1827 mflo t_1
1828 mfhi t_2
1829 daddu c_3,t_1
1830 sltu AT,c_3,t_1
1831 daddu a2,t_2,AT
1832 daddu c_1,a2
1833 sltu AT,c_1,a2
1834 daddu c_2,AT
1835 daddu c_3,t_1
1836 sltu AT,c_3,t_1
1837 daddu t_2,AT
1838 daddu c_1,t_2
1839 sltu AT,c_1,t_2
1840 daddu c_2,AT
1841 dmultu a_4,a_4 /* mul_add_c(a[4],b[4],c3,c1,c2); */
1842 mflo t_1
1843 mfhi t_2
1844 daddu c_3,t_1
1845 sltu AT,c_3,t_1
1846 daddu t_2,AT
1847 daddu c_1,t_2
1848 sltu AT,c_1,t_2
1849 daddu c_2,AT
1850 sd c_3,64(a0)
1851
1852 dmultu a_2,a_7 /* mul_add_c2(a[2],b[7],c1,c2,c3); */
1853 mflo t_1
1854 mfhi t_2
1855 daddu c_1,t_1
1856 sltu AT,c_1,t_1
1857 daddu a2,t_2,AT
1858 daddu c_2,a2
1859 daddu c_1,t_1
1860 sltu AT,c_1,t_1
1861 daddu t_2,AT
1862 daddu c_2,t_2
1863 sltu c_3,c_2,t_2
1864 dmultu a_3,a_6 /* mul_add_c2(a[3],b[6],c1,c2,c3); */
1865 mflo t_1
1866 mfhi t_2
1867 daddu c_1,t_1
1868 sltu AT,c_1,t_1
1869 daddu a2,t_2,AT
1870 daddu c_2,a2
1871 sltu AT,c_2,a2
1872 daddu c_3,AT
1873 daddu c_1,t_1
1874 sltu AT,c_1,t_1
1875 daddu t_2,AT
1876 daddu c_2,t_2
1877 sltu AT,c_2,t_2
1878 daddu c_3,AT
1879 dmultu a_4,a_5 /* mul_add_c2(a[4],b[5],c1,c2,c3); */
1880 mflo t_1
1881 mfhi t_2
1882 daddu c_1,t_1
1883 sltu AT,c_1,t_1
1884 daddu a2,t_2,AT
1885 daddu c_2,a2
1886 sltu AT,c_2,a2
1887 daddu c_3,AT
1888 daddu c_1,t_1
1889 sltu AT,c_1,t_1
1890 daddu t_2,AT
1891 daddu c_2,t_2
1892 sltu AT,c_2,t_2
1893 daddu c_3,AT
1894 sd c_1,72(a0)
1895
1896 dmultu a_7,a_3 /* mul_add_c2(a[7],b[3],c2,c3,c1); */
1897 mflo t_1
1898 mfhi t_2
1899 daddu c_2,t_1
1900 sltu AT,c_2,t_1
1901 daddu a2,t_2,AT
1902 daddu c_3,a2
1903 daddu c_2,t_1
1904 sltu AT,c_2,t_1
1905 daddu t_2,AT
1906 daddu c_3,t_2
1907 sltu c_1,c_3,t_2
1908 dmultu a_6,a_4 /* mul_add_c2(a[6],b[4],c2,c3,c1); */
1909 mflo t_1
1910 mfhi t_2
1911 daddu c_2,t_1
1912 sltu AT,c_2,t_1
1913 daddu a2,t_2,AT
1914 daddu c_3,a2
1915 sltu AT,c_3,a2
1916 daddu c_1,AT
1917 daddu c_2,t_1
1918 sltu AT,c_2,t_1
1919 daddu t_2,AT
1920 daddu c_3,t_2
1921 sltu AT,c_3,t_2
1922 daddu c_1,AT
1923 dmultu a_5,a_5 /* mul_add_c(a[5],b[5],c2,c3,c1); */
1924 mflo t_1
1925 mfhi t_2
1926 daddu c_2,t_1
1927 sltu AT,c_2,t_1
1928 daddu t_2,AT
1929 daddu c_3,t_2
1930 sltu AT,c_3,t_2
1931 daddu c_1,AT
1932 sd c_2,80(a0)
1933
1934 dmultu a_4,a_7 /* mul_add_c2(a[4],b[7],c3,c1,c2); */
1935 mflo t_1
1936 mfhi t_2
1937 daddu c_3,t_1
1938 sltu AT,c_3,t_1
1939 daddu a2,t_2,AT
1940 daddu c_1,a2
1941 daddu c_3,t_1
1942 sltu AT,c_3,t_1
1943 daddu t_2,AT
1944 daddu c_1,t_2
1945 sltu c_2,c_1,t_2
1946 dmultu a_5,a_6 /* mul_add_c2(a[5],b[6],c3,c1,c2); */
1947 mflo t_1
1948 mfhi t_2
1949 daddu c_3,t_1
1950 sltu AT,c_3,t_1
1951 daddu a2,t_2,AT
1952 daddu c_1,a2
1953 sltu AT,c_1,a2
1954 daddu c_2,AT
1955 daddu c_3,t_1
1956 sltu AT,c_3,t_1
1957 daddu t_2,AT
1958 daddu c_1,t_2
1959 sltu AT,c_1,t_2
1960 daddu c_2,AT
1961 sd c_3,88(a0)
1962
1963 dmultu a_7,a_5 /* mul_add_c2(a[7],b[5],c1,c2,c3); */
1964 mflo t_1
1965 mfhi t_2
1966 daddu c_1,t_1
1967 sltu AT,c_1,t_1
1968 daddu a2,t_2,AT
1969 daddu c_2,a2
1970 daddu c_1,t_1
1971 sltu AT,c_1,t_1
1972 daddu t_2,AT
1973 daddu c_2,t_2
1974 sltu c_3,c_2,t_2
1975 dmultu a_6,a_6 /* mul_add_c(a[6],b[6],c1,c2,c3); */
1976 mflo t_1
1977 mfhi t_2
1978 daddu c_1,t_1
1979 sltu AT,c_1,t_1
1980 daddu t_2,AT
1981 daddu c_2,t_2
1982 sltu AT,c_2,t_2
1983 daddu c_3,AT
1984 sd c_1,96(a0)
1985
1986 dmultu a_6,a_7 /* mul_add_c2(a[6],b[7],c2,c3,c1); */
1987 mflo t_1
1988 mfhi t_2
1989 daddu c_2,t_1
1990 sltu AT,c_2,t_1
1991 daddu a2,t_2,AT
1992 daddu c_3,a2
1993 daddu c_2,t_1
1994 sltu AT,c_2,t_1
1995 daddu t_2,AT
1996 daddu c_3,t_2
1997 sltu c_1,c_3,t_2
1998 sd c_2,104(a0)
1999
2000 dmultu a_7,a_7 /* mul_add_c(a[7],b[7],c3,c1,c2); */
2001 mflo t_1
2002 mfhi t_2
2003 daddu c_3,t_1
2004 sltu AT,c_3,t_1
2005 daddu t_2,AT
2006 daddu c_1,t_2
2007 sd c_3,112(a0)
2008 sd c_1,120(a0)
2009
2010 jr ra
2011END(bn_sqr_comba8)
2012
2013.align 5
2014LEAF(bn_sqr_comba4)
2015 .set reorder
2016 ld a_0,0(a1)
2017 ld a_1,8(a1)
2018 ld a_2,16(a1)
2019 ld a_3,24(a1)
2020 dmultu a_0,a_0 /* mul_add_c(a[0],b[0],c1,c2,c3); */
2021 mflo c_1
2022 mfhi c_2
2023 sd c_1,0(a0)
2024
2025 dmultu a_0,a_1 /* mul_add_c2(a[0],b[1],c2,c3,c1); */
2026 mflo t_1
2027 mfhi t_2
2028 daddu c_2,t_1
2029 sltu AT,c_2,t_1
2030 daddu c_3,t_2,AT
2031 daddu c_2,t_1
2032 sltu AT,c_2,t_1
2033 daddu t_2,AT
2034 daddu c_3,t_2
2035 sltu c_1,c_3,t_2
2036 sd c_2,8(a0)
2037
2038 dmultu a_2,a_0 /* mul_add_c2(a[2],b[0],c3,c1,c2); */
2039 mflo t_1
2040 mfhi t_2
2041 daddu c_3,t_1
2042 sltu AT,c_3,t_1
2043 daddu a2,t_2,AT
2044 daddu c_1,a2
2045 daddu c_3,t_1
2046 sltu AT,c_3,t_1
2047 daddu t_2,AT
2048 daddu c_1,t_2
2049 sltu c_2,c_1,t_2
2050 dmultu a_1,a_1 /* mul_add_c(a[1],b[1],c3,c1,c2); */
2051 mflo t_1
2052 mfhi t_2
2053 daddu c_3,t_1
2054 sltu AT,c_3,t_1
2055 daddu t_2,AT
2056 daddu c_1,t_2
2057 sltu AT,c_1,t_2
2058 daddu c_2,AT
2059 sd c_3,16(a0)
2060
2061 dmultu a_0,a_3 /* mul_add_c2(a[0],b[3],c1,c2,c3); */
2062 mflo t_1
2063 mfhi t_2
2064 daddu c_1,t_1
2065 sltu AT,c_1,t_1
2066 daddu a2,t_2,AT
2067 daddu c_2,a2
2068 daddu c_1,t_1
2069 sltu AT,c_1,t_1
2070 daddu t_2,AT
2071 daddu c_2,t_2
2072 sltu c_3,c_2,t_2
2073 dmultu a_1,a_2 /* mul_add_c(a2[1],b[2],c1,c2,c3); */
2074 mflo t_1
2075 mfhi t_2
2076 daddu c_1,t_1
2077 sltu AT,c_1,t_1
2078 daddu a2,t_2,AT
2079 daddu c_2,a2
2080 sltu AT,c_2,a2
2081 daddu c_3,AT
2082 daddu c_1,t_1
2083 sltu AT,c_1,t_1
2084 daddu t_2,AT
2085 daddu c_2,t_2
2086 sltu AT,c_2,t_2
2087 daddu c_3,AT
2088 sd c_1,24(a0)
2089
2090 dmultu a_3,a_1 /* mul_add_c2(a[3],b[1],c2,c3,c1); */
2091 mflo t_1
2092 mfhi t_2
2093 daddu c_2,t_1
2094 sltu AT,c_2,t_1
2095 daddu a2,t_2,AT
2096 daddu c_3,a2
2097 daddu c_2,t_1
2098 sltu AT,c_2,t_1
2099 daddu t_2,AT
2100 daddu c_3,t_2
2101 sltu c_1,c_3,t_2
2102 dmultu a_2,a_2 /* mul_add_c(a[2],b[2],c2,c3,c1); */
2103 mflo t_1
2104 mfhi t_2
2105 daddu c_2,t_1
2106 sltu AT,c_2,t_1
2107 daddu t_2,AT
2108 daddu c_3,t_2
2109 sltu AT,c_3,t_2
2110 daddu c_1,AT
2111 sd c_2,32(a0)
2112
2113 dmultu a_2,a_3 /* mul_add_c2(a[2],b[3],c3,c1,c2); */
2114 mflo t_1
2115 mfhi t_2
2116 daddu c_3,t_1
2117 sltu AT,c_3,t_1
2118 daddu a2,t_2,AT
2119 daddu c_1,a2
2120 daddu c_3,t_1
2121 sltu AT,c_3,t_1
2122 daddu t_2,AT
2123 daddu c_1,t_2
2124 sltu c_2,c_1,t_2
2125 sd c_3,40(a0)
2126
2127 dmultu a_3,a_3 /* mul_add_c(a[3],b[3],c1,c2,c3); */
2128 mflo t_1
2129 mfhi t_2
2130 daddu c_1,t_1
2131 sltu AT,c_1,t_1
2132 daddu t_2,AT
2133 daddu c_2,t_2
2134 sd c_1,48(a0)
2135 sd c_2,56(a0)
2136
2137 jr ra
2138END(bn_sqr_comba4)
diff --git a/src/lib/libcrypto/bn/asm/vms.mar b/src/lib/libcrypto/bn/asm/vms.mar
new file mode 100644
index 0000000000..ac9d57d7b0
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/vms.mar
@@ -0,0 +1,6695 @@
1 .title vax_bn_mul_add_word unsigned multiply & add, 32*32+32+32=>64
2;
3; w.j.m. 15-jan-1999
4;
5; it's magic ...
6;
7; ULONG bn_mul_add_words(ULONG r[],ULONG a[],int n,ULONG w) {
8; ULONG c = 0;
9; int i;
10; for(i = 0; i < n; i++) <c,r[i]> := r[i] + c + a[i] * w ;
11; return c;
12; }
13
14r=4 ;(AP)
15a=8 ;(AP)
16n=12 ;(AP) n by value (input)
17w=16 ;(AP) w by value (input)
18
19
20 .psect code,nowrt
21
22.entry bn_mul_add_words,^m<r2,r3,r4,r5,r6>
23
24 moval @r(ap),r2
25 moval @a(ap),r3
26 movl n(ap),r4 ; assumed >0 by C code
27 movl w(ap),r5
28 clrl r6 ; c
29
300$:
31 emul r5,(r3),(r2),r0 ; w, a[], r[] considered signed
32
33 ; fixup for "negative" r[]
34 tstl (r2)
35 bgeq 10$
36 incl r1
3710$:
38
39 ; add in c
40 addl2 r6,r0
41 adwc #0,r1
42
43 ; combined fixup for "negative" w, a[]
44 tstl r5
45 bgeq 20$
46 addl2 (r3),r1
4720$:
48 tstl (r3)
49 bgeq 30$
50 addl2 r5,r1
5130$:
52
53 movl r0,(r2)+ ; store lo result in r[] & advance
54 addl #4,r3 ; advance a[]
55 movl r1,r6 ; store hi result => c
56
57 sobgtr r4,0$
58
59 movl r6,r0 ; return c
60 ret
61
62 .title vax_bn_mul_word unsigned multiply & add, 32*32+32=>64
63;
64; w.j.m. 15-jan-1999
65;
66; it's magic ...
67;
68; ULONG bn_mul_words(ULONG r[],ULONG a[],int n,ULONG w) {
69; ULONG c = 0;
70; int i;
71; for(i = 0; i < num; i++) <c,r[i]> := a[i] * w + c ;
72; return(c);
73; }
74
75r=4 ;(AP)
76a=8 ;(AP)
77n=12 ;(AP) n by value (input)
78w=16 ;(AP) w by value (input)
79
80
81 .psect code,nowrt
82
83.entry bn_mul_words,^m<r2,r3,r4,r5,r6>
84
85 moval @r(ap),r2 ; r2 -> r[]
86 moval @a(ap),r3 ; r3 -> a[]
87 movl n(ap),r4 ; r4 = loop count (assumed >0 by C code)
88 movl w(ap),r5 ; r5 = w
89 clrl r6 ; r6 = c
90
910$:
92 ; <r1,r0> := w * a[] + c
93 emul r5,(r3),r6,r0 ; w, a[], c considered signed
94
95 ; fixup for "negative" c
96 tstl r6 ; c
97 bgeq 10$
98 incl r1
9910$:
100
101 ; combined fixup for "negative" w, a[]
102 tstl r5 ; w
103 bgeq 20$
104 addl2 (r3),r1 ; a[]
10520$:
106 tstl (r3) ; a[]
107 bgeq 30$
108 addl2 r5,r1 ; w
10930$:
110
111 movl r0,(r2)+ ; store lo result in r[] & advance
112 addl #4,r3 ; advance a[]
113 movl r1,r6 ; store hi result => c
114
115 sobgtr r4,0$
116
117 movl r6,r0 ; return c
118 ret
119
120 .title vax_bn_sqr_words unsigned square, 32*32=>64
121;
122; w.j.m. 15-jan-1999
123;
124; it's magic ...
125;
126; void bn_sqr_words(ULONG r[],ULONG a[],int n) {
127; int i;
128; for(i = 0; i < n; i++) <r[2*i+1],r[2*i]> := a[i] * a[i] ;
129; }
130
131r=4 ;(AP)
132a=8 ;(AP)
133n=12 ;(AP) n by value (input)
134
135
136 .psect code,nowrt
137
138.entry bn_sqr_words,^m<r2,r3,r4,r5>
139
140 moval @r(ap),r2 ; r2 -> r[]
141 moval @a(ap),r3 ; r3 -> a[]
142 movl n(ap),r4 ; r4 = n (assumed >0 by C code)
143
1440$:
145 movl (r3)+,r5 ; r5 = a[] & advance
146
147 ; <r1,r0> := a[] * a[]
148 emul r5,r5,#0,r0 ; a[] considered signed
149
150 ; fixup for "negative" a[]
151 tstl r5 ; a[]
152 bgeq 30$
153 addl2 r5,r1 ; a[]
154 addl2 r5,r1 ; a[]
15530$:
156
157 movl r0,(r2)+ ; store lo result in r[] & advance
158 movl r1,(r2)+ ; store hi result in r[] & advance
159
160 sobgtr r4,0$
161
162 movl #1,r0 ; return SS$_NORMAL
163 ret
164
165 .title (generated)
166
167 .psect code,nowrt
168
169.entry BN_DIV_WORDS,^m<r2,r3,r4,r5,r6,r7,r8,r9,r10>
170 subl2 #4,sp
171
172 clrl r9
173 movl #2,r8
174
175 tstl 12(ap)
176 bneq noname.2
177 mnegl #1,r10
178 brw noname.3
179 tstl r0
180 nop
181noname.2:
182
183 pushl 12(ap)
184 calls #1,BN_NUM_BITS_WORD
185 movl r0,r7
186
187 cmpl r7,#32
188 beql noname.4
189 ashl r7,#1,r2
190 cmpl 4(ap),r2
191 blequ noname.4
192
193 pushl r7
194 calls #1,BN_DIV_WORDS_ABORT
195noname.4:
196
197 subl3 r7,#32,r7
198
199 movl 12(ap),r2
200 cmpl 4(ap),r2
201 blssu noname.5
202 subl2 r2,4(ap)
203noname.5:
204
205 tstl r7
206 beql noname.6
207
208 ashl r7,r2,12(ap)
209
210 ashl r7,4(ap),r4
211 subl3 r7,#32,r3
212 subl3 r3,#32,r2
213 extzv r3,r2,8(ap),r2
214 bisl3 r4,r2,4(ap)
215
216 ashl r7,8(ap),8(ap)
217noname.6:
218
219 bicl3 #65535,12(ap),r2
220 extzv #16,#16,r2,r5
221
222 bicl3 #-65536,12(ap),r6
223
224noname.7:
225
226 moval 4(ap),r2
227 movzwl 2(r2),r0
228 cmpl r0,r5
229 bneq noname.8
230
231 movzwl #65535,r4
232 brb noname.9
233noname.8:
234
235 clrl r1
236 movl (r2),r0
237 movl r5,r2
238 bgeq vcg.1
239 cmpl r2,r0
240 bgtru vcg.2
241 incl r1
242 brb vcg.2
243 nop
244vcg.1:
245 ediv r2,r0,r1,r0
246vcg.2:
247 movl r1,r4
248noname.9:
249
250noname.10:
251
252 mull3 r5,r4,r0
253 subl3 r0,4(ap),r3
254
255 bicl3 #65535,r3,r0
256 bneq noname.13
257 mull3 r6,r4,r2
258 ashl #16,r3,r1
259 bicl3 #65535,8(ap),r0
260 extzv #16,#16,r0,r0
261 addl2 r0,r1
262 cmpl r2,r1
263 bgtru noname.12
264noname.11:
265
266 brb noname.13
267 nop
268noname.12:
269
270 decl r4
271 brb noname.10
272noname.13:
273
274 mull3 r5,r4,r1
275
276 mull3 r6,r4,r0
277
278 extzv #16,#16,r0,r3
279
280 ashl #16,r0,r2
281 bicl3 #65535,r2,r0
282
283 addl2 r3,r1
284
285 moval 8(ap),r3
286 cmpl (r3),r0
287 bgequ noname.15
288 incl r1
289noname.15:
290
291 subl2 r0,(r3)
292
293 cmpl 4(ap),r1
294 bgequ noname.16
295
296 addl2 12(ap),4(ap)
297
298 decl r4
299noname.16:
300
301 subl2 r1,4(ap)
302
303 decl r8
304 beql noname.18
305noname.17:
306
307 ashl #16,r4,r9
308
309 ashl #16,4(ap),r2
310 movzwl 2(r3),r0
311 bisl2 r0,r2
312 bicl3 #0,r2,4(ap)
313
314 bicl3 #-65536,(r3),r0
315 ashl #16,r0,(r3)
316 brw noname.7
317 nop
318noname.18:
319
320 bisl2 r4,r9
321
322 movl r9,r10
323
324noname.3:
325 movl r10,r0
326 ret
327 tstl r0
328
329
330 .psect code,nowrt
331
332.entry BN_ADD_WORDS,^m<r2,r3,r4,r5,r6,r7>
333
334 tstl 16(ap)
335 bgtr noname.21
336 clrl r7
337 brw noname.22
338noname.21:
339
340 clrl r4
341
342 tstl r0
343noname.23:
344
345 movl 8(ap),r6
346 addl3 r4,(r6),r2
347
348 bicl2 #0,r2
349
350 clrl r0
351 cmpl r2,r4
352 bgequ vcg.3
353 incl r0
354vcg.3:
355 movl r0,r4
356
357 movl 12(ap),r5
358 addl3 (r5),r2,r1
359 bicl2 #0,r1
360
361 clrl r0
362 cmpl r1,r2
363 bgequ vcg.4
364 incl r0
365vcg.4:
366 addl2 r0,r4
367
368 movl 4(ap),r3
369 movl r1,(r3)
370
371 decl 16(ap)
372 bgtr gen.1
373 brw noname.25
374gen.1:
375noname.24:
376
377 addl3 r4,4(r6),r2
378
379 bicl2 #0,r2
380
381 clrl r0
382 cmpl r2,r4
383 bgequ vcg.5
384 incl r0
385vcg.5:
386 movl r0,r4
387
388 addl3 4(r5),r2,r1
389 bicl2 #0,r1
390
391 clrl r0
392 cmpl r1,r2
393 bgequ vcg.6
394 incl r0
395vcg.6:
396 addl2 r0,r4
397
398 movl r1,4(r3)
399
400 decl 16(ap)
401 bleq noname.25
402noname.26:
403
404 addl3 r4,8(r6),r2
405
406 bicl2 #0,r2
407
408 clrl r0
409 cmpl r2,r4
410 bgequ vcg.7
411 incl r0
412vcg.7:
413 movl r0,r4
414
415 addl3 8(r5),r2,r1
416 bicl2 #0,r1
417
418 clrl r0
419 cmpl r1,r2
420 bgequ vcg.8
421 incl r0
422vcg.8:
423 addl2 r0,r4
424
425 movl r1,8(r3)
426
427 decl 16(ap)
428 bleq noname.25
429noname.27:
430
431 addl3 r4,12(r6),r2
432
433 bicl2 #0,r2
434
435 clrl r0
436 cmpl r2,r4
437 bgequ vcg.9
438 incl r0
439vcg.9:
440 movl r0,r4
441
442 addl3 12(r5),r2,r1
443 bicl2 #0,r1
444
445 clrl r0
446 cmpl r1,r2
447 bgequ vcg.10
448 incl r0
449vcg.10:
450 addl2 r0,r4
451
452 movl r1,12(r3)
453
454 decl 16(ap)
455 bleq noname.25
456noname.28:
457
458 addl3 #16,r6,8(ap)
459
460 addl3 #16,r5,12(ap)
461
462 addl3 #16,r3,4(ap)
463 brw noname.23
464 tstl r0
465noname.25:
466
467 movl r4,r7
468
469noname.22:
470 movl r7,r0
471 ret
472 nop
473
474
475
476;r=4 ;(AP)
477;a=8 ;(AP)
478;b=12 ;(AP)
479;n=16 ;(AP) n by value (input)
480
481 .psect code,nowrt
482
483.entry BN_SUB_WORDS,^m<r2,r3,r4,r5,r6,r7>
484
485 clrl r6
486
487 tstl 16(ap)
488 bgtr noname.31
489 clrl r7
490 brw noname.32
491 tstl r0
492noname.31:
493
494noname.33:
495
496 movl 8(ap),r5
497 movl (r5),r1
498 movl 12(ap),r4
499 movl (r4),r2
500
501 movl 4(ap),r3
502 subl3 r2,r1,r0
503 subl2 r6,r0
504 bicl3 #0,r0,(r3)
505
506 cmpl r1,r2
507 beql noname.34
508 clrl r0
509 cmpl r1,r2
510 bgequ vcg.11
511 incl r0
512vcg.11:
513 movl r0,r6
514noname.34:
515
516 decl 16(ap)
517 bgtr gen.2
518 brw noname.36
519gen.2:
520noname.35:
521
522 movl 4(r5),r2
523 movl 4(r4),r1
524
525 subl3 r1,r2,r0
526 subl2 r6,r0
527 bicl3 #0,r0,4(r3)
528
529 cmpl r2,r1
530 beql noname.37
531 clrl r0
532 cmpl r2,r1
533 bgequ vcg.12
534 incl r0
535vcg.12:
536 movl r0,r6
537noname.37:
538
539 decl 16(ap)
540 bleq noname.36
541noname.38:
542
543 movl 8(r5),r1
544 movl 8(r4),r2
545
546 subl3 r2,r1,r0
547 subl2 r6,r0
548 bicl3 #0,r0,8(r3)
549
550 cmpl r1,r2
551 beql noname.39
552 clrl r0
553 cmpl r1,r2
554 bgequ vcg.13
555 incl r0
556vcg.13:
557 movl r0,r6
558noname.39:
559
560 decl 16(ap)
561 bleq noname.36
562noname.40:
563
564 movl 12(r5),r1
565 movl 12(r4),r2
566
567 subl3 r2,r1,r0
568 subl2 r6,r0
569 bicl3 #0,r0,12(r3)
570
571 cmpl r1,r2
572 beql noname.41
573 clrl r0
574 cmpl r1,r2
575 bgequ vcg.14
576 incl r0
577vcg.14:
578 movl r0,r6
579noname.41:
580
581 decl 16(ap)
582 bleq noname.36
583noname.42:
584
585 addl3 #16,r5,8(ap)
586
587 addl3 #16,r4,12(ap)
588
589 addl3 #16,r3,4(ap)
590 brw noname.33
591 tstl r0
592noname.36:
593
594 movl r6,r7
595
596noname.32:
597 movl r7,r0
598 ret
599 nop
600
601
602
603;r=4 ;(AP)
604;a=8 ;(AP)
605;b=12 ;(AP)
606;n=16 ;(AP) n by value (input)
607
608 .psect code,nowrt
609
610.entry BN_MUL_COMBA8,^m<r2,r3,r4,r5,r6,r7,r8,r9,r10,r11>
611 movab -924(sp),sp
612 clrq r8
613
614 clrl r10
615
616 movl 8(ap),r6
617 movzwl 2(r6),r3
618 movl 12(ap),r7
619 bicl3 #-65536,(r7),r2
620 movzwl 2(r7),r0
621 bicl2 #-65536,r0
622 bicl3 #-65536,(r6),-12(fp)
623 bicl3 #-65536,r3,-16(fp)
624 mull3 r0,-12(fp),-4(fp)
625 mull2 r2,-12(fp)
626 mull3 r2,-16(fp),-8(fp)
627 mull2 r0,-16(fp)
628 addl3 -4(fp),-8(fp),r0
629 bicl3 #0,r0,-4(fp)
630 cmpl -4(fp),-8(fp)
631 bgequ noname.45
632 addl2 #65536,-16(fp)
633noname.45:
634 movzwl -2(fp),r0
635 bicl2 #-65536,r0
636 addl2 r0,-16(fp)
637 bicl3 #-65536,-4(fp),r0
638 ashl #16,r0,-8(fp)
639 addl3 -8(fp),-12(fp),r0
640 bicl3 #0,r0,-12(fp)
641 cmpl -12(fp),-8(fp)
642 bgequ noname.46
643 incl -16(fp)
644noname.46:
645 movl -12(fp),r1
646 movl -16(fp),r2
647 addl2 r1,r9
648 bicl2 #0,r9
649 cmpl r9,r1
650 bgequ noname.47
651 incl r2
652noname.47:
653 addl2 r2,r8
654 bicl2 #0,r8
655 cmpl r8,r2
656 bgequ noname.48
657 incl r10
658noname.48:
659
660 movl 4(ap),r11
661 movl r9,(r11)
662
663 clrl r9
664
665 movzwl 2(r6),r2
666 bicl3 #-65536,4(r7),r3
667 movzwl 6(r7),r0
668 bicl2 #-65536,r0
669 bicl3 #-65536,(r6),-28(fp)
670 bicl3 #-65536,r2,-32(fp)
671 mull3 r0,-28(fp),-20(fp)
672 mull2 r3,-28(fp)
673 mull3 r3,-32(fp),-24(fp)
674 mull2 r0,-32(fp)
675 addl3 -20(fp),-24(fp),r0
676 bicl3 #0,r0,-20(fp)
677 cmpl -20(fp),-24(fp)
678 bgequ noname.49
679 addl2 #65536,-32(fp)
680noname.49:
681 movzwl -18(fp),r0
682 bicl2 #-65536,r0
683 addl2 r0,-32(fp)
684 bicl3 #-65536,-20(fp),r0
685 ashl #16,r0,-24(fp)
686 addl3 -24(fp),-28(fp),r0
687 bicl3 #0,r0,-28(fp)
688 cmpl -28(fp),-24(fp)
689 bgequ noname.50
690 incl -32(fp)
691noname.50:
692 movl -28(fp),r1
693 movl -32(fp),r2
694 addl2 r1,r8
695 bicl2 #0,r8
696 cmpl r8,r1
697 bgequ noname.51
698 incl r2
699noname.51:
700 addl2 r2,r10
701 bicl2 #0,r10
702 cmpl r10,r2
703 bgequ noname.52
704 incl r9
705noname.52:
706
707 movzwl 6(r6),r2
708 bicl3 #-65536,(r7),r3
709 movzwl 2(r7),r0
710 bicl2 #-65536,r0
711 bicl3 #-65536,4(r6),-44(fp)
712 bicl3 #-65536,r2,-48(fp)
713 mull3 r0,-44(fp),-36(fp)
714 mull2 r3,-44(fp)
715 mull3 r3,-48(fp),-40(fp)
716 mull2 r0,-48(fp)
717 addl3 -36(fp),-40(fp),r0
718 bicl3 #0,r0,-36(fp)
719 cmpl -36(fp),-40(fp)
720 bgequ noname.53
721 addl2 #65536,-48(fp)
722noname.53:
723 movzwl -34(fp),r0
724 bicl2 #-65536,r0
725 addl2 r0,-48(fp)
726 bicl3 #-65536,-36(fp),r0
727 ashl #16,r0,-40(fp)
728 addl3 -40(fp),-44(fp),r0
729 bicl3 #0,r0,-44(fp)
730 cmpl -44(fp),-40(fp)
731 bgequ noname.54
732 incl -48(fp)
733noname.54:
734 movl -44(fp),r1
735 movl -48(fp),r2
736 addl2 r1,r8
737 bicl2 #0,r8
738 cmpl r8,r1
739 bgequ noname.55
740 incl r2
741noname.55:
742 addl2 r2,r10
743 bicl2 #0,r10
744 cmpl r10,r2
745 bgequ noname.56
746 incl r9
747noname.56:
748
749 movl r8,4(r11)
750
751 clrl r8
752
753 movzwl 10(r6),r2
754 bicl3 #-65536,(r7),r3
755 movzwl 2(r7),r0
756 bicl2 #-65536,r0
757 bicl3 #-65536,8(r6),-60(fp)
758 bicl3 #-65536,r2,-64(fp)
759 mull3 r0,-60(fp),-52(fp)
760 mull2 r3,-60(fp)
761 mull3 r3,-64(fp),-56(fp)
762 mull2 r0,-64(fp)
763 addl3 -52(fp),-56(fp),r0
764 bicl3 #0,r0,-52(fp)
765 cmpl -52(fp),-56(fp)
766 bgequ noname.57
767 addl2 #65536,-64(fp)
768noname.57:
769 movzwl -50(fp),r0
770 bicl2 #-65536,r0
771 addl2 r0,-64(fp)
772 bicl3 #-65536,-52(fp),r0
773 ashl #16,r0,-56(fp)
774 addl3 -56(fp),-60(fp),r0
775 bicl3 #0,r0,-60(fp)
776 cmpl -60(fp),-56(fp)
777 bgequ noname.58
778 incl -64(fp)
779noname.58:
780 movl -60(fp),r1
781 movl -64(fp),r2
782 addl2 r1,r10
783 bicl2 #0,r10
784 cmpl r10,r1
785 bgequ noname.59
786 incl r2
787noname.59:
788 addl2 r2,r9
789 bicl2 #0,r9
790 cmpl r9,r2
791 bgequ noname.60
792 incl r8
793noname.60:
794
795 movzwl 6(r6),r2
796 bicl3 #-65536,4(r7),r3
797 movzwl 6(r7),r0
798 bicl2 #-65536,r0
799 bicl3 #-65536,4(r6),-76(fp)
800 bicl3 #-65536,r2,-80(fp)
801 mull3 r0,-76(fp),-68(fp)
802 mull2 r3,-76(fp)
803 mull3 r3,-80(fp),-72(fp)
804 mull2 r0,-80(fp)
805 addl3 -68(fp),-72(fp),r0
806 bicl3 #0,r0,-68(fp)
807 cmpl -68(fp),-72(fp)
808 bgequ noname.61
809 addl2 #65536,-80(fp)
810noname.61:
811 movzwl -66(fp),r0
812 bicl2 #-65536,r0
813 addl2 r0,-80(fp)
814 bicl3 #-65536,-68(fp),r0
815 ashl #16,r0,-72(fp)
816 addl3 -72(fp),-76(fp),r0
817 bicl3 #0,r0,-76(fp)
818 cmpl -76(fp),-72(fp)
819 bgequ noname.62
820 incl -80(fp)
821noname.62:
822 movl -76(fp),r1
823 movl -80(fp),r2
824 addl2 r1,r10
825 bicl2 #0,r10
826 cmpl r10,r1
827 bgequ noname.63
828 incl r2
829noname.63:
830 addl2 r2,r9
831 bicl2 #0,r9
832 cmpl r9,r2
833 bgequ noname.64
834 incl r8
835noname.64:
836
837 movzwl 2(r6),r2
838 bicl3 #-65536,8(r7),r3
839 movzwl 10(r7),r0
840 bicl2 #-65536,r0
841 bicl3 #-65536,(r6),-92(fp)
842 bicl3 #-65536,r2,-96(fp)
843 mull3 r0,-92(fp),-84(fp)
844 mull2 r3,-92(fp)
845 mull3 r3,-96(fp),-88(fp)
846 mull2 r0,-96(fp)
847 addl3 -84(fp),-88(fp),r0
848 bicl3 #0,r0,-84(fp)
849 cmpl -84(fp),-88(fp)
850 bgequ noname.65
851 addl2 #65536,-96(fp)
852noname.65:
853 movzwl -82(fp),r0
854 bicl2 #-65536,r0
855 addl2 r0,-96(fp)
856 bicl3 #-65536,-84(fp),r0
857 ashl #16,r0,-88(fp)
858 addl3 -88(fp),-92(fp),r0
859 bicl3 #0,r0,-92(fp)
860 cmpl -92(fp),-88(fp)
861 bgequ noname.66
862 incl -96(fp)
863noname.66:
864 movl -92(fp),r1
865 movl -96(fp),r2
866 addl2 r1,r10
867 bicl2 #0,r10
868 cmpl r10,r1
869 bgequ noname.67
870 incl r2
871noname.67:
872 addl2 r2,r9
873 bicl2 #0,r9
874 cmpl r9,r2
875 bgequ noname.68
876 incl r8
877noname.68:
878
879 movl r10,8(r11)
880
881 clrl r10
882
883 movzwl 2(r6),r2
884 bicl3 #-65536,12(r7),r3
885 movzwl 14(r7),r0
886 bicl2 #-65536,r0
887 bicl3 #-65536,(r6),-108(fp)
888 bicl3 #-65536,r2,-112(fp)
889 mull3 r0,-108(fp),-100(fp)
890 mull2 r3,-108(fp)
891 mull3 r3,-112(fp),-104(fp)
892 mull2 r0,-112(fp)
893 addl3 -100(fp),-104(fp),r0
894 bicl3 #0,r0,-100(fp)
895 cmpl -100(fp),-104(fp)
896 bgequ noname.69
897 addl2 #65536,-112(fp)
898noname.69:
899 movzwl -98(fp),r0
900 bicl2 #-65536,r0
901 addl2 r0,-112(fp)
902 bicl3 #-65536,-100(fp),r0
903 ashl #16,r0,-104(fp)
904 addl3 -104(fp),-108(fp),r0
905 bicl3 #0,r0,-108(fp)
906 cmpl -108(fp),-104(fp)
907 bgequ noname.70
908 incl -112(fp)
909noname.70:
910 movl -108(fp),r1
911 movl -112(fp),r2
912 addl2 r1,r9
913 bicl2 #0,r9
914 cmpl r9,r1
915 bgequ noname.71
916 incl r2
917noname.71:
918 addl2 r2,r8
919 bicl2 #0,r8
920 cmpl r8,r2
921 bgequ noname.72
922 incl r10
923noname.72:
924
925 movzwl 6(r6),r2
926 bicl3 #-65536,8(r7),r3
927 movzwl 10(r7),r0
928 bicl2 #-65536,r0
929 bicl3 #-65536,4(r6),-124(fp)
930 bicl3 #-65536,r2,-128(fp)
931 mull3 r0,-124(fp),-116(fp)
932 mull2 r3,-124(fp)
933 mull3 r3,-128(fp),-120(fp)
934 mull2 r0,-128(fp)
935 addl3 -116(fp),-120(fp),r0
936 bicl3 #0,r0,-116(fp)
937 cmpl -116(fp),-120(fp)
938 bgequ noname.73
939 addl2 #65536,-128(fp)
940noname.73:
941 movzwl -114(fp),r0
942 bicl2 #-65536,r0
943 addl2 r0,-128(fp)
944 bicl3 #-65536,-116(fp),r0
945 ashl #16,r0,-120(fp)
946 addl3 -120(fp),-124(fp),r0
947 bicl3 #0,r0,-124(fp)
948 cmpl -124(fp),-120(fp)
949 bgequ noname.74
950 incl -128(fp)
951noname.74:
952 movl -124(fp),r1
953 movl -128(fp),r2
954 addl2 r1,r9
955 bicl2 #0,r9
956 cmpl r9,r1
957 bgequ noname.75
958 incl r2
959noname.75:
960 addl2 r2,r8
961 bicl2 #0,r8
962 cmpl r8,r2
963 bgequ noname.76
964 incl r10
965noname.76:
966
967 movzwl 10(r6),r2
968 bicl3 #-65536,4(r7),r3
969 movzwl 6(r7),r0
970 bicl2 #-65536,r0
971 bicl3 #-65536,8(r6),-140(fp)
972 bicl3 #-65536,r2,-144(fp)
973 mull3 r0,-140(fp),-132(fp)
974 mull2 r3,-140(fp)
975 mull3 r3,-144(fp),-136(fp)
976 mull2 r0,-144(fp)
977 addl3 -132(fp),-136(fp),r0
978 bicl3 #0,r0,-132(fp)
979 cmpl -132(fp),-136(fp)
980 bgequ noname.77
981 addl2 #65536,-144(fp)
982noname.77:
983 movzwl -130(fp),r0
984 bicl2 #-65536,r0
985 addl2 r0,-144(fp)
986 bicl3 #-65536,-132(fp),r0
987 ashl #16,r0,-136(fp)
988 addl3 -136(fp),-140(fp),r0
989 bicl3 #0,r0,-140(fp)
990 cmpl -140(fp),-136(fp)
991 bgequ noname.78
992 incl -144(fp)
993noname.78:
994 movl -140(fp),r1
995 movl -144(fp),r2
996 addl2 r1,r9
997 bicl2 #0,r9
998 cmpl r9,r1
999 bgequ noname.79
1000 incl r2
1001noname.79:
1002 addl2 r2,r8
1003 bicl2 #0,r8
1004 cmpl r8,r2
1005 bgequ noname.80
1006 incl r10
1007noname.80:
1008
1009 movzwl 14(r6),r2
1010 bicl3 #-65536,(r7),r3
1011 movzwl 2(r7),r0
1012 bicl2 #-65536,r0
1013 bicl3 #-65536,12(r6),-156(fp)
1014 bicl3 #-65536,r2,-160(fp)
1015 mull3 r0,-156(fp),-148(fp)
1016 mull2 r3,-156(fp)
1017 mull3 r3,-160(fp),-152(fp)
1018 mull2 r0,-160(fp)
1019 addl3 -148(fp),-152(fp),r0
1020 bicl3 #0,r0,-148(fp)
1021 cmpl -148(fp),-152(fp)
1022 bgequ noname.81
1023 addl2 #65536,-160(fp)
1024noname.81:
1025 movzwl -146(fp),r0
1026 bicl2 #-65536,r0
1027 addl2 r0,-160(fp)
1028 bicl3 #-65536,-148(fp),r0
1029 ashl #16,r0,-152(fp)
1030 addl3 -152(fp),-156(fp),r0
1031 bicl3 #0,r0,-156(fp)
1032 cmpl -156(fp),-152(fp)
1033 bgequ noname.82
1034 incl -160(fp)
1035noname.82:
1036 movl -156(fp),r1
1037 movl -160(fp),r2
1038 addl2 r1,r9
1039 bicl2 #0,r9
1040 cmpl r9,r1
1041 bgequ noname.83
1042 incl r2
1043noname.83:
1044 addl2 r2,r8
1045 bicl2 #0,r8
1046 cmpl r8,r2
1047 bgequ noname.84
1048 incl r10
1049noname.84:
1050
1051 movl r9,12(r11)
1052
1053 clrl r9
1054
1055 movzwl 18(r6),r2
1056 bicl3 #-65536,(r7),r3
1057 movzwl 2(r7),r0
1058 bicl2 #-65536,r0
1059 bicl3 #-65536,16(r6),-172(fp)
1060 bicl3 #-65536,r2,-176(fp)
1061 mull3 r0,-172(fp),-164(fp)
1062 mull2 r3,-172(fp)
1063 mull3 r3,-176(fp),-168(fp)
1064 mull2 r0,-176(fp)
1065 addl3 -164(fp),-168(fp),r0
1066 bicl3 #0,r0,-164(fp)
1067 cmpl -164(fp),-168(fp)
1068 bgequ noname.85
1069 addl2 #65536,-176(fp)
1070noname.85:
1071 movzwl -162(fp),r0
1072 bicl2 #-65536,r0
1073 addl2 r0,-176(fp)
1074 bicl3 #-65536,-164(fp),r0
1075 ashl #16,r0,-168(fp)
1076 addl3 -168(fp),-172(fp),r0
1077 bicl3 #0,r0,-172(fp)
1078 cmpl -172(fp),-168(fp)
1079 bgequ noname.86
1080 incl -176(fp)
1081noname.86:
1082 movl -172(fp),r1
1083 movl -176(fp),r2
1084 addl2 r1,r8
1085 bicl2 #0,r8
1086 cmpl r8,r1
1087 bgequ noname.87
1088 incl r2
1089noname.87:
1090 addl2 r2,r10
1091 bicl2 #0,r10
1092 cmpl r10,r2
1093 bgequ noname.88
1094 incl r9
1095noname.88:
1096
1097 movzwl 14(r6),r2
1098 bicl3 #-65536,4(r7),r3
1099 movzwl 6(r7),r0
1100 bicl2 #-65536,r0
1101 bicl3 #-65536,12(r6),-188(fp)
1102 bicl3 #-65536,r2,-192(fp)
1103 mull3 r0,-188(fp),-180(fp)
1104 mull2 r3,-188(fp)
1105 mull3 r3,-192(fp),-184(fp)
1106 mull2 r0,-192(fp)
1107 addl3 -180(fp),-184(fp),r0
1108 bicl3 #0,r0,-180(fp)
1109 cmpl -180(fp),-184(fp)
1110 bgequ noname.89
1111 addl2 #65536,-192(fp)
1112noname.89:
1113 movzwl -178(fp),r0
1114 bicl2 #-65536,r0
1115 addl2 r0,-192(fp)
1116 bicl3 #-65536,-180(fp),r0
1117 ashl #16,r0,-184(fp)
1118 addl3 -184(fp),-188(fp),r0
1119 bicl3 #0,r0,-188(fp)
1120 cmpl -188(fp),-184(fp)
1121 bgequ noname.90
1122 incl -192(fp)
1123noname.90:
1124 movl -188(fp),r1
1125 movl -192(fp),r2
1126 addl2 r1,r8
1127 bicl2 #0,r8
1128 cmpl r8,r1
1129 bgequ noname.91
1130 incl r2
1131noname.91:
1132 addl2 r2,r10
1133 bicl2 #0,r10
1134 cmpl r10,r2
1135 bgequ noname.92
1136 incl r9
1137noname.92:
1138
1139 movzwl 10(r6),r2
1140 bicl3 #-65536,8(r7),r3
1141 movzwl 10(r7),r0
1142 bicl2 #-65536,r0
1143 bicl3 #-65536,8(r6),-204(fp)
1144 bicl3 #-65536,r2,-208(fp)
1145 mull3 r0,-204(fp),-196(fp)
1146 mull2 r3,-204(fp)
1147 mull3 r3,-208(fp),-200(fp)
1148 mull2 r0,-208(fp)
1149 addl3 -196(fp),-200(fp),r0
1150 bicl3 #0,r0,-196(fp)
1151 cmpl -196(fp),-200(fp)
1152 bgequ noname.93
1153 addl2 #65536,-208(fp)
1154noname.93:
1155 movzwl -194(fp),r0
1156 bicl2 #-65536,r0
1157 addl2 r0,-208(fp)
1158 bicl3 #-65536,-196(fp),r0
1159 ashl #16,r0,-200(fp)
1160 addl3 -200(fp),-204(fp),r0
1161 bicl3 #0,r0,-204(fp)
1162 cmpl -204(fp),-200(fp)
1163 bgequ noname.94
1164 incl -208(fp)
1165noname.94:
1166 movl -204(fp),r1
1167 movl -208(fp),r2
1168 addl2 r1,r8
1169 bicl2 #0,r8
1170 cmpl r8,r1
1171 bgequ noname.95
1172 incl r2
1173noname.95:
1174 addl2 r2,r10
1175 bicl2 #0,r10
1176 cmpl r10,r2
1177 bgequ noname.96
1178 incl r9
1179noname.96:
1180
1181 movzwl 6(r6),r2
1182 bicl3 #-65536,12(r7),r3
1183 movzwl 14(r7),r0
1184 bicl2 #-65536,r0
1185 bicl3 #-65536,4(r6),-220(fp)
1186 bicl3 #-65536,r2,-224(fp)
1187 mull3 r0,-220(fp),-212(fp)
1188 mull2 r3,-220(fp)
1189 mull3 r3,-224(fp),-216(fp)
1190 mull2 r0,-224(fp)
1191 addl3 -212(fp),-216(fp),r0
1192 bicl3 #0,r0,-212(fp)
1193 cmpl -212(fp),-216(fp)
1194 bgequ noname.97
1195 addl2 #65536,-224(fp)
1196noname.97:
1197 movzwl -210(fp),r0
1198 bicl2 #-65536,r0
1199 addl2 r0,-224(fp)
1200 bicl3 #-65536,-212(fp),r0
1201 ashl #16,r0,-216(fp)
1202 addl3 -216(fp),-220(fp),r0
1203 bicl3 #0,r0,-220(fp)
1204 cmpl -220(fp),-216(fp)
1205 bgequ noname.98
1206 incl -224(fp)
1207noname.98:
1208 movl -220(fp),r1
1209 movl -224(fp),r2
1210 addl2 r1,r8
1211 bicl2 #0,r8
1212 cmpl r8,r1
1213 bgequ noname.99
1214 incl r2
1215noname.99:
1216 addl2 r2,r10
1217 bicl2 #0,r10
1218 cmpl r10,r2
1219 bgequ noname.100
1220 incl r9
1221noname.100:
1222
1223 movzwl 2(r6),r2
1224 bicl3 #-65536,16(r7),r3
1225 movzwl 18(r7),r0
1226 bicl2 #-65536,r0
1227 bicl3 #-65536,(r6),-236(fp)
1228 bicl3 #-65536,r2,-240(fp)
1229 mull3 r0,-236(fp),-228(fp)
1230 mull2 r3,-236(fp)
1231 mull3 r3,-240(fp),-232(fp)
1232 mull2 r0,-240(fp)
1233 addl3 -228(fp),-232(fp),r0
1234 bicl3 #0,r0,-228(fp)
1235 cmpl -228(fp),-232(fp)
1236 bgequ noname.101
1237 addl2 #65536,-240(fp)
1238noname.101:
1239 movzwl -226(fp),r0
1240 bicl2 #-65536,r0
1241 addl2 r0,-240(fp)
1242 bicl3 #-65536,-228(fp),r0
1243 ashl #16,r0,-232(fp)
1244 addl3 -232(fp),-236(fp),r0
1245 bicl3 #0,r0,-236(fp)
1246 cmpl -236(fp),-232(fp)
1247 bgequ noname.102
1248 incl -240(fp)
1249noname.102:
1250 movl -236(fp),r1
1251 movl -240(fp),r2
1252 addl2 r1,r8
1253 bicl2 #0,r8
1254 cmpl r8,r1
1255 bgequ noname.103
1256 incl r2
1257noname.103:
1258 addl2 r2,r10
1259 bicl2 #0,r10
1260 cmpl r10,r2
1261 bgequ noname.104
1262 incl r9
1263noname.104:
1264
1265 movl r8,16(r11)
1266
1267 clrl r8
1268
1269 movzwl 2(r6),r2
1270 bicl3 #-65536,20(r7),r3
1271 movzwl 22(r7),r0
1272 bicl2 #-65536,r0
1273 bicl3 #-65536,(r6),-252(fp)
1274 bicl3 #-65536,r2,-256(fp)
1275 mull3 r0,-252(fp),-244(fp)
1276 mull2 r3,-252(fp)
1277 mull3 r3,-256(fp),-248(fp)
1278 mull2 r0,-256(fp)
1279 addl3 -244(fp),-248(fp),r0
1280 bicl3 #0,r0,-244(fp)
1281 cmpl -244(fp),-248(fp)
1282 bgequ noname.105
1283 addl2 #65536,-256(fp)
1284noname.105:
1285 movzwl -242(fp),r0
1286 bicl2 #-65536,r0
1287 addl2 r0,-256(fp)
1288 bicl3 #-65536,-244(fp),r0
1289 ashl #16,r0,-248(fp)
1290 addl3 -248(fp),-252(fp),r0
1291 bicl3 #0,r0,-252(fp)
1292 cmpl -252(fp),-248(fp)
1293 bgequ noname.106
1294 incl -256(fp)
1295noname.106:
1296 movl -252(fp),r1
1297 movl -256(fp),r2
1298 addl2 r1,r10
1299 bicl2 #0,r10
1300 cmpl r10,r1
1301 bgequ noname.107
1302 incl r2
1303noname.107:
1304 addl2 r2,r9
1305 bicl2 #0,r9
1306 cmpl r9,r2
1307 bgequ noname.108
1308 incl r8
1309noname.108:
1310
1311 movzwl 6(r6),r2
1312 bicl3 #-65536,16(r7),r3
1313 movzwl 18(r7),r0
1314 bicl2 #-65536,r0
1315 bicl3 #-65536,4(r6),-268(fp)
1316 bicl3 #-65536,r2,-272(fp)
1317 mull3 r0,-268(fp),-260(fp)
1318 mull2 r3,-268(fp)
1319 mull3 r3,-272(fp),-264(fp)
1320 mull2 r0,-272(fp)
1321 addl3 -260(fp),-264(fp),r0
1322 bicl3 #0,r0,-260(fp)
1323 cmpl -260(fp),-264(fp)
1324 bgequ noname.109
1325 addl2 #65536,-272(fp)
1326noname.109:
1327 movzwl -258(fp),r0
1328 bicl2 #-65536,r0
1329 addl2 r0,-272(fp)
1330 bicl3 #-65536,-260(fp),r0
1331 ashl #16,r0,-264(fp)
1332 addl3 -264(fp),-268(fp),r0
1333 bicl3 #0,r0,-268(fp)
1334 cmpl -268(fp),-264(fp)
1335 bgequ noname.110
1336 incl -272(fp)
1337noname.110:
1338 movl -268(fp),r1
1339 movl -272(fp),r2
1340 addl2 r1,r10
1341 bicl2 #0,r10
1342 cmpl r10,r1
1343 bgequ noname.111
1344 incl r2
1345noname.111:
1346 addl2 r2,r9
1347 bicl2 #0,r9
1348 cmpl r9,r2
1349 bgequ noname.112
1350 incl r8
1351noname.112:
1352
1353 movzwl 10(r6),r2
1354 bicl3 #-65536,12(r7),r3
1355 movzwl 14(r7),r0
1356 bicl2 #-65536,r0
1357 bicl3 #-65536,8(r6),-284(fp)
1358 bicl3 #-65536,r2,-288(fp)
1359 mull3 r0,-284(fp),-276(fp)
1360 mull2 r3,-284(fp)
1361 mull3 r3,-288(fp),-280(fp)
1362 mull2 r0,-288(fp)
1363 addl3 -276(fp),-280(fp),r0
1364 bicl3 #0,r0,-276(fp)
1365 cmpl -276(fp),-280(fp)
1366 bgequ noname.113
1367 addl2 #65536,-288(fp)
1368noname.113:
1369 movzwl -274(fp),r0
1370 bicl2 #-65536,r0
1371 addl2 r0,-288(fp)
1372 bicl3 #-65536,-276(fp),r0
1373 ashl #16,r0,-280(fp)
1374 addl3 -280(fp),-284(fp),r0
1375 bicl3 #0,r0,-284(fp)
1376 cmpl -284(fp),-280(fp)
1377 bgequ noname.114
1378 incl -288(fp)
1379noname.114:
1380 movl -284(fp),r1
1381 movl -288(fp),r2
1382 addl2 r1,r10
1383 bicl2 #0,r10
1384 cmpl r10,r1
1385 bgequ noname.115
1386 incl r2
1387noname.115:
1388 addl2 r2,r9
1389 bicl2 #0,r9
1390 cmpl r9,r2
1391 bgequ noname.116
1392 incl r8
1393noname.116:
1394
1395 movzwl 14(r6),r2
1396 bicl3 #-65536,8(r7),r3
1397 movzwl 10(r7),r0
1398 bicl2 #-65536,r0
1399 bicl3 #-65536,12(r6),-300(fp)
1400 bicl3 #-65536,r2,-304(fp)
1401 mull3 r0,-300(fp),-292(fp)
1402 mull2 r3,-300(fp)
1403 mull3 r3,-304(fp),-296(fp)
1404 mull2 r0,-304(fp)
1405 addl3 -292(fp),-296(fp),r0
1406 bicl3 #0,r0,-292(fp)
1407 cmpl -292(fp),-296(fp)
1408 bgequ noname.117
1409 addl2 #65536,-304(fp)
1410noname.117:
1411 movzwl -290(fp),r0
1412 bicl2 #-65536,r0
1413 addl2 r0,-304(fp)
1414 bicl3 #-65536,-292(fp),r0
1415 ashl #16,r0,-296(fp)
1416 addl3 -296(fp),-300(fp),r0
1417 bicl3 #0,r0,-300(fp)
1418 cmpl -300(fp),-296(fp)
1419 bgequ noname.118
1420 incl -304(fp)
1421noname.118:
1422 movl -300(fp),r1
1423 movl -304(fp),r2
1424 addl2 r1,r10
1425 bicl2 #0,r10
1426 cmpl r10,r1
1427 bgequ noname.119
1428 incl r2
1429noname.119:
1430 addl2 r2,r9
1431 bicl2 #0,r9
1432 cmpl r9,r2
1433 bgequ noname.120
1434 incl r8
1435noname.120:
1436
1437 movzwl 18(r6),r2
1438 bicl3 #-65536,4(r7),r3
1439 movzwl 6(r7),r0
1440 bicl2 #-65536,r0
1441 bicl3 #-65536,16(r6),-316(fp)
1442 bicl3 #-65536,r2,-320(fp)
1443 mull3 r0,-316(fp),-308(fp)
1444 mull2 r3,-316(fp)
1445 mull3 r3,-320(fp),-312(fp)
1446 mull2 r0,-320(fp)
1447 addl3 -308(fp),-312(fp),r0
1448 bicl3 #0,r0,-308(fp)
1449 cmpl -308(fp),-312(fp)
1450 bgequ noname.121
1451 addl2 #65536,-320(fp)
1452noname.121:
1453 movzwl -306(fp),r0
1454 bicl2 #-65536,r0
1455 addl2 r0,-320(fp)
1456 bicl3 #-65536,-308(fp),r0
1457 ashl #16,r0,-312(fp)
1458 addl3 -312(fp),-316(fp),r0
1459 bicl3 #0,r0,-316(fp)
1460 cmpl -316(fp),-312(fp)
1461 bgequ noname.122
1462 incl -320(fp)
1463noname.122:
1464 movl -316(fp),r1
1465 movl -320(fp),r2
1466 addl2 r1,r10
1467 bicl2 #0,r10
1468 cmpl r10,r1
1469 bgequ noname.123
1470 incl r2
1471
1472noname.123:
1473 addl2 r2,r9
1474 bicl2 #0,r9
1475 cmpl r9,r2
1476 bgequ noname.124
1477 incl r8
1478noname.124:
1479
1480 movzwl 22(r6),r2
1481 bicl3 #-65536,(r7),r3
1482 movzwl 2(r7),r0
1483 bicl2 #-65536,r0
1484 bicl3 #-65536,20(r6),-332(fp)
1485 bicl3 #-65536,r2,-336(fp)
1486 mull3 r0,-332(fp),-324(fp)
1487 mull2 r3,-332(fp)
1488 mull3 r3,-336(fp),-328(fp)
1489 mull2 r0,-336(fp)
1490 addl3 -324(fp),-328(fp),r0
1491 bicl3 #0,r0,-324(fp)
1492 cmpl -324(fp),-328(fp)
1493 bgequ noname.125
1494 addl2 #65536,-336(fp)
1495noname.125:
1496 movzwl -322(fp),r0
1497 bicl2 #-65536,r0
1498 addl2 r0,-336(fp)
1499 bicl3 #-65536,-324(fp),r0
1500 ashl #16,r0,-328(fp)
1501 addl3 -328(fp),-332(fp),r0
1502 bicl3 #0,r0,-332(fp)
1503 cmpl -332(fp),-328(fp)
1504 bgequ noname.126
1505 incl -336(fp)
1506noname.126:
1507 movl -332(fp),r1
1508 movl -336(fp),r2
1509 addl2 r1,r10
1510 bicl2 #0,r10
1511 cmpl r10,r1
1512 bgequ noname.127
1513 incl r2
1514noname.127:
1515 addl2 r2,r9
1516 bicl2 #0,r9
1517 cmpl r9,r2
1518 bgequ noname.128
1519 incl r8
1520noname.128:
1521
1522 movl r10,20(r11)
1523
1524 clrl r10
1525
1526 movzwl 26(r6),r2
1527 bicl3 #-65536,(r7),r3
1528 movzwl 2(r7),r0
1529 bicl2 #-65536,r0
1530 bicl3 #-65536,24(r6),-348(fp)
1531 bicl3 #-65536,r2,-352(fp)
1532 mull3 r0,-348(fp),-340(fp)
1533 mull2 r3,-348(fp)
1534 mull3 r3,-352(fp),-344(fp)
1535 mull2 r0,-352(fp)
1536 addl3 -340(fp),-344(fp),r0
1537 bicl3 #0,r0,-340(fp)
1538 cmpl -340(fp),-344(fp)
1539 bgequ noname.129
1540 addl2 #65536,-352(fp)
1541noname.129:
1542 movzwl -338(fp),r0
1543 bicl2 #-65536,r0
1544 addl2 r0,-352(fp)
1545 bicl3 #-65536,-340(fp),r0
1546 ashl #16,r0,-344(fp)
1547 addl3 -344(fp),-348(fp),r0
1548 bicl3 #0,r0,-348(fp)
1549 cmpl -348(fp),-344(fp)
1550 bgequ noname.130
1551 incl -352(fp)
1552noname.130:
1553 movl -348(fp),r1
1554 movl -352(fp),r2
1555 addl2 r1,r9
1556 bicl2 #0,r9
1557 cmpl r9,r1
1558 bgequ noname.131
1559 incl r2
1560noname.131:
1561 addl2 r2,r8
1562 bicl2 #0,r8
1563 cmpl r8,r2
1564 bgequ noname.132
1565 incl r10
1566noname.132:
1567
1568 movzwl 22(r6),r2
1569 bicl3 #-65536,4(r7),r3
1570 movzwl 6(r7),r0
1571 bicl2 #-65536,r0
1572 bicl3 #-65536,20(r6),-364(fp)
1573 bicl3 #-65536,r2,-368(fp)
1574 mull3 r0,-364(fp),-356(fp)
1575 mull2 r3,-364(fp)
1576 mull3 r3,-368(fp),-360(fp)
1577 mull2 r0,-368(fp)
1578 addl3 -356(fp),-360(fp),r0
1579 bicl3 #0,r0,-356(fp)
1580 cmpl -356(fp),-360(fp)
1581 bgequ noname.133
1582 addl2 #65536,-368(fp)
1583noname.133:
1584 movzwl -354(fp),r0
1585 bicl2 #-65536,r0
1586 addl2 r0,-368(fp)
1587 bicl3 #-65536,-356(fp),r0
1588 ashl #16,r0,-360(fp)
1589 addl3 -360(fp),-364(fp),r0
1590 bicl3 #0,r0,-364(fp)
1591 cmpl -364(fp),-360(fp)
1592 bgequ noname.134
1593 incl -368(fp)
1594noname.134:
1595 movl -364(fp),r1
1596 movl -368(fp),r2
1597 addl2 r1,r9
1598 bicl2 #0,r9
1599 cmpl r9,r1
1600 bgequ noname.135
1601 incl r2
1602noname.135:
1603 addl2 r2,r8
1604 bicl2 #0,r8
1605 cmpl r8,r2
1606 bgequ noname.136
1607 incl r10
1608noname.136:
1609
1610 movzwl 18(r6),r2
1611 bicl3 #-65536,8(r7),r3
1612 movzwl 10(r7),r0
1613 bicl2 #-65536,r0
1614 bicl3 #-65536,16(r6),-380(fp)
1615 bicl3 #-65536,r2,-384(fp)
1616 mull3 r0,-380(fp),-372(fp)
1617 mull2 r3,-380(fp)
1618 mull3 r3,-384(fp),-376(fp)
1619 mull2 r0,-384(fp)
1620 addl3 -372(fp),-376(fp),r0
1621 bicl3 #0,r0,-372(fp)
1622 cmpl -372(fp),-376(fp)
1623 bgequ noname.137
1624 addl2 #65536,-384(fp)
1625noname.137:
1626 movzwl -370(fp),r0
1627 bicl2 #-65536,r0
1628 addl2 r0,-384(fp)
1629 bicl3 #-65536,-372(fp),r0
1630 ashl #16,r0,-376(fp)
1631 addl3 -376(fp),-380(fp),r0
1632 bicl3 #0,r0,-380(fp)
1633 cmpl -380(fp),-376(fp)
1634 bgequ noname.138
1635 incl -384(fp)
1636noname.138:
1637 movl -380(fp),r1
1638 movl -384(fp),r2
1639 addl2 r1,r9
1640 bicl2 #0,r9
1641 cmpl r9,r1
1642 bgequ noname.139
1643 incl r2
1644noname.139:
1645 addl2 r2,r8
1646 bicl2 #0,r8
1647 cmpl r8,r2
1648 bgequ noname.140
1649 incl r10
1650noname.140:
1651
1652 movzwl 14(r6),r2
1653 bicl3 #-65536,12(r7),r3
1654 movzwl 14(r7),r0
1655 bicl2 #-65536,r0
1656 bicl3 #-65536,12(r6),-396(fp)
1657 bicl3 #-65536,r2,-400(fp)
1658 mull3 r0,-396(fp),-388(fp)
1659 mull2 r3,-396(fp)
1660 mull3 r3,-400(fp),-392(fp)
1661 mull2 r0,-400(fp)
1662 addl3 -388(fp),-392(fp),r0
1663 bicl3 #0,r0,-388(fp)
1664 cmpl -388(fp),-392(fp)
1665 bgequ noname.141
1666 addl2 #65536,-400(fp)
1667noname.141:
1668 movzwl -386(fp),r0
1669 bicl2 #-65536,r0
1670 addl2 r0,-400(fp)
1671 bicl3 #-65536,-388(fp),r0
1672 ashl #16,r0,-392(fp)
1673 addl3 -392(fp),-396(fp),r0
1674 bicl3 #0,r0,-396(fp)
1675 cmpl -396(fp),-392(fp)
1676 bgequ noname.142
1677 incl -400(fp)
1678noname.142:
1679 movl -396(fp),r1
1680 movl -400(fp),r2
1681 addl2 r1,r9
1682 bicl2 #0,r9
1683 cmpl r9,r1
1684 bgequ noname.143
1685 incl r2
1686noname.143:
1687 addl2 r2,r8
1688 bicl2 #0,r8
1689 cmpl r8,r2
1690 bgequ noname.144
1691 incl r10
1692noname.144:
1693
1694 movzwl 10(r6),r2
1695 bicl3 #-65536,16(r7),r3
1696 movzwl 18(r7),r0
1697 bicl2 #-65536,r0
1698 bicl3 #-65536,8(r6),-412(fp)
1699 bicl3 #-65536,r2,-416(fp)
1700 mull3 r0,-412(fp),-404(fp)
1701 mull2 r3,-412(fp)
1702 mull3 r3,-416(fp),-408(fp)
1703 mull2 r0,-416(fp)
1704 addl3 -404(fp),-408(fp),r0
1705 bicl3 #0,r0,-404(fp)
1706 cmpl -404(fp),-408(fp)
1707 bgequ noname.145
1708 addl2 #65536,-416(fp)
1709noname.145:
1710 movzwl -402(fp),r0
1711 bicl2 #-65536,r0
1712 addl2 r0,-416(fp)
1713 bicl3 #-65536,-404(fp),r0
1714 ashl #16,r0,-408(fp)
1715 addl3 -408(fp),-412(fp),r0
1716 bicl3 #0,r0,-412(fp)
1717 cmpl -412(fp),-408(fp)
1718 bgequ noname.146
1719 incl -416(fp)
1720noname.146:
1721 movl -412(fp),r1
1722 movl -416(fp),r2
1723 addl2 r1,r9
1724 bicl2 #0,r9
1725 cmpl r9,r1
1726 bgequ noname.147
1727 incl r2
1728noname.147:
1729 addl2 r2,r8
1730 bicl2 #0,r8
1731 cmpl r8,r2
1732 bgequ noname.148
1733 incl r10
1734noname.148:
1735
1736 movzwl 6(r6),r2
1737 bicl3 #-65536,20(r7),r3
1738 movzwl 22(r7),r0
1739 bicl2 #-65536,r0
1740 bicl3 #-65536,4(r6),-428(fp)
1741 bicl3 #-65536,r2,-432(fp)
1742 mull3 r0,-428(fp),-420(fp)
1743 mull2 r3,-428(fp)
1744 mull3 r3,-432(fp),-424(fp)
1745 mull2 r0,-432(fp)
1746 addl3 -420(fp),-424(fp),r0
1747 bicl3 #0,r0,-420(fp)
1748 cmpl -420(fp),-424(fp)
1749 bgequ noname.149
1750 addl2 #65536,-432(fp)
1751noname.149:
1752 movzwl -418(fp),r0
1753 bicl2 #-65536,r0
1754 addl2 r0,-432(fp)
1755 bicl3 #-65536,-420(fp),r0
1756 ashl #16,r0,-424(fp)
1757 addl3 -424(fp),-428(fp),r0
1758 bicl3 #0,r0,-428(fp)
1759 cmpl -428(fp),-424(fp)
1760 bgequ noname.150
1761 incl -432(fp)
1762noname.150:
1763 movl -428(fp),r1
1764 movl -432(fp),r2
1765 addl2 r1,r9
1766 bicl2 #0,r9
1767 cmpl r9,r1
1768 bgequ noname.151
1769 incl r2
1770noname.151:
1771 addl2 r2,r8
1772 bicl2 #0,r8
1773 cmpl r8,r2
1774 bgequ noname.152
1775 incl r10
1776noname.152:
1777
1778 movzwl 2(r6),r2
1779 bicl3 #-65536,24(r7),r3
1780 movzwl 26(r7),r0
1781 bicl2 #-65536,r0
1782 bicl3 #-65536,(r6),-444(fp)
1783 bicl3 #-65536,r2,-448(fp)
1784 mull3 r0,-444(fp),-436(fp)
1785 mull2 r3,-444(fp)
1786 mull3 r3,-448(fp),-440(fp)
1787 mull2 r0,-448(fp)
1788 addl3 -436(fp),-440(fp),r0
1789 bicl3 #0,r0,-436(fp)
1790 cmpl -436(fp),-440(fp)
1791 bgequ noname.153
1792 addl2 #65536,-448(fp)
1793noname.153:
1794 movzwl -434(fp),r0
1795 bicl2 #-65536,r0
1796 addl2 r0,-448(fp)
1797 bicl3 #-65536,-436(fp),r0
1798 ashl #16,r0,-440(fp)
1799 addl3 -440(fp),-444(fp),r0
1800 bicl3 #0,r0,-444(fp)
1801 cmpl -444(fp),-440(fp)
1802 bgequ noname.154
1803 incl -448(fp)
1804noname.154:
1805 movl -444(fp),r1
1806 movl -448(fp),r2
1807 addl2 r1,r9
1808 bicl2 #0,r9
1809 cmpl r9,r1
1810 bgequ noname.155
1811 incl r2
1812noname.155:
1813 addl2 r2,r8
1814 bicl2 #0,r8
1815 cmpl r8,r2
1816 bgequ noname.156
1817 incl r10
1818noname.156:
1819
1820 movl r9,24(r11)
1821
1822 clrl r9
1823
1824 movzwl 2(r6),r2
1825 bicl3 #-65536,28(r7),r3
1826 movzwl 30(r7),r0
1827 bicl2 #-65536,r0
1828 bicl3 #-65536,(r6),-460(fp)
1829 bicl3 #-65536,r2,-464(fp)
1830 mull3 r0,-460(fp),-452(fp)
1831 mull2 r3,-460(fp)
1832 mull3 r3,-464(fp),-456(fp)
1833 mull2 r0,-464(fp)
1834 addl3 -452(fp),-456(fp),r0
1835 bicl3 #0,r0,-452(fp)
1836 cmpl -452(fp),-456(fp)
1837 bgequ noname.157
1838 addl2 #65536,-464(fp)
1839noname.157:
1840 movzwl -450(fp),r0
1841 bicl2 #-65536,r0
1842 addl2 r0,-464(fp)
1843 bicl3 #-65536,-452(fp),r0
1844 ashl #16,r0,-456(fp)
1845 addl3 -456(fp),-460(fp),r0
1846 bicl3 #0,r0,-460(fp)
1847 cmpl -460(fp),-456(fp)
1848 bgequ noname.158
1849 incl -464(fp)
1850noname.158:
1851 movl -460(fp),r1
1852 movl -464(fp),r2
1853 addl2 r1,r8
1854 bicl2 #0,r8
1855 cmpl r8,r1
1856 bgequ noname.159
1857 incl r2
1858noname.159:
1859 addl2 r2,r10
1860 bicl2 #0,r10
1861 cmpl r10,r2
1862 bgequ noname.160
1863 incl r9
1864noname.160:
1865
1866 movzwl 6(r6),r2
1867 bicl3 #-65536,24(r7),r3
1868 movzwl 26(r7),r0
1869 bicl2 #-65536,r0
1870 bicl3 #-65536,4(r6),-476(fp)
1871 bicl3 #-65536,r2,-480(fp)
1872 mull3 r0,-476(fp),-468(fp)
1873 mull2 r3,-476(fp)
1874 mull3 r3,-480(fp),-472(fp)
1875 mull2 r0,-480(fp)
1876 addl3 -468(fp),-472(fp),r0
1877 bicl3 #0,r0,-468(fp)
1878 cmpl -468(fp),-472(fp)
1879 bgequ noname.161
1880 addl2 #65536,-480(fp)
1881noname.161:
1882 movzwl -466(fp),r0
1883 bicl2 #-65536,r0
1884 addl2 r0,-480(fp)
1885 bicl3 #-65536,-468(fp),r0
1886 ashl #16,r0,-472(fp)
1887 addl3 -472(fp),-476(fp),r0
1888 bicl3 #0,r0,-476(fp)
1889 cmpl -476(fp),-472(fp)
1890 bgequ noname.162
1891 incl -480(fp)
1892noname.162:
1893 movl -476(fp),r1
1894 movl -480(fp),r2
1895 addl2 r1,r8
1896 bicl2 #0,r8
1897 cmpl r8,r1
1898 bgequ noname.163
1899 incl r2
1900noname.163:
1901 addl2 r2,r10
1902 bicl2 #0,r10
1903 cmpl r10,r2
1904 bgequ noname.164
1905 incl r9
1906noname.164:
1907
1908 movzwl 10(r6),r2
1909 bicl3 #-65536,20(r7),r3
1910 movzwl 22(r7),r0
1911 bicl2 #-65536,r0
1912 bicl3 #-65536,8(r6),-492(fp)
1913 bicl3 #-65536,r2,-496(fp)
1914 mull3 r0,-492(fp),-484(fp)
1915 mull2 r3,-492(fp)
1916 mull3 r3,-496(fp),-488(fp)
1917 mull2 r0,-496(fp)
1918 addl3 -484(fp),-488(fp),r0
1919 bicl3 #0,r0,-484(fp)
1920 cmpl -484(fp),-488(fp)
1921 bgequ noname.165
1922 addl2 #65536,-496(fp)
1923noname.165:
1924 movzwl -482(fp),r0
1925 bicl2 #-65536,r0
1926 addl2 r0,-496(fp)
1927 bicl3 #-65536,-484(fp),r0
1928 ashl #16,r0,-488(fp)
1929 addl3 -488(fp),-492(fp),r0
1930 bicl3 #0,r0,-492(fp)
1931 cmpl -492(fp),-488(fp)
1932 bgequ noname.166
1933 incl -496(fp)
1934noname.166:
1935 movl -492(fp),r1
1936 movl -496(fp),r2
1937 addl2 r1,r8
1938 bicl2 #0,r8
1939 cmpl r8,r1
1940 bgequ noname.167
1941 incl r2
1942noname.167:
1943 addl2 r2,r10
1944 bicl2 #0,r10
1945 cmpl r10,r2
1946 bgequ noname.168
1947 incl r9
1948noname.168:
1949
1950 movzwl 14(r6),r2
1951 bicl3 #-65536,16(r7),r3
1952 movzwl 18(r7),r0
1953 bicl2 #-65536,r0
1954 bicl3 #-65536,12(r6),-508(fp)
1955 bicl3 #-65536,r2,-512(fp)
1956 mull3 r0,-508(fp),-500(fp)
1957 mull2 r3,-508(fp)
1958 mull3 r3,-512(fp),-504(fp)
1959 mull2 r0,-512(fp)
1960 addl3 -500(fp),-504(fp),r0
1961 bicl3 #0,r0,-500(fp)
1962 cmpl -500(fp),-504(fp)
1963 bgequ noname.169
1964 addl2 #65536,-512(fp)
1965noname.169:
1966 movzwl -498(fp),r0
1967 bicl2 #-65536,r0
1968 addl2 r0,-512(fp)
1969 bicl3 #-65536,-500(fp),r0
1970 ashl #16,r0,-504(fp)
1971 addl3 -504(fp),-508(fp),r0
1972 bicl3 #0,r0,-508(fp)
1973 cmpl -508(fp),-504(fp)
1974 bgequ noname.170
1975 incl -512(fp)
1976noname.170:
1977 movl -508(fp),r1
1978 movl -512(fp),r2
1979 addl2 r1,r8
1980 bicl2 #0,r8
1981 cmpl r8,r1
1982 bgequ noname.171
1983 incl r2
1984noname.171:
1985 addl2 r2,r10
1986 bicl2 #0,r10
1987 cmpl r10,r2
1988 bgequ noname.172
1989 incl r9
1990noname.172:
1991
1992 movzwl 18(r6),r2
1993 bicl3 #-65536,12(r7),r3
1994 movzwl 14(r7),r0
1995 bicl2 #-65536,r0
1996 bicl3 #-65536,16(r6),-524(fp)
1997 bicl3 #-65536,r2,-528(fp)
1998 mull3 r0,-524(fp),-516(fp)
1999 mull2 r3,-524(fp)
2000 mull3 r3,-528(fp),-520(fp)
2001 mull2 r0,-528(fp)
2002 addl3 -516(fp),-520(fp),r0
2003 bicl3 #0,r0,-516(fp)
2004 cmpl -516(fp),-520(fp)
2005 bgequ noname.173
2006 addl2 #65536,-528(fp)
2007noname.173:
2008 movzwl -514(fp),r0
2009 bicl2 #-65536,r0
2010 addl2 r0,-528(fp)
2011 bicl3 #-65536,-516(fp),r0
2012 ashl #16,r0,-520(fp)
2013 addl3 -520(fp),-524(fp),r0
2014 bicl3 #0,r0,-524(fp)
2015 cmpl -524(fp),-520(fp)
2016 bgequ noname.174
2017 incl -528(fp)
2018noname.174:
2019 movl -524(fp),r1
2020 movl -528(fp),r2
2021 addl2 r1,r8
2022 bicl2 #0,r8
2023 cmpl r8,r1
2024 bgequ noname.175
2025 incl r2
2026noname.175:
2027 addl2 r2,r10
2028 bicl2 #0,r10
2029 cmpl r10,r2
2030 bgequ noname.176
2031 incl r9
2032noname.176:
2033
2034 movzwl 22(r6),r2
2035 bicl3 #-65536,8(r7),r3
2036 movzwl 10(r7),r0
2037 bicl2 #-65536,r0
2038 bicl3 #-65536,20(r6),-540(fp)
2039 bicl3 #-65536,r2,-544(fp)
2040 mull3 r0,-540(fp),-532(fp)
2041 mull2 r3,-540(fp)
2042 mull3 r3,-544(fp),-536(fp)
2043 mull2 r0,-544(fp)
2044 addl3 -532(fp),-536(fp),r0
2045 bicl3 #0,r0,-532(fp)
2046 cmpl -532(fp),-536(fp)
2047 bgequ noname.177
2048 addl2 #65536,-544(fp)
2049noname.177:
2050 movzwl -530(fp),r0
2051 bicl2 #-65536,r0
2052 addl2 r0,-544(fp)
2053 bicl3 #-65536,-532(fp),r0
2054 ashl #16,r0,-536(fp)
2055 addl3 -536(fp),-540(fp),r0
2056 bicl3 #0,r0,-540(fp)
2057 cmpl -540(fp),-536(fp)
2058 bgequ noname.178
2059 incl -544(fp)
2060noname.178:
2061 movl -540(fp),r1
2062 movl -544(fp),r2
2063 addl2 r1,r8
2064 bicl2 #0,r8
2065 cmpl r8,r1
2066 bgequ noname.179
2067 incl r2
2068noname.179:
2069 addl2 r2,r10
2070 bicl2 #0,r10
2071 cmpl r10,r2
2072 bgequ noname.180
2073 incl r9
2074noname.180:
2075
2076 movzwl 26(r6),r2
2077 bicl3 #-65536,4(r7),r3
2078 movzwl 6(r7),r0
2079 bicl2 #-65536,r0
2080 bicl3 #-65536,24(r6),-556(fp)
2081 bicl3 #-65536,r2,-560(fp)
2082 mull3 r0,-556(fp),-548(fp)
2083 mull2 r3,-556(fp)
2084 mull3 r3,-560(fp),-552(fp)
2085 mull2 r0,-560(fp)
2086 addl3 -548(fp),-552(fp),r0
2087 bicl3 #0,r0,-548(fp)
2088 cmpl -548(fp),-552(fp)
2089 bgequ noname.181
2090 addl2 #65536,-560(fp)
2091noname.181:
2092 movzwl -546(fp),r0
2093 bicl2 #-65536,r0
2094 addl2 r0,-560(fp)
2095 bicl3 #-65536,-548(fp),r0
2096 ashl #16,r0,-552(fp)
2097 addl3 -552(fp),-556(fp),r0
2098 bicl3 #0,r0,-556(fp)
2099 cmpl -556(fp),-552(fp)
2100 bgequ noname.182
2101 incl -560(fp)
2102noname.182:
2103 movl -556(fp),r1
2104 movl -560(fp),r2
2105 addl2 r1,r8
2106 bicl2 #0,r8
2107 cmpl r8,r1
2108 bgequ noname.183
2109 incl r2
2110noname.183:
2111 addl2 r2,r10
2112 bicl2 #0,r10
2113 cmpl r10,r2
2114 bgequ noname.184
2115 incl r9
2116noname.184:
2117
2118 movzwl 30(r6),r2
2119 bicl3 #-65536,(r7),r3
2120 movzwl 2(r7),r0
2121 bicl2 #-65536,r0
2122 bicl3 #-65536,28(r6),-572(fp)
2123 bicl3 #-65536,r2,-576(fp)
2124 mull3 r0,-572(fp),-564(fp)
2125 mull2 r3,-572(fp)
2126 mull3 r3,-576(fp),-568(fp)
2127 mull2 r0,-576(fp)
2128 addl3 -564(fp),-568(fp),r0
2129 bicl3 #0,r0,-564(fp)
2130 cmpl -564(fp),-568(fp)
2131 bgequ noname.185
2132 addl2 #65536,-576(fp)
2133noname.185:
2134 movzwl -562(fp),r0
2135 bicl2 #-65536,r0
2136 addl2 r0,-576(fp)
2137 bicl3 #-65536,-564(fp),r0
2138 ashl #16,r0,-568(fp)
2139 addl3 -568(fp),-572(fp),r0
2140 bicl3 #0,r0,-572(fp)
2141 cmpl -572(fp),-568(fp)
2142 bgequ noname.186
2143 incl -576(fp)
2144noname.186:
2145 movl -572(fp),r1
2146 movl -576(fp),r2
2147 addl2 r1,r8
2148 bicl2 #0,r8
2149 cmpl r8,r1
2150 bgequ noname.187
2151 incl r2
2152noname.187:
2153 addl2 r2,r10
2154 bicl2 #0,r10
2155 cmpl r10,r2
2156 bgequ noname.188
2157 incl r9
2158noname.188:
2159
2160 movl r8,28(r11)
2161
2162 clrl r8
2163
2164 movzwl 30(r6),r2
2165 bicl3 #-65536,4(r7),r3
2166 movzwl 6(r7),r0
2167 bicl2 #-65536,r0
2168 bicl3 #-65536,28(r6),-588(fp)
2169 bicl3 #-65536,r2,-592(fp)
2170 mull3 r0,-588(fp),-580(fp)
2171 mull2 r3,-588(fp)
2172 mull3 r3,-592(fp),-584(fp)
2173 mull2 r0,-592(fp)
2174 addl3 -580(fp),-584(fp),r0
2175 bicl3 #0,r0,-580(fp)
2176 cmpl -580(fp),-584(fp)
2177 bgequ noname.189
2178 addl2 #65536,-592(fp)
2179noname.189:
2180 movzwl -578(fp),r0
2181 bicl2 #-65536,r0
2182 addl2 r0,-592(fp)
2183 bicl3 #-65536,-580(fp),r0
2184 ashl #16,r0,-584(fp)
2185 addl3 -584(fp),-588(fp),r0
2186 bicl3 #0,r0,-588(fp)
2187 cmpl -588(fp),-584(fp)
2188 bgequ noname.190
2189 incl -592(fp)
2190noname.190:
2191 movl -588(fp),r1
2192 movl -592(fp),r2
2193 addl2 r1,r10
2194 bicl2 #0,r10
2195 cmpl r10,r1
2196 bgequ noname.191
2197 incl r2
2198noname.191:
2199 addl2 r2,r9
2200 bicl2 #0,r9
2201 cmpl r9,r2
2202 bgequ noname.192
2203 incl r8
2204noname.192:
2205
2206 movzwl 26(r6),r2
2207 bicl3 #-65536,8(r7),r3
2208 movzwl 10(r7),r0
2209 bicl2 #-65536,r0
2210 bicl3 #-65536,24(r6),-604(fp)
2211 bicl3 #-65536,r2,-608(fp)
2212 mull3 r0,-604(fp),-596(fp)
2213 mull2 r3,-604(fp)
2214 mull3 r3,-608(fp),-600(fp)
2215 mull2 r0,-608(fp)
2216 addl3 -596(fp),-600(fp),r0
2217 bicl3 #0,r0,-596(fp)
2218 cmpl -596(fp),-600(fp)
2219 bgequ noname.193
2220 addl2 #65536,-608(fp)
2221noname.193:
2222 movzwl -594(fp),r0
2223 bicl2 #-65536,r0
2224 addl2 r0,-608(fp)
2225 bicl3 #-65536,-596(fp),r0
2226 ashl #16,r0,-600(fp)
2227 addl3 -600(fp),-604(fp),r0
2228 bicl3 #0,r0,-604(fp)
2229 cmpl -604(fp),-600(fp)
2230 bgequ noname.194
2231 incl -608(fp)
2232noname.194:
2233 movl -604(fp),r1
2234 movl -608(fp),r2
2235 addl2 r1,r10
2236 bicl2 #0,r10
2237 cmpl r10,r1
2238 bgequ noname.195
2239 incl r2
2240noname.195:
2241 addl2 r2,r9
2242 bicl2 #0,r9
2243 cmpl r9,r2
2244 bgequ noname.196
2245 incl r8
2246noname.196:
2247
2248 movzwl 22(r6),r2
2249 bicl3 #-65536,12(r7),r3
2250 movzwl 14(r7),r0
2251 bicl2 #-65536,r0
2252 bicl3 #-65536,20(r6),-620(fp)
2253 bicl3 #-65536,r2,-624(fp)
2254 mull3 r0,-620(fp),-612(fp)
2255 mull2 r3,-620(fp)
2256 mull3 r3,-624(fp),-616(fp)
2257 mull2 r0,-624(fp)
2258 addl3 -612(fp),-616(fp),r0
2259 bicl3 #0,r0,-612(fp)
2260 cmpl -612(fp),-616(fp)
2261 bgequ noname.197
2262 addl2 #65536,-624(fp)
2263noname.197:
2264 movzwl -610(fp),r0
2265 bicl2 #-65536,r0
2266 addl2 r0,-624(fp)
2267 bicl3 #-65536,-612(fp),r0
2268 ashl #16,r0,-616(fp)
2269 addl3 -616(fp),-620(fp),r0
2270 bicl3 #0,r0,-620(fp)
2271 cmpl -620(fp),-616(fp)
2272 bgequ noname.198
2273 incl -624(fp)
2274noname.198:
2275 movl -620(fp),r1
2276 movl -624(fp),r2
2277 addl2 r1,r10
2278 bicl2 #0,r10
2279 cmpl r10,r1
2280 bgequ noname.199
2281 incl r2
2282noname.199:
2283 addl2 r2,r9
2284 bicl2 #0,r9
2285 cmpl r9,r2
2286 bgequ noname.200
2287 incl r8
2288noname.200:
2289
2290 movzwl 18(r6),r2
2291 bicl3 #-65536,16(r7),r3
2292 movzwl 18(r7),r0
2293 bicl2 #-65536,r0
2294 bicl3 #-65536,16(r6),-636(fp)
2295 bicl3 #-65536,r2,-640(fp)
2296 mull3 r0,-636(fp),-628(fp)
2297 mull2 r3,-636(fp)
2298 mull3 r3,-640(fp),-632(fp)
2299 mull2 r0,-640(fp)
2300 addl3 -628(fp),-632(fp),r0
2301 bicl3 #0,r0,-628(fp)
2302 cmpl -628(fp),-632(fp)
2303 bgequ noname.201
2304 addl2 #65536,-640(fp)
2305noname.201:
2306 movzwl -626(fp),r0
2307 bicl2 #-65536,r0
2308 addl2 r0,-640(fp)
2309 bicl3 #-65536,-628(fp),r0
2310 ashl #16,r0,-632(fp)
2311 addl3 -632(fp),-636(fp),r0
2312 bicl3 #0,r0,-636(fp)
2313 cmpl -636(fp),-632(fp)
2314 bgequ noname.202
2315 incl -640(fp)
2316noname.202:
2317 movl -636(fp),r1
2318 movl -640(fp),r2
2319 addl2 r1,r10
2320 bicl2 #0,r10
2321 cmpl r10,r1
2322 bgequ noname.203
2323 incl r2
2324noname.203:
2325 addl2 r2,r9
2326 bicl2 #0,r9
2327 cmpl r9,r2
2328 bgequ noname.204
2329 incl r8
2330noname.204:
2331
2332 movzwl 14(r6),r2
2333 bicl3 #-65536,20(r7),r3
2334 movzwl 22(r7),r0
2335 bicl2 #-65536,r0
2336 bicl3 #-65536,12(r6),-652(fp)
2337 bicl3 #-65536,r2,-656(fp)
2338 mull3 r0,-652(fp),-644(fp)
2339 mull2 r3,-652(fp)
2340 mull3 r3,-656(fp),-648(fp)
2341 mull2 r0,-656(fp)
2342 addl3 -644(fp),-648(fp),r0
2343 bicl3 #0,r0,-644(fp)
2344 cmpl -644(fp),-648(fp)
2345 bgequ noname.205
2346 addl2 #65536,-656(fp)
2347noname.205:
2348 movzwl -642(fp),r0
2349 bicl2 #-65536,r0
2350 addl2 r0,-656(fp)
2351 bicl3 #-65536,-644(fp),r0
2352 ashl #16,r0,-648(fp)
2353 addl3 -648(fp),-652(fp),r0
2354 bicl3 #0,r0,-652(fp)
2355 cmpl -652(fp),-648(fp)
2356 bgequ noname.206
2357 incl -656(fp)
2358noname.206:
2359 movl -652(fp),r1
2360 movl -656(fp),r2
2361 addl2 r1,r10
2362 bicl2 #0,r10
2363 cmpl r10,r1
2364 bgequ noname.207
2365 incl r2
2366noname.207:
2367 addl2 r2,r9
2368 bicl2 #0,r9
2369 cmpl r9,r2
2370 bgequ noname.208
2371 incl r8
2372noname.208:
2373
2374 movzwl 10(r6),r2
2375 bicl3 #-65536,24(r7),r3
2376 movzwl 26(r7),r0
2377 bicl2 #-65536,r0
2378 bicl3 #-65536,8(r6),-668(fp)
2379 bicl3 #-65536,r2,-672(fp)
2380 mull3 r0,-668(fp),-660(fp)
2381 mull2 r3,-668(fp)
2382 mull3 r3,-672(fp),-664(fp)
2383 mull2 r0,-672(fp)
2384 addl3 -660(fp),-664(fp),r0
2385 bicl3 #0,r0,-660(fp)
2386 cmpl -660(fp),-664(fp)
2387 bgequ noname.209
2388 addl2 #65536,-672(fp)
2389noname.209:
2390 movzwl -658(fp),r0
2391 bicl2 #-65536,r0
2392 addl2 r0,-672(fp)
2393 bicl3 #-65536,-660(fp),r0
2394 ashl #16,r0,-664(fp)
2395 addl3 -664(fp),-668(fp),r0
2396 bicl3 #0,r0,-668(fp)
2397 cmpl -668(fp),-664(fp)
2398 bgequ noname.210
2399 incl -672(fp)
2400noname.210:
2401 movl -668(fp),r1
2402 movl -672(fp),r2
2403 addl2 r1,r10
2404 bicl2 #0,r10
2405 cmpl r10,r1
2406 bgequ noname.211
2407 incl r2
2408noname.211:
2409 addl2 r2,r9
2410 bicl2 #0,r9
2411 cmpl r9,r2
2412 bgequ noname.212
2413 incl r8
2414noname.212:
2415
2416 movzwl 6(r6),r2
2417 bicl3 #-65536,28(r7),r3
2418 movzwl 30(r7),r0
2419 bicl2 #-65536,r0
2420 bicl3 #-65536,4(r6),-684(fp)
2421 bicl3 #-65536,r2,-688(fp)
2422 mull3 r0,-684(fp),-676(fp)
2423 mull2 r3,-684(fp)
2424 mull3 r3,-688(fp),-680(fp)
2425 mull2 r0,-688(fp)
2426 addl3 -676(fp),-680(fp),r0
2427 bicl3 #0,r0,-676(fp)
2428 cmpl -676(fp),-680(fp)
2429 bgequ noname.213
2430 addl2 #65536,-688(fp)
2431noname.213:
2432 movzwl -674(fp),r0
2433 bicl2 #-65536,r0
2434 addl2 r0,-688(fp)
2435 bicl3 #-65536,-676(fp),r0
2436 ashl #16,r0,-680(fp)
2437 addl3 -680(fp),-684(fp),r0
2438 bicl3 #0,r0,-684(fp)
2439 cmpl -684(fp),-680(fp)
2440 bgequ noname.214
2441 incl -688(fp)
2442noname.214:
2443 movl -684(fp),r1
2444 movl -688(fp),r2
2445 addl2 r1,r10
2446 bicl2 #0,r10
2447 cmpl r10,r1
2448 bgequ noname.215
2449 incl r2
2450noname.215:
2451 addl2 r2,r9
2452 bicl2 #0,r9
2453 cmpl r9,r2
2454 bgequ noname.216
2455 incl r8
2456noname.216:
2457
2458 movl r10,32(r11)
2459
2460 clrl r10
2461
2462 movzwl 10(r6),r2
2463 bicl3 #-65536,28(r7),r3
2464 movzwl 30(r7),r0
2465 bicl2 #-65536,r0
2466 bicl3 #-65536,8(r6),-700(fp)
2467 bicl3 #-65536,r2,-704(fp)
2468 mull3 r0,-700(fp),-692(fp)
2469 mull2 r3,-700(fp)
2470 mull3 r3,-704(fp),-696(fp)
2471 mull2 r0,-704(fp)
2472 addl3 -692(fp),-696(fp),r0
2473 bicl3 #0,r0,-692(fp)
2474 cmpl -692(fp),-696(fp)
2475 bgequ noname.217
2476 addl2 #65536,-704(fp)
2477noname.217:
2478 movzwl -690(fp),r0
2479 bicl2 #-65536,r0
2480 addl2 r0,-704(fp)
2481 bicl3 #-65536,-692(fp),r0
2482 ashl #16,r0,-696(fp)
2483 addl3 -696(fp),-700(fp),r0
2484 bicl3 #0,r0,-700(fp)
2485 cmpl -700(fp),-696(fp)
2486 bgequ noname.218
2487 incl -704(fp)
2488noname.218:
2489 movl -700(fp),r1
2490 movl -704(fp),r2
2491 addl2 r1,r9
2492 bicl2 #0,r9
2493 cmpl r9,r1
2494 bgequ noname.219
2495 incl r2
2496noname.219:
2497 addl2 r2,r8
2498 bicl2 #0,r8
2499 cmpl r8,r2
2500 bgequ noname.220
2501 incl r10
2502noname.220:
2503
2504 movzwl 14(r6),r2
2505 bicl3 #-65536,24(r7),r3
2506 movzwl 26(r7),r0
2507 bicl2 #-65536,r0
2508 bicl3 #-65536,12(r6),-716(fp)
2509 bicl3 #-65536,r2,-720(fp)
2510 mull3 r0,-716(fp),-708(fp)
2511 mull2 r3,-716(fp)
2512 mull3 r3,-720(fp),-712(fp)
2513 mull2 r0,-720(fp)
2514 addl3 -708(fp),-712(fp),r0
2515 bicl3 #0,r0,-708(fp)
2516 cmpl -708(fp),-712(fp)
2517 bgequ noname.221
2518 addl2 #65536,-720(fp)
2519noname.221:
2520 movzwl -706(fp),r0
2521 bicl2 #-65536,r0
2522 addl2 r0,-720(fp)
2523 bicl3 #-65536,-708(fp),r0
2524 ashl #16,r0,-712(fp)
2525 addl3 -712(fp),-716(fp),r0
2526 bicl3 #0,r0,-716(fp)
2527 cmpl -716(fp),-712(fp)
2528 bgequ noname.222
2529 incl -720(fp)
2530noname.222:
2531 movl -716(fp),r1
2532 movl -720(fp),r2
2533 addl2 r1,r9
2534 bicl2 #0,r9
2535 cmpl r9,r1
2536 bgequ noname.223
2537 incl r2
2538noname.223:
2539 addl2 r2,r8
2540 bicl2 #0,r8
2541 cmpl r8,r2
2542 bgequ noname.224
2543 incl r10
2544noname.224:
2545
2546 movzwl 18(r6),r2
2547 bicl3 #-65536,20(r7),r3
2548 movzwl 22(r7),r0
2549 bicl2 #-65536,r0
2550 bicl3 #-65536,16(r6),-732(fp)
2551 bicl3 #-65536,r2,-736(fp)
2552 mull3 r0,-732(fp),-724(fp)
2553 mull2 r3,-732(fp)
2554 mull3 r3,-736(fp),-728(fp)
2555 mull2 r0,-736(fp)
2556 addl3 -724(fp),-728(fp),r0
2557 bicl3 #0,r0,-724(fp)
2558 cmpl -724(fp),-728(fp)
2559 bgequ noname.225
2560 addl2 #65536,-736(fp)
2561noname.225:
2562 movzwl -722(fp),r0
2563 bicl2 #-65536,r0
2564 addl2 r0,-736(fp)
2565 bicl3 #-65536,-724(fp),r0
2566 ashl #16,r0,-728(fp)
2567 addl3 -728(fp),-732(fp),r0
2568 bicl3 #0,r0,-732(fp)
2569 cmpl -732(fp),-728(fp)
2570 bgequ noname.226
2571 incl -736(fp)
2572noname.226:
2573 movl -732(fp),r1
2574 movl -736(fp),r2
2575 addl2 r1,r9
2576 bicl2 #0,r9
2577 cmpl r9,r1
2578 bgequ noname.227
2579 incl r2
2580noname.227:
2581 addl2 r2,r8
2582 bicl2 #0,r8
2583 cmpl r8,r2
2584 bgequ noname.228
2585 incl r10
2586noname.228:
2587
2588 movzwl 22(r6),r2
2589 bicl3 #-65536,16(r7),r3
2590 movzwl 18(r7),r0
2591 bicl2 #-65536,r0
2592 bicl3 #-65536,20(r6),-748(fp)
2593 bicl3 #-65536,r2,-752(fp)
2594 mull3 r0,-748(fp),-740(fp)
2595 mull2 r3,-748(fp)
2596 mull3 r3,-752(fp),-744(fp)
2597 mull2 r0,-752(fp)
2598 addl3 -740(fp),-744(fp),r0
2599 bicl3 #0,r0,-740(fp)
2600 cmpl -740(fp),-744(fp)
2601 bgequ noname.229
2602 addl2 #65536,-752(fp)
2603noname.229:
2604 movzwl -738(fp),r0
2605 bicl2 #-65536,r0
2606 addl2 r0,-752(fp)
2607 bicl3 #-65536,-740(fp),r0
2608 ashl #16,r0,-744(fp)
2609 addl3 -744(fp),-748(fp),r0
2610 bicl3 #0,r0,-748(fp)
2611 cmpl -748(fp),-744(fp)
2612 bgequ noname.230
2613 incl -752(fp)
2614noname.230:
2615 movl -748(fp),r1
2616 movl -752(fp),r2
2617 addl2 r1,r9
2618 bicl2 #0,r9
2619 cmpl r9,r1
2620 bgequ noname.231
2621 incl r2
2622noname.231:
2623 addl2 r2,r8
2624 bicl2 #0,r8
2625 cmpl r8,r2
2626 bgequ noname.232
2627 incl r10
2628noname.232:
2629
2630 movzwl 26(r6),r2
2631 bicl3 #-65536,12(r7),r3
2632 movzwl 14(r7),r0
2633 bicl2 #-65536,r0
2634 bicl3 #-65536,24(r6),-764(fp)
2635 bicl3 #-65536,r2,-768(fp)
2636 mull3 r0,-764(fp),-756(fp)
2637 mull2 r3,-764(fp)
2638 mull3 r3,-768(fp),-760(fp)
2639 mull2 r0,-768(fp)
2640 addl3 -756(fp),-760(fp),r0
2641 bicl3 #0,r0,-756(fp)
2642 cmpl -756(fp),-760(fp)
2643 bgequ noname.233
2644 addl2 #65536,-768(fp)
2645noname.233:
2646 movzwl -754(fp),r0
2647 bicl2 #-65536,r0
2648 addl2 r0,-768(fp)
2649 bicl3 #-65536,-756(fp),r0
2650 ashl #16,r0,-760(fp)
2651 addl3 -760(fp),-764(fp),r0
2652 bicl3 #0,r0,-764(fp)
2653 cmpl -764(fp),-760(fp)
2654 bgequ noname.234
2655 incl -768(fp)
2656noname.234:
2657 movl -764(fp),r1
2658 movl -768(fp),r2
2659 addl2 r1,r9
2660 bicl2 #0,r9
2661 cmpl r9,r1
2662 bgequ noname.235
2663 incl r2
2664noname.235:
2665 addl2 r2,r8
2666 bicl2 #0,r8
2667 cmpl r8,r2
2668 bgequ noname.236
2669 incl r10
2670noname.236:
2671
2672 bicl3 #-65536,28(r6),r3
2673 movzwl 30(r6),r1
2674 bicl2 #-65536,r1
2675 bicl3 #-65536,8(r7),r2
2676 movzwl 10(r7),r0
2677 bicl2 #-65536,r0
2678 movl r3,r5
2679 movl r1,r4
2680 mull3 r0,r5,-772(fp)
2681 mull2 r2,r5
2682 mull3 r2,r4,-776(fp)
2683 mull2 r0,r4
2684 addl3 -772(fp),-776(fp),r0
2685 bicl3 #0,r0,-772(fp)
2686 cmpl -772(fp),-776(fp)
2687 bgequ noname.237
2688 addl2 #65536,r4
2689noname.237:
2690 movzwl -770(fp),r0
2691 bicl2 #-65536,r0
2692 addl2 r0,r4
2693 bicl3 #-65536,-772(fp),r0
2694 ashl #16,r0,-776(fp)
2695 addl2 -776(fp),r5
2696 bicl2 #0,r5
2697 cmpl r5,-776(fp)
2698 bgequ noname.238
2699 incl r4
2700noname.238:
2701 movl r5,r1
2702 movl r4,r2
2703 addl2 r1,r9
2704 bicl2 #0,r9
2705 cmpl r9,r1
2706 bgequ noname.239
2707 incl r2
2708noname.239:
2709 addl2 r2,r8
2710 bicl2 #0,r8
2711 cmpl r8,r2
2712 bgequ noname.240
2713 incl r10
2714noname.240:
2715
2716 movl r9,36(r11)
2717
2718 clrl r9
2719
2720 bicl3 #-65536,28(r6),r3
2721 movzwl 30(r6),r1
2722 bicl2 #-65536,r1
2723 bicl3 #-65536,12(r7),r2
2724 movzwl 14(r7),r0
2725 bicl2 #-65536,r0
2726 movl r3,r5
2727 movl r1,r4
2728 mull3 r0,r5,-780(fp)
2729 mull2 r2,r5
2730 mull3 r2,r4,-784(fp)
2731 mull2 r0,r4
2732 addl3 -780(fp),-784(fp),r0
2733 bicl3 #0,r0,-780(fp)
2734 cmpl -780(fp),-784(fp)
2735 bgequ noname.241
2736 addl2 #65536,r4
2737noname.241:
2738 movzwl -778(fp),r0
2739 bicl2 #-65536,r0
2740 addl2 r0,r4
2741 bicl3 #-65536,-780(fp),r0
2742 ashl #16,r0,-784(fp)
2743 addl2 -784(fp),r5
2744 bicl2 #0,r5
2745 cmpl r5,-784(fp)
2746 bgequ noname.242
2747 incl r4
2748noname.242:
2749 movl r5,r1
2750 movl r4,r2
2751 addl2 r1,r8
2752 bicl2 #0,r8
2753 cmpl r8,r1
2754 bgequ noname.243
2755 incl r2
2756noname.243:
2757 addl2 r2,r10
2758 bicl2 #0,r10
2759 cmpl r10,r2
2760 bgequ noname.244
2761 incl r9
2762noname.244:
2763
2764 bicl3 #-65536,24(r6),r3
2765 movzwl 26(r6),r1
2766 bicl2 #-65536,r1
2767 bicl3 #-65536,16(r7),r2
2768 movzwl 18(r7),r0
2769 bicl2 #-65536,r0
2770 movl r3,r5
2771 movl r1,r4
2772 mull3 r0,r5,-788(fp)
2773 mull2 r2,r5
2774 mull3 r2,r4,-792(fp)
2775 mull2 r0,r4
2776 addl3 -788(fp),-792(fp),r0
2777 bicl3 #0,r0,-788(fp)
2778 cmpl -788(fp),-792(fp)
2779 bgequ noname.245
2780 addl2 #65536,r4
2781noname.245:
2782 movzwl -786(fp),r0
2783 bicl2 #-65536,r0
2784 addl2 r0,r4
2785 bicl3 #-65536,-788(fp),r0
2786 ashl #16,r0,-792(fp)
2787 addl2 -792(fp),r5
2788 bicl2 #0,r5
2789 cmpl r5,-792(fp)
2790 bgequ noname.246
2791 incl r4
2792noname.246:
2793 movl r5,r1
2794 movl r4,r2
2795 addl2 r1,r8
2796 bicl2 #0,r8
2797 cmpl r8,r1
2798 bgequ noname.247
2799 incl r2
2800noname.247:
2801 addl2 r2,r10
2802 bicl2 #0,r10
2803 cmpl r10,r2
2804 bgequ noname.248
2805 incl r9
2806noname.248:
2807
2808 bicl3 #-65536,20(r6),r3
2809 movzwl 22(r6),r1
2810 bicl2 #-65536,r1
2811 bicl3 #-65536,20(r7),r2
2812 movzwl 22(r7),r0
2813 bicl2 #-65536,r0
2814 movl r3,r5
2815 movl r1,r4
2816 mull3 r0,r5,-796(fp)
2817 mull2 r2,r5
2818 mull3 r2,r4,-800(fp)
2819 mull2 r0,r4
2820 addl3 -796(fp),-800(fp),r0
2821 bicl3 #0,r0,-796(fp)
2822 cmpl -796(fp),-800(fp)
2823 bgequ noname.249
2824 addl2 #65536,r4
2825noname.249:
2826 movzwl -794(fp),r0
2827 bicl2 #-65536,r0
2828 addl2 r0,r4
2829 bicl3 #-65536,-796(fp),r0
2830 ashl #16,r0,-800(fp)
2831 addl2 -800(fp),r5
2832 bicl2 #0,r5
2833 cmpl r5,-800(fp)
2834 bgequ noname.250
2835 incl r4
2836noname.250:
2837 movl r5,r1
2838 movl r4,r2
2839 addl2 r1,r8
2840 bicl2 #0,r8
2841 cmpl r8,r1
2842 bgequ noname.251
2843 incl r2
2844noname.251:
2845 addl2 r2,r10
2846 bicl2 #0,r10
2847 cmpl r10,r2
2848 bgequ noname.252
2849 incl r9
2850noname.252:
2851
2852 bicl3 #-65536,16(r6),r3
2853 movzwl 18(r6),r1
2854 bicl2 #-65536,r1
2855 bicl3 #-65536,24(r7),r2
2856 movzwl 26(r7),r0
2857 bicl2 #-65536,r0
2858 movl r3,r5
2859 movl r1,r4
2860 mull3 r0,r5,-804(fp)
2861 mull2 r2,r5
2862 mull3 r2,r4,-808(fp)
2863 mull2 r0,r4
2864 addl3 -804(fp),-808(fp),r0
2865 bicl3 #0,r0,-804(fp)
2866 cmpl -804(fp),-808(fp)
2867 bgequ noname.253
2868 addl2 #65536,r4
2869noname.253:
2870 movzwl -802(fp),r0
2871 bicl2 #-65536,r0
2872 addl2 r0,r4
2873 bicl3 #-65536,-804(fp),r0
2874 ashl #16,r0,-808(fp)
2875 addl2 -808(fp),r5
2876 bicl2 #0,r5
2877 cmpl r5,-808(fp)
2878 bgequ noname.254
2879 incl r4
2880noname.254:
2881 movl r5,r1
2882 movl r4,r2
2883 addl2 r1,r8
2884 bicl2 #0,r8
2885 cmpl r8,r1
2886 bgequ noname.255
2887 incl r2
2888noname.255:
2889 addl2 r2,r10
2890 bicl2 #0,r10
2891 cmpl r10,r2
2892 bgequ noname.256
2893 incl r9
2894noname.256:
2895
2896 bicl3 #-65536,12(r6),r3
2897 movzwl 14(r6),r1
2898 bicl2 #-65536,r1
2899 bicl3 #-65536,28(r7),r2
2900 movzwl 30(r7),r0
2901 bicl2 #-65536,r0
2902 movl r3,r5
2903 movl r1,r4
2904 mull3 r0,r5,-812(fp)
2905 mull2 r2,r5
2906 mull3 r2,r4,-816(fp)
2907 mull2 r0,r4
2908 addl3 -812(fp),-816(fp),r0
2909 bicl3 #0,r0,-812(fp)
2910 cmpl -812(fp),-816(fp)
2911 bgequ noname.257
2912 addl2 #65536,r4
2913noname.257:
2914 movzwl -810(fp),r0
2915 bicl2 #-65536,r0
2916 addl2 r0,r4
2917 bicl3 #-65536,-812(fp),r0
2918 ashl #16,r0,-816(fp)
2919 addl2 -816(fp),r5
2920 bicl2 #0,r5
2921 cmpl r5,-816(fp)
2922 bgequ noname.258
2923 incl r4
2924noname.258:
2925 movl r5,r1
2926 movl r4,r2
2927 addl2 r1,r8
2928 bicl2 #0,r8
2929 cmpl r8,r1
2930 bgequ noname.259
2931 incl r2
2932noname.259:
2933 addl2 r2,r10
2934 bicl2 #0,r10
2935 cmpl r10,r2
2936 bgequ noname.260
2937 incl r9
2938noname.260:
2939
2940 movl r8,40(r11)
2941
2942 clrl r8
2943
2944 bicl3 #-65536,16(r6),r3
2945 movzwl 18(r6),r2
2946 bicl3 #-65536,28(r7),r1
2947 movzwl 30(r7),r0
2948 bicl2 #-65536,r0
2949 movl r3,r4
2950 bicl3 #-65536,r2,-828(fp)
2951 mull3 r0,r4,-820(fp)
2952 mull2 r1,r4
2953 mull3 r1,-828(fp),-824(fp)
2954 mull2 r0,-828(fp)
2955 addl3 -820(fp),-824(fp),r0
2956 bicl3 #0,r0,-820(fp)
2957 cmpl -820(fp),-824(fp)
2958 bgequ noname.261
2959 addl2 #65536,-828(fp)
2960noname.261:
2961 movzwl -818(fp),r0
2962 bicl2 #-65536,r0
2963 addl2 r0,-828(fp)
2964 bicl3 #-65536,-820(fp),r0
2965 ashl #16,r0,-824(fp)
2966 addl2 -824(fp),r4
2967 bicl2 #0,r4
2968 cmpl r4,-824(fp)
2969 bgequ noname.262
2970 incl -828(fp)
2971noname.262:
2972 movl r4,r1
2973 movl -828(fp),r2
2974 addl2 r1,r10
2975 bicl2 #0,r10
2976 cmpl r10,r1
2977 bgequ noname.263
2978 incl r2
2979noname.263:
2980 addl2 r2,r9
2981 bicl2 #0,r9
2982 cmpl r9,r2
2983 bgequ noname.264
2984 incl r8
2985noname.264:
2986
2987 movzwl 22(r6),r2
2988 bicl3 #-65536,24(r7),r3
2989 movzwl 26(r7),r0
2990 bicl2 #-65536,r0
2991 bicl3 #-65536,20(r6),-840(fp)
2992 bicl3 #-65536,r2,-844(fp)
2993 mull3 r0,-840(fp),-832(fp)
2994 mull2 r3,-840(fp)
2995 mull3 r3,-844(fp),-836(fp)
2996 mull2 r0,-844(fp)
2997 addl3 -832(fp),-836(fp),r0
2998 bicl3 #0,r0,-832(fp)
2999 cmpl -832(fp),-836(fp)
3000 bgequ noname.265
3001 addl2 #65536,-844(fp)
3002noname.265:
3003 movzwl -830(fp),r0
3004 bicl2 #-65536,r0
3005 addl2 r0,-844(fp)
3006 bicl3 #-65536,-832(fp),r0
3007 ashl #16,r0,-836(fp)
3008 addl3 -836(fp),-840(fp),r0
3009 bicl3 #0,r0,-840(fp)
3010 cmpl -840(fp),-836(fp)
3011 bgequ noname.266
3012 incl -844(fp)
3013noname.266:
3014 movl -840(fp),r1
3015 movl -844(fp),r2
3016 addl2 r1,r10
3017 bicl2 #0,r10
3018 cmpl r10,r1
3019 bgequ noname.267
3020 incl r2
3021noname.267:
3022 addl2 r2,r9
3023 bicl2 #0,r9
3024 cmpl r9,r2
3025 bgequ noname.268
3026 incl r8
3027noname.268:
3028
3029 bicl3 #-65536,24(r6),r3
3030 movzwl 26(r6),r1
3031 bicl2 #-65536,r1
3032 bicl3 #-65536,20(r7),r2
3033 movzwl 22(r7),r0
3034 bicl2 #-65536,r0
3035 movl r3,r5
3036 movl r1,r4
3037 mull3 r0,r5,-848(fp)
3038 mull2 r2,r5
3039 mull3 r2,r4,-852(fp)
3040 mull2 r0,r4
3041 addl3 -848(fp),-852(fp),r0
3042 bicl3 #0,r0,-848(fp)
3043 cmpl -848(fp),-852(fp)
3044 bgequ noname.269
3045 addl2 #65536,r4
3046noname.269:
3047 movzwl -846(fp),r0
3048 bicl2 #-65536,r0
3049 addl2 r0,r4
3050 bicl3 #-65536,-848(fp),r0
3051 ashl #16,r0,-852(fp)
3052 addl2 -852(fp),r5
3053 bicl2 #0,r5
3054 cmpl r5,-852(fp)
3055 bgequ noname.270
3056 incl r4
3057noname.270:
3058 movl r5,r1
3059 movl r4,r2
3060 addl2 r1,r10
3061 bicl2 #0,r10
3062 cmpl r10,r1
3063 bgequ noname.271
3064 incl r2
3065noname.271:
3066 addl2 r2,r9
3067 bicl2 #0,r9
3068 cmpl r9,r2
3069 bgequ noname.272
3070 incl r8
3071noname.272:
3072
3073 bicl3 #-65536,28(r6),r3
3074 movzwl 30(r6),r1
3075 bicl2 #-65536,r1
3076 bicl3 #-65536,16(r7),r2
3077 movzwl 18(r7),r0
3078 bicl2 #-65536,r0
3079 movl r3,r5
3080 movl r1,r4
3081 mull3 r0,r5,-856(fp)
3082 mull2 r2,r5
3083 mull3 r2,r4,-860(fp)
3084 mull2 r0,r4
3085 addl3 -856(fp),-860(fp),r0
3086 bicl3 #0,r0,-856(fp)
3087 cmpl -856(fp),-860(fp)
3088 bgequ noname.273
3089 addl2 #65536,r4
3090noname.273:
3091 movzwl -854(fp),r0
3092 bicl2 #-65536,r0
3093 addl2 r0,r4
3094 bicl3 #-65536,-856(fp),r0
3095 ashl #16,r0,-860(fp)
3096 addl2 -860(fp),r5
3097 bicl2 #0,r5
3098 cmpl r5,-860(fp)
3099 bgequ noname.274
3100 incl r4
3101noname.274:
3102 movl r5,r1
3103 movl r4,r2
3104 addl2 r1,r10
3105 bicl2 #0,r10
3106 cmpl r10,r1
3107 bgequ noname.275
3108 incl r2
3109noname.275:
3110 addl2 r2,r9
3111 bicl2 #0,r9
3112 cmpl r9,r2
3113 bgequ noname.276
3114 incl r8
3115noname.276:
3116
3117 movl r10,44(r11)
3118
3119 clrl r10
3120
3121 bicl3 #-65536,28(r6),r3
3122 movzwl 30(r6),r1
3123 bicl2 #-65536,r1
3124 bicl3 #-65536,20(r7),r2
3125 movzwl 22(r7),r0
3126 bicl2 #-65536,r0
3127 movl r3,r5
3128 movl r1,r4
3129 mull3 r0,r5,-864(fp)
3130 mull2 r2,r5
3131 mull3 r2,r4,-868(fp)
3132 mull2 r0,r4
3133 addl3 -864(fp),-868(fp),r0
3134 bicl3 #0,r0,-864(fp)
3135 cmpl -864(fp),-868(fp)
3136 bgequ noname.277
3137 addl2 #65536,r4
3138noname.277:
3139 movzwl -862(fp),r0
3140 bicl2 #-65536,r0
3141 addl2 r0,r4
3142 bicl3 #-65536,-864(fp),r0
3143 ashl #16,r0,-868(fp)
3144 addl2 -868(fp),r5
3145 bicl2 #0,r5
3146 cmpl r5,-868(fp)
3147 bgequ noname.278
3148 incl r4
3149noname.278:
3150 movl r5,r1
3151 movl r4,r2
3152 addl2 r1,r9
3153 bicl2 #0,r9
3154 cmpl r9,r1
3155 bgequ noname.279
3156 incl r2
3157noname.279:
3158 addl2 r2,r8
3159 bicl2 #0,r8
3160 cmpl r8,r2
3161 bgequ noname.280
3162 incl r10
3163noname.280:
3164
3165 bicl3 #-65536,24(r6),r3
3166 movzwl 26(r6),r1
3167 bicl2 #-65536,r1
3168 bicl3 #-65536,24(r7),r2
3169 movzwl 26(r7),r0
3170 bicl2 #-65536,r0
3171 movl r3,r5
3172 movl r1,r4
3173 mull3 r0,r5,-872(fp)
3174 mull2 r2,r5
3175 mull3 r2,r4,-876(fp)
3176 mull2 r0,r4
3177 addl3 -872(fp),-876(fp),r0
3178 bicl3 #0,r0,-872(fp)
3179 cmpl -872(fp),-876(fp)
3180 bgequ noname.281
3181 addl2 #65536,r4
3182noname.281:
3183 movzwl -870(fp),r0
3184 bicl2 #-65536,r0
3185 addl2 r0,r4
3186 bicl3 #-65536,-872(fp),r0
3187 ashl #16,r0,-876(fp)
3188 addl2 -876(fp),r5
3189 bicl2 #0,r5
3190 cmpl r5,-876(fp)
3191 bgequ noname.282
3192 incl r4
3193noname.282:
3194 movl r5,r1
3195 movl r4,r2
3196 addl2 r1,r9
3197 bicl2 #0,r9
3198 cmpl r9,r1
3199 bgequ noname.283
3200 incl r2
3201noname.283:
3202 addl2 r2,r8
3203 bicl2 #0,r8
3204 cmpl r8,r2
3205 bgequ noname.284
3206 incl r10
3207noname.284:
3208
3209 bicl3 #-65536,20(r6),r3
3210 movzwl 22(r6),r1
3211 bicl2 #-65536,r1
3212 bicl3 #-65536,28(r7),r2
3213 movzwl 30(r7),r0
3214 bicl2 #-65536,r0
3215 movl r3,r5
3216 movl r1,r4
3217 mull3 r0,r5,-880(fp)
3218 mull2 r2,r5
3219 mull3 r2,r4,-884(fp)
3220 mull2 r0,r4
3221 addl3 -880(fp),-884(fp),r0
3222 bicl3 #0,r0,-880(fp)
3223 cmpl -880(fp),-884(fp)
3224 bgequ noname.285
3225 addl2 #65536,r4
3226noname.285:
3227 movzwl -878(fp),r0
3228 bicl2 #-65536,r0
3229 addl2 r0,r4
3230 bicl3 #-65536,-880(fp),r0
3231 ashl #16,r0,-884(fp)
3232 addl2 -884(fp),r5
3233 bicl2 #0,r5
3234 cmpl r5,-884(fp)
3235 bgequ noname.286
3236 incl r4
3237noname.286:
3238 movl r5,r1
3239 movl r4,r2
3240 addl2 r1,r9
3241 bicl2 #0,r9
3242 cmpl r9,r1
3243 bgequ noname.287
3244 incl r2
3245noname.287:
3246 addl2 r2,r8
3247 bicl2 #0,r8
3248 cmpl r8,r2
3249 bgequ noname.288
3250 incl r10
3251noname.288:
3252
3253 movl r9,48(r11)
3254
3255 clrl r9
3256
3257 bicl3 #-65536,24(r6),r3
3258 movzwl 26(r6),r1
3259 bicl2 #-65536,r1
3260 bicl3 #-65536,28(r7),r2
3261 movzwl 30(r7),r0
3262 bicl2 #-65536,r0
3263 movl r3,r5
3264 movl r1,r4
3265 mull3 r0,r5,-888(fp)
3266 mull2 r2,r5
3267 mull3 r2,r4,-892(fp)
3268 mull2 r0,r4
3269 addl3 -888(fp),-892(fp),r0
3270 bicl3 #0,r0,-888(fp)
3271 cmpl -888(fp),-892(fp)
3272 bgequ noname.289
3273 addl2 #65536,r4
3274noname.289:
3275 movzwl -886(fp),r0
3276 bicl2 #-65536,r0
3277 addl2 r0,r4
3278 bicl3 #-65536,-888(fp),r0
3279 ashl #16,r0,-892(fp)
3280 addl2 -892(fp),r5
3281 bicl2 #0,r5
3282 cmpl r5,-892(fp)
3283 bgequ noname.290
3284 incl r4
3285noname.290:
3286 movl r5,r1
3287 movl r4,r2
3288 addl2 r1,r8
3289 bicl2 #0,r8
3290 cmpl r8,r1
3291 bgequ noname.291
3292 incl r2
3293noname.291:
3294 addl2 r2,r10
3295 bicl2 #0,r10
3296 cmpl r10,r2
3297 bgequ noname.292
3298 incl r9
3299noname.292:
3300
3301 movzwl 30(r6),r2
3302 bicl3 #-65536,24(r7),r3
3303 movzwl 26(r7),r0
3304 bicl2 #-65536,r0
3305 bicl3 #-65536,28(r6),-904(fp)
3306 bicl3 #-65536,r2,-908(fp)
3307 mull3 r0,-904(fp),-896(fp)
3308 mull2 r3,-904(fp)
3309 mull3 r3,-908(fp),-900(fp)
3310 mull2 r0,-908(fp)
3311 addl3 -896(fp),-900(fp),r0
3312 bicl3 #0,r0,-896(fp)
3313 cmpl -896(fp),-900(fp)
3314 bgequ noname.293
3315 addl2 #65536,-908(fp)
3316noname.293:
3317 movzwl -894(fp),r0
3318 bicl2 #-65536,r0
3319 addl2 r0,-908(fp)
3320 bicl3 #-65536,-896(fp),r0
3321 ashl #16,r0,-900(fp)
3322 addl3 -900(fp),-904(fp),r0
3323 bicl3 #0,r0,-904(fp)
3324 cmpl -904(fp),-900(fp)
3325 bgequ noname.294
3326 incl -908(fp)
3327noname.294:
3328 movl -904(fp),r1
3329 movl -908(fp),r2
3330 addl2 r1,r8
3331 bicl2 #0,r8
3332 cmpl r8,r1
3333 bgequ noname.295
3334 incl r2
3335noname.295:
3336 addl2 r2,r10
3337 bicl2 #0,r10
3338 cmpl r10,r2
3339 bgequ noname.296
3340 incl r9
3341noname.296:
3342
3343 movl r8,52(r11)
3344
3345 clrl r8
3346
3347 movzwl 30(r6),r2
3348 bicl3 #-65536,28(r7),r3
3349 movzwl 30(r7),r0
3350 bicl2 #-65536,r0
3351 bicl3 #-65536,28(r6),-920(fp)
3352 bicl3 #-65536,r2,-924(fp)
3353 mull3 r0,-920(fp),-912(fp)
3354 mull2 r3,-920(fp)
3355 mull3 r3,-924(fp),-916(fp)
3356 mull2 r0,-924(fp)
3357 addl3 -912(fp),-916(fp),r0
3358 bicl3 #0,r0,-912(fp)
3359 cmpl -912(fp),-916(fp)
3360 bgequ noname.297
3361 addl2 #65536,-924(fp)
3362noname.297:
3363 movzwl -910(fp),r0
3364 bicl2 #-65536,r0
3365 addl2 r0,-924(fp)
3366 bicl3 #-65536,-912(fp),r0
3367 ashl #16,r0,-916(fp)
3368 addl3 -916(fp),-920(fp),r0
3369 bicl3 #0,r0,-920(fp)
3370 cmpl -920(fp),-916(fp)
3371 bgequ noname.298
3372 incl -924(fp)
3373noname.298:
3374 movl -920(fp),r1
3375 movl -924(fp),r2
3376 addl2 r1,r10
3377 bicl2 #0,r10
3378 cmpl r10,r1
3379 bgequ noname.299
3380 incl r2
3381noname.299:
3382 addl2 r2,r9
3383 bicl2 #0,r9
3384 cmpl r9,r2
3385 bgequ noname.300
3386 incl r8
3387noname.300:
3388
3389 movl r10,56(r11)
3390
3391 movl r9,60(r11)
3392
3393 ret
3394
3395
3396
3397;r=4 ;(AP)
3398;a=8 ;(AP)
3399;b=12 ;(AP)
3400;n=16 ;(AP) n by value (input)
3401
3402 .psect code,nowrt
3403
3404.entry BN_MUL_COMBA4,^m<r2,r3,r4,r5,r6,r7,r8,r9,r10,r11>
3405 movab -156(sp),sp
3406
3407 clrq r9
3408
3409 clrl r8
3410
3411 movl 8(ap),r6
3412 bicl3 #-65536,(r6),r3
3413 movzwl 2(r6),r2
3414 bicl2 #-65536,r2
3415 movl 12(ap),r7
3416 bicl3 #-65536,(r7),r1
3417 movzwl 2(r7),r0
3418 bicl2 #-65536,r0
3419 movl r3,r5
3420 movl r2,r4
3421 mull3 r0,r5,-4(fp)
3422 mull2 r1,r5
3423 mull3 r1,r4,-8(fp)
3424 mull2 r0,r4
3425 addl3 -4(fp),-8(fp),r0
3426 bicl3 #0,r0,-4(fp)
3427 cmpl -4(fp),-8(fp)
3428 bgequ noname.303
3429 addl2 #65536,r4
3430noname.303:
3431 movzwl -2(fp),r0
3432 bicl2 #-65536,r0
3433 addl2 r0,r4
3434 bicl3 #-65536,-4(fp),r0
3435 ashl #16,r0,-8(fp)
3436 addl2 -8(fp),r5
3437 bicl2 #0,r5
3438 cmpl r5,-8(fp)
3439 bgequ noname.304
3440 incl r4
3441noname.304:
3442 movl r5,r1
3443 movl r4,r2
3444 addl2 r1,r10
3445 bicl2 #0,r10
3446 cmpl r10,r1
3447 bgequ noname.305
3448 incl r2
3449noname.305:
3450 addl2 r2,r9
3451 bicl2 #0,r9
3452 cmpl r9,r2
3453 bgequ noname.306
3454 incl r8
3455noname.306:
3456
3457 movl 4(ap),r11
3458 movl r10,(r11)
3459
3460 clrl r10
3461
3462 bicl3 #-65536,(r6),r3
3463 movzwl 2(r6),r1
3464 bicl2 #-65536,r1
3465 bicl3 #-65536,4(r7),r2
3466 movzwl 6(r7),r0
3467 bicl2 #-65536,r0
3468 movl r3,r5
3469 movl r1,r4
3470 mull3 r0,r5,-12(fp)
3471 mull2 r2,r5
3472 mull3 r2,r4,-16(fp)
3473 mull2 r0,r4
3474 addl3 -12(fp),-16(fp),r0
3475 bicl3 #0,r0,-12(fp)
3476 cmpl -12(fp),-16(fp)
3477 bgequ noname.307
3478 addl2 #65536,r4
3479noname.307:
3480 movzwl -10(fp),r0
3481 bicl2 #-65536,r0
3482 addl2 r0,r4
3483 bicl3 #-65536,-12(fp),r0
3484 ashl #16,r0,-16(fp)
3485 addl2 -16(fp),r5
3486 bicl2 #0,r5
3487 cmpl r5,-16(fp)
3488 bgequ noname.308
3489 incl r4
3490noname.308:
3491 movl r5,r1
3492 movl r4,r2
3493 addl2 r1,r9
3494 bicl2 #0,r9
3495 cmpl r9,r1
3496 bgequ noname.309
3497 incl r2
3498noname.309:
3499 addl2 r2,r8
3500 bicl2 #0,r8
3501 cmpl r8,r2
3502 bgequ noname.310
3503 incl r10
3504noname.310:
3505
3506 bicl3 #-65536,4(r6),r3
3507 movzwl 6(r6),r1
3508 bicl2 #-65536,r1
3509 bicl3 #-65536,(r7),r2
3510 movzwl 2(r7),r0
3511 bicl2 #-65536,r0
3512 movl r3,r5
3513 movl r1,r4
3514 mull3 r0,r5,-20(fp)
3515 mull2 r2,r5
3516 mull3 r2,r4,-24(fp)
3517 mull2 r0,r4
3518 addl3 -20(fp),-24(fp),r0
3519 bicl3 #0,r0,-20(fp)
3520 cmpl -20(fp),-24(fp)
3521 bgequ noname.311
3522 addl2 #65536,r4
3523noname.311:
3524 movzwl -18(fp),r0
3525 bicl2 #-65536,r0
3526 addl2 r0,r4
3527 bicl3 #-65536,-20(fp),r0
3528 ashl #16,r0,-24(fp)
3529 addl2 -24(fp),r5
3530 bicl2 #0,r5
3531 cmpl r5,-24(fp)
3532 bgequ noname.312
3533 incl r4
3534noname.312:
3535 movl r5,r1
3536 movl r4,r2
3537 addl2 r1,r9
3538 bicl2 #0,r9
3539 cmpl r9,r1
3540 bgequ noname.313
3541 incl r2
3542noname.313:
3543 addl2 r2,r8
3544 bicl2 #0,r8
3545 cmpl r8,r2
3546 bgequ noname.314
3547 incl r10
3548noname.314:
3549
3550 movl r9,4(r11)
3551
3552 clrl r9
3553
3554 bicl3 #-65536,8(r6),r3
3555 movzwl 10(r6),r1
3556 bicl2 #-65536,r1
3557 bicl3 #-65536,(r7),r2
3558 movzwl 2(r7),r0
3559 bicl2 #-65536,r0
3560 movl r3,r5
3561 movl r1,r4
3562 mull3 r0,r5,-28(fp)
3563 mull2 r2,r5
3564 mull3 r2,r4,-32(fp)
3565 mull2 r0,r4
3566 addl3 -28(fp),-32(fp),r0
3567 bicl3 #0,r0,-28(fp)
3568 cmpl -28(fp),-32(fp)
3569 bgequ noname.315
3570 addl2 #65536,r4
3571noname.315:
3572 movzwl -26(fp),r0
3573 bicl2 #-65536,r0
3574 addl2 r0,r4
3575 bicl3 #-65536,-28(fp),r0
3576 ashl #16,r0,-32(fp)
3577 addl2 -32(fp),r5
3578 bicl2 #0,r5
3579 cmpl r5,-32(fp)
3580 bgequ noname.316
3581 incl r4
3582noname.316:
3583 movl r5,r1
3584 movl r4,r2
3585 addl2 r1,r8
3586 bicl2 #0,r8
3587 cmpl r8,r1
3588 bgequ noname.317
3589 incl r2
3590noname.317:
3591 addl2 r2,r10
3592 bicl2 #0,r10
3593 cmpl r10,r2
3594 bgequ noname.318
3595 incl r9
3596noname.318:
3597
3598 bicl3 #-65536,4(r6),r3
3599 movzwl 6(r6),r1
3600 bicl2 #-65536,r1
3601 bicl3 #-65536,4(r7),r2
3602 movzwl 6(r7),r0
3603 bicl2 #-65536,r0
3604 movl r3,r5
3605 movl r1,r4
3606 mull3 r0,r5,-36(fp)
3607 mull2 r2,r5
3608 mull3 r2,r4,-40(fp)
3609 mull2 r0,r4
3610 addl3 -36(fp),-40(fp),r0
3611 bicl3 #0,r0,-36(fp)
3612 cmpl -36(fp),-40(fp)
3613 bgequ noname.319
3614 addl2 #65536,r4
3615noname.319:
3616 movzwl -34(fp),r0
3617 bicl2 #-65536,r0
3618 addl2 r0,r4
3619 bicl3 #-65536,-36(fp),r0
3620 ashl #16,r0,-40(fp)
3621 addl2 -40(fp),r5
3622 bicl2 #0,r5
3623 cmpl r5,-40(fp)
3624 bgequ noname.320
3625 incl r4
3626noname.320:
3627 movl r5,r1
3628 movl r4,r2
3629 addl2 r1,r8
3630 bicl2 #0,r8
3631 cmpl r8,r1
3632 bgequ noname.321
3633 incl r2
3634noname.321:
3635 addl2 r2,r10
3636 bicl2 #0,r10
3637 cmpl r10,r2
3638 bgequ noname.322
3639 incl r9
3640noname.322:
3641
3642 bicl3 #-65536,(r6),r3
3643 movzwl 2(r6),r1
3644 bicl2 #-65536,r1
3645 bicl3 #-65536,8(r7),r2
3646 movzwl 10(r7),r0
3647 bicl2 #-65536,r0
3648 movl r3,r5
3649 movl r1,r4
3650 mull3 r0,r5,-44(fp)
3651 mull2 r2,r5
3652 mull3 r2,r4,-48(fp)
3653 mull2 r0,r4
3654 addl3 -44(fp),-48(fp),r0
3655 bicl3 #0,r0,-44(fp)
3656 cmpl -44(fp),-48(fp)
3657 bgequ noname.323
3658 addl2 #65536,r4
3659noname.323:
3660 movzwl -42(fp),r0
3661 bicl2 #-65536,r0
3662 addl2 r0,r4
3663 bicl3 #-65536,-44(fp),r0
3664 ashl #16,r0,-48(fp)
3665 addl2 -48(fp),r5
3666 bicl2 #0,r5
3667 cmpl r5,-48(fp)
3668 bgequ noname.324
3669 incl r4
3670noname.324:
3671 movl r5,r1
3672 movl r4,r2
3673 addl2 r1,r8
3674 bicl2 #0,r8
3675 cmpl r8,r1
3676 bgequ noname.325
3677 incl r2
3678noname.325:
3679 addl2 r2,r10
3680 bicl2 #0,r10
3681 cmpl r10,r2
3682 bgequ noname.326
3683 incl r9
3684noname.326:
3685
3686 movl r8,8(r11)
3687
3688 clrl r8
3689
3690 bicl3 #-65536,(r6),r3
3691 movzwl 2(r6),r2
3692 bicl3 #-65536,12(r7),r1
3693 movzwl 14(r7),r0
3694 bicl2 #-65536,r0
3695 movl r3,r4
3696 bicl3 #-65536,r2,-60(fp)
3697 mull3 r0,r4,-52(fp)
3698 mull2 r1,r4
3699 mull3 r1,-60(fp),-56(fp)
3700 mull2 r0,-60(fp)
3701 addl3 -52(fp),-56(fp),r0
3702 bicl3 #0,r0,-52(fp)
3703 cmpl -52(fp),-56(fp)
3704 bgequ noname.327
3705 addl2 #65536,-60(fp)
3706noname.327:
3707 movzwl -50(fp),r0
3708 bicl2 #-65536,r0
3709 addl2 r0,-60(fp)
3710 bicl3 #-65536,-52(fp),r0
3711 ashl #16,r0,-56(fp)
3712 addl2 -56(fp),r4
3713 bicl2 #0,r4
3714 cmpl r4,-56(fp)
3715 bgequ noname.328
3716 incl -60(fp)
3717noname.328:
3718 movl r4,r1
3719 movl -60(fp),r2
3720 addl2 r1,r10
3721 bicl2 #0,r10
3722 cmpl r10,r1
3723 bgequ noname.329
3724 incl r2
3725noname.329:
3726 addl2 r2,r9
3727 bicl2 #0,r9
3728 cmpl r9,r2
3729 bgequ noname.330
3730 incl r8
3731noname.330:
3732
3733 movzwl 6(r6),r2
3734 bicl3 #-65536,8(r7),r3
3735 movzwl 10(r7),r0
3736 bicl2 #-65536,r0
3737 bicl3 #-65536,4(r6),-72(fp)
3738 bicl3 #-65536,r2,-76(fp)
3739 mull3 r0,-72(fp),-64(fp)
3740 mull2 r3,-72(fp)
3741 mull3 r3,-76(fp),-68(fp)
3742 mull2 r0,-76(fp)
3743 addl3 -64(fp),-68(fp),r0
3744 bicl3 #0,r0,-64(fp)
3745 cmpl -64(fp),-68(fp)
3746 bgequ noname.331
3747 addl2 #65536,-76(fp)
3748noname.331:
3749 movzwl -62(fp),r0
3750 bicl2 #-65536,r0
3751 addl2 r0,-76(fp)
3752 bicl3 #-65536,-64(fp),r0
3753 ashl #16,r0,-68(fp)
3754 addl3 -68(fp),-72(fp),r0
3755 bicl3 #0,r0,-72(fp)
3756 cmpl -72(fp),-68(fp)
3757 bgequ noname.332
3758 incl -76(fp)
3759noname.332:
3760 movl -72(fp),r1
3761 movl -76(fp),r2
3762 addl2 r1,r10
3763 bicl2 #0,r10
3764 cmpl r10,r1
3765 bgequ noname.333
3766 incl r2
3767noname.333:
3768 addl2 r2,r9
3769 bicl2 #0,r9
3770 cmpl r9,r2
3771 bgequ noname.334
3772 incl r8
3773noname.334:
3774
3775 bicl3 #-65536,8(r6),r3
3776 movzwl 10(r6),r1
3777 bicl2 #-65536,r1
3778 bicl3 #-65536,4(r7),r2
3779 movzwl 6(r7),r0
3780 bicl2 #-65536,r0
3781 movl r3,r5
3782 movl r1,r4
3783 mull3 r0,r5,-80(fp)
3784 mull2 r2,r5
3785 mull3 r2,r4,-84(fp)
3786 mull2 r0,r4
3787 addl3 -80(fp),-84(fp),r0
3788 bicl3 #0,r0,-80(fp)
3789 cmpl -80(fp),-84(fp)
3790 bgequ noname.335
3791 addl2 #65536,r4
3792noname.335:
3793 movzwl -78(fp),r0
3794 bicl2 #-65536,r0
3795 addl2 r0,r4
3796 bicl3 #-65536,-80(fp),r0
3797 ashl #16,r0,-84(fp)
3798 addl2 -84(fp),r5
3799 bicl2 #0,r5
3800 cmpl r5,-84(fp)
3801 bgequ noname.336
3802 incl r4
3803noname.336:
3804 movl r5,r1
3805 movl r4,r2
3806 addl2 r1,r10
3807 bicl2 #0,r10
3808 cmpl r10,r1
3809 bgequ noname.337
3810 incl r2
3811noname.337:
3812 addl2 r2,r9
3813 bicl2 #0,r9
3814 cmpl r9,r2
3815 bgequ noname.338
3816 incl r8
3817noname.338:
3818
3819 bicl3 #-65536,12(r6),r3
3820 movzwl 14(r6),r1
3821 bicl2 #-65536,r1
3822 bicl3 #-65536,(r7),r2
3823 movzwl 2(r7),r0
3824 bicl2 #-65536,r0
3825 movl r3,r5
3826 movl r1,r4
3827 mull3 r0,r5,-88(fp)
3828 mull2 r2,r5
3829 mull3 r2,r4,-92(fp)
3830 mull2 r0,r4
3831 addl3 -88(fp),-92(fp),r0
3832 bicl3 #0,r0,-88(fp)
3833 cmpl -88(fp),-92(fp)
3834 bgequ noname.339
3835 addl2 #65536,r4
3836noname.339:
3837 movzwl -86(fp),r0
3838 bicl2 #-65536,r0
3839 addl2 r0,r4
3840 bicl3 #-65536,-88(fp),r0
3841 ashl #16,r0,-92(fp)
3842 addl2 -92(fp),r5
3843 bicl2 #0,r5
3844 cmpl r5,-92(fp)
3845 bgequ noname.340
3846 incl r4
3847noname.340:
3848 movl r5,r1
3849 movl r4,r2
3850 addl2 r1,r10
3851 bicl2 #0,r10
3852 cmpl r10,r1
3853 bgequ noname.341
3854 incl r2
3855noname.341:
3856 addl2 r2,r9
3857 bicl2 #0,r9
3858 cmpl r9,r2
3859 bgequ noname.342
3860 incl r8
3861noname.342:
3862
3863 movl r10,12(r11)
3864
3865 clrl r10
3866
3867 bicl3 #-65536,12(r6),r3
3868 movzwl 14(r6),r1
3869 bicl2 #-65536,r1
3870 bicl3 #-65536,4(r7),r2
3871 movzwl 6(r7),r0
3872 bicl2 #-65536,r0
3873 movl r3,r5
3874 movl r1,r4
3875 mull3 r0,r5,-96(fp)
3876 mull2 r2,r5
3877 mull3 r2,r4,-100(fp)
3878 mull2 r0,r4
3879 addl3 -96(fp),-100(fp),r0
3880 bicl3 #0,r0,-96(fp)
3881 cmpl -96(fp),-100(fp)
3882 bgequ noname.343
3883 addl2 #65536,r4
3884noname.343:
3885 movzwl -94(fp),r0
3886 bicl2 #-65536,r0
3887 addl2 r0,r4
3888 bicl3 #-65536,-96(fp),r0
3889 ashl #16,r0,-100(fp)
3890 addl2 -100(fp),r5
3891 bicl2 #0,r5
3892 cmpl r5,-100(fp)
3893 bgequ noname.344
3894 incl r4
3895noname.344:
3896 movl r5,r1
3897 movl r4,r2
3898 addl2 r1,r9
3899 bicl2 #0,r9
3900 cmpl r9,r1
3901 bgequ noname.345
3902 incl r2
3903noname.345:
3904 addl2 r2,r8
3905 bicl2 #0,r8
3906 cmpl r8,r2
3907 bgequ noname.346
3908 incl r10
3909noname.346:
3910
3911 bicl3 #-65536,8(r6),r3
3912 movzwl 10(r6),r1
3913 bicl2 #-65536,r1
3914 bicl3 #-65536,8(r7),r2
3915 movzwl 10(r7),r0
3916 bicl2 #-65536,r0
3917 movl r3,r5
3918 movl r1,r4
3919 mull3 r0,r5,-104(fp)
3920 mull2 r2,r5
3921 mull3 r2,r4,-108(fp)
3922 mull2 r0,r4
3923 addl3 -104(fp),-108(fp),r0
3924 bicl3 #0,r0,-104(fp)
3925 cmpl -104(fp),-108(fp)
3926 bgequ noname.347
3927 addl2 #65536,r4
3928noname.347:
3929 movzwl -102(fp),r0
3930 bicl2 #-65536,r0
3931 addl2 r0,r4
3932 bicl3 #-65536,-104(fp),r0
3933 ashl #16,r0,-108(fp)
3934 addl2 -108(fp),r5
3935 bicl2 #0,r5
3936 cmpl r5,-108(fp)
3937 bgequ noname.348
3938 incl r4
3939noname.348:
3940 movl r5,r1
3941 movl r4,r2
3942 addl2 r1,r9
3943 bicl2 #0,r9
3944 cmpl r9,r1
3945 bgequ noname.349
3946 incl r2
3947noname.349:
3948 addl2 r2,r8
3949 bicl2 #0,r8
3950 cmpl r8,r2
3951 bgequ noname.350
3952 incl r10
3953noname.350:
3954
3955 bicl3 #-65536,4(r6),r3
3956 movzwl 6(r6),r1
3957 bicl2 #-65536,r1
3958 bicl3 #-65536,12(r7),r2
3959 movzwl 14(r7),r0
3960 bicl2 #-65536,r0
3961 movl r3,r5
3962 movl r1,r4
3963 mull3 r0,r5,-112(fp)
3964 mull2 r2,r5
3965 mull3 r2,r4,-116(fp)
3966 mull2 r0,r4
3967 addl3 -112(fp),-116(fp),r0
3968 bicl3 #0,r0,-112(fp)
3969 cmpl -112(fp),-116(fp)
3970 bgequ noname.351
3971 addl2 #65536,r4
3972noname.351:
3973 movzwl -110(fp),r0
3974 bicl2 #-65536,r0
3975 addl2 r0,r4
3976 bicl3 #-65536,-112(fp),r0
3977 ashl #16,r0,-116(fp)
3978 addl2 -116(fp),r5
3979 bicl2 #0,r5
3980 cmpl r5,-116(fp)
3981 bgequ noname.352
3982 incl r4
3983noname.352:
3984 movl r5,r1
3985 movl r4,r2
3986 addl2 r1,r9
3987 bicl2 #0,r9
3988 cmpl r9,r1
3989 bgequ noname.353
3990 incl r2
3991noname.353:
3992 addl2 r2,r8
3993 bicl2 #0,r8
3994 cmpl r8,r2
3995 bgequ noname.354
3996 incl r10
3997noname.354:
3998
3999 movl r9,16(r11)
4000
4001 clrl r9
4002
4003 bicl3 #-65536,8(r6),r3
4004 movzwl 10(r6),r1
4005 bicl2 #-65536,r1
4006 bicl3 #-65536,12(r7),r2
4007 movzwl 14(r7),r0
4008 bicl2 #-65536,r0
4009 movl r3,r5
4010 movl r1,r4
4011 mull3 r0,r5,-120(fp)
4012 mull2 r2,r5
4013 mull3 r2,r4,-124(fp)
4014 mull2 r0,r4
4015 addl3 -120(fp),-124(fp),r0
4016 bicl3 #0,r0,-120(fp)
4017 cmpl -120(fp),-124(fp)
4018 bgequ noname.355
4019 addl2 #65536,r4
4020noname.355:
4021 movzwl -118(fp),r0
4022 bicl2 #-65536,r0
4023 addl2 r0,r4
4024 bicl3 #-65536,-120(fp),r0
4025 ashl #16,r0,-124(fp)
4026 addl2 -124(fp),r5
4027 bicl2 #0,r5
4028 cmpl r5,-124(fp)
4029 bgequ noname.356
4030 incl r4
4031noname.356:
4032 movl r5,r1
4033 movl r4,r2
4034 addl2 r1,r8
4035 bicl2 #0,r8
4036 cmpl r8,r1
4037 bgequ noname.357
4038 incl r2
4039noname.357:
4040 addl2 r2,r10
4041 bicl2 #0,r10
4042 cmpl r10,r2
4043 bgequ noname.358
4044 incl r9
4045noname.358:
4046
4047 movzwl 14(r6),r2
4048 bicl3 #-65536,8(r7),r3
4049 movzwl 10(r7),r0
4050 bicl2 #-65536,r0
4051 bicl3 #-65536,12(r6),-136(fp)
4052 bicl3 #-65536,r2,-140(fp)
4053 mull3 r0,-136(fp),-128(fp)
4054 mull2 r3,-136(fp)
4055 mull3 r3,-140(fp),-132(fp)
4056 mull2 r0,-140(fp)
4057 addl3 -128(fp),-132(fp),r0
4058 bicl3 #0,r0,-128(fp)
4059 cmpl -128(fp),-132(fp)
4060 bgequ noname.359
4061 addl2 #65536,-140(fp)
4062noname.359:
4063 movzwl -126(fp),r0
4064 bicl2 #-65536,r0
4065 addl2 r0,-140(fp)
4066 bicl3 #-65536,-128(fp),r0
4067 ashl #16,r0,-132(fp)
4068 addl3 -132(fp),-136(fp),r0
4069 bicl3 #0,r0,-136(fp)
4070 cmpl -136(fp),-132(fp)
4071 bgequ noname.360
4072 incl -140(fp)
4073noname.360:
4074 movl -136(fp),r1
4075 movl -140(fp),r2
4076 addl2 r1,r8
4077 bicl2 #0,r8
4078 cmpl r8,r1
4079 bgequ noname.361
4080 incl r2
4081noname.361:
4082 addl2 r2,r10
4083 bicl2 #0,r10
4084 cmpl r10,r2
4085 bgequ noname.362
4086 incl r9
4087noname.362:
4088
4089 movl r8,20(r11)
4090
4091 clrl r8
4092
4093 movzwl 14(r6),r2
4094 bicl3 #-65536,12(r7),r3
4095 movzwl 14(r7),r0
4096 bicl2 #-65536,r0
4097 bicl3 #-65536,12(r6),-152(fp)
4098 bicl3 #-65536,r2,-156(fp)
4099 mull3 r0,-152(fp),-144(fp)
4100 mull2 r3,-152(fp)
4101 mull3 r3,-156(fp),-148(fp)
4102 mull2 r0,-156(fp)
4103 addl3 -144(fp),-148(fp),r0
4104 bicl3 #0,r0,-144(fp)
4105 cmpl -144(fp),-148(fp)
4106 bgequ noname.363
4107 addl2 #65536,-156(fp)
4108noname.363:
4109 movzwl -142(fp),r0
4110 bicl2 #-65536,r0
4111 addl2 r0,-156(fp)
4112 bicl3 #-65536,-144(fp),r0
4113 ashl #16,r0,-148(fp)
4114 addl3 -148(fp),-152(fp),r0
4115 bicl3 #0,r0,-152(fp)
4116 cmpl -152(fp),-148(fp)
4117 bgequ noname.364
4118 incl -156(fp)
4119noname.364:
4120 movl -152(fp),r1
4121 movl -156(fp),r2
4122 addl2 r1,r10
4123 bicl2 #0,r10
4124 cmpl r10,r1
4125 bgequ noname.365
4126 incl r2
4127noname.365:
4128 addl2 r2,r9
4129 bicl2 #0,r9
4130 cmpl r9,r2
4131 bgequ noname.366
4132 incl r8
4133noname.366:
4134
4135 movl r10,24(r11)
4136
4137 movl r9,28(r11)
4138
4139 ret
4140
4141
4142
4143;r=4 ;(AP)
4144;a=8 ;(AP)
4145;b=12 ;(AP)
4146;n=16 ;(AP) n by value (input)
4147
4148 .psect code,nowrt
4149
4150.entry BN_SQR_COMBA8,^m<r2,r3,r4,r5,r6,r7,r8,r9>
4151 movab -444(sp),sp
4152
4153 clrq r8
4154
4155 clrl r7
4156
4157 movl 8(ap),r4
4158 movl (r4),r3
4159 bicl3 #-65536,r3,-4(fp)
4160 extzv #16,#16,r3,r0
4161 bicl3 #-65536,r0,r3
4162 movl -4(fp),r0
4163 mull3 r0,r3,-8(fp)
4164 mull3 r0,r0,-4(fp)
4165 mull2 r3,r3
4166 bicl3 #32767,-8(fp),r0
4167 extzv #15,#17,r0,r0
4168 addl2 r0,r3
4169 bicl3 #-65536,-8(fp),r0
4170 ashl #17,r0,-8(fp)
4171 addl3 -4(fp),-8(fp),r0
4172 bicl3 #0,r0,-4(fp)
4173 cmpl -4(fp),-8(fp)
4174 bgequ noname.369
4175 incl r3
4176noname.369:
4177 movl -4(fp),r1
4178 movl r3,r2
4179 addl2 r1,r9
4180 bicl2 #0,r9
4181 cmpl r9,r1
4182 bgequ noname.370
4183 incl r2
4184noname.370:
4185 addl2 r2,r8
4186 bicl2 #0,r8
4187 cmpl r8,r2
4188 bgequ noname.371
4189 incl r7
4190noname.371:
4191
4192 movl r9,@4(ap)
4193
4194 clrl r9
4195
4196 movzwl 6(r4),r2
4197 bicl3 #-65536,(r4),r3
4198 movzwl 2(r4),r0
4199 bicl2 #-65536,r0
4200 bicl3 #-65536,4(r4),-20(fp)
4201 bicl3 #-65536,r2,-24(fp)
4202 mull3 r0,-20(fp),-12(fp)
4203 mull2 r3,-20(fp)
4204 mull3 r3,-24(fp),-16(fp)
4205 mull2 r0,-24(fp)
4206 addl3 -12(fp),-16(fp),r0
4207 bicl3 #0,r0,-12(fp)
4208 cmpl -12(fp),-16(fp)
4209 bgequ noname.372
4210 addl2 #65536,-24(fp)
4211noname.372:
4212 movzwl -10(fp),r0
4213 bicl2 #-65536,r0
4214 addl2 r0,-24(fp)
4215 bicl3 #-65536,-12(fp),r0
4216 ashl #16,r0,-16(fp)
4217 addl3 -16(fp),-20(fp),r0
4218 bicl3 #0,r0,-20(fp)
4219 cmpl -20(fp),-16(fp)
4220 bgequ noname.373
4221 incl -24(fp)
4222noname.373:
4223 movl -20(fp),r3
4224 movl -24(fp),r2
4225 bbc #31,r2,noname.374
4226 incl r9
4227noname.374:
4228 addl2 r2,r2
4229 bicl2 #0,r2
4230 bbc #31,r3,noname.375
4231 incl r2
4232noname.375:
4233 addl2 r3,r3
4234 bicl2 #0,r3
4235 addl2 r3,r8
4236 bicl2 #0,r8
4237 cmpl r8,r3
4238 bgequ noname.376
4239 incl r2
4240 bicl3 #0,r2,r0
4241 bneq noname.376
4242 incl r9
4243noname.376:
4244 addl2 r2,r7
4245 bicl2 #0,r7
4246 cmpl r7,r2
4247 bgequ noname.377
4248 incl r9
4249noname.377:
4250
4251 movl 4(ap),r0
4252 movl r8,4(r0)
4253
4254 clrl r8
4255
4256 movl 8(ap),r4
4257 movl 4(r4),r3
4258 bicl3 #-65536,r3,-28(fp)
4259 extzv #16,#16,r3,r0
4260 bicl3 #-65536,r0,r3
4261 movl -28(fp),r0
4262 mull3 r0,r3,-32(fp)
4263 mull3 r0,r0,-28(fp)
4264 mull2 r3,r3
4265 bicl3 #32767,-32(fp),r0
4266 extzv #15,#17,r0,r0
4267 addl2 r0,r3
4268 bicl3 #-65536,-32(fp),r0
4269 ashl #17,r0,-32(fp)
4270 addl3 -28(fp),-32(fp),r0
4271 bicl3 #0,r0,-28(fp)
4272 cmpl -28(fp),-32(fp)
4273 bgequ noname.378
4274 incl r3
4275noname.378:
4276 movl -28(fp),r1
4277 movl r3,r2
4278 addl2 r1,r7
4279 bicl2 #0,r7
4280 cmpl r7,r1
4281 bgequ noname.379
4282 incl r2
4283noname.379:
4284 addl2 r2,r9
4285 bicl2 #0,r9
4286 cmpl r9,r2
4287 bgequ noname.380
4288 incl r8
4289noname.380:
4290
4291 movzwl 10(r4),r2
4292 bicl3 #-65536,(r4),r3
4293 movzwl 2(r4),r0
4294 bicl2 #-65536,r0
4295 bicl3 #-65536,8(r4),-44(fp)
4296 bicl3 #-65536,r2,-48(fp)
4297 mull3 r0,-44(fp),-36(fp)
4298 mull2 r3,-44(fp)
4299 mull3 r3,-48(fp),-40(fp)
4300 mull2 r0,-48(fp)
4301 addl3 -36(fp),-40(fp),r0
4302 bicl3 #0,r0,-36(fp)
4303 cmpl -36(fp),-40(fp)
4304 bgequ noname.381
4305 addl2 #65536,-48(fp)
4306noname.381:
4307 movzwl -34(fp),r0
4308 bicl2 #-65536,r0
4309 addl2 r0,-48(fp)
4310 bicl3 #-65536,-36(fp),r0
4311 ashl #16,r0,-40(fp)
4312 addl3 -40(fp),-44(fp),r0
4313 bicl3 #0,r0,-44(fp)
4314 cmpl -44(fp),-40(fp)
4315 bgequ noname.382
4316 incl -48(fp)
4317noname.382:
4318 movl -44(fp),r3
4319 movl -48(fp),r2
4320 bbc #31,r2,noname.383
4321 incl r8
4322noname.383:
4323 addl2 r2,r2
4324 bicl2 #0,r2
4325 bbc #31,r3,noname.384
4326 incl r2
4327noname.384:
4328 addl2 r3,r3
4329 bicl2 #0,r3
4330 addl2 r3,r7
4331 bicl2 #0,r7
4332 cmpl r7,r3
4333 bgequ noname.385
4334 incl r2
4335 bicl3 #0,r2,r0
4336 bneq noname.385
4337 incl r8
4338noname.385:
4339 addl2 r2,r9
4340 bicl2 #0,r9
4341 cmpl r9,r2
4342 bgequ noname.386
4343 incl r8
4344noname.386:
4345
4346 movl 4(ap),r0
4347 movl r7,8(r0)
4348
4349 clrl r7
4350
4351 movl 8(ap),r0
4352 movzwl 14(r0),r2
4353 bicl3 #-65536,(r0),r3
4354 movzwl 2(r0),r1
4355 bicl2 #-65536,r1
4356 bicl3 #-65536,12(r0),-60(fp)
4357 bicl3 #-65536,r2,-64(fp)
4358 mull3 r1,-60(fp),-52(fp)
4359 mull2 r3,-60(fp)
4360 mull3 r3,-64(fp),-56(fp)
4361 mull2 r1,-64(fp)
4362 addl3 -52(fp),-56(fp),r0
4363 bicl3 #0,r0,-52(fp)
4364 cmpl -52(fp),-56(fp)
4365 bgequ noname.387
4366 addl2 #65536,-64(fp)
4367noname.387:
4368 movzwl -50(fp),r0
4369 bicl2 #-65536,r0
4370 addl2 r0,-64(fp)
4371 bicl3 #-65536,-52(fp),r0
4372 ashl #16,r0,-56(fp)
4373 addl3 -56(fp),-60(fp),r0
4374 bicl3 #0,r0,-60(fp)
4375 cmpl -60(fp),-56(fp)
4376 bgequ noname.388
4377 incl -64(fp)
4378noname.388:
4379 movl -60(fp),r3
4380 movl -64(fp),r2
4381 bbc #31,r2,noname.389
4382 incl r7
4383noname.389:
4384 addl2 r2,r2
4385 bicl2 #0,r2
4386 bbc #31,r3,noname.390
4387 incl r2
4388noname.390:
4389 addl2 r3,r3
4390 bicl2 #0,r3
4391 addl2 r3,r9
4392 bicl2 #0,r9
4393 cmpl r9,r3
4394 bgequ noname.391
4395 incl r2
4396 bicl3 #0,r2,r0
4397 bneq noname.391
4398 incl r7
4399noname.391:
4400 addl2 r2,r8
4401 bicl2 #0,r8
4402 cmpl r8,r2
4403 bgequ noname.392
4404 incl r7
4405noname.392:
4406
4407 movl 8(ap),r0
4408 movzwl 10(r0),r2
4409 bicl3 #-65536,4(r0),r3
4410 movzwl 6(r0),r1
4411 bicl2 #-65536,r1
4412 bicl3 #-65536,8(r0),-76(fp)
4413 bicl3 #-65536,r2,-80(fp)
4414 mull3 r1,-76(fp),-68(fp)
4415 mull2 r3,-76(fp)
4416 mull3 r3,-80(fp),-72(fp)
4417 mull2 r1,-80(fp)
4418 addl3 -68(fp),-72(fp),r0
4419 bicl3 #0,r0,-68(fp)
4420 cmpl -68(fp),-72(fp)
4421 bgequ noname.393
4422 addl2 #65536,-80(fp)
4423noname.393:
4424 movzwl -66(fp),r0
4425 bicl2 #-65536,r0
4426 addl2 r0,-80(fp)
4427 bicl3 #-65536,-68(fp),r0
4428 ashl #16,r0,-72(fp)
4429 addl3 -72(fp),-76(fp),r0
4430 bicl3 #0,r0,-76(fp)
4431 cmpl -76(fp),-72(fp)
4432 bgequ noname.394
4433 incl -80(fp)
4434noname.394:
4435 movl -76(fp),r3
4436 movl -80(fp),r2
4437 bbc #31,r2,noname.395
4438 incl r7
4439noname.395:
4440 addl2 r2,r2
4441 bicl2 #0,r2
4442 bbc #31,r3,noname.396
4443 incl r2
4444noname.396:
4445 addl2 r3,r3
4446 bicl2 #0,r3
4447 addl2 r3,r9
4448 bicl2 #0,r9
4449 cmpl r9,r3
4450 bgequ noname.397
4451 incl r2
4452 bicl3 #0,r2,r0
4453 bneq noname.397
4454 incl r7
4455noname.397:
4456 addl2 r2,r8
4457 bicl2 #0,r8
4458 cmpl r8,r2
4459 bgequ noname.398
4460 incl r7
4461noname.398:
4462
4463 movl 4(ap),r0
4464 movl r9,12(r0)
4465
4466 clrl r9
4467
4468 movl 8(ap),r2
4469 movl 8(r2),r4
4470 bicl3 #-65536,r4,-84(fp)
4471 extzv #16,#16,r4,r0
4472 bicl3 #-65536,r0,r4
4473 movl -84(fp),r0
4474 mull3 r0,r4,-88(fp)
4475 mull3 r0,r0,-84(fp)
4476 mull2 r4,r4
4477 bicl3 #32767,-88(fp),r0
4478 extzv #15,#17,r0,r0
4479 addl2 r0,r4
4480 bicl3 #-65536,-88(fp),r0
4481 ashl #17,r0,-88(fp)
4482 addl3 -84(fp),-88(fp),r0
4483 bicl3 #0,r0,-84(fp)
4484 cmpl -84(fp),-88(fp)
4485 bgequ noname.399
4486 incl r4
4487noname.399:
4488 movl -84(fp),r1
4489 movl r4,r3
4490 addl2 r1,r8
4491 bicl2 #0,r8
4492 cmpl r8,r1
4493 bgequ noname.400
4494 incl r3
4495noname.400:
4496 addl2 r3,r7
4497 bicl2 #0,r7
4498 cmpl r7,r3
4499 bgequ noname.401
4500 incl r9
4501noname.401:
4502
4503 movzwl 14(r2),r3
4504 bicl3 #-65536,4(r2),r1
4505 movzwl 6(r2),r0
4506 bicl2 #-65536,r0
4507 bicl3 #-65536,12(r2),-100(fp)
4508 bicl3 #-65536,r3,-104(fp)
4509 mull3 r0,-100(fp),-92(fp)
4510 mull2 r1,-100(fp)
4511 mull3 r1,-104(fp),-96(fp)
4512 mull2 r0,-104(fp)
4513 addl3 -92(fp),-96(fp),r0
4514 bicl3 #0,r0,-92(fp)
4515 cmpl -92(fp),-96(fp)
4516 bgequ noname.402
4517 addl2 #65536,-104(fp)
4518noname.402:
4519 movzwl -90(fp),r0
4520 bicl2 #-65536,r0
4521 addl2 r0,-104(fp)
4522 bicl3 #-65536,-92(fp),r0
4523 ashl #16,r0,-96(fp)
4524 addl3 -96(fp),-100(fp),r0
4525 bicl3 #0,r0,-100(fp)
4526 cmpl -100(fp),-96(fp)
4527 bgequ noname.403
4528 incl -104(fp)
4529noname.403:
4530 movl -100(fp),r3
4531 movl -104(fp),r2
4532 bbc #31,r2,noname.404
4533 incl r9
4534noname.404:
4535 addl2 r2,r2
4536 bicl2 #0,r2
4537 bbc #31,r3,noname.405
4538 incl r2
4539noname.405:
4540 addl2 r3,r3
4541 bicl2 #0,r3
4542 addl2 r3,r8
4543 bicl2 #0,r8
4544 cmpl r8,r3
4545 bgequ noname.406
4546 incl r2
4547 bicl3 #0,r2,r0
4548 bneq noname.406
4549 incl r9
4550noname.406:
4551 addl2 r2,r7
4552 bicl2 #0,r7
4553 cmpl r7,r2
4554 bgequ noname.407
4555 incl r9
4556noname.407:
4557
4558 movl 8(ap),r0
4559 movzwl 18(r0),r2
4560 bicl3 #-65536,(r0),r3
4561 movzwl 2(r0),r1
4562 bicl2 #-65536,r1
4563 bicl3 #-65536,16(r0),-116(fp)
4564 bicl3 #-65536,r2,-120(fp)
4565 mull3 r1,-116(fp),-108(fp)
4566 mull2 r3,-116(fp)
4567 mull3 r3,-120(fp),-112(fp)
4568 mull2 r1,-120(fp)
4569 addl3 -108(fp),-112(fp),r0
4570 bicl3 #0,r0,-108(fp)
4571 cmpl -108(fp),-112(fp)
4572 bgequ noname.408
4573 addl2 #65536,-120(fp)
4574noname.408:
4575 movzwl -106(fp),r0
4576 bicl2 #-65536,r0
4577 addl2 r0,-120(fp)
4578 bicl3 #-65536,-108(fp),r0
4579 ashl #16,r0,-112(fp)
4580 addl3 -112(fp),-116(fp),r0
4581 bicl3 #0,r0,-116(fp)
4582 cmpl -116(fp),-112(fp)
4583 bgequ noname.409
4584 incl -120(fp)
4585noname.409:
4586 movl -116(fp),r3
4587 movl -120(fp),r2
4588 bbc #31,r2,noname.410
4589 incl r9
4590noname.410:
4591 addl2 r2,r2
4592 bicl2 #0,r2
4593 bbc #31,r3,noname.411
4594 incl r2
4595noname.411:
4596 addl2 r3,r3
4597 bicl2 #0,r3
4598 addl2 r3,r8
4599 bicl2 #0,r8
4600 cmpl r8,r3
4601 bgequ noname.412
4602 incl r2
4603 bicl3 #0,r2,r0
4604 bneq noname.412
4605 incl r9
4606noname.412:
4607 addl2 r2,r7
4608 bicl2 #0,r7
4609 cmpl r7,r2
4610 bgequ noname.413
4611 incl r9
4612noname.413:
4613
4614 movl 4(ap),r0
4615 movl r8,16(r0)
4616
4617 clrl r8
4618
4619 movl 8(ap),r0
4620 movzwl 22(r0),r2
4621 bicl3 #-65536,(r0),r3
4622 movzwl 2(r0),r1
4623 bicl2 #-65536,r1
4624 bicl3 #-65536,20(r0),-132(fp)
4625 bicl3 #-65536,r2,-136(fp)
4626 mull3 r1,-132(fp),-124(fp)
4627 mull2 r3,-132(fp)
4628 mull3 r3,-136(fp),-128(fp)
4629 mull2 r1,-136(fp)
4630 addl3 -124(fp),-128(fp),r0
4631 bicl3 #0,r0,-124(fp)
4632 cmpl -124(fp),-128(fp)
4633 bgequ noname.414
4634 addl2 #65536,-136(fp)
4635noname.414:
4636 movzwl -122(fp),r0
4637 bicl2 #-65536,r0
4638 addl2 r0,-136(fp)
4639 bicl3 #-65536,-124(fp),r0
4640 ashl #16,r0,-128(fp)
4641 addl3 -128(fp),-132(fp),r0
4642 bicl3 #0,r0,-132(fp)
4643 cmpl -132(fp),-128(fp)
4644 bgequ noname.415
4645 incl -136(fp)
4646noname.415:
4647 movl -132(fp),r3
4648 movl -136(fp),r2
4649 bbc #31,r2,noname.416
4650 incl r8
4651noname.416:
4652 addl2 r2,r2
4653 bicl2 #0,r2
4654 bbc #31,r3,noname.417
4655 incl r2
4656noname.417:
4657 addl2 r3,r3
4658 bicl2 #0,r3
4659 addl2 r3,r7
4660 bicl2 #0,r7
4661 cmpl r7,r3
4662 bgequ noname.418
4663 incl r2
4664 bicl3 #0,r2,r0
4665 bneq noname.418
4666 incl r8
4667noname.418:
4668 addl2 r2,r9
4669 bicl2 #0,r9
4670 cmpl r9,r2
4671 bgequ noname.419
4672 incl r8
4673noname.419:
4674
4675 movl 8(ap),r0
4676 movzwl 18(r0),r2
4677 bicl3 #-65536,4(r0),r3
4678 movzwl 6(r0),r1
4679 bicl2 #-65536,r1
4680 bicl3 #-65536,16(r0),-148(fp)
4681 bicl3 #-65536,r2,-152(fp)
4682 mull3 r1,-148(fp),-140(fp)
4683 mull2 r3,-148(fp)
4684 mull3 r3,-152(fp),-144(fp)
4685 mull2 r1,-152(fp)
4686 addl3 -140(fp),-144(fp),r0
4687 bicl3 #0,r0,-140(fp)
4688 cmpl -140(fp),-144(fp)
4689 bgequ noname.420
4690 addl2 #65536,-152(fp)
4691noname.420:
4692 movzwl -138(fp),r0
4693 bicl2 #-65536,r0
4694 addl2 r0,-152(fp)
4695 bicl3 #-65536,-140(fp),r0
4696 ashl #16,r0,-144(fp)
4697 addl3 -144(fp),-148(fp),r0
4698 bicl3 #0,r0,-148(fp)
4699 cmpl -148(fp),-144(fp)
4700 bgequ noname.421
4701 incl -152(fp)
4702noname.421:
4703 movl -148(fp),r3
4704 movl -152(fp),r2
4705 bbc #31,r2,noname.422
4706 incl r8
4707noname.422:
4708 addl2 r2,r2
4709 bicl2 #0,r2
4710 bbc #31,r3,noname.423
4711 incl r2
4712noname.423:
4713 addl2 r3,r3
4714 bicl2 #0,r3
4715 addl2 r3,r7
4716 bicl2 #0,r7
4717 cmpl r7,r3
4718 bgequ noname.424
4719 incl r2
4720 bicl3 #0,r2,r0
4721 bneq noname.424
4722 incl r8
4723noname.424:
4724 addl2 r2,r9
4725 bicl2 #0,r9
4726 cmpl r9,r2
4727 bgequ noname.425
4728 incl r8
4729noname.425:
4730
4731 movl 8(ap),r0
4732 movzwl 14(r0),r2
4733 bicl3 #-65536,8(r0),r3
4734 movzwl 10(r0),r1
4735 bicl2 #-65536,r1
4736 bicl3 #-65536,12(r0),-164(fp)
4737 bicl3 #-65536,r2,-168(fp)
4738 mull3 r1,-164(fp),-156(fp)
4739 mull2 r3,-164(fp)
4740 mull3 r3,-168(fp),-160(fp)
4741 mull2 r1,-168(fp)
4742 addl3 -156(fp),-160(fp),r0
4743 bicl3 #0,r0,-156(fp)
4744 cmpl -156(fp),-160(fp)
4745 bgequ noname.426
4746 addl2 #65536,-168(fp)
4747noname.426:
4748 movzwl -154(fp),r0
4749 bicl2 #-65536,r0
4750 addl2 r0,-168(fp)
4751 bicl3 #-65536,-156(fp),r0
4752 ashl #16,r0,-160(fp)
4753 addl3 -160(fp),-164(fp),r0
4754 bicl3 #0,r0,-164(fp)
4755 cmpl -164(fp),-160(fp)
4756 bgequ noname.427
4757 incl -168(fp)
4758noname.427:
4759 movl -164(fp),r3
4760 movl -168(fp),r2
4761 bbc #31,r2,noname.428
4762 incl r8
4763noname.428:
4764 addl2 r2,r2
4765 bicl2 #0,r2
4766 bbc #31,r3,noname.429
4767 incl r2
4768noname.429:
4769 addl2 r3,r3
4770 bicl2 #0,r3
4771 addl2 r3,r7
4772 bicl2 #0,r7
4773 cmpl r7,r3
4774 bgequ noname.430
4775 incl r2
4776 bicl3 #0,r2,r0
4777 bneq noname.430
4778 incl r8
4779noname.430:
4780 addl2 r2,r9
4781 bicl2 #0,r9
4782 cmpl r9,r2
4783 bgequ noname.431
4784 incl r8
4785noname.431:
4786
4787 movl 4(ap),r0
4788 movl r7,20(r0)
4789
4790 clrl r7
4791
4792 movl 8(ap),r2
4793 movl 12(r2),r4
4794 bicl3 #-65536,r4,-172(fp)
4795 extzv #16,#16,r4,r0
4796 bicl3 #-65536,r0,r4
4797 movl -172(fp),r0
4798 mull3 r0,r4,-176(fp)
4799 mull3 r0,r0,-172(fp)
4800 mull2 r4,r4
4801 bicl3 #32767,-176(fp),r0
4802 extzv #15,#17,r0,r0
4803 addl2 r0,r4
4804 bicl3 #-65536,-176(fp),r0
4805 ashl #17,r0,-176(fp)
4806 addl3 -172(fp),-176(fp),r0
4807 bicl3 #0,r0,-172(fp)
4808 cmpl -172(fp),-176(fp)
4809 bgequ noname.432
4810 incl r4
4811noname.432:
4812 movl -172(fp),r1
4813 movl r4,r3
4814 addl2 r1,r9
4815 bicl2 #0,r9
4816 cmpl r9,r1
4817 bgequ noname.433
4818 incl r3
4819noname.433:
4820 addl2 r3,r8
4821 bicl2 #0,r8
4822 cmpl r8,r3
4823 bgequ noname.434
4824 incl r7
4825noname.434:
4826
4827 movzwl 18(r2),r3
4828 bicl3 #-65536,8(r2),r1
4829 movzwl 10(r2),r0
4830 bicl2 #-65536,r0
4831 bicl3 #-65536,16(r2),-188(fp)
4832 bicl3 #-65536,r3,-192(fp)
4833 mull3 r0,-188(fp),-180(fp)
4834 mull2 r1,-188(fp)
4835 mull3 r1,-192(fp),-184(fp)
4836 mull2 r0,-192(fp)
4837 addl3 -180(fp),-184(fp),r0
4838 bicl3 #0,r0,-180(fp)
4839 cmpl -180(fp),-184(fp)
4840 bgequ noname.435
4841 addl2 #65536,-192(fp)
4842noname.435:
4843 movzwl -178(fp),r0
4844 bicl2 #-65536,r0
4845 addl2 r0,-192(fp)
4846 bicl3 #-65536,-180(fp),r0
4847 ashl #16,r0,-184(fp)
4848 addl3 -184(fp),-188(fp),r0
4849 bicl3 #0,r0,-188(fp)
4850 cmpl -188(fp),-184(fp)
4851 bgequ noname.436
4852 incl -192(fp)
4853noname.436:
4854 movl -188(fp),r3
4855 movl -192(fp),r2
4856 bbc #31,r2,noname.437
4857 incl r7
4858noname.437:
4859 addl2 r2,r2
4860 bicl2 #0,r2
4861 bbc #31,r3,noname.438
4862 incl r2
4863noname.438:
4864 addl2 r3,r3
4865 bicl2 #0,r3
4866 addl2 r3,r9
4867 bicl2 #0,r9
4868 cmpl r9,r3
4869 bgequ noname.439
4870 incl r2
4871 bicl3 #0,r2,r0
4872 bneq noname.439
4873 incl r7
4874noname.439:
4875 addl2 r2,r8
4876 bicl2 #0,r8
4877 cmpl r8,r2
4878 bgequ noname.440
4879 incl r7
4880noname.440:
4881
4882 movl 8(ap),r0
4883 movzwl 22(r0),r2
4884 bicl3 #-65536,4(r0),r3
4885 movzwl 6(r0),r1
4886 bicl2 #-65536,r1
4887 bicl3 #-65536,20(r0),-204(fp)
4888 bicl3 #-65536,r2,-208(fp)
4889 mull3 r1,-204(fp),-196(fp)
4890 mull2 r3,-204(fp)
4891 mull3 r3,-208(fp),-200(fp)
4892 mull2 r1,-208(fp)
4893 addl3 -196(fp),-200(fp),r0
4894 bicl3 #0,r0,-196(fp)
4895 cmpl -196(fp),-200(fp)
4896 bgequ noname.441
4897 addl2 #65536,-208(fp)
4898noname.441:
4899 movzwl -194(fp),r0
4900 bicl2 #-65536,r0
4901 addl2 r0,-208(fp)
4902 bicl3 #-65536,-196(fp),r0
4903 ashl #16,r0,-200(fp)
4904 addl3 -200(fp),-204(fp),r0
4905 bicl3 #0,r0,-204(fp)
4906 cmpl -204(fp),-200(fp)
4907 bgequ noname.442
4908 incl -208(fp)
4909noname.442:
4910 movl -204(fp),r3
4911 movl -208(fp),r2
4912 bbc #31,r2,noname.443
4913 incl r7
4914noname.443:
4915 addl2 r2,r2
4916 bicl2 #0,r2
4917 bbc #31,r3,noname.444
4918 incl r2
4919noname.444:
4920 addl2 r3,r3
4921 bicl2 #0,r3
4922 addl2 r3,r9
4923 bicl2 #0,r9
4924 cmpl r9,r3
4925 bgequ noname.445
4926 incl r2
4927 bicl3 #0,r2,r0
4928 bneq noname.445
4929 incl r7
4930noname.445:
4931 addl2 r2,r8
4932 bicl2 #0,r8
4933 cmpl r8,r2
4934 bgequ noname.446
4935 incl r7
4936noname.446:
4937
4938 movl 8(ap),r0
4939 movzwl 26(r0),r2
4940 bicl3 #-65536,(r0),r3
4941 movzwl 2(r0),r1
4942 bicl2 #-65536,r1
4943 bicl3 #-65536,24(r0),-220(fp)
4944 bicl3 #-65536,r2,-224(fp)
4945 mull3 r1,-220(fp),-212(fp)
4946 mull2 r3,-220(fp)
4947 mull3 r3,-224(fp),-216(fp)
4948 mull2 r1,-224(fp)
4949 addl3 -212(fp),-216(fp),r0
4950 bicl3 #0,r0,-212(fp)
4951 cmpl -212(fp),-216(fp)
4952 bgequ noname.447
4953 addl2 #65536,-224(fp)
4954noname.447:
4955 movzwl -210(fp),r0
4956 bicl2 #-65536,r0
4957 addl2 r0,-224(fp)
4958 bicl3 #-65536,-212(fp),r0
4959 ashl #16,r0,-216(fp)
4960 addl3 -216(fp),-220(fp),r0
4961 bicl3 #0,r0,-220(fp)
4962 cmpl -220(fp),-216(fp)
4963 bgequ noname.448
4964 incl -224(fp)
4965noname.448:
4966 movl -220(fp),r3
4967 movl -224(fp),r2
4968 bbc #31,r2,noname.449
4969 incl r7
4970noname.449:
4971 addl2 r2,r2
4972 bicl2 #0,r2
4973 bbc #31,r3,noname.450
4974 incl r2
4975noname.450:
4976 addl2 r3,r3
4977 bicl2 #0,r3
4978 addl2 r3,r9
4979 bicl2 #0,r9
4980 cmpl r9,r3
4981 bgequ noname.451
4982 incl r2
4983 bicl3 #0,r2,r0
4984 bneq noname.451
4985 incl r7
4986noname.451:
4987 addl2 r2,r8
4988 bicl2 #0,r8
4989 cmpl r8,r2
4990 bgequ noname.452
4991 incl r7
4992noname.452:
4993
4994 movl 4(ap),r0
4995 movl r9,24(r0)
4996
4997 clrl r9
4998
4999 movl 8(ap),r0
5000 movzwl 30(r0),r2
5001 bicl3 #-65536,(r0),r3
5002 movzwl 2(r0),r1
5003 bicl2 #-65536,r1
5004 bicl3 #-65536,28(r0),-236(fp)
5005 bicl3 #-65536,r2,-240(fp)
5006 mull3 r1,-236(fp),-228(fp)
5007 mull2 r3,-236(fp)
5008 mull3 r3,-240(fp),-232(fp)
5009 mull2 r1,-240(fp)
5010 addl3 -228(fp),-232(fp),r0
5011 bicl3 #0,r0,-228(fp)
5012 cmpl -228(fp),-232(fp)
5013 bgequ noname.453
5014 addl2 #65536,-240(fp)
5015noname.453:
5016 movzwl -226(fp),r0
5017 bicl2 #-65536,r0
5018 addl2 r0,-240(fp)
5019 bicl3 #-65536,-228(fp),r0
5020 ashl #16,r0,-232(fp)
5021 addl3 -232(fp),-236(fp),r0
5022 bicl3 #0,r0,-236(fp)
5023 cmpl -236(fp),-232(fp)
5024 bgequ noname.454
5025 incl -240(fp)
5026noname.454:
5027 movl -236(fp),r3
5028 movl -240(fp),r2
5029 bbc #31,r2,noname.455
5030 incl r9
5031noname.455:
5032 addl2 r2,r2
5033 bicl2 #0,r2
5034 bbc #31,r3,noname.456
5035 incl r2
5036noname.456:
5037 addl2 r3,r3
5038 bicl2 #0,r3
5039 addl2 r3,r8
5040 bicl2 #0,r8
5041 cmpl r8,r3
5042 bgequ noname.457
5043 incl r2
5044 bicl3 #0,r2,r0
5045 bneq noname.457
5046 incl r9
5047noname.457:
5048 addl2 r2,r7
5049 bicl2 #0,r7
5050 cmpl r7,r2
5051 bgequ noname.458
5052 incl r9
5053noname.458:
5054
5055 movl 8(ap),r0
5056 movzwl 26(r0),r2
5057 bicl3 #-65536,4(r0),r3
5058 movzwl 6(r0),r1
5059 bicl2 #-65536,r1
5060 bicl3 #-65536,24(r0),-252(fp)
5061 bicl3 #-65536,r2,-256(fp)
5062 mull3 r1,-252(fp),-244(fp)
5063 mull2 r3,-252(fp)
5064 mull3 r3,-256(fp),-248(fp)
5065 mull2 r1,-256(fp)
5066 addl3 -244(fp),-248(fp),r0
5067 bicl3 #0,r0,-244(fp)
5068 cmpl -244(fp),-248(fp)
5069 bgequ noname.459
5070 addl2 #65536,-256(fp)
5071noname.459:
5072 movzwl -242(fp),r0
5073 bicl2 #-65536,r0
5074 addl2 r0,-256(fp)
5075 bicl3 #-65536,-244(fp),r0
5076 ashl #16,r0,-248(fp)
5077 addl3 -248(fp),-252(fp),r0
5078 bicl3 #0,r0,-252(fp)
5079 cmpl -252(fp),-248(fp)
5080 bgequ noname.460
5081 incl -256(fp)
5082noname.460:
5083 movl -252(fp),r3
5084 movl -256(fp),r2
5085 bbc #31,r2,noname.461
5086 incl r9
5087noname.461:
5088 addl2 r2,r2
5089 bicl2 #0,r2
5090 bbc #31,r3,noname.462
5091 incl r2
5092noname.462:
5093 addl2 r3,r3
5094 bicl2 #0,r3
5095 addl2 r3,r8
5096 bicl2 #0,r8
5097 cmpl r8,r3
5098 bgequ noname.463
5099 incl r2
5100 bicl3 #0,r2,r0
5101 bneq noname.463
5102 incl r9
5103noname.463:
5104 addl2 r2,r7
5105 bicl2 #0,r7
5106 cmpl r7,r2
5107 bgequ noname.464
5108 incl r9
5109noname.464:
5110
5111 movl 8(ap),r0
5112 movzwl 22(r0),r2
5113 bicl3 #-65536,8(r0),r3
5114 movzwl 10(r0),r1
5115 bicl2 #-65536,r1
5116 bicl3 #-65536,20(r0),-268(fp)
5117 bicl3 #-65536,r2,-272(fp)
5118 mull3 r1,-268(fp),-260(fp)
5119 mull2 r3,-268(fp)
5120 mull3 r3,-272(fp),-264(fp)
5121 mull2 r1,-272(fp)
5122 addl3 -260(fp),-264(fp),r0
5123 bicl3 #0,r0,-260(fp)
5124 cmpl -260(fp),-264(fp)
5125 bgequ noname.465
5126 addl2 #65536,-272(fp)
5127noname.465:
5128 movzwl -258(fp),r0
5129 bicl2 #-65536,r0
5130 addl2 r0,-272(fp)
5131 bicl3 #-65536,-260(fp),r0
5132 ashl #16,r0,-264(fp)
5133 addl3 -264(fp),-268(fp),r0
5134 bicl3 #0,r0,-268(fp)
5135 cmpl -268(fp),-264(fp)
5136 bgequ noname.466
5137 incl -272(fp)
5138noname.466:
5139 movl -268(fp),r3
5140 movl -272(fp),r2
5141 bbc #31,r2,noname.467
5142 incl r9
5143noname.467:
5144 addl2 r2,r2
5145 bicl2 #0,r2
5146 bbc #31,r3,noname.468
5147 incl r2
5148noname.468:
5149 addl2 r3,r3
5150 bicl2 #0,r3
5151 addl2 r3,r8
5152 bicl2 #0,r8
5153 cmpl r8,r3
5154 bgequ noname.469
5155 incl r2
5156 bicl3 #0,r2,r0
5157 bneq noname.469
5158 incl r9
5159noname.469:
5160 addl2 r2,r7
5161 bicl2 #0,r7
5162 cmpl r7,r2
5163 bgequ noname.470
5164 incl r9
5165noname.470:
5166
5167 movl 8(ap),r0
5168 movzwl 18(r0),r2
5169 bicl3 #-65536,12(r0),r3
5170 movzwl 14(r0),r1
5171 bicl2 #-65536,r1
5172 bicl3 #-65536,16(r0),-284(fp)
5173 bicl3 #-65536,r2,-288(fp)
5174 mull3 r1,-284(fp),-276(fp)
5175 mull2 r3,-284(fp)
5176 mull3 r3,-288(fp),-280(fp)
5177 mull2 r1,-288(fp)
5178 addl3 -276(fp),-280(fp),r0
5179 bicl3 #0,r0,-276(fp)
5180 cmpl -276(fp),-280(fp)
5181 bgequ noname.471
5182 addl2 #65536,-288(fp)
5183noname.471:
5184 movzwl -274(fp),r0
5185 bicl2 #-65536,r0
5186 addl2 r0,-288(fp)
5187 bicl3 #-65536,-276(fp),r0
5188 ashl #16,r0,-280(fp)
5189 addl3 -280(fp),-284(fp),r0
5190 bicl3 #0,r0,-284(fp)
5191 cmpl -284(fp),-280(fp)
5192 bgequ noname.472
5193 incl -288(fp)
5194noname.472:
5195 movl -284(fp),r3
5196 movl -288(fp),r2
5197 bbc #31,r2,noname.473
5198 incl r9
5199noname.473:
5200 addl2 r2,r2
5201 bicl2 #0,r2
5202 bbc #31,r3,noname.474
5203 incl r2
5204noname.474:
5205 addl2 r3,r3
5206 bicl2 #0,r3
5207 addl2 r3,r8
5208 bicl2 #0,r8
5209 cmpl r8,r3
5210 bgequ noname.475
5211 incl r2
5212 bicl3 #0,r2,r0
5213 bneq noname.475
5214 incl r9
5215noname.475:
5216 addl2 r2,r7
5217 bicl2 #0,r7
5218 cmpl r7,r2
5219 bgequ noname.476
5220 incl r9
5221noname.476:
5222
5223 movl 4(ap),r0
5224 movl r8,28(r0)
5225
5226 clrl r8
5227
5228 movl 8(ap),r3
5229 movl 16(r3),r4
5230 bicl3 #-65536,r4,r5
5231 extzv #16,#16,r4,r0
5232 bicl3 #-65536,r0,r4
5233 mull3 r5,r4,-292(fp)
5234 mull2 r5,r5
5235 mull2 r4,r4
5236 bicl3 #32767,-292(fp),r0
5237 extzv #15,#17,r0,r0
5238 addl2 r0,r4
5239 bicl3 #-65536,-292(fp),r0
5240 ashl #17,r0,-292(fp)
5241 addl2 -292(fp),r5
5242 bicl2 #0,r5
5243 cmpl r5,-292(fp)
5244 bgequ noname.477
5245 incl r4
5246noname.477:
5247 movl r5,r1
5248 movl r4,r2
5249 addl2 r1,r7
5250 bicl2 #0,r7
5251 cmpl r7,r1
5252 bgequ noname.478
5253 incl r2
5254noname.478:
5255 addl2 r2,r9
5256 bicl2 #0,r9
5257 cmpl r9,r2
5258 bgequ noname.479
5259 incl r8
5260noname.479:
5261
5262 bicl3 #-65536,20(r3),r4
5263 movzwl 22(r3),r1
5264 bicl2 #-65536,r1
5265 bicl3 #-65536,12(r3),r2
5266 movzwl 14(r3),r0
5267 bicl2 #-65536,r0
5268 movl r4,r6
5269 movl r1,r5
5270 mull3 r0,r6,-296(fp)
5271 mull2 r2,r6
5272 mull3 r2,r5,-300(fp)
5273 mull2 r0,r5
5274 addl3 -296(fp),-300(fp),r0
5275 bicl3 #0,r0,-296(fp)
5276 cmpl -296(fp),-300(fp)
5277 bgequ noname.480
5278 addl2 #65536,r5
5279noname.480:
5280 movzwl -294(fp),r0
5281 bicl2 #-65536,r0
5282 addl2 r0,r5
5283 bicl3 #-65536,-296(fp),r0
5284 ashl #16,r0,-300(fp)
5285 addl2 -300(fp),r6
5286 bicl2 #0,r6
5287 cmpl r6,-300(fp)
5288 bgequ noname.481
5289 incl r5
5290noname.481:
5291 movl r6,r3
5292 movl r5,r2
5293 bbc #31,r2,noname.482
5294 incl r8
5295noname.482:
5296 addl2 r2,r2
5297 bicl2 #0,r2
5298 bbc #31,r3,noname.483
5299 incl r2
5300noname.483:
5301 addl2 r3,r3
5302 bicl2 #0,r3
5303 addl2 r3,r7
5304 bicl2 #0,r7
5305 cmpl r7,r3
5306 bgequ noname.484
5307 incl r2
5308 bicl3 #0,r2,r0
5309 bneq noname.484
5310 incl r8
5311noname.484:
5312 addl2 r2,r9
5313 bicl2 #0,r9
5314 cmpl r9,r2
5315 bgequ noname.485
5316 incl r8
5317noname.485:
5318
5319 movl 8(ap),r0
5320 bicl3 #-65536,24(r0),r3
5321 movzwl 26(r0),r1
5322 bicl2 #-65536,r1
5323 bicl3 #-65536,8(r0),r2
5324 movzwl 10(r0),r0
5325 bicl2 #-65536,r0
5326 movl r3,r5
5327 movl r1,r4
5328 mull3 r0,r5,-304(fp)
5329 mull2 r2,r5
5330 mull3 r2,r4,-308(fp)
5331 mull2 r0,r4
5332 addl3 -304(fp),-308(fp),r0
5333 bicl3 #0,r0,-304(fp)
5334 cmpl -304(fp),-308(fp)
5335 bgequ noname.486
5336 addl2 #65536,r4
5337noname.486:
5338 movzwl -302(fp),r0
5339 bicl2 #-65536,r0
5340 addl2 r0,r4
5341 bicl3 #-65536,-304(fp),r0
5342 ashl #16,r0,-308(fp)
5343 addl2 -308(fp),r5
5344 bicl2 #0,r5
5345 cmpl r5,-308(fp)
5346 bgequ noname.487
5347 incl r4
5348noname.487:
5349 movl r5,r3
5350 movl r4,r2
5351 bbc #31,r2,noname.488
5352 incl r8
5353noname.488:
5354 addl2 r2,r2
5355 bicl2 #0,r2
5356 bbc #31,r3,noname.489
5357 incl r2
5358noname.489:
5359 addl2 r3,r3
5360 bicl2 #0,r3
5361 addl2 r3,r7
5362 bicl2 #0,r7
5363 cmpl r7,r3
5364 bgequ noname.490
5365 incl r2
5366 bicl3 #0,r2,r0
5367 bneq noname.490
5368 incl r8
5369noname.490:
5370 addl2 r2,r9
5371 bicl2 #0,r9
5372 cmpl r9,r2
5373 bgequ noname.491
5374 incl r8
5375noname.491:
5376
5377 movl 8(ap),r0
5378 bicl3 #-65536,28(r0),r3
5379 movzwl 30(r0),r1
5380 bicl2 #-65536,r1
5381 bicl3 #-65536,4(r0),r2
5382 movzwl 6(r0),r0
5383 bicl2 #-65536,r0
5384 movl r3,r5
5385 movl r1,r4
5386 mull3 r0,r5,-312(fp)
5387 mull2 r2,r5
5388 mull3 r2,r4,-316(fp)
5389 mull2 r0,r4
5390 addl3 -312(fp),-316(fp),r0
5391 bicl3 #0,r0,-312(fp)
5392 cmpl -312(fp),-316(fp)
5393 bgequ noname.492
5394 addl2 #65536,r4
5395noname.492:
5396 movzwl -310(fp),r0
5397 bicl2 #-65536,r0
5398 addl2 r0,r4
5399 bicl3 #-65536,-312(fp),r0
5400 ashl #16,r0,-316(fp)
5401 addl2 -316(fp),r5
5402 bicl2 #0,r5
5403 cmpl r5,-316(fp)
5404 bgequ noname.493
5405 incl r4
5406noname.493:
5407 movl r5,r3
5408 movl r4,r2
5409 bbc #31,r2,noname.494
5410 incl r8
5411noname.494:
5412 addl2 r2,r2
5413 bicl2 #0,r2
5414 bbc #31,r3,noname.495
5415 incl r2
5416noname.495:
5417 addl2 r3,r3
5418 bicl2 #0,r3
5419 addl2 r3,r7
5420 bicl2 #0,r7
5421 cmpl r7,r3
5422 bgequ noname.496
5423 incl r2
5424 bicl3 #0,r2,r0
5425 bneq noname.496
5426 incl r8
5427noname.496:
5428 addl2 r2,r9
5429 bicl2 #0,r9
5430 cmpl r9,r2
5431 bgequ noname.497
5432 incl r8
5433noname.497:
5434
5435 movl 4(ap),r0
5436 movl r7,32(r0)
5437
5438 clrl r7
5439
5440 movl 8(ap),r0
5441 bicl3 #-65536,28(r0),r3
5442 movzwl 30(r0),r2
5443 bicl3 #-65536,8(r0),r1
5444 movzwl 10(r0),r0
5445 bicl2 #-65536,r0
5446 movl r3,r4
5447 bicl3 #-65536,r2,-328(fp)
5448 mull3 r0,r4,-320(fp)
5449 mull2 r1,r4
5450 mull3 r1,-328(fp),-324(fp)
5451 mull2 r0,-328(fp)
5452 addl3 -320(fp),-324(fp),r0
5453 bicl3 #0,r0,-320(fp)
5454 cmpl -320(fp),-324(fp)
5455 bgequ noname.498
5456 addl2 #65536,-328(fp)
5457noname.498:
5458 movzwl -318(fp),r0
5459 bicl2 #-65536,r0
5460 addl2 r0,-328(fp)
5461 bicl3 #-65536,-320(fp),r0
5462 ashl #16,r0,-324(fp)
5463 addl2 -324(fp),r4
5464 bicl2 #0,r4
5465 cmpl r4,-324(fp)
5466 bgequ noname.499
5467 incl -328(fp)
5468noname.499:
5469 movl r4,r3
5470 movl -328(fp),r2
5471 bbc #31,r2,noname.500
5472 incl r7
5473noname.500:
5474 addl2 r2,r2
5475 bicl2 #0,r2
5476 bbc #31,r3,noname.501
5477 incl r2
5478noname.501:
5479 addl2 r3,r3
5480 bicl2 #0,r3
5481 addl2 r3,r9
5482 bicl2 #0,r9
5483 cmpl r9,r3
5484 bgequ noname.502
5485 incl r2
5486 bicl3 #0,r2,r0
5487 bneq noname.502
5488 incl r7
5489noname.502:
5490 addl2 r2,r8
5491 bicl2 #0,r8
5492 cmpl r8,r2
5493 bgequ noname.503
5494 incl r7
5495noname.503:
5496
5497 movl 8(ap),r0
5498 movzwl 26(r0),r2
5499 bicl3 #-65536,12(r0),r3
5500 movzwl 14(r0),r1
5501 bicl2 #-65536,r1
5502 bicl3 #-65536,24(r0),-340(fp)
5503 bicl3 #-65536,r2,-344(fp)
5504 mull3 r1,-340(fp),-332(fp)
5505 mull2 r3,-340(fp)
5506 mull3 r3,-344(fp),-336(fp)
5507 mull2 r1,-344(fp)
5508 addl3 -332(fp),-336(fp),r0
5509 bicl3 #0,r0,-332(fp)
5510 cmpl -332(fp),-336(fp)
5511 bgequ noname.504
5512 addl2 #65536,-344(fp)
5513noname.504:
5514 movzwl -330(fp),r0
5515 bicl2 #-65536,r0
5516 addl2 r0,-344(fp)
5517 bicl3 #-65536,-332(fp),r0
5518 ashl #16,r0,-336(fp)
5519 addl3 -336(fp),-340(fp),r0
5520 bicl3 #0,r0,-340(fp)
5521 cmpl -340(fp),-336(fp)
5522 bgequ noname.505
5523 incl -344(fp)
5524noname.505:
5525 movl -340(fp),r3
5526 movl -344(fp),r2
5527 bbc #31,r2,noname.506
5528 incl r7
5529noname.506:
5530 addl2 r2,r2
5531 bicl2 #0,r2
5532 bbc #31,r3,noname.507
5533 incl r2
5534noname.507:
5535 addl2 r3,r3
5536 bicl2 #0,r3
5537 addl2 r3,r9
5538 bicl2 #0,r9
5539 cmpl r9,r3
5540 bgequ noname.508
5541 incl r2
5542 bicl3 #0,r2,r0
5543 bneq noname.508
5544 incl r7
5545noname.508:
5546 addl2 r2,r8
5547 bicl2 #0,r8
5548 cmpl r8,r2
5549 bgequ noname.509
5550 incl r7
5551noname.509:
5552
5553 movl 8(ap),r0
5554 movzwl 22(r0),r2
5555 bicl3 #-65536,16(r0),r3
5556 movzwl 18(r0),r1
5557 bicl2 #-65536,r1
5558 bicl3 #-65536,20(r0),-356(fp)
5559 bicl3 #-65536,r2,-360(fp)
5560 mull3 r1,-356(fp),-348(fp)
5561 mull2 r3,-356(fp)
5562 mull3 r3,-360(fp),-352(fp)
5563 mull2 r1,-360(fp)
5564 addl3 -348(fp),-352(fp),r0
5565 bicl3 #0,r0,-348(fp)
5566 cmpl -348(fp),-352(fp)
5567 bgequ noname.510
5568 addl2 #65536,-360(fp)
5569noname.510:
5570 movzwl -346(fp),r0
5571 bicl2 #-65536,r0
5572 addl2 r0,-360(fp)
5573 bicl3 #-65536,-348(fp),r0
5574 ashl #16,r0,-352(fp)
5575 addl3 -352(fp),-356(fp),r0
5576 bicl3 #0,r0,-356(fp)
5577 cmpl -356(fp),-352(fp)
5578 bgequ noname.511
5579 incl -360(fp)
5580noname.511:
5581 movl -356(fp),r3
5582 movl -360(fp),r2
5583 bbc #31,r2,noname.512
5584 incl r7
5585noname.512:
5586 addl2 r2,r2
5587 bicl2 #0,r2
5588 bbc #31,r3,noname.513
5589 incl r2
5590noname.513:
5591 addl2 r3,r3
5592 bicl2 #0,r3
5593 addl2 r3,r9
5594 bicl2 #0,r9
5595 cmpl r9,r3
5596 bgequ noname.514
5597 incl r2
5598 bicl3 #0,r2,r0
5599 bneq noname.514
5600 incl r7
5601noname.514:
5602 addl2 r2,r8
5603 bicl2 #0,r8
5604 cmpl r8,r2
5605 bgequ noname.515
5606 incl r7
5607noname.515:
5608
5609 movl 4(ap),r0
5610 movl r9,36(r0)
5611
5612 clrl r9
5613
5614 movl 8(ap),r3
5615 movl 20(r3),r4
5616 bicl3 #-65536,r4,-364(fp)
5617 extzv #16,#16,r4,r0
5618 bicl3 #-65536,r0,r4
5619 movl -364(fp),r0
5620 mull3 r0,r4,-368(fp)
5621 mull3 r0,r0,-364(fp)
5622 mull2 r4,r4
5623 bicl3 #32767,-368(fp),r0
5624 extzv #15,#17,r0,r0
5625 addl2 r0,r4
5626 bicl3 #-65536,-368(fp),r0
5627 ashl #17,r0,-368(fp)
5628 addl3 -364(fp),-368(fp),r0
5629 bicl3 #0,r0,-364(fp)
5630 cmpl -364(fp),-368(fp)
5631 bgequ noname.516
5632 incl r4
5633noname.516:
5634 movl -364(fp),r1
5635 movl r4,r2
5636 addl2 r1,r8
5637 bicl2 #0,r8
5638 cmpl r8,r1
5639 bgequ noname.517
5640 incl r2
5641noname.517:
5642 addl2 r2,r7
5643 bicl2 #0,r7
5644 cmpl r7,r2
5645 bgequ noname.518
5646 incl r9
5647noname.518:
5648
5649 bicl3 #-65536,24(r3),r4
5650 movzwl 26(r3),r1
5651 bicl2 #-65536,r1
5652 bicl3 #-65536,16(r3),r2
5653 movzwl 18(r3),r0
5654 bicl2 #-65536,r0
5655 movl r4,r6
5656 movl r1,r5
5657 mull3 r0,r6,-372(fp)
5658 mull2 r2,r6
5659 mull3 r2,r5,-376(fp)
5660 mull2 r0,r5
5661 addl3 -372(fp),-376(fp),r0
5662 bicl3 #0,r0,-372(fp)
5663 cmpl -372(fp),-376(fp)
5664 bgequ noname.519
5665 addl2 #65536,r5
5666noname.519:
5667 movzwl -370(fp),r0
5668 bicl2 #-65536,r0
5669 addl2 r0,r5
5670 bicl3 #-65536,-372(fp),r0
5671 ashl #16,r0,-376(fp)
5672 addl2 -376(fp),r6
5673 bicl2 #0,r6
5674 cmpl r6,-376(fp)
5675 bgequ noname.520
5676 incl r5
5677noname.520:
5678 movl r6,r3
5679 movl r5,r2
5680 bbc #31,r2,noname.521
5681 incl r9
5682noname.521:
5683 addl2 r2,r2
5684 bicl2 #0,r2
5685 bbc #31,r3,noname.522
5686 incl r2
5687noname.522:
5688 addl2 r3,r3
5689 bicl2 #0,r3
5690 addl2 r3,r8
5691 bicl2 #0,r8
5692 cmpl r8,r3
5693 bgequ noname.523
5694 incl r2
5695 bicl3 #0,r2,r0
5696 bneq noname.523
5697 incl r9
5698noname.523:
5699 addl2 r2,r7
5700 bicl2 #0,r7
5701 cmpl r7,r2
5702 bgequ noname.524
5703 incl r9
5704noname.524:
5705
5706 movl 8(ap),r0
5707 bicl3 #-65536,28(r0),r3
5708 movzwl 30(r0),r1
5709 bicl2 #-65536,r1
5710 bicl3 #-65536,12(r0),r2
5711 movzwl 14(r0),r0
5712 bicl2 #-65536,r0
5713 movl r3,r5
5714 movl r1,r4
5715 mull3 r0,r5,-380(fp)
5716 mull2 r2,r5
5717 mull3 r2,r4,-384(fp)
5718 mull2 r0,r4
5719 addl3 -380(fp),-384(fp),r0
5720 bicl3 #0,r0,-380(fp)
5721 cmpl -380(fp),-384(fp)
5722 bgequ noname.525
5723 addl2 #65536,r4
5724noname.525:
5725 movzwl -378(fp),r0
5726 bicl2 #-65536,r0
5727 addl2 r0,r4
5728 bicl3 #-65536,-380(fp),r0
5729 ashl #16,r0,-384(fp)
5730 addl2 -384(fp),r5
5731 bicl2 #0,r5
5732 cmpl r5,-384(fp)
5733 bgequ noname.526
5734 incl r4
5735noname.526:
5736 movl r5,r3
5737 movl r4,r2
5738 bbc #31,r2,noname.527
5739 incl r9
5740noname.527:
5741 addl2 r2,r2
5742 bicl2 #0,r2
5743 bbc #31,r3,noname.528
5744 incl r2
5745noname.528:
5746 addl2 r3,r3
5747 bicl2 #0,r3
5748 addl2 r3,r8
5749 bicl2 #0,r8
5750 cmpl r8,r3
5751 bgequ noname.529
5752 incl r2
5753 bicl3 #0,r2,r0
5754 bneq noname.529
5755 incl r9
5756noname.529:
5757 addl2 r2,r7
5758 bicl2 #0,r7
5759 cmpl r7,r2
5760 bgequ noname.530
5761 incl r9
5762noname.530:
5763 movl 4(ap),r0
5764 movl r8,40(r0)
5765
5766 clrl r8
5767
5768 movl 8(ap),r0
5769 bicl3 #-65536,28(r0),r3
5770 movzwl 30(r0),r1
5771 bicl2 #-65536,r1
5772 bicl3 #-65536,16(r0),r2
5773 movzwl 18(r0),r0
5774 bicl2 #-65536,r0
5775 movl r3,r5
5776 movl r1,r4
5777 mull3 r0,r5,-388(fp)
5778 mull2 r2,r5
5779 mull3 r2,r4,-392(fp)
5780 mull2 r0,r4
5781 addl3 -388(fp),-392(fp),r0
5782 bicl3 #0,r0,-388(fp)
5783 cmpl -388(fp),-392(fp)
5784 bgequ noname.531
5785 addl2 #65536,r4
5786noname.531:
5787 movzwl -386(fp),r0
5788 bicl2 #-65536,r0
5789 addl2 r0,r4
5790 bicl3 #-65536,-388(fp),r0
5791 ashl #16,r0,-392(fp)
5792 addl2 -392(fp),r5
5793 bicl2 #0,r5
5794 cmpl r5,-392(fp)
5795 bgequ noname.532
5796 incl r4
5797noname.532:
5798 movl r5,r3
5799 movl r4,r2
5800 bbc #31,r2,noname.533
5801 incl r8
5802noname.533:
5803 addl2 r2,r2
5804 bicl2 #0,r2
5805 bbc #31,r3,noname.534
5806 incl r2
5807noname.534:
5808 addl2 r3,r3
5809 bicl2 #0,r3
5810 addl2 r3,r7
5811 bicl2 #0,r7
5812 cmpl r7,r3
5813 bgequ noname.535
5814 incl r2
5815 bicl3 #0,r2,r0
5816 bneq noname.535
5817 incl r8
5818noname.535:
5819 addl2 r2,r9
5820 bicl2 #0,r9
5821 cmpl r9,r2
5822 bgequ noname.536
5823 incl r8
5824noname.536:
5825
5826 movl 8(ap),r0
5827 bicl3 #-65536,24(r0),r3
5828 movzwl 26(r0),r1
5829 bicl2 #-65536,r1
5830 bicl3 #-65536,20(r0),r2
5831 movzwl 22(r0),r0
5832 bicl2 #-65536,r0
5833 movl r3,r5
5834 movl r1,r4
5835 mull3 r0,r5,-396(fp)
5836 mull2 r2,r5
5837 mull3 r2,r4,-400(fp)
5838 mull2 r0,r4
5839 addl3 -396(fp),-400(fp),r0
5840 bicl3 #0,r0,-396(fp)
5841 cmpl -396(fp),-400(fp)
5842 bgequ noname.537
5843 addl2 #65536,r4
5844noname.537:
5845 movzwl -394(fp),r0
5846 bicl2 #-65536,r0
5847 addl2 r0,r4
5848 bicl3 #-65536,-396(fp),r0
5849 ashl #16,r0,-400(fp)
5850 addl2 -400(fp),r5
5851 bicl2 #0,r5
5852 cmpl r5,-400(fp)
5853 bgequ noname.538
5854 incl r4
5855noname.538:
5856 movl r5,r3
5857 movl r4,r2
5858 bbc #31,r2,noname.539
5859 incl r8
5860noname.539:
5861 addl2 r2,r2
5862 bicl2 #0,r2
5863 bbc #31,r3,noname.540
5864 incl r2
5865noname.540:
5866 addl2 r3,r3
5867 bicl2 #0,r3
5868 addl2 r3,r7
5869 bicl2 #0,r7
5870 cmpl r7,r3
5871 bgequ noname.541
5872 incl r2
5873 bicl3 #0,r2,r0
5874 bneq noname.541
5875 incl r8
5876noname.541:
5877 addl2 r2,r9
5878 bicl2 #0,r9
5879 cmpl r9,r2
5880 bgequ noname.542
5881 incl r8
5882noname.542:
5883
5884 movl 4(ap),r0
5885 movl r7,44(r0)
5886
5887 clrl r7
5888
5889 movl 8(ap),r3
5890 movl 24(r3),r4
5891 bicl3 #-65536,r4,r5
5892 extzv #16,#16,r4,r0
5893 bicl3 #-65536,r0,r4
5894 mull3 r5,r4,-404(fp)
5895 mull2 r5,r5
5896 mull2 r4,r4
5897 bicl3 #32767,-404(fp),r0
5898 extzv #15,#17,r0,r0
5899 addl2 r0,r4
5900 bicl3 #-65536,-404(fp),r0
5901 ashl #17,r0,-404(fp)
5902 addl2 -404(fp),r5
5903 bicl2 #0,r5
5904 cmpl r5,-404(fp)
5905 bgequ noname.543
5906 incl r4
5907noname.543:
5908 movl r5,r1
5909 movl r4,r2
5910 addl2 r1,r9
5911 bicl2 #0,r9
5912 cmpl r9,r1
5913 bgequ noname.544
5914 incl r2
5915noname.544:
5916 addl2 r2,r8
5917 bicl2 #0,r8
5918 cmpl r8,r2
5919 bgequ noname.545
5920 incl r7
5921noname.545:
5922
5923 movzwl 30(r3),r2
5924 bicl3 #-65536,20(r3),r1
5925 movzwl 22(r3),r0
5926 bicl2 #-65536,r0
5927 bicl3 #-65536,28(r3),-416(fp)
5928 bicl3 #-65536,r2,-420(fp)
5929 mull3 r0,-416(fp),-408(fp)
5930 mull2 r1,-416(fp)
5931 mull3 r1,-420(fp),-412(fp)
5932 mull2 r0,-420(fp)
5933 addl3 -408(fp),-412(fp),r0
5934 bicl3 #0,r0,-408(fp)
5935 cmpl -408(fp),-412(fp)
5936 bgequ noname.546
5937 addl2 #65536,-420(fp)
5938noname.546:
5939 movzwl -406(fp),r0
5940 bicl2 #-65536,r0
5941 addl2 r0,-420(fp)
5942 bicl3 #-65536,-408(fp),r0
5943 ashl #16,r0,-412(fp)
5944 addl3 -412(fp),-416(fp),r0
5945 bicl3 #0,r0,-416(fp)
5946 cmpl -416(fp),-412(fp)
5947 bgequ noname.547
5948 incl -420(fp)
5949noname.547:
5950 movl -416(fp),r3
5951 movl -420(fp),r2
5952 bbc #31,r2,noname.548
5953 incl r7
5954noname.548:
5955 addl2 r2,r2
5956 bicl2 #0,r2
5957 bbc #31,r3,noname.549
5958 incl r2
5959noname.549:
5960 addl2 r3,r3
5961 bicl2 #0,r3
5962 addl2 r3,r9
5963 bicl2 #0,r9
5964 cmpl r9,r3
5965 bgequ noname.550
5966 incl r2
5967 bicl3 #0,r2,r0
5968 bneq noname.550
5969 incl r7
5970noname.550:
5971 addl2 r2,r8
5972 bicl2 #0,r8
5973 cmpl r8,r2
5974 bgequ noname.551
5975 incl r7
5976noname.551:
5977
5978 movl 4(ap),r0
5979 movl r9,48(r0)
5980
5981 clrl r9
5982
5983 movl 8(ap),r0
5984 movzwl 30(r0),r2
5985 bicl3 #-65536,24(r0),r3
5986 movzwl 26(r0),r1
5987 bicl2 #-65536,r1
5988 bicl3 #-65536,28(r0),-432(fp)
5989 bicl3 #-65536,r2,-436(fp)
5990 mull3 r1,-432(fp),-424(fp)
5991 mull2 r3,-432(fp)
5992 mull3 r3,-436(fp),-428(fp)
5993 mull2 r1,-436(fp)
5994 addl3 -424(fp),-428(fp),r0
5995 bicl3 #0,r0,-424(fp)
5996 cmpl -424(fp),-428(fp)
5997 bgequ noname.552
5998 addl2 #65536,-436(fp)
5999noname.552:
6000 movzwl -422(fp),r0
6001 bicl2 #-65536,r0
6002 addl2 r0,-436(fp)
6003 bicl3 #-65536,-424(fp),r0
6004 ashl #16,r0,-428(fp)
6005 addl3 -428(fp),-432(fp),r0
6006 bicl3 #0,r0,-432(fp)
6007 cmpl -432(fp),-428(fp)
6008 bgequ noname.553
6009 incl -436(fp)
6010noname.553:
6011 movl -432(fp),r3
6012 movl -436(fp),r2
6013 bbc #31,r2,noname.554
6014 incl r9
6015noname.554:
6016 addl2 r2,r2
6017 bicl2 #0,r2
6018 bbc #31,r3,noname.555
6019 incl r2
6020noname.555:
6021 addl2 r3,r3
6022 bicl2 #0,r3
6023 addl2 r3,r8
6024 bicl2 #0,r8
6025 cmpl r8,r3
6026 bgequ noname.556
6027 incl r2
6028 bicl3 #0,r2,r0
6029 bneq noname.556
6030 incl r9
6031noname.556:
6032 addl2 r2,r7
6033 bicl2 #0,r7
6034 cmpl r7,r2
6035 bgequ noname.557
6036 incl r9
6037noname.557:
6038
6039 movl 4(ap),r4
6040 movl r8,52(r4)
6041
6042 clrl r8
6043
6044 movl 8(ap),r0
6045 movl 28(r0),r3
6046 bicl3 #-65536,r3,-440(fp)
6047 extzv #16,#16,r3,r0
6048 bicl3 #-65536,r0,r3
6049 movl -440(fp),r0
6050 mull3 r0,r3,-444(fp)
6051 mull3 r0,r0,-440(fp)
6052 mull2 r3,r3
6053 bicl3 #32767,-444(fp),r0
6054 extzv #15,#17,r0,r0
6055 addl2 r0,r3
6056 bicl3 #-65536,-444(fp),r0
6057 ashl #17,r0,-444(fp)
6058 addl3 -440(fp),-444(fp),r0
6059 bicl3 #0,r0,-440(fp)
6060 cmpl -440(fp),-444(fp)
6061 bgequ noname.558
6062 incl r3
6063noname.558:
6064 movl -440(fp),r1
6065 movl r3,r2
6066 addl2 r1,r7
6067 bicl2 #0,r7
6068 cmpl r7,r1
6069 bgequ noname.559
6070 incl r2
6071noname.559:
6072 addl2 r2,r9
6073 bicl2 #0,r9
6074 cmpl r9,r2
6075 bgequ noname.560
6076 incl r8
6077noname.560:
6078
6079 movl r7,56(r4)
6080
6081 movl r9,60(r4)
6082
6083 ret
6084
6085
6086
6087;r=4 ;(AP)
6088;a=8 ;(AP)
6089;b=12 ;(AP)
6090;n=16 ;(AP) n by value (input)
6091
6092 .psect code,nowrt
6093
6094.entry BN_SQR_COMBA4,^m<r2,r3,r4,r5,r6,r7,r8,r9,r10>
6095 subl2 #44,sp
6096
6097 clrq r8
6098
6099 clrl r10
6100
6101 movl 8(ap),r5
6102 movl (r5),r3
6103 bicl3 #-65536,r3,r4
6104 extzv #16,#16,r3,r0
6105 bicl3 #-65536,r0,r3
6106 mull3 r4,r3,-4(fp)
6107 mull2 r4,r4
6108 mull2 r3,r3
6109 bicl3 #32767,-4(fp),r0
6110 extzv #15,#17,r0,r0
6111 addl2 r0,r3
6112 bicl3 #-65536,-4(fp),r0
6113 ashl #17,r0,-4(fp)
6114 addl2 -4(fp),r4
6115 bicl2 #0,r4
6116 cmpl r4,-4(fp)
6117 bgequ noname.563
6118 incl r3
6119noname.563:
6120 movl r4,r1
6121 movl r3,r2
6122 addl2 r1,r9
6123 bicl2 #0,r9
6124 cmpl r9,r1
6125 bgequ noname.564
6126 incl r2
6127noname.564:
6128 addl2 r2,r8
6129 bicl2 #0,r8
6130 cmpl r8,r2
6131 bgequ noname.565
6132 incl r10
6133noname.565:
6134
6135 movl r9,@4(ap)
6136
6137 clrl r9
6138
6139 bicl3 #-65536,4(r5),r3
6140 movzwl 6(r5),r1
6141 bicl2 #-65536,r1
6142 bicl3 #-65536,(r5),r2
6143 movzwl 2(r5),r0
6144 bicl2 #-65536,r0
6145 movl r3,r6
6146 movl r1,r4
6147 mull3 r0,r6,-8(fp)
6148 mull2 r2,r6
6149 mull2 r4,r2
6150 mull2 r0,r4
6151 addl3 -8(fp),r2,r0
6152 bicl3 #0,r0,-8(fp)
6153 cmpl -8(fp),r2
6154 bgequ noname.566
6155 addl2 #65536,r4
6156noname.566:
6157 movzwl -6(fp),r0
6158 bicl2 #-65536,r0
6159 addl2 r0,r4
6160 bicl3 #-65536,-8(fp),r0
6161 ashl #16,r0,r1
6162 addl2 r1,r6
6163 bicl2 #0,r6
6164 cmpl r6,r1
6165 bgequ noname.567
6166 incl r4
6167noname.567:
6168 movl r6,r3
6169 movl r4,r2
6170 bbc #31,r2,noname.568
6171 incl r9
6172noname.568:
6173 addl2 r2,r2
6174 bicl2 #0,r2
6175 bbc #31,r3,noname.569
6176 incl r2
6177noname.569:
6178 addl2 r3,r3
6179 bicl2 #0,r3
6180 addl2 r3,r8
6181 bicl2 #0,r8
6182 cmpl r8,r3
6183 bgequ noname.570
6184 incl r2
6185 bicl3 #0,r2,r0
6186 bneq noname.570
6187 incl r9
6188noname.570:
6189 addl2 r2,r10
6190 bicl2 #0,r10
6191 cmpl r10,r2
6192 bgequ noname.571
6193 incl r9
6194noname.571:
6195
6196 movl 4(ap),r0
6197 movl r8,4(r0)
6198
6199 clrl r8
6200
6201 movl 8(ap),r4
6202 movl 4(r4),r3
6203 bicl3 #-65536,r3,r5
6204 extzv #16,#16,r3,r0
6205 bicl3 #-65536,r0,r3
6206 mull3 r5,r3,r1
6207 mull2 r5,r5
6208 mull2 r3,r3
6209 bicl3 #32767,r1,r0
6210 extzv #15,#17,r0,r0
6211 addl2 r0,r3
6212 bicl2 #-65536,r1
6213 ashl #17,r1,r1
6214 addl2 r1,r5
6215 bicl2 #0,r5
6216 cmpl r5,r1
6217 bgequ noname.572
6218 incl r3
6219noname.572:
6220 movl r5,r1
6221 movl r3,r2
6222 addl2 r1,r10
6223 bicl2 #0,r10
6224 cmpl r10,r1
6225 bgequ noname.573
6226 incl r2
6227noname.573:
6228 addl2 r2,r9
6229 bicl2 #0,r9
6230 cmpl r9,r2
6231 bgequ noname.574
6232 incl r8
6233noname.574:
6234
6235 bicl3 #-65536,8(r4),r3
6236 movzwl 10(r4),r1
6237 bicl2 #-65536,r1
6238 bicl3 #-65536,(r4),r2
6239 movzwl 2(r4),r0
6240 bicl2 #-65536,r0
6241 movl r3,r6
6242 movl r1,r5
6243 mull3 r0,r6,r7
6244 mull2 r2,r6
6245 mull2 r5,r2
6246 mull2 r0,r5
6247 addl2 r2,r7
6248 bicl2 #0,r7
6249 cmpl r7,r2
6250 bgequ noname.575
6251 addl2 #65536,r5
6252noname.575:
6253 extzv #16,#16,r7,r0
6254 bicl2 #-65536,r0
6255 addl2 r0,r5
6256 bicl3 #-65536,r7,r0
6257 ashl #16,r0,r1
6258 addl2 r1,r6
6259 bicl2 #0,r6
6260 cmpl r6,r1
6261 bgequ noname.576
6262 incl r5
6263noname.576:
6264 movl r6,r3
6265 movl r5,r2
6266 bbc #31,r2,noname.577
6267 incl r8
6268noname.577:
6269 addl2 r2,r2
6270 bicl2 #0,r2
6271 bbc #31,r3,noname.578
6272 incl r2
6273noname.578:
6274 addl2 r3,r3
6275 bicl2 #0,r3
6276 addl2 r3,r10
6277 bicl2 #0,r10
6278 cmpl r10,r3
6279 bgequ noname.579
6280 incl r2
6281 bicl3 #0,r2,r0
6282 bneq noname.579
6283 incl r8
6284noname.579:
6285 addl2 r2,r9
6286 bicl2 #0,r9
6287 cmpl r9,r2
6288 bgequ noname.580
6289 incl r8
6290noname.580:
6291
6292 movl 4(ap),r0
6293 movl r10,8(r0)
6294
6295 clrl r10
6296
6297 movl 8(ap),r0
6298 bicl3 #-65536,12(r0),r3
6299 movzwl 14(r0),r1
6300 bicl2 #-65536,r1
6301 bicl3 #-65536,(r0),r2
6302 movzwl 2(r0),r0
6303 bicl2 #-65536,r0
6304 movl r3,r5
6305 movl r1,r4
6306 mull3 r0,r5,r6
6307 mull2 r2,r5
6308 mull3 r2,r4,-12(fp)
6309 mull2 r0,r4
6310 addl2 -12(fp),r6
6311 bicl2 #0,r6
6312 cmpl r6,-12(fp)
6313 bgequ noname.581
6314 addl2 #65536,r4
6315noname.581:
6316 extzv #16,#16,r6,r0
6317 bicl2 #-65536,r0
6318 addl2 r0,r4
6319 bicl3 #-65536,r6,r0
6320 ashl #16,r0,-12(fp)
6321 addl2 -12(fp),r5
6322 bicl2 #0,r5
6323 cmpl r5,-12(fp)
6324 bgequ noname.582
6325 incl r4
6326noname.582:
6327 movl r5,r3
6328 movl r4,r2
6329 bbc #31,r2,noname.583
6330 incl r10
6331noname.583:
6332 addl2 r2,r2
6333 bicl2 #0,r2
6334 bbc #31,r3,noname.584
6335 incl r2
6336noname.584:
6337 addl2 r3,r3
6338 bicl2 #0,r3
6339 addl2 r3,r9
6340 bicl2 #0,r9
6341 cmpl r9,r3
6342 bgequ noname.585
6343 incl r2
6344 bicl3 #0,r2,r0
6345 bneq noname.585
6346 incl r10
6347noname.585:
6348 addl2 r2,r8
6349 bicl2 #0,r8
6350 cmpl r8,r2
6351 bgequ noname.586
6352 incl r10
6353noname.586:
6354
6355 movl 8(ap),r0
6356 bicl3 #-65536,8(r0),r3
6357 movzwl 10(r0),r1
6358 bicl2 #-65536,r1
6359 bicl3 #-65536,4(r0),r2
6360 movzwl 6(r0),r0
6361 bicl2 #-65536,r0
6362 movl r3,r5
6363 movl r1,r4
6364 mull3 r0,r5,-16(fp)
6365 mull2 r2,r5
6366 mull3 r2,r4,-20(fp)
6367 mull2 r0,r4
6368 addl3 -16(fp),-20(fp),r0
6369 bicl3 #0,r0,-16(fp)
6370 cmpl -16(fp),-20(fp)
6371 bgequ noname.587
6372 addl2 #65536,r4
6373noname.587:
6374 movzwl -14(fp),r0
6375 bicl2 #-65536,r0
6376 addl2 r0,r4
6377 bicl3 #-65536,-16(fp),r0
6378 ashl #16,r0,-20(fp)
6379 addl2 -20(fp),r5
6380 bicl2 #0,r5
6381 cmpl r5,-20(fp)
6382 bgequ noname.588
6383 incl r4
6384noname.588:
6385 movl r5,r3
6386 movl r4,r2
6387 bbc #31,r2,noname.589
6388 incl r10
6389noname.589:
6390 addl2 r2,r2
6391 bicl2 #0,r2
6392 bbc #31,r3,noname.590
6393 incl r2
6394noname.590:
6395 addl2 r3,r3
6396 bicl2 #0,r3
6397 addl2 r3,r9
6398 bicl2 #0,r9
6399 cmpl r9,r3
6400 bgequ noname.591
6401 incl r2
6402 bicl3 #0,r2,r0
6403 bneq noname.591
6404 incl r10
6405noname.591:
6406 addl2 r2,r8
6407 bicl2 #0,r8
6408 cmpl r8,r2
6409 bgequ noname.592
6410 incl r10
6411noname.592:
6412 movl 4(ap),r0
6413 movl r9,12(r0)
6414
6415 clrl r9
6416
6417 movl 8(ap),r3
6418 movl 8(r3),r4
6419 bicl3 #-65536,r4,r5
6420 extzv #16,#16,r4,r0
6421 bicl3 #-65536,r0,r4
6422 mull3 r5,r4,-24(fp)
6423 mull2 r5,r5
6424 mull2 r4,r4
6425 bicl3 #32767,-24(fp),r0
6426 extzv #15,#17,r0,r0
6427 addl2 r0,r4
6428 bicl3 #-65536,-24(fp),r0
6429 ashl #17,r0,-24(fp)
6430 addl2 -24(fp),r5
6431 bicl2 #0,r5
6432 cmpl r5,-24(fp)
6433 bgequ noname.593
6434 incl r4
6435noname.593:
6436 movl r5,r1
6437 movl r4,r2
6438 addl2 r1,r8
6439 bicl2 #0,r8
6440 cmpl r8,r1
6441 bgequ noname.594
6442 incl r2
6443noname.594:
6444 addl2 r2,r10
6445 bicl2 #0,r10
6446 cmpl r10,r2
6447 bgequ noname.595
6448 incl r9
6449noname.595:
6450
6451 bicl3 #-65536,12(r3),r4
6452 movzwl 14(r3),r1
6453 bicl2 #-65536,r1
6454 bicl3 #-65536,4(r3),r2
6455 movzwl 6(r3),r0
6456 bicl2 #-65536,r0
6457 movl r4,r6
6458 movl r1,r5
6459 mull3 r0,r6,-28(fp)
6460 mull2 r2,r6
6461 mull3 r2,r5,-32(fp)
6462 mull2 r0,r5
6463 addl3 -28(fp),-32(fp),r0
6464 bicl3 #0,r0,-28(fp)
6465 cmpl -28(fp),-32(fp)
6466 bgequ noname.596
6467 addl2 #65536,r5
6468noname.596:
6469 movzwl -26(fp),r0
6470 bicl2 #-65536,r0
6471 addl2 r0,r5
6472 bicl3 #-65536,-28(fp),r0
6473 ashl #16,r0,-32(fp)
6474 addl2 -32(fp),r6
6475 bicl2 #0,r6
6476 cmpl r6,-32(fp)
6477 bgequ noname.597
6478 incl r5
6479noname.597:
6480 movl r6,r3
6481 movl r5,r2
6482 bbc #31,r2,noname.598
6483 incl r9
6484noname.598:
6485 addl2 r2,r2
6486 bicl2 #0,r2
6487 bbc #31,r3,noname.599
6488 incl r2
6489noname.599:
6490 addl2 r3,r3
6491 bicl2 #0,r3
6492 addl2 r3,r8
6493 bicl2 #0,r8
6494 cmpl r8,r3
6495 bgequ noname.600
6496 incl r2
6497 bicl3 #0,r2,r0
6498 bneq noname.600
6499 incl r9
6500noname.600:
6501 addl2 r2,r10
6502 bicl2 #0,r10
6503 cmpl r10,r2
6504 bgequ noname.601
6505 incl r9
6506noname.601:
6507
6508 movl 4(ap),r0
6509 movl r8,16(r0)
6510
6511 clrl r8
6512
6513 movl 8(ap),r0
6514 bicl3 #-65536,12(r0),r3
6515 movzwl 14(r0),r1
6516 bicl2 #-65536,r1
6517 bicl3 #-65536,8(r0),r2
6518 movzwl 10(r0),r0
6519 bicl2 #-65536,r0
6520 movl r3,r5
6521 movl r1,r4
6522 mull3 r0,r5,-36(fp)
6523 mull2 r2,r5
6524 mull3 r2,r4,-40(fp)
6525 mull2 r0,r4
6526 addl3 -36(fp),-40(fp),r0
6527 bicl3 #0,r0,-36(fp)
6528 cmpl -36(fp),-40(fp)
6529 bgequ noname.602
6530 addl2 #65536,r4
6531noname.602:
6532 movzwl -34(fp),r0
6533 bicl2 #-65536,r0
6534 addl2 r0,r4
6535 bicl3 #-65536,-36(fp),r0
6536 ashl #16,r0,-40(fp)
6537 addl2 -40(fp),r5
6538 bicl2 #0,r5
6539 cmpl r5,-40(fp)
6540 bgequ noname.603
6541 incl r4
6542noname.603:
6543 movl r5,r3
6544 movl r4,r2
6545 bbc #31,r2,noname.604
6546 incl r8
6547noname.604:
6548 addl2 r2,r2
6549 bicl2 #0,r2
6550 bbc #31,r3,noname.605
6551 incl r2
6552noname.605:
6553 addl2 r3,r3
6554 bicl2 #0,r3
6555 addl2 r3,r10
6556 bicl2 #0,r10
6557 cmpl r10,r3
6558 bgequ noname.606
6559 incl r2
6560 bicl3 #0,r2,r0
6561 bneq noname.606
6562 incl r8
6563noname.606:
6564 addl2 r2,r9
6565 bicl2 #0,r9
6566 cmpl r9,r2
6567 bgequ noname.607
6568 incl r8
6569noname.607:
6570
6571 movl 4(ap),r4
6572 movl r10,20(r4)
6573
6574 clrl r10
6575
6576 movl 8(ap),r0
6577 movl 12(r0),r3
6578 bicl3 #-65536,r3,r5
6579 extzv #16,#16,r3,r0
6580 bicl3 #-65536,r0,r3
6581 mull3 r5,r3,-44(fp)
6582 mull2 r5,r5
6583 mull2 r3,r3
6584 bicl3 #32767,-44(fp),r0
6585 extzv #15,#17,r0,r0
6586 addl2 r0,r3
6587 bicl3 #-65536,-44(fp),r0
6588 ashl #17,r0,-44(fp)
6589 addl2 -44(fp),r5
6590 bicl2 #0,r5
6591 cmpl r5,-44(fp)
6592 bgequ noname.608
6593 incl r3
6594noname.608:
6595 movl r5,r1
6596 movl r3,r2
6597 addl2 r1,r9
6598 bicl2 #0,r9
6599 cmpl r9,r1
6600 bgequ noname.609
6601 incl r2
6602noname.609:
6603 addl2 r2,r8
6604 bicl2 #0,r8
6605 cmpl r8,r2
6606 bgequ noname.610
6607 incl r10
6608noname.610:
6609
6610 movl r9,24(r4)
6611
6612 movl r8,28(r4)
6613
6614 ret
6615
6616; For now, the code below doesn't work, so I end this prematurely.
6617.end
6618
6619 .title vax_bn_div64 division 64/32=>32
6620;
6621; r.l. 16-jan-1998
6622;
6623; unsigned int bn_div64(unsigned long h, unsigned long l, unsigned long d)
6624; return <h,l>/d;
6625;
6626
6627 .psect code,nowrt
6628
6629h=4 ;(AP) by value (input)
6630l=8 ;(AP) by value (input)
6631d=12 ;(AP) by value (input)
6632
6633.entry bn_div64,^m<r2,r3,r4,r5,r6,r7,r8,r9>
6634
6635 movl l(ap),r2 ; l
6636 movl h(ap),r3 ; h
6637 movl d(ap),r4 ; d
6638 clrl r5 ; q
6639 clrl r6 ; r
6640
6641 ; Treat "negative" specially
6642 tstl r3
6643 blss 30$
6644
6645 tstl r4
6646 beql 90$
6647
6648 ediv r4,r2,r5,r6
6649 bvs 666$
6650
6651 movl r5,r0
6652 ret
6653
665430$:
6655 ; The theory here is to do some harmless shifting and a little
6656 ; bit of rounding (brackets are to designate when decimals are
6657 ; cut off):
6658 ;
6659 ; result = 2 * [ ([<h,0>/2] + [d/2]) / d ] + [ l / d ]
6660
6661 movl #0,r7
6662 movl r3,r8 ; copy h
6663 ashq #-1,r7,r7 ; [<h,0>/2] => <r8,r7>
6664 bicl2 #^X80000000,r8 ; Remove "sign"
6665
6666 movl r4,r9 ; copy d
6667 ashl #-1,r9,r9 ; [d/2] => r9
6668 bicl2 #^X80000000,r9 ; Remove "sign"
6669
6670 addl2 r9,r7
6671 adwc #0,r8 ; [<h,0>/2] + [d/2] => <r8,r7>
6672
6673 ediv r4,r7,r5,r6 ; [ ([<h,0>/2] + [d/2]) / d ] => <r5,r6>
6674 bvs 666$
6675
6676 movl #0,r6
6677 ashq #1,r5,r5 ; 2 * [ ([<h,0>/2] + [d/2]) / d ] => r5
6678
6679 movl #0,r3
6680 ediv r4,r2,r8,r9 ; [ l / d ] => <r8,r9>
6681
6682 addl2 r8,r5 ;
6683 bcs 666$
6684
6685 movl r5,r0
6686 ret
6687
668890$:
6689 movl #-1,r0
6690 ret
6691
6692666$:
6693
6694
6695.end
diff --git a/src/lib/libcrypto/bn/asm/x86/f b/src/lib/libcrypto/bn/asm/x86/f
new file mode 100644
index 0000000000..22e4112224
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/x86/f
@@ -0,0 +1,3 @@
1#!/usr/local/bin/perl
2# x86 assember
3
diff --git a/src/lib/libcrypto/bn/bn.mul b/src/lib/libcrypto/bn/bn.mul
new file mode 100644
index 0000000000..9728870d38
--- /dev/null
+++ b/src/lib/libcrypto/bn/bn.mul
@@ -0,0 +1,19 @@
1We need
2
3* bn_mul_comba8
4* bn_mul_comba4
5* bn_mul_normal
6* bn_mul_recursive
7
8* bn_sqr_comba8
9* bn_sqr_comba4
10bn_sqr_normal -> BN_sqr
11* bn_sqr_recursive
12
13* bn_mul_low_recursive
14* bn_mul_low_normal
15* bn_mul_high
16
17* bn_mul_part_recursive # symetric but not power of 2
18
19bn_mul_asymetric_recursive # uneven, but do the chop up.
diff --git a/src/lib/libcrypto/bn/divtest.c b/src/lib/libcrypto/bn/divtest.c
new file mode 100644
index 0000000000..13ba86e3c4
--- /dev/null
+++ b/src/lib/libcrypto/bn/divtest.c
@@ -0,0 +1,41 @@
1#include <openssl/bn.h>
2#include <openssl/rand.h>
3
4static int rand(n)
5{
6 unsigned char x[2];
7 RAND_pseudo_bytes(x,2);
8 return (x[0] + 2*x[1]);
9}
10
11static void bug(char *m, BIGNUM *a, BIGNUM *b)
12{
13 printf("%s!\na=",m);
14 BN_print_fp(stdout, a);
15 printf("\nb=");
16 BN_print_fp(stdout, b);
17 printf("\n");
18 fflush(stdout);
19}
20
21main()
22{
23 BIGNUM *a=BN_new(), *b=BN_new(), *c=BN_new(), *d=BN_new(),
24 *C=BN_new(), *D=BN_new();
25 BN_RECP_CTX *recp=BN_RECP_CTX_new();
26 BN_CTX *ctx=BN_CTX_new();
27
28 for(;;) {
29 BN_pseudo_rand(a,rand(),0,0);
30 BN_pseudo_rand(b,rand(),0,0);
31 if (BN_is_zero(b)) continue;
32
33 BN_RECP_CTX_set(recp,b,ctx);
34 if (BN_div(C,D,a,b,ctx) != 1)
35 bug("BN_div failed",a,b);
36 if (BN_div_recp(c,d,a,recp,ctx) != 1)
37 bug("BN_div_recp failed",a,b);
38 else if (BN_cmp(c,C) != 0 || BN_cmp(c,C) != 0)
39 bug("mismatch",a,b);
40 }
41}
diff --git a/src/lib/libcrypto/bn/exp.c b/src/lib/libcrypto/bn/exp.c
new file mode 100644
index 0000000000..ec443459d8
--- /dev/null
+++ b/src/lib/libcrypto/bn/exp.c
@@ -0,0 +1,60 @@
1#include <stdio.h>
2#include <openssl/tmdiff.h>
3#include "bn_lcl.h"
4
5#define SIZE 256
6#define NUM (8*8*8)
7#define MOD (8*8*8*8*8)
8
9main(argc,argv)
10int argc;
11char *argv[];
12 {
13 BN_CTX ctx;
14 BIGNUM a,b,c,r,rr,t,l;
15 int j,i,size=SIZE,num=NUM,mod=MOD;
16 char *start,*end;
17 BN_MONT_CTX mont;
18 double d,md;
19
20 BN_MONT_CTX_init(&mont);
21 BN_CTX_init(&ctx);
22 BN_init(&a);
23 BN_init(&b);
24 BN_init(&c);
25 BN_init(&r);
26
27 start=ms_time_new();
28 end=ms_time_new();
29 while (size <= 1024*8)
30 {
31 BN_rand(&a,size,0,0);
32 BN_rand(&b,size,1,0);
33 BN_rand(&c,size,0,1);
34
35 BN_mod(&a,&a,&c,&ctx);
36
37 ms_time_get(start);
38 for (i=0; i<10; i++)
39 BN_MONT_CTX_set(&mont,&c,&ctx);
40 ms_time_get(end);
41 md=ms_time_diff(start,end);
42
43 ms_time_get(start);
44 for (i=0; i<num; i++)
45 {
46 /* bn_mull(&r,&a,&b,&ctx); */
47 /* BN_sqr(&r,&a,&ctx); */
48 BN_mod_exp_mont(&r,&a,&b,&c,&ctx,&mont);
49 }
50 ms_time_get(end);
51 d=ms_time_diff(start,end)/* *50/33 */;
52 printf("%5d bit:%6.2f %6d %6.4f %4d m_set(%5.4f)\n",size,
53 d,num,d/num,(int)((d/num)*mod),md/10.0);
54 num/=8;
55 mod/=8;
56 if (num <= 0) num=1;
57 size*=2;
58 }
59
60 }
diff --git a/src/lib/libcrypto/bn/todo b/src/lib/libcrypto/bn/todo
new file mode 100644
index 0000000000..e47e381aea
--- /dev/null
+++ b/src/lib/libcrypto/bn/todo
@@ -0,0 +1,3 @@
1Cache RECP_CTX values
2make the result argument independant of the inputs.
3split up the _exp_ functions
diff --git a/src/lib/libcrypto/bn/vms-helper.c b/src/lib/libcrypto/bn/vms-helper.c
new file mode 100644
index 0000000000..73af337069
--- /dev/null
+++ b/src/lib/libcrypto/bn/vms-helper.c
@@ -0,0 +1,66 @@
1/* vms-helper.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56#include <stdio.h>
57#include "cryptlib.h"
58#include "bn_lcl.h"
59
60bn_div_words_abort(int i)
61{
62#if !defined(NO_STDIO) && !defined(WIN16)
63 fprintf(stderr,"Division would overflow (%d)\n",i);
64#endif
65 abort();
66}
diff --git a/src/lib/libcrypto/crypto-lib.com b/src/lib/libcrypto/crypto-lib.com
new file mode 100644
index 0000000000..bf916528eb
--- /dev/null
+++ b/src/lib/libcrypto/crypto-lib.com
@@ -0,0 +1,1218 @@
1$!
2$! CRYPTO-LIB.COM
3$! Written By: Robert Byer
4$! Vice-President
5$! A-Com Computing, Inc.
6$! byer@mail.all-net.net
7$!
8$! Changes by Richard Levitte <richard@levitte.org>
9$!
10$! This command files compiles and creates the "[.xxx.EXE.CRYPTO]LIBCRYPTO.OLB"
11$! library for OpenSSL. The "xxx" denotes the machine architecture of AXP
12$! or VAX.
13$!
14$! It was re-written so it would try to determine what "C" compiler to use
15$! or you can specify which "C" compiler to use.
16$!
17$! Specify RSAREF as P1 to compile with the RSAREF library instead of
18$! the regular one. If you specify NORSAREF it will compile with the
19$! regular RSAREF routines. (Note: If you are in the United States
20$! you MUST compile with RSAREF unless you have a license from RSA).
21$!
22$! Note: The RSAREF libraries are NOT INCLUDED and you have to
23$! download it from "ftp://ftp.rsa.com/rsaref". You have to
24$! get the ".tar-Z" file as the ".zip" file dosen't have the
25$! directory structure stored. You have to extract the file
26$! into the [.RSAREF] directory under the root directory as that
27$! is where the scripts will look for the files.
28$!
29$! Specify DEBUG or NODEBUG as P2 to compile with or without debugger
30$! information.
31$!
32$! Specify which compiler at P3 to try to compile under.
33$!
34$! VAXC For VAX C.
35$! DECC For DEC C.
36$! GNUC For GNU C.
37$!
38$! If you don't speficy a compiler, it will try to determine which
39$! "C" compiler to use.
40$!
41$! P4, if defined, sets a TCP/IP library to use, through one of the following
42$! keywords:
43$!
44$! UCX for UCX
45$! SOCKETSHR for SOCKETSHR+NETLIB
46$!
47$! P5, if defined, sets a compiler thread NOT needed on OpenVMS 7.1 (and up)
48$!
49$! P6, if defined, sets a choice of crypto methods to compile.
50$! WARNING: this should only be done to recompile some part of an already
51$! fully compiled library.
52$!
53$!
54$! Define A TCP/IP Library That We Will Need To Link To.
55$! (That Is, If We Need To Link To One.)
56$!
57$ TCPIP_LIB = ""
58$!
59$! Check Which Architecture We Are Using.
60$!
61$ IF (F$GETSYI("CPU").GE.128)
62$ THEN
63$!
64$! The Architecture Is AXP
65$!
66$ ARCH := AXP
67$!
68$! Else...
69$!
70$ ELSE
71$!
72$! The Architecture Is VAX.
73$!
74$ ARCH := VAX
75$!
76$! End The Architecture Check.
77$!
78$ ENDIF
79$!
80$! Define The Different Encryption Types.
81$!
82$ ENCRYPT_TYPES = ",MD2,MD5,SHA,MDC2,HMAC,RIPEMD,"+ -
83 "DES,RC2,RC4,RC5,IDEA,BF,CAST,"+ -
84 "BN,RSA,DSA,DH,"+ -
85 "BUFFER,BIO,STACK,LHASH,RAND,ERR,OBJECTS,"+ -
86 "EVP,EVP_2,ASN1,ASN1_2,PEM,X509,X509V3,"+ -
87 "CONF,TXT_DB,PKCS7,PKCS12,COMP"
88$!
89$! Check To Make Sure We Have Valid Command Line Parameters.
90$!
91$ GOSUB CHECK_OPTIONS
92$!
93$! Initialise logical names and such
94$!
95$ GOSUB INITIALISE
96$!
97$! Tell The User What Kind of Machine We Run On.
98$!
99$ WRITE SYS$OUTPUT "Compiling On A ",ARCH," Machine."
100$!
101$! Define The OBJ Directory.
102$!
103$ OBJ_DIR := SYS$DISK:[-.'ARCH'.OBJ.CRYPTO]
104$!
105$! Check To See If The Architecture Specific OBJ Directory Exists.
106$!
107$ IF (F$PARSE(OBJ_DIR).EQS."")
108$ THEN
109$!
110$! It Dosen't Exist, So Create It.
111$!
112$ CREATE/DIR 'OBJ_DIR'
113$!
114$! End The Architecture Specific OBJ Directory Check.
115$!
116$ ENDIF
117$!
118$! Define The EXE Directory.
119$!
120$ EXE_DIR := SYS$DISK:[-.'ARCH'.EXE.CRYPTO]
121$!
122$! Check To See If The Architecture Specific Directory Exists.
123$!
124$ IF (F$PARSE(EXE_DIR).EQS."")
125$ THEN
126$!
127$! It Dosen't Exist, So Create It.
128$!
129$ CREATE/DIRECTORY 'EXE_DIR'
130$!
131$! End The Architecture Specific Directory Check.
132$!
133$ ENDIF
134$!
135$! Define The Library Name.
136$!
137$ LIB_NAME := 'EXE_DIR'LIBCRYPTO.OLB
138$!
139$! Check To See If We Already Have A "[.xxx.EXE.CRYPTO]LIBCRYPTO.OLB" Library...
140$!
141$ IF (F$SEARCH(LIB_NAME).EQS."")
142$ THEN
143$!
144$! Guess Not, Create The Library.
145$!
146$ LIBRARY/CREATE/OBJECT 'LIB_NAME'
147$!
148$! End The Library Check.
149$!
150$ ENDIF
151$!
152$! Define The Different Encryption "library" Strings.
153$!
154$ LIB_ = "cryptlib,mem,cversion,ex_data,tmdiff,cpt_err"
155$ LIB_MD2 = "md2_dgst,md2_one"
156$ LIB_MD5 = "md5_dgst,md5_one"
157$ LIB_SHA = "sha_dgst,sha1dgst,sha_one,sha1_one"
158$ LIB_MDC2 = "mdc2dgst,mdc2_one"
159$ LIB_HMAC = "hmac"
160$ LIB_RIPEMD = "rmd_dgst,rmd_one"
161$ LIB_DES = "set_key,ecb_enc,cbc_enc,"+ -
162 "ecb3_enc,cfb64enc,cfb64ede,cfb_enc,ofb64ede,"+ -
163 "enc_read,enc_writ,ofb64enc,"+ -
164 "ofb_enc,str2key,pcbc_enc,qud_cksm,rand_key,"+ -
165 "des_enc,fcrypt_b,read2pwd,"+ -
166 "fcrypt,xcbc_enc,read_pwd,rpc_enc,cbc_cksm,supp,ede_cbcm_enc"
167$ LIB_RC2 = "rc2_ecb,rc2_skey,rc2_cbc,rc2cfb64,rc2ofb64"
168$ LIB_RC4 = "rc4_skey,rc4_enc"
169$ LIB_RC5 = "rc5_skey,rc5_ecb,rc5_enc,rc5cfb64,rc5ofb64"
170$ LIB_IDEA = "i_cbc,i_cfb64,i_ofb64,i_ecb,i_skey"
171$ LIB_BF = "bf_skey,bf_ecb,bf_enc,bf_cfb64,bf_ofb64"
172$ LIB_CAST = "c_skey,c_ecb,c_enc,c_cfb64,c_ofb64"
173$ LIB_BN_ASM = "[.asm]vms.mar,vms-helper"
174$ IF F$TRNLNM("OPENSSL_NO_ASM") .NES. "" THEN LIB_BN_ASM = "bn_asm"
175$ LIB_BN = "bn_add,bn_div,bn_exp,bn_lib,bn_mul,"+ -
176 "bn_print,bn_rand,bn_shift,bn_word,bn_blind,"+ -
177 "bn_gcd,bn_prime,bn_err,bn_sqr,"+LIB_BN_ASM+",bn_recp,bn_mont,"+ -
178 "bn_mpi,bn_exp2"
179$ LIB_RSA = "rsa_eay,rsa_gen,rsa_lib,rsa_sign,rsa_saos,rsa_err,"+ -
180 "rsa_pk1,rsa_ssl,rsa_none,rsa_oaep,rsa_chk"
181$ LIB_DSA = "dsa_gen,dsa_key,dsa_lib,dsa_asn1,dsa_vrf,dsa_sign,dsa_err"
182$ LIB_DH = "dh_gen,dh_key,dh_lib,dh_check,dh_err"
183$ LIB_BUFFER = "buffer,buf_err"
184$ LIB_BIO = "bio_lib,bio_cb,bio_err,"+ -
185 "bss_mem,bss_null,bss_fd,"+ -
186 "bss_file,bss_sock,bss_conn,"+ -
187 "bf_null,bf_buff,b_print,b_dump,"+ -
188 "b_sock,bss_acpt,bf_nbio,bss_rtcp,bss_bio" ! + ",bss_log" for syslog
189$ LIB_STACK = "stack"
190$ LIB_LHASH = "lhash,lh_stats"
191$ LIB_RAND = "md_rand,randfile,rand_lib"
192$ LIB_ERR = "err,err_all,err_prn"
193$ LIB_OBJECTS = "o_names,obj_dat,obj_lib,obj_err"
194$ LIB_EVP = "encode,digest,evp_enc,evp_key,"+ -
195 "e_ecb_d,e_cbc_d,e_cfb_d,e_ofb_d,"+ -
196 "e_ecb_i,e_cbc_i,e_cfb_i,e_ofb_i,"+ -
197 "e_ecb_3d,e_cbc_3d,e_rc4,names,"+ -
198 "e_cfb_3d,e_ofb_3d,e_xcbc_d,"+ -
199 "e_ecb_r2,e_cbc_r2,e_cfb_r2,e_ofb_r2,"+ -
200 "e_ecb_bf,e_cbc_bf,e_cfb_bf,e_ofb_bf"
201$ LIB_EVP_2 = "e_ecb_c,e_cbc_c,e_cfb_c,e_ofb_c,"+ -
202 "e_ecb_r5,e_cbc_r5,e_cfb_r5,e_ofb_r5,"+ -
203 "m_null,m_md2,m_md5,m_sha,m_sha1,m_dss,m_dss1,m_mdc2,"+ -
204 "m_ripemd,"+ -
205 "p_open,p_seal,p_sign,p_verify,p_lib,p_enc,p_dec,"+ -
206 "bio_md,bio_b64,bio_enc,evp_err,e_null,"+ -
207 "c_all,evp_lib,bio_ok,evp_pkey,evp_pbe,p5_crpt,p5_crpt2"
208$ LIB_ASN1 = "a_object,a_bitstr,a_utctm,a_gentm,a_time,a_int,a_octet,"+ -
209 "a_print,a_type,a_set,a_dup,a_d2i_fp,a_i2d_fp,a_bmp,"+ -
210 "a_enum,a_vis,a_utf8,a_sign,a_digest,a_verify,"+ -
211 "x_algor,x_val,x_pubkey,x_sig,x_req,x_attrib,"+ -
212 "x_name,x_cinf,x_x509,x_crl,x_info,x_spki,nsseq,"+ -
213 "d2i_r_pr,i2d_r_pr,d2i_r_pu,i2d_r_pu,"+ -
214 "d2i_s_pr,i2d_s_pr,d2i_s_pu,i2d_s_pu,"+ -
215 "d2i_pu,d2i_pr,i2d_pu,i2d_pr"
216$ LIB_ASN1_2 = "t_req,t_x509,t_crl,t_pkey,"+ -
217 "p7_i_s,p7_signi,p7_signd,p7_recip,p7_enc_c,p7_evp,"+ -
218 "p7_dgst,p7_s_e,p7_enc,p7_lib,"+ -
219 "f_int,f_string,i2d_dhp,i2d_dsap,d2i_dhp,d2i_dsap,n_pkey,"+ -
220 "f_enum,a_hdr,x_pkey,a_bool,x_exten,"+ -
221 "asn1_par,asn1_lib,asn1_err,a_meth,a_bytes,"+ -
222 "evp_asn1,asn_pack,p5_pbe,p5_pbev2,p8_pkey"
223$ LIB_PEM = "pem_sign,pem_seal,pem_info,pem_lib,pem_all,pem_err"
224$ LIB_X509 = "x509_def,x509_d2,x509_r2x,x509_cmp,"+ -
225 "x509_obj,x509_req,x509_vfy,"+ -
226 "x509_set,x509rset,x509_err,"+ -
227 "x509name,x509_v3,x509_ext,"+ -
228 "x509type,x509_lu,x_all,x509_txt,"+ -
229 "by_file,by_dir"
230$ LIB_X509V3 = "v3_bcons,v3_bitst,v3_conf,v3_extku,v3_ia5,v3_lib,"+ -
231 "v3_prn,v3_utl,v3err,v3_genn,v3_alt,v3_skey,v3_akey,v3_pku,"+ -
232 "v3_int,v3_enum,v3_sxnet,v3_cpols,v3_crld"
233$ LIB_CONF = "conf,conf_err"
234$ LIB_TXT_DB = "txt_db"
235$ LIB_PKCS7 = "pk7_lib,pkcs7err,pk7_doit"
236$ LIB_PKCS12 = "p12_add,p12_attr,p12_bags,p12_crpt,p12_crt,p12_decr,"+ -
237 "p12_init,p12_key,p12_kiss,p12_lib,p12_mac,p12_mutl,"+ -
238 "p12_sbag,p12_utl,pk12err"
239$ LIB_COMP = "comp_lib,"+ -
240 "c_rle,c_zlib"
241$!
242$! Setup exceptional compilations
243$!
244$ COMPILEWITH_CC3 = ",bss_rtcp,"
245$ COMPILEWITH_CC4 = ",a_utctm,"
246$ COMPILEWITH_CC5 = ",md2_dgst,md5_dgst,mdc2dgst,sha_dgst,sha1dgst," + -
247 "rmd_dgst,bf_enc,"
248$!
249$! Check To See If We Are Going To Use RSAREF.
250$!
251$ IF (RSAREF.EQS."TRUE" .AND. ENCRYPT_TYPES - "RSA".NES.ENCRYPT_TYPES)
252$ THEN
253$!
254$! Check To See If The File [-.RSAREF]RSAREF.C Is Actually There.
255$!
256$ IF (F$SEARCH("SYS$DISK:[-.RSAREF]RSAREF.C").EQS."")
257$ THEN
258$!
259$! Tell The User That The File Dosen't Exist.
260$!
261$ WRITE SYS$OUTPUT ""
262$ WRITE SYS$OUTPUT "The File [-.RSAREF]RSAREF.C Dosen't Exist."
263$ WRITE SYS$OUTPUT ""
264$!
265$! Exit The Build.
266$!
267$ GOTO EXIT
268$!
269$! End The [-.RSAREF]RSAREF.C Check.
270$!
271$ ENDIF
272$!
273$! Tell The User We Are Compiling The [-.RSAREF]RSAREF File.
274$!
275$ WRITE SYS$OUTPUT "Compiling The [-.RSAREF]RSAREF File."
276$!
277$! Compile [-.RSAREF]RSAREF.C
278$!
279$ CC/OBJECT='OBJ_DIR'RSAREF.OBJ SYS$DISK:[-.RSAREF]RSAREF.C
280$!
281$! Add It To The Library.
282$!
283$ LIBRARY/REPLACE 'LIB_NAME' 'OBJ_DIR'RSAREF.OBJ
284$!
285$! Delete The Object File.
286$!
287$ DELETE 'OBJ_DIR'RSAREF.OBJ;*
288$!
289$! Check To See If The File [-.RSAREF]RSAR_ERR.C Is Actually There.
290$!
291$ IF (F$SEARCH("SYS$DISK:[-.RSAREF]RSAR_ERR.C").EQS."")
292$ THEN
293$!
294$! Tell The User That The File Dosen't Exist.
295$!
296$ WRITE SYS$OUTPUT ""
297$ WRITE SYS$OUTPUT "The File [-.RSAREF]RSAR_ERR.C Dosen't Exist."
298$ WRITE SYS$OUTPUT ""
299$!
300$! Exit The Build.
301$!
302$ GOTO EXIT
303$!
304$! End The [-.RSAREF]RSAR_ERR.C File Check.
305$!
306$ ENDIF
307$!
308$! Tell The User We Are Compiling The [-.RSAREF]RSAR_ERR File.
309$!
310$ WRITE SYS$OUTPUT "Compiling The [-.RSAREF]RSAR_ERR File."
311$!
312$! Compile [-.RSAREF]RSAR_ERR.C
313$!
314$ CC/OBJECT='OBJ_DIR'RSAR_ERR.OBJ SYS$DISK:[-.RSAREF]RSAR_ERR.C
315$!
316$! Add It To The Library.
317$!
318$ LIBRARY/REPLACE 'LIB_NAME' 'OBJ_DIR'RSAR_ERR.OBJ
319$!
320$! Delete The Object File.
321$!
322$ DELETE 'OBJ_DIR'RSAR_ERR.OBJ;*
323$!
324$! End The RSAREF Check.
325$!
326$ ENDIF
327$!
328$! Figure Out What Other Modules We Are To Build.
329$!
330$ BUILD_SET:
331$!
332$! Define A Module Counter.
333$!
334$ MODULE_COUNTER = 0
335$!
336$! Top Of The Loop.
337$!
338$ MODULE_NEXT:
339$!
340$! Extract The Module Name From The Encryption List.
341$!
342$ MODULE_NAME = F$ELEMENT(MODULE_COUNTER,",",ENCRYPT_TYPES)
343$!
344$! Check To See If We Are At The End Of The Module List.
345$!
346$ IF (MODULE_NAME.EQS.",")
347$ THEN
348$!
349$! We Are At The End Of The Module List, Go To MODULE_DONE.
350$!
351$ GOTO MODULE_DONE
352$!
353$! End The Module List Check.
354$!
355$ ENDIF
356$!
357$! Increment The Moudle Counter.
358$!
359$ MODULE_COUNTER = MODULE_COUNTER + 1
360$!
361$! Tell The User What Module We Are Building.
362$!
363$ IF (MODULE_NAME.NES."")
364$ THEN
365$ WRITE SYS$OUTPUT "Compiling The ",MODULE_NAME," Files."
366$ ENDIF
367$!
368$! Define A File Counter And Set It To "0".
369$!
370$ FILE_COUNTER = 0
371$!
372$! Create The Library Module Name.
373$!
374$ LIB_MODULE = "LIB_" + MODULE_NAME
375$ IF (MODULE_NAME.EQS."ASN1_2")
376$ THEN
377$ MODULE_NAME = "ASN1"
378$ ENDIF
379$ IF (MODULE_NAME.EQS."EVP_2")
380$ THEN
381$ MODULE_NAME = "EVP"
382$ ENDIF
383$!
384$! Check if the library module name actually is defined
385$!
386$ IF F$TYPE('LIB_MODULE') .EQS. ""
387$ THEN
388$ WRITE SYS$ERROR ""
389$ WRITE SYS$ERROR "The module ",MODULE_NAME," does not exist. Continuing..."
390$ WRITE SYS$ERROR ""
391$ GOTO MODULE_NEXT
392$ ENDIF
393$!
394$! Top Of The File Loop.
395$!
396$ NEXT_FILE:
397$!
398$! O.K, Extract The File Name From The File List.
399$!
400$ FILE_NAME = F$ELEMENT(FILE_COUNTER,",",'LIB_MODULE')
401$!
402$! Check To See If We Are At The End Of The File List.
403$!
404$ IF (FILE_NAME.EQS.",")
405$ THEN
406$!
407$! We Are At The End Of The File List, Goto FILE_DONE.
408$!
409$ GOTO FILE_DONE
410$!
411$! End The File List Check.
412$!
413$ ENDIF
414$!
415$! Increment The Counter.
416$!
417$ FILE_COUNTER = FILE_COUNTER + 1
418$!
419$! Create The Source File Name.
420$!
421$ TMP_FILE_NAME = F$ELEMENT(1,"]",FILE_NAME)
422$ IF TMP_FILE_NAME .EQS. "]" THEN TMP_FILE_NAME = FILE_NAME
423$ IF F$ELEMENT(0,".",TMP_FILE_NAME) .EQS. TMP_FILE_NAME THEN -
424 FILE_NAME = FILE_NAME + ".c"
425$ IF (MODULE_NAME.NES."")
426$ THEN
427$ SOURCE_FILE = "SYS$DISK:[." + MODULE_NAME+ "]" + FILE_NAME
428$ ELSE
429$ SOURCE_FILE = "SYS$DISK:[]" + FILE_NAME
430$ ENDIF
431$ SOURCE_FILE = SOURCE_FILE - "]["
432$!
433$! Create The Object File Name.
434$!
435$ OBJECT_FILE = OBJ_DIR + F$PARSE(FILE_NAME,,,"NAME","SYNTAX_ONLY") + ".OBJ"
436$ ON WARNING THEN GOTO NEXT_FILE
437$!
438$! Check To See If The File We Want To Compile Is Actually There.
439$!
440$ IF (F$SEARCH(SOURCE_FILE).EQS."")
441$ THEN
442$!
443$! Tell The User That The File Dosen't Exist.
444$!
445$ WRITE SYS$OUTPUT ""
446$ WRITE SYS$OUTPUT "The File ",SOURCE_FILE," Dosen't Exist."
447$ WRITE SYS$OUTPUT ""
448$!
449$! Exit The Build.
450$!
451$ GOTO EXIT
452$!
453$! End The File Exist Check.
454$!
455$ ENDIF
456$!
457$! Tell The User We Are Compiling The File.
458$!
459$ IF (MODULE_NAME.EQS."")
460$ THEN
461 WRITE SYS$OUTPUT "Compiling The ",FILE_NAME," File."
462$ ENDIF
463$ IF (MODULE_NAME.NES."")
464$ THEN
465$ WRITE SYS$OUTPUT " ",FILE_NAME,""
466$ ENDIF
467$!
468$! Compile The File.
469$!
470$ ON ERROR THEN GOTO NEXT_FILE
471$ FILE_NAME0 = F$ELEMENT(0,".",FILE_NAME)
472$ IF FILE_NAME - ".mar" .NES. FILE_NAME
473$ THEN
474$ MACRO/OBJECT='OBJECT_FILE' 'SOURCE_FILE'
475$ ELSE
476$ IF COMPILEWITH_CC3 - FILE_NAME0 .NES. COMPILEWITH_CC3
477$ THEN
478$ CC3/OBJECT='OBJECT_FILE' 'SOURCE_FILE'
479$ ELSE
480$ IF COMPILEWITH_CC4 - FILE_NAME0 .NES. COMPILEWITH_CC4
481$ THEN
482$ CC4/OBJECT='OBJECT_FILE' 'SOURCE_FILE'
483$ ELSE
484$ IF COMPILEWITH_CC5 - FILE_NAME0 .NES. COMPILEWITH_CC5
485$ THEN
486$ CC5/OBJECT='OBJECT_FILE' 'SOURCE_FILE'
487$ ELSE
488$ CC/OBJECT='OBJECT_FILE' 'SOURCE_FILE'
489$ ENDIF
490$ ENDIF
491$ ENDIF
492$ ENDIF
493$!
494$! Add It To The Library.
495$!
496$ LIBRARY/REPLACE 'LIB_NAME' 'OBJECT_FILE'
497$!
498$! Time To Clean Up The Object File.
499$!
500$ DELETE 'OBJECT_FILE';*
501$!
502$! Go Back And Do It Again.
503$!
504$ GOTO NEXT_FILE
505$!
506$! All Done With This Library Part.
507$!
508$ FILE_DONE:
509$!
510$! Go Back And Get The Next Module.
511$!
512$ GOTO MODULE_NEXT
513$!
514$! All Done With This Module.
515$!
516$ MODULE_DONE:
517$!
518$! Tell The User That We Are All Done.
519$!
520$ WRITE SYS$OUTPUT "All Done..."
521$ EXIT:
522$ GOSUB CLEANUP
523$ EXIT
524$!
525$! Check For The Link Option FIle.
526$!
527$ CHECK_OPT_FILE:
528$!
529$! Check To See If We Need To Make A VAX C Option File.
530$!
531$ IF (COMPILER.EQS."VAXC")
532$ THEN
533$!
534$! Check To See If We Already Have A VAX C Linker Option File.
535$!
536$ IF (F$SEARCH(OPT_FILE).EQS."")
537$ THEN
538$!
539$! We Need A VAX C Linker Option File.
540$!
541$ CREATE 'OPT_FILE'
542$DECK
543!
544! Default System Options File To Link Agianst
545! The Sharable VAX C Runtime Library.
546!
547SYS$SHARE:VAXCRTL.EXE/SHARE
548$EOD
549$!
550$! End The Option File Check.
551$!
552$ ENDIF
553$!
554$! End The VAXC Check.
555$!
556$ ENDIF
557$!
558$! Check To See If We Need A GNU C Option File.
559$!
560$ IF (COMPILER.EQS."GNUC")
561$ THEN
562$!
563$! Check To See If We Already Have A GNU C Linker Option File.
564$!
565$ IF (F$SEARCH(OPT_FILE).EQS."")
566$ THEN
567$!
568$! We Need A GNU C Linker Option File.
569$!
570$ CREATE 'OPT_FILE'
571$DECK
572!
573! Default System Options File To Link Agianst
574! The Sharable C Runtime Library.
575!
576GNU_CC:[000000]GCCLIB/LIBRARY
577SYS$SHARE:VAXCRTL/SHARE
578$EOD
579$!
580$! End The Option File Check.
581$!
582$ ENDIF
583$!
584$! End The GNU C Check.
585$!
586$ ENDIF
587$!
588$! Check To See If We Need A DEC C Option File.
589$!
590$ IF (COMPILER.EQS."DECC")
591$ THEN
592$!
593$! Check To See If We Already Have A DEC C Linker Option File.
594$!
595$ IF (F$SEARCH(OPT_FILE).EQS."")
596$ THEN
597$!
598$! Figure Out If We Need An AXP Or A VAX Linker Option File.
599$!
600$ IF ARCH .EQS. "VAX"
601$ THEN
602$!
603$! We Need A DEC C Linker Option File For VAX.
604$!
605$ CREATE 'OPT_FILE'
606$DECK
607!
608! Default System Options File To Link Agianst
609! The Sharable DEC C Runtime Library.
610!
611SYS$SHARE:DECC$SHR.EXE/SHARE
612$EOD
613$!
614$! Else...
615$!
616$ ELSE
617$!
618$! Create The AXP Linker Option File.
619$!
620$ CREATE 'OPT_FILE'
621$DECK
622!
623! Default System Options File For AXP To Link Agianst
624! The Sharable C Runtime Library.
625!
626SYS$SHARE:CMA$OPEN_LIB_SHR/SHARE
627SYS$SHARE:CMA$OPEN_RTL/SHARE
628$EOD
629$!
630$! End The VAX/AXP DEC C Option File Check.
631$!
632$ ENDIF
633$!
634$! End The Option File Search.
635$!
636$ ENDIF
637$!
638$! End The DEC C Check.
639$!
640$ ENDIF
641$!
642$! Tell The User What Linker Option File We Are Using.
643$!
644$ WRITE SYS$OUTPUT "Using Linker Option File ",OPT_FILE,"."
645$!
646$! Time To RETURN.
647$!
648$ RETURN
649$!
650$! Check The User's Options.
651$!
652$ CHECK_OPTIONS:
653$!
654$! Check To See If P1 Is Blank.
655$!
656$ IF (P1.EQS."NORSAREF")
657$ THEN
658$!
659$! P1 Is NORSAREF, So Compile With The Regular RSA Libraries.
660$!
661$ RSAREF = "FALSE"
662$ ELSE
663$!
664$! Check To See If We Are To Use The RSAREF Library.
665$!
666$ IF (P1.EQS."RSAREF")
667$ THEN
668$!
669$! Check To Make Sure We Have The RSAREF Source Code Directory.
670$!
671$ IF (F$SEARCH("SYS$DISK:[-.RSAREF]SOURCE.DIR").EQS."")
672$ THEN
673$!
674$! We Don't Have The RSAREF Souce Code Directory, So Tell The
675$! User This.
676$!
677$ WRITE SYS$OUTPUT ""
678$ WRITE SYS$OUTPUT "It appears that you don't have the RSAREF Souce Code."
679$ WRITE SYS$OUTPUT "You need to go to 'ftp://ftp.rsa.com/rsaref'. You have to"
680$ WRITE SYS$OUTPUT "get the '.tar-Z' file as the '.zip' file dosen't have the"
681$ WRITE SYS$OUTPUT "directory structure stored. You have to extract the file"
682$ WRITE SYS$OUTPUT "into the [.RSAREF] directory under the root directory"
683$ WRITE SYS$OUTPUT "as that is where the scripts will look for the files."
684$ WRITE SYS$OUTPUT ""
685$!
686$! Time To Exit.
687$!
688$ EXIT
689$!
690$! Else, Compile Using The RSAREF Library.
691$!
692$ ELSE
693$ RSAREF = "TRUE"
694$ ENDIF
695$ ELSE
696$!
697$! They Entered An Invalid Option..
698$!
699$ WRITE SYS$OUTPUT ""
700$ WRITE SYS$OUTPUT "The Option ",P1," Is Invalid. The Valid Options Are:"
701$ WRITE SYS$OUTPUT ""
702$ WRITE SYS$OUTPUT " RSAREF : Compile With The RSAREF Library."
703$ WRITE SYS$OUTPUT " NORSAREF : Compile With The Regular RSA Library."
704$ WRITE SYS$OUTPUT ""
705$!
706$! Time To EXIT.
707$!
708$ EXIT
709$!
710$! End The Valid Arguement Check.
711$!
712$ ENDIF
713$!
714$! End The P1 Check.
715$!
716$ ENDIF
717$!
718$! Check To See If P2 Is Blank.
719$!
720$ IF (P2.EQS."NODEBUG")
721$ THEN
722$!
723$! P2 Is NODEBUG, So Compile Without The Debugger Information.
724$!
725$ DEBUGGER = "NODEBUG"
726$ TRACEBACK = "NOTRACEBACK"
727$ GCC_OPTIMIZE = "OPTIMIZE"
728$ CC_OPTIMIZE = "OPTIMIZE"
729$ MACRO_OPTIMIZE = "OPTIMIZE"
730$ WRITE SYS$OUTPUT "No Debugger Information Will Be Produced During Compile."
731$ WRITE SYS$OUTPUT "Compiling With Compiler Optimization."
732$ ELSE
733$!
734$! Check To See If We Are To Compile With Debugger Information.
735$!
736$ IF (P2.EQS."DEBUG")
737$ THEN
738$!
739$! Compile With Debugger Information.
740$!
741$ DEBUGGER = "DEBUG"
742$ TRACEBACK = "TRACEBACK"
743$ GCC_OPTIMIZE = "NOOPTIMIZE"
744$ CC_OPTIMIZE = "NOOPTIMIZE"
745$ MACRO_OPTIMIZE = "NOOPTIMIZE"
746$ WRITE SYS$OUTPUT "Debugger Information Will Be Produced During Compile."
747$ WRITE SYS$OUTPUT "Compiling Without Compiler Optimization."
748$ ELSE
749$!
750$! They Entered An Invalid Option..
751$!
752$ WRITE SYS$OUTPUT ""
753$ WRITE SYS$OUTPUT "The Option ",P2," Is Invalid. The Valid Options Are:"
754$ WRITE SYS$OUTPUT ""
755$ WRITE SYS$OUTPUT " DEBUG : Compile With The Debugger Information."
756$ WRITE SYS$OUTPUT " NODEBUG : Compile Without The Debugger Information."
757$ WRITE SYS$OUTPUT ""
758$!
759$! Time To EXIT.
760$!
761$ EXIT
762$!
763$! End The Valid Arguement Check.
764$!
765$ ENDIF
766$!
767$! End The P2 Check.
768$!
769$ ENDIF
770$!
771$! Special Threads For OpenVMS v7.1 Or Later
772$!
773$! Written By: Richard Levitte
774$! richard@levitte.org
775$!
776$!
777$! Check To See If We Have A Option For P5.
778$!
779$ IF (P5.EQS."")
780$ THEN
781$!
782$! Get The Version Of VMS We Are Using.
783$!
784$ ISSEVEN :=
785$ TMP = F$ELEMENT(0,"-",F$EXTRACT(1,4,F$GETSYI("VERSION")))
786$ TMP = F$INTEGER(F$ELEMENT(0,".",TMP)+F$ELEMENT(1,".",TMP))
787$!
788$! Check To See If The VMS Version Is v7.1 Or Later.
789$!
790$ IF (TMP.GE.71)
791$ THEN
792$!
793$! We Have OpenVMS v7.1 Or Later, So Use The Special Threads.
794$!
795$ ISSEVEN := ,PTHREAD_USE_D4
796$!
797$! End The VMS Version Check.
798$!
799$ ENDIF
800$!
801$! End The P5 Check.
802$!
803$ ENDIF
804$!
805$! Check To See If P3 Is Blank.
806$!
807$ IF (P3.EQS."")
808$ THEN
809$!
810$! O.K., The User Didn't Specify A Compiler, Let's Try To
811$! Find Out Which One To Use.
812$!
813$! Check To See If We Have GNU C.
814$!
815$ IF (F$TRNLNM("GNU_CC").NES."")
816$ THEN
817$!
818$! Looks Like GNUC, Set To Use GNUC.
819$!
820$ P3 = "GNUC"
821$!
822$! Else...
823$!
824$ ELSE
825$!
826$! Check To See If We Have VAXC Or DECC.
827$!
828$ IF (ARCH.EQS."AXP").OR.(F$TRNLNM("DECC$CC_DEFAULT").NES."")
829$ THEN
830$!
831$! Looks Like DECC, Set To Use DECC.
832$!
833$ P3 = "DECC"
834$!
835$! Else...
836$!
837$ ELSE
838$!
839$! Looks Like VAXC, Set To Use VAXC.
840$!
841$ P3 = "VAXC"
842$!
843$! End The VAXC Compiler Check.
844$!
845$ ENDIF
846$!
847$! End The DECC & VAXC Compiler Check.
848$!
849$ ENDIF
850$!
851$! End The Compiler Check.
852$!
853$ ENDIF
854$!
855$! Check To See If We Have A Option For P4.
856$!
857$ IF (P4.EQS."")
858$ THEN
859$!
860$! Find out what socket library we have available
861$!
862$ IF F$PARSE("SOCKETSHR:") .NES. ""
863$ THEN
864$!
865$! We have SOCKETSHR, and it is my opinion that it's the best to use.
866$!
867$ P4 = "SOCKETSHR"
868$!
869$! Tell the user
870$!
871$ WRITE SYS$OUTPUT "Using SOCKETSHR for TCP/IP"
872$!
873$! Else, let's look for something else
874$!
875$ ELSE
876$!
877$! Like UCX (the reason to do this before Multinet is that the UCX
878$! emulation is easier to use...)
879$!
880$ IF F$TRNLNM("UCX$IPC_SHR") .NES. "" -
881 .OR. F$PARSE("SYS$SHARE:UCX$IPC_SHR.EXE") .NES. "" -
882 .OR. F$PARSE("SYS$LIBRARY:UCX$IPC.OLB") .NES. ""
883$ THEN
884$!
885$! Last resort: a UCX or UCX-compatible library
886$!
887$ P4 = "UCX"
888$!
889$! Tell the user
890$!
891$ WRITE SYS$OUTPUT "Using UCX or an emulation thereof for TCP/IP"
892$!
893$! That was all...
894$!
895$ ENDIF
896$ ENDIF
897$ ENDIF
898$!
899$! Set Up Initial CC Definitions, Possibly With User Ones
900$!
901$ CCDEFS = "VMS=1,TCPIP_TYPE_''P4'"
902$ IF F$TYPE(USER_CCDEFS) .NES. "" THEN CCDEFS = CCDEFS + "," + USER_CCDEFS
903$ CCEXTRAFLAGS = ""
904$ IF F$TYPE(USER_CCFLAGS) .NES. "" THEN CCEXTRAFLAGS = USER_CCFLAGS
905$ CCDISABLEWARNINGS = ""
906$ IF F$TYPE(USER_CCDISABLEWARNINGS) .NES. "" THEN -
907 CCDISABLEWARNINGS = USER_CCDISABLEWARNINGS
908$!
909$! Check To See If The User Entered A Valid Paramter.
910$!
911$ IF (P3.EQS."VAXC").OR.(P3.EQS."DECC").OR.(P3.EQS."GNUC")
912$ THEN
913$!
914$! Check To See If The User Wanted DECC.
915$!
916$ IF (P3.EQS."DECC")
917$ THEN
918$!
919$! Looks Like DECC, Set To Use DECC.
920$!
921$ COMPILER = "DECC"
922$!
923$! Tell The User We Are Using DECC.
924$!
925$ WRITE SYS$OUTPUT "Using DECC 'C' Compiler."
926$!
927$! Use DECC...
928$!
929$ CC = "CC"
930$ IF ARCH.EQS."VAX" .AND. F$TRNLNM("DECC$CC_DEFAULT").NES."/DECC" -
931 THEN CC = "CC/DECC"
932$ CC = CC + "/''CC_OPTIMIZE'/''DEBUGGER'/STANDARD=ANSI89" + -
933 "/NOLIST/PREFIX=ALL/INCLUDE=SYS$DISK:[]" + CCEXTRAFLAGS
934$!
935$! Define The Linker Options File Name.
936$!
937$ OPT_FILE = "SYS$DISK:[]VAX_DECC_OPTIONS.OPT"
938$!
939$! End DECC Check.
940$!
941$ ENDIF
942$!
943$! Check To See If We Are To Use VAXC.
944$!
945$ IF (P3.EQS."VAXC")
946$ THEN
947$!
948$! Looks Like VAXC, Set To Use VAXC.
949$!
950$ COMPILER = "VAXC"
951$!
952$! Tell The User We Are Using VAX C.
953$!
954$ WRITE SYS$OUTPUT "Using VAXC 'C' Compiler."
955$!
956$! Compile Using VAXC.
957$!
958$ CC = "CC"
959$ IF ARCH.EQS."AXP"
960$ THEN
961$ WRITE SYS$OUTPUT "There is no VAX C on Alpha!"
962$ EXIT
963$ ENDIF
964$ IF F$TRNLNM("DECC$CC_DEFAULT").EQS."/DECC" THEN CC = "CC/VAXC"
965$ CC = CC + "/''CC_OPTIMIZE'/''DEBUGGER'/NOLIST/INCLUDE=SYS$DISK:[]" + -
966 CCEXTRAFLAGS
967$ CCDEFS = """VAXC""," + CCDEFS
968$!
969$! Define <sys> As SYS$COMMON:[SYSLIB]
970$!
971$ DEFINE/NOLOG SYS SYS$COMMON:[SYSLIB]
972$!
973$! Define The Linker Options File Name.
974$!
975$ OPT_FILE = "SYS$DISK:[]VAX_VAXC_OPTIONS.OPT"
976$!
977$! End VAXC Check
978$!
979$ ENDIF
980$!
981$! Check To See If We Are To Use GNU C.
982$!
983$ IF (P3.EQS."GNUC")
984$ THEN
985$!
986$! Looks Like GNUC, Set To Use GNUC.
987$!
988$ COMPILER = "GNUC"
989$!
990$! Tell The User We Are Using GNUC.
991$!
992$ WRITE SYS$OUTPUT "Using GNU 'C' Compiler."
993$!
994$! Use GNU C...
995$!
996$ CC = "GCC/NOCASE_HACK/''GCC_OPTIMIZE'/''DEBUGGER'/NOLIST" + -
997 "/INCLUDE=SYS$DISK:[]" + CCEXTRAFLAGS
998$!
999$! Define The Linker Options File Name.
1000$!
1001$ OPT_FILE = "SYS$DISK:[]VAX_GNUC_OPTIONS.OPT"
1002$!
1003$! End The GNU C Check.
1004$!
1005$ ENDIF
1006$!
1007$! Set up default defines
1008$!
1009$ CCDEFS = """FLAT_INC=1""," + CCDEFS
1010$!
1011$! Check To See If We Are To Compile With RSAREF Routines.
1012$!
1013$ IF (RSAREF.EQS."TRUE")
1014$ THEN
1015$!
1016$! Compile With RSAREF.
1017$!
1018$ CCDEFS = CCDEFS + ",""RSAref=1"""
1019$!
1020$! Tell The User This.
1021$!
1022$ WRITE SYS$OUTPUT "Compiling With RSAREF Routines."
1023$!
1024$! Else, We Don't Care. Compile Without The RSAREF Library.
1025$!
1026$ ELSE
1027$!
1028$! Tell The User We Are Compile Without The RSAREF Routines.
1029$!
1030$ WRITE SYS$OUTPUT "Compiling Without The RSAREF Routines.
1031$!
1032$! End The RSAREF Check.
1033$!
1034$ ENDIF
1035$!
1036$! Finish up the definition of CC.
1037$!
1038$ IF COMPILER .EQS. "DECC"
1039$ THEN
1040$ IF CCDISABLEWARNINGS .EQS. ""
1041$ THEN
1042$ CC4DISABLEWARNINGS = "DOLLARID"
1043$ ELSE
1044$ CC4DISABLEWARNINGS = CCDISABLEWARNINGS + ",DOLLARID"
1045$ CCDISABLEWARNINGS = "/WARNING=(DISABLE=(" + CCDISABLEWARNINGS + "))"
1046$ ENDIF
1047$ CC4DISABLEWARNINGS = "/WARNING=(DISABLE=(" + CC4DISABLEWARNINGS + "))"
1048$ ELSE
1049$ CCDISABLEWARNINGS = ""
1050$ CC4DISABLEWARNINGS = ""
1051$ ENDIF
1052$ CC3 = CC + "/DEFINE=(" + CCDEFS + ISSEVEN + ")" + CCDISABLEWARNINGS
1053$ CC = CC + "/DEFINE=(" + CCDEFS + ")" + CCDISABLEWARNINGS
1054$ IF ARCH .EQS. "VAX" .AND. COMPILER .EQS. "DECC" .AND. P2 .NES. "DEBUG"
1055$ THEN
1056$ CC5 = CC + "/OPTIMIZE=NODISJOINT"
1057$ ELSE
1058$ CC5 = CC + "/NOOPTIMIZE"
1059$ ENDIF
1060$ CC4 = CC - CCDISABLEWARNINGS + CC4DISABLEWARNINGS
1061$!
1062$! Show user the result
1063$!
1064$ WRITE SYS$OUTPUT "Main C Compiling Command: ",CC
1065$!
1066$! Else The User Entered An Invalid Arguement.
1067$!
1068$ ELSE
1069$!
1070$! Tell The User We Don't Know What They Want.
1071$!
1072$ WRITE SYS$OUTPUT ""
1073$ WRITE SYS$OUTPUT "The Option ",P3," Is Invalid. The Valid Options Are:"
1074$ WRITE SYS$OUTPUT ""
1075$ WRITE SYS$OUTPUT " VAXC : To Compile With VAX C."
1076$ WRITE SYS$OUTPUT " DECC : To Compile With DEC C."
1077$ WRITE SYS$OUTPUT " GNUC : To Compile With GNU C."
1078$ WRITE SYS$OUTPUT ""
1079$!
1080$! Time To EXIT.
1081$!
1082$ EXIT
1083$!
1084$! End The Valid Arguement Check.
1085$!
1086$ ENDIF
1087$!
1088$! Build a MACRO command for the architecture at hand
1089$!
1090$ IF ARCH .EQS. "VAX" THEN MACRO = "MACRO/''DEBUGGER'"
1091$ IF ARCH .EQS. "AXP" THEN MACRO = "MACRO/MIGRATION/''DEBUGGER'/''MACRO_OPTIMIZE'"
1092$!
1093$! Show user the result
1094$!
1095$ WRITE SYS$OUTPUT "Main MACRO Compiling Command: ",MACRO
1096$!
1097$! Time to check the contents, and to make sure we get the correct library.
1098$!
1099$ IF P4.EQS."SOCKETSHR" .OR. P4.EQS."MULTINET" .OR. P4.EQS."UCX"
1100$ THEN
1101$!
1102$! Check to see if SOCKETSHR was chosen
1103$!
1104$ IF P4.EQS."SOCKETSHR"
1105$ THEN
1106$!
1107$! Set the library to use SOCKETSHR
1108$!
1109$ TCPIP_LIB = "[-.VMS]SOCKETSHR_SHR.OPT/OPT"
1110$!
1111$! Done with SOCKETSHR
1112$!
1113$ ENDIF
1114$!
1115$! Check to see if MULTINET was chosen
1116$!
1117$ IF P4.EQS."MULTINET"
1118$ THEN
1119$!
1120$! Set the library to use UCX emulation.
1121$!
1122$ P4 = "UCX"
1123$!
1124$! Done with MULTINET
1125$!
1126$ ENDIF
1127$!
1128$! Check to see if UCX was chosen
1129$!
1130$ IF P4.EQS."UCX"
1131$ THEN
1132$!
1133$! Set the library to use UCX.
1134$!
1135$ TCPIP_LIB = "[-.VMS]UCX_SHR_DECC.OPT/OPT"
1136$ IF F$TRNLNM("UCX$IPC_SHR") .NES. ""
1137$ THEN
1138$ TCPIP_LIB = "[-.VMS]UCX_SHR_DECC_LOG.OPT/OPT"
1139$ ELSE
1140$ IF COMPILER .NES. "DECC" .AND. ARCH .EQS. "VAX" THEN -
1141 TCPIP_LIB = "[-.VMS]UCX_SHR_VAXC.OPT/OPT"
1142$ ENDIF
1143$!
1144$! Done with UCX
1145$!
1146$ ENDIF
1147$!
1148$! Print info
1149$!
1150$ WRITE SYS$OUTPUT "TCP/IP library spec: ", TCPIP_LIB
1151$!
1152$! Else The User Entered An Invalid Arguement.
1153$!
1154$ ELSE
1155$!
1156$! Tell The User We Don't Know What They Want.
1157$!
1158$ WRITE SYS$OUTPUT ""
1159$ WRITE SYS$OUTPUT "The Option ",P4," Is Invalid. The Valid Options Are:"
1160$ WRITE SYS$OUTPUT ""
1161$ WRITE SYS$OUTPUT " SOCKETSHR : To link with SOCKETSHR TCP/IP library."
1162$ WRITE SYS$OUTPUT " UCX : To link with UCX TCP/IP library."
1163$ WRITE SYS$OUTPUT ""
1164$!
1165$! Time To EXIT.
1166$!
1167$ EXIT
1168$!
1169$! Done with TCP/IP libraries
1170$!
1171$ ENDIF
1172$!
1173$! Check if the user wanted to compile just a subset of all the encryption
1174$! methods.
1175$!
1176$ IF P6 .NES. ""
1177$ THEN
1178$ ENCRYPT_TYPES = P6
1179$ ENDIF
1180$!
1181$! Time To RETURN...
1182$!
1183$ RETURN
1184$!
1185$ INITIALISE:
1186$!
1187$! Save old value of the logical name OPENSSL
1188$!
1189$ __SAVE_OPENSSL = F$TRNLNM("OPENSSL","LNM$PROCESS_TABLE")
1190$!
1191$! Save directory information
1192$!
1193$ __HERE = F$PARSE(F$PARSE("A.;",F$ENVIRONMENT("PROCEDURE"))-"A.;","[]A.;") - "A.;"
1194$ __TOP = __HERE - "CRYPTO]"
1195$ __INCLUDE = __TOP + "INCLUDE.OPENSSL]"
1196$!
1197$! Set up the logical name OPENSSL to point at the include directory
1198$!
1199$ DEFINE OPENSSL/NOLOG '__INCLUDE'
1200$!
1201$! Done
1202$!
1203$ RETURN
1204$!
1205$ CLEANUP:
1206$!
1207$! Restore the logical name OPENSSL if it had a value
1208$!
1209$ IF __SAVE_OPENSSL .EQS. ""
1210$ THEN
1211$ DEASSIGN OPENSSL
1212$ ELSE
1213$ DEFINE/NOLOG OPENSSL '__SAVE_OPENSSL'
1214$ ENDIF
1215$!
1216$! Done
1217$!
1218$ RETURN
diff --git a/src/lib/libcrypto/des/des-lib.com b/src/lib/libcrypto/des/des-lib.com
new file mode 100644
index 0000000000..2aea7a0dea
--- /dev/null
+++ b/src/lib/libcrypto/des/des-lib.com
@@ -0,0 +1,1003 @@
1$!
2$! DES-LIB.COM
3$! Written By: Robert Byer
4$! Vice-President
5$! A-Com Computing, Inc.
6$! byer@mail.all-net.net
7$!
8$! Changes by Richard Levitte <richard@levitte.org>
9$!
10$! This command files compiles and creates the
11$! "[.xxx.EXE.CRYPTO.DES]LIBDES.OLB" library. The "xxx" denotes the machine
12$! architecture of AXP or VAX.
13$!
14$! It was re-written to try to determine which "C" compiler to try to use
15$! or the user can specify a compiler in P3.
16$!
17$! Specify one of the following to build just that part, specify "ALL" to
18$! just build everything.
19$!
20$! ALL To Just Build "Everything".
21$! LIBRARY To Just Build The [.xxx.EXE.CRYPTO.DES]LIBDES.OLB Library.
22$! DESTEST To Just Build The [.xxx.EXE.CRYPTO.DES]DESTEST.EXE Program.
23$! SPEED To Just Build The [.xxx.EXE.CRYPTO.DES]SPEED.EXE Program.
24$! RPW To Just Build The [.xxx.EXE.CRYPTO.DES]RPW.EXE Program.
25$! DES To Just Build The [.xxx.EXE.CRYPTO.DES]DES.EXE Program.
26$! DES_OPTS To Just Build The [.xxx.EXE.CRYPTO.DES]DES_OPTS.EXE Program.
27$!
28$! Specify either DEBUG or NODEBUG as P2 to compile with or without
29$! debugging information.
30$!
31$! Specify which compiler at P3 to try to compile under.
32$!
33$! VAXC For VAX C.
34$! DECC For DEC C.
35$! GNUC For GNU C.
36$!
37$! If you don't speficy a compiler, it will try to determine which
38$! "C" compiler to try to use.
39$!
40$! P4, if defined, sets a compiler thread NOT needed on OpenVMS 7.1 (and up)
41$!
42$!
43$! Make sure we know what architecture we run on.
44$!
45$!
46$! Check Which Architecture We Are Using.
47$!
48$ IF (F$GETSYI("CPU").GE.128)
49$ THEN
50$!
51$! The Architecture Is AXP.
52$!
53$ ARCH := AXP
54$!
55$! Else...
56$!
57$ ELSE
58$!
59$! The Architecture Is VAX.
60$!
61$ ARCH := VAX
62$!
63$! End The Architecture Check.
64$!
65$ ENDIF
66$!
67$! Check To Make Sure We Have Valid Command Line Parameters.
68$!
69$ GOSUB CHECK_OPTIONS
70$!
71$! Tell The User What Kind of Machine We Run On.
72$!
73$ WRITE SYS$OUTPUT "Compiling On A ",ARCH," Machine."
74$!
75$! Define The OBJ Directory Name.
76$!
77$ OBJ_DIR := SYS$DISK:[--.'ARCH'.OBJ.CRYPTO.DES]
78$!
79$! Check To See If The Architecture Specific OBJ Directory Exists.
80$!
81$ IF (F$PARSE(OBJ_DIR).EQS."")
82$ THEN
83$!
84$! It Dosen't Exist, So Create It.
85$!
86$ CREATE/DIR 'OBJ_DIR'
87$!
88$! End The Architecture Specific OBJ Directory Check.
89$!
90$ ENDIF
91$!
92$! Define The EXE Directory Name.
93$!
94$ EXE_DIR :== SYS$DISK:[--.'ARCH'.EXE.CRYPTO.DES]
95$!
96$! Check To See If The Architecture Specific Directory Exists.
97$!
98$ IF (F$PARSE(EXE_DIR).EQS."")
99$ THEN
100$!
101$! It Dosen't Exist, So Create It.
102$!
103$ CREATE/DIR 'EXE_DIR'
104$!
105$! End The Architecture Specific Directory Check.
106$!
107$ ENDIF
108$!
109$! Define The Library Name.
110$!
111$ LIB_NAME := 'EXE_DIR'LIBDES.OLB
112$!
113$! Check To See What We Are To Do.
114$!
115$ IF (BUILDALL.EQS."TRUE")
116$ THEN
117$!
118$! Since Nothing Special Was Specified, Do Everything.
119$!
120$ GOSUB LIBRARY
121$ GOSUB DESTEST
122$ GOSUB SPEED
123$ GOSUB RPW
124$ GOSUB DES
125$ GOSUB DES_OPTS
126$!
127$! Else...
128$!
129$ ELSE
130$!
131$! Build Just What The User Wants Us To Build.
132$!
133$ GOSUB 'BUILDALL'
134$!
135$! End The BUILDALL Check.
136$!
137$ ENDIF
138$!
139$! Time To EXIT.
140$!
141$ EXIT
142$ LIBRARY:
143$!
144$! Tell The User That We Are Compiling.
145$!
146$ WRITE SYS$OUTPUT "Compiling The ",LIB_NAME," Files."
147$!
148$! Check To See If We Already Have A "[.xxx.EXE.CRYPTO.DES]LIBDES.OLB" Library...
149$!
150$ IF (F$SEARCH(LIB_NAME).EQS."")
151$ THEN
152$!
153$! Guess Not, Create The Library.
154$!
155$ LIBRARY/CREATE/OBJECT 'LIB_NAME'
156$!
157$! End The Library Exist Check.
158$!
159$ ENDIF
160$!
161$! Define The DES Library Files.
162$!
163$ LIB_DES = "set_key,ecb_enc,cbc_enc,"+ -
164 "ecb3_enc,cfb64enc,cfb64ede,cfb_enc,ofb64ede,"+ -
165 "enc_read,enc_writ,ofb64enc,"+ -
166 "ofb_enc,str2key,pcbc_enc,qud_cksm,rand_key,"+ -
167 "des_enc,fcrypt_b,read2pwd,"+ -
168 "fcrypt,xcbc_enc,read_pwd,rpc_enc,cbc_cksm,supp"
169$!
170$! Define A File Counter And Set It To "0".
171$!
172$ FILE_COUNTER = 0
173$!
174$! Top Of The File Loop.
175$!
176$ NEXT_FILE:
177$!
178$! O.K, Extract The File Name From The File List.
179$!
180$ FILE_NAME = F$ELEMENT(FILE_COUNTER,",",LIB_DES)
181$!
182$! Check To See If We Are At The End Of The File List.
183$!
184$ IF (FILE_NAME.EQS.",") THEN GOTO FILE_DONE
185$!
186$! Increment The Counter.
187$!
188$ FILE_COUNTER = FILE_COUNTER + 1
189$!
190$! Create The Source File Name.
191$!
192$ SOURCE_FILE = "SYS$DISK:[]" + FILE_NAME + ".C"
193$!
194$! Tell The User We Are Compiling The Source File.
195$!
196$ WRITE SYS$OUTPUT " ",FILE_NAME,".C"
197$!
198$! Create The Object File Name.
199$!
200$ OBJECT_FILE = OBJ_DIR + FILE_NAME + "." + ARCH + "OBJ"
201$ ON WARNING THEN GOTO NEXT_FILE
202$!
203$! Check To See If The File We Want To Compile Actually Exists.
204$!
205$ IF (F$SEARCH(SOURCE_FILE).EQS."")
206$ THEN
207$!
208$! Tell The User That The File Dosen't Exist.
209$!
210$ WRITE SYS$OUTPUT ""
211$ WRITE SYS$OUTPUT "The File ",SOURCE_FILE," Dosen't Exist."
212$ WRITE SYS$OUTPUT ""
213$!
214$! Exit The Build.
215$!
216$ EXIT
217$!
218$! End The File Exists Check.
219$!
220$ ENDIF
221$!
222$! Compile The File.
223$!
224$ ON ERROR THEN GOTO NEXT_FILE
225$ CC/OBJECT='OBJECT_FILE' 'SOURCE_FILE'
226$!
227$! Add It To The Library.
228$!
229$ LIBRARY/REPLACE/OBJECT 'LIB_NAME' 'OBJECT_FILE'
230$!
231$! Time To Clean Up The Object File.
232$!
233$ DELETE 'OBJECT_FILE';*
234$!
235$! Go Back And Do It Again.
236$!
237$ GOTO NEXT_FILE
238$!
239$! All Done With This Library Part.
240$!
241$ FILE_DONE:
242$!
243$! Tell The User That We Are All Done.
244$!
245$ WRITE SYS$OUTPUT "Library ",LIB_NAME," Built."
246$!
247$! All Done, Time To Return.
248$!
249$ RETURN
250$!
251$! Compile The DESTEST Program.
252$!
253$ DESTEST:
254$!
255$! Check To See If We Have The Proper Libraries.
256$!
257$ GOSUB LIB_CHECK
258$!
259$! Check To See If We Have A Linker Option File.
260$!
261$ GOSUB CHECK_OPT_FILE
262$!
263$! Check To See If The File We Want To Compile Actually Exists.
264$!
265$ IF (F$SEARCH("SYS$DISK:[]DESTEST.C").EQS."")
266$ THEN
267$!
268$! Tell The User That The File Dosen't Exist.
269$!
270$ WRITE SYS$OUTPUT ""
271$ WRITE SYS$OUTPUT "The File DESTEST.C Dosen't Exist."
272$ WRITE SYS$OUTPUT ""
273$!
274$! Exit The Build.
275$!
276$ EXIT
277$!
278$! End The DESTEST.C File Check.
279$!
280$ ENDIF
281$!
282$! Tell The User What We Are Building.
283$!
284$ WRITE SYS$OUTPUT "Building ",EXE_DIR,"DESTEST.EXE"
285$!
286$! Compile The DESTEST Program.
287$!
288$ CC/OBJECT='OBJ_DIR'DESTEST.OBJ SYS$DISK:[]DESTEST.C
289$!
290$! Link The DESTEST Program.
291$!
292$ LINK/'DEBUGGER'/'TRACEBACK'/CONTIGUOUS/EXE='EXE_DIR'DESTEST.EXE -
293 'OBJ_DIR'DESTEST.OBJ,'LIB_NAME'/LIBRARY,'OPT_FILE'/OPTION
294$!
295$! All Done, Time To Return.
296$!
297$ RETURN
298$!
299$! Compile The SPEED Program.
300$!
301$ SPEED:
302$!
303$! Check To See If We Have The Proper Libraries.
304$!
305$ GOSUB LIB_CHECK
306$!
307$! Check To See If We Have A Linker Option File.
308$!
309$ GOSUB CHECK_OPT_FILE
310$!
311$! Check To See If The File We Want To Compile Actually Exists.
312$!
313$ IF (F$SEARCH("SYS$DISK:[]SPEED.C").EQS."")
314$ THEN
315$!
316$! Tell The User That The File Dosen't Exist.
317$!
318$ WRITE SYS$OUTPUT ""
319$ WRITE SYS$OUTPUT "The File SPEED.C Dosen't Exist."
320$ WRITE SYS$OUTPUT ""
321$!
322$! Exit The Build.
323$!
324$ EXIT
325$!
326$! End The SPEED.C File Check.
327$!
328$ ENDIF
329$!
330$! Tell The User What We Are Building.
331$!
332$ WRITE SYS$OUTPUT "Building ",EXE_DIR,"SPEED.EXE"
333$!
334$! Compile The SPEED Program.
335$!
336$ CC/OBJECT='OBJ_DIR'SPEED.OBJ SYS$DISK:[]SPEED.C
337$!
338$! Link The SPEED Program.
339$!
340$ LINK/'DEBUGGER'/'TRACEBACK'/CONTIGUOUS/EXE='EXE_DIR'SPEED.EXE -
341 'OBJ_DIR'SPEED.OBJ,'LIB_NAME'/LIBRARY,'OPT_FILE'/OPTION
342$!
343$! All Done, Time To Return.
344$!
345$ RETURN
346$!
347$! Compile The RPW Program.
348$!
349$ RPW:
350$!
351$! Check To See If We Have The Proper Libraries.
352$!
353$ GOSUB LIB_CHECK
354$!
355$! Check To See If We Have A Linker Option File.
356$!
357$ GOSUB CHECK_OPT_FILE
358$!
359$! Check To See If The File We Want To Compile Actually Exists.
360$!
361$ IF (F$SEARCH("SYS$DISK:[]RPW.C").EQS."")
362$ THEN
363$!
364$! Tell The User That The File Dosen't Exist.
365$!
366$ WRITE SYS$OUTPUT ""
367$ WRITE SYS$OUTPUT "The File RPW.C Dosen't Exist."
368$ WRITE SYS$OUTPUT ""
369$!
370$! Exit The Build.
371$!
372$ EXIT
373$!
374$! End The RPW.C File Check.
375$!
376$ ENDIF
377$!
378$! Tell The User What We Are Building.
379$!
380$ WRITE SYS$OUTPUT "Building ",EXE_DIR,"RPW.EXE"
381$!
382$! Compile The RPW Program.
383$!
384$ CC/OBJECT='OBJ_DIR'RPW.OBJ SYS$DISK:[]RPW.C
385$!
386$! Link The RPW Program.
387$!
388$ LINK/'DEBUGGER'/'TRACEBACK'/CONTIGUOUS/EXE='EXE_DIR'RPW.EXE -
389 'OBJ_DIR'RPW.OBJ,'LIB_NAME'/LIBRARY,'OPT_FILE'/OPTION
390$!
391$! All Done, Time To Return.
392$!
393$ RETURN
394$!
395$! Compile The DES Program.
396$!
397$ DES:
398$!
399$! Check To See If We Have The Proper Libraries.
400$!
401$ GOSUB LIB_CHECK
402$!
403$! Check To See If We Have A Linker Option File.
404$!
405$ GOSUB CHECK_OPT_FILE
406$!
407$! Check To See If The File We Want To Compile Actually Exists.
408$!
409$ IF (F$SEARCH("SYS$DISK:[]DES.C").EQS."")
410$ THEN
411$!
412$! Tell The User That The File Dosen't Exist.
413$!
414$ WRITE SYS$OUTPUT ""
415$ WRITE SYS$OUTPUT "The File DES.C Dosen't Exist."
416$ WRITE SYS$OUTPUT ""
417$!
418$! Exit The Build.
419$!
420$ EXIT
421$!
422$! End The DES.C File Check.
423$!
424$ ENDIF
425$!
426$! Tell The User What We Are Building.
427$!
428$ WRITE SYS$OUTPUT "Building ",EXE_DIR,"DES.EXE"
429$!
430$! Compile The DES Program.
431$!
432$ CC/OBJECT='OBJ_DIR'DES.OBJ SYS$DISK:[]DES.C
433$ CC/OBJECT='OBJ_DIR'DES.OBJ SYS$DISK:[]CBC3_ENC.C
434$!
435$! Link The DES Program.
436$!
437$ LINK/'DEBUGGER'/'TRACEBACK'/CONTIGUOUS/EXE='EXE_DIR'DES.EXE -
438 'OBJ_DIR'DES.OBJ,'OBJ_DIR'CBC3_ENC.OBJ,-
439 'LIB_NAME'/LIBRARY,'OPT_FILE'/OPTION
440$!
441$! All Done, Time To Return.
442$!
443$ RETURN
444$!
445$! Compile The DES_OPTS Program.
446$!
447$ DES_OPTS:
448$!
449$! Check To See If We Have The Proper Libraries.
450$!
451$ GOSUB LIB_CHECK
452$!
453$! Check To See If We Have A Linker Option File.
454$!
455$ GOSUB CHECK_OPT_FILE
456$!
457$! Check To See If The File We Want To Compile Actually Exists.
458$!
459$ IF (F$SEARCH("SYS$DISK:[]DES_OPTS.C").EQS."")
460$ THEN
461$!
462$! Tell The User That The File Dosen't Exist.
463$!
464$ WRITE SYS$OUTPUT ""
465$ WRITE SYS$OUTPUT "The File DES_OPTS.C Dosen't Exist."
466$ WRITE SYS$OUTPUT ""
467$!
468$! Exit The Build.
469$!
470$ EXIT
471$!
472$! End The DES_OPTS.C File Check.
473$!
474$ ENDIF
475$!
476$! Tell The User What We Are Building.
477$!
478$ WRITE SYS$OUTPUT "Building ",EXE_DIR,"DES_OPTS.EXE"
479$!
480$! Compile The DES_OPTS Program.
481$!
482$ CC/OBJECT='OBJ_DIR'DES_OPTS.OBJ SYS$DISK:[]DES_OPTS.C
483$!
484$! Link The DES_OPTS Program.
485$!
486$ LINK/'DEBUGGER'/'TRACEBACK'/CONTIGUOUS/EXE='EXE_DIR'DES_OPTS.EXE -
487 'OBJ_DIR'DES_OPTS.OBJ,'LIB_NAME'/LIBRARY,'OPT_FILE'/OPTION
488$!
489$! All Done, Time To Return.
490$!
491$ RETURN
492$ EXIT
493$!
494$! Check For The Link Option FIle.
495$!
496$ CHECK_OPT_FILE:
497$!
498$! Check To See If We Need To Make A VAX C Option File.
499$!
500$ IF (COMPILER.EQS."VAXC")
501$ THEN
502$!
503$! Check To See If We Already Have A VAX C Linker Option File.
504$!
505$ IF (F$SEARCH(OPT_FILE).EQS."")
506$ THEN
507$!
508$! We Need A VAX C Linker Option File.
509$!
510$ CREATE 'OPT_FILE'
511$DECK
512!
513! Default System Options File To Link Agianst
514! The Sharable VAX C Runtime Library.
515!
516SYS$SHARE:VAXCRTL.EXE/SHARE
517$EOD
518$!
519$! End The Option File Check.
520$!
521$ ENDIF
522$!
523$! End The VAXC Check.
524$!
525$ ENDIF
526$!
527$! Check To See If We Need A GNU C Option File.
528$!
529$ IF (COMPILER.EQS."GNUC")
530$ THEN
531$!
532$! Check To See If We Already Have A GNU C Linker Option File.
533$!
534$ IF (F$SEARCH(OPT_FILE).EQS."")
535$ THEN
536$!
537$! We Need A GNU C Linker Option File.
538$!
539$ CREATE 'OPT_FILE'
540$DECK
541!
542! Default System Options File To Link Agianst
543! The Sharable C Runtime Library.
544!
545GNU_CC:[000000]GCCLIB/LIBRARY
546SYS$SHARE:VAXCRTL/SHARE
547$EOD
548$!
549$! End The Option File Check.
550$!
551$ ENDIF
552$!
553$! End The GNU C Check.
554$!
555$ ENDIF
556$!
557$! Check To See If We Need A DEC C Option File.
558$!
559$ IF (COMPILER.EQS."DECC")
560$ THEN
561$!
562$! Check To See If We Already Have A DEC C Linker Option File.
563$!
564$ IF (F$SEARCH(OPT_FILE).EQS."")
565$ THEN
566$!
567$! Figure Out If We Need An AXP Or A VAX Linker Option File.
568$!
569$ IF (F$GETSYI("CPU").LT.128)
570$ THEN
571$!
572$! We Need A DEC C Linker Option File For VAX.
573$!
574$ CREATE 'OPT_FILE'
575$DECK
576!
577! Default System Options File To Link Agianst
578! The Sharable DEC C Runtime Library.
579!
580SYS$SHARE:DECC$SHR.EXE/SHARE
581$EOD
582$!
583$! Else...
584$!
585$ ELSE
586$!
587$! Create The AXP Linker Option File.
588$!
589$ CREATE 'OPT_FILE'
590$DECK
591!
592! Default System Options File For AXP To Link Agianst
593! The Sharable C Runtime Library.
594!
595SYS$SHARE:CMA$OPEN_LIB_SHR/SHARE
596SYS$SHARE:CMA$OPEN_RTL/SHARE
597$EOD
598$!
599$! End The VAX/AXP DEC C Option File Check.
600$!
601$ ENDIF
602$!
603$! End The Option File Search.
604$!
605$ ENDIF
606$!
607$! End The DEC C Check.
608$!
609$ ENDIF
610$!
611$! Tell The User What Linker Option File We Are Using.
612$!
613$ WRITE SYS$OUTPUT "Using Linker Option File ",OPT_FILE,"."
614$!
615$! Time To RETURN.
616$!
617$ RETURN
618$!
619$! Library Check.
620$!
621$ LIB_CHECK:
622$!
623$! Look For The Library LIBDES.OLB.
624$!
625$ IF (F$SEARCH(LIB_NAME).EQS."")
626$ THEN
627$!
628$! Tell The User We Can't Find The [.xxx.CRYPTO.DES]LIBDES.OLB Library.
629$!
630$ WRITE SYS$OUTPUT ""
631$ WRITE SYS$OUTPUT "Can't Find The Library ",LIB_NAME,"."
632$ WRITE SYS$OUTPUT "We Can't Link Without It."
633$ WRITE SYS$OUTPUT ""
634$!
635$! Since We Can't Link Without It, Exit.
636$!
637$ EXIT
638$ ENDIF
639$!
640$! Time To Return.
641$!
642$ RETURN
643$!
644$! Check The User's Options.
645$!
646$ CHECK_OPTIONS:
647$!
648$! Check To See If We Are To "Just Build Everything".
649$!
650$ IF (P1.EQS."ALL")
651$ THEN
652$!
653$! P1 Is "ALL", So Build Everything.
654$!
655$ BUILDALL = "TRUE"
656$!
657$! Else...
658$!
659$ ELSE
660$!
661$! Else, Check To See If P1 Has A Valid Arguement.
662$!
663$ IF (P1.EQS."LIBRARY").OR.(P1.EQS."DESTEST").OR.(P1.EQS."SPEED") -
664 .OR.(P1.EQS."RPW").OR.(P1.EQS."DES").OR.(P1.EQS."DES_OPTS")
665$ THEN
666$!
667$! A Valid Arguement.
668$!
669$ BUILDALL = P1
670$!
671$! Else...
672$!
673$ ELSE
674$!
675$! Tell The User We Don't Know What They Want.
676$!
677$ WRITE SYS$OUTPUT ""
678$ WRITE SYS$OUTPUT "The Option ",P1," Is Invalid. The Valid Options Are:"
679$ WRITE SYS$OUTPUT ""
680$ WRITE SYS$OUTPUT " ALL : Just Build Everything.
681$ WRITE SYS$OUTPUT " LIBRARY : To Compile Just The [.xxx.EXE.CRYPTO.DES]LIBDES.OLB Library."
682$ WRITE SYS$OUTPUT " DESTEST : To Compile Just The [.xxx.EXE.CRYPTO.DES]DESTEST.EXE Program."
683$ WRITE SYS$OUTPUT " SPEED : To Compile Just The [.xxx.EXE.CRYPTO.DES]SPEED.EXE Program."
684$ WRITE SYS$OUTPUT " RPW : To Compile Just The [.xxx.EXE.CRYPTO.DES]RPW.EXE Program."
685$ WRITE SYS$OUTPUT " DES : To Compile Just The [.xxx.EXE.CRYPTO.DES]DES.EXE Program."
686$ WRITE SYS$OUTPUT " DES_OPTS : To Compile Just The [.xxx.EXE.CRYTPO.DES]DES_OPTS.EXE Program."
687$ WRITE SYS$OUTPUT ""
688$ WRITE SYS$OUTPUT " Where 'xxx' Stands For: "
689$ WRITE SYS$OUTPUT ""
690$ WRITE SYS$OUTPUT " AXP : Alpha Architecture."
691$ WRITE SYS$OUTPUT " VAX : VAX Architecture."
692$ WRITE SYS$OUTPUT ""
693$!
694$! Time To EXIT.
695$!
696$ EXIT
697$!
698$! End The Valid Arguement Check.
699$!
700$ ENDIF
701$!
702$! End The P1 Check.
703$!
704$ ENDIF
705$!
706$! Check To See If We Are To Compile Without Debugger Information.
707$!
708$ IF (P2.EQS."NODEBUG")
709$ THEN
710$!
711$! P2 Is Blank, So Compile Without Debugger Information.
712$!
713$ DEBUGGER = "NODEBUG"
714$ TRACEBACK = "NOTRACEBACK"
715$ GCC_OPTIMIZE = "OPTIMIZE"
716$ CC_OPTIMIZE = "OPTIMIZE"
717$ WRITE SYS$OUTPUT "No Debugger Information Will Be Produced During Compile."
718$ WRITE SYS$OUTPUT "Compiling With Compiler Optimization."
719$!
720$! Else...
721$!
722$ ELSE
723$!
724$! Check To See If We Are To Compile With Debugger Information.
725$!
726$ IF (P2.EQS."DEBUG")
727$ THEN
728$!
729$! Compile With Debugger Information.
730$!
731$ DEBUGGER = "DEBUG"
732$ TRACEBACK = "TRACEBACK"
733$ GCC_OPTIMIZE = "NOOPTIMIZE"
734$ CC_OPTIMIZE = "NOOPTIMIZE"
735$ WRITE SYS$OUTPUT "Debugger Information Will Be Produced During Compile."
736$ WRITE SYS$OUTPUT "Compiling Without Compiler Optimization."
737$!
738$! Else...
739$!
740$ ELSE
741$!
742$! Tell The User Entered An Invalid Option..
743$!
744$ WRITE SYS$OUTPUT ""
745$ WRITE SYS$OUTPUT "The Option ",P2," Is Invalid. The Valid Options Are:"
746$ WRITE SYS$OUTPUT ""
747$ WRITE SYS$OUTPUT " DEBUG : Compile With The Debugger Information."
748$ WRITE SYS$OUTPUT " NODEBUG : Compile Without The Debugger Information."
749$ WRITE SYS$OUTPUT ""
750$!
751$! Time To EXIT.
752$!
753$ EXIT
754$!
755$! End The Valid Arguement Check.
756$!
757$ ENDIF
758$!
759$! End The P2 Check.
760$!
761$ ENDIF
762$!
763$! Special Threads For OpenVMS v7.1 Or Later.
764$!
765$! Written By: Richard Levitte
766$! richard@levitte.org
767$!
768$!
769$! Check To See If We Have A Option For P4.
770$!
771$ IF (P4.EQS."")
772$ THEN
773$!
774$! Get The Version Of VMS We Are Using.
775$!
776$ ISSEVEN := ""
777$ TMP = F$ELEMENT(0,"-",F$EXTRACT(1,4,F$GETSYI("VERSION")))
778$ TMP = F$INTEGER(F$ELEMENT(0,".",TMP)+F$ELEMENT(1,".",TMP))
779$!
780$! Check To See If The VMS Version Is v7.1 Or Later.
781$!
782$ IF (TMP.GE.71)
783$ THEN
784$!
785$! We Have OpenVMS v7.1 Or Later, So Use The Special Threads.
786$!
787$ ISSEVEN := ,PTHREAD_USE_D4
788$!
789$! End The VMS Version Check.
790$!
791$ ENDIF
792$!
793$! End The P4 Check.
794$!
795$ ENDIF
796$!
797$! Check To See If P3 Is Blank.
798$!
799$ IF (P3.EQS."")
800$ THEN
801$!
802$! O.K., The User Didn't Specify A Compiler, Let's Try To
803$! Find Out Which One To Use.
804$!
805$! Check To See If We Have GNU C.
806$!
807$ IF (F$TRNLNM("GNU_CC").NES."")
808$ THEN
809$!
810$! Looks Like GNUC, Set To Use GNUC.
811$!
812$ P3 = "GNUC"
813$!
814$! Else...
815$!
816$ ELSE
817$!
818$! Check To See If We Have VAXC Or DECC.
819$!
820$ IF (ARCH.EQS."AXP").OR.(F$TRNLNM("DECC$CC_DEFAULT").NES."")
821$ THEN
822$!
823$! Looks Like DECC, Set To Use DECC.
824$!
825$ P3 = "DECC"
826$!
827$! Else...
828$!
829$ ELSE
830$!
831$! Looks Like VAXC, Set To Use VAXC.
832$!
833$ P3 = "VAXC"
834$!
835$! End The VAXC Compiler Check.
836$!
837$ ENDIF
838$!
839$! End The DECC & VAXC Compiler Check.
840$!
841$ ENDIF
842$!
843$! End The Compiler Check.
844$!
845$ ENDIF
846$!
847$! Set Up Initial CC Definitions, Possibly With User Ones
848$!
849$ CCDEFS = "VMS=1"
850$ IF F$TYPE(USER_CCDEFS) .NES. "" THEN CCDEFS = CCDEFS + "," + USER_CCDEFS
851$ CCEXTRAFLAGS = ""
852$ IF F$TYPE(USER_CCFLAGS) .NES. "" THEN CCEXTRAFLAGS = USER_CCFLAGS
853$ CCDISABLEWARNINGS = ""
854$ IF F$TYPE(USER_CCDISABLEWARNINGS) .NES. "" THEN -
855 CCDISABLEWARNINGS = USER_CCDISABLEWARNINGS
856$!
857$! Check To See If The User Entered A Valid Paramter.
858$!
859$ IF (P3.EQS."VAXC").OR.(P3.EQS."DECC").OR.(P3.EQS."GNUC")
860$ THEN
861$!
862$! Check To See If The User Wanted DECC.
863$!
864$ IF (P3.EQS."DECC")
865$ THEN
866$!
867$! Looks Like DECC, Set To Use DECC.
868$!
869$ COMPILER = "DECC"
870$!
871$! Tell The User We Are Using DECC.
872$!
873$ WRITE SYS$OUTPUT "Using DECC 'C' Compiler."
874$!
875$! Use DECC...
876$!
877$ CC = "CC"
878$ IF ARCH.EQS."VAX" .AND. F$TRNLNM("DECC$CC_DEFAULT").NES."/DECC" -
879 THEN CC = "CC/DECC"
880$ CC = CC + "/''CC_OPTIMIZE'/''DEBUGGER'/STANDARD=ANSI89" + -
881 "/NOLIST/PREFIX=ALL" + CCEXTRAFLAGS
882$!
883$! Define The Linker Options File Name.
884$!
885$ OPT_FILE = "SYS$DISK:[]VAX_DECC_OPTIONS.OPT"
886$!
887$! End DECC Check.
888$!
889$ ENDIF
890$!
891$! Check To See If We Are To Use VAXC.
892$!
893$ IF (P3.EQS."VAXC")
894$ THEN
895$!
896$! Looks Like VAXC, Set To Use VAXC.
897$!
898$ COMPILER = "VAXC"
899$!
900$! Tell The User We Are Using VAX C.
901$!
902$ WRITE SYS$OUTPUT "Using VAXC 'C' Compiler."
903$!
904$! Compile Using VAXC.
905$!
906$ CC = "CC"
907$ IF ARCH.EQS."AXP"
908$ THEN
909$ WRITE SYS$OUTPUT "There is no VAX C on Alpha!"
910$ EXIT
911$ ENDIF
912$ IF F$TRNLNM("DECC$CC_DEFAULT").EQS."/DECC" THEN CC = "CC/VAXC"
913$ CC = CC + "/''CC_OPTIMIZE'/''DEBUGGER'/NOLIST" + CCEXTRAFLAGS
914$ CCDEFS = """VAXC""," + CCDEFS
915$!
916$! Define <sys> As SYS$COMMON:[SYSLIB]
917$!
918$ DEFINE/NOLOG SYS SYS$COMMON:[SYSLIB]
919$!
920$! Define The Linker Options File Name.
921$!
922$ OPT_FILE = "SYS$DISK:[]VAX_VAXC_OPTIONS.OPT"
923$!
924$! End VAXC Check
925$!
926$ ENDIF
927$!
928$! Check To See If We Are To Use GNU C.
929$!
930$ IF (P3.EQS."GNUC")
931$ THEN
932$!
933$! Looks Like GNUC, Set To Use GNUC.
934$!
935$ COMPILER = "GNUC"
936$!
937$! Tell The User We Are Using GNUC.
938$!
939$ WRITE SYS$OUTPUT "Using GNU 'C' Compiler."
940$!
941$! Use GNU C...
942$!
943$ CC = "GCC/NOCASE_HACK/''GCC_OPTIMIZE'/''DEBUGGER'/NOLIST" + CCEXTRAFLAGS
944$!
945$! Define The Linker Options File Name.
946$!
947$ OPT_FILE = "SYS$DISK:[]VAX_GNUC_OPTIONS.OPT"
948$!
949$! End The GNU C Check.
950$!
951$ ENDIF
952$!
953$! Set up default defines
954$!
955$ CCDEFS = """FLAT_INC=1""," + CCDEFS
956$!
957$! Finish up the definition of CC.
958$!
959$ IF COMPILER .EQS. "DECC"
960$ THEN
961$ IF CCDISABLEWARNINGS .EQS. ""
962$ THEN
963$ CC4DISABLEWARNINGS = "DOLLARID"
964$ ELSE
965$ CC4DISABLEWARNINGS = CCDISABLEWARNINGS + ",DOLLARID"
966$ CCDISABLEWARNINGS = "/WARNING=(DISABLE=(" + CCDISABLEWARNINGS + "))"
967$ ENDIF
968$ CC4DISABLEWARNINGS = "/WARNING=(DISABLE=(" + CC4DISABLEWARNINGS + "))"
969$ ELSE
970$ CCDISABLEWARNINGS = ""
971$ CC4DISABLEWARNINGS = ""
972$ ENDIF
973$ CC = CC + "/DEFINE=(" + CCDEFS + ")" + CCDISABLEWARNINGS
974$!
975$! Show user the result
976$!
977$ WRITE SYS$OUTPUT "Main Compiling Command: ",CC
978$!
979$! Else The User Entered An Invalid Arguement.
980$!
981$ ELSE
982$!
983$! Tell The User We Don't Know What They Want.
984$!
985$ WRITE SYS$OUTPUT ""
986$ WRITE SYS$OUTPUT "The Option ",P3," Is Invalid. The Valid Options Are:"
987$ WRITE SYS$OUTPUT ""
988$ WRITE SYS$OUTPUT " VAXC : To Compile With VAX C."
989$ WRITE SYS$OUTPUT " DECC : To Compile With DEC C."
990$ WRITE SYS$OUTPUT " GNUC : To Compile With GNU C."
991$ WRITE SYS$OUTPUT ""
992$!
993$! Time To EXIT.
994$!
995$ EXIT
996$!
997$! End The P3 Check.
998$!
999$ ENDIF
1000$!
1001$! Time To RETURN...
1002$!
1003$ RETURN
diff --git a/src/lib/libcrypto/des/des.pod b/src/lib/libcrypto/des/des.pod
new file mode 100644
index 0000000000..bf479e83d2
--- /dev/null
+++ b/src/lib/libcrypto/des/des.pod
@@ -0,0 +1,217 @@
1=pod
2
3=head1 NAME
4
5des - encrypt or decrypt data using Data Encryption Standard
6
7=head1 SYNOPSIS
8
9B<des>
10(
11B<-e>
12|
13B<-E>
14) | (
15B<-d>
16|
17B<-D>
18) | (
19B<->[B<cC>][B<ckname>]
20) |
21[
22B<-b3hfs>
23] [
24B<-k>
25I<key>
26]
27] [
28B<-u>[I<uuname>]
29[
30I<input-file>
31[
32I<output-file>
33] ]
34
35=head1 NOTE
36
37This page describes the B<des> stand-alone program, not the B<openssl des>
38command.
39
40=head1 DESCRIPTION
41
42B<des>
43encrypts and decrypts data using the
44Data Encryption Standard algorithm.
45One of
46B<-e>, B<-E>
47(for encrypt) or
48B<-d>, B<-D>
49(for decrypt) must be specified.
50It is also possible to use
51B<-c>
52or
53B<-C>
54in conjunction or instead of the a encrypt/decrypt option to generate
55a 16 character hexadecimal checksum, generated via the
56I<des_cbc_cksum>.
57
58Two standard encryption modes are supported by the
59B<des>
60program, Cipher Block Chaining (the default) and Electronic Code Book
61(specified with
62B<-b>).
63
64The key used for the DES
65algorithm is obtained by prompting the user unless the
66B<-k>
67I<key>
68option is given.
69If the key is an argument to the
70B<des>
71command, it is potentially visible to users executing
72ps(1)
73or a derivative. To minimise this possibility,
74B<des>
75takes care to destroy the key argument immediately upon entry.
76If your shell keeps a history file be careful to make sure it is not
77world readable.
78
79Since this program attempts to maintain compatibility with sunOS's
80des(1) command, there are 2 different methods used to convert the user
81supplied key to a des key.
82Whenever and one or more of
83B<-E>, B<-D>, B<-C>
84or
85B<-3>
86options are used, the key conversion procedure will not be compatible
87with the sunOS des(1) version but will use all the user supplied
88character to generate the des key.
89B<des>
90command reads from standard input unless
91I<input-file>
92is specified and writes to standard output unless
93I<output-file>
94is given.
95
96=head1 OPTIONS
97
98=over 4
99
100=item B<-b>
101
102Select ECB
103(eight bytes at a time) encryption mode.
104
105=item B<-3>
106
107Encrypt using triple encryption.
108By default triple cbc encryption is used but if the
109B<-b>
110option is used then triple ECB encryption is performed.
111If the key is less than 8 characters long, the flag has no effect.
112
113=item B<-e>
114
115Encrypt data using an 8 byte key in a manner compatible with sunOS
116des(1).
117
118=item B<-E>
119
120Encrypt data using a key of nearly unlimited length (1024 bytes).
121This will product a more secure encryption.
122
123=item B<-d>
124
125Decrypt data that was encrypted with the B<-e> option.
126
127=item B<-D>
128
129Decrypt data that was encrypted with the B<-E> option.
130
131=item B<-c>
132
133Generate a 16 character hexadecimal cbc checksum and output this to
134stderr.
135If a filename was specified after the
136B<-c>
137option, the checksum is output to that file.
138The checksum is generated using a key generated in a sunOS compatible
139manner.
140
141=item B<-C>
142
143A cbc checksum is generated in the same manner as described for the
144B<-c>
145option but the DES key is generated in the same manner as used for the
146B<-E>
147and
148B<-D>
149options
150
151=item B<-f>
152
153Does nothing - allowed for compatibility with sunOS des(1) command.
154
155=item B<-s>
156
157Does nothing - allowed for compatibility with sunOS des(1) command.
158
159=item B<-k> I<key>
160
161Use the encryption
162I<key>
163specified.
164
165=item B<-h>
166
167The
168I<key>
169is assumed to be a 16 character hexadecimal number.
170If the
171B<-3>
172option is used the key is assumed to be a 32 character hexadecimal
173number.
174
175=item B<-u>
176
177This flag is used to read and write uuencoded files. If decrypting,
178the input file is assumed to contain uuencoded, DES encrypted data.
179If encrypting, the characters following the B<-u> are used as the name of
180the uuencoded file to embed in the begin line of the uuencoded
181output. If there is no name specified after the B<-u>, the name text.des
182will be embedded in the header.
183
184=head1 SEE ALSO
185
186ps(1),
187L<des_crypt(3)|des_crypt(3)>
188
189=head1 BUGS
190
191The problem with using the
192B<-e>
193option is the short key length.
194It would be better to use a real 56-bit key rather than an
195ASCII-based 56-bit pattern. Knowing that the key was derived from ASCII
196radically reduces the time necessary for a brute-force cryptographic attack.
197My attempt to remove this problem is to add an alternative text-key to
198DES-key function. This alternative function (accessed via
199B<-E>, B<-D>, B<-S>
200and
201B<-3>)
202uses DES to help generate the key.
203
204Be carefully when using the B<-u> option. Doing B<des -ud> I<filename> will
205not decrypt filename (the B<-u> option will gobble the B<-d> option).
206
207The VMS operating system operates in a world where files are always a
208multiple of 512 bytes. This causes problems when encrypted data is
209send from Unix to VMS since a 88 byte file will suddenly be padded
210with 424 null bytes. To get around this problem, use the B<-u> option
211to uuencode the data before it is send to the VMS system.
212
213=head1 AUTHOR
214
215Eric Young (eay@cryptsoft.com)
216
217=cut
diff --git a/src/lib/libcrypto/des/des_old.c b/src/lib/libcrypto/des/des_old.c
new file mode 100644
index 0000000000..7e4cd7180d
--- /dev/null
+++ b/src/lib/libcrypto/des/des_old.c
@@ -0,0 +1,271 @@
1/* crypto/des/des_old.c -*- mode:C; c-file-style: "eay" -*- */
2
3/* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
4 *
5 * The function names in here are deprecated and are only present to
6 * provide an interface compatible with libdes. OpenSSL now provides
7 * functions where "des_" has been replaced with "DES_" in the names,
8 * to make it possible to make incompatible changes that are needed
9 * for C type security and other stuff.
10 *
11 * Please consider starting to use the DES_ functions rather than the
12 * des_ ones. The des_ functions will dissapear completely before
13 * OpenSSL 1.0!
14 *
15 * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
16 */
17
18/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
19 * project 2001.
20 */
21/* ====================================================================
22 * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
23 *
24 * Redistribution and use in source and binary forms, with or without
25 * modification, are permitted provided that the following conditions
26 * are met:
27 *
28 * 1. Redistributions of source code must retain the above copyright
29 * notice, this list of conditions and the following disclaimer.
30 *
31 * 2. Redistributions in binary form must reproduce the above copyright
32 * notice, this list of conditions and the following disclaimer in
33 * the documentation and/or other materials provided with the
34 * distribution.
35 *
36 * 3. All advertising materials mentioning features or use of this
37 * software must display the following acknowledgment:
38 * "This product includes software developed by the OpenSSL Project
39 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
40 *
41 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
42 * endorse or promote products derived from this software without
43 * prior written permission. For written permission, please contact
44 * openssl-core@openssl.org.
45 *
46 * 5. Products derived from this software may not be called "OpenSSL"
47 * nor may "OpenSSL" appear in their names without prior written
48 * permission of the OpenSSL Project.
49 *
50 * 6. Redistributions of any form whatsoever must retain the following
51 * acknowledgment:
52 * "This product includes software developed by the OpenSSL Project
53 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
54 *
55 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
56 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
57 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
58 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
59 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
60 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
61 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
62 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
63 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
64 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
65 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
66 * OF THE POSSIBILITY OF SUCH DAMAGE.
67 * ====================================================================
68 *
69 * This product includes cryptographic software written by Eric Young
70 * (eay@cryptsoft.com). This product includes software written by Tim
71 * Hudson (tjh@cryptsoft.com).
72 *
73 */
74
75#define OPENSSL_DES_LIBDES_COMPATIBILITY
76#include <openssl/des.h>
77#include <openssl/rand.h>
78
79const char *_ossl_old_des_options(void)
80 {
81 return DES_options();
82 }
83void _ossl_old_des_ecb3_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,
84 des_key_schedule ks1,des_key_schedule ks2,
85 des_key_schedule ks3, int enc)
86 {
87 DES_ecb3_encrypt((const_DES_cblock *)input, output,
88 (DES_key_schedule *)ks1, (DES_key_schedule *)ks2,
89 (DES_key_schedule *)ks3, enc);
90 }
91DES_LONG _ossl_old_des_cbc_cksum(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,
92 long length,des_key_schedule schedule,_ossl_old_des_cblock *ivec)
93 {
94 return DES_cbc_cksum((unsigned char *)input, output, length,
95 (DES_key_schedule *)schedule, ivec);
96 }
97void _ossl_old_des_cbc_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,long length,
98 des_key_schedule schedule,_ossl_old_des_cblock *ivec,int enc)
99 {
100 DES_cbc_encrypt((unsigned char *)input, (unsigned char *)output,
101 length, (DES_key_schedule *)schedule, ivec, enc);
102 }
103void _ossl_old_des_ncbc_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,long length,
104 des_key_schedule schedule,_ossl_old_des_cblock *ivec,int enc)
105 {
106 DES_ncbc_encrypt((unsigned char *)input, (unsigned char *)output,
107 length, (DES_key_schedule *)schedule, ivec, enc);
108 }
109void _ossl_old_des_xcbc_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,long length,
110 des_key_schedule schedule,_ossl_old_des_cblock *ivec,
111 _ossl_old_des_cblock *inw,_ossl_old_des_cblock *outw,int enc)
112 {
113 DES_xcbc_encrypt((unsigned char *)input, (unsigned char *)output,
114 length, (DES_key_schedule *)schedule, ivec, inw, outw, enc);
115 }
116void _ossl_old_des_cfb_encrypt(unsigned char *in,unsigned char *out,int numbits,
117 long length,des_key_schedule schedule,_ossl_old_des_cblock *ivec,int enc)
118 {
119 DES_cfb_encrypt(in, out, numbits, length,
120 (DES_key_schedule *)schedule, ivec, enc);
121 }
122void _ossl_old_des_ecb_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,
123 des_key_schedule ks,int enc)
124 {
125 DES_ecb_encrypt(input, output, (DES_key_schedule *)ks, enc);
126 }
127void _ossl_old_des_encrypt(DES_LONG *data,des_key_schedule ks, int enc)
128 {
129 DES_encrypt1(data, (DES_key_schedule *)ks, enc);
130 }
131void _ossl_old_des_encrypt2(DES_LONG *data,des_key_schedule ks, int enc)
132 {
133 DES_encrypt2(data, (DES_key_schedule *)ks, enc);
134 }
135void _ossl_old_des_encrypt3(DES_LONG *data, des_key_schedule ks1,
136 des_key_schedule ks2, des_key_schedule ks3)
137 {
138 DES_encrypt3(data, (DES_key_schedule *)ks1, (DES_key_schedule *)ks2,
139 (DES_key_schedule *)ks3);
140 }
141void _ossl_old_des_decrypt3(DES_LONG *data, des_key_schedule ks1,
142 des_key_schedule ks2, des_key_schedule ks3)
143 {
144 DES_decrypt3(data, (DES_key_schedule *)ks1, (DES_key_schedule *)ks2,
145 (DES_key_schedule *)ks3);
146 }
147void _ossl_old_des_ede3_cbc_encrypt(_ossl_old_des_cblock *input, _ossl_old_des_cblock *output,
148 long length, des_key_schedule ks1, des_key_schedule ks2,
149 des_key_schedule ks3, _ossl_old_des_cblock *ivec, int enc)
150 {
151 DES_ede3_cbc_encrypt((unsigned char *)input, (unsigned char *)output,
152 length, (DES_key_schedule *)ks1, (DES_key_schedule *)ks2,
153 (DES_key_schedule *)ks3, ivec, enc);
154 }
155void _ossl_old_des_ede3_cfb64_encrypt(unsigned char *in, unsigned char *out,
156 long length, des_key_schedule ks1, des_key_schedule ks2,
157 des_key_schedule ks3, _ossl_old_des_cblock *ivec, int *num, int enc)
158 {
159 DES_ede3_cfb64_encrypt(in, out, length,
160 (DES_key_schedule *)ks1, (DES_key_schedule *)ks2,
161 (DES_key_schedule *)ks3, ivec, num, enc);
162 }
163void _ossl_old_des_ede3_ofb64_encrypt(unsigned char *in, unsigned char *out,
164 long length, des_key_schedule ks1, des_key_schedule ks2,
165 des_key_schedule ks3, _ossl_old_des_cblock *ivec, int *num)
166 {
167 DES_ede3_ofb64_encrypt(in, out, length,
168 (DES_key_schedule *)ks1, (DES_key_schedule *)ks2,
169 (DES_key_schedule *)ks3, ivec, num);
170 }
171
172void _ossl_old_des_xwhite_in2out(_ossl_old_des_cblock (*des_key), _ossl_old_des_cblock (*in_white),
173 _ossl_old_des_cblock (*out_white))
174 {
175 DES_xwhite_in2out(des_key, in_white, out_white);
176 }
177
178int _ossl_old_des_enc_read(int fd,char *buf,int len,des_key_schedule sched,
179 _ossl_old_des_cblock *iv)
180 {
181 return DES_enc_read(fd, buf, len, (DES_key_schedule *)sched, iv);
182 }
183int _ossl_old_des_enc_write(int fd,char *buf,int len,des_key_schedule sched,
184 _ossl_old_des_cblock *iv)
185 {
186 return DES_enc_write(fd, buf, len, (DES_key_schedule *)sched, iv);
187 }
188char *_ossl_old_des_fcrypt(const char *buf,const char *salt, char *ret)
189 {
190 return DES_fcrypt(buf, salt, ret);
191 }
192char *_ossl_old_des_crypt(const char *buf,const char *salt)
193 {
194 return DES_crypt(buf, salt);
195 }
196char *_ossl_old_crypt(const char *buf,const char *salt)
197 {
198 return DES_crypt(buf, salt);
199 }
200void _ossl_old_des_ofb_encrypt(unsigned char *in,unsigned char *out,
201 int numbits,long length,des_key_schedule schedule,_ossl_old_des_cblock *ivec)
202 {
203 DES_ofb_encrypt(in, out, numbits, length, (DES_key_schedule *)schedule,
204 ivec);
205 }
206void _ossl_old_des_pcbc_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,long length,
207 des_key_schedule schedule,_ossl_old_des_cblock *ivec,int enc)
208 {
209 DES_pcbc_encrypt((unsigned char *)input, (unsigned char *)output,
210 length, (DES_key_schedule *)schedule, ivec, enc);
211 }
212DES_LONG _ossl_old_des_quad_cksum(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,
213 long length,int out_count,_ossl_old_des_cblock *seed)
214 {
215 return DES_quad_cksum((unsigned char *)input, output, length,
216 out_count, seed);
217 }
218void _ossl_old_des_random_seed(_ossl_old_des_cblock key)
219 {
220 RAND_seed(key, sizeof(_ossl_old_des_cblock));
221 }
222void _ossl_old_des_random_key(_ossl_old_des_cblock ret)
223 {
224 DES_random_key((DES_cblock *)ret);
225 }
226int _ossl_old_des_read_password(_ossl_old_des_cblock *key, const char *prompt,
227 int verify)
228 {
229 return DES_read_password(key, prompt, verify);
230 }
231int _ossl_old_des_read_2passwords(_ossl_old_des_cblock *key1, _ossl_old_des_cblock *key2,
232 const char *prompt, int verify)
233 {
234 return DES_read_2passwords(key1, key2, prompt, verify);
235 }
236void _ossl_old_des_set_odd_parity(_ossl_old_des_cblock *key)
237 {
238 DES_set_odd_parity(key);
239 }
240int _ossl_old_des_is_weak_key(_ossl_old_des_cblock *key)
241 {
242 return DES_is_weak_key(key);
243 }
244int _ossl_old_des_set_key(_ossl_old_des_cblock *key,des_key_schedule schedule)
245 {
246 return DES_set_key(key, (DES_key_schedule *)schedule);
247 }
248int _ossl_old_des_key_sched(_ossl_old_des_cblock *key,des_key_schedule schedule)
249 {
250 return DES_key_sched(key, (DES_key_schedule *)schedule);
251 }
252void _ossl_old_des_string_to_key(char *str,_ossl_old_des_cblock *key)
253 {
254 DES_string_to_key(str, key);
255 }
256void _ossl_old_des_string_to_2keys(char *str,_ossl_old_des_cblock *key1,_ossl_old_des_cblock *key2)
257 {
258 DES_string_to_2keys(str, key1, key2);
259 }
260void _ossl_old_des_cfb64_encrypt(unsigned char *in, unsigned char *out, long length,
261 des_key_schedule schedule, _ossl_old_des_cblock *ivec, int *num, int enc)
262 {
263 DES_cfb64_encrypt(in, out, length, (DES_key_schedule *)schedule,
264 ivec, num, enc);
265 }
266void _ossl_old_des_ofb64_encrypt(unsigned char *in, unsigned char *out, long length,
267 des_key_schedule schedule, _ossl_old_des_cblock *ivec, int *num)
268 {
269 DES_ofb64_encrypt(in, out, length, (DES_key_schedule *)schedule,
270 ivec, num);
271 }
diff --git a/src/lib/libcrypto/des/des_old.h b/src/lib/libcrypto/des/des_old.h
new file mode 100644
index 0000000000..3778f93c15
--- /dev/null
+++ b/src/lib/libcrypto/des/des_old.h
@@ -0,0 +1,437 @@
1/* crypto/des/des_old.h -*- mode:C; c-file-style: "eay" -*- */
2
3/* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
4 *
5 * The function names in here are deprecated and are only present to
6 * provide an interface compatible with openssl 0.9.6 and older as
7 * well as libdes. OpenSSL now provides functions where "des_" has
8 * been replaced with "DES_" in the names, to make it possible to
9 * make incompatible changes that are needed for C type security and
10 * other stuff.
11 *
12 * This include files has two compatibility modes:
13 *
14 * - If OPENSSL_DES_LIBDES_COMPATIBILITY is defined, you get an API
15 * that is compatible with libdes and SSLeay.
16 * - If OPENSSL_DES_LIBDES_COMPATIBILITY isn't defined, you get an
17 * API that is compatible with OpenSSL 0.9.5x to 0.9.6x.
18 *
19 * Note that these modes break earlier snapshots of OpenSSL, where
20 * libdes compatibility was the only available mode or (later on) the
21 * prefered compatibility mode. However, after much consideration
22 * (and more or less violent discussions with external parties), it
23 * was concluded that OpenSSL should be compatible with earlier versions
24 * of itself before anything else. Also, in all honesty, libdes is
25 * an old beast that shouldn't really be used any more.
26 *
27 * Please consider starting to use the DES_ functions rather than the
28 * des_ ones. The des_ functions will disappear completely before
29 * OpenSSL 1.0!
30 *
31 * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
32 */
33
34/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
35 * project 2001.
36 */
37/* ====================================================================
38 * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved.
39 *
40 * Redistribution and use in source and binary forms, with or without
41 * modification, are permitted provided that the following conditions
42 * are met:
43 *
44 * 1. Redistributions of source code must retain the above copyright
45 * notice, this list of conditions and the following disclaimer.
46 *
47 * 2. Redistributions in binary form must reproduce the above copyright
48 * notice, this list of conditions and the following disclaimer in
49 * the documentation and/or other materials provided with the
50 * distribution.
51 *
52 * 3. All advertising materials mentioning features or use of this
53 * software must display the following acknowledgment:
54 * "This product includes software developed by the OpenSSL Project
55 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
56 *
57 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
58 * endorse or promote products derived from this software without
59 * prior written permission. For written permission, please contact
60 * openssl-core@openssl.org.
61 *
62 * 5. Products derived from this software may not be called "OpenSSL"
63 * nor may "OpenSSL" appear in their names without prior written
64 * permission of the OpenSSL Project.
65 *
66 * 6. Redistributions of any form whatsoever must retain the following
67 * acknowledgment:
68 * "This product includes software developed by the OpenSSL Project
69 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
70 *
71 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
72 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
73 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
74 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
75 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
76 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
77 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
78 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
79 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
80 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
81 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
82 * OF THE POSSIBILITY OF SUCH DAMAGE.
83 * ====================================================================
84 *
85 * This product includes cryptographic software written by Eric Young
86 * (eay@cryptsoft.com). This product includes software written by Tim
87 * Hudson (tjh@cryptsoft.com).
88 *
89 */
90
91#ifndef HEADER_DES_OLD_H
92#define HEADER_DES_OLD_H
93
94#ifdef OPENSSL_NO_DES
95#error DES is disabled.
96#endif
97
98#ifndef HEADER_DES_H
99#error You must include des.h, not des_old.h directly.
100#endif
101
102#ifdef _KERBEROS_DES_H
103#error <openssl/des_old.h> replaces <kerberos/des.h>.
104#endif
105
106#include <openssl/opensslconf.h> /* DES_LONG */
107#include <openssl/e_os2.h> /* OPENSSL_EXTERN */
108#include <openssl/symhacks.h>
109
110#ifdef OPENSSL_BUILD_SHLIBCRYPTO
111# undef OPENSSL_EXTERN
112# define OPENSSL_EXTERN OPENSSL_EXPORT
113#endif
114
115#ifdef __cplusplus
116extern "C" {
117#endif
118
119typedef unsigned char _ossl_old_des_cblock[8];
120typedef struct _ossl_old_des_ks_struct
121 {
122 union {
123 _ossl_old_des_cblock _;
124 /* make sure things are correct size on machines with
125 * 8 byte longs */
126 DES_LONG pad[2];
127 } ks;
128 } _ossl_old_des_key_schedule[16];
129
130#ifndef OPENSSL_DES_LIBDES_COMPATIBILITY
131#define des_cblock DES_cblock
132#define const_des_cblock const_DES_cblock
133#define des_key_schedule DES_key_schedule
134#define des_ecb3_encrypt(i,o,k1,k2,k3,e)\
135 DES_ecb3_encrypt((i),(o),&(k1),&(k2),&(k3),(e))
136#define des_ede3_cbc_encrypt(i,o,l,k1,k2,k3,iv,e)\
137 DES_ede3_cbc_encrypt((i),(o),(l),&(k1),&(k2),&(k3),(iv),(e))
138#define des_ede3_cbcm_encrypt(i,o,l,k1,k2,k3,iv1,iv2,e)\
139 DES_ede3_cbcm_encrypt((i),(o),(l),&(k1),&(k2),&(k3),(iv1),(iv2),(e))
140#define des_ede3_cfb64_encrypt(i,o,l,k1,k2,k3,iv,n,e)\
141 DES_ede3_cfb64_encrypt((i),(o),(l),&(k1),&(k2),&(k3),(iv),(n),(e))
142#define des_ede3_ofb64_encrypt(i,o,l,k1,k2,k3,iv,n)\
143 DES_ede3_ofb64_encrypt((i),(o),(l),&(k1),&(k2),&(k3),(iv),(n))
144#define des_options()\
145 DES_options()
146#define des_cbc_cksum(i,o,l,k,iv)\
147 DES_cbc_cksum((i),(o),(l),&(k),(iv))
148#define des_cbc_encrypt(i,o,l,k,iv,e)\
149 DES_cbc_encrypt((i),(o),(l),&(k),(iv),(e))
150#define des_ncbc_encrypt(i,o,l,k,iv,e)\
151 DES_ncbc_encrypt((i),(o),(l),&(k),(iv),(e))
152#define des_xcbc_encrypt(i,o,l,k,iv,inw,outw,e)\
153 DES_xcbc_encrypt((i),(o),(l),&(k),(iv),(inw),(outw),(e))
154#define des_cfb_encrypt(i,o,n,l,k,iv,e)\
155 DES_cfb_encrypt((i),(o),(n),(l),&(k),(iv),(e))
156#define des_ecb_encrypt(i,o,k,e)\
157 DES_ecb_encrypt((i),(o),&(k),(e))
158#define des_encrypt1(d,k,e)\
159 DES_encrypt1((d),&(k),(e))
160#define des_encrypt2(d,k,e)\
161 DES_encrypt2((d),&(k),(e))
162#define des_encrypt3(d,k1,k2,k3)\
163 DES_encrypt3((d),&(k1),&(k2),&(k3))
164#define des_decrypt3(d,k1,k2,k3)\
165 DES_decrypt3((d),&(k1),&(k2),&(k3))
166#define des_xwhite_in2out(k,i,o)\
167 DES_xwhite_in2out((k),(i),(o))
168#define des_enc_read(f,b,l,k,iv)\
169 DES_enc_read((f),(b),(l),&(k),(iv))
170#define des_enc_write(f,b,l,k,iv)\
171 DES_enc_write((f),(b),(l),&(k),(iv))
172#define des_fcrypt(b,s,r)\
173 DES_fcrypt((b),(s),(r))
174#define des_crypt(b,s)\
175 DES_crypt((b),(s))
176#if !defined(PERL5) && !defined(__FreeBSD__) && !defined(NeXT)
177#define crypt(b,s)\
178 DES_crypt((b),(s))
179#endif
180#define des_ofb_encrypt(i,o,n,l,k,iv)\
181 DES_ofb_encrypt((i),(o),(n),(l),&(k),(iv))
182#define des_pcbc_encrypt(i,o,l,k,iv,e)\
183 DES_pcbc_encrypt((i),(o),(l),&(k),(iv),(e))
184#define des_quad_cksum(i,o,l,c,s)\
185 DES_quad_cksum((i),(o),(l),(c),(s))
186#define des_random_seed(k)\
187 _ossl_096_des_random_seed((k))
188#define des_random_key(r)\
189 DES_random_key((r))
190#define des_read_password(k,p,v) \
191 DES_read_password((k),(p),(v))
192#define des_read_2passwords(k1,k2,p,v) \
193 DES_read_2passwords((k1),(k2),(p),(v))
194#define des_set_odd_parity(k)\
195 DES_set_odd_parity((k))
196#define des_check_key_parity(k)\
197 DES_check_key_parity((k))
198#define des_is_weak_key(k)\
199 DES_is_weak_key((k))
200#define des_set_key(k,ks)\
201 DES_set_key((k),&(ks))
202#define des_key_sched(k,ks)\
203 DES_key_sched((k),&(ks))
204#define des_set_key_checked(k,ks)\
205 DES_set_key_checked((k),&(ks))
206#define des_set_key_unchecked(k,ks)\
207 DES_set_key_unchecked((k),&(ks))
208#define des_string_to_key(s,k)\
209 DES_string_to_key((s),(k))
210#define des_string_to_2keys(s,k1,k2)\
211 DES_string_to_2keys((s),(k1),(k2))
212#define des_cfb64_encrypt(i,o,l,ks,iv,n,e)\
213 DES_cfb64_encrypt((i),(o),(l),&(ks),(iv),(n),(e))
214#define des_ofb64_encrypt(i,o,l,ks,iv,n)\
215 DES_ofb64_encrypt((i),(o),(l),&(ks),(iv),(n))
216
217
218#define des_ecb2_encrypt(i,o,k1,k2,e) \
219 des_ecb3_encrypt((i),(o),(k1),(k2),(k1),(e))
220
221#define des_ede2_cbc_encrypt(i,o,l,k1,k2,iv,e) \
222 des_ede3_cbc_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(e))
223
224#define des_ede2_cfb64_encrypt(i,o,l,k1,k2,iv,n,e) \
225 des_ede3_cfb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n),(e))
226
227#define des_ede2_ofb64_encrypt(i,o,l,k1,k2,iv,n) \
228 des_ede3_ofb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n))
229
230#define des_check_key DES_check_key
231#define des_rw_mode DES_rw_mode
232#else /* libdes compatibility */
233/* Map all symbol names to _ossl_old_des_* form, so we avoid all
234 clashes with libdes */
235#define des_cblock _ossl_old_des_cblock
236#define des_key_schedule _ossl_old_des_key_schedule
237#define des_ecb3_encrypt(i,o,k1,k2,k3,e)\
238 _ossl_old_des_ecb3_encrypt((i),(o),(k1),(k2),(k3),(e))
239#define des_ede3_cbc_encrypt(i,o,l,k1,k2,k3,iv,e)\
240 _ossl_old_des_ede3_cbc_encrypt((i),(o),(l),(k1),(k2),(k3),(iv),(e))
241#define des_ede3_cfb64_encrypt(i,o,l,k1,k2,k3,iv,n,e)\
242 _ossl_old_des_ede3_cfb64_encrypt((i),(o),(l),(k1),(k2),(k3),(iv),(n),(e))
243#define des_ede3_ofb64_encrypt(i,o,l,k1,k2,k3,iv,n)\
244 _ossl_old_des_ede3_ofb64_encrypt((i),(o),(l),(k1),(k2),(k3),(iv),(n))
245#define des_options()\
246 _ossl_old_des_options()
247#define des_cbc_cksum(i,o,l,k,iv)\
248 _ossl_old_des_cbc_cksum((i),(o),(l),(k),(iv))
249#define des_cbc_encrypt(i,o,l,k,iv,e)\
250 _ossl_old_des_cbc_encrypt((i),(o),(l),(k),(iv),(e))
251#define des_ncbc_encrypt(i,o,l,k,iv,e)\
252 _ossl_old_des_ncbc_encrypt((i),(o),(l),(k),(iv),(e))
253#define des_xcbc_encrypt(i,o,l,k,iv,inw,outw,e)\
254 _ossl_old_des_xcbc_encrypt((i),(o),(l),(k),(iv),(inw),(outw),(e))
255#define des_cfb_encrypt(i,o,n,l,k,iv,e)\
256 _ossl_old_des_cfb_encrypt((i),(o),(n),(l),(k),(iv),(e))
257#define des_ecb_encrypt(i,o,k,e)\
258 _ossl_old_des_ecb_encrypt((i),(o),(k),(e))
259#define des_encrypt(d,k,e)\
260 _ossl_old_des_encrypt((d),(k),(e))
261#define des_encrypt2(d,k,e)\
262 _ossl_old_des_encrypt2((d),(k),(e))
263#define des_encrypt3(d,k1,k2,k3)\
264 _ossl_old_des_encrypt3((d),(k1),(k2),(k3))
265#define des_decrypt3(d,k1,k2,k3)\
266 _ossl_old_des_decrypt3((d),(k1),(k2),(k3))
267#define des_xwhite_in2out(k,i,o)\
268 _ossl_old_des_xwhite_in2out((k),(i),(o))
269#define des_enc_read(f,b,l,k,iv)\
270 _ossl_old_des_enc_read((f),(b),(l),(k),(iv))
271#define des_enc_write(f,b,l,k,iv)\
272 _ossl_old_des_enc_write((f),(b),(l),(k),(iv))
273#define des_fcrypt(b,s,r)\
274 _ossl_old_des_fcrypt((b),(s),(r))
275#define des_crypt(b,s)\
276 _ossl_old_des_crypt((b),(s))
277#define crypt(b,s)\
278 _ossl_old_crypt((b),(s))
279#define des_ofb_encrypt(i,o,n,l,k,iv)\
280 _ossl_old_des_ofb_encrypt((i),(o),(n),(l),(k),(iv))
281#define des_pcbc_encrypt(i,o,l,k,iv,e)\
282 _ossl_old_des_pcbc_encrypt((i),(o),(l),(k),(iv),(e))
283#define des_quad_cksum(i,o,l,c,s)\
284 _ossl_old_des_quad_cksum((i),(o),(l),(c),(s))
285#define des_random_seed(k)\
286 _ossl_old_des_random_seed((k))
287#define des_random_key(r)\
288 _ossl_old_des_random_key((r))
289#define des_read_password(k,p,v) \
290 _ossl_old_des_read_password((k),(p),(v))
291#define des_read_2passwords(k1,k2,p,v) \
292 _ossl_old_des_read_2passwords((k1),(k2),(p),(v))
293#define des_set_odd_parity(k)\
294 _ossl_old_des_set_odd_parity((k))
295#define des_is_weak_key(k)\
296 _ossl_old_des_is_weak_key((k))
297#define des_set_key(k,ks)\
298 _ossl_old_des_set_key((k),(ks))
299#define des_key_sched(k,ks)\
300 _ossl_old_des_key_sched((k),(ks))
301#define des_string_to_key(s,k)\
302 _ossl_old_des_string_to_key((s),(k))
303#define des_string_to_2keys(s,k1,k2)\
304 _ossl_old_des_string_to_2keys((s),(k1),(k2))
305#define des_cfb64_encrypt(i,o,l,ks,iv,n,e)\
306 _ossl_old_des_cfb64_encrypt((i),(o),(l),(ks),(iv),(n),(e))
307#define des_ofb64_encrypt(i,o,l,ks,iv,n)\
308 _ossl_old_des_ofb64_encrypt((i),(o),(l),(ks),(iv),(n))
309
310
311#define des_ecb2_encrypt(i,o,k1,k2,e) \
312 des_ecb3_encrypt((i),(o),(k1),(k2),(k1),(e))
313
314#define des_ede2_cbc_encrypt(i,o,l,k1,k2,iv,e) \
315 des_ede3_cbc_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(e))
316
317#define des_ede2_cfb64_encrypt(i,o,l,k1,k2,iv,n,e) \
318 des_ede3_cfb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n),(e))
319
320#define des_ede2_ofb64_encrypt(i,o,l,k1,k2,iv,n) \
321 des_ede3_ofb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n))
322
323#define des_check_key DES_check_key
324#define des_rw_mode DES_rw_mode
325#endif
326
327const char *_ossl_old_des_options(void);
328void _ossl_old_des_ecb3_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,
329 _ossl_old_des_key_schedule ks1,_ossl_old_des_key_schedule ks2,
330 _ossl_old_des_key_schedule ks3, int enc);
331DES_LONG _ossl_old_des_cbc_cksum(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,
332 long length,_ossl_old_des_key_schedule schedule,_ossl_old_des_cblock *ivec);
333void _ossl_old_des_cbc_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,long length,
334 _ossl_old_des_key_schedule schedule,_ossl_old_des_cblock *ivec,int enc);
335void _ossl_old_des_ncbc_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,long length,
336 _ossl_old_des_key_schedule schedule,_ossl_old_des_cblock *ivec,int enc);
337void _ossl_old_des_xcbc_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,long length,
338 _ossl_old_des_key_schedule schedule,_ossl_old_des_cblock *ivec,
339 _ossl_old_des_cblock *inw,_ossl_old_des_cblock *outw,int enc);
340void _ossl_old_des_cfb_encrypt(unsigned char *in,unsigned char *out,int numbits,
341 long length,_ossl_old_des_key_schedule schedule,_ossl_old_des_cblock *ivec,int enc);
342void _ossl_old_des_ecb_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,
343 _ossl_old_des_key_schedule ks,int enc);
344void _ossl_old_des_encrypt(DES_LONG *data,_ossl_old_des_key_schedule ks, int enc);
345void _ossl_old_des_encrypt2(DES_LONG *data,_ossl_old_des_key_schedule ks, int enc);
346void _ossl_old_des_encrypt3(DES_LONG *data, _ossl_old_des_key_schedule ks1,
347 _ossl_old_des_key_schedule ks2, _ossl_old_des_key_schedule ks3);
348void _ossl_old_des_decrypt3(DES_LONG *data, _ossl_old_des_key_schedule ks1,
349 _ossl_old_des_key_schedule ks2, _ossl_old_des_key_schedule ks3);
350void _ossl_old_des_ede3_cbc_encrypt(_ossl_old_des_cblock *input, _ossl_old_des_cblock *output,
351 long length, _ossl_old_des_key_schedule ks1, _ossl_old_des_key_schedule ks2,
352 _ossl_old_des_key_schedule ks3, _ossl_old_des_cblock *ivec, int enc);
353void _ossl_old_des_ede3_cfb64_encrypt(unsigned char *in, unsigned char *out,
354 long length, _ossl_old_des_key_schedule ks1, _ossl_old_des_key_schedule ks2,
355 _ossl_old_des_key_schedule ks3, _ossl_old_des_cblock *ivec, int *num, int enc);
356void _ossl_old_des_ede3_ofb64_encrypt(unsigned char *in, unsigned char *out,
357 long length, _ossl_old_des_key_schedule ks1, _ossl_old_des_key_schedule ks2,
358 _ossl_old_des_key_schedule ks3, _ossl_old_des_cblock *ivec, int *num);
359
360void _ossl_old_des_xwhite_in2out(_ossl_old_des_cblock (*des_key), _ossl_old_des_cblock (*in_white),
361 _ossl_old_des_cblock (*out_white));
362
363int _ossl_old_des_enc_read(int fd,char *buf,int len,_ossl_old_des_key_schedule sched,
364 _ossl_old_des_cblock *iv);
365int _ossl_old_des_enc_write(int fd,char *buf,int len,_ossl_old_des_key_schedule sched,
366 _ossl_old_des_cblock *iv);
367char *_ossl_old_des_fcrypt(const char *buf,const char *salt, char *ret);
368char *_ossl_old_des_crypt(const char *buf,const char *salt);
369#if !defined(PERL5) && !defined(__FreeBSD__) && !defined(NeXT)
370char *_ossl_old_crypt(const char *buf,const char *salt);
371#endif
372void _ossl_old_des_ofb_encrypt(unsigned char *in,unsigned char *out,
373 int numbits,long length,_ossl_old_des_key_schedule schedule,_ossl_old_des_cblock *ivec);
374void _ossl_old_des_pcbc_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,long length,
375 _ossl_old_des_key_schedule schedule,_ossl_old_des_cblock *ivec,int enc);
376DES_LONG _ossl_old_des_quad_cksum(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,
377 long length,int out_count,_ossl_old_des_cblock *seed);
378void _ossl_old_des_random_seed(_ossl_old_des_cblock key);
379void _ossl_old_des_random_key(_ossl_old_des_cblock ret);
380int _ossl_old_des_read_password(_ossl_old_des_cblock *key,const char *prompt,int verify);
381int _ossl_old_des_read_2passwords(_ossl_old_des_cblock *key1,_ossl_old_des_cblock *key2,
382 const char *prompt,int verify);
383void _ossl_old_des_set_odd_parity(_ossl_old_des_cblock *key);
384int _ossl_old_des_is_weak_key(_ossl_old_des_cblock *key);
385int _ossl_old_des_set_key(_ossl_old_des_cblock *key,_ossl_old_des_key_schedule schedule);
386int _ossl_old_des_key_sched(_ossl_old_des_cblock *key,_ossl_old_des_key_schedule schedule);
387void _ossl_old_des_string_to_key(char *str,_ossl_old_des_cblock *key);
388void _ossl_old_des_string_to_2keys(char *str,_ossl_old_des_cblock *key1,_ossl_old_des_cblock *key2);
389void _ossl_old_des_cfb64_encrypt(unsigned char *in, unsigned char *out, long length,
390 _ossl_old_des_key_schedule schedule, _ossl_old_des_cblock *ivec, int *num, int enc);
391void _ossl_old_des_ofb64_encrypt(unsigned char *in, unsigned char *out, long length,
392 _ossl_old_des_key_schedule schedule, _ossl_old_des_cblock *ivec, int *num);
393
394void _ossl_096_des_random_seed(des_cblock *key);
395
396/* The following definitions provide compatibility with the MIT Kerberos
397 * library. The _ossl_old_des_key_schedule structure is not binary compatible. */
398
399#define _KERBEROS_DES_H
400
401#define KRBDES_ENCRYPT DES_ENCRYPT
402#define KRBDES_DECRYPT DES_DECRYPT
403
404#ifdef KERBEROS
405# define ENCRYPT DES_ENCRYPT
406# define DECRYPT DES_DECRYPT
407#endif
408
409#ifndef NCOMPAT
410# define C_Block des_cblock
411# define Key_schedule des_key_schedule
412# define KEY_SZ DES_KEY_SZ
413# define string_to_key des_string_to_key
414# define read_pw_string des_read_pw_string
415# define random_key des_random_key
416# define pcbc_encrypt des_pcbc_encrypt
417# define set_key des_set_key
418# define key_sched des_key_sched
419# define ecb_encrypt des_ecb_encrypt
420# define cbc_encrypt des_cbc_encrypt
421# define ncbc_encrypt des_ncbc_encrypt
422# define xcbc_encrypt des_xcbc_encrypt
423# define cbc_cksum des_cbc_cksum
424# define quad_cksum des_quad_cksum
425# define check_parity des_check_key_parity
426#endif
427
428#define des_fixup_key_parity DES_fixup_key_parity
429
430#ifdef __cplusplus
431}
432#endif
433
434/* for DES_read_pw_string et al */
435#include <openssl/ui_compat.h>
436
437#endif
diff --git a/src/lib/libcrypto/des/des_old2.c b/src/lib/libcrypto/des/des_old2.c
new file mode 100644
index 0000000000..c8fa3ee135
--- /dev/null
+++ b/src/lib/libcrypto/des/des_old2.c
@@ -0,0 +1,82 @@
1/* crypto/des/des_old.c -*- mode:C; c-file-style: "eay" -*- */
2
3/* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
4 *
5 * The function names in here are deprecated and are only present to
6 * provide an interface compatible with OpenSSL 0.9.6c. OpenSSL now
7 * provides functions where "des_" has been replaced with "DES_" in
8 * the names, to make it possible to make incompatible changes that
9 * are needed for C type security and other stuff.
10 *
11 * Please consider starting to use the DES_ functions rather than the
12 * des_ ones. The des_ functions will dissapear completely before
13 * OpenSSL 1.0!
14 *
15 * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
16 */
17
18/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
19 * project 2001.
20 */
21/* ====================================================================
22 * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
23 *
24 * Redistribution and use in source and binary forms, with or without
25 * modification, are permitted provided that the following conditions
26 * are met:
27 *
28 * 1. Redistributions of source code must retain the above copyright
29 * notice, this list of conditions and the following disclaimer.
30 *
31 * 2. Redistributions in binary form must reproduce the above copyright
32 * notice, this list of conditions and the following disclaimer in
33 * the documentation and/or other materials provided with the
34 * distribution.
35 *
36 * 3. All advertising materials mentioning features or use of this
37 * software must display the following acknowledgment:
38 * "This product includes software developed by the OpenSSL Project
39 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
40 *
41 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
42 * endorse or promote products derived from this software without
43 * prior written permission. For written permission, please contact
44 * openssl-core@openssl.org.
45 *
46 * 5. Products derived from this software may not be called "OpenSSL"
47 * nor may "OpenSSL" appear in their names without prior written
48 * permission of the OpenSSL Project.
49 *
50 * 6. Redistributions of any form whatsoever must retain the following
51 * acknowledgment:
52 * "This product includes software developed by the OpenSSL Project
53 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
54 *
55 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
56 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
57 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
58 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
59 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
60 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
61 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
62 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
63 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
64 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
65 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
66 * OF THE POSSIBILITY OF SUCH DAMAGE.
67 * ====================================================================
68 *
69 * This product includes cryptographic software written by Eric Young
70 * (eay@cryptsoft.com). This product includes software written by Tim
71 * Hudson (tjh@cryptsoft.com).
72 *
73 */
74
75#undef OPENSSL_DES_LIBDES_COMPATIBILITY
76#include <openssl/des.h>
77#include <openssl/rand.h>
78
79void _ossl_096_des_random_seed(DES_cblock *key)
80 {
81 RAND_seed(key, sizeof(DES_cblock));
82 }
diff --git a/src/lib/libcrypto/dso/README b/src/lib/libcrypto/dso/README
new file mode 100644
index 0000000000..6ba03c5631
--- /dev/null
+++ b/src/lib/libcrypto/dso/README
@@ -0,0 +1,24 @@
1TODO
2----
3
4Find a way where name-translation can be done in a way that is
5sensitive to particular methods (ie. generic code could still do
6different path/filename substitutions on win32 to what it does on
7*nix) but doesn't assume some canonical form. Already one case
8exists where the "blah -> (libblah.so,blah.dll)" mapping doesn't
9suffice. I suspect a callback with an enumerated (or string?)
10parameter could be the way to go here ... DSO_ctrl the callback
11into place and it can be invoked to handle name translation with
12some clue to the calling code as to what kind of system it is.
13
14NOTES
15-----
16
17I've checked out HPUX (well, version 11 at least) and shl_t is
18a pointer type so it's safe to use in the way it has been in
19dso_dl.c. On the other hand, HPUX11 support dlfcn too and
20according to their man page, prefer developers to move to that.
21I'll leave Richard's changes there as I guess dso_dl is needed
22for HPUX10.20.
23
24
diff --git a/src/lib/libcrypto/dso/dso_dl.c b/src/lib/libcrypto/dso/dso_dl.c
new file mode 100644
index 0000000000..69810fc3bb
--- /dev/null
+++ b/src/lib/libcrypto/dso/dso_dl.c
@@ -0,0 +1,251 @@
1/* dso_dl.c */
2/* Written by Richard Levitte (levitte@openssl.org) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 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 * licensing@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 <stdio.h>
60#include "cryptlib.h"
61#include <openssl/dso.h>
62
63#ifndef DSO_DL
64DSO_METHOD *DSO_METHOD_dl(void)
65 {
66 return NULL;
67 }
68#else
69
70#include <dl.h>
71
72/* Part of the hack in "dl_load" ... */
73#define DSO_MAX_TRANSLATED_SIZE 256
74
75static int dl_load(DSO *dso, const char *filename);
76static int dl_unload(DSO *dso);
77static void *dl_bind_var(DSO *dso, const char *symname);
78static DSO_FUNC_TYPE dl_bind_func(DSO *dso, const char *symname);
79#if 0
80static int dl_unbind_var(DSO *dso, char *symname, void *symptr);
81static int dl_unbind_func(DSO *dso, char *symname, DSO_FUNC_TYPE symptr);
82static int dl_init(DSO *dso);
83static int dl_finish(DSO *dso);
84#endif
85static int dl_ctrl(DSO *dso, int cmd, long larg, void *parg);
86
87static DSO_METHOD dso_meth_dl = {
88 "OpenSSL 'dl' shared library method",
89 dl_load,
90 dl_unload,
91 dl_bind_var,
92 dl_bind_func,
93/* For now, "unbind" doesn't exist */
94#if 0
95 NULL, /* unbind_var */
96 NULL, /* unbind_func */
97#endif
98 dl_ctrl,
99 NULL, /* init */
100 NULL /* finish */
101 };
102
103DSO_METHOD *DSO_METHOD_dl(void)
104 {
105 return(&dso_meth_dl);
106 }
107
108/* For this DSO_METHOD, our meth_data STACK will contain;
109 * (i) the handle (shl_t) returned from shl_load().
110 * NB: I checked on HPUX11 and shl_t is itself a pointer
111 * type so the cast is safe.
112 */
113
114static int dl_load(DSO *dso, const char *filename)
115 {
116 shl_t ptr;
117 char translated[DSO_MAX_TRANSLATED_SIZE];
118 int len;
119
120 /* The same comment as in dlfcn_load applies here. bleurgh. */
121 len = strlen(filename);
122 if((dso->flags & DSO_FLAG_NAME_TRANSLATION) &&
123 (len + 6 < DSO_MAX_TRANSLATED_SIZE) &&
124 (strstr(filename, "/") == NULL))
125 {
126 sprintf(translated, "lib%s.so", filename);
127 ptr = shl_load(translated, BIND_IMMEDIATE, NULL);
128 }
129 else
130 ptr = shl_load(filename, BIND_IMMEDIATE, NULL);
131 if(ptr == NULL)
132 {
133 DSOerr(DSO_F_DL_LOAD,DSO_R_LOAD_FAILED);
134 return(0);
135 }
136 if(!sk_push(dso->meth_data, (char *)ptr))
137 {
138 DSOerr(DSO_F_DL_LOAD,DSO_R_STACK_ERROR);
139 shl_unload(ptr);
140 return(0);
141 }
142 return(1);
143 }
144
145static int dl_unload(DSO *dso)
146 {
147 shl_t ptr;
148 if(dso == NULL)
149 {
150 DSOerr(DSO_F_DL_UNLOAD,ERR_R_PASSED_NULL_PARAMETER);
151 return(0);
152 }
153 if(sk_num(dso->meth_data) < 1)
154 return(1);
155 /* Is this statement legal? */
156 ptr = (shl_t)sk_pop(dso->meth_data);
157 if(ptr == NULL)
158 {
159 DSOerr(DSO_F_DL_UNLOAD,DSO_R_NULL_HANDLE);
160 /* Should push the value back onto the stack in
161 * case of a retry. */
162 sk_push(dso->meth_data, (char *)ptr);
163 return(0);
164 }
165 shl_unload(ptr);
166 return(1);
167 }
168
169static void *dl_bind_var(DSO *dso, const char *symname)
170 {
171 shl_t ptr;
172 void *sym;
173
174 if((dso == NULL) || (symname == NULL))
175 {
176 DSOerr(DSO_F_DL_BIND_VAR,ERR_R_PASSED_NULL_PARAMETER);
177 return(NULL);
178 }
179 if(sk_num(dso->meth_data) < 1)
180 {
181 DSOerr(DSO_F_DL_BIND_VAR,DSO_R_STACK_ERROR);
182 return(NULL);
183 }
184 ptr = (shl_t)sk_value(dso->meth_data, sk_num(dso->meth_data) - 1);
185 if(ptr == NULL)
186 {
187 DSOerr(DSO_F_DL_BIND_VAR,DSO_R_NULL_HANDLE);
188 return(NULL);
189 }
190 if (shl_findsym(ptr, symname, TYPE_UNDEFINED, &sym) < 0)
191 {
192 DSOerr(DSO_F_DL_BIND_VAR,DSO_R_SYM_FAILURE);
193 return(NULL);
194 }
195 return(sym);
196 }
197
198static DSO_FUNC_TYPE dl_bind_func(DSO *dso, const char *symname)
199 {
200 shl_t ptr;
201 void *sym;
202
203 if((dso == NULL) || (symname == NULL))
204 {
205 DSOerr(DSO_F_DL_BIND_FUNC,ERR_R_PASSED_NULL_PARAMETER);
206 return(NULL);
207 }
208 if(sk_num(dso->meth_data) < 1)
209 {
210 DSOerr(DSO_F_DL_BIND_FUNC,DSO_R_STACK_ERROR);
211 return(NULL);
212 }
213 ptr = (shl_t)sk_value(dso->meth_data, sk_num(dso->meth_data) - 1);
214 if(ptr == NULL)
215 {
216 DSOerr(DSO_F_DL_BIND_FUNC,DSO_R_NULL_HANDLE);
217 return(NULL);
218 }
219 if (shl_findsym(ptr, symname, TYPE_UNDEFINED, &sym) < 0)
220 {
221 DSOerr(DSO_F_DL_BIND_FUNC,DSO_R_SYM_FAILURE);
222 return(NULL);
223 }
224 return((DSO_FUNC_TYPE)sym);
225 }
226
227static int dl_ctrl(DSO *dso, int cmd, long larg, void *parg)
228 {
229 if(dso == NULL)
230 {
231 DSOerr(DSO_F_DL_CTRL,ERR_R_PASSED_NULL_PARAMETER);
232 return(-1);
233 }
234 switch(cmd)
235 {
236 case DSO_CTRL_GET_FLAGS:
237 return dso->flags;
238 case DSO_CTRL_SET_FLAGS:
239 dso->flags = (int)larg;
240 return(0);
241 case DSO_CTRL_OR_FLAGS:
242 dso->flags |= (int)larg;
243 return(0);
244 default:
245 break;
246 }
247 DSOerr(DSO_F_DL_CTRL,DSO_R_UNKNOWN_COMMAND);
248 return(-1);
249 }
250
251#endif /* DSO_DL */
diff --git a/src/lib/libcrypto/dso/dso_vms.c b/src/lib/libcrypto/dso/dso_vms.c
new file mode 100644
index 0000000000..8ff7090129
--- /dev/null
+++ b/src/lib/libcrypto/dso/dso_vms.c
@@ -0,0 +1,371 @@
1/* dso_vms.c */
2/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 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 * licensing@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 <stdio.h>
60#include <string.h>
61#include <errno.h>
62#ifdef VMS
63#pragma message disable DOLLARID
64#include <lib$routines.h>
65#include <libfisdef.h>
66#include <stsdef.h>
67#include <descrip.h>
68#include <starlet.h>
69#endif
70#include "cryptlib.h"
71#include <openssl/dso.h>
72
73#ifndef VMS
74DSO_METHOD *DSO_METHOD_vms(void)
75 {
76 return NULL;
77 }
78#else
79#pragma message disable DOLLARID
80
81static int vms_load(DSO *dso, const char *filename);
82static int vms_unload(DSO *dso);
83static void *vms_bind_var(DSO *dso, const char *symname);
84static DSO_FUNC_TYPE vms_bind_func(DSO *dso, const char *symname);
85#if 0
86static int vms_unbind_var(DSO *dso, char *symname, void *symptr);
87static int vms_unbind_func(DSO *dso, char *symname, DSO_FUNC_TYPE symptr);
88static int vms_init(DSO *dso);
89static int vms_finish(DSO *dso);
90#endif
91static long vms_ctrl(DSO *dso, int cmd, long larg, void *parg);
92
93static DSO_METHOD dso_meth_vms = {
94 "OpenSSL 'VMS' shared library method",
95 vms_load,
96 NULL, /* unload */
97 vms_bind_var,
98 vms_bind_func,
99/* For now, "unbind" doesn't exist */
100#if 0
101 NULL, /* unbind_var */
102 NULL, /* unbind_func */
103#endif
104 vms_ctrl,
105 NULL, /* init */
106 NULL /* finish */
107 };
108
109/* On VMS, the only "handle" is the file name. LIB$FIND_IMAGE_SYMBOL depends
110 * on the reference to the file name being the same for all calls regarding
111 * one shared image, so we'll just store it in an instance of the following
112 * structure and put a pointer to that instance in the meth_data stack.
113 */
114typedef struct dso_internal_st
115 {
116 /* This should contain the name only, no directory,
117 * no extension, nothing but a name. */
118 struct dsc$descriptor_s filename_dsc;
119 char filename[FILENAME_MAX+1];
120 /* This contains whatever is not in filename, if needed.
121 * Normally not defined. */
122 struct dsc$descriptor_s imagename_dsc;
123 char imagename[FILENAME_MAX+1];
124 } DSO_VMS_INTERNAL;
125
126
127DSO_METHOD *DSO_METHOD_vms(void)
128 {
129 return(&dso_meth_vms);
130 }
131
132static int vms_load(DSO *dso, const char *filename)
133 {
134 DSO_VMS_INTERNAL *p;
135 const char *sp1, *sp2; /* Search result */
136
137 /* A file specification may look like this:
138 *
139 * node::dev:[dir-spec]name.type;ver
140 *
141 * or (for compatibility with TOPS-20):
142 *
143 * node::dev:<dir-spec>name.type;ver
144 *
145 * and the dir-spec uses '.' as separator. Also, a dir-spec
146 * may consist of several parts, with mixed use of [] and <>:
147 *
148 * [dir1.]<dir2>
149 *
150 * We need to split the file specification into the name and
151 * the rest (both before and after the name itself).
152 */
153 /* Start with trying to find the end of a dir-spec, and save the
154 position of the byte after in sp1 */
155 sp1 = strrchr(filename, ']');
156 sp2 = strrchr(filename, '>');
157 if (sp1 == NULL) sp1 = sp2;
158 if (sp2 != NULL && sp2 > sp1) sp1 = sp2;
159 if (sp1 == NULL) sp1 = strrchr(filename, ':');
160 if (sp1 == NULL)
161 sp1 = filename;
162 else
163 sp1++; /* The byte after the found character */
164 /* Now, let's see if there's a type, and save the position in sp2 */
165 sp2 = strchr(sp1, '.');
166 /* If we found it, that's where we'll cut. Otherwise, look for a
167 version number and save the position in sp2 */
168 if (sp2 == NULL) sp2 = strchr(sp1, ';');
169 /* If there was still nothing to find, set sp2 to point at the end of
170 the string */
171 if (sp2 == NULL) sp2 = sp1 + strlen(sp1);
172
173 /* Check that we won't get buffer overflows */
174 if (sp2 - sp1 > FILENAME_MAX
175 || (sp1 - filename) + strlen(sp2) > FILENAME_MAX)
176 {
177 DSOerr(DSO_F_VMS_LOAD,DSO_R_FILENAME_TOO_BIG);
178 return(0);
179 }
180
181 p = (DSO_VMS_INTERNAL *)OPENSSL_malloc(sizeof(DSO_VMS_INTERNAL));
182 if(p == NULL)
183 {
184 DSOerr(DSO_F_VMS_LOAD,ERR_R_MALLOC_FAILURE);
185 return(0);
186 }
187
188 strncpy(p->filename, sp1, sp2-sp1);
189 p->filename[sp2-sp1] = '\0';
190
191 strncpy(p->imagename, filename, sp1-filename);
192 p->imagename[sp1-filename] = '\0';
193 strcat(p->imagename, sp2);
194
195 p->filename_dsc.dsc$w_length = strlen(p->filename);
196 p->filename_dsc.dsc$b_dtype = DSC$K_DTYPE_T;
197 p->filename_dsc.dsc$b_class = DSC$K_CLASS_S;
198 p->filename_dsc.dsc$a_pointer = p->filename;
199 p->imagename_dsc.dsc$w_length = strlen(p->imagename);
200 p->imagename_dsc.dsc$b_dtype = DSC$K_DTYPE_T;
201 p->imagename_dsc.dsc$b_class = DSC$K_CLASS_S;
202 p->imagename_dsc.dsc$a_pointer = p->imagename;
203
204 if(!sk_push(dso->meth_data, (char *)p))
205 {
206 DSOerr(DSO_F_VMS_LOAD,DSO_R_STACK_ERROR);
207 OPENSSL_free(p);
208 return(0);
209 }
210 return(1);
211 }
212
213/* Note that this doesn't actually unload the shared image, as there is no
214 * such thing in VMS. Next time it get loaded again, a new copy will
215 * actually be loaded.
216 */
217static int vms_unload(DSO *dso)
218 {
219 DSO_VMS_INTERNAL *p;
220 if(dso == NULL)
221 {
222 DSOerr(DSO_F_VMS_UNLOAD,ERR_R_PASSED_NULL_PARAMETER);
223 return(0);
224 }
225 if(sk_num(dso->meth_data) < 1)
226 return(1);
227 p = (DSO_VMS_INTERNAL *)sk_pop(dso->meth_data);
228 if(p == NULL)
229 {
230 DSOerr(DSO_F_VMS_UNLOAD,DSO_R_NULL_HANDLE);
231 return(0);
232 }
233 /* Cleanup */
234 OPENSSL_free(p);
235 return(1);
236 }
237
238/* We must do this in a separate function because of the way the exception
239 handler works (it makes this function return */
240static int do_find_symbol(DSO_VMS_INTERNAL *ptr,
241 struct dsc$descriptor_s *symname_dsc, void **sym,
242 unsigned long flags)
243 {
244 /* Make sure that signals are caught and returned instead of
245 aborting the program. The exception handler gets unestablished
246 automatically on return from this function. */
247 lib$establish(lib$sig_to_ret);
248
249 if(ptr->imagename_dsc.dsc$w_length)
250 return lib$find_image_symbol(&ptr->filename_dsc,
251 symname_dsc, sym,
252 &ptr->imagename_dsc, flags);
253 else
254 return lib$find_image_symbol(&ptr->filename_dsc,
255 symname_dsc, sym,
256 0, flags);
257 }
258
259void vms_bind_sym(DSO *dso, const char *symname, void **sym)
260 {
261 DSO_VMS_INTERNAL *ptr;
262 int status;
263 int flags = LIB$M_FIS_MIXEDCASE;
264 struct dsc$descriptor_s symname_dsc;
265 *sym = NULL;
266
267 symname_dsc.dsc$w_length = strlen(symname);
268 symname_dsc.dsc$b_dtype = DSC$K_DTYPE_T;
269 symname_dsc.dsc$b_class = DSC$K_CLASS_S;
270 symname_dsc.dsc$a_pointer = (char *)symname; /* The cast is needed */
271
272 if((dso == NULL) || (symname == NULL))
273 {
274 DSOerr(DSO_F_VMS_BIND_VAR,ERR_R_PASSED_NULL_PARAMETER);
275 return;
276 }
277 if(sk_num(dso->meth_data) < 1)
278 {
279 DSOerr(DSO_F_VMS_BIND_VAR,DSO_R_STACK_ERROR);
280 return;
281 }
282 ptr = (DSO_VMS_INTERNAL *)sk_value(dso->meth_data,
283 sk_num(dso->meth_data) - 1);
284 if(ptr == NULL)
285 {
286 DSOerr(DSO_F_VMS_BIND_VAR,DSO_R_NULL_HANDLE);
287 return;
288 }
289
290 if(dso->flags & DSO_FLAG_UPCASE_SYMBOL) flags = 0;
291
292 status = do_find_symbol(ptr, &symname_dsc, sym, flags);
293
294 if(!$VMS_STATUS_SUCCESS(status))
295 {
296 unsigned short length;
297 char errstring[257];
298 struct dsc$descriptor_s errstring_dsc;
299
300 errstring_dsc.dsc$w_length = sizeof(errstring);
301 errstring_dsc.dsc$b_dtype = DSC$K_DTYPE_T;
302 errstring_dsc.dsc$b_class = DSC$K_CLASS_S;
303 errstring_dsc.dsc$a_pointer = errstring;
304
305 *sym = NULL;
306
307 status = sys$getmsg(status, &length, &errstring_dsc, 1, 0);
308
309 if (!$VMS_STATUS_SUCCESS(status))
310 lib$signal(status); /* This is really bad. Abort! */
311 else
312 {
313 errstring[length] = '\0';
314
315 DSOerr(DSO_F_VMS_BIND_VAR,DSO_R_SYM_FAILURE);
316 if (ptr->imagename_dsc.dsc$w_length)
317 ERR_add_error_data(9,
318 "Symbol ", symname,
319 " in ", ptr->filename,
320 " (", ptr->imagename, ")",
321 ": ", errstring);
322 else
323 ERR_add_error_data(6,
324 "Symbol ", symname,
325 " in ", ptr->filename,
326 ": ", errstring);
327 }
328 return;
329 }
330 return;
331 }
332
333static void *vms_bind_var(DSO *dso, const char *symname)
334 {
335 void *sym = 0;
336 vms_bind_sym(dso, symname, &sym);
337 return sym;
338 }
339
340static DSO_FUNC_TYPE vms_bind_func(DSO *dso, const char *symname)
341 {
342 DSO_FUNC_TYPE sym = 0;
343 vms_bind_sym(dso, symname, (void **)&sym);
344 return sym;
345 }
346
347static long vms_ctrl(DSO *dso, int cmd, long larg, void *parg)
348 {
349 if(dso == NULL)
350 {
351 DSOerr(DSO_F_VMS_CTRL,ERR_R_PASSED_NULL_PARAMETER);
352 return(-1);
353 }
354 switch(cmd)
355 {
356 case DSO_CTRL_GET_FLAGS:
357 return dso->flags;
358 case DSO_CTRL_SET_FLAGS:
359 dso->flags = (int)larg;
360 return(0);
361 case DSO_CTRL_OR_FLAGS:
362 dso->flags |= (int)larg;
363 return(0);
364 default:
365 break;
366 }
367 DSOerr(DSO_F_VMS_CTRL,DSO_R_UNKNOWN_COMMAND);
368 return(-1);
369 }
370
371#endif /* VMS */
diff --git a/src/lib/libcrypto/dso/dso_win32.c b/src/lib/libcrypto/dso/dso_win32.c
new file mode 100644
index 0000000000..7f1d904806
--- /dev/null
+++ b/src/lib/libcrypto/dso/dso_win32.c
@@ -0,0 +1,273 @@
1/* dso_win32.c */
2/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 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 * licensing@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 <stdio.h>
60#include <string.h>
61#include "cryptlib.h"
62#include <openssl/dso.h>
63
64#ifndef WIN32
65DSO_METHOD *DSO_METHOD_win32(void)
66 {
67 return NULL;
68 }
69#else
70
71/* Part of the hack in "win32_load" ... */
72#define DSO_MAX_TRANSLATED_SIZE 256
73
74static int win32_load(DSO *dso, const char *filename);
75static int win32_unload(DSO *dso);
76static void *win32_bind_var(DSO *dso, const char *symname);
77static DSO_FUNC_TYPE win32_bind_func(DSO *dso, const char *symname);
78#if 0
79static int win32_unbind_var(DSO *dso, char *symname, void *symptr);
80static int win32_unbind_func(DSO *dso, char *symname, DSO_FUNC_TYPE symptr);
81static int win32_init(DSO *dso);
82static int win32_finish(DSO *dso);
83#endif
84static long win32_ctrl(DSO *dso, int cmd, long larg, void *parg);
85
86static DSO_METHOD dso_meth_win32 = {
87 "OpenSSL 'win32' shared library method",
88 win32_load,
89 win32_unload,
90 win32_bind_var,
91 win32_bind_func,
92/* For now, "unbind" doesn't exist */
93#if 0
94 NULL, /* unbind_var */
95 NULL, /* unbind_func */
96#endif
97 win32_ctrl,
98 NULL, /* init */
99 NULL /* finish */
100 };
101
102DSO_METHOD *DSO_METHOD_win32(void)
103 {
104 return(&dso_meth_win32);
105 }
106
107/* For this DSO_METHOD, our meth_data STACK will contain;
108 * (i) a pointer to the handle (HINSTANCE) returned from
109 * LoadLibrary(), and copied.
110 */
111
112static int win32_load(DSO *dso, const char *filename)
113 {
114 HINSTANCE h, *p;
115 char translated[DSO_MAX_TRANSLATED_SIZE];
116 int len;
117
118 /* NB: This is a hideous hack, but I'm not yet sure what
119 * to replace it with. This attempts to convert any filename,
120 * that looks like it has no path information, into a
121 * translated form, e. "blah" -> "blah.dll" ... I'm more
122 * comfortable putting hacks into win32 code though ;-) */
123 len = strlen(filename);
124 if((dso->flags & DSO_FLAG_NAME_TRANSLATION) &&
125 (len + 4 < DSO_MAX_TRANSLATED_SIZE) &&
126 (strstr(filename, "/") == NULL) &&
127 (strstr(filename, "\\") == NULL) &&
128 (strstr(filename, ":") == NULL))
129 {
130 sprintf(translated, "%s.dll", filename);
131 h = LoadLibrary(translated);
132 }
133 else
134 h = LoadLibrary(filename);
135 if(h == NULL)
136 {
137 DSOerr(DSO_F_WIN32_LOAD,DSO_R_LOAD_FAILED);
138 return(0);
139 }
140 p = (HINSTANCE *)OPENSSL_malloc(sizeof(HINSTANCE));
141 if(p == NULL)
142 {
143 DSOerr(DSO_F_WIN32_LOAD,ERR_R_MALLOC_FAILURE);
144 FreeLibrary(h);
145 return(0);
146 }
147 *p = h;
148 if(!sk_push(dso->meth_data, (char *)p))
149 {
150 DSOerr(DSO_F_WIN32_LOAD,DSO_R_STACK_ERROR);
151 FreeLibrary(h);
152 OPENSSL_free(p);
153 return(0);
154 }
155 return(1);
156 }
157
158static int win32_unload(DSO *dso)
159 {
160 HINSTANCE *p;
161 if(dso == NULL)
162 {
163 DSOerr(DSO_F_WIN32_UNLOAD,ERR_R_PASSED_NULL_PARAMETER);
164 return(0);
165 }
166 if(sk_num(dso->meth_data) < 1)
167 return(1);
168 p = (HINSTANCE *)sk_pop(dso->meth_data);
169 if(p == NULL)
170 {
171 DSOerr(DSO_F_WIN32_UNLOAD,DSO_R_NULL_HANDLE);
172 return(0);
173 }
174 if(!FreeLibrary(*p))
175 {
176 DSOerr(DSO_F_WIN32_UNLOAD,DSO_R_UNLOAD_FAILED);
177 /* We should push the value back onto the stack in
178 * case of a retry. */
179 sk_push(dso->meth_data, (char *)p);
180 return(0);
181 }
182 /* Cleanup */
183 OPENSSL_free(p);
184 return(1);
185 }
186
187/* Using GetProcAddress for variables? TODO: Check this out in
188 * the Win32 API docs, there's probably a variant for variables. */
189static void *win32_bind_var(DSO *dso, const char *symname)
190 {
191 HINSTANCE *ptr;
192 void *sym;
193
194 if((dso == NULL) || (symname == NULL))
195 {
196 DSOerr(DSO_F_WIN32_BIND_VAR,ERR_R_PASSED_NULL_PARAMETER);
197 return(NULL);
198 }
199 if(sk_num(dso->meth_data) < 1)
200 {
201 DSOerr(DSO_F_WIN32_BIND_VAR,DSO_R_STACK_ERROR);
202 return(NULL);
203 }
204 ptr = (HINSTANCE *)sk_value(dso->meth_data, sk_num(dso->meth_data) - 1);
205 if(ptr == NULL)
206 {
207 DSOerr(DSO_F_WIN32_BIND_VAR,DSO_R_NULL_HANDLE);
208 return(NULL);
209 }
210 sym = GetProcAddress(*ptr, symname);
211 if(sym == NULL)
212 {
213 DSOerr(DSO_F_WIN32_BIND_VAR,DSO_R_SYM_FAILURE);
214 return(NULL);
215 }
216 return(sym);
217 }
218
219static DSO_FUNC_TYPE win32_bind_func(DSO *dso, const char *symname)
220 {
221 HINSTANCE *ptr;
222 void *sym;
223
224 if((dso == NULL) || (symname == NULL))
225 {
226 DSOerr(DSO_F_WIN32_BIND_FUNC,ERR_R_PASSED_NULL_PARAMETER);
227 return(NULL);
228 }
229 if(sk_num(dso->meth_data) < 1)
230 {
231 DSOerr(DSO_F_WIN32_BIND_FUNC,DSO_R_STACK_ERROR);
232 return(NULL);
233 }
234 ptr = (HINSTANCE *)sk_value(dso->meth_data, sk_num(dso->meth_data) - 1);
235 if(ptr == NULL)
236 {
237 DSOerr(DSO_F_WIN32_BIND_FUNC,DSO_R_NULL_HANDLE);
238 return(NULL);
239 }
240 sym = GetProcAddress(*ptr, symname);
241 if(sym == NULL)
242 {
243 DSOerr(DSO_F_WIN32_BIND_FUNC,DSO_R_SYM_FAILURE);
244 return(NULL);
245 }
246 return((DSO_FUNC_TYPE)sym);
247 }
248
249static long win32_ctrl(DSO *dso, int cmd, long larg, void *parg)
250 {
251 if(dso == NULL)
252 {
253 DSOerr(DSO_F_WIN32_CTRL,ERR_R_PASSED_NULL_PARAMETER);
254 return(-1);
255 }
256 switch(cmd)
257 {
258 case DSO_CTRL_GET_FLAGS:
259 return dso->flags;
260 case DSO_CTRL_SET_FLAGS:
261 dso->flags = (int)larg;
262 return(0);
263 case DSO_CTRL_OR_FLAGS:
264 dso->flags |= (int)larg;
265 return(0);
266 default:
267 break;
268 }
269 DSOerr(DSO_F_WIN32_CTRL,DSO_R_UNKNOWN_COMMAND);
270 return(-1);
271 }
272
273#endif /* WIN32 */
diff --git a/src/lib/libcrypto/ebcdic.c b/src/lib/libcrypto/ebcdic.c
new file mode 100644
index 0000000000..31397b2add
--- /dev/null
+++ b/src/lib/libcrypto/ebcdic.c
@@ -0,0 +1,217 @@
1/* crypto/ebcdic.c */
2
3#ifdef CHARSET_EBCDIC
4#include "ebcdic.h"
5/* Initial Port for Apache-1.3 by <Martin.Kraemer@Mch.SNI.De>
6 * Adapted for OpenSSL-0.9.4 by <Martin.Kraemer@Mch.SNI.De>
7 */
8
9#ifdef _OSD_POSIX
10/*
11 "BS2000 OSD" is a POSIX subsystem on a main frame.
12 It is made by Siemens AG, Germany, for their BS2000 mainframe machines.
13 Within the POSIX subsystem, the same character set was chosen as in
14 "native BS2000", namely EBCDIC. (EDF04)
15
16 The name "ASCII" in these routines is misleading: actually, conversion
17 is not between EBCDIC and ASCII, but EBCDIC(EDF04) and ISO-8859.1;
18 that means that (western european) national characters are preserved.
19
20 This table is identical to the one used by rsh/rcp/ftp and other POSIX tools.
21*/
22
23/* Here's the bijective ebcdic-to-ascii table: */
24const unsigned char os_toascii[256] = {
25/*00*/ 0x00, 0x01, 0x02, 0x03, 0x85, 0x09, 0x86, 0x7f,
26 0x87, 0x8d, 0x8e, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, /*................*/
27/*10*/ 0x10, 0x11, 0x12, 0x13, 0x8f, 0x0a, 0x08, 0x97,
28 0x18, 0x19, 0x9c, 0x9d, 0x1c, 0x1d, 0x1e, 0x1f, /*................*/
29/*20*/ 0x80, 0x81, 0x82, 0x83, 0x84, 0x92, 0x17, 0x1b,
30 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x05, 0x06, 0x07, /*................*/
31/*30*/ 0x90, 0x91, 0x16, 0x93, 0x94, 0x95, 0x96, 0x04,
32 0x98, 0x99, 0x9a, 0x9b, 0x14, 0x15, 0x9e, 0x1a, /*................*/
33/*40*/ 0x20, 0xa0, 0xe2, 0xe4, 0xe0, 0xe1, 0xe3, 0xe5,
34 0xe7, 0xf1, 0x60, 0x2e, 0x3c, 0x28, 0x2b, 0x7c, /* .........`.<(+|*/
35/*50*/ 0x26, 0xe9, 0xea, 0xeb, 0xe8, 0xed, 0xee, 0xef,
36 0xec, 0xdf, 0x21, 0x24, 0x2a, 0x29, 0x3b, 0x9f, /*&.........!$*);.*/
37/*60*/ 0x2d, 0x2f, 0xc2, 0xc4, 0xc0, 0xc1, 0xc3, 0xc5,
38 0xc7, 0xd1, 0x5e, 0x2c, 0x25, 0x5f, 0x3e, 0x3f, /*-/........^,%_>?*/
39/*70*/ 0xf8, 0xc9, 0xca, 0xcb, 0xc8, 0xcd, 0xce, 0xcf,
40 0xcc, 0xa8, 0x3a, 0x23, 0x40, 0x27, 0x3d, 0x22, /*..........:#@'="*/
41/*80*/ 0xd8, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
42 0x68, 0x69, 0xab, 0xbb, 0xf0, 0xfd, 0xfe, 0xb1, /*.abcdefghi......*/
43/*90*/ 0xb0, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70,
44 0x71, 0x72, 0xaa, 0xba, 0xe6, 0xb8, 0xc6, 0xa4, /*.jklmnopqr......*/
45/*a0*/ 0xb5, 0xaf, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,
46 0x79, 0x7a, 0xa1, 0xbf, 0xd0, 0xdd, 0xde, 0xae, /*..stuvwxyz......*/
47/*b0*/ 0xa2, 0xa3, 0xa5, 0xb7, 0xa9, 0xa7, 0xb6, 0xbc,
48 0xbd, 0xbe, 0xac, 0x5b, 0x5c, 0x5d, 0xb4, 0xd7, /*...........[\]..*/
49/*c0*/ 0xf9, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
50 0x48, 0x49, 0xad, 0xf4, 0xf6, 0xf2, 0xf3, 0xf5, /*.ABCDEFGHI......*/
51/*d0*/ 0xa6, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50,
52 0x51, 0x52, 0xb9, 0xfb, 0xfc, 0xdb, 0xfa, 0xff, /*.JKLMNOPQR......*/
53/*e0*/ 0xd9, 0xf7, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
54 0x59, 0x5a, 0xb2, 0xd4, 0xd6, 0xd2, 0xd3, 0xd5, /*..STUVWXYZ......*/
55/*f0*/ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
56 0x38, 0x39, 0xb3, 0x7b, 0xdc, 0x7d, 0xda, 0x7e /*0123456789.{.}.~*/
57};
58
59
60/* The ascii-to-ebcdic table: */
61const unsigned char os_toebcdic[256] = {
62/*00*/ 0x00, 0x01, 0x02, 0x03, 0x37, 0x2d, 0x2e, 0x2f,
63 0x16, 0x05, 0x15, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, /*................*/
64/*10*/ 0x10, 0x11, 0x12, 0x13, 0x3c, 0x3d, 0x32, 0x26,
65 0x18, 0x19, 0x3f, 0x27, 0x1c, 0x1d, 0x1e, 0x1f, /*................*/
66/*20*/ 0x40, 0x5a, 0x7f, 0x7b, 0x5b, 0x6c, 0x50, 0x7d,
67 0x4d, 0x5d, 0x5c, 0x4e, 0x6b, 0x60, 0x4b, 0x61, /* !"#$%&'()*+,-./ */
68/*30*/ 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
69 0xf8, 0xf9, 0x7a, 0x5e, 0x4c, 0x7e, 0x6e, 0x6f, /*0123456789:;<=>?*/
70/*40*/ 0x7c, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
71 0xc8, 0xc9, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, /*@ABCDEFGHIJKLMNO*/
72/*50*/ 0xd7, 0xd8, 0xd9, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6,
73 0xe7, 0xe8, 0xe9, 0xbb, 0xbc, 0xbd, 0x6a, 0x6d, /*PQRSTUVWXYZ[\]^_*/
74/*60*/ 0x4a, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
75 0x88, 0x89, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, /*`abcdefghijklmno*/
76/*70*/ 0x97, 0x98, 0x99, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6,
77 0xa7, 0xa8, 0xa9, 0xfb, 0x4f, 0xfd, 0xff, 0x07, /*pqrstuvwxyz{|}~.*/
78/*80*/ 0x20, 0x21, 0x22, 0x23, 0x24, 0x04, 0x06, 0x08,
79 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x09, 0x0a, 0x14, /*................*/
80/*90*/ 0x30, 0x31, 0x25, 0x33, 0x34, 0x35, 0x36, 0x17,
81 0x38, 0x39, 0x3a, 0x3b, 0x1a, 0x1b, 0x3e, 0x5f, /*................*/
82/*a0*/ 0x41, 0xaa, 0xb0, 0xb1, 0x9f, 0xb2, 0xd0, 0xb5,
83 0x79, 0xb4, 0x9a, 0x8a, 0xba, 0xca, 0xaf, 0xa1, /*................*/
84/*b0*/ 0x90, 0x8f, 0xea, 0xfa, 0xbe, 0xa0, 0xb6, 0xb3,
85 0x9d, 0xda, 0x9b, 0x8b, 0xb7, 0xb8, 0xb9, 0xab, /*................*/
86/*c0*/ 0x64, 0x65, 0x62, 0x66, 0x63, 0x67, 0x9e, 0x68,
87 0x74, 0x71, 0x72, 0x73, 0x78, 0x75, 0x76, 0x77, /*................*/
88/*d0*/ 0xac, 0x69, 0xed, 0xee, 0xeb, 0xef, 0xec, 0xbf,
89 0x80, 0xe0, 0xfe, 0xdd, 0xfc, 0xad, 0xae, 0x59, /*................*/
90/*e0*/ 0x44, 0x45, 0x42, 0x46, 0x43, 0x47, 0x9c, 0x48,
91 0x54, 0x51, 0x52, 0x53, 0x58, 0x55, 0x56, 0x57, /*................*/
92/*f0*/ 0x8c, 0x49, 0xcd, 0xce, 0xcb, 0xcf, 0xcc, 0xe1,
93 0x70, 0xc0, 0xde, 0xdb, 0xdc, 0x8d, 0x8e, 0xdf /*................*/
94};
95
96#else /*_OSD_POSIX*/
97
98/*
99This code does basic character mapping for IBM's TPF and OS/390 operating systems.
100It is a modified version of the BS2000 table.
101
102Bijective EBCDIC (character set IBM-1047) to US-ASCII table:
103This table is bijective - there are no ambigous or duplicate characters.
104*/
105const unsigned char os_toascii[256] = {
106 0x00, 0x01, 0x02, 0x03, 0x85, 0x09, 0x86, 0x7f, /* 00-0f: */
107 0x87, 0x8d, 0x8e, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, /* ................ */
108 0x10, 0x11, 0x12, 0x13, 0x8f, 0x0a, 0x08, 0x97, /* 10-1f: */
109 0x18, 0x19, 0x9c, 0x9d, 0x1c, 0x1d, 0x1e, 0x1f, /* ................ */
110 0x80, 0x81, 0x82, 0x83, 0x84, 0x92, 0x17, 0x1b, /* 20-2f: */
111 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x05, 0x06, 0x07, /* ................ */
112 0x90, 0x91, 0x16, 0x93, 0x94, 0x95, 0x96, 0x04, /* 30-3f: */
113 0x98, 0x99, 0x9a, 0x9b, 0x14, 0x15, 0x9e, 0x1a, /* ................ */
114 0x20, 0xa0, 0xe2, 0xe4, 0xe0, 0xe1, 0xe3, 0xe5, /* 40-4f: */
115 0xe7, 0xf1, 0xa2, 0x2e, 0x3c, 0x28, 0x2b, 0x7c, /* ...........<(+| */
116 0x26, 0xe9, 0xea, 0xeb, 0xe8, 0xed, 0xee, 0xef, /* 50-5f: */
117 0xec, 0xdf, 0x21, 0x24, 0x2a, 0x29, 0x3b, 0x5e, /* &.........!$*);^ */
118 0x2d, 0x2f, 0xc2, 0xc4, 0xc0, 0xc1, 0xc3, 0xc5, /* 60-6f: */
119 0xc7, 0xd1, 0xa6, 0x2c, 0x25, 0x5f, 0x3e, 0x3f, /* -/.........,%_>? */
120 0xf8, 0xc9, 0xca, 0xcb, 0xc8, 0xcd, 0xce, 0xcf, /* 70-7f: */
121 0xcc, 0x60, 0x3a, 0x23, 0x40, 0x27, 0x3d, 0x22, /* .........`:#@'=" */
122 0xd8, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, /* 80-8f: */
123 0x68, 0x69, 0xab, 0xbb, 0xf0, 0xfd, 0xfe, 0xb1, /* .abcdefghi...... */
124 0xb0, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, /* 90-9f: */
125 0x71, 0x72, 0xaa, 0xba, 0xe6, 0xb8, 0xc6, 0xa4, /* .jklmnopqr...... */
126 0xb5, 0x7e, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, /* a0-af: */
127 0x79, 0x7a, 0xa1, 0xbf, 0xd0, 0x5b, 0xde, 0xae, /* .~stuvwxyz...[.. */
128 0xac, 0xa3, 0xa5, 0xb7, 0xa9, 0xa7, 0xb6, 0xbc, /* b0-bf: */
129 0xbd, 0xbe, 0xdd, 0xa8, 0xaf, 0x5d, 0xb4, 0xd7, /* .............].. */
130 0x7b, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, /* c0-cf: */
131 0x48, 0x49, 0xad, 0xf4, 0xf6, 0xf2, 0xf3, 0xf5, /* {ABCDEFGHI...... */
132 0x7d, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, /* d0-df: */
133 0x51, 0x52, 0xb9, 0xfb, 0xfc, 0xf9, 0xfa, 0xff, /* }JKLMNOPQR...... */
134 0x5c, 0xf7, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, /* e0-ef: */
135 0x59, 0x5a, 0xb2, 0xd4, 0xd6, 0xd2, 0xd3, 0xd5, /* \.STUVWXYZ...... */
136 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, /* f0-ff: */
137 0x38, 0x39, 0xb3, 0xdb, 0xdc, 0xd9, 0xda, 0x9f /* 0123456789...... */
138};
139
140
141/*
142The US-ASCII to EBCDIC (character set IBM-1047) table:
143This table is bijective (no ambiguous or duplicate characters)
144*/
145const unsigned char os_toebcdic[256] = {
146 0x00, 0x01, 0x02, 0x03, 0x37, 0x2d, 0x2e, 0x2f, /* 00-0f: */
147 0x16, 0x05, 0x15, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, /* ................ */
148 0x10, 0x11, 0x12, 0x13, 0x3c, 0x3d, 0x32, 0x26, /* 10-1f: */
149 0x18, 0x19, 0x3f, 0x27, 0x1c, 0x1d, 0x1e, 0x1f, /* ................ */
150 0x40, 0x5a, 0x7f, 0x7b, 0x5b, 0x6c, 0x50, 0x7d, /* 20-2f: */
151 0x4d, 0x5d, 0x5c, 0x4e, 0x6b, 0x60, 0x4b, 0x61, /* !"#$%&'()*+,-./ */
152 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, /* 30-3f: */
153 0xf8, 0xf9, 0x7a, 0x5e, 0x4c, 0x7e, 0x6e, 0x6f, /* 0123456789:;<=>? */
154 0x7c, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, /* 40-4f: */
155 0xc8, 0xc9, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, /* @ABCDEFGHIJKLMNO */
156 0xd7, 0xd8, 0xd9, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, /* 50-5f: */
157 0xe7, 0xe8, 0xe9, 0xad, 0xe0, 0xbd, 0x5f, 0x6d, /* PQRSTUVWXYZ[\]^_ */
158 0x79, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, /* 60-6f: */
159 0x88, 0x89, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, /* `abcdefghijklmno */
160 0x97, 0x98, 0x99, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, /* 70-7f: */
161 0xa7, 0xa8, 0xa9, 0xc0, 0x4f, 0xd0, 0xa1, 0x07, /* pqrstuvwxyz{|}~. */
162 0x20, 0x21, 0x22, 0x23, 0x24, 0x04, 0x06, 0x08, /* 80-8f: */
163 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x09, 0x0a, 0x14, /* ................ */
164 0x30, 0x31, 0x25, 0x33, 0x34, 0x35, 0x36, 0x17, /* 90-9f: */
165 0x38, 0x39, 0x3a, 0x3b, 0x1a, 0x1b, 0x3e, 0xff, /* ................ */
166 0x41, 0xaa, 0x4a, 0xb1, 0x9f, 0xb2, 0x6a, 0xb5, /* a0-af: */
167 0xbb, 0xb4, 0x9a, 0x8a, 0xb0, 0xca, 0xaf, 0xbc, /* ................ */
168 0x90, 0x8f, 0xea, 0xfa, 0xbe, 0xa0, 0xb6, 0xb3, /* b0-bf: */
169 0x9d, 0xda, 0x9b, 0x8b, 0xb7, 0xb8, 0xb9, 0xab, /* ................ */
170 0x64, 0x65, 0x62, 0x66, 0x63, 0x67, 0x9e, 0x68, /* c0-cf: */
171 0x74, 0x71, 0x72, 0x73, 0x78, 0x75, 0x76, 0x77, /* ................ */
172 0xac, 0x69, 0xed, 0xee, 0xeb, 0xef, 0xec, 0xbf, /* d0-df: */
173 0x80, 0xfd, 0xfe, 0xfb, 0xfc, 0xba, 0xae, 0x59, /* ................ */
174 0x44, 0x45, 0x42, 0x46, 0x43, 0x47, 0x9c, 0x48, /* e0-ef: */
175 0x54, 0x51, 0x52, 0x53, 0x58, 0x55, 0x56, 0x57, /* ................ */
176 0x8c, 0x49, 0xcd, 0xce, 0xcb, 0xcf, 0xcc, 0xe1, /* f0-ff: */
177 0x70, 0xdd, 0xde, 0xdb, 0xdc, 0x8d, 0x8e, 0xdf /* ................ */
178};
179#endif /*_OSD_POSIX*/
180
181/* Translate a memory block from EBCDIC (host charset) to ASCII (net charset)
182 * dest and srce may be identical, or separate memory blocks, but
183 * should not overlap. These functions intentionally have an interface
184 * compatible to memcpy(3).
185 */
186
187void *
188ebcdic2ascii(void *dest, const void *srce, size_t count)
189{
190 unsigned char *udest = dest;
191 const unsigned char *usrce = srce;
192
193 while (count-- != 0) {
194 *udest++ = os_toascii[*usrce++];
195 }
196
197 return dest;
198}
199
200void *
201ascii2ebcdic(void *dest, const void *srce, size_t count)
202{
203 unsigned char *udest = dest;
204 const unsigned char *usrce = srce;
205
206 while (count-- != 0) {
207 *udest++ = os_toebcdic[*usrce++];
208 }
209
210 return dest;
211}
212
213#else /*CHARSET_EBCDIC*/
214#ifdef PEDANTIC
215static void *dummy=&dummy;
216#endif
217#endif
diff --git a/src/lib/libcrypto/ebcdic.h b/src/lib/libcrypto/ebcdic.h
new file mode 100644
index 0000000000..d3b4e98b12
--- /dev/null
+++ b/src/lib/libcrypto/ebcdic.h
@@ -0,0 +1,17 @@
1#ifndef HEADER_EBCDIC_H
2#define HEADER_EBCDIC_H
3
4#include <sys/types.h>
5
6/* Avoid name clashes with other applications */
7#define os_toascii _eay2000_os_toascii
8#define os_toebcdic _eay2000_os_toebcdic
9#define ebcdic2ascii _eay2000_ebcdic2ascii
10#define ascii2ebcdic _eay2000_ascii2ebcdic
11
12extern const unsigned char os_toascii[256];
13extern const unsigned char os_toebcdic[256];
14void ebcdic2ascii(unsigned char *dest, const unsigned char *srce, size_t count);
15void ascii2ebcdic(unsigned char *dest, const unsigned char *srce, size_t count);
16
17#endif
diff --git a/src/lib/libcrypto/ec/ecp_recp.c b/src/lib/libcrypto/ec/ecp_recp.c
new file mode 100644
index 0000000000..fec843b5c8
--- /dev/null
+++ b/src/lib/libcrypto/ec/ecp_recp.c
@@ -0,0 +1,133 @@
1/* crypto/ec/ecp_recp.c */
2/* ====================================================================
3 * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56#include "ec_lcl.h"
57
58#if 0
59const EC_METHOD *EC_GFp_recp_method(void)
60 {
61 static const EC_METHOD ret = {
62 ec_GFp_recp_group_init,
63 ec_GFp_recp_group_finish,
64 ec_GFp_recp_group_clear_finish,
65 ec_GFp_recp_group_copy,
66 ec_GFp_recp_group_set_curve_GFp,
67 ec_GFp_simple_group_get_curve_GFp,
68 ec_GFp_simple_group_set_generator,
69 ec_GFp_simple_group_get0_generator,
70 ec_GFp_simple_group_get_order,
71 ec_GFp_simple_group_get_cofactor,
72 ec_GFp_simple_point_init,
73 ec_GFp_simple_point_finish,
74 ec_GFp_simple_point_clear_finish,
75 ec_GFp_simple_point_copy,
76 ec_GFp_simple_point_set_to_infinity,
77 ec_GFp_simple_set_Jprojective_coordinates_GFp,
78 ec_GFp_simple_get_Jprojective_coordinates_GFp,
79 ec_GFp_simple_point_set_affine_coordinates_GFp,
80 ec_GFp_simple_point_get_affine_coordinates_GFp,
81 ec_GFp_simple_set_compressed_coordinates_GFp,
82 ec_GFp_simple_point2oct,
83 ec_GFp_simple_oct2point,
84 ec_GFp_simple_add,
85 ec_GFp_simple_dbl,
86 ec_GFp_simple_invert,
87 ec_GFp_simple_is_at_infinity,
88 ec_GFp_simple_is_on_curve,
89 ec_GFp_simple_cmp,
90 ec_GFp_simple_make_affine,
91 ec_GFp_simple_points_make_affine,
92 ec_GFp_recp_field_mul,
93 ec_GFp_recp_field_sqr,
94 0 /* field_encode */,
95 0 /* field_decode */,
96 0 /* field_set_to_one */ };
97
98 return &ret;
99 }
100#endif
101
102int ec_GFp_recp_group_init(EC_GROUP *group)
103 {
104 int ok;
105
106 ok = ec_GFp_simple_group_init(group);
107 group->field_data1 = NULL;
108 return ok;
109 }
110
111
112int ec_GFp_recp_group_set_curve_GFp(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx);
113/* TODO */
114
115
116void ec_GFp_recp_group_finish(EC_GROUP *group);
117/* TODO */
118
119
120void ec_GFp_recp_group_clear_finish(EC_GROUP *group);
121/* TODO */
122
123
124int ec_GFp_recp_group_copy(EC_GROUP *dest, const EC_GROUP *src);
125/* TODO */
126
127
128int ec_GFp_recp_field_mul(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx);
129/* TODO */
130
131
132int ec_GFp_recp_field_sqr(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, BN_CTX *ctx);
133/* TODO */
diff --git a/src/lib/libcrypto/ec/ectest.c b/src/lib/libcrypto/ec/ectest.c
new file mode 100644
index 0000000000..243cd83fb5
--- /dev/null
+++ b/src/lib/libcrypto/ec/ectest.c
@@ -0,0 +1,634 @@
1/* crypto/ec/ectest.c */
2/* ====================================================================
3 * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56#include <stdio.h>
57#include <stdlib.h>
58#include <string.h>
59#include <time.h>
60
61
62#ifdef OPENSSL_NO_EC
63int main(int argc, char * argv[]) { puts("Elliptic curves are disabled."); return 0; }
64#else
65
66
67#include <openssl/ec.h>
68#include <openssl/engine.h>
69#include <openssl/err.h>
70
71#define ABORT do { \
72 fflush(stdout); \
73 fprintf(stderr, "%s:%d: ABORT\n", __FILE__, __LINE__); \
74 ERR_print_errors_fp(stderr); \
75 exit(1); \
76} while (0)
77
78
79void timings(EC_GROUP *group, int multi, BN_CTX *ctx)
80 {
81 clock_t clck;
82 int i, j;
83 BIGNUM *s, *s0;
84 EC_POINT *P;
85
86 s = BN_new();
87 s0 = BN_new();
88 if (s == NULL || s0 == NULL) ABORT;
89
90 if (!EC_GROUP_get_curve_GFp(group, s, NULL, NULL, ctx)) ABORT;
91 fprintf(stdout, "Timings for %d bit prime, ", (int)BN_num_bits(s));
92 if (!EC_GROUP_get_order(group, s, ctx)) ABORT;
93 fprintf(stdout, "%d bit scalars ", (int)BN_num_bits(s));
94 fflush(stdout);
95
96 P = EC_POINT_new(group);
97 if (P == NULL) ABORT;
98 EC_POINT_copy(P, EC_GROUP_get0_generator(group));
99
100 clck = clock();
101 for (i = 0; i < 10; i++)
102 {
103 if (!BN_pseudo_rand(s, BN_num_bits(s), 0, 0)) ABORT;
104 if (multi)
105 {
106 if (!BN_pseudo_rand(s0, BN_num_bits(s), 0, 0)) ABORT;
107 }
108 for (j = 0; j < 10; j++)
109 {
110 if (!EC_POINT_mul(group, P, s, multi ? P : NULL, multi ? s0 : NULL, ctx)) ABORT;
111 }
112 fprintf(stdout, ".");
113 fflush(stdout);
114 }
115 fprintf(stdout, "\n");
116
117 clck = clock() - clck;
118
119#ifdef CLOCKS_PER_SEC
120 /* "To determine the time in seconds, the value returned
121 * by the clock function should be divided by the value
122 * of the macro CLOCKS_PER_SEC."
123 * -- ISO/IEC 9899 */
124# define UNIT "s"
125#else
126 /* "`CLOCKS_PER_SEC' undeclared (first use this function)"
127 * -- cc on NeXTstep/OpenStep */
128# define UNIT "units"
129# define CLOCKS_PER_SEC 1
130#endif
131
132 fprintf(stdout, "%i %s in %.2f " UNIT "\n", i*j,
133 multi ? "s*P+t*Q operations" : "point multiplications",
134 (double)clck/CLOCKS_PER_SEC);
135 fprintf(stdout, "average: %.4f " UNIT "\n", (double)clck/(CLOCKS_PER_SEC*i*j));
136
137 EC_POINT_free(P);
138 BN_free(s);
139 BN_free(s0);
140 }
141
142
143int main(int argc, char *argv[])
144 {
145 BN_CTX *ctx = NULL;
146 BIGNUM *p, *a, *b;
147 EC_GROUP *group;
148 EC_GROUP *P_192 = NULL, *P_224 = NULL, *P_256 = NULL, *P_384 = NULL, *P_521 = NULL;
149 EC_POINT *P, *Q, *R;
150 BIGNUM *x, *y, *z;
151 unsigned char buf[100];
152 size_t i, len;
153 int k;
154
155 /* enable memory leak checking unless explicitly disabled */
156 if (!((getenv("OPENSSL_DEBUG_MEMORY") != NULL) && (0 == strcmp(getenv("OPENSSL_DEBUG_MEMORY"), "off"))))
157 {
158 CRYPTO_malloc_debug_init();
159 CRYPTO_set_mem_debug_options(V_CRYPTO_MDEBUG_ALL);
160 }
161 else
162 {
163 /* OPENSSL_DEBUG_MEMORY=off */
164 CRYPTO_set_mem_debug_functions(0, 0, 0, 0, 0);
165 }
166 CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
167 ERR_load_crypto_strings();
168
169#if 1 /* optional */
170 ctx = BN_CTX_new();
171 if (!ctx) ABORT;
172#endif
173
174 p = BN_new();
175 a = BN_new();
176 b = BN_new();
177 if (!p || !a || !b) ABORT;
178
179 if (!BN_hex2bn(&p, "17")) ABORT;
180 if (!BN_hex2bn(&a, "1")) ABORT;
181 if (!BN_hex2bn(&b, "1")) ABORT;
182
183 group = EC_GROUP_new(EC_GFp_mont_method()); /* applications should use EC_GROUP_new_curve_GFp
184 * so that the library gets to choose the EC_METHOD */
185 if (!group) ABORT;
186
187 if (!EC_GROUP_set_curve_GFp(group, p, a, b, ctx)) ABORT;
188
189 {
190 EC_GROUP *tmp;
191 tmp = EC_GROUP_new(EC_GROUP_method_of(group));
192 if (!tmp) ABORT;
193 if (!EC_GROUP_copy(tmp, group));
194 EC_GROUP_free(group);
195 group = tmp;
196 }
197
198 if (!EC_GROUP_get_curve_GFp(group, p, a, b, ctx)) ABORT;
199
200 fprintf(stdout, "Curve defined by Weierstrass equation\n y^2 = x^3 + a*x + b (mod 0x");
201 BN_print_fp(stdout, p);
202 fprintf(stdout, ")\n a = 0x");
203 BN_print_fp(stdout, a);
204 fprintf(stdout, "\n b = 0x");
205 BN_print_fp(stdout, b);
206 fprintf(stdout, "\n");
207
208 P = EC_POINT_new(group);
209 Q = EC_POINT_new(group);
210 R = EC_POINT_new(group);
211 if (!P || !Q || !R) ABORT;
212
213 if (!EC_POINT_set_to_infinity(group, P)) ABORT;
214 if (!EC_POINT_is_at_infinity(group, P)) ABORT;
215
216 buf[0] = 0;
217 if (!EC_POINT_oct2point(group, Q, buf, 1, ctx)) ABORT;
218
219 if (!EC_POINT_add(group, P, P, Q, ctx)) ABORT;
220 if (!EC_POINT_is_at_infinity(group, P)) ABORT;
221
222 x = BN_new();
223 y = BN_new();
224 z = BN_new();
225 if (!x || !y || !z) ABORT;
226
227 if (!BN_hex2bn(&x, "D")) ABORT;
228 if (!EC_POINT_set_compressed_coordinates_GFp(group, Q, x, 1, ctx)) ABORT;
229 if (!EC_POINT_is_on_curve(group, Q, ctx))
230 {
231 if (!EC_POINT_get_affine_coordinates_GFp(group, Q, x, y, ctx)) ABORT;
232 fprintf(stderr, "Point is not on curve: x = 0x");
233 BN_print_fp(stderr, x);
234 fprintf(stderr, ", y = 0x");
235 BN_print_fp(stderr, y);
236 fprintf(stderr, "\n");
237 ABORT;
238 }
239
240 fprintf(stdout, "A cyclic subgroup:\n");
241 k = 100;
242 do
243 {
244 if (k-- == 0) ABORT;
245
246 if (EC_POINT_is_at_infinity(group, P))
247 fprintf(stdout, " point at infinity\n");
248 else
249 {
250 if (!EC_POINT_get_affine_coordinates_GFp(group, P, x, y, ctx)) ABORT;
251
252 fprintf(stdout, " x = 0x");
253 BN_print_fp(stdout, x);
254 fprintf(stdout, ", y = 0x");
255 BN_print_fp(stdout, y);
256 fprintf(stdout, "\n");
257 }
258
259 if (!EC_POINT_copy(R, P)) ABORT;
260 if (!EC_POINT_add(group, P, P, Q, ctx)) ABORT;
261
262#if 0 /* optional */
263 {
264 EC_POINT *points[3];
265
266 points[0] = R;
267 points[1] = Q;
268 points[2] = P;
269 if (!EC_POINTs_make_affine(group, 2, points, ctx)) ABORT;
270 }
271#endif
272
273 }
274 while (!EC_POINT_is_at_infinity(group, P));
275
276 if (!EC_POINT_add(group, P, Q, R, ctx)) ABORT;
277 if (!EC_POINT_is_at_infinity(group, P)) ABORT;
278
279 len = EC_POINT_point2oct(group, Q, POINT_CONVERSION_COMPRESSED, buf, sizeof buf, ctx);
280 if (len == 0) ABORT;
281 if (!EC_POINT_oct2point(group, P, buf, len, ctx)) ABORT;
282 if (0 != EC_POINT_cmp(group, P, Q, ctx)) ABORT;
283 fprintf(stdout, "Generator as octect string, compressed form:\n ");
284 for (i = 0; i < len; i++) fprintf(stdout, "%02X", buf[i]);
285
286 len = EC_POINT_point2oct(group, Q, POINT_CONVERSION_UNCOMPRESSED, buf, sizeof buf, ctx);
287 if (len == 0) ABORT;
288 if (!EC_POINT_oct2point(group, P, buf, len, ctx)) ABORT;
289 if (0 != EC_POINT_cmp(group, P, Q, ctx)) ABORT;
290 fprintf(stdout, "\nGenerator as octect string, uncompressed form:\n ");
291 for (i = 0; i < len; i++) fprintf(stdout, "%02X", buf[i]);
292
293 len = EC_POINT_point2oct(group, Q, POINT_CONVERSION_HYBRID, buf, sizeof buf, ctx);
294 if (len == 0) ABORT;
295 if (!EC_POINT_oct2point(group, P, buf, len, ctx)) ABORT;
296 if (0 != EC_POINT_cmp(group, P, Q, ctx)) ABORT;
297 fprintf(stdout, "\nGenerator as octect string, hybrid form:\n ");
298 for (i = 0; i < len; i++) fprintf(stdout, "%02X", buf[i]);
299
300 if (!EC_POINT_get_Jprojective_coordinates_GFp(group, R, x, y, z, ctx)) ABORT;
301 fprintf(stdout, "\nA representation of the inverse of that generator in\nJacobian projective coordinates:\n X = 0x");
302 BN_print_fp(stdout, x);
303 fprintf(stdout, ", Y = 0x");
304 BN_print_fp(stdout, y);
305 fprintf(stdout, ", Z = 0x");
306 BN_print_fp(stdout, z);
307 fprintf(stdout, "\n");
308
309 if (!EC_POINT_invert(group, P, ctx)) ABORT;
310 if (0 != EC_POINT_cmp(group, P, R, ctx)) ABORT;
311
312
313 /* Curve P-192 (FIPS PUB 186-2, App. 6) */
314
315 if (!BN_hex2bn(&p, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFF")) ABORT;
316 if (1 != BN_is_prime(p, BN_prime_checks, 0, ctx, NULL)) ABORT;
317 if (!BN_hex2bn(&a, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFC")) ABORT;
318 if (!BN_hex2bn(&b, "64210519E59C80E70FA7E9AB72243049FEB8DEECC146B9B1")) ABORT;
319 if (!EC_GROUP_set_curve_GFp(group, p, a, b, ctx)) ABORT;
320
321 if (!BN_hex2bn(&x, "188DA80EB03090F67CBF20EB43A18800F4FF0AFD82FF1012")) ABORT;
322 if (!EC_POINT_set_compressed_coordinates_GFp(group, P, x, 1, ctx)) ABORT;
323 if (!EC_POINT_is_on_curve(group, P, ctx)) ABORT;
324 if (!BN_hex2bn(&z, "FFFFFFFFFFFFFFFFFFFFFFFF99DEF836146BC9B1B4D22831")) ABORT;
325 if (!EC_GROUP_set_generator(group, P, z, BN_value_one())) ABORT;
326
327 if (!EC_POINT_get_affine_coordinates_GFp(group, P, x, y, ctx)) ABORT;
328 fprintf(stdout, "\nNIST curve P-192 -- Generator:\n x = 0x");
329 BN_print_fp(stdout, x);
330 fprintf(stdout, "\n y = 0x");
331 BN_print_fp(stdout, y);
332 fprintf(stdout, "\n");
333 /* G_y value taken from the standard: */
334 if (!BN_hex2bn(&z, "07192B95FFC8DA78631011ED6B24CDD573F977A11E794811")) ABORT;
335 if (0 != BN_cmp(y, z)) ABORT;
336
337 fprintf(stdout, "verify group order ...");
338 fflush(stdout);
339 if (!EC_GROUP_get_order(group, z, ctx)) ABORT;
340 if (!EC_POINT_mul(group, Q, z, NULL, NULL, ctx)) ABORT;
341 if (!EC_POINT_is_at_infinity(group, Q)) ABORT;
342 fprintf(stdout, ".");
343 fflush(stdout);
344 if (!EC_GROUP_precompute_mult(group, ctx)) ABORT;
345 if (!EC_POINT_mul(group, Q, z, NULL, NULL, ctx)) ABORT;
346 if (!EC_POINT_is_at_infinity(group, Q)) ABORT;
347 fprintf(stdout, " ok\n");
348
349 if (!(P_192 = EC_GROUP_new(EC_GROUP_method_of(group)))) ABORT;
350 if (!EC_GROUP_copy(P_192, group)) ABORT;
351
352
353 /* Curve P-224 (FIPS PUB 186-2, App. 6) */
354
355 if (!BN_hex2bn(&p, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000000000000000000001")) ABORT;
356 if (1 != BN_is_prime(p, BN_prime_checks, 0, ctx, NULL)) ABORT;
357 if (!BN_hex2bn(&a, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFE")) ABORT;
358 if (!BN_hex2bn(&b, "B4050A850C04B3ABF54132565044B0B7D7BFD8BA270B39432355FFB4")) ABORT;
359 if (!EC_GROUP_set_curve_GFp(group, p, a, b, ctx)) ABORT;
360
361 if (!BN_hex2bn(&x, "B70E0CBD6BB4BF7F321390B94A03C1D356C21122343280D6115C1D21")) ABORT;
362 if (!EC_POINT_set_compressed_coordinates_GFp(group, P, x, 0, ctx)) ABORT;
363 if (!EC_POINT_is_on_curve(group, P, ctx)) ABORT;
364 if (!BN_hex2bn(&z, "FFFFFFFFFFFFFFFFFFFFFFFFFFFF16A2E0B8F03E13DD29455C5C2A3D")) ABORT;
365 if (!EC_GROUP_set_generator(group, P, z, BN_value_one())) ABORT;
366
367 if (!EC_POINT_get_affine_coordinates_GFp(group, P, x, y, ctx)) ABORT;
368 fprintf(stdout, "\nNIST curve P-224 -- Generator:\n x = 0x");
369 BN_print_fp(stdout, x);
370 fprintf(stdout, "\n y = 0x");
371 BN_print_fp(stdout, y);
372 fprintf(stdout, "\n");
373 /* G_y value taken from the standard: */
374 if (!BN_hex2bn(&z, "BD376388B5F723FB4C22DFE6CD4375A05A07476444D5819985007E34")) ABORT;
375 if (0 != BN_cmp(y, z)) ABORT;
376
377 fprintf(stdout, "verify group order ...");
378 fflush(stdout);
379 if (!EC_GROUP_get_order(group, z, ctx)) ABORT;
380 if (!EC_POINT_mul(group, Q, z, NULL, NULL, ctx)) ABORT;
381 if (!EC_POINT_is_at_infinity(group, Q)) ABORT;
382 fprintf(stdout, ".");
383 fflush(stdout);
384 if (!EC_GROUP_precompute_mult(group, ctx)) ABORT;
385 if (!EC_POINT_mul(group, Q, z, NULL, NULL, ctx)) ABORT;
386 if (!EC_POINT_is_at_infinity(group, Q)) ABORT;
387 fprintf(stdout, " ok\n");
388
389 if (!(P_224 = EC_GROUP_new(EC_GROUP_method_of(group)))) ABORT;
390 if (!EC_GROUP_copy(P_224, group)) ABORT;
391
392
393 /* Curve P-256 (FIPS PUB 186-2, App. 6) */
394
395 if (!BN_hex2bn(&p, "FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF")) ABORT;
396 if (1 != BN_is_prime(p, BN_prime_checks, 0, ctx, NULL)) ABORT;
397 if (!BN_hex2bn(&a, "FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFC")) ABORT;
398 if (!BN_hex2bn(&b, "5AC635D8AA3A93E7B3EBBD55769886BC651D06B0CC53B0F63BCE3C3E27D2604B")) ABORT;
399 if (!EC_GROUP_set_curve_GFp(group, p, a, b, ctx)) ABORT;
400
401 if (!BN_hex2bn(&x, "6B17D1F2E12C4247F8BCE6E563A440F277037D812DEB33A0F4A13945D898C296")) ABORT;
402 if (!EC_POINT_set_compressed_coordinates_GFp(group, P, x, 1, ctx)) ABORT;
403 if (!EC_POINT_is_on_curve(group, P, ctx)) ABORT;
404 if (!BN_hex2bn(&z, "FFFFFFFF00000000FFFFFFFFFFFFFFFFBCE6FAADA7179E"
405 "84F3B9CAC2FC632551")) ABORT;
406 if (!EC_GROUP_set_generator(group, P, z, BN_value_one())) ABORT;
407
408 if (!EC_POINT_get_affine_coordinates_GFp(group, P, x, y, ctx)) ABORT;
409 fprintf(stdout, "\nNIST curve P-256 -- Generator:\n x = 0x");
410 BN_print_fp(stdout, x);
411 fprintf(stdout, "\n y = 0x");
412 BN_print_fp(stdout, y);
413 fprintf(stdout, "\n");
414 /* G_y value taken from the standard: */
415 if (!BN_hex2bn(&z, "4FE342E2FE1A7F9B8EE7EB4A7C0F9E162BCE33576B315ECECBB6406837BF51F5")) ABORT;
416 if (0 != BN_cmp(y, z)) ABORT;
417
418 fprintf(stdout, "verify group order ...");
419 fflush(stdout);
420 if (!EC_GROUP_get_order(group, z, ctx)) ABORT;
421 if (!EC_POINT_mul(group, Q, z, NULL, NULL, ctx)) ABORT;
422 if (!EC_POINT_is_at_infinity(group, Q)) ABORT;
423 fprintf(stdout, ".");
424 fflush(stdout);
425 if (!EC_GROUP_precompute_mult(group, ctx)) ABORT;
426 if (!EC_POINT_mul(group, Q, z, NULL, NULL, ctx)) ABORT;
427 if (!EC_POINT_is_at_infinity(group, Q)) ABORT;
428 fprintf(stdout, " ok\n");
429
430 if (!(P_256 = EC_GROUP_new(EC_GROUP_method_of(group)))) ABORT;
431 if (!EC_GROUP_copy(P_256, group)) ABORT;
432
433
434 /* Curve P-384 (FIPS PUB 186-2, App. 6) */
435
436 if (!BN_hex2bn(&p, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
437 "FFFFFFFFFFFFFFFFFEFFFFFFFF0000000000000000FFFFFFFF")) ABORT;
438 if (1 != BN_is_prime(p, BN_prime_checks, 0, ctx, NULL)) ABORT;
439 if (!BN_hex2bn(&a, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
440 "FFFFFFFFFFFFFFFFFEFFFFFFFF0000000000000000FFFFFFFC")) ABORT;
441 if (!BN_hex2bn(&b, "B3312FA7E23EE7E4988E056BE3F82D19181D9C6EFE8141"
442 "120314088F5013875AC656398D8A2ED19D2A85C8EDD3EC2AEF")) ABORT;
443 if (!EC_GROUP_set_curve_GFp(group, p, a, b, ctx)) ABORT;
444
445 if (!BN_hex2bn(&x, "AA87CA22BE8B05378EB1C71EF320AD746E1D3B628BA79B"
446 "9859F741E082542A385502F25DBF55296C3A545E3872760AB7")) ABORT;
447 if (!EC_POINT_set_compressed_coordinates_GFp(group, P, x, 1, ctx)) ABORT;
448 if (!EC_POINT_is_on_curve(group, P, ctx)) ABORT;
449 if (!BN_hex2bn(&z, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
450 "FFC7634D81F4372DDF581A0DB248B0A77AECEC196ACCC52973")) ABORT;
451 if (!EC_GROUP_set_generator(group, P, z, BN_value_one())) ABORT;
452
453 if (!EC_POINT_get_affine_coordinates_GFp(group, P, x, y, ctx)) ABORT;
454 fprintf(stdout, "\nNIST curve P-384 -- Generator:\n x = 0x");
455 BN_print_fp(stdout, x);
456 fprintf(stdout, "\n y = 0x");
457 BN_print_fp(stdout, y);
458 fprintf(stdout, "\n");
459 /* G_y value taken from the standard: */
460 if (!BN_hex2bn(&z, "3617DE4A96262C6F5D9E98BF9292DC29F8F41DBD289A14"
461 "7CE9DA3113B5F0B8C00A60B1CE1D7E819D7A431D7C90EA0E5F")) ABORT;
462 if (0 != BN_cmp(y, z)) ABORT;
463
464 fprintf(stdout, "verify group order ...");
465 fflush(stdout);
466 if (!EC_GROUP_get_order(group, z, ctx)) ABORT;
467 if (!EC_POINT_mul(group, Q, z, NULL, NULL, ctx)) ABORT;
468 if (!EC_POINT_is_at_infinity(group, Q)) ABORT;
469 fprintf(stdout, ".");
470 fflush(stdout);
471 if (!EC_GROUP_precompute_mult(group, ctx)) ABORT;
472 if (!EC_POINT_mul(group, Q, z, NULL, NULL, ctx)) ABORT;
473 if (!EC_POINT_is_at_infinity(group, Q)) ABORT;
474 fprintf(stdout, " ok\n");
475
476 if (!(P_384 = EC_GROUP_new(EC_GROUP_method_of(group)))) ABORT;
477 if (!EC_GROUP_copy(P_384, group)) ABORT;
478
479
480 /* Curve P-521 (FIPS PUB 186-2, App. 6) */
481
482 if (!BN_hex2bn(&p, "1FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
483 "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
484 "FFFFFFFFFFFFFFFFFFFFFFFFFFFF")) ABORT;
485 if (1 != BN_is_prime(p, BN_prime_checks, 0, ctx, NULL)) ABORT;
486 if (!BN_hex2bn(&a, "1FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
487 "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
488 "FFFFFFFFFFFFFFFFFFFFFFFFFFFC")) ABORT;
489 if (!BN_hex2bn(&b, "051953EB9618E1C9A1F929A21A0B68540EEA2DA725B99B"
490 "315F3B8B489918EF109E156193951EC7E937B1652C0BD3BB1BF073573"
491 "DF883D2C34F1EF451FD46B503F00")) ABORT;
492 if (!EC_GROUP_set_curve_GFp(group, p, a, b, ctx)) ABORT;
493
494 if (!BN_hex2bn(&x, "C6858E06B70404E9CD9E3ECB662395B4429C648139053F"
495 "B521F828AF606B4D3DBAA14B5E77EFE75928FE1DC127A2FFA8DE3348B"
496 "3C1856A429BF97E7E31C2E5BD66")) ABORT;
497 if (!EC_POINT_set_compressed_coordinates_GFp(group, P, x, 0, ctx)) ABORT;
498 if (!EC_POINT_is_on_curve(group, P, ctx)) ABORT;
499 if (!BN_hex2bn(&z, "1FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
500 "FFFFFFFFFFFFFFFFFFFFA51868783BF2F966B7FCC0148F709A5D03BB5"
501 "C9B8899C47AEBB6FB71E91386409")) ABORT;
502 if (!EC_GROUP_set_generator(group, P, z, BN_value_one())) ABORT;
503
504 if (!EC_POINT_get_affine_coordinates_GFp(group, P, x, y, ctx)) ABORT;
505 fprintf(stdout, "\nNIST curve P-521 -- Generator:\n x = 0x");
506 BN_print_fp(stdout, x);
507 fprintf(stdout, "\n y = 0x");
508 BN_print_fp(stdout, y);
509 fprintf(stdout, "\n");
510 /* G_y value taken from the standard: */
511 if (!BN_hex2bn(&z, "11839296A789A3BC0045C8A5FB42C7D1BD998F54449579"
512 "B446817AFBD17273E662C97EE72995EF42640C550B9013FAD0761353C"
513 "7086A272C24088BE94769FD16650")) ABORT;
514 if (0 != BN_cmp(y, z)) ABORT;
515
516 fprintf(stdout, "verify group order ...");
517 fflush(stdout);
518 if (!EC_GROUP_get_order(group, z, ctx)) ABORT;
519 if (!EC_POINT_mul(group, Q, z, NULL, NULL, ctx)) ABORT;
520 if (!EC_POINT_is_at_infinity(group, Q)) ABORT;
521 fprintf(stdout, ".");
522 fflush(stdout);
523 if (!EC_GROUP_precompute_mult(group, ctx)) ABORT;
524 if (!EC_POINT_mul(group, Q, z, NULL, NULL, ctx)) ABORT;
525 if (!EC_POINT_is_at_infinity(group, Q)) ABORT;
526 fprintf(stdout, " ok\n");
527
528 if (!(P_521 = EC_GROUP_new(EC_GROUP_method_of(group)))) ABORT;
529 if (!EC_GROUP_copy(P_521, group)) ABORT;
530
531
532 /* more tests using the last curve */
533
534 if (!EC_POINT_copy(Q, P)) ABORT;
535 if (EC_POINT_is_at_infinity(group, Q)) ABORT;
536 if (!EC_POINT_dbl(group, P, P, ctx)) ABORT;
537 if (!EC_POINT_is_on_curve(group, P, ctx)) ABORT;
538 if (!EC_POINT_invert(group, Q, ctx)) ABORT; /* P = -2Q */
539
540 if (!EC_POINT_add(group, R, P, Q, ctx)) ABORT;
541 if (!EC_POINT_add(group, R, R, Q, ctx)) ABORT;
542 if (!EC_POINT_is_at_infinity(group, R)) ABORT; /* R = P + 2Q */
543
544 {
545 const EC_POINT *points[3];
546 const BIGNUM *scalars[3];
547
548 if (EC_POINT_is_at_infinity(group, Q)) ABORT;
549 points[0] = Q;
550 points[1] = Q;
551 points[2] = Q;
552
553 if (!BN_add(y, z, BN_value_one())) ABORT;
554 if (BN_is_odd(y)) ABORT;
555 if (!BN_rshift1(y, y)) ABORT;
556 scalars[0] = y; /* (group order + 1)/2, so y*Q + y*Q = Q */
557 scalars[1] = y;
558
559 fprintf(stdout, "combined multiplication ...");
560 fflush(stdout);
561
562 /* z is still the group order */
563 if (!EC_POINTs_mul(group, P, NULL, 2, points, scalars, ctx)) ABORT;
564 if (!EC_POINTs_mul(group, R, z, 2, points, scalars, ctx)) ABORT;
565 if (0 != EC_POINT_cmp(group, P, R, ctx)) ABORT;
566 if (0 != EC_POINT_cmp(group, R, Q, ctx)) ABORT;
567
568 fprintf(stdout, ".");
569 fflush(stdout);
570
571 if (!BN_pseudo_rand(y, BN_num_bits(y), 0, 0)) ABORT;
572 if (!BN_add(z, z, y)) ABORT;
573 z->neg = 1;
574 scalars[0] = y;
575 scalars[1] = z; /* z = -(order + y) */
576
577 if (!EC_POINTs_mul(group, P, NULL, 2, points, scalars, ctx)) ABORT;
578 if (!EC_POINT_is_at_infinity(group, P)) ABORT;
579
580 fprintf(stdout, ".");
581 fflush(stdout);
582
583 if (!BN_pseudo_rand(x, BN_num_bits(y) - 1, 0, 0)) ABORT;
584 if (!BN_add(z, x, y)) ABORT;
585 z->neg = 1;
586 scalars[0] = x;
587 scalars[1] = y;
588 scalars[2] = z; /* z = -(x+y) */
589
590 if (!EC_POINTs_mul(group, P, NULL, 3, points, scalars, ctx)) ABORT;
591 if (!EC_POINT_is_at_infinity(group, P)) ABORT;
592
593 fprintf(stdout, " ok\n\n");
594 }
595
596
597#if 0
598 timings(P_192, 0, ctx);
599 timings(P_192, 1, ctx);
600 timings(P_224, 0, ctx);
601 timings(P_224, 1, ctx);
602 timings(P_256, 0, ctx);
603 timings(P_256, 1, ctx);
604 timings(P_384, 0, ctx);
605 timings(P_384, 1, ctx);
606 timings(P_521, 0, ctx);
607 timings(P_521, 1, ctx);
608#endif
609
610
611 if (ctx)
612 BN_CTX_free(ctx);
613 BN_free(p); BN_free(a); BN_free(b);
614 EC_GROUP_free(group);
615 EC_POINT_free(P);
616 EC_POINT_free(Q);
617 EC_POINT_free(R);
618 BN_free(x); BN_free(y); BN_free(z);
619
620 if (P_192) EC_GROUP_free(P_192);
621 if (P_224) EC_GROUP_free(P_224);
622 if (P_256) EC_GROUP_free(P_256);
623 if (P_384) EC_GROUP_free(P_384);
624 if (P_521) EC_GROUP_free(P_521);
625
626 ENGINE_cleanup();
627 CRYPTO_cleanup_all_ex_data();
628 ERR_free_strings();
629 ERR_remove_state(0);
630 CRYPTO_mem_leaks_fp(stderr);
631
632 return 0;
633 }
634#endif
diff --git a/src/lib/libcrypto/engine/enginetest.c b/src/lib/libcrypto/engine/enginetest.c
new file mode 100644
index 0000000000..a5a3c47fcb
--- /dev/null
+++ b/src/lib/libcrypto/engine/enginetest.c
@@ -0,0 +1,251 @@
1/* crypto/engine/enginetest.c */
2/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 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 * licensing@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 <stdio.h>
60#include <string.h>
61#include <openssl/engine.h>
62#include <openssl/err.h>
63
64static void display_engine_list()
65 {
66 ENGINE *h;
67 int loop;
68
69 h = ENGINE_get_first();
70 loop = 0;
71 printf("listing available engine types\n");
72 while(h)
73 {
74 printf("engine %i, id = \"%s\", name = \"%s\"\n",
75 loop++, ENGINE_get_id(h), ENGINE_get_name(h));
76 h = ENGINE_get_next(h);
77 }
78 printf("end of list\n");
79 }
80
81int main(int argc, char *argv[])
82 {
83 ENGINE *block[512];
84 char buf[256];
85 const char *id, *name;
86 ENGINE *ptr;
87 int loop;
88 int to_return = 1;
89 ENGINE *new_h1 = NULL;
90 ENGINE *new_h2 = NULL;
91 ENGINE *new_h3 = NULL;
92 ENGINE *new_h4 = NULL;
93
94 ERR_load_crypto_strings();
95
96 memset(block, 0, 512 * sizeof(ENGINE *));
97 if(((new_h1 = ENGINE_new()) == NULL) ||
98 !ENGINE_set_id(new_h1, "test_id0") ||
99 !ENGINE_set_name(new_h1, "First test item") ||
100 ((new_h2 = ENGINE_new()) == NULL) ||
101 !ENGINE_set_id(new_h2, "test_id1") ||
102 !ENGINE_set_name(new_h2, "Second test item") ||
103 ((new_h3 = ENGINE_new()) == NULL) ||
104 !ENGINE_set_id(new_h3, "test_id2") ||
105 !ENGINE_set_name(new_h3, "Third test item") ||
106 ((new_h4 = ENGINE_new()) == NULL) ||
107 !ENGINE_set_id(new_h4, "test_id3") ||
108 !ENGINE_set_name(new_h4, "Fourth test item"))
109 {
110 printf("Couldn't set up test ENGINE structures\n");
111 goto end;
112 }
113 printf("\nenginetest beginning\n\n");
114 display_engine_list();
115 if(!ENGINE_add(new_h1))
116 {
117 printf("Add failed!\n");
118 goto end;
119 }
120 display_engine_list();
121 ptr = ENGINE_get_first();
122 if(!ENGINE_remove(ptr))
123 {
124 printf("Remove failed!\n");
125 goto end;
126 }
127 display_engine_list();
128 if(!ENGINE_add(new_h3) || !ENGINE_add(new_h2))
129 {
130 printf("Add failed!\n");
131 goto end;
132 }
133 display_engine_list();
134 if(!ENGINE_remove(new_h2))
135 {
136 printf("Remove failed!\n");
137 goto end;
138 }
139 display_engine_list();
140 if(!ENGINE_add(new_h4))
141 {
142 printf("Add failed!\n");
143 goto end;
144 }
145 display_engine_list();
146 if(ENGINE_add(new_h3))
147 {
148 printf("Add *should* have failed but didn't!\n");
149 goto end;
150 }
151 else
152 printf("Add that should fail did.\n");
153 ERR_clear_error();
154 if(ENGINE_remove(new_h2))
155 {
156 printf("Remove *should* have failed but didn't!\n");
157 goto end;
158 }
159 else
160 printf("Remove that should fail did.\n");
161 if(!ENGINE_remove(new_h1))
162 {
163 printf("Remove failed!\n");
164 goto end;
165 }
166 display_engine_list();
167 if(!ENGINE_remove(new_h3))
168 {
169 printf("Remove failed!\n");
170 goto end;
171 }
172 display_engine_list();
173 if(!ENGINE_remove(new_h4))
174 {
175 printf("Remove failed!\n");
176 goto end;
177 }
178 display_engine_list();
179 /* Depending on whether there's any hardware support compiled
180 * in, this remove may be destined to fail. */
181 ptr = ENGINE_get_first();
182 if(ptr)
183 if(!ENGINE_remove(ptr))
184 printf("Remove failed!i - probably no hardware "
185 "support present.\n");
186 display_engine_list();
187 if(!ENGINE_add(new_h1) || !ENGINE_remove(new_h1))
188 {
189 printf("Couldn't add and remove to an empty list!\n");
190 goto end;
191 }
192 else
193 printf("Successfully added and removed to an empty list!\n");
194 printf("About to beef up the engine-type list\n");
195 for(loop = 0; loop < 512; loop++)
196 {
197 sprintf(buf, "id%i", loop);
198 id = strdup(buf);
199 sprintf(buf, "Fake engine type %i", loop);
200 name = strdup(buf);
201 if(((block[loop] = ENGINE_new()) == NULL) ||
202 !ENGINE_set_id(block[loop], id) ||
203 !ENGINE_set_name(block[loop], name))
204 {
205 printf("Couldn't create block of ENGINE structures.\n"
206 "I'll probably also core-dump now, damn.\n");
207 goto end;
208 }
209 }
210 for(loop = 0; loop < 512; loop++)
211 {
212 if(!ENGINE_add(block[loop]))
213 {
214 printf("\nAdding stopped at %i, (%s,%s)\n",
215 loop, ENGINE_get_id(block[loop]),
216 ENGINE_get_name(block[loop]));
217 goto cleanup_loop;
218 }
219 else
220 printf("."); fflush(stdout);
221 }
222cleanup_loop:
223 printf("\nAbout to empty the engine-type list\n");
224 while((ptr = ENGINE_get_first()) != NULL)
225 {
226 if(!ENGINE_remove(ptr))
227 {
228 printf("\nRemove failed!\n");
229 goto end;
230 }
231 printf("."); fflush(stdout);
232 }
233 for(loop = 0; loop < 512; loop++)
234 {
235 free((char *)(ENGINE_get_id(block[loop])));
236 free((char *)(ENGINE_get_name(block[loop])));
237 }
238 printf("\nTests completed happily\n");
239 to_return = 0;
240end:
241 if(to_return)
242 ERR_print_errors_fp(stderr);
243 if(new_h1) ENGINE_free(new_h1);
244 if(new_h2) ENGINE_free(new_h2);
245 if(new_h3) ENGINE_free(new_h3);
246 if(new_h4) ENGINE_free(new_h4);
247 for(loop = 0; loop < 512; loop++)
248 if(block[loop])
249 ENGINE_free(block[loop]);
250 return to_return;
251 }
diff --git a/src/lib/libcrypto/engine/hw.ec b/src/lib/libcrypto/engine/hw.ec
new file mode 100644
index 0000000000..5481a43918
--- /dev/null
+++ b/src/lib/libcrypto/engine/hw.ec
@@ -0,0 +1,8 @@
1L AEPHK hw_aep_err.h hw_aep_err.c
2L ATALLA hw_atalla_err.h hw_atalla_err.c
3L CSWIFT hw_cswift_err.h hw_cswift_err.c
4L HWCRHK hw_ncipher_err.h hw_ncipher_err.c
5L NURON hw_nuron_err.h hw_nuron_err.c
6L SUREWARE hw_sureware_err.h hw_sureware_err.c
7L UBSEC hw_ubsec_err.h hw_ubsec_err.c
8L CCA4758 hw_4758_cca_err.h hw_4758_cca_err.c
diff --git a/src/lib/libcrypto/engine/hw_4758_cca.c b/src/lib/libcrypto/engine/hw_4758_cca.c
new file mode 100644
index 0000000000..959d8f1a61
--- /dev/null
+++ b/src/lib/libcrypto/engine/hw_4758_cca.c
@@ -0,0 +1,950 @@
1/* Author: Maurice Gittens <maurice@gittens.nl> */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * licensing@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56#include <stdio.h>
57#include <openssl/crypto.h>
58/* #include <openssl/pem.h> */
59#include "cryptlib.h"
60#include <openssl/dso.h>
61#include <openssl/x509.h>
62#include <openssl/objects.h>
63#include <openssl/engine.h>
64
65#ifndef OPENSSL_NO_HW
66#ifndef OPENSSL_NO_HW_4758_CCA
67
68#ifdef FLAT_INC
69#include "hw_4758_cca.h"
70#else
71#include "vendor_defns/hw_4758_cca.h"
72#endif
73
74#include "hw_4758_cca_err.c"
75
76static int ibm_4758_cca_destroy(ENGINE *e);
77static int ibm_4758_cca_init(ENGINE *e);
78static int ibm_4758_cca_finish(ENGINE *e);
79static int ibm_4758_cca_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)());
80
81/* rsa functions */
82/*---------------*/
83#ifndef OPENSSL_NO_RSA
84static int cca_rsa_pub_enc(int flen, const unsigned char *from,
85 unsigned char *to, RSA *rsa,int padding);
86static int cca_rsa_priv_dec(int flen, const unsigned char *from,
87 unsigned char *to, RSA *rsa,int padding);
88static int cca_rsa_sign(int type, const unsigned char *m, unsigned int m_len,
89 unsigned char *sigret, unsigned int *siglen, const RSA *rsa);
90static int cca_rsa_verify(int dtype, const unsigned char *m, unsigned int m_len,
91 unsigned char *sigbuf, unsigned int siglen, const RSA *rsa);
92
93/* utility functions */
94/*-----------------------*/
95static EVP_PKEY *ibm_4758_load_privkey(ENGINE*, const char*,
96 UI_METHOD *ui_method, void *callback_data);
97static EVP_PKEY *ibm_4758_load_pubkey(ENGINE*, const char*,
98 UI_METHOD *ui_method, void *callback_data);
99
100static int getModulusAndExponent(const unsigned char *token, long *exponentLength,
101 unsigned char *exponent, long *modulusLength,
102 long *modulusFieldLength, unsigned char *modulus);
103#endif
104
105/* RAND number functions */
106/*-----------------------*/
107static int cca_get_random_bytes(unsigned char*, int );
108static int cca_random_status(void);
109
110static void cca_ex_free(void *obj, void *item, CRYPTO_EX_DATA *ad,
111 int idx,long argl, void *argp);
112
113/* Function pointers for CCA verbs */
114/*---------------------------------*/
115#ifndef OPENSSL_NO_RSA
116static F_KEYRECORDREAD keyRecordRead;
117static F_DIGITALSIGNATUREGENERATE digitalSignatureGenerate;
118static F_DIGITALSIGNATUREVERIFY digitalSignatureVerify;
119static F_PUBLICKEYEXTRACT publicKeyExtract;
120static F_PKAENCRYPT pkaEncrypt;
121static F_PKADECRYPT pkaDecrypt;
122#endif
123static F_RANDOMNUMBERGENERATE randomNumberGenerate;
124
125/* static variables */
126/*------------------*/
127static const char def_CCA4758_LIB_NAME[] = CCA_LIB_NAME;
128static const char *CCA4758_LIB_NAME = def_CCA4758_LIB_NAME;
129#ifndef OPENSSL_NO_RSA
130static const char* n_keyRecordRead = CSNDKRR;
131static const char* n_digitalSignatureGenerate = CSNDDSG;
132static const char* n_digitalSignatureVerify = CSNDDSV;
133static const char* n_publicKeyExtract = CSNDPKX;
134static const char* n_pkaEncrypt = CSNDPKE;
135static const char* n_pkaDecrypt = CSNDPKD;
136#endif
137static const char* n_randomNumberGenerate = CSNBRNG;
138
139static int hndidx = -1;
140static DSO *dso = NULL;
141
142/* openssl engine initialization structures */
143/*------------------------------------------*/
144
145#define CCA4758_CMD_SO_PATH ENGINE_CMD_BASE
146static const ENGINE_CMD_DEFN cca4758_cmd_defns[] = {
147 {CCA4758_CMD_SO_PATH,
148 "SO_PATH",
149 "Specifies the path to the '4758cca' shared library",
150 ENGINE_CMD_FLAG_STRING},
151 {0, NULL, NULL, 0}
152 };
153
154#ifndef OPENSSL_NO_RSA
155static RSA_METHOD ibm_4758_cca_rsa =
156 {
157 "IBM 4758 CCA RSA method",
158 cca_rsa_pub_enc,
159 NULL,
160 NULL,
161 cca_rsa_priv_dec,
162 NULL, /*rsa_mod_exp,*/
163 NULL, /*mod_exp_mont,*/
164 NULL, /* init */
165 NULL, /* finish */
166 RSA_FLAG_SIGN_VER, /* flags */
167 NULL, /* app_data */
168 cca_rsa_sign, /* rsa_sign */
169 cca_rsa_verify /* rsa_verify */
170 };
171#endif
172
173static RAND_METHOD ibm_4758_cca_rand =
174 {
175 /* "IBM 4758 RAND method", */
176 NULL, /* seed */
177 cca_get_random_bytes, /* get random bytes from the card */
178 NULL, /* cleanup */
179 NULL, /* add */
180 cca_get_random_bytes, /* pseudo rand */
181 cca_random_status, /* status */
182 };
183
184static const char *engine_4758_cca_id = "4758cca";
185static const char *engine_4758_cca_name = "IBM 4758 CCA hardware engine support";
186
187/* engine implementation */
188/*-----------------------*/
189static int bind_helper(ENGINE *e)
190 {
191 if(!ENGINE_set_id(e, engine_4758_cca_id) ||
192 !ENGINE_set_name(e, engine_4758_cca_name) ||
193#ifndef OPENSSL_NO_RSA
194 !ENGINE_set_RSA(e, &ibm_4758_cca_rsa) ||
195#endif
196 !ENGINE_set_RAND(e, &ibm_4758_cca_rand) ||
197 !ENGINE_set_destroy_function(e, ibm_4758_cca_destroy) ||
198 !ENGINE_set_init_function(e, ibm_4758_cca_init) ||
199 !ENGINE_set_finish_function(e, ibm_4758_cca_finish) ||
200 !ENGINE_set_ctrl_function(e, ibm_4758_cca_ctrl) ||
201 !ENGINE_set_load_privkey_function(e, ibm_4758_load_privkey) ||
202 !ENGINE_set_load_pubkey_function(e, ibm_4758_load_pubkey) ||
203 !ENGINE_set_cmd_defns(e, cca4758_cmd_defns))
204 return 0;
205 /* Ensure the error handling is set up */
206 ERR_load_CCA4758_strings();
207 return 1;
208 }
209
210static ENGINE *engine_4758_cca(void)
211 {
212 ENGINE *ret = ENGINE_new();
213 if(!ret)
214 return NULL;
215 if(!bind_helper(ret))
216 {
217 ENGINE_free(ret);
218 return NULL;
219 }
220 return ret;
221 }
222
223void ENGINE_load_4758cca(void)
224 {
225 ENGINE *e_4758 = engine_4758_cca();
226 if (!e_4758) return;
227 ENGINE_add(e_4758);
228 ENGINE_free(e_4758);
229 ERR_clear_error();
230 }
231
232static int ibm_4758_cca_destroy(ENGINE *e)
233 {
234 ERR_unload_CCA4758_strings();
235 return 1;
236 }
237
238static int ibm_4758_cca_init(ENGINE *e)
239 {
240 if(dso)
241 {
242 CCA4758err(CCA4758_F_IBM_4758_CCA_INIT,CCA4758_R_ALREADY_LOADED);
243 goto err;
244 }
245
246 dso = DSO_load(NULL, CCA4758_LIB_NAME , NULL, 0);
247 if(!dso)
248 {
249 CCA4758err(CCA4758_F_IBM_4758_CCA_INIT,CCA4758_R_DSO_FAILURE);
250 goto err;
251 }
252
253#ifndef OPENSSL_NO_RSA
254 if(!(keyRecordRead = (F_KEYRECORDREAD)
255 DSO_bind_func(dso, n_keyRecordRead)) ||
256 !(randomNumberGenerate = (F_RANDOMNUMBERGENERATE)
257 DSO_bind_func(dso, n_randomNumberGenerate)) ||
258 !(digitalSignatureGenerate = (F_DIGITALSIGNATUREGENERATE)
259 DSO_bind_func(dso, n_digitalSignatureGenerate)) ||
260 !(digitalSignatureVerify = (F_DIGITALSIGNATUREVERIFY)
261 DSO_bind_func(dso, n_digitalSignatureVerify)) ||
262 !(publicKeyExtract = (F_PUBLICKEYEXTRACT)
263 DSO_bind_func(dso, n_publicKeyExtract)) ||
264 !(pkaEncrypt = (F_PKAENCRYPT)
265 DSO_bind_func(dso, n_pkaEncrypt)) ||
266 !(pkaDecrypt = (F_PKADECRYPT)
267 DSO_bind_func(dso, n_pkaDecrypt)))
268 {
269 CCA4758err(CCA4758_F_IBM_4758_CCA_INIT,CCA4758_R_DSO_FAILURE);
270 goto err;
271 }
272#else
273 if(!(randomNumberGenerate = (F_RANDOMNUMBERGENERATE)
274 DSO_bind_func(dso, n_randomNumberGenerate)))
275 {
276 CCA4758err(CCA4758_F_IBM_4758_CCA_INIT,CCA4758_R_DSO_FAILURE);
277 goto err;
278 }
279#endif
280
281 hndidx = RSA_get_ex_new_index(0, "IBM 4758 CCA RSA key handle",
282 NULL, NULL, cca_ex_free);
283
284 return 1;
285err:
286 if(dso)
287 DSO_free(dso);
288 dso = NULL;
289
290 keyRecordRead = (F_KEYRECORDREAD)NULL;
291 randomNumberGenerate = (F_RANDOMNUMBERGENERATE)NULL;
292 digitalSignatureGenerate = (F_DIGITALSIGNATUREGENERATE)NULL;
293 digitalSignatureVerify = (F_DIGITALSIGNATUREVERIFY)NULL;
294 publicKeyExtract = (F_PUBLICKEYEXTRACT)NULL;
295 pkaEncrypt = (F_PKAENCRYPT)NULL;
296 pkaDecrypt = (F_PKADECRYPT)NULL;
297 return 0;
298 }
299
300static int ibm_4758_cca_finish(ENGINE *e)
301 {
302 if(dso)
303 {
304 CCA4758err(CCA4758_F_IBM_4758_CCA_FINISH,
305 CCA4758_R_NOT_LOADED);
306 return 0;
307 }
308 if(!DSO_free(dso))
309 {
310 CCA4758err(CCA4758_F_IBM_4758_CCA_FINISH,
311 CCA4758_R_UNIT_FAILURE);
312 return 0;
313 }
314 dso = NULL;
315 keyRecordRead = (F_KEYRECORDREAD)NULL;
316 randomNumberGenerate = (F_RANDOMNUMBERGENERATE)NULL;
317 digitalSignatureGenerate = (F_DIGITALSIGNATUREGENERATE)NULL;
318 digitalSignatureVerify = (F_DIGITALSIGNATUREVERIFY)NULL;
319 publicKeyExtract = (F_PUBLICKEYEXTRACT)NULL;
320 pkaEncrypt = (F_PKAENCRYPT)NULL;
321 pkaDecrypt = (F_PKADECRYPT)NULL;
322 return 1;
323 }
324
325static int ibm_4758_cca_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)())
326 {
327 int initialised = ((dso == NULL) ? 0 : 1);
328 switch(cmd)
329 {
330 case CCA4758_CMD_SO_PATH:
331 if(p == NULL)
332 {
333 CCA4758err(CCA4758_F_IBM_4758_CCA_CTRL,
334 ERR_R_PASSED_NULL_PARAMETER);
335 return 0;
336 }
337 if(initialised)
338 {
339 CCA4758err(CCA4758_F_IBM_4758_CCA_CTRL,
340 CCA4758_R_ALREADY_LOADED);
341 return 0;
342 }
343 CCA4758_LIB_NAME = (const char *)p;
344 return 1;
345 default:
346 break;
347 }
348 CCA4758err(CCA4758_F_IBM_4758_CCA_CTRL,
349 CCA4758_R_COMMAND_NOT_IMPLEMENTED);
350 return 0;
351 }
352
353#ifndef OPENSSL_NO_RSA
354
355#define MAX_CCA_PKA_TOKEN_SIZE 2500
356
357static EVP_PKEY *ibm_4758_load_privkey(ENGINE* e, const char* key_id,
358 UI_METHOD *ui_method, void *callback_data)
359 {
360 RSA *rtmp = NULL;
361 EVP_PKEY *res = NULL;
362 unsigned char* keyToken = NULL;
363 unsigned char pubKeyToken[MAX_CCA_PKA_TOKEN_SIZE];
364 long pubKeyTokenLength = MAX_CCA_PKA_TOKEN_SIZE;
365 long keyTokenLength = MAX_CCA_PKA_TOKEN_SIZE;
366 long returnCode;
367 long reasonCode;
368 long exitDataLength = 0;
369 long ruleArrayLength = 0;
370 unsigned char exitData[8];
371 unsigned char ruleArray[8];
372 unsigned char keyLabel[64];
373 long keyLabelLength = strlen(key_id);
374 unsigned char modulus[256];
375 long modulusFieldLength = sizeof(modulus);
376 long modulusLength = 0;
377 unsigned char exponent[256];
378 long exponentLength = sizeof(exponent);
379
380 if (keyLabelLength > sizeof(keyLabel))
381 {
382 CCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY,
383 CCA4758_R_SIZE_TOO_LARGE_OR_TOO_SMALL);
384 return NULL;
385 }
386
387 memset(keyLabel,' ', sizeof(keyLabel));
388 memcpy(keyLabel, key_id, keyLabelLength);
389
390 keyToken = OPENSSL_malloc(MAX_CCA_PKA_TOKEN_SIZE + sizeof(long));
391 if (!keyToken)
392 {
393 CCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY,
394 ERR_R_MALLOC_FAILURE);
395 goto err;
396 }
397
398 keyRecordRead(&returnCode, &reasonCode, &exitDataLength,
399 exitData, &ruleArrayLength, ruleArray, keyLabel,
400 &keyTokenLength, keyToken+sizeof(long));
401
402 if (returnCode)
403 {
404 CCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY,
405 CCA4758_R_FAILED_LOADING_PRIVATE_KEY);
406 goto err;
407 }
408
409 publicKeyExtract(&returnCode, &reasonCode, &exitDataLength,
410 exitData, &ruleArrayLength, ruleArray, &keyTokenLength,
411 keyToken+sizeof(long), &pubKeyTokenLength, pubKeyToken);
412
413 if (returnCode)
414 {
415 CCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY,
416 CCA4758_R_FAILED_LOADING_PRIVATE_KEY);
417 goto err;
418 }
419
420 if (!getModulusAndExponent(pubKeyToken, &exponentLength,
421 exponent, &modulusLength, &modulusFieldLength,
422 modulus))
423 {
424 CCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY,
425 CCA4758_R_FAILED_LOADING_PRIVATE_KEY);
426 goto err;
427 }
428
429 (*(long*)keyToken) = keyTokenLength;
430 rtmp = RSA_new_method(e);
431 RSA_set_ex_data(rtmp, hndidx, (char *)keyToken);
432
433 rtmp->e = BN_bin2bn(exponent, exponentLength, NULL);
434 rtmp->n = BN_bin2bn(modulus, modulusFieldLength, NULL);
435 rtmp->flags |= RSA_FLAG_EXT_PKEY;
436
437 res = EVP_PKEY_new();
438 EVP_PKEY_assign_RSA(res, rtmp);
439
440 return res;
441err:
442 if (keyToken)
443 OPENSSL_free(keyToken);
444 if (res)
445 EVP_PKEY_free(res);
446 if (rtmp)
447 RSA_free(rtmp);
448 return NULL;
449 }
450
451static EVP_PKEY *ibm_4758_load_pubkey(ENGINE* e, const char* key_id,
452 UI_METHOD *ui_method, void *callback_data)
453 {
454 RSA *rtmp = NULL;
455 EVP_PKEY *res = NULL;
456 unsigned char* keyToken = NULL;
457 long keyTokenLength = MAX_CCA_PKA_TOKEN_SIZE;
458 long returnCode;
459 long reasonCode;
460 long exitDataLength = 0;
461 long ruleArrayLength = 0;
462 unsigned char exitData[8];
463 unsigned char ruleArray[8];
464 unsigned char keyLabel[64];
465 long keyLabelLength = strlen(key_id);
466 unsigned char modulus[512];
467 long modulusFieldLength = sizeof(modulus);
468 long modulusLength = 0;
469 unsigned char exponent[512];
470 long exponentLength = sizeof(exponent);
471
472 if (keyLabelLength > sizeof(keyLabel))
473 {
474 CCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY,
475 CCA4758_R_SIZE_TOO_LARGE_OR_TOO_SMALL);
476 return NULL;
477 }
478
479 memset(keyLabel,' ', sizeof(keyLabel));
480 memcpy(keyLabel, key_id, keyLabelLength);
481
482 keyToken = OPENSSL_malloc(MAX_CCA_PKA_TOKEN_SIZE + sizeof(long));
483 if (!keyToken)
484 {
485 CCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PUBKEY,
486 ERR_R_MALLOC_FAILURE);
487 goto err;
488 }
489
490 keyRecordRead(&returnCode, &reasonCode, &exitDataLength, exitData,
491 &ruleArrayLength, ruleArray, keyLabel, &keyTokenLength,
492 keyToken+sizeof(long));
493
494 if (returnCode)
495 {
496 CCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY,
497 ERR_R_MALLOC_FAILURE);
498 goto err;
499 }
500
501 if (!getModulusAndExponent(keyToken+sizeof(long), &exponentLength,
502 exponent, &modulusLength, &modulusFieldLength, modulus))
503 {
504 CCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY,
505 CCA4758_R_FAILED_LOADING_PUBLIC_KEY);
506 goto err;
507 }
508
509 (*(long*)keyToken) = keyTokenLength;
510 rtmp = RSA_new_method(e);
511 RSA_set_ex_data(rtmp, hndidx, (char *)keyToken);
512 rtmp->e = BN_bin2bn(exponent, exponentLength, NULL);
513 rtmp->n = BN_bin2bn(modulus, modulusFieldLength, NULL);
514 rtmp->flags |= RSA_FLAG_EXT_PKEY;
515 res = EVP_PKEY_new();
516 EVP_PKEY_assign_RSA(res, rtmp);
517
518 return res;
519err:
520 if (keyToken)
521 OPENSSL_free(keyToken);
522 if (res)
523 EVP_PKEY_free(res);
524 if (rtmp)
525 RSA_free(rtmp);
526 return NULL;
527 }
528
529static int cca_rsa_pub_enc(int flen, const unsigned char *from,
530 unsigned char *to, RSA *rsa,int padding)
531 {
532 long returnCode;
533 long reasonCode;
534 long lflen = flen;
535 long exitDataLength = 0;
536 unsigned char exitData[8];
537 long ruleArrayLength = 1;
538 unsigned char ruleArray[8] = "PKCS-1.2";
539 long dataStructureLength = 0;
540 unsigned char dataStructure[8];
541 long outputLength = RSA_size(rsa);
542 long keyTokenLength;
543 unsigned char* keyToken = (unsigned char*)RSA_get_ex_data(rsa, hndidx);
544
545 keyTokenLength = *(long*)keyToken;
546 keyToken+=sizeof(long);
547
548 pkaEncrypt(&returnCode, &reasonCode, &exitDataLength, exitData,
549 &ruleArrayLength, ruleArray, &lflen, (unsigned char*)from,
550 &dataStructureLength, dataStructure, &keyTokenLength,
551 keyToken, &outputLength, to);
552
553 if (returnCode || reasonCode)
554 return -(returnCode << 16 | reasonCode);
555 return outputLength;
556 }
557
558static int cca_rsa_priv_dec(int flen, const unsigned char *from,
559 unsigned char *to, RSA *rsa,int padding)
560 {
561 long returnCode;
562 long reasonCode;
563 long lflen = flen;
564 long exitDataLength = 0;
565 unsigned char exitData[8];
566 long ruleArrayLength = 1;
567 unsigned char ruleArray[8] = "PKCS-1.2";
568 long dataStructureLength = 0;
569 unsigned char dataStructure[8];
570 long outputLength = RSA_size(rsa);
571 long keyTokenLength;
572 unsigned char* keyToken = (unsigned char*)RSA_get_ex_data(rsa, hndidx);
573
574 keyTokenLength = *(long*)keyToken;
575 keyToken+=sizeof(long);
576
577 pkaDecrypt(&returnCode, &reasonCode, &exitDataLength, exitData,
578 &ruleArrayLength, ruleArray, &lflen, (unsigned char*)from,
579 &dataStructureLength, dataStructure, &keyTokenLength,
580 keyToken, &outputLength, to);
581
582 return (returnCode | reasonCode) ? 0 : 1;
583 }
584
585#define SSL_SIG_LEN 36
586
587static int cca_rsa_verify(int type, const unsigned char *m, unsigned int m_len,
588 unsigned char *sigbuf, unsigned int siglen, const RSA *rsa)
589 {
590 long returnCode;
591 long reasonCode;
592 long lsiglen = siglen;
593 long exitDataLength = 0;
594 unsigned char exitData[8];
595 long ruleArrayLength = 1;
596 unsigned char ruleArray[8] = "PKCS-1.1";
597 long keyTokenLength;
598 unsigned char* keyToken = (unsigned char*)RSA_get_ex_data(rsa, hndidx);
599 long length = SSL_SIG_LEN;
600 long keyLength ;
601 unsigned char *hashBuffer = NULL;
602 X509_SIG sig;
603 ASN1_TYPE parameter;
604 X509_ALGOR algorithm;
605 ASN1_OCTET_STRING digest;
606
607 keyTokenLength = *(long*)keyToken;
608 keyToken+=sizeof(long);
609
610 if (type == NID_md5 || type == NID_sha1)
611 {
612 sig.algor = &algorithm;
613 algorithm.algorithm = OBJ_nid2obj(type);
614
615 if (!algorithm.algorithm)
616 {
617 CCA4758err(CCA4758_F_IBM_4758_CCA_VERIFY,
618 CCA4758_R_UNKNOWN_ALGORITHM_TYPE);
619 return 0;
620 }
621
622 if (!algorithm.algorithm->length)
623 {
624 CCA4758err(CCA4758_F_IBM_4758_CCA_VERIFY,
625 CCA4758_R_ASN1_OID_UNKNOWN_FOR_MD);
626 return 0;
627 }
628
629 parameter.type = V_ASN1_NULL;
630 parameter.value.ptr = NULL;
631 algorithm.parameter = &parameter;
632
633 sig.digest = &digest;
634 sig.digest->data = (unsigned char*)m;
635 sig.digest->length = m_len;
636
637 length = i2d_X509_SIG(&sig, NULL);
638 }
639
640 keyLength = RSA_size(rsa);
641
642 if (length - RSA_PKCS1_PADDING > keyLength)
643 {
644 CCA4758err(CCA4758_F_IBM_4758_CCA_VERIFY,
645 CCA4758_R_SIZE_TOO_LARGE_OR_TOO_SMALL);
646 return 0;
647 }
648
649 switch (type)
650 {
651 case NID_md5_sha1 :
652 if (m_len != SSL_SIG_LEN)
653 {
654 CCA4758err(CCA4758_F_IBM_4758_CCA_VERIFY,
655 CCA4758_R_SIZE_TOO_LARGE_OR_TOO_SMALL);
656 return 0;
657 }
658
659 hashBuffer = (unsigned char *)m;
660 length = m_len;
661 break;
662 case NID_md5 :
663 {
664 unsigned char *ptr;
665 ptr = hashBuffer = OPENSSL_malloc(
666 (unsigned int)keyLength+1);
667 if (!hashBuffer)
668 {
669 CCA4758err(CCA4758_F_IBM_4758_CCA_VERIFY,
670 ERR_R_MALLOC_FAILURE);
671 return 0;
672 }
673
674 i2d_X509_SIG(&sig, &ptr);
675 }
676 break;
677 case NID_sha1 :
678 {
679 unsigned char *ptr;
680 ptr = hashBuffer = OPENSSL_malloc(
681 (unsigned int)keyLength+1);
682 if (!hashBuffer)
683 {
684 CCA4758err(CCA4758_F_IBM_4758_CCA_VERIFY,
685 ERR_R_MALLOC_FAILURE);
686 return 0;
687 }
688 i2d_X509_SIG(&sig, &ptr);
689 }
690 break;
691 default:
692 return 0;
693 }
694
695 digitalSignatureVerify(&returnCode, &reasonCode, &exitDataLength,
696 exitData, &ruleArrayLength, ruleArray, &keyTokenLength,
697 keyToken, &length, hashBuffer, &lsiglen, sigbuf);
698
699 if (type == NID_sha1 || type == NID_md5)
700 {
701 memset(hashBuffer, keyLength+1, 0);
702 OPENSSL_free(hashBuffer);
703 }
704
705 return ((returnCode || reasonCode) ? 0 : 1);
706 }
707
708#define SSL_SIG_LEN 36
709
710static int cca_rsa_sign(int type, const unsigned char *m, unsigned int m_len,
711 unsigned char *sigret, unsigned int *siglen, const RSA *rsa)
712 {
713 long returnCode;
714 long reasonCode;
715 long exitDataLength = 0;
716 unsigned char exitData[8];
717 long ruleArrayLength = 1;
718 unsigned char ruleArray[8] = "PKCS-1.1";
719 long outputLength=256;
720 long outputBitLength;
721 long keyTokenLength;
722 unsigned char *hashBuffer = NULL;
723 unsigned char* keyToken = (unsigned char*)RSA_get_ex_data(rsa, hndidx);
724 long length = SSL_SIG_LEN;
725 long keyLength ;
726 X509_SIG sig;
727 ASN1_TYPE parameter;
728 X509_ALGOR algorithm;
729 ASN1_OCTET_STRING digest;
730
731 keyTokenLength = *(long*)keyToken;
732 keyToken+=sizeof(long);
733
734 if (type == NID_md5 || type == NID_sha1)
735 {
736 sig.algor = &algorithm;
737 algorithm.algorithm = OBJ_nid2obj(type);
738
739 if (!algorithm.algorithm)
740 {
741 CCA4758err(CCA4758_F_IBM_4758_CCA_SIGN,
742 CCA4758_R_UNKNOWN_ALGORITHM_TYPE);
743 return 0;
744 }
745
746 if (!algorithm.algorithm->length)
747 {
748 CCA4758err(CCA4758_F_IBM_4758_CCA_SIGN,
749 CCA4758_R_ASN1_OID_UNKNOWN_FOR_MD);
750 return 0;
751 }
752
753 parameter.type = V_ASN1_NULL;
754 parameter.value.ptr = NULL;
755 algorithm.parameter = &parameter;
756
757 sig.digest = &digest;
758 sig.digest->data = (unsigned char*)m;
759 sig.digest->length = m_len;
760
761 length = i2d_X509_SIG(&sig, NULL);
762 }
763
764 keyLength = RSA_size(rsa);
765
766 if (length - RSA_PKCS1_PADDING > keyLength)
767 {
768 CCA4758err(CCA4758_F_IBM_4758_CCA_SIGN,
769 CCA4758_R_SIZE_TOO_LARGE_OR_TOO_SMALL);
770 return 0;
771 }
772
773 switch (type)
774 {
775 case NID_md5_sha1 :
776 if (m_len != SSL_SIG_LEN)
777 {
778 CCA4758err(CCA4758_F_IBM_4758_CCA_SIGN,
779 CCA4758_R_SIZE_TOO_LARGE_OR_TOO_SMALL);
780 return 0;
781 }
782 hashBuffer = (unsigned char*)m;
783 length = m_len;
784 break;
785 case NID_md5 :
786 {
787 unsigned char *ptr;
788 ptr = hashBuffer = OPENSSL_malloc(
789 (unsigned int)keyLength+1);
790 if (!hashBuffer)
791 {
792 CCA4758err(CCA4758_F_IBM_4758_CCA_VERIFY,
793 ERR_R_MALLOC_FAILURE);
794 return 0;
795 }
796 i2d_X509_SIG(&sig, &ptr);
797 }
798 break;
799 case NID_sha1 :
800 {
801 unsigned char *ptr;
802 ptr = hashBuffer = OPENSSL_malloc(
803 (unsigned int)keyLength+1);
804 if (!hashBuffer)
805 {
806 CCA4758err(CCA4758_F_IBM_4758_CCA_VERIFY,
807 ERR_R_MALLOC_FAILURE);
808 return 0;
809 }
810 i2d_X509_SIG(&sig, &ptr);
811 }
812 break;
813 default:
814 return 0;
815 }
816
817 digitalSignatureGenerate(&returnCode, &reasonCode, &exitDataLength,
818 exitData, &ruleArrayLength, ruleArray, &keyTokenLength,
819 keyToken, &length, hashBuffer, &outputLength, &outputBitLength,
820 sigret);
821
822 if (type == NID_sha1 || type == NID_md5)
823 {
824 memset(hashBuffer, keyLength+1, 0);
825 OPENSSL_free(hashBuffer);
826 }
827
828 *siglen = outputLength;
829
830 return ((returnCode || reasonCode) ? 0 : 1);
831 }
832
833static int getModulusAndExponent(const unsigned char*token, long *exponentLength,
834 unsigned char *exponent, long *modulusLength, long *modulusFieldLength,
835 unsigned char *modulus)
836 {
837 unsigned long len;
838
839 if (*token++ != (char)0x1E) /* internal PKA token? */
840 return 0;
841
842 if (*token++) /* token version must be zero */
843 return 0;
844
845 len = *token++;
846 len = len << 8;
847 len |= (unsigned char)*token++;
848
849 token += 4; /* skip reserved bytes */
850
851 if (*token++ == (char)0x04)
852 {
853 if (*token++) /* token version must be zero */
854 return 0;
855
856 len = *token++;
857 len = len << 8;
858 len |= (unsigned char)*token++;
859
860 token+=2; /* skip reserved section */
861
862 len = *token++;
863 len = len << 8;
864 len |= (unsigned char)*token++;
865
866 *exponentLength = len;
867
868 len = *token++;
869 len = len << 8;
870 len |= (unsigned char)*token++;
871
872 *modulusLength = len;
873
874 len = *token++;
875 len = len << 8;
876 len |= (unsigned char)*token++;
877
878 *modulusFieldLength = len;
879
880 memcpy(exponent, token, *exponentLength);
881 token+= *exponentLength;
882
883 memcpy(modulus, token, *modulusFieldLength);
884 return 1;
885 }
886 return 0;
887 }
888
889#endif /* OPENSSL_NO_RSA */
890
891static int cca_random_status(void)
892 {
893 return 1;
894 }
895
896static int cca_get_random_bytes(unsigned char* buf, int num)
897 {
898 long ret_code;
899 long reason_code;
900 long exit_data_length;
901 unsigned char exit_data[4];
902 unsigned char form[] = "RANDOM ";
903 unsigned char rand_buf[8];
904
905 while(num >= sizeof(rand_buf))
906 {
907 randomNumberGenerate(&ret_code, &reason_code, &exit_data_length,
908 exit_data, form, rand_buf);
909 if (ret_code)
910 return 0;
911 num -= sizeof(rand_buf);
912 memcpy(buf, rand_buf, sizeof(rand_buf));
913 buf += sizeof(rand_buf);
914 }
915
916 if (num)
917 {
918 randomNumberGenerate(&ret_code, &reason_code, NULL, NULL,
919 form, rand_buf);
920 if (ret_code)
921 return 0;
922 memcpy(buf, rand_buf, num);
923 }
924
925 return 1;
926 }
927
928static void cca_ex_free(void *obj, void *item, CRYPTO_EX_DATA *ad, int idx,
929 long argl, void *argp)
930 {
931 if (item)
932 OPENSSL_free(item);
933 }
934
935/* Goo to handle building as a dynamic engine */
936#ifdef ENGINE_DYNAMIC_SUPPORT
937static int bind_fn(ENGINE *e, const char *id)
938 {
939 if(id && (strcmp(id, engine_cswift_id) != 0))
940 return 0;
941 if(!bind_helper(e))
942 return 0;
943 return 1;
944 }
945IMPLEMENT_DYNAMIC_CHECK_FN()
946IMPLEMENT_DYNAMIC_BIND_FN(bind_fn)
947#endif /* ENGINE_DYNAMIC_SUPPORT */
948
949#endif /* !OPENSSL_NO_HW_4758_CCA */
950#endif /* !OPENSSL_NO_HW */
diff --git a/src/lib/libcrypto/engine/hw_4758_cca_err.c b/src/lib/libcrypto/engine/hw_4758_cca_err.c
new file mode 100644
index 0000000000..7ea5c63707
--- /dev/null
+++ b/src/lib/libcrypto/engine/hw_4758_cca_err.c
@@ -0,0 +1,149 @@
1/* hw_4758_cca_err.c */
2/* ====================================================================
3 * Copyright (c) 1999-2002 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file,
58 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include "hw_4758_cca_err.h"
64
65/* BEGIN ERROR CODES */
66#ifndef OPENSSL_NO_ERR
67static ERR_STRING_DATA CCA4758_str_functs[]=
68 {
69{ERR_PACK(0,CCA4758_F_IBM_4758_CCA_CTRL,0), "IBM_4758_CCA_CTRL"},
70{ERR_PACK(0,CCA4758_F_IBM_4758_CCA_FINISH,0), "IBM_4758_CCA_FINISH"},
71{ERR_PACK(0,CCA4758_F_IBM_4758_CCA_INIT,0), "IBM_4758_CCA_INIT"},
72{ERR_PACK(0,CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY,0), "IBM_4758_CCA_LOAD_PRIVKEY"},
73{ERR_PACK(0,CCA4758_F_IBM_4758_CCA_LOAD_PUBKEY,0), "IBM_4758_CCA_LOAD_PUBKEY"},
74{ERR_PACK(0,CCA4758_F_IBM_4758_CCA_SIGN,0), "IBM_4758_CCA_SIGN"},
75{ERR_PACK(0,CCA4758_F_IBM_4758_CCA_VERIFY,0), "IBM_4758_CCA_VERIFY"},
76{0,NULL}
77 };
78
79static ERR_STRING_DATA CCA4758_str_reasons[]=
80 {
81{CCA4758_R_ALREADY_LOADED ,"already loaded"},
82{CCA4758_R_ASN1_OID_UNKNOWN_FOR_MD ,"asn1 oid unknown for md"},
83{CCA4758_R_COMMAND_NOT_IMPLEMENTED ,"command not implemented"},
84{CCA4758_R_DSO_FAILURE ,"dso failure"},
85{CCA4758_R_FAILED_LOADING_PRIVATE_KEY ,"failed loading private key"},
86{CCA4758_R_FAILED_LOADING_PUBLIC_KEY ,"failed loading public key"},
87{CCA4758_R_NOT_LOADED ,"not loaded"},
88{CCA4758_R_SIZE_TOO_LARGE_OR_TOO_SMALL ,"size too large or too small"},
89{CCA4758_R_UNIT_FAILURE ,"unit failure"},
90{CCA4758_R_UNKNOWN_ALGORITHM_TYPE ,"unknown algorithm type"},
91{0,NULL}
92 };
93
94#endif
95
96#ifdef CCA4758_LIB_NAME
97static ERR_STRING_DATA CCA4758_lib_name[]=
98 {
99{0 ,CCA4758_LIB_NAME},
100{0,NULL}
101 };
102#endif
103
104
105static int CCA4758_lib_error_code=0;
106static int CCA4758_error_init=1;
107
108static void ERR_load_CCA4758_strings(void)
109 {
110 if (CCA4758_lib_error_code == 0)
111 CCA4758_lib_error_code=ERR_get_next_error_library();
112
113 if (CCA4758_error_init)
114 {
115 CCA4758_error_init=0;
116#ifndef OPENSSL_NO_ERR
117 ERR_load_strings(CCA4758_lib_error_code,CCA4758_str_functs);
118 ERR_load_strings(CCA4758_lib_error_code,CCA4758_str_reasons);
119#endif
120
121#ifdef CCA4758_LIB_NAME
122 CCA4758_lib_name->error = ERR_PACK(CCA4758_lib_error_code,0,0);
123 ERR_load_strings(0,CCA4758_lib_name);
124#endif
125 }
126 }
127
128static void ERR_unload_CCA4758_strings(void)
129 {
130 if (CCA4758_error_init == 0)
131 {
132#ifndef OPENSSL_NO_ERR
133 ERR_unload_strings(CCA4758_lib_error_code,CCA4758_str_functs);
134 ERR_unload_strings(CCA4758_lib_error_code,CCA4758_str_reasons);
135#endif
136
137#ifdef CCA4758_LIB_NAME
138 ERR_unload_strings(0,CCA4758_lib_name);
139#endif
140 CCA4758_error_init=1;
141 }
142 }
143
144static void ERR_CCA4758_error(int function, int reason, char *file, int line)
145 {
146 if (CCA4758_lib_error_code == 0)
147 CCA4758_lib_error_code=ERR_get_next_error_library();
148 ERR_PUT_error(CCA4758_lib_error_code,function,reason,file,line);
149 }
diff --git a/src/lib/libcrypto/engine/hw_4758_cca_err.h b/src/lib/libcrypto/engine/hw_4758_cca_err.h
new file mode 100644
index 0000000000..2fc563ab11
--- /dev/null
+++ b/src/lib/libcrypto/engine/hw_4758_cca_err.h
@@ -0,0 +1,93 @@
1/* ====================================================================
2 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * 3. All advertising materials mentioning features or use of this
17 * software must display the following acknowledgment:
18 * "This product includes software developed by the OpenSSL Project
19 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
20 *
21 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission. For written permission, please contact
24 * openssl-core@openssl.org.
25 *
26 * 5. Products derived from this software may not be called "OpenSSL"
27 * nor may "OpenSSL" appear in their names without prior written
28 * permission of the OpenSSL Project.
29 *
30 * 6. Redistributions of any form whatsoever must retain the following
31 * acknowledgment:
32 * "This product includes software developed by the OpenSSL Project
33 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46 * OF THE POSSIBILITY OF SUCH DAMAGE.
47 * ====================================================================
48 *
49 * This product includes cryptographic software written by Eric Young
50 * (eay@cryptsoft.com). This product includes software written by Tim
51 * Hudson (tjh@cryptsoft.com).
52 *
53 */
54
55#ifndef HEADER_CCA4758_ERR_H
56#define HEADER_CCA4758_ERR_H
57
58/* BEGIN ERROR CODES */
59/* The following lines are auto generated by the script mkerr.pl. Any changes
60 * made after this point may be overwritten when the script is next run.
61 */
62static void ERR_load_CCA4758_strings(void);
63static void ERR_unload_CCA4758_strings(void);
64static void ERR_CCA4758_error(int function, int reason, char *file, int line);
65#define CCA4758err(f,r) ERR_CCA4758_error((f),(r),__FILE__,__LINE__)
66
67/* Error codes for the CCA4758 functions. */
68
69/* Function codes. */
70#define CCA4758_F_IBM_4758_CCA_CTRL 100
71#define CCA4758_F_IBM_4758_CCA_FINISH 101
72#define CCA4758_F_IBM_4758_CCA_INIT 102
73#define CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY 103
74#define CCA4758_F_IBM_4758_CCA_LOAD_PUBKEY 104
75#define CCA4758_F_IBM_4758_CCA_SIGN 105
76#define CCA4758_F_IBM_4758_CCA_VERIFY 106
77
78/* Reason codes. */
79#define CCA4758_R_ALREADY_LOADED 100
80#define CCA4758_R_ASN1_OID_UNKNOWN_FOR_MD 101
81#define CCA4758_R_COMMAND_NOT_IMPLEMENTED 102
82#define CCA4758_R_DSO_FAILURE 103
83#define CCA4758_R_FAILED_LOADING_PRIVATE_KEY 104
84#define CCA4758_R_FAILED_LOADING_PUBLIC_KEY 105
85#define CCA4758_R_NOT_LOADED 106
86#define CCA4758_R_SIZE_TOO_LARGE_OR_TOO_SMALL 107
87#define CCA4758_R_UNIT_FAILURE 108
88#define CCA4758_R_UNKNOWN_ALGORITHM_TYPE 109
89
90#ifdef __cplusplus
91}
92#endif
93#endif
diff --git a/src/lib/libcrypto/engine/hw_aep.c b/src/lib/libcrypto/engine/hw_aep.c
new file mode 100644
index 0000000000..cf4507cff1
--- /dev/null
+++ b/src/lib/libcrypto/engine/hw_aep.c
@@ -0,0 +1,1101 @@
1/* crypto/engine/hw_aep.c */
2/*
3 */
4/* ====================================================================
5 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 *
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
17 * distribution.
18 *
19 * 3. All advertising materials mentioning features or use of this
20 * software must display the following acknowledgment:
21 * "This product includes software developed by the OpenSSL Project
22 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
23 *
24 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25 * endorse or promote products derived from this software without
26 * prior written permission. For written permission, please contact
27 * licensing@OpenSSL.org.
28 *
29 * 5. Products derived from this software may not be called "OpenSSL"
30 * nor may "OpenSSL" appear in their names without prior written
31 * permission of the OpenSSL Project.
32 *
33 * 6. Redistributions of any form whatsoever must retain the following
34 * acknowledgment:
35 * "This product includes software developed by the OpenSSL Project
36 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
37 *
38 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49 * OF THE POSSIBILITY OF SUCH DAMAGE.
50 * ====================================================================
51 *
52 * This product includes cryptographic software written by Eric Young
53 * (eay@cryptsoft.com). This product includes software written by Tim
54 * Hudson (tjh@cryptsoft.com).
55 *
56 */
57
58#include <stdio.h>
59#include <openssl/bn.h>
60#include <string.h>
61
62#include <openssl/e_os2.h>
63#ifndef OPENSSL_SYS_MSDOS
64#include <sys/types.h>
65#include <unistd.h>
66#else
67#include <process.h>
68typedef int pid_t;
69#endif
70
71#include <openssl/crypto.h>
72#include <openssl/dso.h>
73#include <openssl/engine.h>
74
75#ifndef OPENSSL_NO_HW
76#ifndef OPENSSL_NO_HW_AEP
77#ifdef FLAT_INC
78#include "aep.h"
79#else
80#include "vendor_defns/aep.h"
81#endif
82
83#define AEP_LIB_NAME "aep engine"
84#define FAIL_TO_SW 0x10101010
85
86#include "hw_aep_err.c"
87
88static int aep_init(ENGINE *e);
89static int aep_finish(ENGINE *e);
90static int aep_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)());
91static int aep_destroy(ENGINE *e);
92
93static AEP_RV aep_get_connection(AEP_CONNECTION_HNDL_PTR hConnection);
94static AEP_RV aep_return_connection(AEP_CONNECTION_HNDL hConnection);
95static AEP_RV aep_close_connection(AEP_CONNECTION_HNDL hConnection);
96static AEP_RV aep_close_all_connections(int use_engine_lock, int *in_use);
97
98/* BIGNUM stuff */
99static int aep_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
100 const BIGNUM *m, BN_CTX *ctx);
101
102static AEP_RV aep_mod_exp_crt(BIGNUM *r,const BIGNUM *a, const BIGNUM *p,
103 const BIGNUM *q, const BIGNUM *dmp1,const BIGNUM *dmq1,
104 const BIGNUM *iqmp, BN_CTX *ctx);
105
106/* RSA stuff */
107#ifndef OPENSSL_NO_RSA
108static int aep_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa);
109#endif
110
111/* This function is aliased to mod_exp (with the mont stuff dropped). */
112static int aep_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
113 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
114
115/* DSA stuff */
116#ifndef OPENSSL_NO_DSA
117static int aep_dsa_mod_exp(DSA *dsa, BIGNUM *rr, BIGNUM *a1,
118 BIGNUM *p1, BIGNUM *a2, BIGNUM *p2, BIGNUM *m,
119 BN_CTX *ctx, BN_MONT_CTX *in_mont);
120
121static int aep_mod_exp_dsa(DSA *dsa, BIGNUM *r, BIGNUM *a,
122 const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx,
123 BN_MONT_CTX *m_ctx);
124#endif
125
126/* DH stuff */
127/* This function is aliased to mod_exp (with the DH and mont dropped). */
128#ifndef OPENSSL_NO_DH
129static int aep_mod_exp_dh(const DH *dh, BIGNUM *r, const BIGNUM *a,
130 const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
131#endif
132
133/* rand stuff */
134#ifdef AEPRAND
135static int aep_rand(unsigned char *buf, int num);
136static int aep_rand_status(void);
137#endif
138
139/* Bignum conversion stuff */
140static AEP_RV GetBigNumSize(AEP_VOID_PTR ArbBigNum, AEP_U32* BigNumSize);
141static AEP_RV MakeAEPBigNum(AEP_VOID_PTR ArbBigNum, AEP_U32 BigNumSize,
142 unsigned char* AEP_BigNum);
143static AEP_RV ConvertAEPBigNum(void* ArbBigNum, AEP_U32 BigNumSize,
144 unsigned char* AEP_BigNum);
145
146/* The definitions for control commands specific to this engine */
147#define AEP_CMD_SO_PATH ENGINE_CMD_BASE
148static const ENGINE_CMD_DEFN aep_cmd_defns[] =
149 {
150 { AEP_CMD_SO_PATH,
151 "SO_PATH",
152 "Specifies the path to the 'aep' shared library",
153 ENGINE_CMD_FLAG_STRING
154 },
155 {0, NULL, NULL, 0}
156 };
157
158#ifndef OPENSSL_NO_RSA
159/* Our internal RSA_METHOD that we provide pointers to */
160static RSA_METHOD aep_rsa =
161 {
162 "Aep RSA method",
163 NULL, /*rsa_pub_encrypt*/
164 NULL, /*rsa_pub_decrypt*/
165 NULL, /*rsa_priv_encrypt*/
166 NULL, /*rsa_priv_encrypt*/
167 aep_rsa_mod_exp, /*rsa_mod_exp*/
168 aep_mod_exp_mont, /*bn_mod_exp*/
169 NULL, /*init*/
170 NULL, /*finish*/
171 0, /*flags*/
172 NULL, /*app_data*/
173 NULL, /*rsa_sign*/
174 NULL /*rsa_verify*/
175 };
176#endif
177
178#ifndef OPENSSL_NO_DSA
179/* Our internal DSA_METHOD that we provide pointers to */
180static DSA_METHOD aep_dsa =
181 {
182 "Aep DSA method",
183 NULL, /* dsa_do_sign */
184 NULL, /* dsa_sign_setup */
185 NULL, /* dsa_do_verify */
186 aep_dsa_mod_exp, /* dsa_mod_exp */
187 aep_mod_exp_dsa, /* bn_mod_exp */
188 NULL, /* init */
189 NULL, /* finish */
190 0, /* flags */
191 NULL /* app_data */
192 };
193#endif
194
195#ifndef OPENSSL_NO_DH
196/* Our internal DH_METHOD that we provide pointers to */
197static DH_METHOD aep_dh =
198 {
199 "Aep DH method",
200 NULL,
201 NULL,
202 aep_mod_exp_dh,
203 NULL,
204 NULL,
205 0,
206 NULL
207 };
208#endif
209
210#ifdef AEPRAND
211/* our internal RAND_method that we provide pointers to */
212static RAND_METHOD aep_random =
213 {
214 /*"AEP RAND method", */
215 NULL,
216 aep_rand,
217 NULL,
218 NULL,
219 aep_rand,
220 aep_rand_status,
221 };
222#endif
223
224/*Define an array of structures to hold connections*/
225static AEP_CONNECTION_ENTRY aep_app_conn_table[MAX_PROCESS_CONNECTIONS];
226
227/*Used to determine if this is a new process*/
228static pid_t recorded_pid = 0;
229
230#ifdef AEPRAND
231static AEP_U8 rand_block[RAND_BLK_SIZE];
232static AEP_U32 rand_block_bytes = 0;
233#endif
234
235/* Constants used when creating the ENGINE */
236static const char *engine_aep_id = "aep";
237static const char *engine_aep_name = "Aep hardware engine support";
238
239static int max_key_len = 2176;
240
241
242/* This internal function is used by ENGINE_aep() and possibly by the
243 * "dynamic" ENGINE support too */
244static int bind_aep(ENGINE *e)
245 {
246#ifndef OPENSSL_NO_RSA
247 const RSA_METHOD *meth1;
248#endif
249#ifndef OPENSSL_NO_DSA
250 const DSA_METHOD *meth2;
251#endif
252#ifndef OPENSSL_NO_DH
253 const DH_METHOD *meth3;
254#endif
255
256 if(!ENGINE_set_id(e, engine_aep_id) ||
257 !ENGINE_set_name(e, engine_aep_name) ||
258#ifndef OPENSSL_NO_RSA
259 !ENGINE_set_RSA(e, &aep_rsa) ||
260#endif
261#ifndef OPENSSL_NO_DSA
262 !ENGINE_set_DSA(e, &aep_dsa) ||
263#endif
264#ifndef OPENSSL_NO_DH
265 !ENGINE_set_DH(e, &aep_dh) ||
266#endif
267#ifdef AEPRAND
268 !ENGINE_set_RAND(e, &aep_random) ||
269#endif
270 !ENGINE_set_init_function(e, aep_init) ||
271 !ENGINE_set_destroy_function(e, aep_destroy) ||
272 !ENGINE_set_finish_function(e, aep_finish) ||
273 !ENGINE_set_ctrl_function(e, aep_ctrl) ||
274 !ENGINE_set_cmd_defns(e, aep_cmd_defns))
275 return 0;
276
277#ifndef OPENSSL_NO_RSA
278 /* We know that the "PKCS1_SSLeay()" functions hook properly
279 * to the aep-specific mod_exp and mod_exp_crt so we use
280 * those functions. NB: We don't use ENGINE_openssl() or
281 * anything "more generic" because something like the RSAref
282 * code may not hook properly, and if you own one of these
283 * cards then you have the right to do RSA operations on it
284 * anyway! */
285 meth1 = RSA_PKCS1_SSLeay();
286 aep_rsa.rsa_pub_enc = meth1->rsa_pub_enc;
287 aep_rsa.rsa_pub_dec = meth1->rsa_pub_dec;
288 aep_rsa.rsa_priv_enc = meth1->rsa_priv_enc;
289 aep_rsa.rsa_priv_dec = meth1->rsa_priv_dec;
290#endif
291
292
293#ifndef OPENSSL_NO_DSA
294 /* Use the DSA_OpenSSL() method and just hook the mod_exp-ish
295 * bits. */
296 meth2 = DSA_OpenSSL();
297 aep_dsa.dsa_do_sign = meth2->dsa_do_sign;
298 aep_dsa.dsa_sign_setup = meth2->dsa_sign_setup;
299 aep_dsa.dsa_do_verify = meth2->dsa_do_verify;
300
301 aep_dsa = *DSA_get_default_method();
302 aep_dsa.dsa_mod_exp = aep_dsa_mod_exp;
303 aep_dsa.bn_mod_exp = aep_mod_exp_dsa;
304#endif
305
306#ifndef OPENSSL_NO_DH
307 /* Much the same for Diffie-Hellman */
308 meth3 = DH_OpenSSL();
309 aep_dh.generate_key = meth3->generate_key;
310 aep_dh.compute_key = meth3->compute_key;
311 aep_dh.bn_mod_exp = meth3->bn_mod_exp;
312#endif
313
314 /* Ensure the aep error handling is set up */
315 ERR_load_AEPHK_strings();
316
317 return 1;
318}
319
320#ifdef ENGINE_DYNAMIC_SUPPORT
321static int bind_helper(ENGINE *e, const char *id)
322 {
323 if(id && (strcmp(id, engine_aep_id) != 0))
324 return 0;
325 if(!bind_aep(e))
326 return 0;
327 return 1;
328 }
329IMPLEMENT_DYNAMIC_CHECK_FN()
330IMPLEMENT_DYNAMIC_BIND_FN(bind_helper)
331#else
332static ENGINE *engine_aep(void)
333 {
334 ENGINE *ret = ENGINE_new();
335 if(!ret)
336 return NULL;
337 if(!bind_aep(ret))
338 {
339 ENGINE_free(ret);
340 return NULL;
341 }
342 return ret;
343 }
344
345void ENGINE_load_aep(void)
346 {
347 /* Copied from eng_[openssl|dyn].c */
348 ENGINE *toadd = engine_aep();
349 if(!toadd) return;
350 ENGINE_add(toadd);
351 ENGINE_free(toadd);
352 ERR_clear_error();
353 }
354#endif
355
356/* This is a process-global DSO handle used for loading and unloading
357 * the Aep library. NB: This is only set (or unset) during an
358 * init() or finish() call (reference counts permitting) and they're
359 * operating with global locks, so this should be thread-safe
360 * implicitly. */
361static DSO *aep_dso = NULL;
362
363/* These are the static string constants for the DSO file name and the function
364 * symbol names to bind to.
365*/
366static const char *AEP_LIBNAME = "aep";
367
368static const char *AEP_F1 = "AEP_ModExp";
369static const char *AEP_F2 = "AEP_ModExpCrt";
370#ifdef AEPRAND
371static const char *AEP_F3 = "AEP_GenRandom";
372#endif
373static const char *AEP_F4 = "AEP_Finalize";
374static const char *AEP_F5 = "AEP_Initialize";
375static const char *AEP_F6 = "AEP_OpenConnection";
376static const char *AEP_F7 = "AEP_SetBNCallBacks";
377static const char *AEP_F8 = "AEP_CloseConnection";
378
379/* These are the function pointers that are (un)set when the library has
380 * successfully (un)loaded. */
381static t_AEP_OpenConnection *p_AEP_OpenConnection = NULL;
382static t_AEP_CloseConnection *p_AEP_CloseConnection = NULL;
383static t_AEP_ModExp *p_AEP_ModExp = NULL;
384static t_AEP_ModExpCrt *p_AEP_ModExpCrt = NULL;
385#ifdef AEPRAND
386static t_AEP_GenRandom *p_AEP_GenRandom = NULL;
387#endif
388static t_AEP_Initialize *p_AEP_Initialize = NULL;
389static t_AEP_Finalize *p_AEP_Finalize = NULL;
390static t_AEP_SetBNCallBacks *p_AEP_SetBNCallBacks = NULL;
391
392/* (de)initialisation functions. */
393static int aep_init(ENGINE *e)
394 {
395 t_AEP_ModExp *p1;
396 t_AEP_ModExpCrt *p2;
397#ifdef AEPRAND
398 t_AEP_GenRandom *p3;
399#endif
400 t_AEP_Finalize *p4;
401 t_AEP_Initialize *p5;
402 t_AEP_OpenConnection *p6;
403 t_AEP_SetBNCallBacks *p7;
404 t_AEP_CloseConnection *p8;
405
406 int to_return = 0;
407
408 if(aep_dso != NULL)
409 {
410 AEPHKerr(AEPHK_F_AEP_INIT,AEPHK_R_ALREADY_LOADED);
411 goto err;
412 }
413 /* Attempt to load libaep.so. */
414
415 aep_dso = DSO_load(NULL, AEP_LIBNAME, NULL, 0);
416
417 if(aep_dso == NULL)
418 {
419 AEPHKerr(AEPHK_F_AEP_INIT,AEPHK_R_NOT_LOADED);
420 goto err;
421 }
422
423 if( !(p1 = (t_AEP_ModExp *) DSO_bind_func( aep_dso,AEP_F1)) ||
424 !(p2 = (t_AEP_ModExpCrt*) DSO_bind_func( aep_dso,AEP_F2)) ||
425#ifdef AEPRAND
426 !(p3 = (t_AEP_GenRandom*) DSO_bind_func( aep_dso,AEP_F3)) ||
427#endif
428 !(p4 = (t_AEP_Finalize*) DSO_bind_func( aep_dso,AEP_F4)) ||
429 !(p5 = (t_AEP_Initialize*) DSO_bind_func( aep_dso,AEP_F5)) ||
430 !(p6 = (t_AEP_OpenConnection*) DSO_bind_func( aep_dso,AEP_F6)) ||
431 !(p7 = (t_AEP_SetBNCallBacks*) DSO_bind_func( aep_dso,AEP_F7)) ||
432 !(p8 = (t_AEP_CloseConnection*) DSO_bind_func( aep_dso,AEP_F8)))
433 {
434 AEPHKerr(AEPHK_F_AEP_INIT,AEPHK_R_NOT_LOADED);
435 goto err;
436 }
437
438 /* Copy the pointers */
439
440 p_AEP_ModExp = p1;
441 p_AEP_ModExpCrt = p2;
442#ifdef AEPRAND
443 p_AEP_GenRandom = p3;
444#endif
445 p_AEP_Finalize = p4;
446 p_AEP_Initialize = p5;
447 p_AEP_OpenConnection = p6;
448 p_AEP_SetBNCallBacks = p7;
449 p_AEP_CloseConnection = p8;
450
451 to_return = 1;
452
453 return to_return;
454
455 err:
456
457 if(aep_dso)
458 DSO_free(aep_dso);
459
460 p_AEP_OpenConnection = NULL;
461 p_AEP_ModExp = NULL;
462 p_AEP_ModExpCrt = NULL;
463#ifdef AEPRAND
464 p_AEP_GenRandom = NULL;
465#endif
466 p_AEP_Initialize = NULL;
467 p_AEP_Finalize = NULL;
468 p_AEP_SetBNCallBacks = NULL;
469 p_AEP_CloseConnection = NULL;
470
471 return to_return;
472 }
473
474/* Destructor (complements the "ENGINE_aep()" constructor) */
475static int aep_destroy(ENGINE *e)
476 {
477 ERR_unload_AEPHK_strings();
478 return 1;
479 }
480
481static int aep_finish(ENGINE *e)
482 {
483 int to_return = 0, in_use;
484 AEP_RV rv;
485
486 if(aep_dso == NULL)
487 {
488 AEPHKerr(AEPHK_F_AEP_FINISH,AEPHK_R_NOT_LOADED);
489 goto err;
490 }
491
492 rv = aep_close_all_connections(0, &in_use);
493 if (rv != AEP_R_OK)
494 {
495 AEPHKerr(AEPHK_F_AEP_FINISH,AEPHK_R_CLOSE_HANDLES_FAILED);
496 goto err;
497 }
498 if (in_use)
499 {
500 AEPHKerr(AEPHK_F_AEP_FINISH,AEPHK_R_CONNECTIONS_IN_USE);
501 goto err;
502 }
503
504 rv = p_AEP_Finalize();
505 if (rv != AEP_R_OK)
506 {
507 AEPHKerr(AEPHK_F_AEP_FINISH,AEPHK_R_FINALIZE_FAILED);
508 goto err;
509 }
510
511 if(!DSO_free(aep_dso))
512 {
513 AEPHKerr(AEPHK_F_AEP_FINISH,AEPHK_R_UNIT_FAILURE);
514 goto err;
515 }
516
517 aep_dso = NULL;
518 p_AEP_CloseConnection = NULL;
519 p_AEP_OpenConnection = NULL;
520 p_AEP_ModExp = NULL;
521 p_AEP_ModExpCrt = NULL;
522#ifdef AEPRAND
523 p_AEP_GenRandom = NULL;
524#endif
525 p_AEP_Initialize = NULL;
526 p_AEP_Finalize = NULL;
527 p_AEP_SetBNCallBacks = NULL;
528
529 to_return = 1;
530 err:
531 return to_return;
532 }
533
534static int aep_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)())
535 {
536 int initialised = ((aep_dso == NULL) ? 0 : 1);
537 switch(cmd)
538 {
539 case AEP_CMD_SO_PATH:
540 if(p == NULL)
541 {
542 AEPHKerr(AEPHK_F_AEP_CTRL,
543 ERR_R_PASSED_NULL_PARAMETER);
544 return 0;
545 }
546 if(initialised)
547 {
548 AEPHKerr(AEPHK_F_AEP_CTRL,
549 AEPHK_R_ALREADY_LOADED);
550 return 0;
551 }
552 AEP_LIBNAME = (const char *)p;
553 return 1;
554 default:
555 break;
556 }
557 AEPHKerr(AEPHK_F_AEP_CTRL,AEPHK_R_CTRL_COMMAND_NOT_IMPLEMENTED);
558 return 0;
559 }
560
561static int aep_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
562 const BIGNUM *m, BN_CTX *ctx)
563 {
564 int to_return = 0;
565 int r_len = 0;
566 AEP_CONNECTION_HNDL hConnection;
567 AEP_RV rv;
568
569 r_len = BN_num_bits(m);
570
571 /* Perform in software if modulus is too large for hardware. */
572
573 if (r_len > max_key_len){
574 AEPHKerr(AEPHK_F_AEP_MOD_EXP, AEPHK_R_SIZE_TOO_LARGE_OR_TOO_SMALL);
575 return BN_mod_exp(r, a, p, m, ctx);
576 }
577
578 /*Grab a connection from the pool*/
579 rv = aep_get_connection(&hConnection);
580 if (rv != AEP_R_OK)
581 {
582 AEPHKerr(AEPHK_F_AEP_MOD_EXP,AEPHK_R_GET_HANDLE_FAILED);
583 return BN_mod_exp(r, a, p, m, ctx);
584 }
585
586 /*To the card with the mod exp*/
587 rv = p_AEP_ModExp(hConnection,(void*)a, (void*)p,(void*)m, (void*)r,NULL);
588
589 if (rv != AEP_R_OK)
590 {
591 AEPHKerr(AEPHK_F_AEP_MOD_EXP,AEPHK_R_MOD_EXP_FAILED);
592 rv = aep_close_connection(hConnection);
593 return BN_mod_exp(r, a, p, m, ctx);
594 }
595
596 /*Return the connection to the pool*/
597 rv = aep_return_connection(hConnection);
598 if (rv != AEP_R_OK)
599 {
600 AEPHKerr(AEPHK_F_AEP_RAND,AEPHK_R_RETURN_CONNECTION_FAILED);
601 goto err;
602 }
603
604 to_return = 1;
605 err:
606 return to_return;
607 }
608
609static AEP_RV aep_mod_exp_crt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
610 const BIGNUM *q, const BIGNUM *dmp1,
611 const BIGNUM *dmq1,const BIGNUM *iqmp, BN_CTX *ctx)
612 {
613 AEP_RV rv = AEP_R_OK;
614 AEP_CONNECTION_HNDL hConnection;
615
616 /*Grab a connection from the pool*/
617 rv = aep_get_connection(&hConnection);
618 if (rv != AEP_R_OK)
619 {
620 AEPHKerr(AEPHK_F_AEP_MOD_EXP_CRT,AEPHK_R_GET_HANDLE_FAILED);
621 return FAIL_TO_SW;
622 }
623
624 /*To the card with the mod exp*/
625 rv = p_AEP_ModExpCrt(hConnection,(void*)a, (void*)p, (void*)q, (void*)dmp1,(void*)dmq1,
626 (void*)iqmp,(void*)r,NULL);
627 if (rv != AEP_R_OK)
628 {
629 AEPHKerr(AEPHK_F_AEP_MOD_EXP_CRT,AEPHK_R_MOD_EXP_CRT_FAILED);
630 rv = aep_close_connection(hConnection);
631 return FAIL_TO_SW;
632 }
633
634 /*Return the connection to the pool*/
635 rv = aep_return_connection(hConnection);
636 if (rv != AEP_R_OK)
637 {
638 AEPHKerr(AEPHK_F_AEP_RAND,AEPHK_R_RETURN_CONNECTION_FAILED);
639 goto err;
640 }
641
642 err:
643 return rv;
644 }
645
646
647#ifdef AEPRAND
648static int aep_rand(unsigned char *buf,int len )
649 {
650 AEP_RV rv = AEP_R_OK;
651 AEP_CONNECTION_HNDL hConnection;
652
653 CRYPTO_w_lock(CRYPTO_LOCK_RAND);
654
655 /*Can the request be serviced with what's already in the buffer?*/
656 if (len <= rand_block_bytes)
657 {
658 memcpy(buf, &rand_block[RAND_BLK_SIZE - rand_block_bytes], len);
659 rand_block_bytes -= len;
660 CRYPTO_w_unlock(CRYPTO_LOCK_RAND);
661 }
662 else
663 /*If not the get another block of random bytes*/
664 {
665 CRYPTO_w_unlock(CRYPTO_LOCK_RAND);
666
667 rv = aep_get_connection(&hConnection);
668 if (rv != AEP_R_OK)
669 {
670 AEPHKerr(AEPHK_F_AEP_RAND,AEPHK_R_GET_HANDLE_FAILED);
671 goto err_nounlock;
672 }
673
674 if (len > RAND_BLK_SIZE)
675 {
676 rv = p_AEP_GenRandom(hConnection, len, 2, buf, NULL);
677 if (rv != AEP_R_OK)
678 {
679 AEPHKerr(AEPHK_F_AEP_RAND,AEPHK_R_GET_RANDOM_FAILED);
680 goto err_nounlock;
681 }
682 }
683 else
684 {
685 CRYPTO_w_lock(CRYPTO_LOCK_RAND);
686
687 rv = p_AEP_GenRandom(hConnection, RAND_BLK_SIZE, 2, &rand_block[0], NULL);
688 if (rv != AEP_R_OK)
689 {
690 AEPHKerr(AEPHK_F_AEP_RAND,AEPHK_R_GET_RANDOM_FAILED);
691
692 goto err;
693 }
694
695 rand_block_bytes = RAND_BLK_SIZE;
696
697 memcpy(buf, &rand_block[RAND_BLK_SIZE - rand_block_bytes], len);
698 rand_block_bytes -= len;
699
700 CRYPTO_w_unlock(CRYPTO_LOCK_RAND);
701 }
702
703 rv = aep_return_connection(hConnection);
704 if (rv != AEP_R_OK)
705 {
706 AEPHKerr(AEPHK_F_AEP_RAND,AEPHK_R_RETURN_CONNECTION_FAILED);
707
708 goto err_nounlock;
709 }
710 }
711
712 return 1;
713 err:
714 CRYPTO_w_unlock(CRYPTO_LOCK_RAND);
715 err_nounlock:
716 return 0;
717 }
718
719static int aep_rand_status(void)
720{
721 return 1;
722}
723#endif
724
725#ifndef OPENSSL_NO_RSA
726static int aep_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa)
727 {
728 BN_CTX *ctx = NULL;
729 int to_return = 0;
730 AEP_RV rv = AEP_R_OK;
731
732 if ((ctx = BN_CTX_new()) == NULL)
733 goto err;
734
735 if (!aep_dso)
736 {
737 AEPHKerr(AEPHK_F_AEP_RSA_MOD_EXP,AEPHK_R_NOT_LOADED);
738 goto err;
739 }
740
741 /*See if we have all the necessary bits for a crt*/
742 if (rsa->q && rsa->dmp1 && rsa->dmq1 && rsa->iqmp)
743 {
744 rv = aep_mod_exp_crt(r0,I,rsa->p,rsa->q, rsa->dmp1,rsa->dmq1,rsa->iqmp,ctx);
745
746 if (rv == FAIL_TO_SW){
747 const RSA_METHOD *meth = RSA_PKCS1_SSLeay();
748 to_return = (*meth->rsa_mod_exp)(r0, I, rsa);
749 goto err;
750 }
751 else if (rv != AEP_R_OK)
752 goto err;
753 }
754 else
755 {
756 if (!rsa->d || !rsa->n)
757 {
758 AEPHKerr(AEPHK_F_AEP_RSA_MOD_EXP,AEPHK_R_MISSING_KEY_COMPONENTS);
759 goto err;
760 }
761
762 rv = aep_mod_exp(r0,I,rsa->d,rsa->n,ctx);
763 if (rv != AEP_R_OK)
764 goto err;
765
766 }
767
768 to_return = 1;
769
770 err:
771 if(ctx)
772 BN_CTX_free(ctx);
773 return to_return;
774}
775#endif
776
777#ifndef OPENSSL_NO_DSA
778static int aep_dsa_mod_exp(DSA *dsa, BIGNUM *rr, BIGNUM *a1,
779 BIGNUM *p1, BIGNUM *a2, BIGNUM *p2, BIGNUM *m,
780 BN_CTX *ctx, BN_MONT_CTX *in_mont)
781 {
782 BIGNUM t;
783 int to_return = 0;
784 BN_init(&t);
785
786 /* let rr = a1 ^ p1 mod m */
787 if (!aep_mod_exp(rr,a1,p1,m,ctx)) goto end;
788 /* let t = a2 ^ p2 mod m */
789 if (!aep_mod_exp(&t,a2,p2,m,ctx)) goto end;
790 /* let rr = rr * t mod m */
791 if (!BN_mod_mul(rr,rr,&t,m,ctx)) goto end;
792 to_return = 1;
793 end:
794 BN_free(&t);
795 return to_return;
796 }
797
798static int aep_mod_exp_dsa(DSA *dsa, BIGNUM *r, BIGNUM *a,
799 const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx,
800 BN_MONT_CTX *m_ctx)
801 {
802 return aep_mod_exp(r, a, p, m, ctx);
803 }
804#endif
805
806/* This function is aliased to mod_exp (with the mont stuff dropped). */
807static int aep_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
808 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx)
809 {
810 return aep_mod_exp(r, a, p, m, ctx);
811 }
812
813#ifndef OPENSSL_NO_DH
814/* This function is aliased to mod_exp (with the dh and mont dropped). */
815static int aep_mod_exp_dh(const DH *dh, BIGNUM *r, const BIGNUM *a,
816 const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx,
817 BN_MONT_CTX *m_ctx)
818 {
819 return aep_mod_exp(r, a, p, m, ctx);
820 }
821#endif
822
823static AEP_RV aep_get_connection(AEP_CONNECTION_HNDL_PTR phConnection)
824 {
825 int count;
826 AEP_RV rv = AEP_R_OK;
827
828 /*Get the current process id*/
829 pid_t curr_pid;
830
831 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
832
833 curr_pid = getpid();
834
835 /*Check if this is the first time this is being called from the current
836 process*/
837 if (recorded_pid != curr_pid)
838 {
839 /*Remember our pid so we can check if we're in a new process*/
840 recorded_pid = curr_pid;
841
842 /*Call Finalize to make sure we have not inherited some data
843 from a parent process*/
844 p_AEP_Finalize();
845
846 /*Initialise the AEP API*/
847 rv = p_AEP_Initialize(NULL);
848
849 if (rv != AEP_R_OK)
850 {
851 AEPHKerr(AEPHK_F_AEP_GET_CONNECTION,AEPHK_R_INIT_FAILURE);
852 recorded_pid = 0;
853 goto end;
854 }
855
856 /*Set the AEP big num call back functions*/
857 rv = p_AEP_SetBNCallBacks(&GetBigNumSize, &MakeAEPBigNum,
858 &ConvertAEPBigNum);
859
860 if (rv != AEP_R_OK)
861 {
862 AEPHKerr(AEPHK_F_AEP_GET_CONNECTION,AEPHK_R_SETBNCALLBACK_FAILURE);
863 recorded_pid = 0;
864 goto end;
865 }
866
867#ifdef AEPRAND
868 /*Reset the rand byte count*/
869 rand_block_bytes = 0;
870#endif
871
872 /*Init the structures*/
873 for (count = 0;count < MAX_PROCESS_CONNECTIONS;count ++)
874 {
875 aep_app_conn_table[count].conn_state = NotConnected;
876 aep_app_conn_table[count].conn_hndl = 0;
877 }
878
879 /*Open a connection*/
880 rv = p_AEP_OpenConnection(phConnection);
881
882 if (rv != AEP_R_OK)
883 {
884 AEPHKerr(AEPHK_F_AEP_GET_CONNECTION,AEPHK_R_UNIT_FAILURE);
885 recorded_pid = 0;
886 goto end;
887 }
888
889 aep_app_conn_table[0].conn_state = InUse;
890 aep_app_conn_table[0].conn_hndl = *phConnection;
891 goto end;
892 }
893 /*Check the existing connections to see if we can find a free one*/
894 for (count = 0;count < MAX_PROCESS_CONNECTIONS;count ++)
895 {
896 if (aep_app_conn_table[count].conn_state == Connected)
897 {
898 aep_app_conn_table[count].conn_state = InUse;
899 *phConnection = aep_app_conn_table[count].conn_hndl;
900 goto end;
901 }
902 }
903 /*If no connections available, we're going to have to try
904 to open a new one*/
905 for (count = 0;count < MAX_PROCESS_CONNECTIONS;count ++)
906 {
907 if (aep_app_conn_table[count].conn_state == NotConnected)
908 {
909 /*Open a connection*/
910 rv = p_AEP_OpenConnection(phConnection);
911
912 if (rv != AEP_R_OK)
913 {
914 AEPHKerr(AEPHK_F_AEP_GET_CONNECTION,AEPHK_R_UNIT_FAILURE);
915 goto end;
916 }
917
918 aep_app_conn_table[count].conn_state = InUse;
919 aep_app_conn_table[count].conn_hndl = *phConnection;
920 goto end;
921 }
922 }
923 rv = AEP_R_GENERAL_ERROR;
924 end:
925 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
926 return rv;
927 }
928
929
930static AEP_RV aep_return_connection(AEP_CONNECTION_HNDL hConnection)
931 {
932 int count;
933
934 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
935
936 /*Find the connection item that matches this connection handle*/
937 for(count = 0;count < MAX_PROCESS_CONNECTIONS;count ++)
938 {
939 if (aep_app_conn_table[count].conn_hndl == hConnection)
940 {
941 aep_app_conn_table[count].conn_state = Connected;
942 break;
943 }
944 }
945
946 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
947
948 return AEP_R_OK;
949 }
950
951static AEP_RV aep_close_connection(AEP_CONNECTION_HNDL hConnection)
952 {
953 int count;
954 AEP_RV rv = AEP_R_OK;
955
956 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
957
958 /*Find the connection item that matches this connection handle*/
959 for(count = 0;count < MAX_PROCESS_CONNECTIONS;count ++)
960 {
961 if (aep_app_conn_table[count].conn_hndl == hConnection)
962 {
963 rv = p_AEP_CloseConnection(aep_app_conn_table[count].conn_hndl);
964 if (rv != AEP_R_OK)
965 goto end;
966 aep_app_conn_table[count].conn_state = NotConnected;
967 aep_app_conn_table[count].conn_hndl = 0;
968 break;
969 }
970 }
971
972 end:
973 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
974 return rv;
975 }
976
977static AEP_RV aep_close_all_connections(int use_engine_lock, int *in_use)
978 {
979 int count;
980 AEP_RV rv = AEP_R_OK;
981
982 *in_use = 0;
983 if (use_engine_lock) CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
984 for (count = 0;count < MAX_PROCESS_CONNECTIONS;count ++)
985 {
986 switch (aep_app_conn_table[count].conn_state)
987 {
988 case Connected:
989 rv = p_AEP_CloseConnection(aep_app_conn_table[count].conn_hndl);
990 if (rv != AEP_R_OK)
991 goto end;
992 aep_app_conn_table[count].conn_state = NotConnected;
993 aep_app_conn_table[count].conn_hndl = 0;
994 break;
995 case InUse:
996 (*in_use)++;
997 break;
998 case NotConnected:
999 break;
1000 }
1001 }
1002 end:
1003 if (use_engine_lock) CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
1004 return rv;
1005 }
1006
1007/*BigNum call back functions, used to convert OpenSSL bignums into AEP bignums.
1008 Note only 32bit Openssl build support*/
1009
1010static AEP_RV GetBigNumSize(AEP_VOID_PTR ArbBigNum, AEP_U32* BigNumSize)
1011 {
1012 BIGNUM* bn;
1013
1014 /*Cast the ArbBigNum pointer to our BIGNUM struct*/
1015 bn = (BIGNUM*) ArbBigNum;
1016
1017#ifdef SIXTY_FOUR_BIT_LONG
1018 *BigNumSize = bn->top << 3;
1019#else
1020 /*Size of the bignum in bytes is equal to the bn->top (no of 32 bit
1021 words) multiplies by 4*/
1022 *BigNumSize = bn->top << 2;
1023#endif
1024
1025 return AEP_R_OK;
1026 }
1027
1028static AEP_RV MakeAEPBigNum(AEP_VOID_PTR ArbBigNum, AEP_U32 BigNumSize,
1029 unsigned char* AEP_BigNum)
1030 {
1031 BIGNUM* bn;
1032
1033#ifndef SIXTY_FOUR_BIT_LONG
1034 unsigned char* buf;
1035 int i;
1036#endif
1037
1038 /*Cast the ArbBigNum pointer to our BIGNUM struct*/
1039 bn = (BIGNUM*) ArbBigNum;
1040
1041#ifdef SIXTY_FOUR_BIT_LONG
1042 memcpy(AEP_BigNum, bn->d, BigNumSize);
1043#else
1044 /*Must copy data into a (monotone) least significant byte first format
1045 performing endian conversion if necessary*/
1046 for(i=0;i<bn->top;i++)
1047 {
1048 buf = (unsigned char*)&bn->d[i];
1049
1050 *((AEP_U32*)AEP_BigNum) = (AEP_U32)
1051 ((unsigned) buf[1] << 8 | buf[0]) |
1052 ((unsigned) buf[3] << 8 | buf[2]) << 16;
1053
1054 AEP_BigNum += 4;
1055 }
1056#endif
1057
1058 return AEP_R_OK;
1059 }
1060
1061/*Turn an AEP Big Num back to a user big num*/
1062static AEP_RV ConvertAEPBigNum(void* ArbBigNum, AEP_U32 BigNumSize,
1063 unsigned char* AEP_BigNum)
1064 {
1065 BIGNUM* bn;
1066#ifndef SIXTY_FOUR_BIT_LONG
1067 int i;
1068#endif
1069
1070 bn = (BIGNUM*)ArbBigNum;
1071
1072 /*Expand the result bn so that it can hold our big num.
1073 Size is in bits*/
1074 bn_expand(bn, (int)(BigNumSize << 3));
1075
1076#ifdef SIXTY_FOUR_BIT_LONG
1077 bn->top = BigNumSize >> 3;
1078
1079 if((BigNumSize & 7) != 0)
1080 bn->top++;
1081
1082 memset(bn->d, 0, bn->top << 3);
1083
1084 memcpy(bn->d, AEP_BigNum, BigNumSize);
1085#else
1086 bn->top = BigNumSize >> 2;
1087
1088 for(i=0;i<bn->top;i++)
1089 {
1090 bn->d[i] = (AEP_U32)
1091 ((unsigned) AEP_BigNum[3] << 8 | AEP_BigNum[2]) << 16 |
1092 ((unsigned) AEP_BigNum[1] << 8 | AEP_BigNum[0]);
1093 AEP_BigNum += 4;
1094 }
1095#endif
1096
1097 return AEP_R_OK;
1098}
1099
1100#endif /* !OPENSSL_NO_HW_AEP */
1101#endif /* !OPENSSL_NO_HW */
diff --git a/src/lib/libcrypto/engine/hw_aep_err.c b/src/lib/libcrypto/engine/hw_aep_err.c
new file mode 100644
index 0000000000..092f532946
--- /dev/null
+++ b/src/lib/libcrypto/engine/hw_aep_err.c
@@ -0,0 +1,157 @@
1/* hw_aep_err.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file,
58 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include "hw_aep_err.h"
64
65/* BEGIN ERROR CODES */
66#ifndef OPENSSL_NO_ERR
67static ERR_STRING_DATA AEPHK_str_functs[]=
68 {
69{ERR_PACK(0,AEPHK_F_AEP_CTRL,0), "AEP_CTRL"},
70{ERR_PACK(0,AEPHK_F_AEP_FINISH,0), "AEP_FINISH"},
71{ERR_PACK(0,AEPHK_F_AEP_GET_CONNECTION,0), "AEP_GET_CONNECTION"},
72{ERR_PACK(0,AEPHK_F_AEP_INIT,0), "AEP_INIT"},
73{ERR_PACK(0,AEPHK_F_AEP_MOD_EXP,0), "AEP_MOD_EXP"},
74{ERR_PACK(0,AEPHK_F_AEP_MOD_EXP_CRT,0), "AEP_MOD_EXP_CRT"},
75{ERR_PACK(0,AEPHK_F_AEP_RAND,0), "AEP_RAND"},
76{ERR_PACK(0,AEPHK_F_AEP_RSA_MOD_EXP,0), "AEP_RSA_MOD_EXP"},
77{0,NULL}
78 };
79
80static ERR_STRING_DATA AEPHK_str_reasons[]=
81 {
82{AEPHK_R_ALREADY_LOADED ,"already loaded"},
83{AEPHK_R_CLOSE_HANDLES_FAILED ,"close handles failed"},
84{AEPHK_R_CONNECTIONS_IN_USE ,"connections in use"},
85{AEPHK_R_CTRL_COMMAND_NOT_IMPLEMENTED ,"ctrl command not implemented"},
86{AEPHK_R_FINALIZE_FAILED ,"finalize failed"},
87{AEPHK_R_GET_HANDLE_FAILED ,"get handle failed"},
88{AEPHK_R_GET_RANDOM_FAILED ,"get random failed"},
89{AEPHK_R_INIT_FAILURE ,"init failure"},
90{AEPHK_R_MISSING_KEY_COMPONENTS ,"missing key components"},
91{AEPHK_R_MOD_EXP_CRT_FAILED ,"mod exp crt failed"},
92{AEPHK_R_MOD_EXP_FAILED ,"mod exp failed"},
93{AEPHK_R_NOT_LOADED ,"not loaded"},
94{AEPHK_R_OK ,"ok"},
95{AEPHK_R_RETURN_CONNECTION_FAILED ,"return connection failed"},
96{AEPHK_R_SETBNCALLBACK_FAILURE ,"setbncallback failure"},
97{AEPHK_R_SIZE_TOO_LARGE_OR_TOO_SMALL ,"size too large or too small"},
98{AEPHK_R_UNIT_FAILURE ,"unit failure"},
99{0,NULL}
100 };
101
102#endif
103
104#ifdef AEPHK_LIB_NAME
105static ERR_STRING_DATA AEPHK_lib_name[]=
106 {
107{0 ,AEPHK_LIB_NAME},
108{0,NULL}
109 };
110#endif
111
112
113static int AEPHK_lib_error_code=0;
114static int AEPHK_error_init=1;
115
116static void ERR_load_AEPHK_strings(void)
117 {
118 if (AEPHK_lib_error_code == 0)
119 AEPHK_lib_error_code=ERR_get_next_error_library();
120
121 if (AEPHK_error_init)
122 {
123 AEPHK_error_init=0;
124#ifndef OPENSSL_NO_ERR
125 ERR_load_strings(AEPHK_lib_error_code,AEPHK_str_functs);
126 ERR_load_strings(AEPHK_lib_error_code,AEPHK_str_reasons);
127#endif
128
129#ifdef AEPHK_LIB_NAME
130 AEPHK_lib_name->error = ERR_PACK(AEPHK_lib_error_code,0,0);
131 ERR_load_strings(0,AEPHK_lib_name);
132#endif
133 }
134 }
135
136static void ERR_unload_AEPHK_strings(void)
137 {
138 if (AEPHK_error_init == 0)
139 {
140#ifndef OPENSSL_NO_ERR
141 ERR_unload_strings(AEPHK_lib_error_code,AEPHK_str_functs);
142 ERR_unload_strings(AEPHK_lib_error_code,AEPHK_str_reasons);
143#endif
144
145#ifdef AEPHK_LIB_NAME
146 ERR_unload_strings(0,AEPHK_lib_name);
147#endif
148 AEPHK_error_init=1;
149 }
150 }
151
152static void ERR_AEPHK_error(int function, int reason, char *file, int line)
153 {
154 if (AEPHK_lib_error_code == 0)
155 AEPHK_lib_error_code=ERR_get_next_error_library();
156 ERR_PUT_error(AEPHK_lib_error_code,function,reason,file,line);
157 }
diff --git a/src/lib/libcrypto/engine/hw_aep_err.h b/src/lib/libcrypto/engine/hw_aep_err.h
new file mode 100644
index 0000000000..8fe4cf921f
--- /dev/null
+++ b/src/lib/libcrypto/engine/hw_aep_err.h
@@ -0,0 +1,101 @@
1/* ====================================================================
2 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * 3. All advertising materials mentioning features or use of this
17 * software must display the following acknowledgment:
18 * "This product includes software developed by the OpenSSL Project
19 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
20 *
21 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission. For written permission, please contact
24 * openssl-core@openssl.org.
25 *
26 * 5. Products derived from this software may not be called "OpenSSL"
27 * nor may "OpenSSL" appear in their names without prior written
28 * permission of the OpenSSL Project.
29 *
30 * 6. Redistributions of any form whatsoever must retain the following
31 * acknowledgment:
32 * "This product includes software developed by the OpenSSL Project
33 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46 * OF THE POSSIBILITY OF SUCH DAMAGE.
47 * ====================================================================
48 *
49 * This product includes cryptographic software written by Eric Young
50 * (eay@cryptsoft.com). This product includes software written by Tim
51 * Hudson (tjh@cryptsoft.com).
52 *
53 */
54
55#ifndef HEADER_AEPHK_ERR_H
56#define HEADER_AEPHK_ERR_H
57
58/* BEGIN ERROR CODES */
59/* The following lines are auto generated by the script mkerr.pl. Any changes
60 * made after this point may be overwritten when the script is next run.
61 */
62static void ERR_load_AEPHK_strings(void);
63static void ERR_unload_AEPHK_strings(void);
64static void ERR_AEPHK_error(int function, int reason, char *file, int line);
65#define AEPHKerr(f,r) ERR_AEPHK_error((f),(r),__FILE__,__LINE__)
66
67/* Error codes for the AEPHK functions. */
68
69/* Function codes. */
70#define AEPHK_F_AEP_CTRL 100
71#define AEPHK_F_AEP_FINISH 101
72#define AEPHK_F_AEP_GET_CONNECTION 102
73#define AEPHK_F_AEP_INIT 103
74#define AEPHK_F_AEP_MOD_EXP 104
75#define AEPHK_F_AEP_MOD_EXP_CRT 105
76#define AEPHK_F_AEP_RAND 106
77#define AEPHK_F_AEP_RSA_MOD_EXP 107
78
79/* Reason codes. */
80#define AEPHK_R_ALREADY_LOADED 100
81#define AEPHK_R_CLOSE_HANDLES_FAILED 101
82#define AEPHK_R_CONNECTIONS_IN_USE 102
83#define AEPHK_R_CTRL_COMMAND_NOT_IMPLEMENTED 103
84#define AEPHK_R_FINALIZE_FAILED 104
85#define AEPHK_R_GET_HANDLE_FAILED 105
86#define AEPHK_R_GET_RANDOM_FAILED 106
87#define AEPHK_R_INIT_FAILURE 107
88#define AEPHK_R_MISSING_KEY_COMPONENTS 108
89#define AEPHK_R_MOD_EXP_CRT_FAILED 109
90#define AEPHK_R_MOD_EXP_FAILED 110
91#define AEPHK_R_NOT_LOADED 111
92#define AEPHK_R_OK 112
93#define AEPHK_R_RETURN_CONNECTION_FAILED 113
94#define AEPHK_R_SETBNCALLBACK_FAILURE 114
95#define AEPHK_R_SIZE_TOO_LARGE_OR_TOO_SMALL 116
96#define AEPHK_R_UNIT_FAILURE 115
97
98#ifdef __cplusplus
99}
100#endif
101#endif
diff --git a/src/lib/libcrypto/engine/hw_atalla.c b/src/lib/libcrypto/engine/hw_atalla.c
new file mode 100644
index 0000000000..3bb992a193
--- /dev/null
+++ b/src/lib/libcrypto/engine/hw_atalla.c
@@ -0,0 +1,444 @@
1/* crypto/engine/hw_atalla.c */
2/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 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 * licensing@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 <stdio.h>
60#include <openssl/crypto.h>
61#include "cryptlib.h"
62#include <openssl/dso.h>
63#include "engine_int.h"
64#include <openssl/engine.h>
65
66#ifndef NO_HW
67#ifndef NO_HW_ATALLA
68
69#ifdef FLAT_INC
70#include "atalla.h"
71#else
72#include "vendor_defns/atalla.h"
73#endif
74
75static int atalla_init(void);
76static int atalla_finish(void);
77
78/* BIGNUM stuff */
79static int atalla_mod_exp(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
80 const BIGNUM *m, BN_CTX *ctx);
81
82/* RSA stuff */
83static int atalla_rsa_mod_exp(BIGNUM *r0, BIGNUM *I, RSA *rsa);
84/* This function is aliased to mod_exp (with the mont stuff dropped). */
85static int atalla_mod_exp_mont(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
86 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
87
88/* DSA stuff */
89static int atalla_dsa_mod_exp(DSA *dsa, BIGNUM *rr, BIGNUM *a1,
90 BIGNUM *p1, BIGNUM *a2, BIGNUM *p2, BIGNUM *m,
91 BN_CTX *ctx, BN_MONT_CTX *in_mont);
92static int atalla_mod_exp_dsa(DSA *dsa, BIGNUM *r, BIGNUM *a,
93 const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx,
94 BN_MONT_CTX *m_ctx);
95
96/* DH stuff */
97/* This function is alised to mod_exp (with the DH and mont dropped). */
98static int atalla_mod_exp_dh(DH *dh, BIGNUM *r, BIGNUM *a, const BIGNUM *p,
99 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
100
101
102/* Our internal RSA_METHOD that we provide pointers to */
103static RSA_METHOD atalla_rsa =
104 {
105 "Atalla RSA method",
106 NULL,
107 NULL,
108 NULL,
109 NULL,
110 atalla_rsa_mod_exp,
111 atalla_mod_exp_mont,
112 NULL,
113 NULL,
114 0,
115 NULL,
116 NULL,
117 NULL
118 };
119
120/* Our internal DSA_METHOD that we provide pointers to */
121static DSA_METHOD atalla_dsa =
122 {
123 "Atalla DSA method",
124 NULL, /* dsa_do_sign */
125 NULL, /* dsa_sign_setup */
126 NULL, /* dsa_do_verify */
127 atalla_dsa_mod_exp, /* dsa_mod_exp */
128 atalla_mod_exp_dsa, /* bn_mod_exp */
129 NULL, /* init */
130 NULL, /* finish */
131 0, /* flags */
132 NULL /* app_data */
133 };
134
135/* Our internal DH_METHOD that we provide pointers to */
136static DH_METHOD atalla_dh =
137 {
138 "Atalla DH method",
139 NULL,
140 NULL,
141 atalla_mod_exp_dh,
142 NULL,
143 NULL,
144 0,
145 NULL
146 };
147
148/* Our ENGINE structure. */
149static ENGINE engine_atalla =
150 {
151 "atalla",
152 "Atalla hardware engine support",
153 &atalla_rsa,
154 &atalla_dsa,
155 &atalla_dh,
156 NULL,
157 atalla_mod_exp,
158 NULL,
159 atalla_init,
160 atalla_finish,
161 NULL, /* no ctrl() */
162 NULL, /* no load_privkey() */
163 NULL, /* no load_pubkey() */
164 0, /* no flags */
165 0, 0, /* no references */
166 NULL, NULL /* unlinked */
167 };
168
169/* As this is only ever called once, there's no need for locking
170 * (indeed - the lock will already be held by our caller!!!) */
171ENGINE *ENGINE_atalla()
172 {
173 RSA_METHOD *meth1;
174 DSA_METHOD *meth2;
175 DH_METHOD *meth3;
176
177 /* We know that the "PKCS1_SSLeay()" functions hook properly
178 * to the atalla-specific mod_exp and mod_exp_crt so we use
179 * those functions. NB: We don't use ENGINE_openssl() or
180 * anything "more generic" because something like the RSAref
181 * code may not hook properly, and if you own one of these
182 * cards then you have the right to do RSA operations on it
183 * anyway! */
184 meth1 = RSA_PKCS1_SSLeay();
185 atalla_rsa.rsa_pub_enc = meth1->rsa_pub_enc;
186 atalla_rsa.rsa_pub_dec = meth1->rsa_pub_dec;
187 atalla_rsa.rsa_priv_enc = meth1->rsa_priv_enc;
188 atalla_rsa.rsa_priv_dec = meth1->rsa_priv_dec;
189
190 /* Use the DSA_OpenSSL() method and just hook the mod_exp-ish
191 * bits. */
192 meth2 = DSA_OpenSSL();
193 atalla_dsa.dsa_do_sign = meth2->dsa_do_sign;
194 atalla_dsa.dsa_sign_setup = meth2->dsa_sign_setup;
195 atalla_dsa.dsa_do_verify = meth2->dsa_do_verify;
196
197 /* Much the same for Diffie-Hellman */
198 meth3 = DH_OpenSSL();
199 atalla_dh.generate_key = meth3->generate_key;
200 atalla_dh.compute_key = meth3->compute_key;
201 return &engine_atalla;
202 }
203
204/* This is a process-global DSO handle used for loading and unloading
205 * the Atalla library. NB: This is only set (or unset) during an
206 * init() or finish() call (reference counts permitting) and they're
207 * operating with global locks, so this should be thread-safe
208 * implicitly. */
209static DSO *atalla_dso = NULL;
210
211/* These are the function pointers that are (un)set when the library has
212 * successfully (un)loaded. */
213static tfnASI_GetHardwareConfig *p_Atalla_GetHardwareConfig = NULL;
214static tfnASI_RSAPrivateKeyOpFn *p_Atalla_RSAPrivateKeyOpFn = NULL;
215static tfnASI_GetPerformanceStatistics *p_Atalla_GetPerformanceStatistics = NULL;
216
217/* (de)initialisation functions. */
218static int atalla_init()
219 {
220 tfnASI_GetHardwareConfig *p1;
221 tfnASI_RSAPrivateKeyOpFn *p2;
222 tfnASI_GetPerformanceStatistics *p3;
223 /* Not sure of the origin of this magic value, but Ben's code had it
224 * and it seemed to have been working for a few people. :-) */
225 unsigned int config_buf[1024];
226
227 if(atalla_dso != NULL)
228 {
229 ENGINEerr(ENGINE_F_ATALLA_INIT,ENGINE_R_ALREADY_LOADED);
230 goto err;
231 }
232 /* Attempt to load libatasi.so/atasi.dll/whatever. Needs to be
233 * changed unfortunately because the Atalla drivers don't have
234 * standard library names that can be platform-translated well. */
235 /* TODO: Work out how to actually map to the names the Atalla
236 * drivers really use - for now a symbollic link needs to be
237 * created on the host system from libatasi.so to atasi.so on
238 * unix variants. */
239 atalla_dso = DSO_load(NULL, ATALLA_LIBNAME, NULL,
240 DSO_FLAG_NAME_TRANSLATION);
241 if(atalla_dso == NULL)
242 {
243 ENGINEerr(ENGINE_F_ATALLA_INIT,ENGINE_R_DSO_FAILURE);
244 goto err;
245 }
246 if(!(p1 = (tfnASI_GetHardwareConfig *)DSO_bind_func(
247 atalla_dso, ATALLA_F1)) ||
248 !(p2 = (tfnASI_RSAPrivateKeyOpFn *)DSO_bind_func(
249 atalla_dso, ATALLA_F2)) ||
250 !(p3 = (tfnASI_GetPerformanceStatistics *)DSO_bind_func(
251 atalla_dso, ATALLA_F3)))
252 {
253 ENGINEerr(ENGINE_F_ATALLA_INIT,ENGINE_R_DSO_FAILURE);
254 goto err;
255 }
256 /* Copy the pointers */
257 p_Atalla_GetHardwareConfig = p1;
258 p_Atalla_RSAPrivateKeyOpFn = p2;
259 p_Atalla_GetPerformanceStatistics = p3;
260 /* Perform a basic test to see if there's actually any unit
261 * running. */
262 if(p1(0L, config_buf) != 0)
263 {
264 ENGINEerr(ENGINE_F_ATALLA_INIT,ENGINE_R_UNIT_FAILURE);
265 goto err;
266 }
267 /* Everything's fine. */
268 return 1;
269err:
270 if(atalla_dso)
271 DSO_free(atalla_dso);
272 p_Atalla_GetHardwareConfig = NULL;
273 p_Atalla_RSAPrivateKeyOpFn = NULL;
274 p_Atalla_GetPerformanceStatistics = NULL;
275 return 0;
276 }
277
278static int atalla_finish()
279 {
280 if(atalla_dso == NULL)
281 {
282 ENGINEerr(ENGINE_F_ATALLA_FINISH,ENGINE_R_NOT_LOADED);
283 return 0;
284 }
285 if(!DSO_free(atalla_dso))
286 {
287 ENGINEerr(ENGINE_F_ATALLA_FINISH,ENGINE_R_DSO_FAILURE);
288 return 0;
289 }
290 atalla_dso = NULL;
291 p_Atalla_GetHardwareConfig = NULL;
292 p_Atalla_RSAPrivateKeyOpFn = NULL;
293 p_Atalla_GetPerformanceStatistics = NULL;
294 return 1;
295 }
296
297static int atalla_mod_exp(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
298 const BIGNUM *m, BN_CTX *ctx)
299 {
300 /* I need somewhere to store temporary serialised values for
301 * use with the Atalla API calls. A neat cheat - I'll use
302 * BIGNUMs from the BN_CTX but access their arrays directly as
303 * byte arrays <grin>. This way I don't have to clean anything
304 * up. */
305 BIGNUM *modulus;
306 BIGNUM *exponent;
307 BIGNUM *argument;
308 BIGNUM *result;
309 RSAPrivateKey keydata;
310 int to_return, numbytes;
311
312 modulus = exponent = argument = result = NULL;
313 to_return = 0; /* expect failure */
314
315 if(!atalla_dso)
316 {
317 ENGINEerr(ENGINE_F_ATALLA_MOD_EXP,ENGINE_R_NOT_LOADED);
318 goto err;
319 }
320 /* Prepare the params */
321 modulus = BN_CTX_get(ctx);
322 exponent = BN_CTX_get(ctx);
323 argument = BN_CTX_get(ctx);
324 result = BN_CTX_get(ctx);
325 if(!modulus || !exponent || !argument || !result)
326 {
327 ENGINEerr(ENGINE_F_ATALLA_MOD_EXP,ENGINE_R_BN_CTX_FULL);
328 goto err;
329 }
330 if(!bn_wexpand(modulus, m->top) || !bn_wexpand(exponent, m->top) ||
331 !bn_wexpand(argument, m->top) || !bn_wexpand(result, m->top))
332 {
333 ENGINEerr(ENGINE_F_ATALLA_MOD_EXP,ENGINE_R_BN_EXPAND_FAIL);
334 goto err;
335 }
336 /* Prepare the key-data */
337 memset(&keydata, 0,sizeof keydata);
338 numbytes = BN_num_bytes(m);
339 memset(exponent->d, 0, numbytes);
340 memset(modulus->d, 0, numbytes);
341 BN_bn2bin(p, (unsigned char *)exponent->d + numbytes - BN_num_bytes(p));
342 BN_bn2bin(m, (unsigned char *)modulus->d + numbytes - BN_num_bytes(m));
343 keydata.privateExponent.data = (unsigned char *)exponent->d;
344 keydata.privateExponent.len = numbytes;
345 keydata.modulus.data = (unsigned char *)modulus->d;
346 keydata.modulus.len = numbytes;
347 /* Prepare the argument */
348 memset(argument->d, 0, numbytes);
349 memset(result->d, 0, numbytes);
350 BN_bn2bin(a, (unsigned char *)argument->d + numbytes - BN_num_bytes(a));
351 /* Perform the operation */
352 if(p_Atalla_RSAPrivateKeyOpFn(&keydata, (unsigned char *)result->d,
353 (unsigned char *)argument->d,
354 keydata.modulus.len) != 0)
355 {
356 ENGINEerr(ENGINE_F_ATALLA_MOD_EXP,ENGINE_R_REQUEST_FAILED);
357 goto err;
358 }
359 /* Convert the response */
360 BN_bin2bn((unsigned char *)result->d, numbytes, r);
361 to_return = 1;
362err:
363 if(modulus) ctx->tos--;
364 if(exponent) ctx->tos--;
365 if(argument) ctx->tos--;
366 if(result) ctx->tos--;
367 return to_return;
368 }
369
370static int atalla_rsa_mod_exp(BIGNUM *r0, BIGNUM *I, RSA *rsa)
371 {
372 BN_CTX *ctx = NULL;
373 int to_return = 0;
374
375 if(!atalla_dso)
376 {
377 ENGINEerr(ENGINE_F_ATALLA_RSA_MOD_EXP,ENGINE_R_NOT_LOADED);
378 goto err;
379 }
380 if((ctx = BN_CTX_new()) == NULL)
381 goto err;
382 if(!rsa->d || !rsa->n)
383 {
384 ENGINEerr(ENGINE_F_ATALLA_RSA_MOD_EXP,ENGINE_R_MISSING_KEY_COMPONENTS);
385 goto err;
386 }
387 to_return = atalla_mod_exp(r0, I, rsa->d, rsa->n, ctx);
388err:
389 if(ctx)
390 BN_CTX_free(ctx);
391 return to_return;
392 }
393
394/* This code was liberated and adapted from the commented-out code in
395 * dsa_ossl.c. Because of the unoptimised form of the Atalla acceleration
396 * (it doesn't have a CRT form for RSA), this function means that an
397 * Atalla system running with a DSA server certificate can handshake
398 * around 5 or 6 times faster/more than an equivalent system running with
399 * RSA. Just check out the "signs" statistics from the RSA and DSA parts
400 * of "openssl speed -engine atalla dsa1024 rsa1024". */
401static int atalla_dsa_mod_exp(DSA *dsa, BIGNUM *rr, BIGNUM *a1,
402 BIGNUM *p1, BIGNUM *a2, BIGNUM *p2, BIGNUM *m,
403 BN_CTX *ctx, BN_MONT_CTX *in_mont)
404 {
405 BIGNUM t;
406 int to_return = 0;
407
408 BN_init(&t);
409 /* let rr = a1 ^ p1 mod m */
410 if (!atalla_mod_exp(rr,a1,p1,m,ctx)) goto end;
411 /* let t = a2 ^ p2 mod m */
412 if (!atalla_mod_exp(&t,a2,p2,m,ctx)) goto end;
413 /* let rr = rr * t mod m */
414 if (!BN_mod_mul(rr,rr,&t,m,ctx)) goto end;
415 to_return = 1;
416end:
417 BN_free(&t);
418 return to_return;
419 }
420
421
422static int atalla_mod_exp_dsa(DSA *dsa, BIGNUM *r, BIGNUM *a,
423 const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx,
424 BN_MONT_CTX *m_ctx)
425 {
426 return atalla_mod_exp(r, a, p, m, ctx);
427 }
428
429/* This function is aliased to mod_exp (with the mont stuff dropped). */
430static int atalla_mod_exp_mont(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
431 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx)
432 {
433 return atalla_mod_exp(r, a, p, m, ctx);
434 }
435
436/* This function is aliased to mod_exp (with the dh and mont dropped). */
437static int atalla_mod_exp_dh(DH *dh, BIGNUM *r, BIGNUM *a, const BIGNUM *p,
438 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx)
439 {
440 return atalla_mod_exp(r, a, p, m, ctx);
441 }
442
443#endif /* !NO_HW_ATALLA */
444#endif /* !NO_HW */
diff --git a/src/lib/libcrypto/engine/hw_atalla_err.c b/src/lib/libcrypto/engine/hw_atalla_err.c
new file mode 100644
index 0000000000..1df9c4570c
--- /dev/null
+++ b/src/lib/libcrypto/engine/hw_atalla_err.c
@@ -0,0 +1,145 @@
1/* hw_atalla_err.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file,
58 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include "hw_atalla_err.h"
64
65/* BEGIN ERROR CODES */
66#ifndef OPENSSL_NO_ERR
67static ERR_STRING_DATA ATALLA_str_functs[]=
68 {
69{ERR_PACK(0,ATALLA_F_ATALLA_CTRL,0), "ATALLA_CTRL"},
70{ERR_PACK(0,ATALLA_F_ATALLA_FINISH,0), "ATALLA_FINISH"},
71{ERR_PACK(0,ATALLA_F_ATALLA_INIT,0), "ATALLA_INIT"},
72{ERR_PACK(0,ATALLA_F_ATALLA_MOD_EXP,0), "ATALLA_MOD_EXP"},
73{ERR_PACK(0,ATALLA_F_ATALLA_RSA_MOD_EXP,0), "ATALLA_RSA_MOD_EXP"},
74{0,NULL}
75 };
76
77static ERR_STRING_DATA ATALLA_str_reasons[]=
78 {
79{ATALLA_R_ALREADY_LOADED ,"already loaded"},
80{ATALLA_R_BN_CTX_FULL ,"bn ctx full"},
81{ATALLA_R_BN_EXPAND_FAIL ,"bn expand fail"},
82{ATALLA_R_CTRL_COMMAND_NOT_IMPLEMENTED ,"ctrl command not implemented"},
83{ATALLA_R_MISSING_KEY_COMPONENTS ,"missing key components"},
84{ATALLA_R_NOT_LOADED ,"not loaded"},
85{ATALLA_R_REQUEST_FAILED ,"request failed"},
86{ATALLA_R_UNIT_FAILURE ,"unit failure"},
87{0,NULL}
88 };
89
90#endif
91
92#ifdef ATALLA_LIB_NAME
93static ERR_STRING_DATA ATALLA_lib_name[]=
94 {
95{0 ,ATALLA_LIB_NAME},
96{0,NULL}
97 };
98#endif
99
100
101static int ATALLA_lib_error_code=0;
102static int ATALLA_error_init=1;
103
104static void ERR_load_ATALLA_strings(void)
105 {
106 if (ATALLA_lib_error_code == 0)
107 ATALLA_lib_error_code=ERR_get_next_error_library();
108
109 if (ATALLA_error_init)
110 {
111 ATALLA_error_init=0;
112#ifndef OPENSSL_NO_ERR
113 ERR_load_strings(ATALLA_lib_error_code,ATALLA_str_functs);
114 ERR_load_strings(ATALLA_lib_error_code,ATALLA_str_reasons);
115#endif
116
117#ifdef ATALLA_LIB_NAME
118 ATALLA_lib_name->error = ERR_PACK(ATALLA_lib_error_code,0,0);
119 ERR_load_strings(0,ATALLA_lib_name);
120#endif
121 }
122 }
123
124static void ERR_unload_ATALLA_strings(void)
125 {
126 if (ATALLA_error_init == 0)
127 {
128#ifndef OPENSSL_NO_ERR
129 ERR_unload_strings(ATALLA_lib_error_code,ATALLA_str_functs);
130 ERR_unload_strings(ATALLA_lib_error_code,ATALLA_str_reasons);
131#endif
132
133#ifdef ATALLA_LIB_NAME
134 ERR_unload_strings(0,ATALLA_lib_name);
135#endif
136 ATALLA_error_init=1;
137 }
138 }
139
140static void ERR_ATALLA_error(int function, int reason, char *file, int line)
141 {
142 if (ATALLA_lib_error_code == 0)
143 ATALLA_lib_error_code=ERR_get_next_error_library();
144 ERR_PUT_error(ATALLA_lib_error_code,function,reason,file,line);
145 }
diff --git a/src/lib/libcrypto/engine/hw_atalla_err.h b/src/lib/libcrypto/engine/hw_atalla_err.h
new file mode 100644
index 0000000000..cdac052d8c
--- /dev/null
+++ b/src/lib/libcrypto/engine/hw_atalla_err.h
@@ -0,0 +1,89 @@
1/* ====================================================================
2 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * 3. All advertising materials mentioning features or use of this
17 * software must display the following acknowledgment:
18 * "This product includes software developed by the OpenSSL Project
19 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
20 *
21 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission. For written permission, please contact
24 * openssl-core@openssl.org.
25 *
26 * 5. Products derived from this software may not be called "OpenSSL"
27 * nor may "OpenSSL" appear in their names without prior written
28 * permission of the OpenSSL Project.
29 *
30 * 6. Redistributions of any form whatsoever must retain the following
31 * acknowledgment:
32 * "This product includes software developed by the OpenSSL Project
33 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46 * OF THE POSSIBILITY OF SUCH DAMAGE.
47 * ====================================================================
48 *
49 * This product includes cryptographic software written by Eric Young
50 * (eay@cryptsoft.com). This product includes software written by Tim
51 * Hudson (tjh@cryptsoft.com).
52 *
53 */
54
55#ifndef HEADER_ATALLA_ERR_H
56#define HEADER_ATALLA_ERR_H
57
58/* BEGIN ERROR CODES */
59/* The following lines are auto generated by the script mkerr.pl. Any changes
60 * made after this point may be overwritten when the script is next run.
61 */
62static void ERR_load_ATALLA_strings(void);
63static void ERR_unload_ATALLA_strings(void);
64static void ERR_ATALLA_error(int function, int reason, char *file, int line);
65#define ATALLAerr(f,r) ERR_ATALLA_error((f),(r),__FILE__,__LINE__)
66
67/* Error codes for the ATALLA functions. */
68
69/* Function codes. */
70#define ATALLA_F_ATALLA_CTRL 100
71#define ATALLA_F_ATALLA_FINISH 101
72#define ATALLA_F_ATALLA_INIT 102
73#define ATALLA_F_ATALLA_MOD_EXP 103
74#define ATALLA_F_ATALLA_RSA_MOD_EXP 104
75
76/* Reason codes. */
77#define ATALLA_R_ALREADY_LOADED 100
78#define ATALLA_R_BN_CTX_FULL 101
79#define ATALLA_R_BN_EXPAND_FAIL 102
80#define ATALLA_R_CTRL_COMMAND_NOT_IMPLEMENTED 103
81#define ATALLA_R_MISSING_KEY_COMPONENTS 104
82#define ATALLA_R_NOT_LOADED 105
83#define ATALLA_R_REQUEST_FAILED 106
84#define ATALLA_R_UNIT_FAILURE 107
85
86#ifdef __cplusplus
87}
88#endif
89#endif
diff --git a/src/lib/libcrypto/engine/hw_cryptodev.c b/src/lib/libcrypto/engine/hw_cryptodev.c
new file mode 100644
index 0000000000..7c3728f395
--- /dev/null
+++ b/src/lib/libcrypto/engine/hw_cryptodev.c
@@ -0,0 +1,926 @@
1/*
2 * Copyright (c) 2002 Bob Beck <beck@openbsd.org>
3 * Copyright (c) 2002 Theo de Raadt
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. Neither the name of the author nor the names of contributors
15 * may be used to endorse or promote products derived from this software
16 * without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY
19 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY
22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 *
29 */
30
31#include <sys/types.h>
32#include <sys/param.h>
33#include <crypto/cryptodev.h>
34#include <sys/ioctl.h>
35#include <errno.h>
36#include <stdio.h>
37#include <unistd.h>
38#include <fcntl.h>
39#include <syslog.h>
40#include <stdarg.h>
41#include <ssl/objects.h>
42#include <ssl/engine.h>
43#include <ssl/evp.h>
44
45static int cryptodev_fd = -1;
46static int cryptodev_sessions = 0;
47static u_int32_t cryptodev_symfeat = 0;
48
49static int bn2crparam(const BIGNUM *a, struct crparam *crp);
50static int crparam2bn(struct crparam *crp, BIGNUM *a);
51static void zapparams(struct crypt_kop *kop);
52
53static int cryptodev_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa);
54static int cryptodev_bn_mod_exp(BIGNUM *r, const BIGNUM *a,
55 const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
56static int cryptodev_dsa_bn_mod_exp(DSA *dsa, BIGNUM *r, BIGNUM *a,
57 const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
58static DSA_SIG *cryptodev_dsa_do_sign(const unsigned char *dgst,
59 int dlen, DSA *dsa);
60static int cryptodev_dsa_verify(const unsigned char *dgst, int dgst_len,
61 DSA_SIG *sig, DSA *dsa);
62static int cryptodev_mod_exp_dh(const DH *dh, BIGNUM *r, const BIGNUM *a,
63 const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx,
64 BN_MONT_CTX *m_ctx);
65static int cryptodev_dh_compute_key(unsigned char *key,
66 const BIGNUM *pub_key, DH *dh);
67
68static const ENGINE_CMD_DEFN cryptodev_defns[] = {
69 { 0, NULL, NULL, 0 }
70};
71
72static struct {
73 int id;
74 int nid;
75 int ivmax;
76 int keylen;
77} ciphers[] = {
78 { CRYPTO_DES_CBC, NID_des_cbc, 8, 8, },
79 { CRYPTO_3DES_CBC, NID_des_ede3_cbc, 8, 24, },
80 { CRYPTO_AES_CBC, NID_undef, 8, 24, },
81 { CRYPTO_BLF_CBC, NID_bf_cbc, 8, 16, },
82 { CRYPTO_CAST_CBC, NID_cast5_cbc, 8, 8, },
83 { CRYPTO_SKIPJACK_CBC, NID_undef, 0, 0, },
84 { CRYPTO_ARC4, NID_rc4, 8, 16, },
85 { 0, NID_undef, 0, 0, },
86};
87
88static struct {
89 int id;
90 int nid;
91} digests[] = {
92 { CRYPTO_SHA1_HMAC, NID_hmacWithSHA1, },
93 { CRYPTO_RIPEMD160_HMAC, NID_ripemd160, },
94 { CRYPTO_MD5_KPDK, NID_undef, },
95 { CRYPTO_SHA1_KPDK, NID_undef, },
96 { CRYPTO_MD5, NID_md5, },
97 { CRYPTO_SHA1, NID_undef, },
98 { 0, NID_undef, },
99};
100
101/*
102 * Return 1 if /dev/crypto seems usable, 0 otherwise , also
103 * does most of the work of initting the device, if not already
104 * done.. This should leave is with global fd initialized with CRIOGET.
105 */
106static int
107check_dev_crypto()
108{
109 int fd;
110
111 if (cryptodev_fd == -1) {
112 if ((fd = open("/dev/crypto", O_RDWR, 0)) == -1)
113 return (0);
114 if (ioctl(fd, CRIOGET, &cryptodev_fd) == -1) {
115 close(fd);
116 return (0);
117 }
118 close(fd);
119 /* close on exec */
120 if (fcntl(cryptodev_fd, F_SETFD, 1) == -1) {
121 close(cryptodev_fd);
122 cryptodev_fd = -1;
123 return (0);
124 }
125 }
126 ioctl(cryptodev_fd, CIOCSYMFEAT, &cryptodev_symfeat);
127
128 return (1);
129}
130
131/*
132 * XXXX this needs to be set for each alg - and determined from
133 * a running card.
134 */
135static int
136cryptodev_max_iv(int cipher)
137{
138 int i;
139
140 for (i = 0; ciphers[i].id; i++)
141 if (ciphers[i].id == cipher)
142 return (ciphers[i].ivmax);
143 return (0);
144}
145
146/*
147 * XXXX this needs to be set for each alg - and determined from
148 * a running card. For now, fake it out - but most of these
149 * for real devices should return 1 for the supported key
150 * sizes the device can handle.
151 */
152static int
153cryptodev_key_length_valid(int cipher, int len)
154{
155 int i;
156
157 for (i = 0; ciphers[i].id; i++)
158 if (ciphers[i].id == cipher)
159 return (ciphers[i].keylen == len);
160 return (0);
161}
162
163/* convert libcrypto nids to cryptodev */
164static int
165cipher_nid_to_cryptodev(int nid)
166{
167 int i;
168
169 for (i = 0; ciphers[i].id; i++)
170 if (ciphers[i].nid == nid)
171 return (ciphers[i].id);
172 return (0);
173}
174
175/*
176 * Find out what ciphers /dev/crypto will let us have a session for.
177 * XXX note, that some of these openssl doesn't deal with yet!
178 * returning them here is harmless, as long as we return NULL
179 * when asked for a handler in the cryptodev_engine_ciphers routine
180 */
181static int
182get_cryptodev_ciphers(const int **cnids)
183{
184 static int nids[CRYPTO_ALGORITHM_MAX];
185 struct session_op sess;
186 int i, count = 0;
187
188 memset(&sess, 0, sizeof(sess));
189 sess.key = (caddr_t)"123456781234567812345678";
190
191 for (i = 0; ciphers[i].id && count < CRYPTO_ALGORITHM_MAX; i++) {
192 if (ciphers[i].nid == NID_undef)
193 continue;
194 sess.cipher = ciphers[i].id;
195 sess.keylen = ciphers[i].keylen;
196 sess.mac = 0;
197 if (ioctl(cryptodev_fd, CIOCGSESSION, &sess) != -1 &&
198 ioctl(cryptodev_fd, CIOCFSESSION, &sess.ses) != -1)
199 nids[count++] = ciphers[i].nid;
200 }
201 if (count > 0)
202 *cnids = nids;
203 else
204 *cnids = NULL;
205 return (count);
206}
207
208/*
209 * Find out what digests /dev/crypto will let us have a session for.
210 * XXX note, that some of these openssl doesn't deal with yet!
211 * returning them here is harmless, as long as we return NULL
212 * when asked for a handler in the cryptodev_engine_digests routine
213 */
214static int
215get_cryptodev_digests(const int **cnids)
216{
217 static int nids[CRYPTO_ALGORITHM_MAX];
218 struct session_op sess;
219 int i, count = 0;
220
221 memset(&sess, 0, sizeof(sess));
222 for (i = 0; digests[i].id && count < CRYPTO_ALGORITHM_MAX; i++) {
223 if (digests[i].nid == NID_undef)
224 continue;
225 sess.mac = digests[i].id;
226 sess.cipher = 0;
227 if (ioctl(cryptodev_fd, CIOCGSESSION, &sess) != -1 &&
228 ioctl(cryptodev_fd, CIOCFSESSION, &sess.ses) != -1)
229 nids[count++] = digests[i].nid;
230 }
231 if (count > 0)
232 *cnids = nids;
233 else
234 *cnids = NULL;
235 return (count);
236}
237
238/*
239 * Find the useable ciphers|digests from dev/crypto - this is the first
240 * thing called by the engine init crud which determines what it
241 * can use for ciphers from this engine. We want to return
242 * only what we can do, anythine else is handled by software.
243 *
244 * If we can't initialize the device to do anything useful for
245 * any reason, we want to return a NULL array, and 0 length,
246 * which forces everything to be done is software. By putting
247 * the initalization of the device in here, we ensure we can
248 * use this engine as the default, and if for whatever reason
249 * /dev/crypto won't do what we want it will just be done in
250 * software
251 *
252 * This can (should) be greatly expanded to perhaps take into
253 * account speed of the device, and what we want to do.
254 * (although the disabling of particular alg's could be controlled
255 * by the device driver with sysctl's.) - this is where we
256 * want most of the decisions made about what we actually want
257 * to use from /dev/crypto.
258 */
259int
260cryptodev_usable_ciphers(const int **nids)
261{
262 if (!check_dev_crypto()) {
263 *nids = NULL;
264 return (0);
265 }
266
267 /* find what the device can do. Unfortunately, we don't
268 * necessarily want all of these yet, because we aren't
269 * yet set up to do them
270 */
271 return (get_cryptodev_ciphers(nids));
272}
273
274int
275cryptodev_usable_digests(const int **nids)
276{
277#if 1
278 /*
279 * XXXX just disable all digests for now, because it sucks.
280 * we need a better way to decide this - i.e. I may not
281 * want digests on slow cards like hifn on fast machines,
282 * but might want them on slow or loaded machines, etc.
283 * will also want them when using crypto cards that don't
284 * suck moose gonads - would be nice to be able to decide something
285 * as reasonable default without having hackery that's card dependent.
286 * of course, the default should probably be just do everything,
287 * with perhaps a sysctl to turn algoritms off (or have them off
288 * by default) on cards that generally suck like the hifn.
289 */
290 *nids = NULL;
291 return (0);
292#endif
293
294 if (!check_dev_crypto()) {
295 *nids = NULL;
296 return (0);
297 }
298 return (get_cryptodev_digests(nids));
299}
300
301
302int
303cryptodev_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
304 const unsigned char *in, unsigned int inl)
305{
306 struct crypt_op cryp;
307 struct session_op *sess = ctx->cipher_data;
308 void *iiv;
309 unsigned char save_iv[EVP_MAX_IV_LENGTH];
310 struct syslog_data sd = SYSLOG_DATA_INIT;
311
312 if (cryptodev_fd == -1)
313 return (0);
314 if (sess == NULL)
315 return (0);
316 if (!inl)
317 return (1);
318 if ((inl % ctx->cipher->block_size) != 0)
319 return (0);
320
321 memset(&cryp, 0, sizeof(cryp));
322
323 cryp.ses = sess->ses;
324 cryp.flags = 0;
325 cryp.len = inl;
326 cryp.src = (caddr_t) in;
327 cryp.dst = (caddr_t) out;
328 cryp.mac = 0;
329
330 cryp.op = ctx->encrypt ? COP_ENCRYPT : COP_DECRYPT;
331
332 if (ctx->cipher->iv_len) {
333 cryp.iv = (caddr_t) ctx->iv;
334 if (!ctx->encrypt) {
335 iiv = (void *) in + inl - ctx->cipher->iv_len;
336 memcpy(save_iv, iiv, ctx->cipher->iv_len);
337 }
338 } else
339 cryp.iv = NULL;
340
341 if (ioctl(cryptodev_fd, CIOCCRYPT, &cryp) == -1) {
342 /* XXX need better errror handling
343 * this can fail for a number of different reasons.
344 */
345 syslog_r(LOG_ERR, &sd, "CIOCCRYPT failed (%m)");
346 return (0);
347 }
348
349 if (ctx->cipher->iv_len) {
350 if (ctx->encrypt)
351 iiv = (void *) out + inl - ctx->cipher->iv_len;
352 else
353 iiv = save_iv;
354 memcpy(ctx->iv, iiv, ctx->cipher->iv_len);
355 }
356 return (1);
357}
358
359int
360cryptodev_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
361 const unsigned char *iv, int enc)
362{
363 struct session_op *sess = ctx->cipher_data;
364 struct syslog_data sd = SYSLOG_DATA_INIT;
365 int cipher;
366
367 if ((cipher = cipher_nid_to_cryptodev(ctx->cipher->nid)) == NID_undef)
368 return (0);
369
370 if (!check_dev_crypto())
371 return (0);
372
373 if (ctx->cipher->iv_len > cryptodev_max_iv(cipher))
374 return (0);
375
376 if (!cryptodev_key_length_valid(cipher, ctx->key_len))
377 return (0);
378
379 memset(sess, 0, sizeof(struct session_op));
380
381 sess->key = (unsigned char *)key;
382 sess->keylen = ctx->key_len;
383 sess->cipher = cipher;
384
385 if (ioctl(cryptodev_fd, CIOCGSESSION, sess) == -1) {
386 syslog_r(LOG_ERR, &sd, "CIOCGSESSION failed (%m)");
387 return (0);
388 }
389 cryptodev_sessions++;
390 return (1);
391}
392
393/*
394 * free anything we allocated earlier when initting a
395 * session, and close the session.
396 */
397int
398cryptodev_cleanup(EVP_CIPHER_CTX *ctx)
399{
400 int ret = 0;
401 struct session_op *sess = ctx->cipher_data;
402 struct syslog_data sd = SYSLOG_DATA_INIT;
403
404 if (sess == NULL)
405 return (0);
406
407 /* XXX if this ioctl fails, someting's wrong. the invoker
408 * may have called us with a bogus ctx, or we could
409 * have a device that for whatever reason just doesn't
410 * want to play ball - it's not clear what's right
411 * here - should this be an error? should it just
412 * increase a counter, hmm. For right now, we return
413 * 0 - I don't believe that to be "right". we could
414 * call the gorpy openssl lib error handlers that
415 * print messages to users of the library. hmm..
416 */
417
418 if (ioctl(cryptodev_fd, CIOCFSESSION, &sess->ses) == -1) {
419 syslog_r(LOG_ERR, &sd, "CIOCFSESSION failed (%m)");
420 ret = 0;
421 } else {
422 cryptodev_sessions--;
423 ret = 1;
424 }
425 if (cryptodev_sessions == 0 && cryptodev_fd != -1 ) {
426 close(cryptodev_fd); /* XXX should this be closed? */
427 cryptodev_fd = -1;
428 }
429 return (ret);
430}
431
432/*
433 * libcrypto EVP stuff - this is how we get wired to EVP so the engine
434 * gets called when libcrypto requests a cipher NID.
435 */
436
437/* ARC4 (16 byte key) */
438const EVP_CIPHER cryptodev_arc4_cipher = {
439 NID_rc4,
440 1, 16, 0,
441 EVP_CIPH_VARIABLE_LENGTH,
442 cryptodev_init_key,
443 cryptodev_cipher,
444 cryptodev_cleanup,
445 sizeof(struct session_op),
446 NULL,
447 NULL,
448 NULL
449};
450
451/* DES CBC EVP */
452const EVP_CIPHER cryptodev_des_cbc = {
453 NID_des_cbc,
454 8, 8, 8,
455 EVP_CIPH_CBC_MODE,
456 cryptodev_init_key,
457 cryptodev_cipher,
458 cryptodev_cleanup,
459 sizeof(struct session_op),
460 EVP_CIPHER_set_asn1_iv,
461 EVP_CIPHER_get_asn1_iv,
462 NULL
463};
464
465/* 3DES CBC EVP */
466const EVP_CIPHER cryptodev_3des_cbc = {
467 NID_des_ede3_cbc,
468 8, 24, 8,
469 EVP_CIPH_CBC_MODE,
470 cryptodev_init_key,
471 cryptodev_cipher,
472 cryptodev_cleanup,
473 sizeof(struct session_op),
474 EVP_CIPHER_set_asn1_iv,
475 EVP_CIPHER_get_asn1_iv,
476 NULL
477};
478
479
480/*
481 * Registered by the ENGINE when used to find out how to deal with
482 * a particular NID in the ENGINE. this says what we'll do at the
483 * top level - note, that list is restricted by what we answer with
484 */
485int
486cryptodev_engine_ciphers(ENGINE *e, const EVP_CIPHER **cipher,
487 const int **nids, int nid)
488{
489 if (!cipher)
490 return (cryptodev_usable_ciphers(nids));
491
492 switch (nid) {
493 case NID_rc4:
494 *cipher = &cryptodev_arc4_cipher;
495 break;
496 case NID_des_ede3_cbc:
497 *cipher = &cryptodev_3des_cbc;
498 break;
499 case NID_des_cbc:
500 *cipher = &cryptodev_des_cbc;
501 break;
502 default:
503 *cipher = NULL;
504 break;
505 }
506 return (*cipher != NULL);
507}
508
509int
510cryptodev_engine_digests(ENGINE *e, const EVP_MD **digest,
511 const int **nids, int nid)
512{
513 if (!digest)
514 return (cryptodev_usable_digests(nids));
515
516 switch (nid) {
517 case NID_md5:
518 *digest = NULL; /* need to make a clean md5 critter */
519 break;
520 default:
521 *digest = NULL;
522 break;
523 }
524 return (*digest != NULL);
525}
526
527
528/*
529 * Convert a BIGNUM to the representation that /dev/crypto needs.
530 * Upon completion of use, the caller is responsible for freeing
531 * crp->crp_p.
532 */
533static int
534bn2crparam(const BIGNUM *a, struct crparam *crp)
535{
536 int i, j, n;
537 ssize_t words, bytes, bits;
538 u_char *b;
539
540 crp->crp_p = NULL;
541 crp->crp_nbits = 0;
542
543 bits = BN_num_bits(a);
544 bytes = (bits + 7) / 8;
545
546 b = malloc(bytes);
547 if (b == NULL)
548 return (1);
549
550 crp->crp_p = b;
551 crp->crp_nbits = bits;
552
553 words = (bits + BN_BITS2 - 1) / BN_BITS2;
554
555 n = 0;
556 for (i = 0; i < words && n < bytes; i++) {
557 BN_ULONG word;
558
559 word = a->d[i];
560 for (j = 0 ; j < BN_BYTES && n < bytes; j++, n++) {
561 *b++ = (word & 0xff);
562 word >>= 8;
563 }
564 }
565 return (0);
566}
567
568/* Convert a /dev/crypto parameter to a BIGNUM */
569static int
570crparam2bn(struct crparam *crp, BIGNUM *a)
571{
572 int i, bytes;
573
574 bytes = (crp->crp_nbits + 7)/8;
575
576 BN_zero(a);
577 for (i = bytes - 1; i >= 0; i--) {
578 BN_lshift(a, a, 8);
579 BN_add_word(a, (u_char)crp->crp_p[i]);
580 }
581
582 return (0);
583}
584
585static void
586zapparams(struct crypt_kop *kop)
587{
588 int i;
589
590 for (i = 0; i <= kop->crk_iparams + kop->crk_oparams; i++) {
591 if (kop->crk_param[i].crp_p)
592 free(kop->crk_param[i].crp_p);
593 kop->crk_param[i].crp_p = NULL;
594 kop->crk_param[i].crp_nbits = 0;
595 }
596}
597
598static int
599cryptodev_sym(struct crypt_kop *kop, BIGNUM *r, BIGNUM *s)
600{
601 int ret = -1;
602
603 if (r) {
604 kop->crk_param[kop->crk_iparams].crp_p = malloc(256);
605 kop->crk_param[kop->crk_iparams].crp_nbits = 256 * 8;
606 kop->crk_oparams++;
607 }
608 if (s) {
609 kop->crk_param[kop->crk_iparams+1].crp_p = malloc(256);
610 kop->crk_param[kop->crk_iparams+1].crp_nbits = 256 * 8;
611 kop->crk_oparams++;
612 }
613
614 if (ioctl(cryptodev_fd, CIOCKEY, &kop) == 0) {
615 crparam2bn(&kop->crk_param[3], r);
616 ret = 0;
617 }
618 return (ret);
619}
620
621static int
622cryptodev_bn_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
623 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont)
624{
625 struct crypt_kop kop;
626 int ret = 0;
627
628 memset(&kop, 0, sizeof kop);
629 kop.crk_op = CRK_MOD_EXP;
630
631 /* inputs: a m p */
632 if (bn2crparam(a, &kop.crk_param[0]))
633 goto err;
634 if (bn2crparam(m, &kop.crk_param[1]))
635 goto err;
636 if (bn2crparam(p, &kop.crk_param[2]))
637 goto err;
638 kop.crk_iparams = 3;
639
640 if (cryptodev_sym(&kop, r, NULL) == -1) {
641 ret = BN_mod_exp(r, a, p, m, ctx);
642 }
643err:
644 zapparams(&kop);
645 return (ret);
646}
647
648
649static int
650cryptodev_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa)
651{
652 struct crypt_kop kop;
653 int ret = 0;
654
655 if (!rsa->p || !rsa->q || !rsa->dmp1 || !rsa->dmq1 || !rsa->iqmp) {
656 /* XXX 0 means failure?? */
657 goto err;
658 }
659
660 memset(&kop, 0, sizeof kop);
661 kop.crk_op = CRK_MOD_EXP_CRT;
662 /* inputs: rsa->p rsa->q I rsa->dmp1 rsa->dmq1 rsa->iqmp */
663 if (bn2crparam(rsa->p, &kop.crk_param[0]))
664 goto err;
665 if (bn2crparam(rsa->q, &kop.crk_param[1]))
666 goto err;
667 if (bn2crparam(I, &kop.crk_param[2]))
668 goto err;
669 if (bn2crparam(rsa->dmp1, &kop.crk_param[3]))
670 goto err;
671 if (bn2crparam(rsa->dmq1, &kop.crk_param[4]))
672 goto err;
673 if (bn2crparam(rsa->iqmp, &kop.crk_param[5]))
674 goto err;
675 kop.crk_iparams = 6;
676
677 if (cryptodev_sym(&kop, r0, NULL) == -1) {
678 const RSA_METHOD *meth = RSA_PKCS1_SSLeay();
679
680 ret = (*meth->rsa_mod_exp)(r0, I, rsa);
681 }
682err:
683 zapparams(&kop);
684 return (ret);
685}
686
687static RSA_METHOD cryptodev_rsa = {
688 "cryptodev RSA method",
689 NULL, /* rsa_pub_enc */
690 NULL, /* rsa_pub_dec */
691 NULL, /* rsa_priv_enc */
692 NULL, /* rsa_priv_dec */
693 cryptodev_rsa_mod_exp, /* rsa_mod_exp */
694 cryptodev_bn_mod_exp, /* bn_mod_exp */
695 NULL, /* init */
696 NULL, /* finish */
697 0, /* flags */
698 NULL, /* app_data */
699 NULL, /* rsa_sign */
700 NULL /* rsa_verify */
701};
702
703static int
704cryptodev_dsa_bn_mod_exp(DSA *dsa, BIGNUM *r, BIGNUM *a, const BIGNUM *p,
705 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx)
706{
707 return (cryptodev_bn_mod_exp(r, a, p, m, ctx, m_ctx));
708}
709
710static DSA_SIG *
711cryptodev_dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa)
712{
713 struct crypt_kop kop;
714 BIGNUM *r = NULL, *s = NULL;
715 DSA_SIG *dsaret = NULL;
716
717 if ((r = BN_new()) == NULL)
718 goto err;
719 if ((s = BN_new()) == NULL) {
720 BN_free(r);
721 goto err;
722 }
723
724 memset(&kop, 0, sizeof kop);
725 kop.crk_op = CRK_DSA_SIGN;
726
727 /* inputs: dgst dsa->p dsa->q dsa->g dsa->priv_key */
728 kop.crk_param[0].crp_p = (caddr_t)dgst;
729 kop.crk_param[0].crp_nbits = dlen * 8;
730 if (bn2crparam(dsa->p, &kop.crk_param[1]))
731 goto err;
732 if (bn2crparam(dsa->q, &kop.crk_param[2]))
733 goto err;
734 if (bn2crparam(dsa->g, &kop.crk_param[3]))
735 goto err;
736 if (bn2crparam(dsa->priv_key, &kop.crk_param[4]))
737 goto err;
738 kop.crk_iparams = 5;
739
740 if (cryptodev_sym(&kop, r, s) == 0) {
741 dsaret = DSA_SIG_new();
742 dsaret->r = r;
743 dsaret->s = s;
744 } else {
745 const DSA_METHOD *meth = DSA_OpenSSL();
746
747 BN_free(r);
748 BN_free(s);
749 dsaret = (meth->dsa_do_sign)(dgst, dlen, dsa);
750 }
751err:
752 kop.crk_param[0].crp_p = NULL;
753 zapparams(&kop);
754 return (dsaret);
755}
756
757static int
758cryptodev_dsa_verify(const unsigned char *dgst, int dlen,
759 DSA_SIG *sig, DSA *dsa)
760{
761 struct crypt_kop kop;
762 int dsaret = 0;
763
764 memset(&kop, 0, sizeof kop);
765 kop.crk_op = CRK_DSA_VERIFY;
766
767 /* inputs: dgst dsa->p dsa->q dsa->g dsa->pub_key sig->r sig->s */
768 kop.crk_param[0].crp_p = (caddr_t)dgst;
769 kop.crk_param[0].crp_nbits = dlen * 8;
770 if (bn2crparam(dsa->p, &kop.crk_param[1]))
771 goto err;
772 if (bn2crparam(dsa->q, &kop.crk_param[2]))
773 goto err;
774 if (bn2crparam(dsa->g, &kop.crk_param[3]))
775 goto err;
776 if (bn2crparam(dsa->pub_key, &kop.crk_param[4]))
777 goto err;
778 if (bn2crparam(sig->r, &kop.crk_param[5]))
779 goto err;
780 if (bn2crparam(sig->s, &kop.crk_param[6]))
781 goto err;
782 kop.crk_iparams = 7;
783
784 if (cryptodev_sym(&kop, NULL, NULL) == 0) {
785 dsaret = kop.crk_status;
786 } else {
787 const DSA_METHOD *meth = DSA_OpenSSL();
788
789 dsaret = (meth->dsa_do_verify)(dgst, dlen, sig, dsa);
790 }
791err:
792 kop.crk_param[0].crp_p = NULL;
793 zapparams(&kop);
794 return (dsaret);
795}
796
797static DSA_METHOD cryptodev_dsa = {
798 "cryptodev DSA method",
799 cryptodev_dsa_do_sign,
800 NULL, /* dsa_sign_setup */
801 cryptodev_dsa_verify,
802 NULL, /* dsa_mod_exp */
803 cryptodev_dsa_bn_mod_exp, /* bn_mod_exp */
804 NULL, /* init */
805 NULL, /* finish */
806 0, /* flags */
807 NULL /* app_data */
808};
809
810static int
811cryptodev_mod_exp_dh(const DH *dh, BIGNUM *r, const BIGNUM *a,
812 const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx,
813 BN_MONT_CTX *m_ctx)
814{
815 return (cryptodev_bn_mod_exp(r, a, p, m, ctx, m_ctx));
816}
817
818static int
819cryptodev_dh_compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh)
820{
821 struct crypt_kop kop;
822 int dhret = 0;
823 int keylen;
824
825 keylen = BN_num_bits(dh->p);
826
827 memset(&kop, 0, sizeof kop);
828 kop.crk_op = CRK_DH_COMPUTE_KEY;
829
830 /* inputs: dh->priv_key pub_key dh->p key */
831 if (bn2crparam(dh->priv_key, &kop.crk_param[0]))
832 goto err;
833 if (bn2crparam(pub_key, &kop.crk_param[1]))
834 goto err;
835 if (bn2crparam(dh->p, &kop.crk_param[2]))
836 goto err;
837 kop.crk_iparams = 3;
838
839 kop.crk_param[3].crp_p = key;
840 kop.crk_param[3].crp_nbits = keylen * 8;
841 kop.crk_oparams = 1;
842
843 if (ioctl(cryptodev_fd, CIOCKEY, &kop) == -1) {
844 const DH_METHOD *meth = DH_OpenSSL();
845
846 dhret = (meth->compute_key)(key, pub_key, dh);
847 }
848err:
849 kop.crk_param[3].crp_p = NULL;
850 zapparams(&kop);
851 return (dhret);
852}
853
854static DH_METHOD cryptodev_dh = {
855 "cryptodev DH method",
856 NULL, /* cryptodev_dh_generate_key */
857 cryptodev_dh_compute_key,
858 cryptodev_mod_exp_dh,
859 NULL,
860 NULL,
861 0, /* flags */
862 NULL /* app_data */
863};
864
865/*
866 * ctrl right now is just a wrapper that doesn't do much
867 * but I expect we'll want some options soon.
868 */
869static int
870cryptodev_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)())
871{
872 struct syslog_data sd = SYSLOG_DATA_INIT;
873
874 switch (cmd) {
875 default:
876 syslog_r(LOG_ERR, &sd,
877 "cryptodev_ctrl: unknown command %d", cmd);
878 break;
879 }
880 return (1);
881}
882
883void
884ENGINE_load_cryptodev(void)
885{
886 ENGINE *engine = ENGINE_new();
887 const RSA_METHOD *rsa_meth;
888 const DH_METHOD *dh_meth;
889
890 if (engine == NULL)
891 return;
892
893 if (!ENGINE_set_id(engine, "cryptodev") ||
894 !ENGINE_set_name(engine, "OpenBSD cryptodev engine") ||
895 !ENGINE_set_ciphers(engine, cryptodev_engine_ciphers) ||
896 !ENGINE_set_digests(engine, cryptodev_engine_digests) ||
897 !ENGINE_set_ctrl_function(engine, cryptodev_ctrl) ||
898 !ENGINE_set_cmd_defns(engine, cryptodev_defns)) {
899 ENGINE_free(engine);
900 return;
901 }
902
903 if ((cryptodev_symfeat & CRSFEAT_RSA) &&
904 ENGINE_set_RSA(engine, &cryptodev_rsa)) {
905 rsa_meth = RSA_PKCS1_SSLeay();
906 cryptodev_rsa.rsa_pub_enc = rsa_meth->rsa_pub_enc;
907 cryptodev_rsa.rsa_pub_dec = rsa_meth->rsa_pub_dec;
908 cryptodev_rsa.rsa_priv_enc = rsa_meth->rsa_priv_dec;
909 cryptodev_rsa.rsa_priv_dec = rsa_meth->rsa_priv_dec;
910 }
911
912 if ((cryptodev_symfeat & CRSFEAT_DSA) &&
913 ENGINE_set_DSA(engine, &cryptodev_dsa)) {
914 }
915
916 if ((cryptodev_symfeat & CRSFEAT_DH) &&
917 ENGINE_set_DH(engine, &cryptodev_dh)) {
918 dh_meth = DH_OpenSSL();
919 cryptodev_dh.generate_key = dh_meth->generate_key;
920 cryptodev_dh.compute_key = dh_meth->compute_key;
921 }
922
923 ENGINE_add(engine);
924 ENGINE_free(engine);
925 ERR_clear_error();
926}
diff --git a/src/lib/libcrypto/engine/hw_cswift.c b/src/lib/libcrypto/engine/hw_cswift.c
new file mode 100644
index 0000000000..77608b8983
--- /dev/null
+++ b/src/lib/libcrypto/engine/hw_cswift.c
@@ -0,0 +1,807 @@
1/* crypto/engine/hw_cswift.c */
2/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 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 * licensing@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 <stdio.h>
60#include <openssl/crypto.h>
61#include "cryptlib.h"
62#include <openssl/dso.h>
63#include "engine_int.h"
64#include <openssl/engine.h>
65
66#ifndef NO_HW
67#ifndef NO_HW_CSWIFT
68
69/* Attribution notice: Rainbow have generously allowed me to reproduce
70 * the necessary definitions here from their API. This means the support
71 * can build independently of whether application builders have the
72 * API or hardware. This will allow developers to easily produce software
73 * that has latent hardware support for any users that have accelerators
74 * installed, without the developers themselves needing anything extra.
75 *
76 * I have only clipped the parts from the CryptoSwift header files that
77 * are (or seem) relevant to the CryptoSwift support code. This is
78 * simply to keep the file sizes reasonable.
79 * [Geoff]
80 */
81#ifdef FLAT_INC
82#include "cswift.h"
83#else
84#include "vendor_defns/cswift.h"
85#endif
86
87static int cswift_init(void);
88static int cswift_finish(void);
89
90/* BIGNUM stuff */
91static int cswift_mod_exp(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
92 const BIGNUM *m, BN_CTX *ctx);
93static int cswift_mod_exp_crt(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
94 const BIGNUM *q, const BIGNUM *dmp1, const BIGNUM *dmq1,
95 const BIGNUM *iqmp, BN_CTX *ctx);
96
97/* RSA stuff */
98static int cswift_rsa_mod_exp(BIGNUM *r0, BIGNUM *I, RSA *rsa);
99/* This function is aliased to mod_exp (with the mont stuff dropped). */
100static int cswift_mod_exp_mont(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
101 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
102
103/* DSA stuff */
104static DSA_SIG *cswift_dsa_sign(const unsigned char *dgst, int dlen, DSA *dsa);
105static int cswift_dsa_verify(const unsigned char *dgst, int dgst_len,
106 DSA_SIG *sig, DSA *dsa);
107
108/* DH stuff */
109/* This function is alised to mod_exp (with the DH and mont dropped). */
110static int cswift_mod_exp_dh(DH *dh, BIGNUM *r, BIGNUM *a, const BIGNUM *p,
111 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
112
113
114/* Our internal RSA_METHOD that we provide pointers to */
115static RSA_METHOD cswift_rsa =
116 {
117 "CryptoSwift RSA method",
118 NULL,
119 NULL,
120 NULL,
121 NULL,
122 cswift_rsa_mod_exp,
123 cswift_mod_exp_mont,
124 NULL,
125 NULL,
126 0,
127 NULL,
128 NULL,
129 NULL
130 };
131
132/* Our internal DSA_METHOD that we provide pointers to */
133static DSA_METHOD cswift_dsa =
134 {
135 "CryptoSwift DSA method",
136 cswift_dsa_sign,
137 NULL, /* dsa_sign_setup */
138 cswift_dsa_verify,
139 NULL, /* dsa_mod_exp */
140 NULL, /* bn_mod_exp */
141 NULL, /* init */
142 NULL, /* finish */
143 0, /* flags */
144 NULL /* app_data */
145 };
146
147/* Our internal DH_METHOD that we provide pointers to */
148static DH_METHOD cswift_dh =
149 {
150 "CryptoSwift DH method",
151 NULL,
152 NULL,
153 cswift_mod_exp_dh,
154 NULL,
155 NULL,
156 0,
157 NULL
158 };
159
160/* Our ENGINE structure. */
161static ENGINE engine_cswift =
162 {
163 "cswift",
164 "CryptoSwift hardware engine support",
165 &cswift_rsa,
166 &cswift_dsa,
167 &cswift_dh,
168 NULL,
169 cswift_mod_exp,
170 cswift_mod_exp_crt,
171 cswift_init,
172 cswift_finish,
173 NULL, /* no ctrl() */
174 NULL, /* no load_privkey() */
175 NULL, /* no load_pubkey() */
176 0, /* no flags */
177 0, 0, /* no references */
178 NULL, NULL /* unlinked */
179 };
180
181/* As this is only ever called once, there's no need for locking
182 * (indeed - the lock will already be held by our caller!!!) */
183ENGINE *ENGINE_cswift()
184 {
185 RSA_METHOD *meth1;
186 DH_METHOD *meth2;
187
188 /* We know that the "PKCS1_SSLeay()" functions hook properly
189 * to the cswift-specific mod_exp and mod_exp_crt so we use
190 * those functions. NB: We don't use ENGINE_openssl() or
191 * anything "more generic" because something like the RSAref
192 * code may not hook properly, and if you own one of these
193 * cards then you have the right to do RSA operations on it
194 * anyway! */
195 meth1 = RSA_PKCS1_SSLeay();
196 cswift_rsa.rsa_pub_enc = meth1->rsa_pub_enc;
197 cswift_rsa.rsa_pub_dec = meth1->rsa_pub_dec;
198 cswift_rsa.rsa_priv_enc = meth1->rsa_priv_enc;
199 cswift_rsa.rsa_priv_dec = meth1->rsa_priv_dec;
200
201 /* Much the same for Diffie-Hellman */
202 meth2 = DH_OpenSSL();
203 cswift_dh.generate_key = meth2->generate_key;
204 cswift_dh.compute_key = meth2->compute_key;
205 return &engine_cswift;
206 }
207
208/* This is a process-global DSO handle used for loading and unloading
209 * the CryptoSwift library. NB: This is only set (or unset) during an
210 * init() or finish() call (reference counts permitting) and they're
211 * operating with global locks, so this should be thread-safe
212 * implicitly. */
213static DSO *cswift_dso = NULL;
214
215/* These are the function pointers that are (un)set when the library has
216 * successfully (un)loaded. */
217t_swAcquireAccContext *p_CSwift_AcquireAccContext = NULL;
218t_swAttachKeyParam *p_CSwift_AttachKeyParam = NULL;
219t_swSimpleRequest *p_CSwift_SimpleRequest = NULL;
220t_swReleaseAccContext *p_CSwift_ReleaseAccContext = NULL;
221
222/* Used in the DSO operations. */
223static const char *CSWIFT_LIBNAME = "swift";
224static const char *CSWIFT_F1 = "swAcquireAccContext";
225static const char *CSWIFT_F2 = "swAttachKeyParam";
226static const char *CSWIFT_F3 = "swSimpleRequest";
227static const char *CSWIFT_F4 = "swReleaseAccContext";
228
229
230/* CryptoSwift library functions and mechanics - these are used by the
231 * higher-level functions further down. NB: As and where there's no
232 * error checking, take a look lower down where these functions are
233 * called, the checking and error handling is probably down there. */
234
235/* utility function to obtain a context */
236static int get_context(SW_CONTEXT_HANDLE *hac)
237 {
238 SW_STATUS status;
239
240 status = p_CSwift_AcquireAccContext(hac);
241 if(status != SW_OK)
242 return 0;
243 return 1;
244 }
245
246/* similarly to release one. */
247static void release_context(SW_CONTEXT_HANDLE hac)
248 {
249 p_CSwift_ReleaseAccContext(hac);
250 }
251
252/* (de)initialisation functions. */
253static int cswift_init()
254 {
255 SW_CONTEXT_HANDLE hac;
256 t_swAcquireAccContext *p1;
257 t_swAttachKeyParam *p2;
258 t_swSimpleRequest *p3;
259 t_swReleaseAccContext *p4;
260
261 if(cswift_dso != NULL)
262 {
263 ENGINEerr(ENGINE_F_CSWIFT_INIT,ENGINE_R_ALREADY_LOADED);
264 goto err;
265 }
266 /* Attempt to load libswift.so/swift.dll/whatever. */
267 cswift_dso = DSO_load(NULL, CSWIFT_LIBNAME, NULL,
268 DSO_FLAG_NAME_TRANSLATION);
269 if(cswift_dso == NULL)
270 {
271 ENGINEerr(ENGINE_F_CSWIFT_INIT,ENGINE_R_DSO_FAILURE);
272 goto err;
273 }
274 if(!(p1 = (t_swAcquireAccContext *)
275 DSO_bind_func(cswift_dso, CSWIFT_F1)) ||
276 !(p2 = (t_swAttachKeyParam *)
277 DSO_bind_func(cswift_dso, CSWIFT_F2)) ||
278 !(p3 = (t_swSimpleRequest *)
279 DSO_bind_func(cswift_dso, CSWIFT_F3)) ||
280 !(p4 = (t_swReleaseAccContext *)
281 DSO_bind_func(cswift_dso, CSWIFT_F4)))
282 {
283 ENGINEerr(ENGINE_F_CSWIFT_INIT,ENGINE_R_DSO_FAILURE);
284 goto err;
285 }
286 /* Copy the pointers */
287 p_CSwift_AcquireAccContext = p1;
288 p_CSwift_AttachKeyParam = p2;
289 p_CSwift_SimpleRequest = p3;
290 p_CSwift_ReleaseAccContext = p4;
291 /* Try and get a context - if not, we may have a DSO but no
292 * accelerator! */
293 if(!get_context(&hac))
294 {
295 ENGINEerr(ENGINE_F_CSWIFT_INIT,ENGINE_R_UNIT_FAILURE);
296 goto err;
297 }
298 release_context(hac);
299 /* Everything's fine. */
300 return 1;
301err:
302 if(cswift_dso)
303 DSO_free(cswift_dso);
304 p_CSwift_AcquireAccContext = NULL;
305 p_CSwift_AttachKeyParam = NULL;
306 p_CSwift_SimpleRequest = NULL;
307 p_CSwift_ReleaseAccContext = NULL;
308 return 0;
309 }
310
311static int cswift_finish()
312 {
313 if(cswift_dso == NULL)
314 {
315 ENGINEerr(ENGINE_F_CSWIFT_FINISH,ENGINE_R_NOT_LOADED);
316 return 0;
317 }
318 if(!DSO_free(cswift_dso))
319 {
320 ENGINEerr(ENGINE_F_CSWIFT_FINISH,ENGINE_R_DSO_FAILURE);
321 return 0;
322 }
323 cswift_dso = NULL;
324 p_CSwift_AcquireAccContext = NULL;
325 p_CSwift_AttachKeyParam = NULL;
326 p_CSwift_SimpleRequest = NULL;
327 p_CSwift_ReleaseAccContext = NULL;
328 return 1;
329 }
330
331/* Un petit mod_exp */
332static int cswift_mod_exp(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
333 const BIGNUM *m, BN_CTX *ctx)
334 {
335 /* I need somewhere to store temporary serialised values for
336 * use with the CryptoSwift API calls. A neat cheat - I'll use
337 * BIGNUMs from the BN_CTX but access their arrays directly as
338 * byte arrays <grin>. This way I don't have to clean anything
339 * up. */
340 BIGNUM *modulus;
341 BIGNUM *exponent;
342 BIGNUM *argument;
343 BIGNUM *result;
344 SW_STATUS sw_status;
345 SW_LARGENUMBER arg, res;
346 SW_PARAM sw_param;
347 SW_CONTEXT_HANDLE hac;
348 int to_return, acquired;
349
350 modulus = exponent = argument = result = NULL;
351 to_return = 0; /* expect failure */
352 acquired = 0;
353
354 if(!get_context(&hac))
355 {
356 ENGINEerr(ENGINE_F_CSWIFT_MOD_EXP,ENGINE_R_GET_HANDLE_FAILED);
357 goto err;
358 }
359 acquired = 1;
360 /* Prepare the params */
361 modulus = BN_CTX_get(ctx);
362 exponent = BN_CTX_get(ctx);
363 argument = BN_CTX_get(ctx);
364 result = BN_CTX_get(ctx);
365 if(!modulus || !exponent || !argument || !result)
366 {
367 ENGINEerr(ENGINE_F_CSWIFT_MOD_EXP,ENGINE_R_BN_CTX_FULL);
368 goto err;
369 }
370 if(!bn_wexpand(modulus, m->top) || !bn_wexpand(exponent, p->top) ||
371 !bn_wexpand(argument, a->top) || !bn_wexpand(result, m->top))
372 {
373 ENGINEerr(ENGINE_F_CSWIFT_MOD_EXP,ENGINE_R_BN_EXPAND_FAIL);
374 goto err;
375 }
376 sw_param.type = SW_ALG_EXP;
377 sw_param.up.exp.modulus.nbytes = BN_bn2bin(m,
378 (unsigned char *)modulus->d);
379 sw_param.up.exp.modulus.value = (unsigned char *)modulus->d;
380 sw_param.up.exp.exponent.nbytes = BN_bn2bin(p,
381 (unsigned char *)exponent->d);
382 sw_param.up.exp.exponent.value = (unsigned char *)exponent->d;
383 /* Attach the key params */
384 sw_status = p_CSwift_AttachKeyParam(hac, &sw_param);
385 switch(sw_status)
386 {
387 case SW_OK:
388 break;
389 case SW_ERR_INPUT_SIZE:
390 ENGINEerr(ENGINE_F_CSWIFT_MOD_EXP,
391 ENGINE_R_SIZE_TOO_LARGE_OR_TOO_SMALL);
392 goto err;
393 default:
394 {
395 char tmpbuf[20];
396 ENGINEerr(ENGINE_F_CSWIFT_MOD_EXP,ENGINE_R_REQUEST_FAILED);
397 sprintf(tmpbuf, "%ld", sw_status);
398 ERR_add_error_data(2, "CryptoSwift error number is ",tmpbuf);
399 }
400 goto err;
401 }
402 /* Prepare the argument and response */
403 arg.nbytes = BN_bn2bin(a, (unsigned char *)argument->d);
404 arg.value = (unsigned char *)argument->d;
405 res.nbytes = BN_num_bytes(m);
406 memset(result->d, 0, res.nbytes);
407 res.value = (unsigned char *)result->d;
408 /* Perform the operation */
409 if((sw_status = p_CSwift_SimpleRequest(hac, SW_CMD_MODEXP, &arg, 1,
410 &res, 1)) != SW_OK)
411 {
412 char tmpbuf[20];
413 ENGINEerr(ENGINE_F_CSWIFT_MOD_EXP,ENGINE_R_REQUEST_FAILED);
414 sprintf(tmpbuf, "%ld", sw_status);
415 ERR_add_error_data(2, "CryptoSwift error number is ",tmpbuf);
416 goto err;
417 }
418 /* Convert the response */
419 BN_bin2bn((unsigned char *)result->d, res.nbytes, r);
420 to_return = 1;
421err:
422 if(acquired)
423 release_context(hac);
424 if(modulus) ctx->tos--;
425 if(exponent) ctx->tos--;
426 if(argument) ctx->tos--;
427 if(result) ctx->tos--;
428 return to_return;
429 }
430
431/* Un petit mod_exp chinois */
432static int cswift_mod_exp_crt(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
433 const BIGNUM *q, const BIGNUM *dmp1,
434 const BIGNUM *dmq1, const BIGNUM *iqmp, BN_CTX *ctx)
435 {
436 SW_STATUS sw_status;
437 SW_LARGENUMBER arg, res;
438 SW_PARAM sw_param;
439 SW_CONTEXT_HANDLE hac;
440 BIGNUM *rsa_p = NULL;
441 BIGNUM *rsa_q = NULL;
442 BIGNUM *rsa_dmp1 = NULL;
443 BIGNUM *rsa_dmq1 = NULL;
444 BIGNUM *rsa_iqmp = NULL;
445 BIGNUM *argument = NULL;
446 BIGNUM *result = NULL;
447 int to_return = 0; /* expect failure */
448 int acquired = 0;
449
450 if(!get_context(&hac))
451 {
452 ENGINEerr(ENGINE_F_CSWIFT_MOD_EXP_CRT,ENGINE_R_GET_HANDLE_FAILED);
453 goto err;
454 }
455 acquired = 1;
456 /* Prepare the params */
457 rsa_p = BN_CTX_get(ctx);
458 rsa_q = BN_CTX_get(ctx);
459 rsa_dmp1 = BN_CTX_get(ctx);
460 rsa_dmq1 = BN_CTX_get(ctx);
461 rsa_iqmp = BN_CTX_get(ctx);
462 argument = BN_CTX_get(ctx);
463 result = BN_CTX_get(ctx);
464 if(!rsa_p || !rsa_q || !rsa_dmp1 || !rsa_dmq1 || !rsa_iqmp ||
465 !argument || !result)
466 {
467 ENGINEerr(ENGINE_F_CSWIFT_MOD_EXP_CRT,ENGINE_R_BN_CTX_FULL);
468 goto err;
469 }
470 if(!bn_wexpand(rsa_p, p->top) || !bn_wexpand(rsa_q, q->top) ||
471 !bn_wexpand(rsa_dmp1, dmp1->top) ||
472 !bn_wexpand(rsa_dmq1, dmq1->top) ||
473 !bn_wexpand(rsa_iqmp, iqmp->top) ||
474 !bn_wexpand(argument, a->top) ||
475 !bn_wexpand(result, p->top + q->top))
476 {
477 ENGINEerr(ENGINE_F_CSWIFT_MOD_EXP_CRT,ENGINE_R_BN_EXPAND_FAIL);
478 goto err;
479 }
480 sw_param.type = SW_ALG_CRT;
481 sw_param.up.crt.p.nbytes = BN_bn2bin(p, (unsigned char *)rsa_p->d);
482 sw_param.up.crt.p.value = (unsigned char *)rsa_p->d;
483 sw_param.up.crt.q.nbytes = BN_bn2bin(q, (unsigned char *)rsa_q->d);
484 sw_param.up.crt.q.value = (unsigned char *)rsa_q->d;
485 sw_param.up.crt.dmp1.nbytes = BN_bn2bin(dmp1,
486 (unsigned char *)rsa_dmp1->d);
487 sw_param.up.crt.dmp1.value = (unsigned char *)rsa_dmp1->d;
488 sw_param.up.crt.dmq1.nbytes = BN_bn2bin(dmq1,
489 (unsigned char *)rsa_dmq1->d);
490 sw_param.up.crt.dmq1.value = (unsigned char *)rsa_dmq1->d;
491 sw_param.up.crt.iqmp.nbytes = BN_bn2bin(iqmp,
492 (unsigned char *)rsa_iqmp->d);
493 sw_param.up.crt.iqmp.value = (unsigned char *)rsa_iqmp->d;
494 /* Attach the key params */
495 sw_status = p_CSwift_AttachKeyParam(hac, &sw_param);
496 switch(sw_status)
497 {
498 case SW_OK:
499 break;
500 case SW_ERR_INPUT_SIZE:
501 ENGINEerr(ENGINE_F_CSWIFT_MOD_EXP_CRT,
502 ENGINE_R_SIZE_TOO_LARGE_OR_TOO_SMALL);
503 goto err;
504 default:
505 {
506 char tmpbuf[20];
507 ENGINEerr(ENGINE_F_CSWIFT_MOD_EXP_CRT,ENGINE_R_REQUEST_FAILED);
508 sprintf(tmpbuf, "%ld", sw_status);
509 ERR_add_error_data(2, "CryptoSwift error number is ",tmpbuf);
510 }
511 goto err;
512 }
513 /* Prepare the argument and response */
514 arg.nbytes = BN_bn2bin(a, (unsigned char *)argument->d);
515 arg.value = (unsigned char *)argument->d;
516 res.nbytes = 2 * BN_num_bytes(p);
517 memset(result->d, 0, res.nbytes);
518 res.value = (unsigned char *)result->d;
519 /* Perform the operation */
520 if((sw_status = p_CSwift_SimpleRequest(hac, SW_CMD_MODEXP_CRT, &arg, 1,
521 &res, 1)) != SW_OK)
522 {
523 char tmpbuf[20];
524 ENGINEerr(ENGINE_F_CSWIFT_MOD_EXP_CRT,ENGINE_R_REQUEST_FAILED);
525 sprintf(tmpbuf, "%ld", sw_status);
526 ERR_add_error_data(2, "CryptoSwift error number is ",tmpbuf);
527 goto err;
528 }
529 /* Convert the response */
530 BN_bin2bn((unsigned char *)result->d, res.nbytes, r);
531 to_return = 1;
532err:
533 if(acquired)
534 release_context(hac);
535 if(rsa_p) ctx->tos--;
536 if(rsa_q) ctx->tos--;
537 if(rsa_dmp1) ctx->tos--;
538 if(rsa_dmq1) ctx->tos--;
539 if(rsa_iqmp) ctx->tos--;
540 if(argument) ctx->tos--;
541 if(result) ctx->tos--;
542 return to_return;
543 }
544
545static int cswift_rsa_mod_exp(BIGNUM *r0, BIGNUM *I, RSA *rsa)
546 {
547 BN_CTX *ctx;
548 int to_return = 0;
549
550 if((ctx = BN_CTX_new()) == NULL)
551 goto err;
552 if(!rsa->p || !rsa->q || !rsa->dmp1 || !rsa->dmq1 || !rsa->iqmp)
553 {
554 ENGINEerr(ENGINE_F_CSWIFT_RSA_MOD_EXP,ENGINE_R_MISSING_KEY_COMPONENTS);
555 goto err;
556 }
557 to_return = cswift_mod_exp_crt(r0, I, rsa->p, rsa->q, rsa->dmp1,
558 rsa->dmq1, rsa->iqmp, ctx);
559err:
560 if(ctx)
561 BN_CTX_free(ctx);
562 return to_return;
563 }
564
565/* This function is aliased to mod_exp (with the mont stuff dropped). */
566static int cswift_mod_exp_mont(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
567 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx)
568 {
569 return cswift_mod_exp(r, a, p, m, ctx);
570 }
571
572static DSA_SIG *cswift_dsa_sign(const unsigned char *dgst, int dlen, DSA *dsa)
573 {
574 SW_CONTEXT_HANDLE hac;
575 SW_PARAM sw_param;
576 SW_STATUS sw_status;
577 SW_LARGENUMBER arg, res;
578 unsigned char *ptr;
579 BN_CTX *ctx;
580 BIGNUM *dsa_p = NULL;
581 BIGNUM *dsa_q = NULL;
582 BIGNUM *dsa_g = NULL;
583 BIGNUM *dsa_key = NULL;
584 BIGNUM *result = NULL;
585 DSA_SIG *to_return = NULL;
586 int acquired = 0;
587
588 if((ctx = BN_CTX_new()) == NULL)
589 goto err;
590 if(!get_context(&hac))
591 {
592 ENGINEerr(ENGINE_F_CSWIFT_DSA_SIGN,ENGINE_R_GET_HANDLE_FAILED);
593 goto err;
594 }
595 acquired = 1;
596 /* Prepare the params */
597 dsa_p = BN_CTX_get(ctx);
598 dsa_q = BN_CTX_get(ctx);
599 dsa_g = BN_CTX_get(ctx);
600 dsa_key = BN_CTX_get(ctx);
601 result = BN_CTX_get(ctx);
602 if(!dsa_p || !dsa_q || !dsa_g || !dsa_key || !result)
603 {
604 ENGINEerr(ENGINE_F_CSWIFT_DSA_SIGN,ENGINE_R_BN_CTX_FULL);
605 goto err;
606 }
607 if(!bn_wexpand(dsa_p, dsa->p->top) ||
608 !bn_wexpand(dsa_q, dsa->q->top) ||
609 !bn_wexpand(dsa_g, dsa->g->top) ||
610 !bn_wexpand(dsa_key, dsa->priv_key->top) ||
611 !bn_wexpand(result, dsa->p->top))
612 {
613 ENGINEerr(ENGINE_F_CSWIFT_DSA_SIGN,ENGINE_R_BN_EXPAND_FAIL);
614 goto err;
615 }
616 sw_param.type = SW_ALG_DSA;
617 sw_param.up.dsa.p.nbytes = BN_bn2bin(dsa->p,
618 (unsigned char *)dsa_p->d);
619 sw_param.up.dsa.p.value = (unsigned char *)dsa_p->d;
620 sw_param.up.dsa.q.nbytes = BN_bn2bin(dsa->q,
621 (unsigned char *)dsa_q->d);
622 sw_param.up.dsa.q.value = (unsigned char *)dsa_q->d;
623 sw_param.up.dsa.g.nbytes = BN_bn2bin(dsa->g,
624 (unsigned char *)dsa_g->d);
625 sw_param.up.dsa.g.value = (unsigned char *)dsa_g->d;
626 sw_param.up.dsa.key.nbytes = BN_bn2bin(dsa->priv_key,
627 (unsigned char *)dsa_key->d);
628 sw_param.up.dsa.key.value = (unsigned char *)dsa_key->d;
629 /* Attach the key params */
630 sw_status = p_CSwift_AttachKeyParam(hac, &sw_param);
631 switch(sw_status)
632 {
633 case SW_OK:
634 break;
635 case SW_ERR_INPUT_SIZE:
636 ENGINEerr(ENGINE_F_CSWIFT_DSA_SIGN,
637 ENGINE_R_SIZE_TOO_LARGE_OR_TOO_SMALL);
638 goto err;
639 default:
640 {
641 char tmpbuf[20];
642 ENGINEerr(ENGINE_F_CSWIFT_DSA_SIGN,ENGINE_R_REQUEST_FAILED);
643 sprintf(tmpbuf, "%ld", sw_status);
644 ERR_add_error_data(2, "CryptoSwift error number is ",tmpbuf);
645 }
646 goto err;
647 }
648 /* Prepare the argument and response */
649 arg.nbytes = dlen;
650 arg.value = (unsigned char *)dgst;
651 res.nbytes = BN_num_bytes(dsa->p);
652 memset(result->d, 0, res.nbytes);
653 res.value = (unsigned char *)result->d;
654 /* Perform the operation */
655 sw_status = p_CSwift_SimpleRequest(hac, SW_CMD_DSS_SIGN, &arg, 1,
656 &res, 1);
657 if(sw_status != SW_OK)
658 {
659 char tmpbuf[20];
660 ENGINEerr(ENGINE_F_CSWIFT_DSA_SIGN,ENGINE_R_REQUEST_FAILED);
661 sprintf(tmpbuf, "%ld", sw_status);
662 ERR_add_error_data(2, "CryptoSwift error number is ",tmpbuf);
663 goto err;
664 }
665 /* Convert the response */
666 ptr = (unsigned char *)result->d;
667 if((to_return = DSA_SIG_new()) == NULL)
668 goto err;
669 to_return->r = BN_bin2bn((unsigned char *)result->d, 20, NULL);
670 to_return->s = BN_bin2bn((unsigned char *)result->d + 20, 20, NULL);
671
672err:
673 if(acquired)
674 release_context(hac);
675 if(dsa_p) ctx->tos--;
676 if(dsa_q) ctx->tos--;
677 if(dsa_g) ctx->tos--;
678 if(dsa_key) ctx->tos--;
679 if(result) ctx->tos--;
680 if(ctx)
681 BN_CTX_free(ctx);
682 return to_return;
683 }
684
685static int cswift_dsa_verify(const unsigned char *dgst, int dgst_len,
686 DSA_SIG *sig, DSA *dsa)
687 {
688 SW_CONTEXT_HANDLE hac;
689 SW_PARAM sw_param;
690 SW_STATUS sw_status;
691 SW_LARGENUMBER arg[2], res;
692 unsigned long sig_result;
693 BN_CTX *ctx;
694 BIGNUM *dsa_p = NULL;
695 BIGNUM *dsa_q = NULL;
696 BIGNUM *dsa_g = NULL;
697 BIGNUM *dsa_key = NULL;
698 BIGNUM *argument = NULL;
699 int to_return = -1;
700 int acquired = 0;
701
702 if((ctx = BN_CTX_new()) == NULL)
703 goto err;
704 if(!get_context(&hac))
705 {
706 ENGINEerr(ENGINE_F_CSWIFT_DSA_VERIFY,ENGINE_R_GET_HANDLE_FAILED);
707 goto err;
708 }
709 acquired = 1;
710 /* Prepare the params */
711 dsa_p = BN_CTX_get(ctx);
712 dsa_q = BN_CTX_get(ctx);
713 dsa_g = BN_CTX_get(ctx);
714 dsa_key = BN_CTX_get(ctx);
715 argument = BN_CTX_get(ctx);
716 if(!dsa_p || !dsa_q || !dsa_g || !dsa_key || !argument)
717 {
718 ENGINEerr(ENGINE_F_CSWIFT_DSA_VERIFY,ENGINE_R_BN_CTX_FULL);
719 goto err;
720 }
721 if(!bn_wexpand(dsa_p, dsa->p->top) ||
722 !bn_wexpand(dsa_q, dsa->q->top) ||
723 !bn_wexpand(dsa_g, dsa->g->top) ||
724 !bn_wexpand(dsa_key, dsa->pub_key->top) ||
725 !bn_wexpand(argument, 40))
726 {
727 ENGINEerr(ENGINE_F_CSWIFT_DSA_VERIFY,ENGINE_R_BN_EXPAND_FAIL);
728 goto err;
729 }
730 sw_param.type = SW_ALG_DSA;
731 sw_param.up.dsa.p.nbytes = BN_bn2bin(dsa->p,
732 (unsigned char *)dsa_p->d);
733 sw_param.up.dsa.p.value = (unsigned char *)dsa_p->d;
734 sw_param.up.dsa.q.nbytes = BN_bn2bin(dsa->q,
735 (unsigned char *)dsa_q->d);
736 sw_param.up.dsa.q.value = (unsigned char *)dsa_q->d;
737 sw_param.up.dsa.g.nbytes = BN_bn2bin(dsa->g,
738 (unsigned char *)dsa_g->d);
739 sw_param.up.dsa.g.value = (unsigned char *)dsa_g->d;
740 sw_param.up.dsa.key.nbytes = BN_bn2bin(dsa->pub_key,
741 (unsigned char *)dsa_key->d);
742 sw_param.up.dsa.key.value = (unsigned char *)dsa_key->d;
743 /* Attach the key params */
744 sw_status = p_CSwift_AttachKeyParam(hac, &sw_param);
745 switch(sw_status)
746 {
747 case SW_OK:
748 break;
749 case SW_ERR_INPUT_SIZE:
750 ENGINEerr(ENGINE_F_CSWIFT_DSA_VERIFY,
751 ENGINE_R_SIZE_TOO_LARGE_OR_TOO_SMALL);
752 goto err;
753 default:
754 {
755 char tmpbuf[20];
756 ENGINEerr(ENGINE_F_CSWIFT_DSA_VERIFY,ENGINE_R_REQUEST_FAILED);
757 sprintf(tmpbuf, "%ld", sw_status);
758 ERR_add_error_data(2, "CryptoSwift error number is ",tmpbuf);
759 }
760 goto err;
761 }
762 /* Prepare the argument and response */
763 arg[0].nbytes = dgst_len;
764 arg[0].value = (unsigned char *)dgst;
765 arg[1].nbytes = 40;
766 arg[1].value = (unsigned char *)argument->d;
767 memset(arg[1].value, 0, 40);
768 BN_bn2bin(sig->r, arg[1].value + 20 - BN_num_bytes(sig->r));
769 BN_bn2bin(sig->s, arg[1].value + 40 - BN_num_bytes(sig->s));
770 res.nbytes = 4; /* unsigned long */
771 res.value = (unsigned char *)(&sig_result);
772 /* Perform the operation */
773 sw_status = p_CSwift_SimpleRequest(hac, SW_CMD_DSS_VERIFY, arg, 2,
774 &res, 1);
775 if(sw_status != SW_OK)
776 {
777 char tmpbuf[20];
778 ENGINEerr(ENGINE_F_CSWIFT_DSA_VERIFY,ENGINE_R_REQUEST_FAILED);
779 sprintf(tmpbuf, "%ld", sw_status);
780 ERR_add_error_data(2, "CryptoSwift error number is ",tmpbuf);
781 goto err;
782 }
783 /* Convert the response */
784 to_return = ((sig_result == 0) ? 0 : 1);
785
786err:
787 if(acquired)
788 release_context(hac);
789 if(dsa_p) ctx->tos--;
790 if(dsa_q) ctx->tos--;
791 if(dsa_g) ctx->tos--;
792 if(dsa_key) ctx->tos--;
793 if(argument) ctx->tos--;
794 if(ctx)
795 BN_CTX_free(ctx);
796 return to_return;
797 }
798
799/* This function is aliased to mod_exp (with the dh and mont dropped). */
800static int cswift_mod_exp_dh(DH *dh, BIGNUM *r, BIGNUM *a, const BIGNUM *p,
801 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx)
802 {
803 return cswift_mod_exp(r, a, p, m, ctx);
804 }
805
806#endif /* !NO_HW_CSWIFT */
807#endif /* !NO_HW */
diff --git a/src/lib/libcrypto/engine/hw_cswift_err.c b/src/lib/libcrypto/engine/hw_cswift_err.c
new file mode 100644
index 0000000000..684f53bf27
--- /dev/null
+++ b/src/lib/libcrypto/engine/hw_cswift_err.c
@@ -0,0 +1,149 @@
1/* hw_cswift_err.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file,
58 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include "hw_cswift_err.h"
64
65/* BEGIN ERROR CODES */
66#ifndef OPENSSL_NO_ERR
67static ERR_STRING_DATA CSWIFT_str_functs[]=
68 {
69{ERR_PACK(0,CSWIFT_F_CSWIFT_CTRL,0), "CSWIFT_CTRL"},
70{ERR_PACK(0,CSWIFT_F_CSWIFT_DSA_SIGN,0), "CSWIFT_DSA_SIGN"},
71{ERR_PACK(0,CSWIFT_F_CSWIFT_DSA_VERIFY,0), "CSWIFT_DSA_VERIFY"},
72{ERR_PACK(0,CSWIFT_F_CSWIFT_FINISH,0), "CSWIFT_FINISH"},
73{ERR_PACK(0,CSWIFT_F_CSWIFT_INIT,0), "CSWIFT_INIT"},
74{ERR_PACK(0,CSWIFT_F_CSWIFT_MOD_EXP,0), "CSWIFT_MOD_EXP"},
75{ERR_PACK(0,CSWIFT_F_CSWIFT_MOD_EXP_CRT,0), "CSWIFT_MOD_EXP_CRT"},
76{ERR_PACK(0,CSWIFT_F_CSWIFT_RSA_MOD_EXP,0), "CSWIFT_RSA_MOD_EXP"},
77{0,NULL}
78 };
79
80static ERR_STRING_DATA CSWIFT_str_reasons[]=
81 {
82{CSWIFT_R_ALREADY_LOADED ,"already loaded"},
83{CSWIFT_R_BAD_KEY_SIZE ,"bad key size"},
84{CSWIFT_R_BN_CTX_FULL ,"bn ctx full"},
85{CSWIFT_R_BN_EXPAND_FAIL ,"bn expand fail"},
86{CSWIFT_R_CTRL_COMMAND_NOT_IMPLEMENTED ,"ctrl command not implemented"},
87{CSWIFT_R_MISSING_KEY_COMPONENTS ,"missing key components"},
88{CSWIFT_R_NOT_LOADED ,"not loaded"},
89{CSWIFT_R_REQUEST_FAILED ,"request failed"},
90{CSWIFT_R_UNIT_FAILURE ,"unit failure"},
91{0,NULL}
92 };
93
94#endif
95
96#ifdef CSWIFT_LIB_NAME
97static ERR_STRING_DATA CSWIFT_lib_name[]=
98 {
99{0 ,CSWIFT_LIB_NAME},
100{0,NULL}
101 };
102#endif
103
104
105static int CSWIFT_lib_error_code=0;
106static int CSWIFT_error_init=1;
107
108static void ERR_load_CSWIFT_strings(void)
109 {
110 if (CSWIFT_lib_error_code == 0)
111 CSWIFT_lib_error_code=ERR_get_next_error_library();
112
113 if (CSWIFT_error_init)
114 {
115 CSWIFT_error_init=0;
116#ifndef OPENSSL_NO_ERR
117 ERR_load_strings(CSWIFT_lib_error_code,CSWIFT_str_functs);
118 ERR_load_strings(CSWIFT_lib_error_code,CSWIFT_str_reasons);
119#endif
120
121#ifdef CSWIFT_LIB_NAME
122 CSWIFT_lib_name->error = ERR_PACK(CSWIFT_lib_error_code,0,0);
123 ERR_load_strings(0,CSWIFT_lib_name);
124#endif
125 }
126 }
127
128static void ERR_unload_CSWIFT_strings(void)
129 {
130 if (CSWIFT_error_init == 0)
131 {
132#ifndef OPENSSL_NO_ERR
133 ERR_unload_strings(CSWIFT_lib_error_code,CSWIFT_str_functs);
134 ERR_unload_strings(CSWIFT_lib_error_code,CSWIFT_str_reasons);
135#endif
136
137#ifdef CSWIFT_LIB_NAME
138 ERR_unload_strings(0,CSWIFT_lib_name);
139#endif
140 CSWIFT_error_init=1;
141 }
142 }
143
144static void ERR_CSWIFT_error(int function, int reason, char *file, int line)
145 {
146 if (CSWIFT_lib_error_code == 0)
147 CSWIFT_lib_error_code=ERR_get_next_error_library();
148 ERR_PUT_error(CSWIFT_lib_error_code,function,reason,file,line);
149 }
diff --git a/src/lib/libcrypto/engine/hw_cswift_err.h b/src/lib/libcrypto/engine/hw_cswift_err.h
new file mode 100644
index 0000000000..7120c3216f
--- /dev/null
+++ b/src/lib/libcrypto/engine/hw_cswift_err.h
@@ -0,0 +1,93 @@
1/* ====================================================================
2 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * 3. All advertising materials mentioning features or use of this
17 * software must display the following acknowledgment:
18 * "This product includes software developed by the OpenSSL Project
19 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
20 *
21 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission. For written permission, please contact
24 * openssl-core@openssl.org.
25 *
26 * 5. Products derived from this software may not be called "OpenSSL"
27 * nor may "OpenSSL" appear in their names without prior written
28 * permission of the OpenSSL Project.
29 *
30 * 6. Redistributions of any form whatsoever must retain the following
31 * acknowledgment:
32 * "This product includes software developed by the OpenSSL Project
33 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46 * OF THE POSSIBILITY OF SUCH DAMAGE.
47 * ====================================================================
48 *
49 * This product includes cryptographic software written by Eric Young
50 * (eay@cryptsoft.com). This product includes software written by Tim
51 * Hudson (tjh@cryptsoft.com).
52 *
53 */
54
55#ifndef HEADER_CSWIFT_ERR_H
56#define HEADER_CSWIFT_ERR_H
57
58/* BEGIN ERROR CODES */
59/* The following lines are auto generated by the script mkerr.pl. Any changes
60 * made after this point may be overwritten when the script is next run.
61 */
62static void ERR_load_CSWIFT_strings(void);
63static void ERR_unload_CSWIFT_strings(void);
64static void ERR_CSWIFT_error(int function, int reason, char *file, int line);
65#define CSWIFTerr(f,r) ERR_CSWIFT_error((f),(r),__FILE__,__LINE__)
66
67/* Error codes for the CSWIFT functions. */
68
69/* Function codes. */
70#define CSWIFT_F_CSWIFT_CTRL 100
71#define CSWIFT_F_CSWIFT_DSA_SIGN 101
72#define CSWIFT_F_CSWIFT_DSA_VERIFY 102
73#define CSWIFT_F_CSWIFT_FINISH 103
74#define CSWIFT_F_CSWIFT_INIT 104
75#define CSWIFT_F_CSWIFT_MOD_EXP 105
76#define CSWIFT_F_CSWIFT_MOD_EXP_CRT 106
77#define CSWIFT_F_CSWIFT_RSA_MOD_EXP 107
78
79/* Reason codes. */
80#define CSWIFT_R_ALREADY_LOADED 100
81#define CSWIFT_R_BAD_KEY_SIZE 101
82#define CSWIFT_R_BN_CTX_FULL 102
83#define CSWIFT_R_BN_EXPAND_FAIL 103
84#define CSWIFT_R_CTRL_COMMAND_NOT_IMPLEMENTED 104
85#define CSWIFT_R_MISSING_KEY_COMPONENTS 105
86#define CSWIFT_R_NOT_LOADED 106
87#define CSWIFT_R_REQUEST_FAILED 107
88#define CSWIFT_R_UNIT_FAILURE 108
89
90#ifdef __cplusplus
91}
92#endif
93#endif
diff --git a/src/lib/libcrypto/engine/hw_ncipher.c b/src/lib/libcrypto/engine/hw_ncipher.c
new file mode 100644
index 0000000000..41f5900676
--- /dev/null
+++ b/src/lib/libcrypto/engine/hw_ncipher.c
@@ -0,0 +1,1019 @@
1/* crypto/engine/hw_ncipher.c -*- mode: C; c-file-style: "eay" -*- */
2/* Written by Richard Levitte (richard@levitte.org), Geoff Thorpe
3 * (geoff@geoffthorpe.net) and Dr Stephen N Henson (shenson@bigfoot.com)
4 * for the OpenSSL project 2000.
5 */
6/* ====================================================================
7 * Copyright (c) 1999 The OpenSSL Project. 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
18 * the documentation and/or other materials provided with the
19 * distribution.
20 *
21 * 3. All advertising materials mentioning features or use of this
22 * software must display the following acknowledgment:
23 * "This product includes software developed by the OpenSSL Project
24 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
25 *
26 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
27 * endorse or promote products derived from this software without
28 * prior written permission. For written permission, please contact
29 * licensing@OpenSSL.org.
30 *
31 * 5. Products derived from this software may not be called "OpenSSL"
32 * nor may "OpenSSL" appear in their names without prior written
33 * permission of the OpenSSL Project.
34 *
35 * 6. Redistributions of any form whatsoever must retain the following
36 * acknowledgment:
37 * "This product includes software developed by the OpenSSL Project
38 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
39 *
40 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
41 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
43 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
44 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
49 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
51 * OF THE POSSIBILITY OF SUCH DAMAGE.
52 * ====================================================================
53 *
54 * This product includes cryptographic software written by Eric Young
55 * (eay@cryptsoft.com). This product includes software written by Tim
56 * Hudson (tjh@cryptsoft.com).
57 *
58 */
59
60#include <stdio.h>
61#include <openssl/crypto.h>
62#include <openssl/pem.h>
63#include "cryptlib.h"
64#include <openssl/dso.h>
65#include "engine_int.h"
66#include <openssl/engine.h>
67
68#ifndef NO_HW
69#ifndef NO_HW_NCIPHER
70
71/* Attribution notice: nCipher have said several times that it's OK for
72 * us to implement a general interface to their boxes, and recently declared
73 * their HWCryptoHook to be public, and therefore available for us to use.
74 * Thanks, nCipher.
75 *
76 * The hwcryptohook.h included here is from May 2000.
77 * [Richard Levitte]
78 */
79#ifdef FLAT_INC
80#include "hwcryptohook.h"
81#else
82#include "vendor_defns/hwcryptohook.h"
83#endif
84
85static int hwcrhk_init(void);
86static int hwcrhk_finish(void);
87static int hwcrhk_ctrl(int cmd, long i, void *p, void (*f)());
88
89/* Functions to handle mutexes */
90static int hwcrhk_mutex_init(HWCryptoHook_Mutex*, HWCryptoHook_CallerContext*);
91static int hwcrhk_mutex_lock(HWCryptoHook_Mutex*);
92static void hwcrhk_mutex_unlock(HWCryptoHook_Mutex*);
93static void hwcrhk_mutex_destroy(HWCryptoHook_Mutex*);
94
95/* BIGNUM stuff */
96static int hwcrhk_mod_exp(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
97 const BIGNUM *m, BN_CTX *ctx);
98
99/* RSA stuff */
100static int hwcrhk_rsa_mod_exp(BIGNUM *r, BIGNUM *I, RSA *rsa);
101/* This function is aliased to mod_exp (with the mont stuff dropped). */
102static int hwcrhk_mod_exp_mont(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
103 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
104
105/* DH stuff */
106/* This function is alised to mod_exp (with the DH and mont dropped). */
107static int hwcrhk_mod_exp_dh(DH *dh, BIGNUM *r, BIGNUM *a, const BIGNUM *p,
108 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
109
110/* RAND stuff */
111static int hwcrhk_rand_bytes(unsigned char *buf, int num);
112static int hwcrhk_rand_status(void);
113
114/* KM stuff */
115static EVP_PKEY *hwcrhk_load_privkey(const char *key_id,
116 const char *passphrase);
117static EVP_PKEY *hwcrhk_load_pubkey(const char *key_id,
118 const char *passphrase);
119static void hwcrhk_ex_free(void *obj, void *item, CRYPTO_EX_DATA *ad,
120 int index,long argl, void *argp);
121
122/* Interaction stuff */
123static int hwcrhk_get_pass(const char *prompt_info,
124 int *len_io, char *buf,
125 HWCryptoHook_PassphraseContext *ppctx,
126 HWCryptoHook_CallerContext *cactx);
127static void hwcrhk_log_message(void *logstream, const char *message);
128
129/* Our internal RSA_METHOD that we provide pointers to */
130static RSA_METHOD hwcrhk_rsa =
131 {
132 "nCipher RSA method",
133 NULL,
134 NULL,
135 NULL,
136 NULL,
137 hwcrhk_rsa_mod_exp,
138 hwcrhk_mod_exp_mont,
139 NULL,
140 NULL,
141 0,
142 NULL,
143 NULL,
144 NULL
145 };
146
147/* Our internal DH_METHOD that we provide pointers to */
148static DH_METHOD hwcrhk_dh =
149 {
150 "nCipher DH method",
151 NULL,
152 NULL,
153 hwcrhk_mod_exp_dh,
154 NULL,
155 NULL,
156 0,
157 NULL
158 };
159
160static RAND_METHOD hwcrhk_rand =
161 {
162 /* "nCipher RAND method", */
163 NULL,
164 hwcrhk_rand_bytes,
165 NULL,
166 NULL,
167 hwcrhk_rand_bytes,
168 hwcrhk_rand_status,
169 };
170
171/* Our ENGINE structure. */
172static ENGINE engine_hwcrhk =
173 {
174 "chil",
175 "nCipher hardware engine support",
176 &hwcrhk_rsa,
177 NULL,
178 &hwcrhk_dh,
179 &hwcrhk_rand,
180 hwcrhk_mod_exp,
181 NULL,
182 hwcrhk_init,
183 hwcrhk_finish,
184 hwcrhk_ctrl,
185 hwcrhk_load_privkey,
186 hwcrhk_load_pubkey,
187 0, /* no flags */
188 0, 0, /* no references */
189 NULL, NULL /* unlinked */
190 };
191
192/* Internal stuff for HWCryptoHook */
193
194/* Some structures needed for proper use of thread locks */
195/* hwcryptohook.h has some typedefs that turn struct HWCryptoHook_MutexValue
196 into HWCryptoHook_Mutex */
197struct HWCryptoHook_MutexValue
198 {
199 int lockid;
200 };
201
202/* hwcryptohook.h has some typedefs that turn
203 struct HWCryptoHook_PassphraseContextValue
204 into HWCryptoHook_PassphraseContext */
205struct HWCryptoHook_PassphraseContextValue
206 {
207 void *any;
208 };
209
210/* hwcryptohook.h has some typedefs that turn
211 struct HWCryptoHook_CallerContextValue
212 into HWCryptoHook_CallerContext */
213struct HWCryptoHook_CallerContextValue
214 {
215 void *any;
216 };
217
218/* The MPI structure in HWCryptoHook is pretty compatible with OpenSSL
219 BIGNUM's, so lets define a couple of conversion macros */
220#define BN2MPI(mp, bn) \
221 {mp.size = bn->top * sizeof(BN_ULONG); mp.buf = (unsigned char *)bn->d;}
222#define MPI2BN(bn, mp) \
223 {mp.size = bn->dmax * sizeof(BN_ULONG); mp.buf = (unsigned char *)bn->d;}
224
225#if 0 /* Card and password management is not yet supported */
226/* HWCryptoHook callbacks. insert_card() and get_pass() are not yet
227 defined, because we haven't quite decided on the proper form yet.
228 log_message() just adds an entry in the error stack. I don't know
229 if that's good or bad... */
230static int insert_card(const char *prompt_info,
231 const char *wrong_info,
232 HWCryptoHook_PassphraseContext *ppctx,
233 HWCryptoHook_CallerContext *cactx);
234static int get_pass(const char *prompt_info,
235 int *len_io, char *buf,
236 HWCryptoHook_PassphraseContext *ppctx,
237 HWCryptoHook_CallerContext *cactx);
238#endif
239
240static BIO *logstream = NULL;
241static pem_password_cb *password_callback = NULL;
242#if 0
243static void *password_callback_userdata = NULL;
244#endif
245static int disable_mutex_callbacks = 0;
246
247/* Stuff to pass to the HWCryptoHook library */
248static HWCryptoHook_InitInfo hwcrhk_globals = {
249 0, /* Flags */
250 &logstream, /* logstream */
251 sizeof(BN_ULONG), /* limbsize */
252 0, /* mslimb first: false for BNs */
253 -1, /* msbyte first: use native */
254 0, /* Max mutexes, 0 = no small limit */
255 0, /* Max simultaneous, 0 = default */
256
257 /* The next few are mutex stuff: we write wrapper functions
258 around the OS mutex functions. We initialise them to 0
259 here, and change that to actual function pointers in hwcrhk_init()
260 if dynamic locks are supported (that is, if the application
261 programmer has made sure of setting up callbacks bafore starting
262 this engine) *and* if disable_mutex_callbacks hasn't been set by
263 a call to ENGINE_ctrl(ENGINE_CTRL_CHIL_NO_LOCKING). */
264 sizeof(HWCryptoHook_Mutex),
265 0,
266 0,
267 0,
268 0,
269
270 /* The next few are condvar stuff: we write wrapper functions
271 round the OS functions. Currently not implemented and not
272 and absolute necessity even in threaded programs, therefore
273 0'ed. Will hopefully be implemented some day, since it
274 enhances the efficiency of HWCryptoHook. */
275 0, /* sizeof(HWCryptoHook_CondVar), */
276 0, /* hwcrhk_cv_init, */
277 0, /* hwcrhk_cv_wait, */
278 0, /* hwcrhk_cv_signal, */
279 0, /* hwcrhk_cv_broadcast, */
280 0, /* hwcrhk_cv_destroy, */
281
282 hwcrhk_get_pass, /* pass phrase */
283 0, /* insert_card, */ /* insert a card */
284 hwcrhk_log_message /* Log message */
285};
286
287
288/* Now, to our own code */
289
290/* As this is only ever called once, there's no need for locking
291 * (indeed - the lock will already be held by our caller!!!) */
292ENGINE *ENGINE_ncipher()
293 {
294 RSA_METHOD *meth1;
295 DH_METHOD *meth2;
296
297 /* We know that the "PKCS1_SSLeay()" functions hook properly
298 * to the cswift-specific mod_exp and mod_exp_crt so we use
299 * those functions. NB: We don't use ENGINE_openssl() or
300 * anything "more generic" because something like the RSAref
301 * code may not hook properly, and if you own one of these
302 * cards then you have the right to do RSA operations on it
303 * anyway! */
304 meth1 = RSA_PKCS1_SSLeay();
305 hwcrhk_rsa.rsa_pub_enc = meth1->rsa_pub_enc;
306 hwcrhk_rsa.rsa_pub_dec = meth1->rsa_pub_dec;
307 hwcrhk_rsa.rsa_priv_enc = meth1->rsa_priv_enc;
308 hwcrhk_rsa.rsa_priv_dec = meth1->rsa_priv_dec;
309
310 /* Much the same for Diffie-Hellman */
311 meth2 = DH_OpenSSL();
312 hwcrhk_dh.generate_key = meth2->generate_key;
313 hwcrhk_dh.compute_key = meth2->compute_key;
314 return &engine_hwcrhk;
315 }
316
317/* This is a process-global DSO handle used for loading and unloading
318 * the HWCryptoHook library. NB: This is only set (or unset) during an
319 * init() or finish() call (reference counts permitting) and they're
320 * operating with global locks, so this should be thread-safe
321 * implicitly. */
322static DSO *hwcrhk_dso = NULL;
323static HWCryptoHook_ContextHandle hwcrhk_context = 0;
324static int hndidx = -1; /* Index for KM handle. Not really used yet. */
325
326/* These are the function pointers that are (un)set when the library has
327 * successfully (un)loaded. */
328static HWCryptoHook_Init_t *p_hwcrhk_Init = NULL;
329static HWCryptoHook_Finish_t *p_hwcrhk_Finish = NULL;
330static HWCryptoHook_ModExp_t *p_hwcrhk_ModExp = NULL;
331static HWCryptoHook_RSA_t *p_hwcrhk_RSA = NULL;
332static HWCryptoHook_RandomBytes_t *p_hwcrhk_RandomBytes = NULL;
333static HWCryptoHook_RSALoadKey_t *p_hwcrhk_RSALoadKey = NULL;
334static HWCryptoHook_RSAGetPublicKey_t *p_hwcrhk_RSAGetPublicKey = NULL;
335static HWCryptoHook_RSAUnloadKey_t *p_hwcrhk_RSAUnloadKey = NULL;
336static HWCryptoHook_ModExpCRT_t *p_hwcrhk_ModExpCRT = NULL;
337
338/* Used in the DSO operations. */
339static const char *HWCRHK_LIBNAME = "nfhwcrhk";
340static const char *n_hwcrhk_Init = "HWCryptoHook_Init";
341static const char *n_hwcrhk_Finish = "HWCryptoHook_Finish";
342static const char *n_hwcrhk_ModExp = "HWCryptoHook_ModExp";
343static const char *n_hwcrhk_RSA = "HWCryptoHook_RSA";
344static const char *n_hwcrhk_RandomBytes = "HWCryptoHook_RandomBytes";
345static const char *n_hwcrhk_RSALoadKey = "HWCryptoHook_RSALoadKey";
346static const char *n_hwcrhk_RSAGetPublicKey = "HWCryptoHook_RSAGetPublicKey";
347static const char *n_hwcrhk_RSAUnloadKey = "HWCryptoHook_RSAUnloadKey";
348static const char *n_hwcrhk_ModExpCRT = "HWCryptoHook_ModExpCRT";
349
350/* HWCryptoHook library functions and mechanics - these are used by the
351 * higher-level functions further down. NB: As and where there's no
352 * error checking, take a look lower down where these functions are
353 * called, the checking and error handling is probably down there. */
354
355/* utility function to obtain a context */
356static int get_context(HWCryptoHook_ContextHandle *hac)
357 {
358 char tempbuf[1024];
359 HWCryptoHook_ErrMsgBuf rmsg;
360
361 rmsg.buf = tempbuf;
362 rmsg.size = 1024;
363
364 *hac = p_hwcrhk_Init(&hwcrhk_globals, sizeof(hwcrhk_globals), &rmsg,
365 NULL);
366 if (!*hac)
367 return 0;
368 return 1;
369 }
370
371/* similarly to release one. */
372static void release_context(HWCryptoHook_ContextHandle hac)
373 {
374 p_hwcrhk_Finish(hac);
375 }
376
377/* (de)initialisation functions. */
378static int hwcrhk_init()
379 {
380 HWCryptoHook_Init_t *p1;
381 HWCryptoHook_Finish_t *p2;
382 HWCryptoHook_ModExp_t *p3;
383 HWCryptoHook_RSA_t *p4;
384 HWCryptoHook_RSALoadKey_t *p5;
385 HWCryptoHook_RSAGetPublicKey_t *p6;
386 HWCryptoHook_RSAUnloadKey_t *p7;
387 HWCryptoHook_RandomBytes_t *p8;
388 HWCryptoHook_ModExpCRT_t *p9;
389
390 if(hwcrhk_dso != NULL)
391 {
392 ENGINEerr(ENGINE_F_HWCRHK_INIT,ENGINE_R_ALREADY_LOADED);
393 goto err;
394 }
395 /* Attempt to load libnfhwcrhk.so/nfhwcrhk.dll/whatever. */
396 hwcrhk_dso = DSO_load(NULL, HWCRHK_LIBNAME, NULL,
397 DSO_FLAG_NAME_TRANSLATION);
398 if(hwcrhk_dso == NULL)
399 {
400 ENGINEerr(ENGINE_F_HWCRHK_INIT,ENGINE_R_DSO_FAILURE);
401 goto err;
402 }
403 if(!(p1 = (HWCryptoHook_Init_t *)
404 DSO_bind_func(hwcrhk_dso, n_hwcrhk_Init)) ||
405 !(p2 = (HWCryptoHook_Finish_t *)
406 DSO_bind_func(hwcrhk_dso, n_hwcrhk_Finish)) ||
407 !(p3 = (HWCryptoHook_ModExp_t *)
408 DSO_bind_func(hwcrhk_dso, n_hwcrhk_ModExp)) ||
409 !(p4 = (HWCryptoHook_RSA_t *)
410 DSO_bind_func(hwcrhk_dso, n_hwcrhk_RSA)) ||
411 !(p5 = (HWCryptoHook_RSALoadKey_t *)
412 DSO_bind_func(hwcrhk_dso, n_hwcrhk_RSALoadKey)) ||
413 !(p6 = (HWCryptoHook_RSAGetPublicKey_t *)
414 DSO_bind_func(hwcrhk_dso, n_hwcrhk_RSAGetPublicKey)) ||
415 !(p7 = (HWCryptoHook_RSAUnloadKey_t *)
416 DSO_bind_func(hwcrhk_dso, n_hwcrhk_RSAUnloadKey)) ||
417 !(p8 = (HWCryptoHook_RandomBytes_t *)
418 DSO_bind_func(hwcrhk_dso, n_hwcrhk_RandomBytes)) ||
419 !(p9 = (HWCryptoHook_ModExpCRT_t *)
420 DSO_bind_func(hwcrhk_dso, n_hwcrhk_ModExpCRT)))
421 {
422 ENGINEerr(ENGINE_F_HWCRHK_INIT,ENGINE_R_DSO_FAILURE);
423 goto err;
424 }
425 /* Copy the pointers */
426 p_hwcrhk_Init = p1;
427 p_hwcrhk_Finish = p2;
428 p_hwcrhk_ModExp = p3;
429 p_hwcrhk_RSA = p4;
430 p_hwcrhk_RSALoadKey = p5;
431 p_hwcrhk_RSAGetPublicKey = p6;
432 p_hwcrhk_RSAUnloadKey = p7;
433 p_hwcrhk_RandomBytes = p8;
434 p_hwcrhk_ModExpCRT = p9;
435
436 /* Check if the application decided to support dynamic locks,
437 and if it does, use them. */
438 if (disable_mutex_callbacks == 0 &&
439 CRYPTO_get_dynlock_create_callback() != NULL &&
440 CRYPTO_get_dynlock_lock_callback() != NULL &&
441 CRYPTO_get_dynlock_destroy_callback() != NULL)
442 {
443 hwcrhk_globals.mutex_init = hwcrhk_mutex_init;
444 hwcrhk_globals.mutex_acquire = hwcrhk_mutex_lock;
445 hwcrhk_globals.mutex_release = hwcrhk_mutex_unlock;
446 hwcrhk_globals.mutex_destroy = hwcrhk_mutex_destroy;
447 }
448
449 /* Try and get a context - if not, we may have a DSO but no
450 * accelerator! */
451 if(!get_context(&hwcrhk_context))
452 {
453 ENGINEerr(ENGINE_F_HWCRHK_INIT,ENGINE_R_UNIT_FAILURE);
454 goto err;
455 }
456 /* Everything's fine. */
457 if (hndidx == -1)
458 hndidx = RSA_get_ex_new_index(0,
459 "nFast HWCryptoHook RSA key handle",
460 NULL, NULL, hwcrhk_ex_free);
461 return 1;
462err:
463 if(hwcrhk_dso)
464 DSO_free(hwcrhk_dso);
465 hwcrhk_dso = NULL;
466 p_hwcrhk_Init = NULL;
467 p_hwcrhk_Finish = NULL;
468 p_hwcrhk_ModExp = NULL;
469 p_hwcrhk_RSA = NULL;
470 p_hwcrhk_RSALoadKey = NULL;
471 p_hwcrhk_RSAGetPublicKey = NULL;
472 p_hwcrhk_RSAUnloadKey = NULL;
473 p_hwcrhk_ModExpCRT = NULL;
474 p_hwcrhk_RandomBytes = NULL;
475 return 0;
476 }
477
478static int hwcrhk_finish()
479 {
480 int to_return = 1;
481 if(hwcrhk_dso == NULL)
482 {
483 ENGINEerr(ENGINE_F_HWCRHK_FINISH,ENGINE_R_NOT_LOADED);
484 to_return = 0;
485 goto err;
486 }
487 release_context(hwcrhk_context);
488 if(!DSO_free(hwcrhk_dso))
489 {
490 ENGINEerr(ENGINE_F_HWCRHK_FINISH,ENGINE_R_DSO_FAILURE);
491 to_return = 0;
492 goto err;
493 }
494 err:
495 if (logstream)
496 BIO_free(logstream);
497 hwcrhk_dso = NULL;
498 p_hwcrhk_Init = NULL;
499 p_hwcrhk_Finish = NULL;
500 p_hwcrhk_ModExp = NULL;
501 p_hwcrhk_RSA = NULL;
502 p_hwcrhk_RSALoadKey = NULL;
503 p_hwcrhk_RSAGetPublicKey = NULL;
504 p_hwcrhk_RSAUnloadKey = NULL;
505 p_hwcrhk_ModExpCRT = NULL;
506 p_hwcrhk_RandomBytes = NULL;
507 return to_return;
508 }
509
510static int hwcrhk_ctrl(int cmd, long i, void *p, void (*f)())
511 {
512 int to_return = 1;
513
514 switch(cmd)
515 {
516 case ENGINE_CTRL_SET_LOGSTREAM:
517 {
518 BIO *bio = (BIO *)p;
519
520 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
521 if (logstream)
522 {
523 BIO_free(logstream);
524 logstream = NULL;
525 }
526 if (CRYPTO_add(&bio->references,1,CRYPTO_LOCK_BIO) > 1)
527 logstream = bio;
528 else
529 ENGINEerr(ENGINE_F_HWCRHK_CTRL,ENGINE_R_BIO_WAS_FREED);
530 }
531 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
532 break;
533 case ENGINE_CTRL_SET_PASSWORD_CALLBACK:
534 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
535 password_callback = (pem_password_cb *)f;
536 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
537 break;
538 /* this enables or disables the "SimpleForkCheck" flag used in the
539 * initialisation structure. */
540 case ENGINE_CTRL_CHIL_SET_FORKCHECK:
541 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
542 if(i)
543 hwcrhk_globals.flags |=
544 HWCryptoHook_InitFlags_SimpleForkCheck;
545 else
546 hwcrhk_globals.flags &=
547 ~HWCryptoHook_InitFlags_SimpleForkCheck;
548 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
549 break;
550 /* This will prevent the initialisation function from "installing"
551 * the mutex-handling callbacks, even if they are available from
552 * within the library (or were provided to the library from the
553 * calling application). This is to remove any baggage for
554 * applications not using multithreading. */
555 case ENGINE_CTRL_CHIL_NO_LOCKING:
556 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
557 disable_mutex_callbacks = 1;
558 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
559 break;
560
561 /* The command isn't understood by this engine */
562 default:
563 ENGINEerr(ENGINE_F_HWCRHK_CTRL,
564 ENGINE_R_CTRL_COMMAND_NOT_IMPLEMENTED);
565 to_return = 0;
566 break;
567 }
568
569 return to_return;
570 }
571
572static EVP_PKEY *hwcrhk_load_privkey(const char *key_id,
573 const char *passphrase)
574 {
575 RSA *rtmp = NULL;
576 EVP_PKEY *res = NULL;
577 HWCryptoHook_MPI e, n;
578 HWCryptoHook_RSAKeyHandle *hptr;
579 HWCryptoHook_ErrMsgBuf rmsg;
580
581 if(!hwcrhk_context)
582 {
583 ENGINEerr(ENGINE_F_HWCRHK_LOAD_PRIVKEY,
584 ENGINE_R_NOT_INITIALISED);
585 goto err;
586 }
587 hptr = OPENSSL_malloc(sizeof(HWCryptoHook_RSAKeyHandle));
588 if (!hptr)
589 {
590 ENGINEerr(ENGINE_F_HWCRHK_LOAD_PRIVKEY,
591 ERR_R_MALLOC_FAILURE);
592 goto err;
593 }
594 if (p_hwcrhk_RSALoadKey(hwcrhk_context, key_id, hptr,
595 &rmsg, NULL))
596 {
597 ENGINEerr(ENGINE_F_HWCRHK_LOAD_PRIVKEY,
598 ENGINE_R_CHIL_ERROR);
599 ERR_add_error_data(1,rmsg.buf);
600 goto err;
601 }
602 if (!*hptr)
603 {
604 ENGINEerr(ENGINE_F_HWCRHK_LOAD_PRIVKEY,
605 ENGINE_R_NO_KEY);
606 goto err;
607 }
608 rtmp = RSA_new_method(&engine_hwcrhk);
609 RSA_set_ex_data(rtmp, hndidx, (char *)hptr);
610 rtmp->e = BN_new();
611 rtmp->n = BN_new();
612 rtmp->flags |= RSA_FLAG_EXT_PKEY;
613 MPI2BN(rtmp->e, e);
614 MPI2BN(rtmp->n, n);
615 if (p_hwcrhk_RSAGetPublicKey(*hptr, &n, &e, &rmsg)
616 != HWCRYPTOHOOK_ERROR_MPISIZE)
617 {
618 ENGINEerr(ENGINE_F_HWCRHK_LOAD_PUBKEY,ENGINE_R_CHIL_ERROR);
619 ERR_add_error_data(1,rmsg.buf);
620 goto err;
621 }
622
623 bn_expand2(rtmp->e, e.size/sizeof(BN_ULONG));
624 bn_expand2(rtmp->n, n.size/sizeof(BN_ULONG));
625 MPI2BN(rtmp->e, e);
626 MPI2BN(rtmp->n, n);
627
628 if (p_hwcrhk_RSAGetPublicKey(*hptr, &n, &e, &rmsg))
629 {
630 ENGINEerr(ENGINE_F_HWCRHK_LOAD_PUBKEY,
631 ENGINE_R_CHIL_ERROR);
632 ERR_add_error_data(1,rmsg.buf);
633 goto err;
634 }
635 rtmp->e->top = e.size / sizeof(BN_ULONG);
636 bn_fix_top(rtmp->e);
637 rtmp->n->top = n.size / sizeof(BN_ULONG);
638 bn_fix_top(rtmp->n);
639
640 res = EVP_PKEY_new();
641 EVP_PKEY_assign_RSA(res, rtmp);
642
643 return res;
644 err:
645 if (res)
646 EVP_PKEY_free(res);
647 if (rtmp)
648 RSA_free(rtmp);
649 return NULL;
650 }
651
652static EVP_PKEY *hwcrhk_load_pubkey(const char *key_id, const char *passphrase)
653 {
654 EVP_PKEY *res = hwcrhk_load_privkey(key_id, passphrase);
655
656 if (res)
657 switch(res->type)
658 {
659 case EVP_PKEY_RSA:
660 {
661 RSA *rsa = NULL;
662
663 CRYPTO_w_lock(CRYPTO_LOCK_EVP_PKEY);
664 rsa = res->pkey.rsa;
665 res->pkey.rsa = RSA_new();
666 res->pkey.rsa->n = rsa->n;
667 res->pkey.rsa->e = rsa->e;
668 CRYPTO_w_unlock(CRYPTO_LOCK_EVP_PKEY);
669 RSA_free(rsa);
670 }
671 default:
672 ENGINEerr(ENGINE_F_HWCRHK_LOAD_PUBKEY,
673 ENGINE_R_CTRL_COMMAND_NOT_IMPLEMENTED);
674 goto err;
675 }
676
677 return res;
678 err:
679 if (res)
680 EVP_PKEY_free(res);
681 return NULL;
682 }
683
684/* A little mod_exp */
685static int hwcrhk_mod_exp(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
686 const BIGNUM *m, BN_CTX *ctx)
687 {
688 char tempbuf[1024];
689 HWCryptoHook_ErrMsgBuf rmsg;
690 /* Since HWCryptoHook_MPI is pretty compatible with BIGNUM's,
691 we use them directly, plus a little macro magic. We only
692 thing we need to make sure of is that enough space is allocated. */
693 HWCryptoHook_MPI m_a, m_p, m_n, m_r;
694 int to_return, ret;
695
696 to_return = 0; /* expect failure */
697 rmsg.buf = tempbuf;
698 rmsg.size = 1024;
699
700 if(!hwcrhk_context)
701 {
702 ENGINEerr(ENGINE_F_HWCRHK_MOD_EXP,ENGINE_R_NOT_INITIALISED);
703 goto err;
704 }
705 /* Prepare the params */
706 bn_expand2(r, m->top); /* Check for error !! */
707 BN2MPI(m_a, a);
708 BN2MPI(m_p, p);
709 BN2MPI(m_n, m);
710 MPI2BN(r, m_r);
711
712 /* Perform the operation */
713 ret = p_hwcrhk_ModExp(hwcrhk_context, m_a, m_p, m_n, &m_r, &rmsg);
714
715 /* Convert the response */
716 r->top = m_r.size / sizeof(BN_ULONG);
717 bn_fix_top(r);
718
719 if (ret < 0)
720 {
721 /* FIXME: When this error is returned, HWCryptoHook is
722 telling us that falling back to software computation
723 might be a good thing. */
724 if(ret == HWCRYPTOHOOK_ERROR_FALLBACK)
725 {
726 ENGINEerr(ENGINE_F_HWCRHK_MOD_EXP,ENGINE_R_REQUEST_FALLBACK);
727 }
728 else
729 {
730 ENGINEerr(ENGINE_F_HWCRHK_MOD_EXP,ENGINE_R_REQUEST_FAILED);
731 }
732 ERR_add_error_data(1,rmsg.buf);
733 goto err;
734 }
735
736 to_return = 1;
737err:
738 return to_return;
739 }
740
741static int hwcrhk_rsa_mod_exp(BIGNUM *r, BIGNUM *I, RSA *rsa)
742 {
743 char tempbuf[1024];
744 HWCryptoHook_ErrMsgBuf rmsg;
745 HWCryptoHook_RSAKeyHandle *hptr;
746 int to_return = 0, ret;
747
748 if(!hwcrhk_context)
749 {
750 ENGINEerr(ENGINE_F_HWCRHK_MOD_EXP,ENGINE_R_NOT_INITIALISED);
751 goto err;
752 }
753
754 /* This provides support for nForce keys. Since that's opaque data
755 all we do is provide a handle to the proper key and let HWCryptoHook
756 take care of the rest. */
757 if ((hptr = (HWCryptoHook_RSAKeyHandle *) RSA_get_ex_data(rsa, hndidx))
758 != NULL)
759 {
760 HWCryptoHook_MPI m_a, m_r;
761
762 if(!rsa->n)
763 {
764 ENGINEerr(ENGINE_F_HWCRHK_RSA_MOD_EXP,
765 ENGINE_R_MISSING_KEY_COMPONENTS);
766 goto err;
767 }
768
769 rmsg.buf = tempbuf;
770 rmsg.size = 1024;
771
772 /* Prepare the params */
773 bn_expand2(r, rsa->n->top); /* Check for error !! */
774 BN2MPI(m_a, I);
775 MPI2BN(r, m_r);
776
777 /* Perform the operation */
778 ret = p_hwcrhk_RSA(m_a, *hptr, &m_r, &rmsg);
779
780 /* Convert the response */
781 r->top = m_r.size / sizeof(BN_ULONG);
782 bn_fix_top(r);
783
784 if (ret < 0)
785 {
786 /* FIXME: When this error is returned, HWCryptoHook is
787 telling us that falling back to software computation
788 might be a good thing. */
789 if(ret == HWCRYPTOHOOK_ERROR_FALLBACK)
790 {
791 ENGINEerr(ENGINE_F_HWCRHK_RSA_MOD_EXP,ENGINE_R_REQUEST_FALLBACK);
792 }
793 else
794 {
795 ENGINEerr(ENGINE_F_HWCRHK_RSA_MOD_EXP,ENGINE_R_REQUEST_FAILED);
796 }
797 ERR_add_error_data(1,rmsg.buf);
798 goto err;
799 }
800 }
801 else
802 {
803 HWCryptoHook_MPI m_a, m_p, m_q, m_dmp1, m_dmq1, m_iqmp, m_r;
804
805 if(!rsa->p || !rsa->q || !rsa->dmp1 || !rsa->dmq1 || !rsa->iqmp)
806 {
807 ENGINEerr(ENGINE_F_HWCRHK_RSA_MOD_EXP,
808 ENGINE_R_MISSING_KEY_COMPONENTS);
809 goto err;
810 }
811
812 rmsg.buf = tempbuf;
813 rmsg.size = 1024;
814
815 /* Prepare the params */
816 bn_expand2(r, rsa->n->top); /* Check for error !! */
817 BN2MPI(m_a, I);
818 BN2MPI(m_p, rsa->p);
819 BN2MPI(m_q, rsa->q);
820 BN2MPI(m_dmp1, rsa->dmp1);
821 BN2MPI(m_dmq1, rsa->dmq1);
822 BN2MPI(m_iqmp, rsa->iqmp);
823 MPI2BN(r, m_r);
824
825 /* Perform the operation */
826 ret = p_hwcrhk_ModExpCRT(hwcrhk_context, m_a, m_p, m_q,
827 m_dmp1, m_dmq1, m_iqmp, &m_r, NULL);
828
829 /* Convert the response */
830 r->top = m_r.size / sizeof(BN_ULONG);
831 bn_fix_top(r);
832
833 if (ret < 0)
834 {
835 /* FIXME: When this error is returned, HWCryptoHook is
836 telling us that falling back to software computation
837 might be a good thing. */
838 if(ret == HWCRYPTOHOOK_ERROR_FALLBACK)
839 {
840 ENGINEerr(ENGINE_F_HWCRHK_RSA_MOD_EXP,ENGINE_R_REQUEST_FALLBACK);
841 }
842 else
843 {
844 ENGINEerr(ENGINE_F_HWCRHK_RSA_MOD_EXP,ENGINE_R_REQUEST_FAILED);
845 }
846 ERR_add_error_data(1,rmsg.buf);
847 goto err;
848 }
849 }
850 /* If we're here, we must be here with some semblance of success :-) */
851 to_return = 1;
852err:
853 return to_return;
854 }
855
856/* This function is aliased to mod_exp (with the mont stuff dropped). */
857static int hwcrhk_mod_exp_mont(BIGNUM *r, BIGNUM *a, const BIGNUM *p,
858 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx)
859 {
860 return hwcrhk_mod_exp(r, a, p, m, ctx);
861 }
862
863/* This function is aliased to mod_exp (with the dh and mont dropped). */
864static int hwcrhk_mod_exp_dh(DH *dh, BIGNUM *r, BIGNUM *a, const BIGNUM *p,
865 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx)
866 {
867 return hwcrhk_mod_exp(r, a, p, m, ctx);
868 }
869
870/* Random bytes are good */
871static int hwcrhk_rand_bytes(unsigned char *buf, int num)
872 {
873 char tempbuf[1024];
874 HWCryptoHook_ErrMsgBuf rmsg;
875 int to_return = 0; /* assume failure */
876 int ret;
877
878 rmsg.buf = tempbuf;
879 rmsg.size = 1024;
880
881 if(!hwcrhk_context)
882 {
883 ENGINEerr(ENGINE_F_HWCRHK_RAND_BYTES,ENGINE_R_NOT_INITIALISED);
884 goto err;
885 }
886
887 ret = p_hwcrhk_RandomBytes(hwcrhk_context, buf, num, &rmsg);
888 if (ret < 0)
889 {
890 /* FIXME: When this error is returned, HWCryptoHook is
891 telling us that falling back to software computation
892 might be a good thing. */
893 if(ret == HWCRYPTOHOOK_ERROR_FALLBACK)
894 {
895 ENGINEerr(ENGINE_F_HWCRHK_RAND_BYTES,ENGINE_R_REQUEST_FALLBACK);
896 }
897 else
898 {
899 ENGINEerr(ENGINE_F_HWCRHK_RAND_BYTES,ENGINE_R_REQUEST_FAILED);
900 }
901 ERR_add_error_data(1,rmsg.buf);
902 goto err;
903 }
904 to_return = 1;
905 err:
906 return to_return;
907 }
908
909static int hwcrhk_rand_status(void)
910 {
911 return 1;
912 }
913
914/* This cleans up an RSA KM key, called when ex_data is freed */
915
916static void hwcrhk_ex_free(void *obj, void *item, CRYPTO_EX_DATA *ad,
917 int index,long argl, void *argp)
918{
919 char tempbuf[1024];
920 HWCryptoHook_ErrMsgBuf rmsg;
921 HWCryptoHook_RSAKeyHandle *hptr;
922 int ret;
923
924 rmsg.buf = tempbuf;
925 rmsg.size = 1024;
926
927 hptr = (HWCryptoHook_RSAKeyHandle *) item;
928 if(!hptr) return;
929 ret = p_hwcrhk_RSAUnloadKey(*hptr, NULL);
930 OPENSSL_free(hptr);
931}
932
933/* Mutex calls: since the HWCryptoHook model closely follows the POSIX model
934 * these just wrap the POSIX functions and add some logging.
935 */
936
937static int hwcrhk_mutex_init(HWCryptoHook_Mutex* mt,
938 HWCryptoHook_CallerContext *cactx)
939 {
940 mt->lockid = CRYPTO_get_new_dynlockid();
941 if (mt->lockid == 0)
942 return 0;
943 return 1;
944 }
945
946static int hwcrhk_mutex_lock(HWCryptoHook_Mutex *mt)
947 {
948 CRYPTO_w_lock(mt->lockid);
949 return 1;
950 }
951
952void hwcrhk_mutex_unlock(HWCryptoHook_Mutex * mt)
953 {
954 CRYPTO_w_unlock(mt->lockid);
955 }
956
957static void hwcrhk_mutex_destroy(HWCryptoHook_Mutex *mt)
958 {
959 CRYPTO_destroy_dynlockid(mt->lockid);
960 }
961
962static int hwcrhk_get_pass(const char *prompt_info,
963 int *len_io, char *buf,
964 HWCryptoHook_PassphraseContext *ppctx,
965 HWCryptoHook_CallerContext *cactx)
966 {
967 int l = 0;
968 char prompt[1024];
969
970 if (password_callback == NULL)
971 {
972 ENGINEerr(ENGINE_F_HWCRHK_GET_PASS,ENGINE_R_NO_CALLBACK);
973 return -1;
974 }
975 if (prompt_info)
976 {
977 strncpy(prompt, "Card: \"", sizeof(prompt));
978 l += 5;
979 strncpy(prompt + l, prompt_info, sizeof(prompt) - l);
980 l += strlen(prompt_info);
981 if (l + 2 < sizeof(prompt))
982 {
983 strncpy(prompt + l, "\"\n", sizeof(prompt) - l);
984 l += 2;
985 }
986 }
987 if (l < sizeof(prompt) - 1)
988 {
989 strncpy(prompt, "Enter Passphrase <enter to cancel>:",
990 sizeof(prompt) - l);
991 l += 35;
992 }
993 prompt[l] = '\0';
994
995 /* I know, passing on the prompt instead of the user data *is*
996 a bad thing. However, that's all we have right now.
997 -- Richard Levitte */
998 *len_io = password_callback(buf, *len_io, 0, prompt);
999 if(!*len_io)
1000 return -1;
1001 return 0;
1002 }
1003
1004static void hwcrhk_log_message(void *logstream, const char *message)
1005 {
1006 BIO *lstream = NULL;
1007
1008 CRYPTO_w_lock(CRYPTO_LOCK_BIO);
1009 if (logstream)
1010 lstream=*(BIO **)logstream;
1011 if (lstream)
1012 {
1013 BIO_write(lstream, message, strlen(message));
1014 }
1015 CRYPTO_w_unlock(CRYPTO_LOCK_BIO);
1016 }
1017
1018#endif /* !NO_HW_NCIPHER */
1019#endif /* !NO_HW */
diff --git a/src/lib/libcrypto/engine/hw_ncipher_err.c b/src/lib/libcrypto/engine/hw_ncipher_err.c
new file mode 100644
index 0000000000..24024cfc6f
--- /dev/null
+++ b/src/lib/libcrypto/engine/hw_ncipher_err.c
@@ -0,0 +1,156 @@
1/* hw_ncipher_err.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file,
58 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include "hw_ncipher_err.h"
64
65/* BEGIN ERROR CODES */
66#ifndef OPENSSL_NO_ERR
67static ERR_STRING_DATA HWCRHK_str_functs[]=
68 {
69{ERR_PACK(0,HWCRHK_F_HWCRHK_CTRL,0), "HWCRHK_CTRL"},
70{ERR_PACK(0,HWCRHK_F_HWCRHK_FINISH,0), "HWCRHK_FINISH"},
71{ERR_PACK(0,HWCRHK_F_HWCRHK_GET_PASS,0), "HWCRHK_GET_PASS"},
72{ERR_PACK(0,HWCRHK_F_HWCRHK_INIT,0), "HWCRHK_INIT"},
73{ERR_PACK(0,HWCRHK_F_HWCRHK_INSERT_CARD,0), "HWCRHK_INSERT_CARD"},
74{ERR_PACK(0,HWCRHK_F_HWCRHK_LOAD_PRIVKEY,0), "HWCRHK_LOAD_PRIVKEY"},
75{ERR_PACK(0,HWCRHK_F_HWCRHK_LOAD_PUBKEY,0), "HWCRHK_LOAD_PUBKEY"},
76{ERR_PACK(0,HWCRHK_F_HWCRHK_MOD_EXP,0), "HWCRHK_MOD_EXP"},
77{ERR_PACK(0,HWCRHK_F_HWCRHK_RAND_BYTES,0), "HWCRHK_RAND_BYTES"},
78{ERR_PACK(0,HWCRHK_F_HWCRHK_RSA_MOD_EXP,0), "HWCRHK_RSA_MOD_EXP"},
79{0,NULL}
80 };
81
82static ERR_STRING_DATA HWCRHK_str_reasons[]=
83 {
84{HWCRHK_R_ALREADY_LOADED ,"already loaded"},
85{HWCRHK_R_BIO_WAS_FREED ,"bio was freed"},
86{HWCRHK_R_CHIL_ERROR ,"chil error"},
87{HWCRHK_R_CTRL_COMMAND_NOT_IMPLEMENTED ,"ctrl command not implemented"},
88{HWCRHK_R_DSO_FAILURE ,"dso failure"},
89{HWCRHK_R_MISSING_KEY_COMPONENTS ,"missing key components"},
90{HWCRHK_R_NOT_INITIALISED ,"not initialised"},
91{HWCRHK_R_NOT_LOADED ,"not loaded"},
92{HWCRHK_R_NO_CALLBACK ,"no callback"},
93{HWCRHK_R_NO_KEY ,"no key"},
94{HWCRHK_R_PRIVATE_KEY_ALGORITHMS_DISABLED,"private key algorithms disabled"},
95{HWCRHK_R_REQUEST_FAILED ,"request failed"},
96{HWCRHK_R_REQUEST_FALLBACK ,"request fallback"},
97{HWCRHK_R_UNIT_FAILURE ,"unit failure"},
98{0,NULL}
99 };
100
101#endif
102
103#ifdef HWCRHK_LIB_NAME
104static ERR_STRING_DATA HWCRHK_lib_name[]=
105 {
106{0 ,HWCRHK_LIB_NAME},
107{0,NULL}
108 };
109#endif
110
111
112static int HWCRHK_lib_error_code=0;
113static int HWCRHK_error_init=1;
114
115static void ERR_load_HWCRHK_strings(void)
116 {
117 if (HWCRHK_lib_error_code == 0)
118 HWCRHK_lib_error_code=ERR_get_next_error_library();
119
120 if (HWCRHK_error_init)
121 {
122 HWCRHK_error_init=0;
123#ifndef OPENSSL_NO_ERR
124 ERR_load_strings(HWCRHK_lib_error_code,HWCRHK_str_functs);
125 ERR_load_strings(HWCRHK_lib_error_code,HWCRHK_str_reasons);
126#endif
127
128#ifdef HWCRHK_LIB_NAME
129 HWCRHK_lib_name->error = ERR_PACK(HWCRHK_lib_error_code,0,0);
130 ERR_load_strings(0,HWCRHK_lib_name);
131#endif
132 }
133 }
134
135static void ERR_unload_HWCRHK_strings(void)
136 {
137 if (HWCRHK_error_init == 0)
138 {
139#ifndef OPENSSL_NO_ERR
140 ERR_unload_strings(HWCRHK_lib_error_code,HWCRHK_str_functs);
141 ERR_unload_strings(HWCRHK_lib_error_code,HWCRHK_str_reasons);
142#endif
143
144#ifdef HWCRHK_LIB_NAME
145 ERR_unload_strings(0,HWCRHK_lib_name);
146#endif
147 HWCRHK_error_init=1;
148 }
149 }
150
151static void ERR_HWCRHK_error(int function, int reason, char *file, int line)
152 {
153 if (HWCRHK_lib_error_code == 0)
154 HWCRHK_lib_error_code=ERR_get_next_error_library();
155 ERR_PUT_error(HWCRHK_lib_error_code,function,reason,file,line);
156 }
diff --git a/src/lib/libcrypto/engine/hw_ncipher_err.h b/src/lib/libcrypto/engine/hw_ncipher_err.h
new file mode 100644
index 0000000000..4d65b1d470
--- /dev/null
+++ b/src/lib/libcrypto/engine/hw_ncipher_err.h
@@ -0,0 +1,100 @@
1/* ====================================================================
2 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * 3. All advertising materials mentioning features or use of this
17 * software must display the following acknowledgment:
18 * "This product includes software developed by the OpenSSL Project
19 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
20 *
21 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission. For written permission, please contact
24 * openssl-core@openssl.org.
25 *
26 * 5. Products derived from this software may not be called "OpenSSL"
27 * nor may "OpenSSL" appear in their names without prior written
28 * permission of the OpenSSL Project.
29 *
30 * 6. Redistributions of any form whatsoever must retain the following
31 * acknowledgment:
32 * "This product includes software developed by the OpenSSL Project
33 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46 * OF THE POSSIBILITY OF SUCH DAMAGE.
47 * ====================================================================
48 *
49 * This product includes cryptographic software written by Eric Young
50 * (eay@cryptsoft.com). This product includes software written by Tim
51 * Hudson (tjh@cryptsoft.com).
52 *
53 */
54
55#ifndef HEADER_HWCRHK_ERR_H
56#define HEADER_HWCRHK_ERR_H
57
58/* BEGIN ERROR CODES */
59/* The following lines are auto generated by the script mkerr.pl. Any changes
60 * made after this point may be overwritten when the script is next run.
61 */
62static void ERR_load_HWCRHK_strings(void);
63static void ERR_unload_HWCRHK_strings(void);
64static void ERR_HWCRHK_error(int function, int reason, char *file, int line);
65#define HWCRHKerr(f,r) ERR_HWCRHK_error((f),(r),__FILE__,__LINE__)
66
67/* Error codes for the HWCRHK functions. */
68
69/* Function codes. */
70#define HWCRHK_F_HWCRHK_CTRL 100
71#define HWCRHK_F_HWCRHK_FINISH 101
72#define HWCRHK_F_HWCRHK_GET_PASS 102
73#define HWCRHK_F_HWCRHK_INIT 103
74#define HWCRHK_F_HWCRHK_INSERT_CARD 104
75#define HWCRHK_F_HWCRHK_LOAD_PRIVKEY 105
76#define HWCRHK_F_HWCRHK_LOAD_PUBKEY 106
77#define HWCRHK_F_HWCRHK_MOD_EXP 107
78#define HWCRHK_F_HWCRHK_RAND_BYTES 108
79#define HWCRHK_F_HWCRHK_RSA_MOD_EXP 109
80
81/* Reason codes. */
82#define HWCRHK_R_ALREADY_LOADED 100
83#define HWCRHK_R_BIO_WAS_FREED 101
84#define HWCRHK_R_CHIL_ERROR 102
85#define HWCRHK_R_CTRL_COMMAND_NOT_IMPLEMENTED 103
86#define HWCRHK_R_DSO_FAILURE 104
87#define HWCRHK_R_MISSING_KEY_COMPONENTS 105
88#define HWCRHK_R_NOT_INITIALISED 106
89#define HWCRHK_R_NOT_LOADED 107
90#define HWCRHK_R_NO_CALLBACK 108
91#define HWCRHK_R_NO_KEY 109
92#define HWCRHK_R_PRIVATE_KEY_ALGORITHMS_DISABLED 110
93#define HWCRHK_R_REQUEST_FAILED 111
94#define HWCRHK_R_REQUEST_FALLBACK 112
95#define HWCRHK_R_UNIT_FAILURE 113
96
97#ifdef __cplusplus
98}
99#endif
100#endif
diff --git a/src/lib/libcrypto/engine/hw_nuron.c b/src/lib/libcrypto/engine/hw_nuron.c
new file mode 100644
index 0000000000..2672012154
--- /dev/null
+++ b/src/lib/libcrypto/engine/hw_nuron.c
@@ -0,0 +1,399 @@
1/* crypto/engine/hw_nuron.c */
2/* Written by Ben Laurie for the OpenSSL Project, leaning heavily on Geoff
3 * Thorpe's Atalla implementation.
4 */
5/* ====================================================================
6 * Copyright (c) 2000-2001 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 * licensing@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 <stdio.h>
60#include <openssl/crypto.h>
61#include "cryptlib.h"
62#include <openssl/dso.h>
63#include <openssl/engine.h>
64
65
66#ifndef OPENSSL_NO_HW
67#ifndef OPENSSL_NO_HW_NURON
68
69#define NURON_LIB_NAME "nuron engine"
70#include "hw_nuron_err.c"
71
72static const char def_NURON_LIBNAME[] = "nuronssl";
73static const char *NURON_LIBNAME = def_NURON_LIBNAME;
74static const char *NURON_F1 = "nuron_mod_exp";
75
76/* The definitions for control commands specific to this engine */
77#define NURON_CMD_SO_PATH ENGINE_CMD_BASE
78static const ENGINE_CMD_DEFN nuron_cmd_defns[] = {
79 {NURON_CMD_SO_PATH,
80 "SO_PATH",
81 "Specifies the path to the 'nuronssl' shared library",
82 ENGINE_CMD_FLAG_STRING},
83 {0, NULL, NULL, 0}
84 };
85
86typedef int tfnModExp(BIGNUM *r,const BIGNUM *a,const BIGNUM *p,const BIGNUM *m);
87static tfnModExp *pfnModExp = NULL;
88
89static DSO *pvDSOHandle = NULL;
90
91static int nuron_destroy(ENGINE *e)
92 {
93 ERR_unload_NURON_strings();
94 return 1;
95 }
96
97static int nuron_init(ENGINE *e)
98 {
99 if(pvDSOHandle != NULL)
100 {
101 NURONerr(NURON_F_NURON_INIT,NURON_R_ALREADY_LOADED);
102 return 0;
103 }
104
105 pvDSOHandle = DSO_load(NULL, NURON_LIBNAME, NULL,
106 DSO_FLAG_NAME_TRANSLATION_EXT_ONLY);
107 if(!pvDSOHandle)
108 {
109 NURONerr(NURON_F_NURON_INIT,NURON_R_DSO_NOT_FOUND);
110 return 0;
111 }
112
113 pfnModExp = (tfnModExp *)DSO_bind_func(pvDSOHandle, NURON_F1);
114 if(!pfnModExp)
115 {
116 NURONerr(NURON_F_NURON_INIT,NURON_R_DSO_FUNCTION_NOT_FOUND);
117 return 0;
118 }
119
120 return 1;
121 }
122
123static int nuron_finish(ENGINE *e)
124 {
125 if(pvDSOHandle == NULL)
126 {
127 NURONerr(NURON_F_NURON_FINISH,NURON_R_NOT_LOADED);
128 return 0;
129 }
130 if(!DSO_free(pvDSOHandle))
131 {
132 NURONerr(NURON_F_NURON_FINISH,NURON_R_DSO_FAILURE);
133 return 0;
134 }
135 pvDSOHandle=NULL;
136 pfnModExp=NULL;
137 return 1;
138 }
139
140static int nuron_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)())
141 {
142 int initialised = ((pvDSOHandle == NULL) ? 0 : 1);
143 switch(cmd)
144 {
145 case NURON_CMD_SO_PATH:
146 if(p == NULL)
147 {
148 NURONerr(NURON_F_NURON_CTRL,ERR_R_PASSED_NULL_PARAMETER);
149 return 0;
150 }
151 if(initialised)
152 {
153 NURONerr(NURON_F_NURON_CTRL,NURON_R_ALREADY_LOADED);
154 return 0;
155 }
156 NURON_LIBNAME = (const char *)p;
157 return 1;
158 default:
159 break;
160 }
161 NURONerr(NURON_F_NURON_CTRL,NURON_R_CTRL_COMMAND_NOT_IMPLEMENTED);
162 return 0;
163}
164
165static int nuron_mod_exp(BIGNUM *r,const BIGNUM *a,const BIGNUM *p,
166 const BIGNUM *m,BN_CTX *ctx)
167 {
168 if(!pvDSOHandle)
169 {
170 NURONerr(NURON_F_NURON_MOD_EXP,NURON_R_NOT_LOADED);
171 return 0;
172 }
173 return pfnModExp(r,a,p,m);
174 }
175
176#ifndef OPENSSL_NO_RSA
177static int nuron_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa)
178 {
179 return nuron_mod_exp(r0,I,rsa->d,rsa->n,NULL);
180 }
181#endif
182
183#ifndef OPENSSL_NO_DSA
184/* This code was liberated and adapted from the commented-out code in
185 * dsa_ossl.c. Because of the unoptimised form of the Atalla acceleration
186 * (it doesn't have a CRT form for RSA), this function means that an
187 * Atalla system running with a DSA server certificate can handshake
188 * around 5 or 6 times faster/more than an equivalent system running with
189 * RSA. Just check out the "signs" statistics from the RSA and DSA parts
190 * of "openssl speed -engine atalla dsa1024 rsa1024". */
191static int nuron_dsa_mod_exp(DSA *dsa, BIGNUM *rr, BIGNUM *a1,
192 BIGNUM *p1, BIGNUM *a2, BIGNUM *p2, BIGNUM *m,
193 BN_CTX *ctx, BN_MONT_CTX *in_mont)
194 {
195 BIGNUM t;
196 int to_return = 0;
197
198 BN_init(&t);
199 /* let rr = a1 ^ p1 mod m */
200 if (!nuron_mod_exp(rr,a1,p1,m,ctx))
201 goto end;
202 /* let t = a2 ^ p2 mod m */
203 if (!nuron_mod_exp(&t,a2,p2,m,ctx))
204 goto end;
205 /* let rr = rr * t mod m */
206 if (!BN_mod_mul(rr,rr,&t,m,ctx))
207 goto end;
208 to_return = 1;
209end:
210 BN_free(&t);
211 return to_return;
212 }
213
214
215static int nuron_mod_exp_dsa(DSA *dsa, BIGNUM *r, BIGNUM *a,
216 const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx,
217 BN_MONT_CTX *m_ctx)
218 {
219 return nuron_mod_exp(r, a, p, m, ctx);
220 }
221#endif
222
223/* This function is aliased to mod_exp (with the mont stuff dropped). */
224static int nuron_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
225 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx)
226 {
227 return nuron_mod_exp(r, a, p, m, ctx);
228 }
229
230#ifndef OPENSSL_NO_DH
231/* This function is aliased to mod_exp (with the dh and mont dropped). */
232static int nuron_mod_exp_dh(const DH *dh, BIGNUM *r,
233 const BIGNUM *a, const BIGNUM *p,
234 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx)
235 {
236 return nuron_mod_exp(r, a, p, m, ctx);
237 }
238#endif
239
240#ifndef OPENSSL_NO_RSA
241static RSA_METHOD nuron_rsa =
242 {
243 "Nuron RSA method",
244 NULL,
245 NULL,
246 NULL,
247 NULL,
248 nuron_rsa_mod_exp,
249 nuron_mod_exp_mont,
250 NULL,
251 NULL,
252 0,
253 NULL,
254 NULL,
255 NULL
256 };
257#endif
258
259#ifndef OPENSSL_NO_DSA
260static DSA_METHOD nuron_dsa =
261 {
262 "Nuron DSA method",
263 NULL, /* dsa_do_sign */
264 NULL, /* dsa_sign_setup */
265 NULL, /* dsa_do_verify */
266 nuron_dsa_mod_exp, /* dsa_mod_exp */
267 nuron_mod_exp_dsa, /* bn_mod_exp */
268 NULL, /* init */
269 NULL, /* finish */
270 0, /* flags */
271 NULL /* app_data */
272 };
273#endif
274
275#ifndef OPENSSL_NO_DH
276static DH_METHOD nuron_dh =
277 {
278 "Nuron DH method",
279 NULL,
280 NULL,
281 nuron_mod_exp_dh,
282 NULL,
283 NULL,
284 0,
285 NULL
286 };
287#endif
288
289/* Constants used when creating the ENGINE */
290static const char *engine_nuron_id = "nuron";
291static const char *engine_nuron_name = "Nuron hardware engine support";
292
293/* This internal function is used by ENGINE_nuron() and possibly by the
294 * "dynamic" ENGINE support too */
295static int bind_helper(ENGINE *e)
296 {
297#ifndef OPENSSL_NO_RSA
298 const RSA_METHOD *meth1;
299#endif
300#ifndef OPENSSL_NO_DSA
301 const DSA_METHOD *meth2;
302#endif
303#ifndef OPENSSL_NO_DH
304 const DH_METHOD *meth3;
305#endif
306 if(!ENGINE_set_id(e, engine_nuron_id) ||
307 !ENGINE_set_name(e, engine_nuron_name) ||
308#ifndef OPENSSL_NO_RSA
309 !ENGINE_set_RSA(e, &nuron_rsa) ||
310#endif
311#ifndef OPENSSL_NO_DSA
312 !ENGINE_set_DSA(e, &nuron_dsa) ||
313#endif
314#ifndef OPENSSL_NO_DH
315 !ENGINE_set_DH(e, &nuron_dh) ||
316#endif
317 !ENGINE_set_destroy_function(e, nuron_destroy) ||
318 !ENGINE_set_init_function(e, nuron_init) ||
319 !ENGINE_set_finish_function(e, nuron_finish) ||
320 !ENGINE_set_ctrl_function(e, nuron_ctrl) ||
321 !ENGINE_set_cmd_defns(e, nuron_cmd_defns))
322 return 0;
323
324#ifndef OPENSSL_NO_RSA
325 /* We know that the "PKCS1_SSLeay()" functions hook properly
326 * to the nuron-specific mod_exp and mod_exp_crt so we use
327 * those functions. NB: We don't use ENGINE_openssl() or
328 * anything "more generic" because something like the RSAref
329 * code may not hook properly, and if you own one of these
330 * cards then you have the right to do RSA operations on it
331 * anyway! */
332 meth1=RSA_PKCS1_SSLeay();
333 nuron_rsa.rsa_pub_enc=meth1->rsa_pub_enc;
334 nuron_rsa.rsa_pub_dec=meth1->rsa_pub_dec;
335 nuron_rsa.rsa_priv_enc=meth1->rsa_priv_enc;
336 nuron_rsa.rsa_priv_dec=meth1->rsa_priv_dec;
337#endif
338
339#ifndef OPENSSL_NO_DSA
340 /* Use the DSA_OpenSSL() method and just hook the mod_exp-ish
341 * bits. */
342 meth2=DSA_OpenSSL();
343 nuron_dsa.dsa_do_sign=meth2->dsa_do_sign;
344 nuron_dsa.dsa_sign_setup=meth2->dsa_sign_setup;
345 nuron_dsa.dsa_do_verify=meth2->dsa_do_verify;
346#endif
347
348#ifndef OPENSSL_NO_DH
349 /* Much the same for Diffie-Hellman */
350 meth3=DH_OpenSSL();
351 nuron_dh.generate_key=meth3->generate_key;
352 nuron_dh.compute_key=meth3->compute_key;
353#endif
354
355 /* Ensure the nuron error handling is set up */
356 ERR_load_NURON_strings();
357 return 1;
358 }
359
360static ENGINE *engine_nuron(void)
361 {
362 ENGINE *ret = ENGINE_new();
363 if(!ret)
364 return NULL;
365 if(!bind_helper(ret))
366 {
367 ENGINE_free(ret);
368 return NULL;
369 }
370 return ret;
371 }
372
373void ENGINE_load_nuron(void)
374 {
375 /* Copied from eng_[openssl|dyn].c */
376 ENGINE *toadd = engine_nuron();
377 if(!toadd) return;
378 ENGINE_add(toadd);
379 ENGINE_free(toadd);
380 ERR_clear_error();
381 }
382
383/* This stuff is needed if this ENGINE is being compiled into a self-contained
384 * shared-library. */
385#ifdef ENGINE_DYNAMIC_SUPPORT
386static int bind_fn(ENGINE *e, const char *id)
387 {
388 if(id && (strcmp(id, engine_nuron_id) != 0))
389 return 0;
390 if(!bind_helper(e))
391 return 0;
392 return 1;
393 }
394IMPLEMENT_DYNAMIC_CHECK_FN()
395IMPLEMENT_DYNAMIC_BIND_FN(bind_fn)
396#endif /* ENGINE_DYNAMIC_SUPPORT */
397
398#endif /* !OPENSSL_NO_HW_NURON */
399#endif /* !OPENSSL_NO_HW */
diff --git a/src/lib/libcrypto/engine/hw_nuron_err.c b/src/lib/libcrypto/engine/hw_nuron_err.c
new file mode 100644
index 0000000000..df9d7bde76
--- /dev/null
+++ b/src/lib/libcrypto/engine/hw_nuron_err.c
@@ -0,0 +1,142 @@
1/* hw_nuron_err.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file,
58 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include "hw_nuron_err.h"
64
65/* BEGIN ERROR CODES */
66#ifndef OPENSSL_NO_ERR
67static ERR_STRING_DATA NURON_str_functs[]=
68 {
69{ERR_PACK(0,NURON_F_NURON_CTRL,0), "NURON_CTRL"},
70{ERR_PACK(0,NURON_F_NURON_FINISH,0), "NURON_FINISH"},
71{ERR_PACK(0,NURON_F_NURON_INIT,0), "NURON_INIT"},
72{ERR_PACK(0,NURON_F_NURON_MOD_EXP,0), "NURON_MOD_EXP"},
73{0,NULL}
74 };
75
76static ERR_STRING_DATA NURON_str_reasons[]=
77 {
78{NURON_R_ALREADY_LOADED ,"already loaded"},
79{NURON_R_CTRL_COMMAND_NOT_IMPLEMENTED ,"ctrl command not implemented"},
80{NURON_R_DSO_FAILURE ,"dso failure"},
81{NURON_R_DSO_FUNCTION_NOT_FOUND ,"dso function not found"},
82{NURON_R_DSO_NOT_FOUND ,"dso not found"},
83{NURON_R_NOT_LOADED ,"not loaded"},
84{0,NULL}
85 };
86
87#endif
88
89#ifdef NURON_LIB_NAME
90static ERR_STRING_DATA NURON_lib_name[]=
91 {
92{0 ,NURON_LIB_NAME},
93{0,NULL}
94 };
95#endif
96
97
98static int NURON_lib_error_code=0;
99static int NURON_error_init=1;
100
101static void ERR_load_NURON_strings(void)
102 {
103 if (NURON_lib_error_code == 0)
104 NURON_lib_error_code=ERR_get_next_error_library();
105
106 if (NURON_error_init)
107 {
108 NURON_error_init=0;
109#ifndef OPENSSL_NO_ERR
110 ERR_load_strings(NURON_lib_error_code,NURON_str_functs);
111 ERR_load_strings(NURON_lib_error_code,NURON_str_reasons);
112#endif
113
114#ifdef NURON_LIB_NAME
115 NURON_lib_name->error = ERR_PACK(NURON_lib_error_code,0,0);
116 ERR_load_strings(0,NURON_lib_name);
117#endif
118 }
119 }
120
121static void ERR_unload_NURON_strings(void)
122 {
123 if (NURON_error_init == 0)
124 {
125#ifndef OPENSSL_NO_ERR
126 ERR_unload_strings(NURON_lib_error_code,NURON_str_functs);
127 ERR_unload_strings(NURON_lib_error_code,NURON_str_reasons);
128#endif
129
130#ifdef NURON_LIB_NAME
131 ERR_unload_strings(0,NURON_lib_name);
132#endif
133 NURON_error_init=1;
134 }
135 }
136
137static void ERR_NURON_error(int function, int reason, char *file, int line)
138 {
139 if (NURON_lib_error_code == 0)
140 NURON_lib_error_code=ERR_get_next_error_library();
141 ERR_PUT_error(NURON_lib_error_code,function,reason,file,line);
142 }
diff --git a/src/lib/libcrypto/engine/hw_nuron_err.h b/src/lib/libcrypto/engine/hw_nuron_err.h
new file mode 100644
index 0000000000..a56bfdf303
--- /dev/null
+++ b/src/lib/libcrypto/engine/hw_nuron_err.h
@@ -0,0 +1,86 @@
1/* ====================================================================
2 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * 3. All advertising materials mentioning features or use of this
17 * software must display the following acknowledgment:
18 * "This product includes software developed by the OpenSSL Project
19 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
20 *
21 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission. For written permission, please contact
24 * openssl-core@openssl.org.
25 *
26 * 5. Products derived from this software may not be called "OpenSSL"
27 * nor may "OpenSSL" appear in their names without prior written
28 * permission of the OpenSSL Project.
29 *
30 * 6. Redistributions of any form whatsoever must retain the following
31 * acknowledgment:
32 * "This product includes software developed by the OpenSSL Project
33 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46 * OF THE POSSIBILITY OF SUCH DAMAGE.
47 * ====================================================================
48 *
49 * This product includes cryptographic software written by Eric Young
50 * (eay@cryptsoft.com). This product includes software written by Tim
51 * Hudson (tjh@cryptsoft.com).
52 *
53 */
54
55#ifndef HEADER_NURON_ERR_H
56#define HEADER_NURON_ERR_H
57
58/* BEGIN ERROR CODES */
59/* The following lines are auto generated by the script mkerr.pl. Any changes
60 * made after this point may be overwritten when the script is next run.
61 */
62static void ERR_load_NURON_strings(void);
63static void ERR_unload_NURON_strings(void);
64static void ERR_NURON_error(int function, int reason, char *file, int line);
65#define NURONerr(f,r) ERR_NURON_error((f),(r),__FILE__,__LINE__)
66
67/* Error codes for the NURON functions. */
68
69/* Function codes. */
70#define NURON_F_NURON_CTRL 100
71#define NURON_F_NURON_FINISH 101
72#define NURON_F_NURON_INIT 102
73#define NURON_F_NURON_MOD_EXP 103
74
75/* Reason codes. */
76#define NURON_R_ALREADY_LOADED 100
77#define NURON_R_CTRL_COMMAND_NOT_IMPLEMENTED 101
78#define NURON_R_DSO_FAILURE 102
79#define NURON_R_DSO_FUNCTION_NOT_FOUND 103
80#define NURON_R_DSO_NOT_FOUND 104
81#define NURON_R_NOT_LOADED 105
82
83#ifdef __cplusplus
84}
85#endif
86#endif
diff --git a/src/lib/libcrypto/engine/hw_sureware_err.c b/src/lib/libcrypto/engine/hw_sureware_err.c
new file mode 100644
index 0000000000..69955dadbb
--- /dev/null
+++ b/src/lib/libcrypto/engine/hw_sureware_err.c
@@ -0,0 +1,150 @@
1/* hw_sureware_err.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file,
58 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include "hw_sureware_err.h"
64
65/* BEGIN ERROR CODES */
66#ifndef OPENSSL_NO_ERR
67static ERR_STRING_DATA SUREWARE_str_functs[]=
68 {
69{ERR_PACK(0,SUREWARE_F_SUREWAREHK_CTRL,0), "SUREWAREHK_CTRL"},
70{ERR_PACK(0,SUREWARE_F_SUREWAREHK_DSA_DO_SIGN,0), "SUREWAREHK_DSA_DO_SIGN"},
71{ERR_PACK(0,SUREWARE_F_SUREWAREHK_EX_FREE,0), "SUREWAREHK_EX_FREE"},
72{ERR_PACK(0,SUREWARE_F_SUREWAREHK_FINISH,0), "SUREWAREHK_FINISH"},
73{ERR_PACK(0,SUREWARE_F_SUREWAREHK_INIT,0), "SUREWAREHK_INIT"},
74{ERR_PACK(0,SUREWARE_F_SUREWAREHK_LOAD_PRIVATE_KEY,0), "SUREWAREHK_LOAD_PRIVATE_KEY"},
75{ERR_PACK(0,SUREWARE_F_SUREWAREHK_LOAD_PUBLIC_KEY,0), "SUREWAREHK_LOAD_PUBLIC_KEY"},
76{ERR_PACK(0,SUREWARE_F_SUREWAREHK_MOD_EXP,0), "SUREWAREHK_MOD_EXP"},
77{ERR_PACK(0,SUREWARE_F_SUREWAREHK_RAND_BYTES,0), "SUREWAREHK_RAND_BYTES"},
78{ERR_PACK(0,SUREWARE_F_SUREWAREHK_RAND_SEED,0), "SUREWAREHK_RAND_SEED"},
79{ERR_PACK(0,SUREWARE_F_SUREWAREHK_RSA_PRIV_DEC,0), "SUREWAREHK_RSA_PRIV_DEC"},
80{ERR_PACK(0,SUREWARE_F_SUREWAREHK_RSA_PRIV_ENC,0), "SUREWAREHK_RSA_PRIV_ENC"},
81{0,NULL}
82 };
83
84static ERR_STRING_DATA SUREWARE_str_reasons[]=
85 {
86{SUREWARE_R_BIO_WAS_FREED ,"bio was freed"},
87{SUREWARE_R_MISSING_KEY_COMPONENTS ,"missing key components"},
88{SUREWARE_R_REQUEST_FAILED ,"request failed"},
89{SUREWARE_R_REQUEST_FALLBACK ,"request fallback"},
90{SUREWARE_R_SIZE_TOO_LARGE_OR_TOO_SMALL ,"size too large or too small"},
91{SUREWARE_R_UNIT_FAILURE ,"unit failure"},
92{0,NULL}
93 };
94
95#endif
96
97#ifdef SUREWARE_LIB_NAME
98static ERR_STRING_DATA SUREWARE_lib_name[]=
99 {
100{0 ,SUREWARE_LIB_NAME},
101{0,NULL}
102 };
103#endif
104
105
106static int SUREWARE_lib_error_code=0;
107static int SUREWARE_error_init=1;
108
109static void ERR_load_SUREWARE_strings(void)
110 {
111 if (SUREWARE_lib_error_code == 0)
112 SUREWARE_lib_error_code=ERR_get_next_error_library();
113
114 if (SUREWARE_error_init)
115 {
116 SUREWARE_error_init=0;
117#ifndef OPENSSL_NO_ERR
118 ERR_load_strings(SUREWARE_lib_error_code,SUREWARE_str_functs);
119 ERR_load_strings(SUREWARE_lib_error_code,SUREWARE_str_reasons);
120#endif
121
122#ifdef SUREWARE_LIB_NAME
123 SUREWARE_lib_name->error = ERR_PACK(SUREWARE_lib_error_code,0,0);
124 ERR_load_strings(0,SUREWARE_lib_name);
125#endif
126 }
127 }
128
129static void ERR_unload_SUREWARE_strings(void)
130 {
131 if (SUREWARE_error_init == 0)
132 {
133#ifndef OPENSSL_NO_ERR
134 ERR_unload_strings(SUREWARE_lib_error_code,SUREWARE_str_functs);
135 ERR_unload_strings(SUREWARE_lib_error_code,SUREWARE_str_reasons);
136#endif
137
138#ifdef SUREWARE_LIB_NAME
139 ERR_unload_strings(0,SUREWARE_lib_name);
140#endif
141 SUREWARE_error_init=1;
142 }
143 }
144
145static void ERR_SUREWARE_error(int function, int reason, char *file, int line)
146 {
147 if (SUREWARE_lib_error_code == 0)
148 SUREWARE_lib_error_code=ERR_get_next_error_library();
149 ERR_PUT_error(SUREWARE_lib_error_code,function,reason,file,line);
150 }
diff --git a/src/lib/libcrypto/engine/hw_sureware_err.h b/src/lib/libcrypto/engine/hw_sureware_err.h
new file mode 100644
index 0000000000..bc52af5e05
--- /dev/null
+++ b/src/lib/libcrypto/engine/hw_sureware_err.h
@@ -0,0 +1,94 @@
1/* ====================================================================
2 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * 3. All advertising materials mentioning features or use of this
17 * software must display the following acknowledgment:
18 * "This product includes software developed by the OpenSSL Project
19 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
20 *
21 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission. For written permission, please contact
24 * openssl-core@openssl.org.
25 *
26 * 5. Products derived from this software may not be called "OpenSSL"
27 * nor may "OpenSSL" appear in their names without prior written
28 * permission of the OpenSSL Project.
29 *
30 * 6. Redistributions of any form whatsoever must retain the following
31 * acknowledgment:
32 * "This product includes software developed by the OpenSSL Project
33 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46 * OF THE POSSIBILITY OF SUCH DAMAGE.
47 * ====================================================================
48 *
49 * This product includes cryptographic software written by Eric Young
50 * (eay@cryptsoft.com). This product includes software written by Tim
51 * Hudson (tjh@cryptsoft.com).
52 *
53 */
54
55#ifndef HEADER_SUREWARE_ERR_H
56#define HEADER_SUREWARE_ERR_H
57
58/* BEGIN ERROR CODES */
59/* The following lines are auto generated by the script mkerr.pl. Any changes
60 * made after this point may be overwritten when the script is next run.
61 */
62static void ERR_load_SUREWARE_strings(void);
63static void ERR_unload_SUREWARE_strings(void);
64static void ERR_SUREWARE_error(int function, int reason, char *file, int line);
65#define SUREWAREerr(f,r) ERR_SUREWARE_error((f),(r),__FILE__,__LINE__)
66
67/* Error codes for the SUREWARE functions. */
68
69/* Function codes. */
70#define SUREWARE_F_SUREWAREHK_CTRL 100
71#define SUREWARE_F_SUREWAREHK_DSA_DO_SIGN 101
72#define SUREWARE_F_SUREWAREHK_EX_FREE 102
73#define SUREWARE_F_SUREWAREHK_FINISH 103
74#define SUREWARE_F_SUREWAREHK_INIT 104
75#define SUREWARE_F_SUREWAREHK_LOAD_PRIVATE_KEY 105
76#define SUREWARE_F_SUREWAREHK_LOAD_PUBLIC_KEY 106
77#define SUREWARE_F_SUREWAREHK_MOD_EXP 107
78#define SUREWARE_F_SUREWAREHK_RAND_BYTES 108
79#define SUREWARE_F_SUREWAREHK_RAND_SEED 109
80#define SUREWARE_F_SUREWAREHK_RSA_PRIV_DEC 110
81#define SUREWARE_F_SUREWAREHK_RSA_PRIV_ENC 111
82
83/* Reason codes. */
84#define SUREWARE_R_BIO_WAS_FREED 100
85#define SUREWARE_R_MISSING_KEY_COMPONENTS 105
86#define SUREWARE_R_REQUEST_FAILED 101
87#define SUREWARE_R_REQUEST_FALLBACK 102
88#define SUREWARE_R_SIZE_TOO_LARGE_OR_TOO_SMALL 103
89#define SUREWARE_R_UNIT_FAILURE 104
90
91#ifdef __cplusplus
92}
93#endif
94#endif
diff --git a/src/lib/libcrypto/engine/hw_ubsec.c b/src/lib/libcrypto/engine/hw_ubsec.c
new file mode 100644
index 0000000000..743c06043c
--- /dev/null
+++ b/src/lib/libcrypto/engine/hw_ubsec.c
@@ -0,0 +1,1041 @@
1/* crypto/engine/hw_ubsec.c */
2/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
3 * project 2000.
4 *
5 * Cloned shamelessly by Joe Tardo.
6 */
7/* ====================================================================
8 * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 *
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 *
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in
19 * the documentation and/or other materials provided with the
20 * distribution.
21 *
22 * 3. All advertising materials mentioning features or use of this
23 * software must display the following acknowledgment:
24 * "This product includes software developed by the OpenSSL Project
25 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
26 *
27 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
28 * endorse or promote products derived from this software without
29 * prior written permission. For written permission, please contact
30 * licensing@OpenSSL.org.
31 *
32 * 5. Products derived from this software may not be called "OpenSSL"
33 * nor may "OpenSSL" appear in their names without prior written
34 * permission of the OpenSSL Project.
35 *
36 * 6. Redistributions of any form whatsoever must retain the following
37 * acknowledgment:
38 * "This product includes software developed by the OpenSSL Project
39 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
42 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
44 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
45 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
46 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
47 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
48 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
49 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
50 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
51 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
52 * OF THE POSSIBILITY OF SUCH DAMAGE.
53 * ====================================================================
54 *
55 * This product includes cryptographic software written by Eric Young
56 * (eay@cryptsoft.com). This product includes software written by Tim
57 * Hudson (tjh@cryptsoft.com).
58 *
59 */
60
61#include <stdio.h>
62#include <openssl/crypto.h>
63#include "cryptlib.h"
64#include <openssl/dso.h>
65#include <openssl/engine.h>
66
67#ifndef OPENSSL_NO_HW
68#ifndef OPENSSL_NO_HW_UBSEC
69
70#ifdef FLAT_INC
71#include "hw_ubsec.h"
72#else
73#include "vendor_defns/hw_ubsec.h"
74#endif
75
76#define UBSEC_LIB_NAME "ubsec engine"
77#include "hw_ubsec_err.c"
78
79#define FAIL_TO_SOFTWARE -15
80
81static int ubsec_destroy(ENGINE *e);
82static int ubsec_init(ENGINE *e);
83static int ubsec_finish(ENGINE *e);
84static int ubsec_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)());
85static int ubsec_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
86 const BIGNUM *m, BN_CTX *ctx);
87static int ubsec_mod_exp_crt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
88 const BIGNUM *q, const BIGNUM *dp,
89 const BIGNUM *dq, const BIGNUM *qinv, BN_CTX *ctx);
90#ifndef OPENSSL_NO_RSA
91static int ubsec_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa);
92#endif
93static int ubsec_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
94 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
95#ifndef OPENSSL_NO_DSA
96#if NOT_USED
97static int ubsec_dsa_mod_exp(DSA *dsa, BIGNUM *rr, BIGNUM *a1,
98 BIGNUM *p1, BIGNUM *a2, BIGNUM *p2, BIGNUM *m,
99 BN_CTX *ctx, BN_MONT_CTX *in_mont);
100static int ubsec_mod_exp_dsa(DSA *dsa, BIGNUM *r, BIGNUM *a,
101 const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx,
102 BN_MONT_CTX *m_ctx);
103#endif
104static DSA_SIG *ubsec_dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa);
105static int ubsec_dsa_verify(const unsigned char *dgst, int dgst_len,
106 DSA_SIG *sig, DSA *dsa);
107#endif
108#ifndef OPENSSL_NO_DH
109static int ubsec_mod_exp_dh(const DH *dh, BIGNUM *r, const BIGNUM *a,
110 const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx,
111 BN_MONT_CTX *m_ctx);
112static int ubsec_dh_compute_key(unsigned char *key,const BIGNUM *pub_key,DH *dh);
113static int ubsec_dh_generate_key(DH *dh);
114#endif
115
116#if NOT_USED
117static int ubsec_rand_bytes(unsigned char *buf, int num);
118static int ubsec_rand_status(void);
119#endif
120
121#define UBSEC_CMD_SO_PATH ENGINE_CMD_BASE
122static const ENGINE_CMD_DEFN ubsec_cmd_defns[] = {
123 {UBSEC_CMD_SO_PATH,
124 "SO_PATH",
125 "Specifies the path to the 'ubsec' shared library",
126 ENGINE_CMD_FLAG_STRING},
127 {0, NULL, NULL, 0}
128 };
129
130#ifndef OPENSSL_NO_RSA
131/* Our internal RSA_METHOD that we provide pointers to */
132static RSA_METHOD ubsec_rsa =
133 {
134 "UBSEC RSA method",
135 NULL,
136 NULL,
137 NULL,
138 NULL,
139 ubsec_rsa_mod_exp,
140 ubsec_mod_exp_mont,
141 NULL,
142 NULL,
143 0,
144 NULL,
145 NULL,
146 NULL
147 };
148#endif
149
150#ifndef OPENSSL_NO_DSA
151/* Our internal DSA_METHOD that we provide pointers to */
152static DSA_METHOD ubsec_dsa =
153 {
154 "UBSEC DSA method",
155 ubsec_dsa_do_sign, /* dsa_do_sign */
156 NULL, /* dsa_sign_setup */
157 ubsec_dsa_verify, /* dsa_do_verify */
158 NULL, /* ubsec_dsa_mod_exp */ /* dsa_mod_exp */
159 NULL, /* ubsec_mod_exp_dsa */ /* bn_mod_exp */
160 NULL, /* init */
161 NULL, /* finish */
162 0, /* flags */
163 NULL /* app_data */
164 };
165#endif
166
167#ifndef OPENSSL_NO_DH
168/* Our internal DH_METHOD that we provide pointers to */
169static DH_METHOD ubsec_dh =
170 {
171 "UBSEC DH method",
172 ubsec_dh_generate_key,
173 ubsec_dh_compute_key,
174 ubsec_mod_exp_dh,
175 NULL,
176 NULL,
177 0,
178 NULL
179 };
180#endif
181
182/* Constants used when creating the ENGINE */
183static const char *engine_ubsec_id = "ubsec";
184static const char *engine_ubsec_name = "UBSEC hardware engine support";
185
186/* This internal function is used by ENGINE_ubsec() and possibly by the
187 * "dynamic" ENGINE support too */
188static int bind_helper(ENGINE *e)
189 {
190#ifndef OPENSSL_NO_RSA
191 const RSA_METHOD *meth1;
192#endif
193#ifndef OPENSSL_NO_DH
194#ifndef HAVE_UBSEC_DH
195 const DH_METHOD *meth3;
196#endif /* HAVE_UBSEC_DH */
197#endif
198 if(!ENGINE_set_id(e, engine_ubsec_id) ||
199 !ENGINE_set_name(e, engine_ubsec_name) ||
200#ifndef OPENSSL_NO_RSA
201 !ENGINE_set_RSA(e, &ubsec_rsa) ||
202#endif
203#ifndef OPENSSL_NO_DSA
204 !ENGINE_set_DSA(e, &ubsec_dsa) ||
205#endif
206#ifndef OPENSSL_NO_DH
207 !ENGINE_set_DH(e, &ubsec_dh) ||
208#endif
209 !ENGINE_set_destroy_function(e, ubsec_destroy) ||
210 !ENGINE_set_init_function(e, ubsec_init) ||
211 !ENGINE_set_finish_function(e, ubsec_finish) ||
212 !ENGINE_set_ctrl_function(e, ubsec_ctrl) ||
213 !ENGINE_set_cmd_defns(e, ubsec_cmd_defns))
214 return 0;
215
216#ifndef OPENSSL_NO_RSA
217 /* We know that the "PKCS1_SSLeay()" functions hook properly
218 * to the Broadcom-specific mod_exp and mod_exp_crt so we use
219 * those functions. NB: We don't use ENGINE_openssl() or
220 * anything "more generic" because something like the RSAref
221 * code may not hook properly, and if you own one of these
222 * cards then you have the right to do RSA operations on it
223 * anyway! */
224 meth1 = RSA_PKCS1_SSLeay();
225 ubsec_rsa.rsa_pub_enc = meth1->rsa_pub_enc;
226 ubsec_rsa.rsa_pub_dec = meth1->rsa_pub_dec;
227 ubsec_rsa.rsa_priv_enc = meth1->rsa_priv_enc;
228 ubsec_rsa.rsa_priv_dec = meth1->rsa_priv_dec;
229#endif
230
231#ifndef OPENSSL_NO_DH
232#ifndef HAVE_UBSEC_DH
233 /* Much the same for Diffie-Hellman */
234 meth3 = DH_OpenSSL();
235 ubsec_dh.generate_key = meth3->generate_key;
236 ubsec_dh.compute_key = meth3->compute_key;
237#endif /* HAVE_UBSEC_DH */
238#endif
239
240 /* Ensure the ubsec error handling is set up */
241 ERR_load_UBSEC_strings();
242 return 1;
243 }
244
245static ENGINE *engine_ubsec(void)
246 {
247 ENGINE *ret = ENGINE_new();
248 if(!ret)
249 return NULL;
250 if(!bind_helper(ret))
251 {
252 ENGINE_free(ret);
253 return NULL;
254 }
255 return ret;
256 }
257
258void ENGINE_load_ubsec(void)
259 {
260 /* Copied from eng_[openssl|dyn].c */
261 ENGINE *toadd = engine_ubsec();
262 if(!toadd) return;
263 ENGINE_add(toadd);
264 ENGINE_free(toadd);
265 ERR_clear_error();
266 }
267
268/* This is a process-global DSO handle used for loading and unloading
269 * the UBSEC library. NB: This is only set (or unset) during an
270 * init() or finish() call (reference counts permitting) and they're
271 * operating with global locks, so this should be thread-safe
272 * implicitly. */
273
274static DSO *ubsec_dso = NULL;
275
276/* These are the function pointers that are (un)set when the library has
277 * successfully (un)loaded. */
278
279static t_UBSEC_ubsec_bytes_to_bits *p_UBSEC_ubsec_bytes_to_bits = NULL;
280static t_UBSEC_ubsec_bits_to_bytes *p_UBSEC_ubsec_bits_to_bytes = NULL;
281static t_UBSEC_ubsec_open *p_UBSEC_ubsec_open = NULL;
282static t_UBSEC_ubsec_close *p_UBSEC_ubsec_close = NULL;
283#ifndef OPENSSL_NO_DH
284static t_UBSEC_diffie_hellman_generate_ioctl
285 *p_UBSEC_diffie_hellman_generate_ioctl = NULL;
286static t_UBSEC_diffie_hellman_agree_ioctl *p_UBSEC_diffie_hellman_agree_ioctl = NULL;
287#endif
288/* #ifndef OPENSSL_NO_RSA */
289static t_UBSEC_rsa_mod_exp_ioctl *p_UBSEC_rsa_mod_exp_ioctl = NULL;
290static t_UBSEC_rsa_mod_exp_crt_ioctl *p_UBSEC_rsa_mod_exp_crt_ioctl = NULL;
291/* #endif */
292#ifndef OPENSSL_NO_DSA
293static t_UBSEC_dsa_sign_ioctl *p_UBSEC_dsa_sign_ioctl = NULL;
294static t_UBSEC_dsa_verify_ioctl *p_UBSEC_dsa_verify_ioctl = NULL;
295#endif
296static t_UBSEC_math_accelerate_ioctl *p_UBSEC_math_accelerate_ioctl = NULL;
297static t_UBSEC_rng_ioctl *p_UBSEC_rng_ioctl = NULL;
298static t_UBSEC_max_key_len_ioctl *p_UBSEC_max_key_len_ioctl = NULL;
299
300static int max_key_len = 1024; /* ??? */
301
302/*
303 * These are the static string constants for the DSO file name and the function
304 * symbol names to bind to.
305 */
306
307static const char *UBSEC_LIBNAME = "ubsec";
308static const char *UBSEC_F1 = "ubsec_bytes_to_bits";
309static const char *UBSEC_F2 = "ubsec_bits_to_bytes";
310static const char *UBSEC_F3 = "ubsec_open";
311static const char *UBSEC_F4 = "ubsec_close";
312#ifndef OPENSSL_NO_DH
313static const char *UBSEC_F5 = "diffie_hellman_generate_ioctl";
314static const char *UBSEC_F6 = "diffie_hellman_agree_ioctl";
315#endif
316/* #ifndef OPENSSL_NO_RSA */
317static const char *UBSEC_F7 = "rsa_mod_exp_ioctl";
318static const char *UBSEC_F8 = "rsa_mod_exp_crt_ioctl";
319/* #endif */
320#ifndef OPENSSL_NO_DSA
321static const char *UBSEC_F9 = "dsa_sign_ioctl";
322static const char *UBSEC_F10 = "dsa_verify_ioctl";
323#endif
324static const char *UBSEC_F11 = "math_accelerate_ioctl";
325static const char *UBSEC_F12 = "rng_ioctl";
326static const char *UBSEC_F13 = "ubsec_max_key_len_ioctl";
327
328/* Destructor (complements the "ENGINE_ubsec()" constructor) */
329static int ubsec_destroy(ENGINE *e)
330 {
331 ERR_unload_UBSEC_strings();
332 return 1;
333 }
334
335/* (de)initialisation functions. */
336static int ubsec_init(ENGINE *e)
337 {
338 t_UBSEC_ubsec_bytes_to_bits *p1;
339 t_UBSEC_ubsec_bits_to_bytes *p2;
340 t_UBSEC_ubsec_open *p3;
341 t_UBSEC_ubsec_close *p4;
342#ifndef OPENSSL_NO_DH
343 t_UBSEC_diffie_hellman_generate_ioctl *p5;
344 t_UBSEC_diffie_hellman_agree_ioctl *p6;
345#endif
346/* #ifndef OPENSSL_NO_RSA */
347 t_UBSEC_rsa_mod_exp_ioctl *p7;
348 t_UBSEC_rsa_mod_exp_crt_ioctl *p8;
349/* #endif */
350#ifndef OPENSSL_NO_DSA
351 t_UBSEC_dsa_sign_ioctl *p9;
352 t_UBSEC_dsa_verify_ioctl *p10;
353#endif
354 t_UBSEC_math_accelerate_ioctl *p11;
355 t_UBSEC_rng_ioctl *p12;
356 t_UBSEC_max_key_len_ioctl *p13;
357 int fd = 0;
358
359 if(ubsec_dso != NULL)
360 {
361 UBSECerr(UBSEC_F_UBSEC_INIT, UBSEC_R_ALREADY_LOADED);
362 goto err;
363 }
364 /*
365 * Attempt to load libubsec.so/ubsec.dll/whatever.
366 */
367 ubsec_dso = DSO_load(NULL, UBSEC_LIBNAME, NULL, 0);
368 if(ubsec_dso == NULL)
369 {
370 UBSECerr(UBSEC_F_UBSEC_INIT, UBSEC_R_DSO_FAILURE);
371 goto err;
372 }
373
374 if (
375 !(p1 = (t_UBSEC_ubsec_bytes_to_bits *) DSO_bind_func(ubsec_dso, UBSEC_F1)) ||
376 !(p2 = (t_UBSEC_ubsec_bits_to_bytes *) DSO_bind_func(ubsec_dso, UBSEC_F2)) ||
377 !(p3 = (t_UBSEC_ubsec_open *) DSO_bind_func(ubsec_dso, UBSEC_F3)) ||
378 !(p4 = (t_UBSEC_ubsec_close *) DSO_bind_func(ubsec_dso, UBSEC_F4)) ||
379#ifndef OPENSSL_NO_DH
380 !(p5 = (t_UBSEC_diffie_hellman_generate_ioctl *)
381 DSO_bind_func(ubsec_dso, UBSEC_F5)) ||
382 !(p6 = (t_UBSEC_diffie_hellman_agree_ioctl *)
383 DSO_bind_func(ubsec_dso, UBSEC_F6)) ||
384#endif
385/* #ifndef OPENSSL_NO_RSA */
386 !(p7 = (t_UBSEC_rsa_mod_exp_ioctl *) DSO_bind_func(ubsec_dso, UBSEC_F7)) ||
387 !(p8 = (t_UBSEC_rsa_mod_exp_crt_ioctl *) DSO_bind_func(ubsec_dso, UBSEC_F8)) ||
388/* #endif */
389#ifndef OPENSSL_NO_DSA
390 !(p9 = (t_UBSEC_dsa_sign_ioctl *) DSO_bind_func(ubsec_dso, UBSEC_F9)) ||
391 !(p10 = (t_UBSEC_dsa_verify_ioctl *) DSO_bind_func(ubsec_dso, UBSEC_F10)) ||
392#endif
393 !(p11 = (t_UBSEC_math_accelerate_ioctl *)
394 DSO_bind_func(ubsec_dso, UBSEC_F11)) ||
395 !(p12 = (t_UBSEC_rng_ioctl *) DSO_bind_func(ubsec_dso, UBSEC_F12)) ||
396 !(p13 = (t_UBSEC_max_key_len_ioctl *) DSO_bind_func(ubsec_dso, UBSEC_F13)))
397 {
398 UBSECerr(UBSEC_F_UBSEC_INIT, UBSEC_R_DSO_FAILURE);
399 goto err;
400 }
401
402 /* Copy the pointers */
403 p_UBSEC_ubsec_bytes_to_bits = p1;
404 p_UBSEC_ubsec_bits_to_bytes = p2;
405 p_UBSEC_ubsec_open = p3;
406 p_UBSEC_ubsec_close = p4;
407#ifndef OPENSSL_NO_DH
408 p_UBSEC_diffie_hellman_generate_ioctl = p5;
409 p_UBSEC_diffie_hellman_agree_ioctl = p6;
410#endif
411#ifndef OPENSSL_NO_RSA
412 p_UBSEC_rsa_mod_exp_ioctl = p7;
413 p_UBSEC_rsa_mod_exp_crt_ioctl = p8;
414#endif
415#ifndef OPENSSL_NO_DSA
416 p_UBSEC_dsa_sign_ioctl = p9;
417 p_UBSEC_dsa_verify_ioctl = p10;
418#endif
419 p_UBSEC_math_accelerate_ioctl = p11;
420 p_UBSEC_rng_ioctl = p12;
421 p_UBSEC_max_key_len_ioctl = p13;
422
423 /* Perform an open to see if there's actually any unit running. */
424 if (((fd = p_UBSEC_ubsec_open(UBSEC_KEY_DEVICE_NAME)) > 0) && (p_UBSEC_max_key_len_ioctl(fd, &max_key_len) == 0))
425 {
426 p_UBSEC_ubsec_close(fd);
427 return 1;
428 }
429 else
430 {
431 UBSECerr(UBSEC_F_UBSEC_INIT, UBSEC_R_UNIT_FAILURE);
432 }
433
434err:
435 if(ubsec_dso)
436 DSO_free(ubsec_dso);
437 p_UBSEC_ubsec_bytes_to_bits = NULL;
438 p_UBSEC_ubsec_bits_to_bytes = NULL;
439 p_UBSEC_ubsec_open = NULL;
440 p_UBSEC_ubsec_close = NULL;
441#ifndef OPENSSL_NO_DH
442 p_UBSEC_diffie_hellman_generate_ioctl = NULL;
443 p_UBSEC_diffie_hellman_agree_ioctl = NULL;
444#endif
445#ifndef OPENSSL_NO_RSA
446 p_UBSEC_rsa_mod_exp_ioctl = NULL;
447 p_UBSEC_rsa_mod_exp_crt_ioctl = NULL;
448#endif
449#ifndef OPENSSL_NO_DSA
450 p_UBSEC_dsa_sign_ioctl = NULL;
451 p_UBSEC_dsa_verify_ioctl = NULL;
452#endif
453 p_UBSEC_math_accelerate_ioctl = NULL;
454 p_UBSEC_rng_ioctl = NULL;
455 p_UBSEC_max_key_len_ioctl = NULL;
456
457 return 0;
458 }
459
460static int ubsec_finish(ENGINE *e)
461 {
462 if(ubsec_dso == NULL)
463 {
464 UBSECerr(UBSEC_F_UBSEC_FINISH, UBSEC_R_NOT_LOADED);
465 return 0;
466 }
467 if(!DSO_free(ubsec_dso))
468 {
469 UBSECerr(UBSEC_F_UBSEC_FINISH, UBSEC_R_DSO_FAILURE);
470 return 0;
471 }
472 ubsec_dso = NULL;
473 p_UBSEC_ubsec_bytes_to_bits = NULL;
474 p_UBSEC_ubsec_bits_to_bytes = NULL;
475 p_UBSEC_ubsec_open = NULL;
476 p_UBSEC_ubsec_close = NULL;
477#ifndef OPENSSL_NO_DH
478 p_UBSEC_diffie_hellman_generate_ioctl = NULL;
479 p_UBSEC_diffie_hellman_agree_ioctl = NULL;
480#endif
481#ifndef OPENSSL_NO_RSA
482 p_UBSEC_rsa_mod_exp_ioctl = NULL;
483 p_UBSEC_rsa_mod_exp_crt_ioctl = NULL;
484#endif
485#ifndef OPENSSL_NO_DSA
486 p_UBSEC_dsa_sign_ioctl = NULL;
487 p_UBSEC_dsa_verify_ioctl = NULL;
488#endif
489 p_UBSEC_math_accelerate_ioctl = NULL;
490 p_UBSEC_rng_ioctl = NULL;
491 p_UBSEC_max_key_len_ioctl = NULL;
492 return 1;
493 }
494
495static int ubsec_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)())
496 {
497 int initialised = ((ubsec_dso == NULL) ? 0 : 1);
498 switch(cmd)
499 {
500 case UBSEC_CMD_SO_PATH:
501 if(p == NULL)
502 {
503 UBSECerr(UBSEC_F_UBSEC_CTRL,ERR_R_PASSED_NULL_PARAMETER);
504 return 0;
505 }
506 if(initialised)
507 {
508 UBSECerr(UBSEC_F_UBSEC_CTRL,UBSEC_R_ALREADY_LOADED);
509 return 0;
510 }
511 UBSEC_LIBNAME = (const char *)p;
512 return 1;
513 default:
514 break;
515 }
516 UBSECerr(UBSEC_F_UBSEC_CTRL,UBSEC_R_CTRL_COMMAND_NOT_IMPLEMENTED);
517 return 0;
518 }
519
520static int ubsec_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
521 const BIGNUM *m, BN_CTX *ctx)
522 {
523 int y_len = 0;
524 int fd;
525
526 if(ubsec_dso == NULL)
527 {
528 UBSECerr(UBSEC_F_UBSEC_MOD_EXP, UBSEC_R_NOT_LOADED);
529 return 0;
530 }
531
532 /* Check if hardware can't handle this argument. */
533 y_len = BN_num_bits(m);
534 if (y_len > max_key_len) {
535 UBSECerr(UBSEC_F_UBSEC_MOD_EXP, UBSEC_R_SIZE_TOO_LARGE_OR_TOO_SMALL);
536 return BN_mod_exp(r, a, p, m, ctx);
537 }
538
539 if(!bn_wexpand(r, m->top))
540 {
541 UBSECerr(UBSEC_F_UBSEC_MOD_EXP, UBSEC_R_BN_EXPAND_FAIL);
542 return 0;
543 }
544 memset(r->d, 0, BN_num_bytes(m));
545
546 if ((fd = p_UBSEC_ubsec_open(UBSEC_KEY_DEVICE_NAME)) <= 0) {
547 fd = 0;
548 UBSECerr(UBSEC_F_UBSEC_INIT, UBSEC_R_UNIT_FAILURE);
549 return BN_mod_exp(r, a, p, m, ctx);
550 }
551
552 if (p_UBSEC_rsa_mod_exp_ioctl(fd, (unsigned char *)a->d, BN_num_bits(a),
553 (unsigned char *)m->d, BN_num_bits(m), (unsigned char *)p->d,
554 BN_num_bits(p), (unsigned char *)r->d, &y_len) != 0)
555 {
556 UBSECerr(UBSEC_F_UBSEC_MOD_EXP, UBSEC_R_REQUEST_FAILED);
557 p_UBSEC_ubsec_close(fd);
558
559 return BN_mod_exp(r, a, p, m, ctx);
560 }
561
562 p_UBSEC_ubsec_close(fd);
563
564 r->top = (BN_num_bits(m)+BN_BITS2-1)/BN_BITS2;
565 return 1;
566 }
567
568#ifndef OPENSSL_NO_RSA
569static int ubsec_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa)
570 {
571 BN_CTX *ctx;
572 int to_return = 0;
573
574 if((ctx = BN_CTX_new()) == NULL)
575 goto err;
576
577 if(!rsa->p || !rsa->q || !rsa->dmp1 || !rsa->dmq1 || !rsa->iqmp)
578 {
579 UBSECerr(UBSEC_F_UBSEC_RSA_MOD_EXP, UBSEC_R_MISSING_KEY_COMPONENTS);
580 goto err;
581 }
582
583 to_return = ubsec_mod_exp_crt(r0, I, rsa->p, rsa->q, rsa->dmp1,
584 rsa->dmq1, rsa->iqmp, ctx);
585 if (to_return == FAIL_TO_SOFTWARE)
586 {
587 /*
588 * Do in software as hardware failed.
589 */
590 const RSA_METHOD *meth = RSA_PKCS1_SSLeay();
591 to_return = (*meth->rsa_mod_exp)(r0, I, rsa);
592 }
593err:
594 if(ctx)
595 BN_CTX_free(ctx);
596 return to_return;
597 }
598#endif
599
600static int ubsec_mod_exp_crt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
601 const BIGNUM *q, const BIGNUM *dp,
602 const BIGNUM *dq, const BIGNUM *qinv, BN_CTX *ctx)
603 {
604 int y_len,
605 m_len,
606 fd;
607
608 m_len = BN_num_bytes(p) + BN_num_bytes(q) + 1;
609 y_len = BN_num_bits(p) + BN_num_bits(q);
610
611 /* Check if hardware can't handle this argument. */
612 if (y_len > max_key_len) {
613 UBSECerr(UBSEC_F_UBSEC_MOD_EXP, UBSEC_R_SIZE_TOO_LARGE_OR_TOO_SMALL);
614 return FAIL_TO_SOFTWARE;
615 }
616
617 if (!bn_wexpand(r, p->top + q->top + 1)) {
618 UBSECerr(UBSEC_F_UBSEC_RSA_MOD_EXP_CRT, UBSEC_R_BN_EXPAND_FAIL);
619 return 0;
620 }
621
622 if ((fd = p_UBSEC_ubsec_open(UBSEC_KEY_DEVICE_NAME)) <= 0) {
623 fd = 0;
624 UBSECerr(UBSEC_F_UBSEC_INIT, UBSEC_R_UNIT_FAILURE);
625 return FAIL_TO_SOFTWARE;
626 }
627
628 if (p_UBSEC_rsa_mod_exp_crt_ioctl(fd,
629 (unsigned char *)a->d, BN_num_bits(a),
630 (unsigned char *)qinv->d, BN_num_bits(qinv),
631 (unsigned char *)dp->d, BN_num_bits(dp),
632 (unsigned char *)p->d, BN_num_bits(p),
633 (unsigned char *)dq->d, BN_num_bits(dq),
634 (unsigned char *)q->d, BN_num_bits(q),
635 (unsigned char *)r->d, &y_len) != 0) {
636 UBSECerr(UBSEC_F_UBSEC_MOD_EXP, UBSEC_R_REQUEST_FAILED);
637 p_UBSEC_ubsec_close(fd);
638 return FAIL_TO_SOFTWARE;
639 }
640
641 p_UBSEC_ubsec_close(fd);
642
643 r->top = (BN_num_bits(p) + BN_num_bits(q) + BN_BITS2 - 1)/BN_BITS2;
644 return 1;
645}
646
647#ifndef OPENSSL_NO_DSA
648#if NOT_USED
649static int ubsec_dsa_mod_exp(DSA *dsa, BIGNUM *rr, BIGNUM *a1,
650 BIGNUM *p1, BIGNUM *a2, BIGNUM *p2, BIGNUM *m,
651 BN_CTX *ctx, BN_MONT_CTX *in_mont)
652 {
653 BIGNUM t;
654 int to_return = 0;
655
656 BN_init(&t);
657 /* let rr = a1 ^ p1 mod m */
658 if (!ubsec_mod_exp(rr,a1,p1,m,ctx)) goto end;
659 /* let t = a2 ^ p2 mod m */
660 if (!ubsec_mod_exp(&t,a2,p2,m,ctx)) goto end;
661 /* let rr = rr * t mod m */
662 if (!BN_mod_mul(rr,rr,&t,m,ctx)) goto end;
663 to_return = 1;
664end:
665 BN_free(&t);
666 return to_return;
667 }
668
669static int ubsec_mod_exp_dsa(DSA *dsa, BIGNUM *r, BIGNUM *a,
670 const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx,
671 BN_MONT_CTX *m_ctx)
672 {
673 return ubsec_mod_exp(r, a, p, m, ctx);
674 }
675#endif
676#endif
677
678/*
679 * This function is aliased to mod_exp (with the mont stuff dropped).
680 */
681static int ubsec_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
682 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx)
683 {
684 int ret = 0;
685
686#ifndef OPENSSL_NO_RSA
687 /* Do in software if the key is too large for the hardware. */
688 if (BN_num_bits(m) > max_key_len)
689 {
690 const RSA_METHOD *meth = RSA_PKCS1_SSLeay();
691 ret = (*meth->bn_mod_exp)(r, a, p, m, ctx, m_ctx);
692 }
693 else
694#endif
695 {
696 ret = ubsec_mod_exp(r, a, p, m, ctx);
697 }
698
699 return ret;
700 }
701
702#ifndef OPENSSL_NO_DH
703/* This function is aliased to mod_exp (with the dh and mont dropped). */
704static int ubsec_mod_exp_dh(const DH *dh, BIGNUM *r, const BIGNUM *a,
705 const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx,
706 BN_MONT_CTX *m_ctx)
707 {
708 return ubsec_mod_exp(r, a, p, m, ctx);
709 }
710#endif
711
712#ifndef OPENSSL_NO_DSA
713static DSA_SIG *ubsec_dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa)
714 {
715 DSA_SIG *to_return = NULL;
716 int s_len = 160, r_len = 160, d_len, fd;
717 BIGNUM m, *r=NULL, *s=NULL;
718
719 BN_init(&m);
720
721 s = BN_new();
722 r = BN_new();
723 if ((s == NULL) || (r==NULL))
724 goto err;
725
726 d_len = p_UBSEC_ubsec_bytes_to_bits((unsigned char *)dgst, dlen);
727
728 if(!bn_wexpand(r, (160+BN_BITS2-1)/BN_BITS2) ||
729 (!bn_wexpand(s, (160+BN_BITS2-1)/BN_BITS2))) {
730 UBSECerr(UBSEC_F_UBSEC_DSA_SIGN, UBSEC_R_BN_EXPAND_FAIL);
731 goto err;
732 }
733
734 if (BN_bin2bn(dgst,dlen,&m) == NULL) {
735 UBSECerr(UBSEC_F_UBSEC_DSA_SIGN, UBSEC_R_BN_EXPAND_FAIL);
736 goto err;
737 }
738
739 if ((fd = p_UBSEC_ubsec_open(UBSEC_KEY_DEVICE_NAME)) <= 0) {
740 const DSA_METHOD *meth;
741 fd = 0;
742 UBSECerr(UBSEC_F_UBSEC_INIT, UBSEC_R_UNIT_FAILURE);
743 meth = DSA_OpenSSL();
744 to_return = meth->dsa_do_sign(dgst, dlen, dsa);
745 goto err;
746 }
747
748 if (p_UBSEC_dsa_sign_ioctl(fd, 0, /* compute hash before signing */
749 (unsigned char *)dgst, d_len,
750 NULL, 0, /* compute random value */
751 (unsigned char *)dsa->p->d, BN_num_bits(dsa->p),
752 (unsigned char *)dsa->q->d, BN_num_bits(dsa->q),
753 (unsigned char *)dsa->g->d, BN_num_bits(dsa->g),
754 (unsigned char *)dsa->priv_key->d, BN_num_bits(dsa->priv_key),
755 (unsigned char *)r->d, &r_len,
756 (unsigned char *)s->d, &s_len ) != 0) {
757 const DSA_METHOD *meth;
758
759 UBSECerr(UBSEC_F_UBSEC_DSA_SIGN, UBSEC_R_REQUEST_FAILED);
760 p_UBSEC_ubsec_close(fd);
761 meth = DSA_OpenSSL();
762 to_return = meth->dsa_do_sign(dgst, dlen, dsa);
763
764 goto err;
765 }
766
767 p_UBSEC_ubsec_close(fd);
768
769 r->top = (160+BN_BITS2-1)/BN_BITS2;
770 s->top = (160+BN_BITS2-1)/BN_BITS2;
771
772 to_return = DSA_SIG_new();
773 if(to_return == NULL) {
774 UBSECerr(UBSEC_F_UBSEC_DSA_SIGN, UBSEC_R_BN_EXPAND_FAIL);
775 goto err;
776 }
777
778 to_return->r = r;
779 to_return->s = s;
780
781err:
782 if (!to_return) {
783 if (r) BN_free(r);
784 if (s) BN_free(s);
785 }
786 BN_clear_free(&m);
787 return to_return;
788}
789
790static int ubsec_dsa_verify(const unsigned char *dgst, int dgst_len,
791 DSA_SIG *sig, DSA *dsa)
792 {
793 int v_len, d_len;
794 int to_return = 0;
795 int fd;
796 BIGNUM v;
797
798 BN_init(&v);
799
800 if(!bn_wexpand(&v, dsa->p->top)) {
801 UBSECerr(UBSEC_F_UBSEC_DSA_VERIFY ,UBSEC_R_BN_EXPAND_FAIL);
802 goto err;
803 }
804
805 v_len = BN_num_bits(dsa->p);
806
807 d_len = p_UBSEC_ubsec_bytes_to_bits((unsigned char *)dgst, dgst_len);
808
809 if ((fd = p_UBSEC_ubsec_open(UBSEC_KEY_DEVICE_NAME)) <= 0) {
810 const DSA_METHOD *meth;
811 fd = 0;
812 UBSECerr(UBSEC_F_UBSEC_INIT, UBSEC_R_UNIT_FAILURE);
813 meth = DSA_OpenSSL();
814 to_return = meth->dsa_do_verify(dgst, dgst_len, sig, dsa);
815 goto err;
816 }
817
818 if (p_UBSEC_dsa_verify_ioctl(fd, 0, /* compute hash before signing */
819 (unsigned char *)dgst, d_len,
820 (unsigned char *)dsa->p->d, BN_num_bits(dsa->p),
821 (unsigned char *)dsa->q->d, BN_num_bits(dsa->q),
822 (unsigned char *)dsa->g->d, BN_num_bits(dsa->g),
823 (unsigned char *)dsa->pub_key->d, BN_num_bits(dsa->pub_key),
824 (unsigned char *)sig->r->d, BN_num_bits(sig->r),
825 (unsigned char *)sig->s->d, BN_num_bits(sig->s),
826 (unsigned char *)v.d, &v_len) != 0) {
827 const DSA_METHOD *meth;
828 UBSECerr(UBSEC_F_UBSEC_DSA_VERIFY , UBSEC_R_REQUEST_FAILED);
829 p_UBSEC_ubsec_close(fd);
830
831 meth = DSA_OpenSSL();
832 to_return = meth->dsa_do_verify(dgst, dgst_len, sig, dsa);
833
834 goto err;
835 }
836
837 p_UBSEC_ubsec_close(fd);
838
839 to_return = 1;
840err:
841 BN_clear_free(&v);
842 return to_return;
843 }
844#endif
845
846#ifndef OPENSSL_NO_DH
847static int ubsec_dh_compute_key (unsigned char *key,const BIGNUM *pub_key,DH *dh)
848 {
849 int ret = -1,
850 k_len,
851 fd;
852
853 k_len = BN_num_bits(dh->p);
854
855 if ((fd = p_UBSEC_ubsec_open(UBSEC_KEY_DEVICE_NAME)) <= 0)
856 {
857 const DH_METHOD *meth;
858 ENGINEerr(UBSEC_F_UBSEC_INIT, UBSEC_R_UNIT_FAILURE);
859 meth = DH_OpenSSL();
860 ret = meth->compute_key(key, pub_key, dh);
861 goto err;
862 }
863
864 if (p_UBSEC_diffie_hellman_agree_ioctl(fd,
865 (unsigned char *)dh->priv_key->d, BN_num_bits(dh->priv_key),
866 (unsigned char *)pub_key->d, BN_num_bits(pub_key),
867 (unsigned char *)dh->p->d, BN_num_bits(dh->p),
868 key, &k_len) != 0)
869 {
870 /* Hardware's a no go, failover to software */
871 const DH_METHOD *meth;
872 ENGINEerr(UBSEC_F_UBSEC_DH_COMPUTE_KEY, UBSEC_R_REQUEST_FAILED);
873 p_UBSEC_ubsec_close(fd);
874
875 meth = DH_OpenSSL();
876 ret = meth->compute_key(key, pub_key, dh);
877
878 goto err;
879 }
880
881 p_UBSEC_ubsec_close(fd);
882
883 ret = p_UBSEC_ubsec_bits_to_bytes(k_len);
884err:
885 return ret;
886 }
887
888static int ubsec_dh_generate_key (DH *dh)
889 {
890 int ret = 0,
891 random_bits = 0,
892 pub_key_len = 0,
893 priv_key_len = 0,
894 fd;
895 BIGNUM *pub_key = NULL;
896 BIGNUM *priv_key = NULL;
897
898 /*
899 * How many bits should Random x be? dh_key.c
900 * sets the range from 0 to num_bits(modulus) ???
901 */
902
903 if (dh->priv_key == NULL)
904 {
905 priv_key = BN_new();
906 if (priv_key == NULL) goto err;
907 priv_key_len = BN_num_bits(dh->p);
908 bn_wexpand(priv_key, dh->p->top);
909 do
910 if (!BN_rand_range(priv_key, dh->p)) goto err;
911 while (BN_is_zero(priv_key));
912 random_bits = BN_num_bits(priv_key);
913 }
914 else
915 {
916 priv_key = dh->priv_key;
917 }
918
919 if (dh->pub_key == NULL)
920 {
921 pub_key = BN_new();
922 pub_key_len = BN_num_bits(dh->p);
923 bn_wexpand(pub_key, dh->p->top);
924 if(pub_key == NULL) goto err;
925 }
926 else
927 {
928 pub_key = dh->pub_key;
929 }
930
931 if ((fd = p_UBSEC_ubsec_open(UBSEC_KEY_DEVICE_NAME)) <= 0)
932 {
933 const DH_METHOD *meth;
934 ENGINEerr(UBSEC_F_UBSEC_INIT, UBSEC_R_UNIT_FAILURE);
935 meth = DH_OpenSSL();
936 ret = meth->generate_key(dh);
937 goto err;
938 }
939
940 if (p_UBSEC_diffie_hellman_generate_ioctl(fd,
941 (unsigned char *)priv_key->d, &priv_key_len,
942 (unsigned char *)pub_key->d, &pub_key_len,
943 (unsigned char *)dh->g->d, BN_num_bits(dh->g),
944 (unsigned char *)dh->p->d, BN_num_bits(dh->p),
945 0, 0, random_bits) != 0)
946 {
947 /* Hardware's a no go, failover to software */
948 const DH_METHOD *meth;
949
950 ENGINEerr(UBSEC_F_UBSEC_DH_COMPUTE_KEY, UBSEC_R_REQUEST_FAILED);
951 p_UBSEC_ubsec_close(fd);
952
953 meth = DH_OpenSSL();
954 ret = meth->generate_key(dh);
955
956 goto err;
957 }
958
959 p_UBSEC_ubsec_close(fd);
960
961 dh->pub_key = pub_key;
962 dh->pub_key->top = (pub_key_len + BN_BITS2-1) / BN_BITS2;
963 dh->priv_key = priv_key;
964 dh->priv_key->top = (priv_key_len + BN_BITS2-1) / BN_BITS2;
965
966 ret = 1;
967err:
968 return ret;
969 }
970#endif
971
972#if NOT_USED
973static int ubsec_rand_bytes(unsigned char * buf,
974 int num)
975 {
976 int ret = 0,
977 fd;
978
979 if ((fd = p_UBSEC_ubsec_open(UBSEC_KEY_DEVICE_NAME)) <= 0)
980 {
981 const RAND_METHOD *meth;
982 ENGINEerr(UBSEC_F_UBSEC_INIT, UBSEC_R_UNIT_FAILURE);
983 num = p_UBSEC_ubsec_bits_to_bytes(num);
984 meth = RAND_SSLeay();
985 meth->seed(buf, num);
986 ret = meth->bytes(buf, num);
987 goto err;
988 }
989
990 num *= 8; /* bytes to bits */
991
992 if (p_UBSEC_rng_ioctl(fd,
993 UBSEC_RNG_DIRECT,
994 buf,
995 &num) != 0)
996 {
997 /* Hardware's a no go, failover to software */
998 const RAND_METHOD *meth;
999
1000 ENGINEerr(UBSEC_F_UBSEC_RNG_BYTES, UBSEC_R_REQUEST_FAILED);
1001 p_UBSEC_ubsec_close(fd);
1002
1003 num = p_UBSEC_ubsec_bits_to_bytes(num);
1004 meth = RAND_SSLeay();
1005 meth->seed(buf, num);
1006 ret = meth->bytes(buf, num);
1007
1008 goto err;
1009 }
1010
1011 p_UBSEC_ubsec_close(fd);
1012
1013 ret = 1;
1014err:
1015 return(ret);
1016 }
1017
1018
1019static int ubsec_rand_status(void)
1020 {
1021 return 0;
1022 }
1023#endif
1024
1025/* This stuff is needed if this ENGINE is being compiled into a self-contained
1026 * shared-library. */
1027#ifdef ENGINE_DYNAMIC_SUPPORT
1028static int bind_fn(ENGINE *e, const char *id)
1029 {
1030 if(id && (strcmp(id, engine_ubsec_id) != 0))
1031 return 0;
1032 if(!bind_helper(e))
1033 return 0;
1034 return 1;
1035 }
1036IMPLEMENT_DYNAMIC_CHECK_FN()
1037IMPLEMENT_DYNAMIC_BIND_FN(bind_fn)
1038#endif /* ENGINE_DYNAMIC_SUPPORT */
1039
1040#endif /* !OPENSSL_NO_HW_UBSEC */
1041#endif /* !OPENSSL_NO_HW */
diff --git a/src/lib/libcrypto/engine/hw_ubsec_err.c b/src/lib/libcrypto/engine/hw_ubsec_err.c
new file mode 100644
index 0000000000..d707331fc2
--- /dev/null
+++ b/src/lib/libcrypto/engine/hw_ubsec_err.c
@@ -0,0 +1,151 @@
1/* hw_ubsec_err.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file,
58 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include "hw_ubsec_err.h"
64
65/* BEGIN ERROR CODES */
66#ifndef OPENSSL_NO_ERR
67static ERR_STRING_DATA UBSEC_str_functs[]=
68 {
69{ERR_PACK(0,UBSEC_F_UBSEC_CTRL,0), "UBSEC_CTRL"},
70{ERR_PACK(0,UBSEC_F_UBSEC_DH_COMPUTE_KEY,0), "UBSEC_DH_COMPUTE_KEY"},
71{ERR_PACK(0,UBSEC_F_UBSEC_DSA_SIGN,0), "UBSEC_DSA_SIGN"},
72{ERR_PACK(0,UBSEC_F_UBSEC_DSA_VERIFY,0), "UBSEC_DSA_VERIFY"},
73{ERR_PACK(0,UBSEC_F_UBSEC_FINISH,0), "UBSEC_FINISH"},
74{ERR_PACK(0,UBSEC_F_UBSEC_INIT,0), "UBSEC_INIT"},
75{ERR_PACK(0,UBSEC_F_UBSEC_MOD_EXP,0), "UBSEC_MOD_EXP"},
76{ERR_PACK(0,UBSEC_F_UBSEC_RNG_BYTES,0), "UBSEC_RNG_BYTES"},
77{ERR_PACK(0,UBSEC_F_UBSEC_RSA_MOD_EXP,0), "UBSEC_RSA_MOD_EXP"},
78{ERR_PACK(0,UBSEC_F_UBSEC_RSA_MOD_EXP_CRT,0), "UBSEC_RSA_MOD_EXP_CRT"},
79{0,NULL}
80 };
81
82static ERR_STRING_DATA UBSEC_str_reasons[]=
83 {
84{UBSEC_R_ALREADY_LOADED ,"already loaded"},
85{UBSEC_R_BN_EXPAND_FAIL ,"bn expand fail"},
86{UBSEC_R_CTRL_COMMAND_NOT_IMPLEMENTED ,"ctrl command not implemented"},
87{UBSEC_R_DSO_FAILURE ,"dso failure"},
88{UBSEC_R_MISSING_KEY_COMPONENTS ,"missing key components"},
89{UBSEC_R_NOT_LOADED ,"not loaded"},
90{UBSEC_R_REQUEST_FAILED ,"request failed"},
91{UBSEC_R_SIZE_TOO_LARGE_OR_TOO_SMALL ,"size too large or too small"},
92{UBSEC_R_UNIT_FAILURE ,"unit failure"},
93{0,NULL}
94 };
95
96#endif
97
98#ifdef UBSEC_LIB_NAME
99static ERR_STRING_DATA UBSEC_lib_name[]=
100 {
101{0 ,UBSEC_LIB_NAME},
102{0,NULL}
103 };
104#endif
105
106
107static int UBSEC_lib_error_code=0;
108static int UBSEC_error_init=1;
109
110static void ERR_load_UBSEC_strings(void)
111 {
112 if (UBSEC_lib_error_code == 0)
113 UBSEC_lib_error_code=ERR_get_next_error_library();
114
115 if (UBSEC_error_init)
116 {
117 UBSEC_error_init=0;
118#ifndef OPENSSL_NO_ERR
119 ERR_load_strings(UBSEC_lib_error_code,UBSEC_str_functs);
120 ERR_load_strings(UBSEC_lib_error_code,UBSEC_str_reasons);
121#endif
122
123#ifdef UBSEC_LIB_NAME
124 UBSEC_lib_name->error = ERR_PACK(UBSEC_lib_error_code,0,0);
125 ERR_load_strings(0,UBSEC_lib_name);
126#endif
127 }
128 }
129
130static void ERR_unload_UBSEC_strings(void)
131 {
132 if (UBSEC_error_init == 0)
133 {
134#ifndef OPENSSL_NO_ERR
135 ERR_unload_strings(UBSEC_lib_error_code,UBSEC_str_functs);
136 ERR_unload_strings(UBSEC_lib_error_code,UBSEC_str_reasons);
137#endif
138
139#ifdef UBSEC_LIB_NAME
140 ERR_unload_strings(0,UBSEC_lib_name);
141#endif
142 UBSEC_error_init=1;
143 }
144 }
145
146static void ERR_UBSEC_error(int function, int reason, char *file, int line)
147 {
148 if (UBSEC_lib_error_code == 0)
149 UBSEC_lib_error_code=ERR_get_next_error_library();
150 ERR_PUT_error(UBSEC_lib_error_code,function,reason,file,line);
151 }
diff --git a/src/lib/libcrypto/engine/hw_ubsec_err.h b/src/lib/libcrypto/engine/hw_ubsec_err.h
new file mode 100644
index 0000000000..023d3be771
--- /dev/null
+++ b/src/lib/libcrypto/engine/hw_ubsec_err.h
@@ -0,0 +1,95 @@
1/* ====================================================================
2 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * 3. All advertising materials mentioning features or use of this
17 * software must display the following acknowledgment:
18 * "This product includes software developed by the OpenSSL Project
19 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
20 *
21 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission. For written permission, please contact
24 * openssl-core@openssl.org.
25 *
26 * 5. Products derived from this software may not be called "OpenSSL"
27 * nor may "OpenSSL" appear in their names without prior written
28 * permission of the OpenSSL Project.
29 *
30 * 6. Redistributions of any form whatsoever must retain the following
31 * acknowledgment:
32 * "This product includes software developed by the OpenSSL Project
33 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46 * OF THE POSSIBILITY OF SUCH DAMAGE.
47 * ====================================================================
48 *
49 * This product includes cryptographic software written by Eric Young
50 * (eay@cryptsoft.com). This product includes software written by Tim
51 * Hudson (tjh@cryptsoft.com).
52 *
53 */
54
55#ifndef HEADER_UBSEC_ERR_H
56#define HEADER_UBSEC_ERR_H
57
58/* BEGIN ERROR CODES */
59/* The following lines are auto generated by the script mkerr.pl. Any changes
60 * made after this point may be overwritten when the script is next run.
61 */
62static void ERR_load_UBSEC_strings(void);
63static void ERR_unload_UBSEC_strings(void);
64static void ERR_UBSEC_error(int function, int reason, char *file, int line);
65#define UBSECerr(f,r) ERR_UBSEC_error((f),(r),__FILE__,__LINE__)
66
67/* Error codes for the UBSEC functions. */
68
69/* Function codes. */
70#define UBSEC_F_UBSEC_CTRL 100
71#define UBSEC_F_UBSEC_DH_COMPUTE_KEY 101
72#define UBSEC_F_UBSEC_DSA_SIGN 102
73#define UBSEC_F_UBSEC_DSA_VERIFY 103
74#define UBSEC_F_UBSEC_FINISH 104
75#define UBSEC_F_UBSEC_INIT 105
76#define UBSEC_F_UBSEC_MOD_EXP 106
77#define UBSEC_F_UBSEC_RNG_BYTES 107
78#define UBSEC_F_UBSEC_RSA_MOD_EXP 108
79#define UBSEC_F_UBSEC_RSA_MOD_EXP_CRT 109
80
81/* Reason codes. */
82#define UBSEC_R_ALREADY_LOADED 100
83#define UBSEC_R_BN_EXPAND_FAIL 101
84#define UBSEC_R_CTRL_COMMAND_NOT_IMPLEMENTED 102
85#define UBSEC_R_DSO_FAILURE 103
86#define UBSEC_R_MISSING_KEY_COMPONENTS 104
87#define UBSEC_R_NOT_LOADED 105
88#define UBSEC_R_REQUEST_FAILED 106
89#define UBSEC_R_SIZE_TOO_LARGE_OR_TOO_SMALL 107
90#define UBSEC_R_UNIT_FAILURE 108
91
92#ifdef __cplusplus
93}
94#endif
95#endif
diff --git a/src/lib/libcrypto/engine/vendor_defns/aep.h b/src/lib/libcrypto/engine/vendor_defns/aep.h
new file mode 100644
index 0000000000..2b2792d2d6
--- /dev/null
+++ b/src/lib/libcrypto/engine/vendor_defns/aep.h
@@ -0,0 +1,178 @@
1/* This header declares the necessary definitions for using the exponentiation
2 * acceleration capabilities, and rnd number generation of the AEP card.
3 *
4 */
5
6/*
7 *
8 * Some AEP defines
9 *
10 */
11
12/*Successful return value*/
13#define AEP_R_OK 0x00000000
14
15/*Miscelleanous unsuccessful return value*/
16#define AEP_R_GENERAL_ERROR 0x10000001
17
18/*Insufficient host memory*/
19#define AEP_R_HOST_MEMORY 0x10000002
20
21#define AEP_R_FUNCTION_FAILED 0x10000006
22
23/*Invalid arguments in function call*/
24#define AEP_R_ARGUMENTS_BAD 0x10020000
25
26#define AEP_R_NO_TARGET_RESOURCES 0x10030000
27
28/*Error occuring on socket operation*/
29#define AEP_R_SOCKERROR 0x10000010
30
31/*Socket has been closed from the other end*/
32#define AEP_R_SOCKEOF 0x10000011
33
34/*Invalid handles*/
35#define AEP_R_CONNECTION_HANDLE_INVALID 0x100000B3
36
37#define AEP_R_TRANSACTION_HANDLE_INVALID 0x10040000
38
39/*Transaction has not yet returned from accelerator*/
40#define AEP_R_TRANSACTION_NOT_READY 0x00010000
41
42/*There is already a thread waiting on this transaction*/
43#define AEP_R_TRANSACTION_CLAIMED 0x10050000
44
45/*The transaction timed out*/
46#define AEP_R_TIMED_OUT 0x10060000
47
48#define AEP_R_FXN_NOT_IMPLEMENTED 0x10070000
49
50#define AEP_R_TARGET_ERROR 0x10080000
51
52/*Error in the AEP daemon process*/
53#define AEP_R_DAEMON_ERROR 0x10090000
54
55/*Invalid ctx id*/
56#define AEP_R_INVALID_CTX_ID 0x10009000
57
58#define AEP_R_NO_KEY_MANAGER 0x1000a000
59
60/*Error obtaining a mutex*/
61#define AEP_R_MUTEX_BAD 0x000001A0
62
63/*Fxn call before AEP_Initialise ot after AEP_Finialise*/
64#define AEP_R_AEPAPI_NOT_INITIALIZED 0x10000190
65
66/*AEP_Initialise has already been called*/
67#define AEP_R_AEPAPI_ALREADY_INITIALIZED 0x10000191
68
69/*Maximum number of connections to daemon reached*/
70#define AEP_R_NO_MORE_CONNECTION_HNDLS 0x10000200
71
72/*
73 *
74 * Some AEP Type definitions
75 *
76 */
77
78/* an unsigned 8-bit value */
79typedef unsigned char AEP_U8;
80
81/* an unsigned 8-bit character */
82typedef char AEP_CHAR;
83
84/* a BYTE-sized Boolean flag */
85typedef AEP_U8 AEP_BBOOL;
86
87/*Unsigned value, at least 16 bits long*/
88typedef unsigned short AEP_U16;
89
90/* an unsigned value, at least 32 bits long */
91#ifdef SIXTY_FOUR_BIT_LONG
92typedef unsigned int AEP_U32;
93#else
94typedef unsigned long AEP_U32;
95#endif
96
97#ifdef SIXTY_FOUR_BIT_LONG
98typedef unsigned long AEP_U64;
99#else
100typedef struct { unsigned long l1, l2; } AEP_U64;
101#endif
102
103/* at least 32 bits; each bit is a Boolean flag */
104typedef AEP_U32 AEP_FLAGS;
105
106typedef AEP_U8 *AEP_U8_PTR;
107typedef AEP_CHAR *AEP_CHAR_PTR;
108typedef AEP_U32 *AEP_U32_PTR;
109typedef AEP_U64 *AEP_U64_PTR;
110typedef void *AEP_VOID_PTR;
111
112/* Pointer to a AEP_VOID_PTR-- i.e., pointer to pointer to void */
113typedef AEP_VOID_PTR *AEP_VOID_PTR_PTR;
114
115/*Used to identify an AEP connection handle*/
116typedef AEP_U32 AEP_CONNECTION_HNDL;
117
118/*Pointer to an AEP connection handle*/
119typedef AEP_CONNECTION_HNDL *AEP_CONNECTION_HNDL_PTR;
120
121/*Used by an application (in conjunction with the apps process id) to
122identify an individual transaction*/
123typedef AEP_U32 AEP_TRANSACTION_ID;
124
125/*Pointer to an applications transaction identifier*/
126typedef AEP_TRANSACTION_ID *AEP_TRANSACTION_ID_PTR;
127
128/*Return value type*/
129typedef AEP_U32 AEP_RV;
130
131#define MAX_PROCESS_CONNECTIONS 256
132
133#define RAND_BLK_SIZE 1024
134
135typedef enum{
136 NotConnected= 0,
137 Connected= 1,
138 InUse= 2
139} AEP_CONNECTION_STATE;
140
141
142typedef struct AEP_CONNECTION_ENTRY{
143 AEP_CONNECTION_STATE conn_state;
144 AEP_CONNECTION_HNDL conn_hndl;
145} AEP_CONNECTION_ENTRY;
146
147
148typedef AEP_RV t_AEP_OpenConnection(AEP_CONNECTION_HNDL_PTR phConnection);
149typedef AEP_RV t_AEP_CloseConnection(AEP_CONNECTION_HNDL hConnection);
150
151typedef AEP_RV t_AEP_ModExp(AEP_CONNECTION_HNDL hConnection,
152 AEP_VOID_PTR pA, AEP_VOID_PTR pP,
153 AEP_VOID_PTR pN,
154 AEP_VOID_PTR pResult,
155 AEP_TRANSACTION_ID* pidTransID);
156
157typedef AEP_RV t_AEP_ModExpCrt(AEP_CONNECTION_HNDL hConnection,
158 AEP_VOID_PTR pA, AEP_VOID_PTR pP,
159 AEP_VOID_PTR pQ,
160 AEP_VOID_PTR pDmp1, AEP_VOID_PTR pDmq1,
161 AEP_VOID_PTR pIqmp,
162 AEP_VOID_PTR pResult,
163 AEP_TRANSACTION_ID* pidTransID);
164
165#ifdef AEPRAND
166typedef AEP_RV t_AEP_GenRandom(AEP_CONNECTION_HNDL hConnection,
167 AEP_U32 Len,
168 AEP_U32 Type,
169 AEP_VOID_PTR pResult,
170 AEP_TRANSACTION_ID* pidTransID);
171#endif
172
173typedef AEP_RV t_AEP_Initialize(AEP_VOID_PTR pInitArgs);
174typedef AEP_RV t_AEP_Finalize();
175typedef AEP_RV t_AEP_SetBNCallBacks(AEP_RV (*GetBigNumSizeFunc)(),
176 AEP_RV (*MakeAEPBigNumFunc)(),
177 AEP_RV (*ConverAEPBigNumFunc)());
178
diff --git a/src/lib/libcrypto/engine/vendor_defns/atalla.h b/src/lib/libcrypto/engine/vendor_defns/atalla.h
new file mode 100644
index 0000000000..8111649c54
--- /dev/null
+++ b/src/lib/libcrypto/engine/vendor_defns/atalla.h
@@ -0,0 +1,61 @@
1/* This header declares the necessary definitions for using the exponentiation
2 * acceleration capabilities of Atalla cards. The only cryptographic operation
3 * is performed by "ASI_RSAPrivateKeyOpFn" and this takes a structure that
4 * defines an "RSA private key". However, it is really only performing a
5 * regular mod_exp using the supplied modulus and exponent - no CRT form is
6 * being used. Hence, it is a generic mod_exp function in disguise, and we use
7 * it as such.
8 *
9 * Thanks to the people at Atalla for letting me know these definitions are
10 * fine and that they can be reproduced here.
11 *
12 * Geoff.
13 */
14
15typedef struct ItemStr
16 {
17 unsigned char *data;
18 int len;
19 } Item;
20
21typedef struct RSAPrivateKeyStr
22 {
23 void *reserved;
24 Item version;
25 Item modulus;
26 Item publicExponent;
27 Item privateExponent;
28 Item prime[2];
29 Item exponent[2];
30 Item coefficient;
31 } RSAPrivateKey;
32
33/* Predeclare the function pointer types that we dynamically load from the DSO.
34 * These use the same names and form that Ben's original support code had (in
35 * crypto/bn/bn_exp.c) unless of course I've inadvertently changed the style
36 * somewhere along the way!
37 */
38
39typedef int tfnASI_GetPerformanceStatistics(int reset_flag,
40 unsigned int *ret_buf);
41
42typedef int tfnASI_GetHardwareConfig(long card_num, unsigned int *ret_buf);
43
44typedef int tfnASI_RSAPrivateKeyOpFn(RSAPrivateKey * rsaKey,
45 unsigned char *output,
46 unsigned char *input,
47 unsigned int modulus_len);
48
49/* These are the static string constants for the DSO file name and the function
50 * symbol names to bind to. Regrettably, the DSO name on *nix appears to be
51 * "atasi.so" rather than something more consistent like "libatasi.so". At the
52 * time of writing, I'm not sure what the file name on win32 is but clearly
53 * native name translation is not possible (eg libatasi.so on *nix, and
54 * atasi.dll on win32). For the purposes of testing, I have created a symbollic
55 * link called "libatasi.so" so that we can use native name-translation - a
56 * better solution will be needed. */
57static const char *ATALLA_LIBNAME = "atasi";
58static const char *ATALLA_F1 = "ASI_GetHardwareConfig";
59static const char *ATALLA_F2 = "ASI_RSAPrivateKeyOpFn";
60static const char *ATALLA_F3 = "ASI_GetPerformanceStatistics";
61
diff --git a/src/lib/libcrypto/engine/vendor_defns/cswift.h b/src/lib/libcrypto/engine/vendor_defns/cswift.h
new file mode 100644
index 0000000000..0af14a1a92
--- /dev/null
+++ b/src/lib/libcrypto/engine/vendor_defns/cswift.h
@@ -0,0 +1,213 @@
1/* Attribution notice: Rainbow have generously allowed me to reproduce
2 * the necessary definitions here from their API. This means the support
3 * can build independently of whether application builders have the
4 * API or hardware. This will allow developers to easily produce software
5 * that has latent hardware support for any users that have accelertors
6 * installed, without the developers themselves needing anything extra.
7 *
8 * I have only clipped the parts from the CryptoSwift header files that
9 * are (or seem) relevant to the CryptoSwift support code. This is
10 * simply to keep the file sizes reasonable.
11 * [Geoff]
12 */
13
14
15/* NB: These type widths do *not* seem right in general, in particular
16 * they're not terribly friendly to 64-bit architectures (unsigned long)
17 * will be 64-bit on IA-64 for a start. I'm leaving these alone as they
18 * agree with Rainbow's API and this will only be called into question
19 * on platforms with Rainbow support anyway! ;-) */
20
21#ifdef __cplusplus
22extern "C" {
23#endif /* __cplusplus */
24
25typedef long SW_STATUS; /* status */
26typedef unsigned char SW_BYTE; /* 8 bit byte */
27typedef unsigned short SW_U16; /* 16 bit number */
28#if defined(_IRIX)
29#include <sgidefs.h>
30typedef __uint32_t SW_U32;
31#else
32typedef unsigned long SW_U32; /* 32 bit integer */
33#endif
34
35#if defined(WIN32)
36 typedef struct _SW_U64 {
37 SW_U32 low32;
38 SW_U32 high32;
39 } SW_U64; /* 64 bit integer */
40#elif defined(MAC)
41 typedef longlong SW_U64
42#else /* Unix variants */
43 typedef struct _SW_U64 {
44 SW_U32 low32;
45 SW_U32 high32;
46 } SW_U64; /* 64 bit integer */
47#endif
48
49/* status codes */
50#define SW_OK (0L)
51#define SW_ERR_BASE (-10000L)
52#define SW_ERR_NO_CARD (SW_ERR_BASE-1) /* The Card is not present */
53#define SW_ERR_CARD_NOT_READY (SW_ERR_BASE-2) /* The card has not powered */
54 /* up yet */
55#define SW_ERR_TIME_OUT (SW_ERR_BASE-3) /* Execution of a command */
56 /* time out */
57#define SW_ERR_NO_EXECUTE (SW_ERR_BASE-4) /* The Card failed to */
58 /* execute the command */
59#define SW_ERR_INPUT_NULL_PTR (SW_ERR_BASE-5) /* a required pointer is */
60 /* NULL */
61#define SW_ERR_INPUT_SIZE (SW_ERR_BASE-6) /* size is invalid, too */
62 /* small, too large. */
63#define SW_ERR_INVALID_HANDLE (SW_ERR_BASE-7) /* Invalid SW_ACC_CONTEXT */
64 /* handle */
65#define SW_ERR_PENDING (SW_ERR_BASE-8) /* A request is already out- */
66 /* standing at this */
67 /* context handle */
68#define SW_ERR_AVAILABLE (SW_ERR_BASE-9) /* A result is available. */
69#define SW_ERR_NO_PENDING (SW_ERR_BASE-10)/* No request is pending. */
70#define SW_ERR_NO_MEMORY (SW_ERR_BASE-11)/* Not enough memory */
71#define SW_ERR_BAD_ALGORITHM (SW_ERR_BASE-12)/* Invalid algorithm type */
72 /* in SW_PARAM structure */
73#define SW_ERR_MISSING_KEY (SW_ERR_BASE-13)/* No key is associated with */
74 /* context. */
75 /* swAttachKeyParam() is */
76 /* not called. */
77#define SW_ERR_KEY_CMD_MISMATCH \
78 (SW_ERR_BASE-14)/* Cannot perform requested */
79 /* SW_COMMAND_CODE since */
80 /* key attached via */
81 /* swAttachKeyParam() */
82 /* cannot be used for this*/
83 /* SW_COMMAND_CODE. */
84#define SW_ERR_NOT_IMPLEMENTED \
85 (SW_ERR_BASE-15)/* Not implemented */
86#define SW_ERR_BAD_COMMAND (SW_ERR_BASE-16)/* Bad command code */
87#define SW_ERR_BAD_ITEM_SIZE (SW_ERR_BASE-17)/* too small or too large in */
88 /* the "initems" or */
89 /* "outitems". */
90#define SW_ERR_BAD_ACCNUM (SW_ERR_BASE-18)/* Bad accelerator number */
91#define SW_ERR_SELFTEST_FAIL (SW_ERR_BASE-19)/* At least one of the self */
92 /* test fail, look at the */
93 /* selfTestBitmap in */
94 /* SW_ACCELERATOR_INFO for*/
95 /* details. */
96#define SW_ERR_MISALIGN (SW_ERR_BASE-20)/* Certain alogrithms require*/
97 /* key materials aligned */
98 /* in certain order, e.g. */
99 /* 128 bit for CRT */
100#define SW_ERR_OUTPUT_NULL_PTR \
101 (SW_ERR_BASE-21)/* a required pointer is */
102 /* NULL */
103#define SW_ERR_OUTPUT_SIZE \
104 (SW_ERR_BASE-22)/* size is invalid, too */
105 /* small, too large. */
106#define SW_ERR_FIRMWARE_CHECKSUM \
107 (SW_ERR_BASE-23)/* firmware checksum mismatch*/
108 /* download failed. */
109#define SW_ERR_UNKNOWN_FIRMWARE \
110 (SW_ERR_BASE-24)/* unknown firmware error */
111#define SW_ERR_INTERRUPT (SW_ERR_BASE-25)/* request is abort when */
112 /* it's waiting to be */
113 /* completed. */
114#define SW_ERR_NVWRITE_FAIL (SW_ERR_BASE-26)/* error in writing to Non- */
115 /* volatile memory */
116#define SW_ERR_NVWRITE_RANGE (SW_ERR_BASE-27)/* out of range error in */
117 /* writing to NV memory */
118#define SW_ERR_RNG_ERROR (SW_ERR_BASE-28)/* Random Number Generation */
119 /* failure */
120#define SW_ERR_DSS_FAILURE (SW_ERR_BASE-29)/* DSS Sign or Verify failure*/
121#define SW_ERR_MODEXP_FAILURE (SW_ERR_BASE-30)/* Failure in various math */
122 /* calculations */
123#define SW_ERR_ONBOARD_MEMORY (SW_ERR_BASE-31)/* Error in accessing on - */
124 /* board memory */
125#define SW_ERR_FIRMWARE_VERSION \
126 (SW_ERR_BASE-32)/* Wrong version in firmware */
127 /* update */
128#define SW_ERR_ZERO_WORKING_ACCELERATOR \
129 (SW_ERR_BASE-44)/* All accelerators are bad */
130
131
132 /* algorithm type */
133#define SW_ALG_CRT 1
134#define SW_ALG_EXP 2
135#define SW_ALG_DSA 3
136#define SW_ALG_NVDATA 4
137
138 /* command code */
139#define SW_CMD_MODEXP_CRT 1 /* perform Modular Exponentiation using */
140 /* Chinese Remainder Theorem (CRT) */
141#define SW_CMD_MODEXP 2 /* perform Modular Exponentiation */
142#define SW_CMD_DSS_SIGN 3 /* perform DSS sign */
143#define SW_CMD_DSS_VERIFY 4 /* perform DSS verify */
144#define SW_CMD_RAND 5 /* perform random number generation */
145#define SW_CMD_NVREAD 6 /* perform read to nonvolatile RAM */
146#define SW_CMD_NVWRITE 7 /* perform write to nonvolatile RAM */
147
148typedef SW_U32 SW_ALGTYPE; /* alogrithm type */
149typedef SW_U32 SW_STATE; /* state */
150typedef SW_U32 SW_COMMAND_CODE; /* command code */
151typedef SW_U32 SW_COMMAND_BITMAP[4]; /* bitmap */
152
153typedef struct _SW_LARGENUMBER {
154 SW_U32 nbytes; /* number of bytes in the buffer "value" */
155 SW_BYTE* value; /* the large integer as a string of */
156 /* bytes in network (big endian) order */
157} SW_LARGENUMBER;
158
159typedef struct _SW_CRT {
160 SW_LARGENUMBER p; /* prime number p */
161 SW_LARGENUMBER q; /* prime number q */
162 SW_LARGENUMBER dmp1; /* exponent1 */
163 SW_LARGENUMBER dmq1; /* exponent2 */
164 SW_LARGENUMBER iqmp; /* CRT coefficient */
165} SW_CRT;
166
167typedef struct _SW_EXP {
168 SW_LARGENUMBER modulus; /* modulus */
169 SW_LARGENUMBER exponent;/* exponent */
170} SW_EXP;
171
172typedef struct _SW_DSA {
173 SW_LARGENUMBER p; /* */
174 SW_LARGENUMBER q; /* */
175 SW_LARGENUMBER g; /* */
176 SW_LARGENUMBER key; /* private/public key */
177} SW_DSA;
178
179typedef struct _SW_NVDATA {
180 SW_U32 accnum; /* accelerator board number */
181 SW_U32 offset; /* offset in byte */
182} SW_NVDATA;
183
184typedef struct _SW_PARAM {
185 SW_ALGTYPE type; /* type of the alogrithm */
186 union {
187 SW_CRT crt;
188 SW_EXP exp;
189 SW_DSA dsa;
190 SW_NVDATA nvdata;
191 } up;
192} SW_PARAM;
193
194typedef SW_U32 SW_CONTEXT_HANDLE; /* opaque context handle */
195
196
197/* Now the OpenSSL bits, these function types are the for the function
198 * pointers that will bound into the Rainbow shared libraries. */
199typedef SW_STATUS t_swAcquireAccContext(SW_CONTEXT_HANDLE *hac);
200typedef SW_STATUS t_swAttachKeyParam(SW_CONTEXT_HANDLE hac,
201 SW_PARAM *key_params);
202typedef SW_STATUS t_swSimpleRequest(SW_CONTEXT_HANDLE hac,
203 SW_COMMAND_CODE cmd,
204 SW_LARGENUMBER pin[],
205 SW_U32 pin_count,
206 SW_LARGENUMBER pout[],
207 SW_U32 pout_count);
208typedef SW_STATUS t_swReleaseAccContext(SW_CONTEXT_HANDLE hac);
209
210#ifdef __cplusplus
211}
212#endif /* __cplusplus */
213
diff --git a/src/lib/libcrypto/engine/vendor_defns/hw_4758_cca.h b/src/lib/libcrypto/engine/vendor_defns/hw_4758_cca.h
new file mode 100644
index 0000000000..296636e81a
--- /dev/null
+++ b/src/lib/libcrypto/engine/vendor_defns/hw_4758_cca.h
@@ -0,0 +1,149 @@
1/**********************************************************************/
2/* */
3/* Prototypes of the CCA verbs used by the 4758 CCA openssl driver */
4/* */
5/* Maurice Gittens <maurice@gittens.nl> */
6/* */
7/**********************************************************************/
8
9#ifndef __HW_4758_CCA__
10#define __HW_4758_CCA__
11
12/*
13 * Only WIN32 support for now
14 */
15#if defined(WIN32)
16
17 #define CCA_LIB_NAME "CSUNSAPI"
18
19 #define CSNDPKX "CSNDPKX_32"
20 #define CSNDKRR "CSNDKRR_32"
21 #define CSNDPKE "CSNDPKE_32"
22 #define CSNDPKD "CSNDPKD_32"
23 #define CSNDDSV "CSNDDSV_32"
24 #define CSNDDSG "CSNDDSG_32"
25 #define CSNBRNG "CSNBRNG_32"
26
27 #define SECURITYAPI __stdcall
28#else
29 /* Fixme!!
30 Find out the values of these constants for other platforms.
31 */
32 #define CCA_LIB_NAME "CSUNSAPI"
33
34 #define CSNDPKX "CSNDPKX"
35 #define CSNDKRR "CSNDKRR"
36 #define CSNDPKE "CSNDPKE"
37 #define CSNDPKD "CSNDPKD"
38 #define CSNDDSV "CSNDDSV"
39 #define CSNDDSG "CSNDDSG"
40 #define CSNBRNG "CSNBRNG"
41
42 #define SECURITYAPI
43#endif
44
45/*
46 * security API prototypes
47 */
48
49/* PKA Key Record Read */
50typedef void (SECURITYAPI *F_KEYRECORDREAD)
51 (long * return_code,
52 long * reason_code,
53 long * exit_data_length,
54 unsigned char * exit_data,
55 long * rule_array_count,
56 unsigned char * rule_array,
57 unsigned char * key_label,
58 long * key_token_length,
59 unsigned char * key_token);
60
61/* Random Number Generate */
62typedef void (SECURITYAPI *F_RANDOMNUMBERGENERATE)
63 (long * return_code,
64 long * reason_code,
65 long * exit_data_length,
66 unsigned char * exit_data,
67 unsigned char * form,
68 unsigned char * random_number);
69
70/* Digital Signature Generate */
71typedef void (SECURITYAPI *F_DIGITALSIGNATUREGENERATE)
72 (long * return_code,
73 long * reason_code,
74 long * exit_data_length,
75 unsigned char * exit_data,
76 long * rule_array_count,
77 unsigned char * rule_array,
78 long * PKA_private_key_id_length,
79 unsigned char * PKA_private_key_id,
80 long * hash_length,
81 unsigned char * hash,
82 long * signature_field_length,
83 long * signature_bit_length,
84 unsigned char * signature_field);
85
86/* Digital Signature Verify */
87typedef void (SECURITYAPI *F_DIGITALSIGNATUREVERIFY)(
88 long * return_code,
89 long * reason_code,
90 long * exit_data_length,
91 unsigned char * exit_data,
92 long * rule_array_count,
93 unsigned char * rule_array,
94 long * PKA_public_key_id_length,
95 unsigned char * PKA_public_key_id,
96 long * hash_length,
97 unsigned char * hash,
98 long * signature_field_length,
99 unsigned char * signature_field);
100
101/* PKA Public Key Extract */
102typedef void (SECURITYAPI *F_PUBLICKEYEXTRACT)(
103 long * return_code,
104 long * reason_code,
105 long * exit_data_length,
106 unsigned char * exit_data,
107 long * rule_array_count,
108 unsigned char * rule_array,
109 long * source_key_identifier_length,
110 unsigned char * source_key_identifier,
111 long * target_key_token_length,
112 unsigned char * target_key_token);
113
114/* PKA Encrypt */
115typedef void (SECURITYAPI *F_PKAENCRYPT)
116 (long * return_code,
117 long * reason_code,
118 long * exit_data_length,
119 unsigned char * exit_data,
120 long * rule_array_count,
121 unsigned char * rule_array,
122 long * key_value_length,
123 unsigned char * key_value,
124 long * data_struct_length,
125 unsigned char * data_struct,
126 long * RSA_public_key_length,
127 unsigned char * RSA_public_key,
128 long * RSA_encipher_length,
129 unsigned char * RSA_encipher );
130
131/* PKA Decrypt */
132typedef void (SECURITYAPI *F_PKADECRYPT)
133 (long * return_code,
134 long * reason_code,
135 long * exit_data_length,
136 unsigned char * exit_data,
137 long * rule_array_count,
138 unsigned char * rule_array,
139 long * enciphered_key_length,
140 unsigned char * enciphered_key,
141 long * data_struct_length,
142 unsigned char * data_struct,
143 long * RSA_private_key_length,
144 unsigned char * RSA_private_key,
145 long * key_value_length,
146 unsigned char * key_value );
147
148
149#endif
diff --git a/src/lib/libcrypto/evp/bio_ok.c b/src/lib/libcrypto/evp/bio_ok.c
new file mode 100644
index 0000000000..101275d648
--- /dev/null
+++ b/src/lib/libcrypto/evp/bio_ok.c
@@ -0,0 +1,552 @@
1/* crypto/evp/bio_ok.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59/*
60 From: Arne Ansper <arne@cyber.ee>
61
62 Why BIO_f_reliable?
63
64 I wrote function which took BIO* as argument, read data from it
65 and processed it. Then I wanted to store the input file in
66 encrypted form. OK I pushed BIO_f_cipher to the BIO stack
67 and everything was OK. BUT if user types wrong password
68 BIO_f_cipher outputs only garbage and my function crashes. Yes
69 I can and I should fix my function, but BIO_f_cipher is
70 easy way to add encryption support to many exisiting applications
71 and it's hard to debug and fix them all.
72
73 So I wanted another BIO which would catch the incorrect passwords and
74 file damages which cause garbage on BIO_f_cipher's output.
75
76 The easy way is to push the BIO_f_md and save the checksum at
77 the end of the file. However there are several problems with this
78 approach:
79
80 1) you must somehow separate checksum from actual data.
81 2) you need lot's of memory when reading the file, because you
82 must read to the end of the file and verify the checksum before
83 leting the application to read the data.
84
85 BIO_f_reliable tries to solve both problems, so that you can
86 read and write arbitraly long streams using only fixed amount
87 of memory.
88
89 BIO_f_reliable splits data stream into blocks. Each block is prefixed
90 with it's length and suffixed with it's digest. So you need only
91 several Kbytes of memory to buffer single block before verifying
92 it's digest.
93
94 BIO_f_reliable goes futher and adds several important capabilities:
95
96 1) the digest of the block is computed over the whole stream
97 -- so nobody can rearrange the blocks or remove or replace them.
98
99 2) to detect invalid passwords right at the start BIO_f_reliable
100 adds special prefix to the stream. In order to avoid known plain-text
101 attacks this prefix is generated as follows:
102
103 *) digest is initialized with random seed instead of
104 standardized one.
105 *) same seed is written to ouput
106 *) well-known text is then hashed and the output
107 of the digest is also written to output.
108
109 reader can now read the seed from stream, hash the same string
110 and then compare the digest output.
111
112 Bad things: BIO_f_reliable knows what's going on in EVP_Digest. I
113 initialy wrote and tested this code on x86 machine and wrote the
114 digests out in machine-dependent order :( There are people using
115 this code and I cannot change this easily without making existing
116 data files unreadable.
117
118*/
119
120#include <stdio.h>
121#include <errno.h>
122#include "cryptlib.h"
123#include <openssl/buffer.h>
124#include <openssl/bio.h>
125#include <openssl/evp.h>
126#include <openssl/rand.h>
127
128static int ok_write(BIO *h,char *buf,int num);
129static int ok_read(BIO *h,char *buf,int size);
130static long ok_ctrl(BIO *h,int cmd,long arg1,char *arg2);
131static int ok_new(BIO *h);
132static int ok_free(BIO *data);
133static void sig_out(BIO* b);
134static void sig_in(BIO* b);
135static void block_out(BIO* b);
136static void block_in(BIO* b);
137#define OK_BLOCK_SIZE (1024*4)
138#define OK_BLOCK_BLOCK 4
139#define IOBS (OK_BLOCK_SIZE+ OK_BLOCK_BLOCK+ 3*EVP_MAX_MD_SIZE)
140#define WELLKNOWN "The quick brown fox jumped over the lazy dog's back."
141
142#ifndef L_ENDIAN
143#define swapem(x) \
144 ((unsigned long int)((((unsigned long int)(x) & 0x000000ffU) << 24) | \
145 (((unsigned long int)(x) & 0x0000ff00U) << 8) | \
146 (((unsigned long int)(x) & 0x00ff0000U) >> 8) | \
147 (((unsigned long int)(x) & 0xff000000U) >> 24)))
148#else
149#define swapem(x) (x)
150#endif
151
152typedef struct ok_struct
153 {
154 int buf_len;
155 int buf_off;
156 int buf_len_save;
157 int buf_off_save;
158 int cont; /* <= 0 when finished */
159 int finished;
160 EVP_MD_CTX md;
161 int blockout; /* output block is ready */
162 int sigio; /* must process signature */
163 char buf[IOBS];
164 } BIO_OK_CTX;
165
166static BIO_METHOD methods_ok=
167 {
168 BIO_TYPE_CIPHER,"reliable",
169 ok_write,
170 ok_read,
171 NULL, /* ok_puts, */
172 NULL, /* ok_gets, */
173 ok_ctrl,
174 ok_new,
175 ok_free,
176 };
177
178BIO_METHOD *BIO_f_reliable(void)
179 {
180 return(&methods_ok);
181 }
182
183static int ok_new(BIO *bi)
184 {
185 BIO_OK_CTX *ctx;
186
187 ctx=(BIO_OK_CTX *)Malloc(sizeof(BIO_OK_CTX));
188 if (ctx == NULL) return(0);
189
190 ctx->buf_len=0;
191 ctx->buf_off=0;
192 ctx->buf_len_save=0;
193 ctx->buf_off_save=0;
194 ctx->cont=1;
195 ctx->finished=0;
196 ctx->blockout= 0;
197 ctx->sigio=1;
198
199 bi->init=0;
200 bi->ptr=(char *)ctx;
201 bi->flags=0;
202 return(1);
203 }
204
205static int ok_free(BIO *a)
206 {
207 if (a == NULL) return(0);
208 memset(a->ptr,0,sizeof(BIO_OK_CTX));
209 Free(a->ptr);
210 a->ptr=NULL;
211 a->init=0;
212 a->flags=0;
213 return(1);
214 }
215
216static int ok_read(BIO *b, char *out, int outl)
217 {
218 int ret=0,i,n;
219 BIO_OK_CTX *ctx;
220
221 if (out == NULL) return(0);
222 ctx=(BIO_OK_CTX *)b->ptr;
223
224 if ((ctx == NULL) || (b->next_bio == NULL) || (b->init == 0)) return(0);
225
226 while(outl > 0)
227 {
228
229 /* copy clean bytes to output buffer */
230 if (ctx->blockout)
231 {
232 i=ctx->buf_len-ctx->buf_off;
233 if (i > outl) i=outl;
234 memcpy(out,&(ctx->buf[ctx->buf_off]),i);
235 ret+=i;
236 out+=i;
237 outl-=i;
238 ctx->buf_off+=i;
239
240 /* all clean bytes are out */
241 if (ctx->buf_len == ctx->buf_off)
242 {
243 ctx->buf_off=0;
244
245 /* copy start of the next block into proper place */
246 if(ctx->buf_len_save- ctx->buf_off_save > 0)
247 {
248 ctx->buf_len= ctx->buf_len_save- ctx->buf_off_save;
249 memmove(ctx->buf, &(ctx->buf[ctx->buf_off_save]),
250 ctx->buf_len);
251 }
252 else
253 {
254 ctx->buf_len=0;
255 }
256 ctx->blockout= 0;
257 }
258 }
259
260 /* output buffer full -- cancel */
261 if (outl == 0) break;
262
263 /* no clean bytes in buffer -- fill it */
264 n=IOBS- ctx->buf_len;
265 i=BIO_read(b->next_bio,&(ctx->buf[ctx->buf_len]),n);
266
267 if (i <= 0) break; /* nothing new */
268
269 ctx->buf_len+= i;
270
271 /* no signature yet -- check if we got one */
272 if (ctx->sigio == 1) sig_in(b);
273
274 /* signature ok -- check if we got block */
275 if (ctx->sigio == 0) block_in(b);
276
277 /* invalid block -- cancel */
278 if (ctx->cont <= 0) break;
279
280 }
281
282 BIO_clear_retry_flags(b);
283 BIO_copy_next_retry(b);
284 return(ret);
285 }
286
287static int ok_write(BIO *b, char *in, int inl)
288 {
289 int ret=0,n,i;
290 BIO_OK_CTX *ctx;
291
292 ctx=(BIO_OK_CTX *)b->ptr;
293 ret=inl;
294
295 if ((ctx == NULL) || (b->next_bio == NULL) || (b->init == 0)) return(0);
296
297 if(ctx->sigio) sig_out(b);
298
299 do{
300 BIO_clear_retry_flags(b);
301 n=ctx->buf_len-ctx->buf_off;
302 while (ctx->blockout && n > 0)
303 {
304 i=BIO_write(b->next_bio,&(ctx->buf[ctx->buf_off]),n);
305 if (i <= 0)
306 {
307 BIO_copy_next_retry(b);
308 if(!BIO_should_retry(b))
309 ctx->cont= 0;
310 return(i);
311 }
312 ctx->buf_off+=i;
313 n-=i;
314 }
315
316 /* at this point all pending data has been written */
317 ctx->blockout= 0;
318 if (ctx->buf_len == ctx->buf_off)
319 {
320 ctx->buf_len=OK_BLOCK_BLOCK;
321 ctx->buf_off=0;
322 }
323
324 if ((in == NULL) || (inl <= 0)) return(0);
325
326 n= (inl+ ctx->buf_len > OK_BLOCK_SIZE+ OK_BLOCK_BLOCK) ?
327 OK_BLOCK_SIZE+ OK_BLOCK_BLOCK- ctx->buf_len : inl;
328
329 memcpy((unsigned char *)(&(ctx->buf[ctx->buf_len])),(unsigned char *)in,n);
330 ctx->buf_len+= n;
331 inl-=n;
332 in+=n;
333
334 if(ctx->buf_len >= OK_BLOCK_SIZE+ OK_BLOCK_BLOCK)
335 {
336 block_out(b);
337 }
338 }while(inl > 0);
339
340 BIO_clear_retry_flags(b);
341 BIO_copy_next_retry(b);
342 return(ret);
343 }
344
345static long ok_ctrl(BIO *b, int cmd, long num, char *ptr)
346 {
347 BIO_OK_CTX *ctx;
348 EVP_MD *md;
349 const EVP_MD **ppmd;
350 long ret=1;
351 int i;
352
353 ctx=(BIO_OK_CTX *)b->ptr;
354
355 switch (cmd)
356 {
357 case BIO_CTRL_RESET:
358 ctx->buf_len=0;
359 ctx->buf_off=0;
360 ctx->buf_len_save=0;
361 ctx->buf_off_save=0;
362 ctx->cont=1;
363 ctx->finished=0;
364 ctx->blockout= 0;
365 ctx->sigio=1;
366 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
367 break;
368 case BIO_CTRL_EOF: /* More to read */
369 if (ctx->cont <= 0)
370 ret=1;
371 else
372 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
373 break;
374 case BIO_CTRL_PENDING: /* More to read in buffer */
375 case BIO_CTRL_WPENDING: /* More to read in buffer */
376 ret=ctx->blockout ? ctx->buf_len-ctx->buf_off : 0;
377 if (ret <= 0)
378 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
379 break;
380 case BIO_CTRL_FLUSH:
381 /* do a final write */
382 if(ctx->blockout == 0)
383 block_out(b);
384
385 while (ctx->blockout)
386 {
387 i=ok_write(b,NULL,0);
388 if (i < 0)
389 {
390 ret=i;
391 break;
392 }
393 }
394
395 ctx->finished=1;
396 ctx->buf_off=ctx->buf_len=0;
397 ctx->cont=(int)ret;
398
399 /* Finally flush the underlying BIO */
400 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
401 break;
402 case BIO_C_DO_STATE_MACHINE:
403 BIO_clear_retry_flags(b);
404 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
405 BIO_copy_next_retry(b);
406 break;
407 case BIO_CTRL_INFO:
408 ret=(long)ctx->cont;
409 break;
410 case BIO_C_SET_MD:
411 md=(EVP_MD *)ptr;
412 EVP_DigestInit(&(ctx->md),md);
413 b->init=1;
414 break;
415 case BIO_C_GET_MD:
416 if (b->init)
417 {
418 ppmd=(const EVP_MD **)ptr;
419 *ppmd=ctx->md.digest;
420 }
421 else
422 ret=0;
423 break;
424 default:
425 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
426 break;
427 }
428 return(ret);
429 }
430
431static void longswap(void *_ptr, int len)
432{
433#ifndef L_ENDIAN
434 int i;
435 char *ptr=_ptr;
436
437 for(i= 0;i < len;i+= 4){
438 *((unsigned long *)&(ptr[i]))= swapem(*((unsigned long *)&(ptr[i])));
439 }
440#endif
441}
442
443static void sig_out(BIO* b)
444 {
445 BIO_OK_CTX *ctx;
446 EVP_MD_CTX *md;
447
448 ctx=(BIO_OK_CTX *)b->ptr;
449 md= &(ctx->md);
450
451 if(ctx->buf_len+ 2* md->digest->md_size > OK_BLOCK_SIZE) return;
452
453 EVP_DigestInit(md, md->digest);
454 RAND_bytes(&(md->md.base[0]), md->digest->md_size);
455 memcpy(&(ctx->buf[ctx->buf_len]), &(md->md.base[0]), md->digest->md_size);
456 longswap(&(ctx->buf[ctx->buf_len]), md->digest->md_size);
457 ctx->buf_len+= md->digest->md_size;
458
459 EVP_DigestUpdate(md, (unsigned char*)WELLKNOWN, strlen(WELLKNOWN));
460 md->digest->final(&(ctx->buf[ctx->buf_len]), &(md->md.base[0]));
461 ctx->buf_len+= md->digest->md_size;
462 ctx->blockout= 1;
463 ctx->sigio= 0;
464 }
465
466static void sig_in(BIO* b)
467 {
468 BIO_OK_CTX *ctx;
469 EVP_MD_CTX *md;
470 unsigned char tmp[EVP_MAX_MD_SIZE];
471 int ret= 0;
472
473 ctx=(BIO_OK_CTX *)b->ptr;
474 md= &(ctx->md);
475
476 if(ctx->buf_len- ctx->buf_off < 2* md->digest->md_size) return;
477
478 EVP_DigestInit(md, md->digest);
479 memcpy(&(md->md.base[0]), &(ctx->buf[ctx->buf_off]), md->digest->md_size);
480 longswap(&(md->md.base[0]), md->digest->md_size);
481 ctx->buf_off+= md->digest->md_size;
482
483 EVP_DigestUpdate(md, (unsigned char*)WELLKNOWN, strlen(WELLKNOWN));
484 md->digest->final(tmp, &(md->md.base[0]));
485 ret= memcmp(&(ctx->buf[ctx->buf_off]), tmp, md->digest->md_size) == 0;
486 ctx->buf_off+= md->digest->md_size;
487 if(ret == 1)
488 {
489 ctx->sigio= 0;
490 if(ctx->buf_len != ctx->buf_off)
491 {
492 memmove(ctx->buf, &(ctx->buf[ctx->buf_off]), ctx->buf_len- ctx->buf_off);
493 }
494 ctx->buf_len-= ctx->buf_off;
495 ctx->buf_off= 0;
496 }
497 else
498 {
499 ctx->cont= 0;
500 }
501 }
502
503static void block_out(BIO* b)
504 {
505 BIO_OK_CTX *ctx;
506 EVP_MD_CTX *md;
507 unsigned long tl;
508
509 ctx=(BIO_OK_CTX *)b->ptr;
510 md= &(ctx->md);
511
512 tl= ctx->buf_len- OK_BLOCK_BLOCK;
513 tl= swapem(tl);
514 memcpy(ctx->buf, &tl, OK_BLOCK_BLOCK);
515 tl= swapem(tl);
516 EVP_DigestUpdate(md, (unsigned char*) &(ctx->buf[OK_BLOCK_BLOCK]), tl);
517 md->digest->final(&(ctx->buf[ctx->buf_len]), &(md->md.base[0]));
518 ctx->buf_len+= md->digest->md_size;
519 ctx->blockout= 1;
520 }
521
522static void block_in(BIO* b)
523 {
524 BIO_OK_CTX *ctx;
525 EVP_MD_CTX *md;
526 long tl= 0;
527 unsigned char tmp[EVP_MAX_MD_SIZE];
528
529 ctx=(BIO_OK_CTX *)b->ptr;
530 md= &(ctx->md);
531
532 memcpy(&tl, ctx->buf, OK_BLOCK_BLOCK);
533 tl= swapem(tl);
534 if (ctx->buf_len < tl+ OK_BLOCK_BLOCK+ md->digest->md_size) return;
535
536 EVP_DigestUpdate(md, (unsigned char*) &(ctx->buf[OK_BLOCK_BLOCK]), tl);
537 md->digest->final(tmp, &(md->md.base[0]));
538 if(memcmp(&(ctx->buf[tl+ OK_BLOCK_BLOCK]), tmp, md->digest->md_size) == 0)
539 {
540 /* there might be parts from next block lurking around ! */
541 ctx->buf_off_save= tl+ OK_BLOCK_BLOCK+ md->digest->md_size;
542 ctx->buf_len_save= ctx->buf_len;
543 ctx->buf_off= OK_BLOCK_BLOCK;
544 ctx->buf_len= tl+ OK_BLOCK_BLOCK;
545 ctx->blockout= 1;
546 }
547 else
548 {
549 ctx->cont= 0;
550 }
551 }
552
diff --git a/src/lib/libcrypto/evp/c_allc.c b/src/lib/libcrypto/evp/c_allc.c
new file mode 100644
index 0000000000..f24d3756c9
--- /dev/null
+++ b/src/lib/libcrypto/evp/c_allc.c
@@ -0,0 +1,149 @@
1/* crypto/evp/c_allc.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/evp.h>
62#include <openssl/pkcs12.h>
63#include <openssl/objects.h>
64
65void OpenSSL_add_all_ciphers(void)
66 {
67#ifndef NO_DES
68 EVP_add_cipher(EVP_des_cfb());
69 EVP_add_cipher(EVP_des_ede_cfb());
70 EVP_add_cipher(EVP_des_ede3_cfb());
71
72 EVP_add_cipher(EVP_des_ofb());
73 EVP_add_cipher(EVP_des_ede_ofb());
74 EVP_add_cipher(EVP_des_ede3_ofb());
75
76 EVP_add_cipher(EVP_desx_cbc());
77 EVP_add_cipher_alias(SN_desx_cbc,"DESX");
78 EVP_add_cipher_alias(SN_desx_cbc,"desx");
79
80 EVP_add_cipher(EVP_des_cbc());
81 EVP_add_cipher_alias(SN_des_cbc,"DES");
82 EVP_add_cipher_alias(SN_des_cbc,"des");
83 EVP_add_cipher(EVP_des_ede_cbc());
84 EVP_add_cipher(EVP_des_ede3_cbc());
85 EVP_add_cipher_alias(SN_des_ede3_cbc,"DES3");
86 EVP_add_cipher_alias(SN_des_ede3_cbc,"des3");
87
88 EVP_add_cipher(EVP_des_ecb());
89 EVP_add_cipher(EVP_des_ede());
90 EVP_add_cipher(EVP_des_ede3());
91#endif
92
93#ifndef NO_RC4
94 EVP_add_cipher(EVP_rc4());
95 EVP_add_cipher(EVP_rc4_40());
96#endif
97
98#ifndef NO_IDEA
99 EVP_add_cipher(EVP_idea_ecb());
100 EVP_add_cipher(EVP_idea_cfb());
101 EVP_add_cipher(EVP_idea_ofb());
102 EVP_add_cipher(EVP_idea_cbc());
103 EVP_add_cipher_alias(SN_idea_cbc,"IDEA");
104 EVP_add_cipher_alias(SN_idea_cbc,"idea");
105#endif
106
107#ifndef NO_RC2
108 EVP_add_cipher(EVP_rc2_ecb());
109 EVP_add_cipher(EVP_rc2_cfb());
110 EVP_add_cipher(EVP_rc2_ofb());
111 EVP_add_cipher(EVP_rc2_cbc());
112 EVP_add_cipher(EVP_rc2_40_cbc());
113 EVP_add_cipher(EVP_rc2_64_cbc());
114 EVP_add_cipher_alias(SN_rc2_cbc,"RC2");
115 EVP_add_cipher_alias(SN_rc2_cbc,"rc2");
116#endif
117
118#ifndef NO_BF
119 EVP_add_cipher(EVP_bf_ecb());
120 EVP_add_cipher(EVP_bf_cfb());
121 EVP_add_cipher(EVP_bf_ofb());
122 EVP_add_cipher(EVP_bf_cbc());
123 EVP_add_cipher_alias(SN_bf_cbc,"BF");
124 EVP_add_cipher_alias(SN_bf_cbc,"bf");
125 EVP_add_cipher_alias(SN_bf_cbc,"blowfish");
126#endif
127
128#ifndef NO_CAST
129 EVP_add_cipher(EVP_cast5_ecb());
130 EVP_add_cipher(EVP_cast5_cfb());
131 EVP_add_cipher(EVP_cast5_ofb());
132 EVP_add_cipher(EVP_cast5_cbc());
133 EVP_add_cipher_alias(SN_cast5_cbc,"CAST");
134 EVP_add_cipher_alias(SN_cast5_cbc,"cast");
135 EVP_add_cipher_alias(SN_cast5_cbc,"CAST-cbc");
136 EVP_add_cipher_alias(SN_cast5_cbc,"cast-cbc");
137#endif
138
139#ifndef NO_RC5
140 EVP_add_cipher(EVP_rc5_32_12_16_ecb());
141 EVP_add_cipher(EVP_rc5_32_12_16_cfb());
142 EVP_add_cipher(EVP_rc5_32_12_16_ofb());
143 EVP_add_cipher(EVP_rc5_32_12_16_cbc());
144 EVP_add_cipher_alias(SN_rc5_cbc,"rc5");
145 EVP_add_cipher_alias(SN_rc5_cbc,"RC5");
146#endif
147 PKCS12_PBE_add();
148 PKCS5_PBE_add();
149 }
diff --git a/src/lib/libcrypto/evp/c_alld.c b/src/lib/libcrypto/evp/c_alld.c
new file mode 100644
index 0000000000..febe51a3ee
--- /dev/null
+++ b/src/lib/libcrypto/evp/c_alld.c
@@ -0,0 +1,100 @@
1/* crypto/evp/c_alld.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/evp.h>
62#include <openssl/pkcs12.h>
63#include <openssl/objects.h>
64
65void OpenSSL_add_all_digests(void)
66 {
67#ifndef NO_MD2
68 EVP_add_digest(EVP_md2());
69#endif
70#ifndef NO_MD5
71 EVP_add_digest(EVP_md5());
72 EVP_add_digest_alias(SN_md5,"ssl2-md5");
73 EVP_add_digest_alias(SN_md5,"ssl3-md5");
74#endif
75#ifndef NO_SHA
76 EVP_add_digest(EVP_sha());
77#ifndef NO_DSA
78 EVP_add_digest(EVP_dss());
79#endif
80#endif
81#ifndef NO_SHA
82 EVP_add_digest(EVP_sha1());
83 EVP_add_digest_alias(SN_sha1,"ssl3-sha1");
84 EVP_add_digest_alias(SN_sha1WithRSAEncryption,SN_sha1WithRSA);
85#ifndef NO_DSA
86 EVP_add_digest(EVP_dss1());
87 EVP_add_digest_alias(SN_dsaWithSHA1,SN_dsaWithSHA1_2);
88 EVP_add_digest_alias(SN_dsaWithSHA1,"DSS1");
89 EVP_add_digest_alias(SN_dsaWithSHA1,"dss1");
90#endif
91#endif
92#if !defined(NO_MDC2) && !defined(NO_DES)
93 EVP_add_digest(EVP_mdc2());
94#endif
95#ifndef NO_RIPEMD
96 EVP_add_digest(EVP_ripemd160());
97 EVP_add_digest_alias(SN_ripemd160,"ripemd");
98 EVP_add_digest_alias(SN_ripemd160,"rmd160");
99#endif
100 }
diff --git a/src/lib/libcrypto/evp/e_rc5.c b/src/lib/libcrypto/evp/e_rc5.c
new file mode 100644
index 0000000000..5885f1826b
--- /dev/null
+++ b/src/lib/libcrypto/evp/e_rc5.c
@@ -0,0 +1,118 @@
1/* crypto/evp/e_rc5.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef NO_RC5
60
61#include <stdio.h>
62#include "cryptlib.h"
63#include <openssl/evp.h>
64#include <openssl/objects.h>
65#include "evp_locl.h"
66
67static int r_32_12_16_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
68 const unsigned char *iv,int enc);
69static int rc5_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr);
70
71IMPLEMENT_BLOCK_CIPHER(rc5_32_12_16, rc5.ks, RC5_32, rc5, NID_rc5,
72 8, EVP_RC5_32_12_16_KEY_SIZE, 8,
73 EVP_CIPH_VARIABLE_LENGTH | EVP_CIPH_CTRL_INIT,
74 r_32_12_16_init_key, NULL,
75 NULL, NULL, rc5_ctrl)
76
77
78
79static int rc5_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr)
80 {
81 switch(type) {
82
83 case EVP_CTRL_INIT:
84 c->c.rc5.rounds = RC5_12_ROUNDS;
85 return 1;
86
87 case EVP_CTRL_GET_RC5_ROUNDS:
88 *(int *)ptr = c->c.rc5.rounds;
89 return 1;
90
91
92 case EVP_CTRL_SET_RC5_ROUNDS:
93 switch(arg) {
94 case RC5_8_ROUNDS:
95 case RC5_12_ROUNDS:
96 case RC5_16_ROUNDS:
97 c->c.rc5.rounds = arg;
98 return 1;
99
100 default:
101 EVPerr(EVP_F_RC5_CTRL, EVP_R_UNSUPORTED_NUMBER_OF_ROUNDS);
102 return 0;
103 }
104
105 default:
106 return -1;
107 }
108 }
109
110static int r_32_12_16_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
111 const unsigned char *iv, int enc)
112 {
113 RC5_32_set_key(&(ctx->c.rc5.ks),EVP_CIPHER_CTX_key_length(ctx),
114 key,ctx->c.rc5.rounds);
115 return 1;
116 }
117
118#endif
diff --git a/src/lib/libcrypto/evp/evp_acnf.c b/src/lib/libcrypto/evp/evp_acnf.c
new file mode 100644
index 0000000000..a68b979bdb
--- /dev/null
+++ b/src/lib/libcrypto/evp/evp_acnf.c
@@ -0,0 +1,74 @@
1/* evp_acnf.c */
2/* Written by Stephen Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2001.
4 */
5/* ====================================================================
6 * Copyright (c) 2001 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 * licensing@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 "cryptlib.h"
60#include <openssl/evp.h>
61#include <openssl/conf.h>
62#include <openssl/engine.h>
63
64
65/* Load all algorithms and configure OpenSSL.
66 * This function is called automatically when
67 * OPENSSL_LOAD_CONF is set.
68 */
69
70void OPENSSL_add_all_algorithms_conf(void)
71 {
72 OPENSSL_add_all_algorithms_noconf();
73 OPENSSL_config(NULL);
74 }
diff --git a/src/lib/libcrypto/evp/evp_test.c b/src/lib/libcrypto/evp/evp_test.c
new file mode 100644
index 0000000000..3607fe7776
--- /dev/null
+++ b/src/lib/libcrypto/evp/evp_test.c
@@ -0,0 +1,365 @@
1/* Written by Ben Laurie, 2001 */
2/*
3 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 */
49
50#include <stdio.h>
51#include <string.h>
52#include <openssl/evp.h>
53#include <openssl/engine.h>
54#include <openssl/conf.h>
55
56static void hexdump(FILE *f,const char *title,const unsigned char *s,int l)
57 {
58 int n=0;
59
60 fprintf(f,"%s",title);
61 for( ; n < l ; ++n)
62 {
63 if((n%16) == 0)
64 fprintf(f,"\n%04x",n);
65 fprintf(f," %02x",s[n]);
66 }
67 fprintf(f,"\n");
68 }
69
70static int convert(unsigned char *s)
71 {
72 unsigned char *d;
73
74 for(d=s ; *s ; s+=2,++d)
75 {
76 unsigned int n;
77
78 if(!s[1])
79 {
80 fprintf(stderr,"Odd number of hex digits!");
81 exit(4);
82 }
83 sscanf((char *)s,"%2x",&n);
84 *d=(unsigned char)n;
85 }
86 return s-d;
87 }
88
89static char *sstrsep(char **string, const char *delim)
90 {
91 char isdelim[256];
92 char *token = *string;
93
94 if (**string == 0)
95 return NULL;
96
97 memset(isdelim, 0, 256);
98 isdelim[0] = 1;
99
100 while (*delim)
101 {
102 isdelim[(unsigned char)(*delim)] = 1;
103 delim++;
104 }
105
106 while (!isdelim[(unsigned char)(**string)])
107 {
108 (*string)++;
109 }
110
111 if (**string)
112 {
113 **string = 0;
114 (*string)++;
115 }
116
117 return token;
118 }
119
120static unsigned char *ustrsep(char **p,const char *sep)
121 { return (unsigned char *)sstrsep((char **)p,sep); }
122
123static void test1(const EVP_CIPHER *c,const unsigned char *key,int kn,
124 const unsigned char *iv,int in,
125 const unsigned char *plaintext,int pn,
126 const unsigned char *ciphertext,int cn)
127 {
128 EVP_CIPHER_CTX ctx;
129 unsigned char out[4096];
130 int outl,outl2;
131
132 printf("Testing cipher %s\n",EVP_CIPHER_name(c));
133 hexdump(stdout,"Key",key,kn);
134 if(in)
135 hexdump(stdout,"IV",iv,in);
136 hexdump(stdout,"Plaintext",plaintext,pn);
137 hexdump(stdout,"Ciphertext",ciphertext,cn);
138
139 if(kn != c->key_len)
140 {
141 fprintf(stderr,"Key length doesn't match, got %d expected %d\n",kn,
142 c->key_len);
143 exit(5);
144 }
145 EVP_CIPHER_CTX_init(&ctx);
146 if(!EVP_EncryptInit_ex(&ctx,c,NULL,key,iv))
147 {
148 fprintf(stderr,"EncryptInit failed\n");
149 exit(10);
150 }
151 EVP_CIPHER_CTX_set_padding(&ctx,0);
152
153 if(!EVP_EncryptUpdate(&ctx,out,&outl,plaintext,pn))
154 {
155 fprintf(stderr,"Encrypt failed\n");
156 exit(6);
157 }
158 if(!EVP_EncryptFinal_ex(&ctx,out+outl,&outl2))
159 {
160 fprintf(stderr,"EncryptFinal failed\n");
161 exit(7);
162 }
163
164 if(outl+outl2 != cn)
165 {
166 fprintf(stderr,"Ciphertext length mismatch got %d expected %d\n",
167 outl+outl2,cn);
168 exit(8);
169 }
170
171 if(memcmp(out,ciphertext,cn))
172 {
173 fprintf(stderr,"Ciphertext mismatch\n");
174 hexdump(stderr,"Got",out,cn);
175 hexdump(stderr,"Expected",ciphertext,cn);
176 exit(9);
177 }
178
179 if(!EVP_DecryptInit_ex(&ctx,c,NULL,key,iv))
180 {
181 fprintf(stderr,"DecryptInit failed\n");
182 exit(11);
183 }
184 EVP_CIPHER_CTX_set_padding(&ctx,0);
185
186 if(!EVP_DecryptUpdate(&ctx,out,&outl,ciphertext,pn))
187 {
188 fprintf(stderr,"Decrypt failed\n");
189 exit(6);
190 }
191 if(!EVP_DecryptFinal_ex(&ctx,out+outl,&outl2))
192 {
193 fprintf(stderr,"DecryptFinal failed\n");
194 exit(7);
195 }
196
197 if(outl+outl2 != cn)
198 {
199 fprintf(stderr,"Plaintext length mismatch got %d expected %d\n",
200 outl+outl2,cn);
201 exit(8);
202 }
203
204 if(memcmp(out,plaintext,cn))
205 {
206 fprintf(stderr,"Plaintext mismatch\n");
207 hexdump(stderr,"Got",out,cn);
208 hexdump(stderr,"Expected",plaintext,cn);
209 exit(9);
210 }
211
212 printf("\n");
213 }
214
215static int test_cipher(const char *cipher,const unsigned char *key,int kn,
216 const unsigned char *iv,int in,
217 const unsigned char *plaintext,int pn,
218 const unsigned char *ciphertext,int cn)
219 {
220 const EVP_CIPHER *c;
221
222 c=EVP_get_cipherbyname(cipher);
223 if(!c)
224 return 0;
225
226 test1(c,key,kn,iv,in,plaintext,pn,ciphertext,cn);
227
228 return 1;
229 }
230
231static int test_digest(const char *digest,
232 const unsigned char *plaintext,int pn,
233 const unsigned char *ciphertext, unsigned int cn)
234 {
235 const EVP_MD *d;
236 EVP_MD_CTX ctx;
237 unsigned char md[EVP_MAX_MD_SIZE];
238 unsigned int mdn;
239
240 d=EVP_get_digestbyname(digest);
241 if(!d)
242 return 0;
243
244 printf("Testing digest %s\n",EVP_MD_name(d));
245 hexdump(stdout,"Plaintext",plaintext,pn);
246 hexdump(stdout,"Digest",ciphertext,cn);
247
248 EVP_MD_CTX_init(&ctx);
249 if(!EVP_DigestInit_ex(&ctx,d, NULL))
250 {
251 fprintf(stderr,"DigestInit failed\n");
252 exit(100);
253 }
254 if(!EVP_DigestUpdate(&ctx,plaintext,pn))
255 {
256 fprintf(stderr,"DigestUpdate failed\n");
257 exit(101);
258 }
259 if(!EVP_DigestFinal_ex(&ctx,md,&mdn))
260 {
261 fprintf(stderr,"DigestFinal failed\n");
262 exit(101);
263 }
264 EVP_MD_CTX_cleanup(&ctx);
265
266 if(mdn != cn)
267 {
268 fprintf(stderr,"Digest length mismatch, got %d expected %d\n",mdn,cn);
269 exit(102);
270 }
271
272 if(memcmp(md,ciphertext,cn))
273 {
274 fprintf(stderr,"Digest mismatch\n");
275 hexdump(stderr,"Got",md,cn);
276 hexdump(stderr,"Expected",ciphertext,cn);
277 exit(103);
278 }
279
280 printf("\n");
281
282 return 1;
283 }
284
285int main(int argc,char **argv)
286 {
287 const char *szTestFile;
288 FILE *f;
289
290 if(argc != 2)
291 {
292 fprintf(stderr,"%s <test file>\n",argv[0]);
293 exit(1);
294 }
295 CRYPTO_malloc_debug_init();
296 CRYPTO_set_mem_debug_options(V_CRYPTO_MDEBUG_ALL);
297 CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
298
299 szTestFile=argv[1];
300
301 f=fopen(szTestFile,"r");
302 if(!f)
303 {
304 perror(szTestFile);
305 exit(2);
306 }
307
308 /* Load up the software EVP_CIPHER and EVP_MD definitions */
309 OpenSSL_add_all_ciphers();
310 OpenSSL_add_all_digests();
311 /* Load all compiled-in ENGINEs */
312 ENGINE_load_builtin_engines();
313#if 0
314 OPENSSL_config();
315#endif
316 /* Register all available ENGINE implementations of ciphers and digests.
317 * This could perhaps be changed to "ENGINE_register_all_complete()"? */
318 ENGINE_register_all_ciphers();
319 ENGINE_register_all_digests();
320 /* If we add command-line options, this statement should be switchable.
321 * It'll prevent ENGINEs being ENGINE_init()ialised for cipher/digest use if
322 * they weren't already initialised. */
323 /* ENGINE_set_cipher_flags(ENGINE_CIPHER_FLAG_NOINIT); */
324
325 for( ; ; )
326 {
327 char line[4096];
328 char *p;
329 char *cipher;
330 unsigned char *iv,*key,*plaintext,*ciphertext;
331 int kn,in,pn,cn;
332
333 if(!fgets((char *)line,sizeof line,f))
334 break;
335 if(line[0] == '#' || line[0] == '\n')
336 continue;
337 p=line;
338 cipher=sstrsep(&p,":");
339 key=ustrsep(&p,":");
340 iv=ustrsep(&p,":");
341 plaintext=ustrsep(&p,":");
342 ciphertext=ustrsep(&p,"\n");
343
344 kn=convert(key);
345 in=convert(iv);
346 pn=convert(plaintext);
347 cn=convert(ciphertext);
348
349 if(!test_cipher(cipher,key,kn,iv,in,plaintext,pn,ciphertext,cn)
350 && !test_digest(cipher,plaintext,pn,ciphertext,cn))
351 {
352 fprintf(stderr,"Can't find %s\n",cipher);
353 exit(3);
354 }
355 }
356
357 ENGINE_cleanup();
358 EVP_cleanup();
359 CRYPTO_cleanup_all_ex_data();
360 ERR_remove_state(0);
361 ERR_free_strings();
362 CRYPTO_mem_leaks_fp(stderr);
363
364 return 0;
365 }
diff --git a/src/lib/libcrypto/evp/evptests.txt b/src/lib/libcrypto/evp/evptests.txt
new file mode 100644
index 0000000000..6c1529db37
--- /dev/null
+++ b/src/lib/libcrypto/evp/evptests.txt
@@ -0,0 +1,82 @@
1#cipher:key:iv:input:output
2#digest:::input:output
3
4# SHA(1) tests (from shatest.c)
5SHA1:::616263:a9993e364706816aba3e25717850c26c9cd0d89d
6
7# MD5 tests (from md5test.c)
8MD5::::d41d8cd98f00b204e9800998ecf8427e
9MD5:::61:0cc175b9c0f1b6a831c399e269772661
10MD5:::616263:900150983cd24fb0d6963f7d28e17f72
11MD5:::6d65737361676520646967657374:f96b697d7cb7938d525a2f31aaf161d0
12MD5:::6162636465666768696a6b6c6d6e6f707172737475767778797a:c3fcd3d76192e4007dfb496cca67e13b
13MD5:::4142434445464748494a4b4c4d4e4f505152535455565758595a6162636465666768696a6b6c6d6e6f707172737475767778797a30313233343536373839:d174ab98d277d9f5a5611c2c9f419d9f
14MD5:::3132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930:57edf4a22be3c955ac49da2e2107b67a
15
16# AES 128 ECB tests (from FIPS-197 test vectors, encrypt)
17
18AES-128-ECB:000102030405060708090A0B0C0D0E0F::00112233445566778899AABBCCDDEEFF:69C4E0D86A7B0430D8CDB78070B4C55A
19
20# AES 192 ECB tests (from FIPS-197 test vectors, encrypt)
21
22AES-192-ECB:000102030405060708090A0B0C0D0E0F1011121314151617::00112233445566778899AABBCCDDEEFF:DDA97CA4864CDFE06EAF70A0EC0D7191
23
24# AES 256 ECB tests (from FIPS-197 test vectors, encrypt)
25
26AES-256-ECB:000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F::00112233445566778899AABBCCDDEEFF:8EA2B7CA516745BFEAFC49904B496089
27
28# AES 128 ECB tests (from NIST test vectors, encrypt)
29
30#AES-128-ECB:00000000000000000000000000000000::00000000000000000000000000000000:C34C052CC0DA8D73451AFE5F03BE297F
31
32# AES 128 ECB tests (from NIST test vectors, decrypt)
33
34#AES-128-ECB:00000000000000000000000000000000::44416AC2D1F53C583303917E6BE9EBE0:00000000000000000000000000000000
35
36# AES 192 ECB tests (from NIST test vectors, decrypt)
37
38#AES-192-ECB:000000000000000000000000000000000000000000000000::48E31E9E256718F29229319C19F15BA4:00000000000000000000000000000000
39
40# AES 256 ECB tests (from NIST test vectors, decrypt)
41
42#AES-256-ECB:0000000000000000000000000000000000000000000000000000000000000000::058CCFFDBBCB382D1F6F56585D8A4ADE:00000000000000000000000000000000
43
44# AES 128 CBC tests (from NIST test vectors, encrypt)
45
46#AES-128-CBC:00000000000000000000000000000000:00000000000000000000000000000000:00000000000000000000000000000000:8A05FC5E095AF4848A08D328D3688E3D
47
48# AES 192 CBC tests (from NIST test vectors, encrypt)
49
50#AES-192-CBC:000000000000000000000000000000000000000000000000:00000000000000000000000000000000:00000000000000000000000000000000:7BD966D53AD8C1BB85D2ADFAE87BB104
51
52# AES 256 CBC tests (from NIST test vectors, encrypt)
53
54#AES-256-CBC:0000000000000000000000000000000000000000000000000000000000000000:00000000000000000000000000000000:00000000000000000000000000000000:FE3C53653E2F45B56FCD88B2CC898FF0
55
56# AES 128 CBC tests (from NIST test vectors, decrypt)
57
58#AES-128-CBC:00000000000000000000000000000000:00000000000000000000000000000000:FACA37E0B0C85373DF706E73F7C9AF86:00000000000000000000000000000000
59
60# DES ECB tests (from destest)
61
62DES-ECB:0000000000000000::0000000000000000:8CA64DE9C1B123A7
63DES-ECB:FFFFFFFFFFFFFFFF::FFFFFFFFFFFFFFFF:7359B2163E4EDC58
64DES-ECB:3000000000000000::1000000000000001:958E6E627A05557B
65DES-ECB:1111111111111111::1111111111111111:F40379AB9E0EC533
66DES-ECB:0123456789ABCDEF::1111111111111111:17668DFC7292532D
67DES-ECB:1111111111111111::0123456789ABCDEF:8A5AE1F81AB8F2DD
68DES-ECB:FEDCBA9876543210::0123456789ABCDEF:ED39D950FA74BCC4
69
70# DESX-CBC tests (from destest)
71DESX-CBC:0123456789abcdeff1e0d3c2b5a49786fedcba9876543210:fedcba9876543210:37363534333231204E6F77206973207468652074696D6520666F722000000000:846B2914851E9A2954732F8AA0A611C115CDC2D7951B1053A63C5E03B21AA3C4
72
73# DES EDE3 CBC tests (from destest)
74DES-EDE3-CBC:0123456789abcdeff1e0d3c2b5a49786fedcba9876543210:fedcba9876543210:37363534333231204E6F77206973207468652074696D6520666F722000000000:3FE301C962AC01D02213763C1CBD4CDC799657C064ECF5D41C673812CFDE9675
75
76# RC4 tests (from rc4test)
77RC4:0123456789abcdef0123456789abcdef::0123456789abcdef:75b7878099e0c596
78RC4:0123456789abcdef0123456789abcdef::0000000000000000:7494c2e7104b0879
79RC4:00000000000000000000000000000000::0000000000000000:de188941a3375d3a
80RC4:ef012345ef012345ef012345ef012345::0000000000000000000000000000000000000000:d6a141a7ec3c38dfbd615a1162e1c7ba36b67858
81RC4:0123456789abcdef0123456789abcdef::123456789ABCDEF0123456789ABCDEF0123456789ABCDEF012345678:66a0949f8af7d6891f7f832ba833c00c892ebe30143ce28740011ecf
82RC4:ef012345ef012345ef012345ef012345::00000000000000000000:d6a141a7ec3c38dfbd61
diff --git a/src/lib/libcrypto/evp/openbsd_hw.c b/src/lib/libcrypto/evp/openbsd_hw.c
new file mode 100644
index 0000000000..3831a5731e
--- /dev/null
+++ b/src/lib/libcrypto/evp/openbsd_hw.c
@@ -0,0 +1,446 @@
1/* Written by Ben Laurie, 2001 */
2/*
3 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 */
49
50#include <openssl/evp.h>
51#include <openssl/objects.h>
52#include <openssl/rsa.h>
53#include "evp_locl.h"
54
55/* This stuff should now all be supported through
56 * crypto/engine/hw_openbsd_dev_crypto.c unless I botched it up */
57static void *dummy=&dummy;
58
59#if 0
60
61/* check flag after OpenSSL headers to ensure make depend works */
62#ifdef OPENSSL_OPENBSD_DEV_CRYPTO
63
64#include <fcntl.h>
65#include <stdio.h>
66#include <errno.h>
67#include <sys/ioctl.h>
68#include <crypto/cryptodev.h>
69#include <unistd.h>
70#include <assert.h>
71
72/* longest key supported in hardware */
73#define MAX_HW_KEY 24
74#define MAX_HW_IV 8
75
76#define MD5_DIGEST_LENGTH 16
77#define MD5_CBLOCK 64
78
79static int fd;
80static int dev_failed;
81
82typedef struct session_op session_op;
83
84#define CDATA(ctx) EVP_C_DATA(session_op,ctx)
85
86static void err(const char *str)
87 {
88 fprintf(stderr,"%s: errno %d\n",str,errno);
89 }
90
91static int dev_crypto_init(session_op *ses)
92 {
93 if(dev_failed)
94 return 0;
95 if(!fd)
96 {
97 int cryptodev_fd;
98
99 if ((cryptodev_fd=open("/dev/crypto",O_RDWR,0)) < 0)
100 {
101 err("/dev/crypto");
102 dev_failed=1;
103 return 0;
104 }
105 if (ioctl(cryptodev_fd,CRIOGET,&fd) == -1)
106 {
107 err("CRIOGET failed");
108 close(cryptodev_fd);
109 dev_failed=1;
110 return 0;
111 }
112 close(cryptodev_fd);
113 }
114 assert(ses);
115 memset(ses,'\0',sizeof *ses);
116
117 return 1;
118 }
119
120static int dev_crypto_cleanup(EVP_CIPHER_CTX *ctx)
121 {
122 if(ioctl(fd,CIOCFSESSION,&CDATA(ctx)->ses) == -1)
123 err("CIOCFSESSION failed");
124
125 OPENSSL_free(CDATA(ctx)->key);
126
127 return 1;
128 }
129
130static int dev_crypto_init_key(EVP_CIPHER_CTX *ctx,int cipher,
131 const unsigned char *key,int klen)
132 {
133 if(!dev_crypto_init(CDATA(ctx)))
134 return 0;
135
136 CDATA(ctx)->key=OPENSSL_malloc(MAX_HW_KEY);
137
138 assert(ctx->cipher->iv_len <= MAX_HW_IV);
139
140 memcpy(CDATA(ctx)->key,key,klen);
141
142 CDATA(ctx)->cipher=cipher;
143 CDATA(ctx)->keylen=klen;
144
145 if (ioctl(fd,CIOCGSESSION,CDATA(ctx)) == -1)
146 {
147 err("CIOCGSESSION failed");
148 return 0;
149 }
150 return 1;
151 }
152
153static int dev_crypto_cipher(EVP_CIPHER_CTX *ctx,unsigned char *out,
154 const unsigned char *in,unsigned int inl)
155 {
156 struct crypt_op cryp;
157 unsigned char lb[MAX_HW_IV];
158
159 if(!inl)
160 return 1;
161
162 assert(CDATA(ctx));
163 assert(!dev_failed);
164
165 memset(&cryp,'\0',sizeof cryp);
166 cryp.ses=CDATA(ctx)->ses;
167 cryp.op=ctx->encrypt ? COP_ENCRYPT : COP_DECRYPT;
168 cryp.flags=0;
169 cryp.len=inl;
170 assert((inl&(ctx->cipher->block_size-1)) == 0);
171 cryp.src=(caddr_t)in;
172 cryp.dst=(caddr_t)out;
173 cryp.mac=0;
174 if(ctx->cipher->iv_len)
175 cryp.iv=(caddr_t)ctx->iv;
176
177 if(!ctx->encrypt)
178 memcpy(lb,&in[cryp.len-ctx->cipher->iv_len],ctx->cipher->iv_len);
179
180 if(ioctl(fd, CIOCCRYPT, &cryp) == -1)
181 {
182 if(errno == EINVAL) /* buffers are misaligned */
183 {
184 unsigned int cinl=0;
185 char *cin=NULL;
186 char *cout=NULL;
187
188 /* NB: this can only make cinl != inl with stream ciphers */
189 cinl=(inl+3)/4*4;
190
191 if(((unsigned long)in&3) || cinl != inl)
192 {
193 cin=OPENSSL_malloc(cinl);
194 memcpy(cin,in,inl);
195 cryp.src=cin;
196 }
197
198 if(((unsigned long)out&3) || cinl != inl)
199 {
200 cout=OPENSSL_malloc(cinl);
201 cryp.dst=cout;
202 }
203
204 cryp.len=cinl;
205
206 if(ioctl(fd, CIOCCRYPT, &cryp) == -1)
207 {
208 err("CIOCCRYPT(2) failed");
209 printf("src=%p dst=%p\n",cryp.src,cryp.dst);
210 abort();
211 return 0;
212 }
213
214 if(cout)
215 {
216 memcpy(out,cout,inl);
217 OPENSSL_free(cout);
218 }
219 if(cin)
220 OPENSSL_free(cin);
221 }
222 else
223 {
224 err("CIOCCRYPT failed");
225 abort();
226 return 0;
227 }
228 }
229
230 if(ctx->encrypt)
231 memcpy(ctx->iv,&out[cryp.len-ctx->cipher->iv_len],ctx->cipher->iv_len);
232 else
233 memcpy(ctx->iv,lb,ctx->cipher->iv_len);
234
235 return 1;
236 }
237
238static int dev_crypto_des_ede3_init_key(EVP_CIPHER_CTX *ctx,
239 const unsigned char *key,
240 const unsigned char *iv, int enc)
241 { return dev_crypto_init_key(ctx,CRYPTO_3DES_CBC,key,24); }
242
243#define dev_crypto_des_ede3_cbc_cipher dev_crypto_cipher
244
245BLOCK_CIPHER_def_cbc(dev_crypto_des_ede3, session_op, NID_des_ede3, 8, 24, 8,
246 0, dev_crypto_des_ede3_init_key,
247 dev_crypto_cleanup,
248 EVP_CIPHER_set_asn1_iv,
249 EVP_CIPHER_get_asn1_iv,
250 NULL)
251
252static int dev_crypto_rc4_init_key(EVP_CIPHER_CTX *ctx,
253 const unsigned char *key,
254 const unsigned char *iv, int enc)
255 { return dev_crypto_init_key(ctx,CRYPTO_ARC4,key,16); }
256
257static const EVP_CIPHER r4_cipher=
258 {
259 NID_rc4,
260 1,16,0, /* FIXME: key should be up to 256 bytes */
261 EVP_CIPH_VARIABLE_LENGTH,
262 dev_crypto_rc4_init_key,
263 dev_crypto_cipher,
264 dev_crypto_cleanup,
265 sizeof(session_op),
266 NULL,
267 NULL,
268 NULL
269 };
270
271const EVP_CIPHER *EVP_dev_crypto_rc4(void)
272 { return &r4_cipher; }
273
274typedef struct
275 {
276 session_op sess;
277 char *data;
278 int len;
279 unsigned char md[EVP_MAX_MD_SIZE];
280 } MD_DATA;
281
282static int dev_crypto_init_digest(MD_DATA *md_data,int mac)
283 {
284 if(!dev_crypto_init(&md_data->sess))
285 return 0;
286
287 md_data->len=0;
288 md_data->data=NULL;
289
290 md_data->sess.mac=mac;
291
292 if (ioctl(fd,CIOCGSESSION,&md_data->sess) == -1)
293 {
294 err("CIOCGSESSION failed");
295 return 0;
296 }
297 return 1;
298 }
299
300static int dev_crypto_cleanup_digest(MD_DATA *md_data)
301 {
302 if (ioctl(fd,CIOCFSESSION,&md_data->sess.ses) == -1)
303 {
304 err("CIOCFSESSION failed");
305 return 0;
306 }
307
308 return 1;
309 }
310
311/* FIXME: if device can do chained MACs, then don't accumulate */
312/* FIXME: move accumulation to the framework */
313static int dev_crypto_md5_init(EVP_MD_CTX *ctx)
314 { return dev_crypto_init_digest(ctx->md_data,CRYPTO_MD5); }
315
316static int do_digest(int ses,unsigned char *md,const void *data,int len)
317 {
318 struct crypt_op cryp;
319 static unsigned char md5zero[16]=
320 {
321 0xd4,0x1d,0x8c,0xd9,0x8f,0x00,0xb2,0x04,
322 0xe9,0x80,0x09,0x98,0xec,0xf8,0x42,0x7e
323 };
324
325 /* some cards can't do zero length */
326 if(!len)
327 {
328 memcpy(md,md5zero,16);
329 return 1;
330 }
331
332 memset(&cryp,'\0',sizeof cryp);
333 cryp.ses=ses;
334 cryp.op=COP_ENCRYPT;/* required to do the MAC rather than check it */
335 cryp.len=len;
336 cryp.src=(caddr_t)data;
337 cryp.dst=(caddr_t)data; // FIXME!!!
338 cryp.mac=(caddr_t)md;
339
340 if(ioctl(fd, CIOCCRYPT, &cryp) == -1)
341 {
342 if(errno == EINVAL) /* buffer is misaligned */
343 {
344 char *dcopy;
345
346 dcopy=OPENSSL_malloc(len);
347 memcpy(dcopy,data,len);
348 cryp.src=dcopy;
349 cryp.dst=cryp.src; // FIXME!!!
350
351 if(ioctl(fd, CIOCCRYPT, &cryp) == -1)
352 {
353 err("CIOCCRYPT(MAC2) failed");
354 abort();
355 return 0;
356 }
357 OPENSSL_free(dcopy);
358 }
359 else
360 {
361 err("CIOCCRYPT(MAC) failed");
362 abort();
363 return 0;
364 }
365 }
366 // printf("done\n");
367
368 return 1;
369 }
370
371static int dev_crypto_md5_update(EVP_MD_CTX *ctx,const void *data,
372 unsigned long len)
373 {
374 MD_DATA *md_data=ctx->md_data;
375
376 if(ctx->flags&EVP_MD_CTX_FLAG_ONESHOT)
377 return do_digest(md_data->sess.ses,md_data->md,data,len);
378
379 md_data->data=OPENSSL_realloc(md_data->data,md_data->len+len);
380 memcpy(md_data->data+md_data->len,data,len);
381 md_data->len+=len;
382
383 return 1;
384 }
385
386static int dev_crypto_md5_final(EVP_MD_CTX *ctx,unsigned char *md)
387 {
388 int ret;
389 MD_DATA *md_data=ctx->md_data;
390
391 if(ctx->flags&EVP_MD_CTX_FLAG_ONESHOT)
392 {
393 memcpy(md,md_data->md,MD5_DIGEST_LENGTH);
394 ret=1;
395 }
396 else
397 {
398 ret=do_digest(md_data->sess.ses,md,md_data->data,md_data->len);
399 OPENSSL_free(md_data->data);
400 md_data->data=NULL;
401 md_data->len=0;
402 }
403
404 return ret;
405 }
406
407static int dev_crypto_md5_copy(EVP_MD_CTX *to,const EVP_MD_CTX *from)
408 {
409 const MD_DATA *from_md=from->md_data;
410 MD_DATA *to_md=to->md_data;
411
412 // How do we copy sessions?
413 assert(from->digest->flags&EVP_MD_FLAG_ONESHOT);
414
415 to_md->data=OPENSSL_malloc(from_md->len);
416 memcpy(to_md->data,from_md->data,from_md->len);
417
418 return 1;
419 }
420
421static int dev_crypto_md5_cleanup(EVP_MD_CTX *ctx)
422 {
423 return dev_crypto_cleanup_digest(ctx->md_data);
424 }
425
426static const EVP_MD md5_md=
427 {
428 NID_md5,
429 NID_md5WithRSAEncryption,
430 MD5_DIGEST_LENGTH,
431 EVP_MD_FLAG_ONESHOT, // XXX: set according to device info...
432 dev_crypto_md5_init,
433 dev_crypto_md5_update,
434 dev_crypto_md5_final,
435 dev_crypto_md5_copy,
436 dev_crypto_md5_cleanup,
437 EVP_PKEY_RSA_method,
438 MD5_CBLOCK,
439 sizeof(MD_DATA),
440 };
441
442const EVP_MD *EVP_dev_crypto_md5(void)
443 { return &md5_md; }
444
445#endif
446#endif
diff --git a/src/lib/libcrypto/install.com b/src/lib/libcrypto/install.com
new file mode 100644
index 0000000000..b75d1b44b2
--- /dev/null
+++ b/src/lib/libcrypto/install.com
@@ -0,0 +1,128 @@
1$! INSTALL.COM -- Installs the files in a given directory tree
2$!
3$! Author: Richard Levitte <richard@levitte.org>
4$! Time of creation: 22-MAY-1998 10:13
5$!
6$! P1 root of the directory tree
7$!
8$ IF P1 .EQS. ""
9$ THEN
10$ WRITE SYS$OUTPUT "First argument missing."
11$ WRITE SYS$OUTPUT "Should be the directory where you want things installed."
12$ EXIT
13$ ENDIF
14$
15$ ROOT = F$PARSE(P1,"[]A.;0",,,"SYNTAX_ONLY,NO_CONCEAL") - "A.;0"
16$ ROOT_DEV = F$PARSE(ROOT,,,"DEVICE","SYNTAX_ONLY")
17$ ROOT_DIR = F$PARSE(ROOT,,,"DIRECTORY","SYNTAX_ONLY") -
18 - "[000000." - "][" - "[" - "]"
19$ ROOT = ROOT_DEV + "[" + ROOT_DIR
20$
21$ DEFINE/NOLOG WRK_SSLROOT 'ROOT'.] /TRANS=CONC
22$ DEFINE/NOLOG WRK_SSLVLIB WRK_SSLROOT:[VAX_LIB]
23$ DEFINE/NOLOG WRK_SSLALIB WRK_SSLROOT:[ALPHA_LIB]
24$ DEFINE/NOLOG WRK_SSLINCLUDE WRK_SSLROOT:[INCLUDE]
25$
26$ IF F$PARSE("WRK_SSLROOT:[000000]") .EQS. "" THEN -
27 CREATE/DIR/LOG WRK_SSLROOT:[000000]
28$ IF F$PARSE("WRK_SSLVLIB:") .EQS. "" THEN -
29 CREATE/DIR/LOG WRK_SSLVLIB:
30$ IF F$PARSE("WRK_SSLALIB:") .EQS. "" THEN -
31 CREATE/DIR/LOG WRK_SSLALIB:
32$ IF F$PARSE("WRK_SSLINCLUDE:") .EQS. "" THEN -
33 CREATE/DIR/LOG WRK_SSLINCLUDE:
34$
35$ SDIRS := ,MD2,MD5,SHA,MDC2,HMAC,RIPEMD,-
36 DES,RC2,RC4,RC5,IDEA,BF,CAST,-
37 BN,RSA,DSA,DH,-
38 BUFFER,BIO,STACK,LHASH,RAND,ERR,OBJECTS,-
39 EVP,ASN1,PEM,X509,X509V3,-
40 CONF,TXT_DB,PKCS7,PKCS12,COMP
41$ EXHEADER_ := crypto.h,tmdiff.h,opensslv.h,opensslconf.h,ebcdic.h
42$ EXHEADER_MD2 := md2.h
43$ EXHEADER_MD5 := md5.h
44$ EXHEADER_SHA := sha.h
45$ EXHEADER_MDC2 := mdc2.h
46$ EXHEADER_HMAC := hmac.h
47$ EXHEADER_RIPEMD := ripemd.h
48$ EXHEADER_DES := des.h
49$ EXHEADER_RC2 := rc2.h
50$ EXHEADER_RC4 := rc4.h
51$ EXHEADER_RC5 := rc5.h
52$ EXHEADER_IDEA := idea.h
53$ EXHEADER_BF := blowfish.h
54$ EXHEADER_CAST := cast.h
55$ EXHEADER_BN := bn.h
56$ EXHEADER_RSA := rsa.h
57$ EXHEADER_DSA := dsa.h
58$ EXHEADER_DH := dh.h
59$ EXHEADER_BUFFER := buffer.h
60$ EXHEADER_BIO := bio.h
61$ EXHEADER_STACK := stack.h,safestack.h
62$ EXHEADER_LHASH := lhash.h
63$ EXHEADER_RAND := rand.h
64$ EXHEADER_ERR := err.h
65$ EXHEADER_OBJECTS := objects.h
66$ EXHEADER_EVP := evp.h
67$ EXHEADER_ASN1 := asn1.h,asn1_mac.h
68$ EXHEADER_PEM := pem.h,pem2.h
69$ EXHEADER_X509 := x509.h,x509_vfy.h
70$ EXHEADER_X509V3 := x509v3.h
71$ EXHEADER_CONF := conf.h
72$ EXHEADER_TXT_DB := txt_db.h
73$ EXHEADER_PKCS7 := pkcs7.h
74$ EXHEADER_PKCS12 := pkcs12.h
75$ EXHEADER_COMP := comp.h
76$ LIBS := LIBCRYPTO
77$
78$ VEXE_DIR := [-.VAX.EXE.CRYPTO]
79$ AEXE_DIR := [-.AXP.EXE.CRYPTO]
80$
81$ I = 0
82$ LOOP_SDIRS:
83$ D = F$EDIT(F$ELEMENT(I, ",", SDIRS),"TRIM")
84$ I = I + 1
85$ IF D .EQS. "," THEN GOTO LOOP_SDIRS_END
86$ tmp = EXHEADER_'D'
87$ IF D .EQS. ""
88$ THEN
89$ COPY 'tmp' WRK_SSLINCLUDE: /LOG
90$ ELSE
91$ COPY [.'D']'tmp' WRK_SSLINCLUDE: /LOG
92$ ENDIF
93$ GOTO LOOP_SDIRS
94$ LOOP_SDIRS_END:
95$
96$ I = 0
97$ LOOP_LIB:
98$ E = F$EDIT(F$ELEMENT(I, ",", LIBS),"TRIM")
99$ I = I + 1
100$ IF E .EQS. "," THEN GOTO LOOP_LIB_END
101$ SET NOON
102$ IF F$SEARCH(VEXE_DIR+E+".OLB") .NES. ""
103$ THEN
104$ COPY 'VEXE_DIR''E'.OLB WRK_SSLVLIB:'E'.OLB/log
105$ SET FILE/PROT=W:RE WRK_SSLVLIB:'E'.OLB
106$ ENDIF
107$ ! Preparing for the time when we have shareable images
108$ IF F$SEARCH(VEXE_DIR+E+".EXE") .NES. ""
109$ THEN
110$ COPY 'VEXE_DIR''E'.EXE WRK_SSLVLIB:'E'.EXE/log
111$ SET FILE/PROT=W:RE WRK_SSLVLIB:'E'.EXE
112$ ENDIF
113$ IF F$SEARCH(AEXE_DIR+E+".OLB") .NES. ""
114$ THEN
115$ COPY 'AEXE_DIR''E'.OLB WRK_SSLALIB:'E'.OLB/log
116$ SET FILE/PROT=W:RE WRK_SSLALIB:'E'.OLB
117$ ENDIF
118$ ! Preparing for the time when we have shareable images
119$ IF F$SEARCH(AEXE_DIR+E+".EXE") .NES. ""
120$ THEN
121$ COPY 'AEXE_DIR''E'.EXE WRK_SSLALIB:'E'.EXE/log
122$ SET FILE/PROT=W:RE WRK_SSLALIB:'E'.EXE
123$ ENDIF
124$ SET ON
125$ GOTO LOOP_LIB
126$ LOOP_LIB_END:
127$
128$ EXIT
diff --git a/src/lib/libcrypto/md2/md2.h b/src/lib/libcrypto/md2/md2.h
new file mode 100644
index 0000000000..0d3592506c
--- /dev/null
+++ b/src/lib/libcrypto/md2/md2.h
@@ -0,0 +1,91 @@
1/* crypto/md/md2.h */
2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef HEADER_MD2_H
60#define HEADER_MD2_H
61
62#ifdef __cplusplus
63extern "C" {
64#endif
65
66#ifdef NO_MD2
67#error MD2 is disabled.
68#endif
69
70#define MD2_DIGEST_LENGTH 16
71#define MD2_BLOCK 16
72#include <openssl/opensslconf.h> /* MD2_INT */
73
74typedef struct MD2state_st
75 {
76 int num;
77 unsigned char data[MD2_BLOCK];
78 MD2_INT cksm[MD2_BLOCK];
79 MD2_INT state[MD2_BLOCK];
80 } MD2_CTX;
81
82const char *MD2_options(void);
83void MD2_Init(MD2_CTX *c);
84void MD2_Update(MD2_CTX *c, register unsigned char *data, unsigned long len);
85void MD2_Final(unsigned char *md, MD2_CTX *c);
86unsigned char *MD2(unsigned char *d, unsigned long n,unsigned char *md);
87#ifdef __cplusplus
88}
89#endif
90
91#endif
diff --git a/src/lib/libcrypto/md4/md4.c b/src/lib/libcrypto/md4/md4.c
new file mode 100644
index 0000000000..e4b0aac011
--- /dev/null
+++ b/src/lib/libcrypto/md4/md4.c
@@ -0,0 +1,127 @@
1/* crypto/md4/md4.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <stdlib.h>
61#include <openssl/md4.h>
62
63#define BUFSIZE 1024*16
64
65void do_fp(FILE *f);
66void pt(unsigned char *md);
67#ifndef _OSD_POSIX
68int read(int, void *, unsigned int);
69#endif
70
71int main(int argc, char **argv)
72 {
73 int i,err=0;
74 FILE *IN;
75
76 if (argc == 1)
77 {
78 do_fp(stdin);
79 }
80 else
81 {
82 for (i=1; i<argc; i++)
83 {
84 IN=fopen(argv[i],"r");
85 if (IN == NULL)
86 {
87 perror(argv[i]);
88 err++;
89 continue;
90 }
91 printf("MD4(%s)= ",argv[i]);
92 do_fp(IN);
93 fclose(IN);
94 }
95 }
96 exit(err);
97 }
98
99void do_fp(FILE *f)
100 {
101 MD4_CTX c;
102 unsigned char md[MD4_DIGEST_LENGTH];
103 int fd;
104 int i;
105 static unsigned char buf[BUFSIZE];
106
107 fd=fileno(f);
108 MD4_Init(&c);
109 for (;;)
110 {
111 i=read(fd,buf,BUFSIZE);
112 if (i <= 0) break;
113 MD4_Update(&c,buf,(unsigned long)i);
114 }
115 MD4_Final(&(md[0]),&c);
116 pt(md);
117 }
118
119void pt(unsigned char *md)
120 {
121 int i;
122
123 for (i=0; i<MD4_DIGEST_LENGTH; i++)
124 printf("%02x",md[i]);
125 printf("\n");
126 }
127
diff --git a/src/lib/libcrypto/md4/md4s.cpp b/src/lib/libcrypto/md4/md4s.cpp
new file mode 100644
index 0000000000..c0ec97fc9f
--- /dev/null
+++ b/src/lib/libcrypto/md4/md4s.cpp
@@ -0,0 +1,78 @@
1//
2// gettsc.inl
3//
4// gives access to the Pentium's (secret) cycle counter
5//
6// This software was written by Leonard Janke (janke@unixg.ubc.ca)
7// in 1996-7 and is entered, by him, into the public domain.
8
9#if defined(__WATCOMC__)
10void GetTSC(unsigned long&);
11#pragma aux GetTSC = 0x0f 0x31 "mov [edi], eax" parm [edi] modify [edx eax];
12#elif defined(__GNUC__)
13inline
14void GetTSC(unsigned long& tsc)
15{
16 asm volatile(".byte 15, 49\n\t"
17 : "=eax" (tsc)
18 :
19 : "%edx", "%eax");
20}
21#elif defined(_MSC_VER)
22inline
23void GetTSC(unsigned long& tsc)
24{
25 unsigned long a;
26 __asm _emit 0fh
27 __asm _emit 31h
28 __asm mov a, eax;
29 tsc=a;
30}
31#endif
32
33#include <stdio.h>
34#include <stdlib.h>
35#include <openssl/md4.h>
36
37extern "C" {
38void md4_block_x86(MD4_CTX *ctx, unsigned char *buffer,int num);
39}
40
41void main(int argc,char *argv[])
42 {
43 unsigned char buffer[64*256];
44 MD4_CTX ctx;
45 unsigned long s1,s2,e1,e2;
46 unsigned char k[16];
47 unsigned long data[2];
48 unsigned char iv[8];
49 int i,num=0,numm;
50 int j=0;
51
52 if (argc >= 2)
53 num=atoi(argv[1]);
54
55 if (num == 0) num=16;
56 if (num > 250) num=16;
57 numm=num+2;
58 num*=64;
59 numm*=64;
60
61 for (j=0; j<6; j++)
62 {
63 for (i=0; i<10; i++) /**/
64 {
65 md4_block_x86(&ctx,buffer,numm);
66 GetTSC(s1);
67 md4_block_x86(&ctx,buffer,numm);
68 GetTSC(e1);
69 GetTSC(s2);
70 md4_block_x86(&ctx,buffer,num);
71 GetTSC(e2);
72 md4_block_x86(&ctx,buffer,num);
73 }
74 printf("md4 (%d bytes) %d %d (%.2f)\n",num,
75 e1-s1,e2-s2,(double)((e1-s1)-(e2-s2))/2);
76 }
77 }
78
diff --git a/src/lib/libcrypto/md4/md4test.c b/src/lib/libcrypto/md4/md4test.c
new file mode 100644
index 0000000000..97e6e21efd
--- /dev/null
+++ b/src/lib/libcrypto/md4/md4test.c
@@ -0,0 +1,131 @@
1/* crypto/md4/md4test.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <string.h>
61#include <stdlib.h>
62
63#ifdef NO_MD4
64int main(int argc, char *argv[])
65{
66 printf("No MD4 support\n");
67 return(0);
68}
69#else
70#include <openssl/md4.h>
71
72static char *test[]={
73 "",
74 "a",
75 "abc",
76 "message digest",
77 "abcdefghijklmnopqrstuvwxyz",
78 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
79 "12345678901234567890123456789012345678901234567890123456789012345678901234567890",
80 NULL,
81 };
82
83static char *ret[]={
84"31d6cfe0d16ae931b73c59d7e0c089c0",
85"bde52cb31de33e46245e05fbdbd6fb24",
86"a448017aaf21d8525fc10ae87aa6729d",
87"d9130a8164549fe818874806e1c7014b",
88"d79e1c308aa5bbcdeea8ed63df412da9",
89"043f8582f241db351ce627e153e7f0e4",
90"e33b4ddc9c38f2199c3e7b164fcc0536",
91};
92
93static char *pt(unsigned char *md);
94int main(int argc, char *argv[])
95 {
96 int i,err=0;
97 unsigned char **P,**R;
98 char *p;
99
100 P=(unsigned char **)test;
101 R=(unsigned char **)ret;
102 i=1;
103 while (*P != NULL)
104 {
105 p=pt(MD4(&(P[0][0]),(unsigned long)strlen((char *)*P),NULL));
106 if (strcmp(p,(char *)*R) != 0)
107 {
108 printf("error calculating MD4 on '%s'\n",*P);
109 printf("got %s instead of %s\n",p,*R);
110 err++;
111 }
112 else
113 printf("test %d ok\n",i);
114 i++;
115 R++;
116 P++;
117 }
118 exit(err);
119 return(0);
120 }
121
122static char *pt(unsigned char *md)
123 {
124 int i;
125 static char buf[80];
126
127 for (i=0; i<MD4_DIGEST_LENGTH; i++)
128 sprintf(&(buf[i*2]),"%02x",md[i]);
129 return(buf);
130 }
131#endif
diff --git a/src/lib/libcrypto/md5/asm/md5-sparcv9.S b/src/lib/libcrypto/md5/asm/md5-sparcv9.S
new file mode 100644
index 0000000000..ca4257f134
--- /dev/null
+++ b/src/lib/libcrypto/md5/asm/md5-sparcv9.S
@@ -0,0 +1,1029 @@
1.ident "md5-sparcv9.S, Version 1.0"
2.ident "SPARC V9 ISA artwork by Andy Polyakov <appro@fy.chalmers.se>"
3.file "md5-sparcv9.S"
4
5/*
6 * ====================================================================
7 * Copyright (c) 1999 Andy Polyakov <appro@fy.chalmers.se>.
8 *
9 * Rights for redistribution and usage in source and binary forms are
10 * granted as long as above copyright notices are retained. Warranty
11 * of any kind is (of course:-) disclaimed.
12 * ====================================================================
13 */
14
15/*
16 * This is my modest contribution to OpenSSL project (see
17 * http://www.openssl.org/ for more information about it) and is an
18 * assembler implementation of MD5 block hash function. I've hand-coded
19 * this for the sole reason to reach UltraSPARC-specific "load in
20 * little-endian byte order" instruction. This gives up to 15%
21 * performance improvement for cases when input message is aligned at
22 * 32 bits boundary. The module was tested under both 32 *and* 64 bit
23 * kernels. For updates see http://fy.chalmers.se/~appro/hpe/.
24 *
25 * To compile with SC4.x/SC5.x:
26 *
27 * cc -xarch=v[9|8plus] -DULTRASPARC -DMD5_BLOCK_DATA_ORDER \
28 * -c md5-sparcv9.S
29 *
30 * and with gcc:
31 *
32 * gcc -mcpu=ultrasparc -DULTRASPARC -DMD5_BLOCK_DATA_ORDER \
33 * -c md5-sparcv9.S
34 *
35 * or if above fails (it does if you have gas):
36 *
37 * gcc -E -DULTRASPARC -DMD5_BLOCK_DATA_ORDER md5_block.sparc.S | \
38 * as -xarch=v8plus /dev/fd/0 -o md5-sparcv9.o
39 */
40
41#define A %o0
42#define B %o1
43#define C %o2
44#define D %o3
45#define T1 %o4
46#define T2 %o5
47
48#define R0 %l0
49#define R1 %l1
50#define R2 %l2
51#define R3 %l3
52#define R4 %l4
53#define R5 %l5
54#define R6 %l6
55#define R7 %l7
56#define R8 %i3
57#define R9 %i4
58#define R10 %i5
59#define R11 %g1
60#define R12 %g2
61#define R13 %g3
62#define RX %g4
63
64#define Aptr %i0+0
65#define Bptr %i0+4
66#define Cptr %i0+8
67#define Dptr %i0+12
68
69#define Aval R5 /* those not used at the end of the last round */
70#define Bval R6
71#define Cval R7
72#define Dval R8
73
74#if defined(MD5_BLOCK_DATA_ORDER)
75# if defined(ULTRASPARC)
76# define LOAD lda
77# define X(i) [%i1+i*4]%asi
78# define md5_block md5_block_asm_data_order_aligned
79# define ASI_PRIMARY_LITTLE 0x88
80# else
81# error "MD5_BLOCK_DATA_ORDER is supported only on UltraSPARC!"
82# endif
83#else
84# define LOAD ld
85# define X(i) [%i1+i*4]
86# define md5_block md5_block_asm_host_order
87#endif
88
89.section ".text",#alloc,#execinstr
90
91#if defined(__SUNPRO_C) && defined(__sparcv9)
92 /* They've said -xarch=v9 at command line */
93 .register %g2,#scratch
94 .register %g3,#scratch
95# define FRAME -192
96#elif defined(__GNUC__) && defined(__arch64__)
97 /* They've said -m64 at command line */
98 .register %g2,#scratch
99 .register %g3,#scratch
100# define FRAME -192
101#else
102# define FRAME -96
103#endif
104
105.align 32
106
107.global md5_block
108md5_block:
109 save %sp,FRAME,%sp
110
111 ld [Dptr],D
112 ld [Cptr],C
113 ld [Bptr],B
114 ld [Aptr],A
115#ifdef ASI_PRIMARY_LITTLE
116 rd %asi,%o7 ! How dare I? Well, I just do:-)
117 wr %g0,ASI_PRIMARY_LITTLE,%asi
118#endif
119 LOAD X(0),R0
120
121.Lmd5_block_loop:
122
123!!!!!!!!Round 0
124
125 xor C,D,T1
126 sethi %hi(0xd76aa478),T2
127 and T1,B,T1
128 or T2,%lo(0xd76aa478),T2 !=
129 xor T1,D,T1
130 add T1,R0,T1
131 LOAD X(1),R1
132 add T1,T2,T1 !=
133 add A,T1,A
134 sll A,7,T2
135 srl A,32-7,A
136 or A,T2,A !=
137 xor B,C,T1
138 add A,B,A
139
140 sethi %hi(0xe8c7b756),T2
141 and T1,A,T1 !=
142 or T2,%lo(0xe8c7b756),T2
143 xor T1,C,T1
144 LOAD X(2),R2
145 add T1,R1,T1 !=
146 add T1,T2,T1
147 add D,T1,D
148 sll D,12,T2
149 srl D,32-12,D !=
150 or D,T2,D
151 xor A,B,T1
152 add D,A,D
153
154 sethi %hi(0x242070db),T2 !=
155 and T1,D,T1
156 or T2,%lo(0x242070db),T2
157 xor T1,B,T1
158 add T1,R2,T1 !=
159 LOAD X(3),R3
160 add T1,T2,T1
161 add C,T1,C
162 sll C,17,T2 !=
163 srl C,32-17,C
164 or C,T2,C
165 xor D,A,T1
166 add C,D,C !=
167
168 sethi %hi(0xc1bdceee),T2
169 and T1,C,T1
170 or T2,%lo(0xc1bdceee),T2
171 xor T1,A,T1 !=
172 add T1,R3,T1
173 LOAD X(4),R4
174 add T1,T2,T1
175 add B,T1,B !=
176 sll B,22,T2
177 srl B,32-22,B
178 or B,T2,B
179 xor C,D,T1 !=
180 add B,C,B
181
182 sethi %hi(0xf57c0faf),T2
183 and T1,B,T1
184 or T2,%lo(0xf57c0faf),T2 !=
185 xor T1,D,T1
186 add T1,R4,T1
187 LOAD X(5),R5
188 add T1,T2,T1 !=
189 add A,T1,A
190 sll A,7,T2
191 srl A,32-7,A
192 or A,T2,A !=
193 xor B,C,T1
194 add A,B,A
195
196 sethi %hi(0x4787c62a),T2
197 and T1,A,T1 !=
198 or T2,%lo(0x4787c62a),T2
199 xor T1,C,T1
200 LOAD X(6),R6
201 add T1,R5,T1 !=
202 add T1,T2,T1
203 add D,T1,D
204 sll D,12,T2
205 srl D,32-12,D !=
206 or D,T2,D
207 xor A,B,T1
208 add D,A,D
209
210 sethi %hi(0xa8304613),T2 !=
211 and T1,D,T1
212 or T2,%lo(0xa8304613),T2
213 xor T1,B,T1
214 add T1,R6,T1 !=
215 LOAD X(7),R7
216 add T1,T2,T1
217 add C,T1,C
218 sll C,17,T2 !=
219 srl C,32-17,C
220 or C,T2,C
221 xor D,A,T1
222 add C,D,C !=
223
224 sethi %hi(0xfd469501),T2
225 and T1,C,T1
226 or T2,%lo(0xfd469501),T2
227 xor T1,A,T1 !=
228 add T1,R7,T1
229 LOAD X(8),R8
230 add T1,T2,T1
231 add B,T1,B !=
232 sll B,22,T2
233 srl B,32-22,B
234 or B,T2,B
235 xor C,D,T1 !=
236 add B,C,B
237
238 sethi %hi(0x698098d8),T2
239 and T1,B,T1
240 or T2,%lo(0x698098d8),T2 !=
241 xor T1,D,T1
242 add T1,R8,T1
243 LOAD X(9),R9
244 add T1,T2,T1 !=
245 add A,T1,A
246 sll A,7,T2
247 srl A,32-7,A
248 or A,T2,A !=
249 xor B,C,T1
250 add A,B,A
251
252 sethi %hi(0x8b44f7af),T2
253 and T1,A,T1 !=
254 or T2,%lo(0x8b44f7af),T2
255 xor T1,C,T1
256 LOAD X(10),R10
257 add T1,R9,T1 !=
258 add T1,T2,T1
259 add D,T1,D
260 sll D,12,T2
261 srl D,32-12,D !=
262 or D,T2,D
263 xor A,B,T1
264 add D,A,D
265
266 sethi %hi(0xffff5bb1),T2 !=
267 and T1,D,T1
268 or T2,%lo(0xffff5bb1),T2
269 xor T1,B,T1
270 add T1,R10,T1 !=
271 LOAD X(11),R11
272 add T1,T2,T1
273 add C,T1,C
274 sll C,17,T2 !=
275 srl C,32-17,C
276 or C,T2,C
277 xor D,A,T1
278 add C,D,C !=
279
280 sethi %hi(0x895cd7be),T2
281 and T1,C,T1
282 or T2,%lo(0x895cd7be),T2
283 xor T1,A,T1 !=
284 add T1,R11,T1
285 LOAD X(12),R12
286 add T1,T2,T1
287 add B,T1,B !=
288 sll B,22,T2
289 srl B,32-22,B
290 or B,T2,B
291 xor C,D,T1 !=
292 add B,C,B
293
294 sethi %hi(0x6b901122),T2
295 and T1,B,T1
296 or T2,%lo(0x6b901122),T2 !=
297 xor T1,D,T1
298 add T1,R12,T1
299 LOAD X(13),R13
300 add T1,T2,T1 !=
301 add A,T1,A
302 sll A,7,T2
303 srl A,32-7,A
304 or A,T2,A !=
305 xor B,C,T1
306 add A,B,A
307
308 sethi %hi(0xfd987193),T2
309 and T1,A,T1 !=
310 or T2,%lo(0xfd987193),T2
311 xor T1,C,T1
312 LOAD X(14),RX
313 add T1,R13,T1 !=
314 add T1,T2,T1
315 add D,T1,D
316 sll D,12,T2
317 srl D,32-12,D !=
318 or D,T2,D
319 xor A,B,T1
320 add D,A,D
321
322 sethi %hi(0xa679438e),T2 !=
323 and T1,D,T1
324 or T2,%lo(0xa679438e),T2
325 xor T1,B,T1
326 add T1,RX,T1 !=
327 LOAD X(15),RX
328 add T1,T2,T1
329 add C,T1,C
330 sll C,17,T2 !=
331 srl C,32-17,C
332 or C,T2,C
333 xor D,A,T1
334 add C,D,C !=
335
336 sethi %hi(0x49b40821),T2
337 and T1,C,T1
338 or T2,%lo(0x49b40821),T2
339 xor T1,A,T1 !=
340 add T1,RX,T1
341 !pre-LOADed X(1),R1
342 add T1,T2,T1
343 add B,T1,B
344 sll B,22,T2 !=
345 srl B,32-22,B
346 or B,T2,B
347 add B,C,B
348
349!!!!!!!!Round 1
350
351 xor B,C,T1 !=
352 sethi %hi(0xf61e2562),T2
353 and T1,D,T1
354 or T2,%lo(0xf61e2562),T2
355 xor T1,C,T1 !=
356 add T1,R1,T1
357 !pre-LOADed X(6),R6
358 add T1,T2,T1
359 add A,T1,A
360 sll A,5,T2 !=
361 srl A,32-5,A
362 or A,T2,A
363 add A,B,A
364
365 xor A,B,T1 !=
366 sethi %hi(0xc040b340),T2
367 and T1,C,T1
368 or T2,%lo(0xc040b340),T2
369 xor T1,B,T1 !=
370 add T1,R6,T1
371 !pre-LOADed X(11),R11
372 add T1,T2,T1
373 add D,T1,D
374 sll D,9,T2 !=
375 srl D,32-9,D
376 or D,T2,D
377 add D,A,D
378
379 xor D,A,T1 !=
380 sethi %hi(0x265e5a51),T2
381 and T1,B,T1
382 or T2,%lo(0x265e5a51),T2
383 xor T1,A,T1 !=
384 add T1,R11,T1
385 !pre-LOADed X(0),R0
386 add T1,T2,T1
387 add C,T1,C
388 sll C,14,T2 !=
389 srl C,32-14,C
390 or C,T2,C
391 add C,D,C
392
393 xor C,D,T1 !=
394 sethi %hi(0xe9b6c7aa),T2
395 and T1,A,T1
396 or T2,%lo(0xe9b6c7aa),T2
397 xor T1,D,T1 !=
398 add T1,R0,T1
399 !pre-LOADed X(5),R5
400 add T1,T2,T1
401 add B,T1,B
402 sll B,20,T2 !=
403 srl B,32-20,B
404 or B,T2,B
405 add B,C,B
406
407 xor B,C,T1 !=
408 sethi %hi(0xd62f105d),T2
409 and T1,D,T1
410 or T2,%lo(0xd62f105d),T2
411 xor T1,C,T1 !=
412 add T1,R5,T1
413 !pre-LOADed X(10),R10
414 add T1,T2,T1
415 add A,T1,A
416 sll A,5,T2 !=
417 srl A,32-5,A
418 or A,T2,A
419 add A,B,A
420
421 xor A,B,T1 !=
422 sethi %hi(0x02441453),T2
423 and T1,C,T1
424 or T2,%lo(0x02441453),T2
425 xor T1,B,T1 !=
426 add T1,R10,T1
427 LOAD X(15),RX
428 add T1,T2,T1
429 add D,T1,D !=
430 sll D,9,T2
431 srl D,32-9,D
432 or D,T2,D
433 add D,A,D !=
434
435 xor D,A,T1
436 sethi %hi(0xd8a1e681),T2
437 and T1,B,T1
438 or T2,%lo(0xd8a1e681),T2 !=
439 xor T1,A,T1
440 add T1,RX,T1
441 !pre-LOADed X(4),R4
442 add T1,T2,T1
443 add C,T1,C !=
444 sll C,14,T2
445 srl C,32-14,C
446 or C,T2,C
447 add C,D,C !=
448
449 xor C,D,T1
450 sethi %hi(0xe7d3fbc8),T2
451 and T1,A,T1
452 or T2,%lo(0xe7d3fbc8),T2 !=
453 xor T1,D,T1
454 add T1,R4,T1
455 !pre-LOADed X(9),R9
456 add T1,T2,T1
457 add B,T1,B !=
458 sll B,20,T2
459 srl B,32-20,B
460 or B,T2,B
461 add B,C,B !=
462
463 xor B,C,T1
464 sethi %hi(0x21e1cde6),T2
465 and T1,D,T1
466 or T2,%lo(0x21e1cde6),T2 !=
467 xor T1,C,T1
468 add T1,R9,T1
469 LOAD X(14),RX
470 add T1,T2,T1 !=
471 add A,T1,A
472 sll A,5,T2
473 srl A,32-5,A
474 or A,T2,A !=
475 add A,B,A
476
477 xor A,B,T1
478 sethi %hi(0xc33707d6),T2
479 and T1,C,T1 !=
480 or T2,%lo(0xc33707d6),T2
481 xor T1,B,T1
482 add T1,RX,T1
483 !pre-LOADed X(3),R3
484 add T1,T2,T1 !=
485 add D,T1,D
486 sll D,9,T2
487 srl D,32-9,D
488 or D,T2,D !=
489 add D,A,D
490
491 xor D,A,T1
492 sethi %hi(0xf4d50d87),T2
493 and T1,B,T1 !=
494 or T2,%lo(0xf4d50d87),T2
495 xor T1,A,T1
496 add T1,R3,T1
497 !pre-LOADed X(8),R8
498 add T1,T2,T1 !=
499 add C,T1,C
500 sll C,14,T2
501 srl C,32-14,C
502 or C,T2,C !=
503 add C,D,C
504
505 xor C,D,T1
506 sethi %hi(0x455a14ed),T2
507 and T1,A,T1 !=
508 or T2,%lo(0x455a14ed),T2
509 xor T1,D,T1
510 add T1,R8,T1
511 !pre-LOADed X(13),R13
512 add T1,T2,T1 !=
513 add B,T1,B
514 sll B,20,T2
515 srl B,32-20,B
516 or B,T2,B !=
517 add B,C,B
518
519 xor B,C,T1
520 sethi %hi(0xa9e3e905),T2
521 and T1,D,T1 !=
522 or T2,%lo(0xa9e3e905),T2
523 xor T1,C,T1
524 add T1,R13,T1
525 !pre-LOADed X(2),R2
526 add T1,T2,T1 !=
527 add A,T1,A
528 sll A,5,T2
529 srl A,32-5,A
530 or A,T2,A !=
531 add A,B,A
532
533 xor A,B,T1
534 sethi %hi(0xfcefa3f8),T2
535 and T1,C,T1 !=
536 or T2,%lo(0xfcefa3f8),T2
537 xor T1,B,T1
538 add T1,R2,T1
539 !pre-LOADed X(7),R7
540 add T1,T2,T1 !=
541 add D,T1,D
542 sll D,9,T2
543 srl D,32-9,D
544 or D,T2,D !=
545 add D,A,D
546
547 xor D,A,T1
548 sethi %hi(0x676f02d9),T2
549 and T1,B,T1 !=
550 or T2,%lo(0x676f02d9),T2
551 xor T1,A,T1
552 add T1,R7,T1
553 !pre-LOADed X(12),R12
554 add T1,T2,T1 !=
555 add C,T1,C
556 sll C,14,T2
557 srl C,32-14,C
558 or C,T2,C !=
559 add C,D,C
560
561 xor C,D,T1
562 sethi %hi(0x8d2a4c8a),T2
563 and T1,A,T1 !=
564 or T2,%lo(0x8d2a4c8a),T2
565 xor T1,D,T1
566 add T1,R12,T1
567 !pre-LOADed X(5),R5
568 add T1,T2,T1 !=
569 add B,T1,B
570 sll B,20,T2
571 srl B,32-20,B
572 or B,T2,B !=
573 add B,C,B
574
575!!!!!!!!Round 2
576
577 xor B,C,T1
578 sethi %hi(0xfffa3942),T2
579 xor T1,D,T1 !=
580 or T2,%lo(0xfffa3942),T2
581 add T1,R5,T1
582 !pre-LOADed X(8),R8
583 add T1,T2,T1
584 add A,T1,A !=
585 sll A,4,T2
586 srl A,32-4,A
587 or A,T2,A
588 add A,B,A !=
589
590 xor A,B,T1
591 sethi %hi(0x8771f681),T2
592 xor T1,C,T1
593 or T2,%lo(0x8771f681),T2 !=
594 add T1,R8,T1
595 !pre-LOADed X(11),R11
596 add T1,T2,T1
597 add D,T1,D
598 sll D,11,T2 !=
599 srl D,32-11,D
600 or D,T2,D
601 add D,A,D
602
603 xor D,A,T1 !=
604 sethi %hi(0x6d9d6122),T2
605 xor T1,B,T1
606 or T2,%lo(0x6d9d6122),T2
607 add T1,R11,T1 !=
608 LOAD X(14),RX
609 add T1,T2,T1
610 add C,T1,C
611 sll C,16,T2 !=
612 srl C,32-16,C
613 or C,T2,C
614 add C,D,C
615
616 xor C,D,T1 !=
617 sethi %hi(0xfde5380c),T2
618 xor T1,A,T1
619 or T2,%lo(0xfde5380c),T2
620 add T1,RX,T1 !=
621 !pre-LOADed X(1),R1
622 add T1,T2,T1
623 add B,T1,B
624 sll B,23,T2
625 srl B,32-23,B !=
626 or B,T2,B
627 add B,C,B
628
629 xor B,C,T1
630 sethi %hi(0xa4beea44),T2 !=
631 xor T1,D,T1
632 or T2,%lo(0xa4beea44),T2
633 add T1,R1,T1
634 !pre-LOADed X(4),R4
635 add T1,T2,T1 !=
636 add A,T1,A
637 sll A,4,T2
638 srl A,32-4,A
639 or A,T2,A !=
640 add A,B,A
641
642 xor A,B,T1
643 sethi %hi(0x4bdecfa9),T2
644 xor T1,C,T1 !=
645 or T2,%lo(0x4bdecfa9),T2
646 add T1,R4,T1
647 !pre-LOADed X(7),R7
648 add T1,T2,T1
649 add D,T1,D !=
650 sll D,11,T2
651 srl D,32-11,D
652 or D,T2,D
653 add D,A,D !=
654
655 xor D,A,T1
656 sethi %hi(0xf6bb4b60),T2
657 xor T1,B,T1
658 or T2,%lo(0xf6bb4b60),T2 !=
659 add T1,R7,T1
660 !pre-LOADed X(10),R10
661 add T1,T2,T1
662 add C,T1,C
663 sll C,16,T2 !=
664 srl C,32-16,C
665 or C,T2,C
666 add C,D,C
667
668 xor C,D,T1 !=
669 sethi %hi(0xbebfbc70),T2
670 xor T1,A,T1
671 or T2,%lo(0xbebfbc70),T2
672 add T1,R10,T1 !=
673 !pre-LOADed X(13),R13
674 add T1,T2,T1
675 add B,T1,B
676 sll B,23,T2
677 srl B,32-23,B !=
678 or B,T2,B
679 add B,C,B
680
681 xor B,C,T1
682 sethi %hi(0x289b7ec6),T2 !=
683 xor T1,D,T1
684 or T2,%lo(0x289b7ec6),T2
685 add T1,R13,T1
686 !pre-LOADed X(0),R0
687 add T1,T2,T1 !=
688 add A,T1,A
689 sll A,4,T2
690 srl A,32-4,A
691 or A,T2,A !=
692 add A,B,A
693
694 xor A,B,T1
695 sethi %hi(0xeaa127fa),T2
696 xor T1,C,T1 !=
697 or T2,%lo(0xeaa127fa),T2
698 add T1,R0,T1
699 !pre-LOADed X(3),R3
700 add T1,T2,T1
701 add D,T1,D !=
702 sll D,11,T2
703 srl D,32-11,D
704 or D,T2,D
705 add D,A,D !=
706
707 xor D,A,T1
708 sethi %hi(0xd4ef3085),T2
709 xor T1,B,T1
710 or T2,%lo(0xd4ef3085),T2 !=
711 add T1,R3,T1
712 !pre-LOADed X(6),R6
713 add T1,T2,T1
714 add C,T1,C
715 sll C,16,T2 !=
716 srl C,32-16,C
717 or C,T2,C
718 add C,D,C
719
720 xor C,D,T1 !=
721 sethi %hi(0x04881d05),T2
722 xor T1,A,T1
723 or T2,%lo(0x04881d05),T2
724 add T1,R6,T1 !=
725 !pre-LOADed X(9),R9
726 add T1,T2,T1
727 add B,T1,B
728 sll B,23,T2
729 srl B,32-23,B !=
730 or B,T2,B
731 add B,C,B
732
733 xor B,C,T1
734 sethi %hi(0xd9d4d039),T2 !=
735 xor T1,D,T1
736 or T2,%lo(0xd9d4d039),T2
737 add T1,R9,T1
738 !pre-LOADed X(12),R12
739 add T1,T2,T1 !=
740 add A,T1,A
741 sll A,4,T2
742 srl A,32-4,A
743 or A,T2,A !=
744 add A,B,A
745
746 xor A,B,T1
747 sethi %hi(0xe6db99e5),T2
748 xor T1,C,T1 !=
749 or T2,%lo(0xe6db99e5),T2
750 add T1,R12,T1
751 LOAD X(15),RX
752 add T1,T2,T1 !=
753 add D,T1,D
754 sll D,11,T2
755 srl D,32-11,D
756 or D,T2,D !=
757 add D,A,D
758
759 xor D,A,T1
760 sethi %hi(0x1fa27cf8),T2
761 xor T1,B,T1 !=
762 or T2,%lo(0x1fa27cf8),T2
763 add T1,RX,T1
764 !pre-LOADed X(2),R2
765 add T1,T2,T1
766 add C,T1,C !=
767 sll C,16,T2
768 srl C,32-16,C
769 or C,T2,C
770 add C,D,C !=
771
772 xor C,D,T1
773 sethi %hi(0xc4ac5665),T2
774 xor T1,A,T1
775 or T2,%lo(0xc4ac5665),T2 !=
776 add T1,R2,T1
777 !pre-LOADed X(0),R0
778 add T1,T2,T1
779 add B,T1,B
780 sll B,23,T2 !=
781 srl B,32-23,B
782 or B,T2,B
783 add B,C,B
784
785!!!!!!!!Round 3
786
787 orn B,D,T1 !=
788 sethi %hi(0xf4292244),T2
789 xor T1,C,T1
790 or T2,%lo(0xf4292244),T2
791 add T1,R0,T1 !=
792 !pre-LOADed X(7),R7
793 add T1,T2,T1
794 add A,T1,A
795 sll A,6,T2
796 srl A,32-6,A !=
797 or A,T2,A
798 add A,B,A
799
800 orn A,C,T1
801 sethi %hi(0x432aff97),T2 !=
802 xor T1,B,T1
803 or T2,%lo(0x432aff97),T2
804 LOAD X(14),RX
805 add T1,R7,T1 !=
806 add T1,T2,T1
807 add D,T1,D
808 sll D,10,T2
809 srl D,32-10,D !=
810 or D,T2,D
811 add D,A,D
812
813 orn D,B,T1
814 sethi %hi(0xab9423a7),T2 !=
815 xor T1,A,T1
816 or T2,%lo(0xab9423a7),T2
817 add T1,RX,T1
818 !pre-LOADed X(5),R5
819 add T1,T2,T1 !=
820 add C,T1,C
821 sll C,15,T2
822 srl C,32-15,C
823 or C,T2,C !=
824 add C,D,C
825
826 orn C,A,T1
827 sethi %hi(0xfc93a039),T2
828 xor T1,D,T1 !=
829 or T2,%lo(0xfc93a039),T2
830 add T1,R5,T1
831 !pre-LOADed X(12),R12
832 add T1,T2,T1
833 add B,T1,B !=
834 sll B,21,T2
835 srl B,32-21,B
836 or B,T2,B
837 add B,C,B !=
838
839 orn B,D,T1
840 sethi %hi(0x655b59c3),T2
841 xor T1,C,T1
842 or T2,%lo(0x655b59c3),T2 !=
843 add T1,R12,T1
844 !pre-LOADed X(3),R3
845 add T1,T2,T1
846 add A,T1,A
847 sll A,6,T2 !=
848 srl A,32-6,A
849 or A,T2,A
850 add A,B,A
851
852 orn A,C,T1 !=
853 sethi %hi(0x8f0ccc92),T2
854 xor T1,B,T1
855 or T2,%lo(0x8f0ccc92),T2
856 add T1,R3,T1 !=
857 !pre-LOADed X(10),R10
858 add T1,T2,T1
859 add D,T1,D
860 sll D,10,T2
861 srl D,32-10,D !=
862 or D,T2,D
863 add D,A,D
864
865 orn D,B,T1
866 sethi %hi(0xffeff47d),T2 !=
867 xor T1,A,T1
868 or T2,%lo(0xffeff47d),T2
869 add T1,R10,T1
870 !pre-LOADed X(1),R1
871 add T1,T2,T1 !=
872 add C,T1,C
873 sll C,15,T2
874 srl C,32-15,C
875 or C,T2,C !=
876 add C,D,C
877
878 orn C,A,T1
879 sethi %hi(0x85845dd1),T2
880 xor T1,D,T1 !=
881 or T2,%lo(0x85845dd1),T2
882 add T1,R1,T1
883 !pre-LOADed X(8),R8
884 add T1,T2,T1
885 add B,T1,B !=
886 sll B,21,T2
887 srl B,32-21,B
888 or B,T2,B
889 add B,C,B !=
890
891 orn B,D,T1
892 sethi %hi(0x6fa87e4f),T2
893 xor T1,C,T1
894 or T2,%lo(0x6fa87e4f),T2 !=
895 add T1,R8,T1
896 LOAD X(15),RX
897 add T1,T2,T1
898 add A,T1,A !=
899 sll A,6,T2
900 srl A,32-6,A
901 or A,T2,A
902 add A,B,A !=
903
904 orn A,C,T1
905 sethi %hi(0xfe2ce6e0),T2
906 xor T1,B,T1
907 or T2,%lo(0xfe2ce6e0),T2 !=
908 add T1,RX,T1
909 !pre-LOADed X(6),R6
910 add T1,T2,T1
911 add D,T1,D
912 sll D,10,T2 !=
913 srl D,32-10,D
914 or D,T2,D
915 add D,A,D
916
917 orn D,B,T1 !=
918 sethi %hi(0xa3014314),T2
919 xor T1,A,T1
920 or T2,%lo(0xa3014314),T2
921 add T1,R6,T1 !=
922 !pre-LOADed X(13),R13
923 add T1,T2,T1
924 add C,T1,C
925 sll C,15,T2
926 srl C,32-15,C !=
927 or C,T2,C
928 add C,D,C
929
930 orn C,A,T1
931 sethi %hi(0x4e0811a1),T2 !=
932 xor T1,D,T1
933 or T2,%lo(0x4e0811a1),T2
934 !pre-LOADed X(4),R4
935 ld [Aptr],Aval
936 add T1,R13,T1 !=
937 add T1,T2,T1
938 add B,T1,B
939 sll B,21,T2
940 srl B,32-21,B !=
941 or B,T2,B
942 add B,C,B
943
944 orn B,D,T1
945 sethi %hi(0xf7537e82),T2 !=
946 xor T1,C,T1
947 or T2,%lo(0xf7537e82),T2
948 !pre-LOADed X(11),R11
949 ld [Dptr],Dval
950 add T1,R4,T1 !=
951 add T1,T2,T1
952 add A,T1,A
953 sll A,6,T2
954 srl A,32-6,A !=
955 or A,T2,A
956 add A,B,A
957
958 orn A,C,T1
959 sethi %hi(0xbd3af235),T2 !=
960 xor T1,B,T1
961 or T2,%lo(0xbd3af235),T2
962 !pre-LOADed X(2),R2
963 ld [Cptr],Cval
964 add T1,R11,T1 !=
965 add T1,T2,T1
966 add D,T1,D
967 sll D,10,T2
968 srl D,32-10,D !=
969 or D,T2,D
970 add D,A,D
971
972 orn D,B,T1
973 sethi %hi(0x2ad7d2bb),T2 !=
974 xor T1,A,T1
975 or T2,%lo(0x2ad7d2bb),T2
976 !pre-LOADed X(9),R9
977 ld [Bptr],Bval
978 add T1,R2,T1 !=
979 add Aval,A,Aval
980 add T1,T2,T1
981 st Aval,[Aptr]
982 add C,T1,C !=
983 sll C,15,T2
984 add Dval,D,Dval
985 srl C,32-15,C
986 or C,T2,C !=
987 st Dval,[Dptr]
988 add C,D,C
989
990 orn C,A,T1
991 sethi %hi(0xeb86d391),T2 !=
992 xor T1,D,T1
993 or T2,%lo(0xeb86d391),T2
994 add T1,R9,T1
995 !pre-LOADed X(0),R0
996 mov Aval,A !=
997 add T1,T2,T1
998 mov Dval,D
999 add B,T1,B
1000 sll B,21,T2 !=
1001 add Cval,C,Cval
1002 srl B,32-21,B
1003 st Cval,[Cptr]
1004 or B,T2,B !=
1005 add B,C,B
1006
1007 deccc %i2
1008 mov Cval,C
1009 add B,Bval,B !=
1010 inc 64,%i1
1011 nop
1012 st B,[Bptr]
1013 nop !=
1014
1015#ifdef ULTRASPARC
1016 bg,a,pt %icc,.Lmd5_block_loop
1017#else
1018 bg,a .Lmd5_block_loop
1019#endif
1020 LOAD X(0),R0
1021
1022#ifdef ASI_PRIMARY_LITTLE
1023 wr %g0,%o7,%asi
1024#endif
1025 ret
1026 restore %g0,0,%o0
1027
1028.type md5_block,#function
1029.size md5_block,(.-md5_block)
diff --git a/src/lib/libcrypto/objects/obj_mac.h b/src/lib/libcrypto/objects/obj_mac.h
new file mode 100644
index 0000000000..401b1e5a1b
--- /dev/null
+++ b/src/lib/libcrypto/objects/obj_mac.h
@@ -0,0 +1,1798 @@
1/* lib/obj/obj_mac.h */
2/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59/* THIS FILE IS GENERATED FROM objects.txt by objects.pl via the
60 * following command:
61 * perl objects.pl objects.txt obj_mac.num obj_mac.h
62 */
63
64#define SN_undef "UNDEF"
65#define LN_undef "undefined"
66#define NID_undef 0
67#define OBJ_undef 0L
68
69#define SN_iso "ISO"
70#define LN_iso "iso"
71#define NID_iso 181
72#define OBJ_iso 1L
73
74#define SN_member_body "member-body"
75#define LN_member_body "ISO Member Body"
76#define NID_member_body 182
77#define OBJ_member_body OBJ_iso,2L
78
79#define SN_ISO_US "ISO-US"
80#define LN_ISO_US "ISO US Member Body"
81#define NID_ISO_US 183
82#define OBJ_ISO_US OBJ_member_body,840L
83
84#define SN_X9_57 "X9-57"
85#define LN_X9_57 "X9.57"
86#define NID_X9_57 184
87#define OBJ_X9_57 OBJ_ISO_US,10040L
88
89#define SN_X9cm "X9cm"
90#define LN_X9cm "X9.57 CM ?"
91#define NID_X9cm 185
92#define OBJ_X9cm OBJ_X9_57,4L
93
94#define SN_dsa "DSA"
95#define LN_dsa "dsaEncryption"
96#define NID_dsa 116
97#define OBJ_dsa OBJ_X9cm,1L
98
99#define SN_dsaWithSHA1 "DSA-SHA1"
100#define LN_dsaWithSHA1 "dsaWithSHA1"
101#define NID_dsaWithSHA1 113
102#define OBJ_dsaWithSHA1 OBJ_X9cm,3L
103
104#define SN_cast5_cbc "CAST5-CBC"
105#define LN_cast5_cbc "cast5-cbc"
106#define NID_cast5_cbc 108
107#define OBJ_cast5_cbc OBJ_ISO_US,113533L,7L,66L,10L
108
109#define SN_cast5_ecb "CAST5-ECB"
110#define LN_cast5_ecb "cast5-ecb"
111#define NID_cast5_ecb 109
112
113#define SN_cast5_cfb64 "CAST5-CFB"
114#define LN_cast5_cfb64 "cast5-cfb"
115#define NID_cast5_cfb64 110
116
117#define SN_cast5_ofb64 "CAST5-OFB"
118#define LN_cast5_ofb64 "cast5-ofb"
119#define NID_cast5_ofb64 111
120
121#define LN_pbeWithMD5AndCast5_CBC "pbeWithMD5AndCast5CBC"
122#define NID_pbeWithMD5AndCast5_CBC 112
123#define OBJ_pbeWithMD5AndCast5_CBC OBJ_ISO_US,113533L,7L,66L,12L
124
125#define SN_rsadsi "rsadsi"
126#define LN_rsadsi "RSA Data Security, Inc."
127#define NID_rsadsi 1
128#define OBJ_rsadsi OBJ_ISO_US,113549L
129
130#define SN_pkcs "pkcs"
131#define LN_pkcs "RSA Data Security, Inc. PKCS"
132#define NID_pkcs 2
133#define OBJ_pkcs OBJ_rsadsi,1L
134
135#define SN_pkcs1 "pkcs1"
136#define NID_pkcs1 186
137#define OBJ_pkcs1 OBJ_pkcs,1L
138
139#define LN_rsaEncryption "rsaEncryption"
140#define NID_rsaEncryption 6
141#define OBJ_rsaEncryption OBJ_pkcs1,1L
142
143#define SN_md2WithRSAEncryption "RSA-MD2"
144#define LN_md2WithRSAEncryption "md2WithRSAEncryption"
145#define NID_md2WithRSAEncryption 7
146#define OBJ_md2WithRSAEncryption OBJ_pkcs1,2L
147
148#define SN_md5WithRSAEncryption "RSA-MD5"
149#define LN_md5WithRSAEncryption "md5WithRSAEncryption"
150#define NID_md5WithRSAEncryption 8
151#define OBJ_md5WithRSAEncryption OBJ_pkcs1,4L
152
153#define SN_sha1WithRSAEncryption "RSA-SHA1"
154#define LN_sha1WithRSAEncryption "sha1WithRSAEncryption"
155#define NID_sha1WithRSAEncryption 65
156#define OBJ_sha1WithRSAEncryption OBJ_pkcs1,5L
157
158#define SN_pkcs3 "pkcs3"
159#define NID_pkcs3 27
160#define OBJ_pkcs3 OBJ_pkcs,3L
161
162#define LN_dhKeyAgreement "dhKeyAgreement"
163#define NID_dhKeyAgreement 28
164#define OBJ_dhKeyAgreement OBJ_pkcs3,1L
165
166#define SN_pkcs5 "pkcs5"
167#define NID_pkcs5 187
168#define OBJ_pkcs5 OBJ_pkcs,5L
169
170#define SN_pbeWithMD2AndDES_CBC "PBE-MD2-DES"
171#define LN_pbeWithMD2AndDES_CBC "pbeWithMD2AndDES-CBC"
172#define NID_pbeWithMD2AndDES_CBC 9
173#define OBJ_pbeWithMD2AndDES_CBC OBJ_pkcs5,1L
174
175#define SN_pbeWithMD5AndDES_CBC "PBE-MD5-DES"
176#define LN_pbeWithMD5AndDES_CBC "pbeWithMD5AndDES-CBC"
177#define NID_pbeWithMD5AndDES_CBC 10
178#define OBJ_pbeWithMD5AndDES_CBC OBJ_pkcs5,3L
179
180#define SN_pbeWithMD2AndRC2_CBC "PBE-MD2-RC2-64"
181#define LN_pbeWithMD2AndRC2_CBC "pbeWithMD2AndRC2-CBC"
182#define NID_pbeWithMD2AndRC2_CBC 168
183#define OBJ_pbeWithMD2AndRC2_CBC OBJ_pkcs5,4L
184
185#define SN_pbeWithMD5AndRC2_CBC "PBE-MD5-RC2-64"
186#define LN_pbeWithMD5AndRC2_CBC "pbeWithMD5AndRC2-CBC"
187#define NID_pbeWithMD5AndRC2_CBC 169
188#define OBJ_pbeWithMD5AndRC2_CBC OBJ_pkcs5,6L
189
190#define SN_pbeWithSHA1AndDES_CBC "PBE-SHA1-DES"
191#define LN_pbeWithSHA1AndDES_CBC "pbeWithSHA1AndDES-CBC"
192#define NID_pbeWithSHA1AndDES_CBC 170
193#define OBJ_pbeWithSHA1AndDES_CBC OBJ_pkcs5,10L
194
195#define SN_pbeWithSHA1AndRC2_CBC "PBE-SHA1-RC2-64"
196#define LN_pbeWithSHA1AndRC2_CBC "pbeWithSHA1AndRC2-CBC"
197#define NID_pbeWithSHA1AndRC2_CBC 68
198#define OBJ_pbeWithSHA1AndRC2_CBC OBJ_pkcs5,11L
199
200#define LN_id_pbkdf2 "PBKDF2"
201#define NID_id_pbkdf2 69
202#define OBJ_id_pbkdf2 OBJ_pkcs5,12L
203
204#define LN_pbes2 "PBES2"
205#define NID_pbes2 161
206#define OBJ_pbes2 OBJ_pkcs5,13L
207
208#define LN_pbmac1 "PBMAC1"
209#define NID_pbmac1 162
210#define OBJ_pbmac1 OBJ_pkcs5,14L
211
212#define SN_pkcs7 "pkcs7"
213#define NID_pkcs7 20
214#define OBJ_pkcs7 OBJ_pkcs,7L
215
216#define LN_pkcs7_data "pkcs7-data"
217#define NID_pkcs7_data 21
218#define OBJ_pkcs7_data OBJ_pkcs7,1L
219
220#define LN_pkcs7_signed "pkcs7-signedData"
221#define NID_pkcs7_signed 22
222#define OBJ_pkcs7_signed OBJ_pkcs7,2L
223
224#define LN_pkcs7_enveloped "pkcs7-envelopedData"
225#define NID_pkcs7_enveloped 23
226#define OBJ_pkcs7_enveloped OBJ_pkcs7,3L
227
228#define LN_pkcs7_signedAndEnveloped "pkcs7-signedAndEnvelopedData"
229#define NID_pkcs7_signedAndEnveloped 24
230#define OBJ_pkcs7_signedAndEnveloped OBJ_pkcs7,4L
231
232#define LN_pkcs7_digest "pkcs7-digestData"
233#define NID_pkcs7_digest 25
234#define OBJ_pkcs7_digest OBJ_pkcs7,5L
235
236#define LN_pkcs7_encrypted "pkcs7-encryptedData"
237#define NID_pkcs7_encrypted 26
238#define OBJ_pkcs7_encrypted OBJ_pkcs7,6L
239
240#define SN_pkcs9 "pkcs9"
241#define NID_pkcs9 47
242#define OBJ_pkcs9 OBJ_pkcs,9L
243
244#define SN_pkcs9_emailAddress "Email"
245#define LN_pkcs9_emailAddress "emailAddress"
246#define NID_pkcs9_emailAddress 48
247#define OBJ_pkcs9_emailAddress OBJ_pkcs9,1L
248
249#define LN_pkcs9_unstructuredName "unstructuredName"
250#define NID_pkcs9_unstructuredName 49
251#define OBJ_pkcs9_unstructuredName OBJ_pkcs9,2L
252
253#define LN_pkcs9_contentType "contentType"
254#define NID_pkcs9_contentType 50
255#define OBJ_pkcs9_contentType OBJ_pkcs9,3L
256
257#define LN_pkcs9_messageDigest "messageDigest"
258#define NID_pkcs9_messageDigest 51
259#define OBJ_pkcs9_messageDigest OBJ_pkcs9,4L
260
261#define LN_pkcs9_signingTime "signingTime"
262#define NID_pkcs9_signingTime 52
263#define OBJ_pkcs9_signingTime OBJ_pkcs9,5L
264
265#define LN_pkcs9_countersignature "countersignature"
266#define NID_pkcs9_countersignature 53
267#define OBJ_pkcs9_countersignature OBJ_pkcs9,6L
268
269#define LN_pkcs9_challengePassword "challengePassword"
270#define NID_pkcs9_challengePassword 54
271#define OBJ_pkcs9_challengePassword OBJ_pkcs9,7L
272
273#define LN_pkcs9_unstructuredAddress "unstructuredAddress"
274#define NID_pkcs9_unstructuredAddress 55
275#define OBJ_pkcs9_unstructuredAddress OBJ_pkcs9,8L
276
277#define LN_pkcs9_extCertAttributes "extendedCertificateAttributes"
278#define NID_pkcs9_extCertAttributes 56
279#define OBJ_pkcs9_extCertAttributes OBJ_pkcs9,9L
280
281#define SN_ext_req "extReq"
282#define LN_ext_req "Extension Request"
283#define NID_ext_req 172
284#define OBJ_ext_req OBJ_pkcs9,14L
285
286#define SN_SMIMECapabilities "SMIME-CAPS"
287#define LN_SMIMECapabilities "S/MIME Capabilities"
288#define NID_SMIMECapabilities 167
289#define OBJ_SMIMECapabilities OBJ_pkcs9,15L
290
291#define SN_SMIME "SMIME"
292#define LN_SMIME "S/MIME"
293#define NID_SMIME 188
294#define OBJ_SMIME OBJ_pkcs9,16L
295
296#define SN_id_smime_mod "id-smime-mod"
297#define NID_id_smime_mod 189
298#define OBJ_id_smime_mod OBJ_SMIME,0L
299
300#define SN_id_smime_ct "id-smime-ct"
301#define NID_id_smime_ct 190
302#define OBJ_id_smime_ct OBJ_SMIME,1L
303
304#define SN_id_smime_aa "id-smime-aa"
305#define NID_id_smime_aa 191
306#define OBJ_id_smime_aa OBJ_SMIME,2L
307
308#define SN_id_smime_alg "id-smime-alg"
309#define NID_id_smime_alg 192
310#define OBJ_id_smime_alg OBJ_SMIME,3L
311
312#define SN_id_smime_cd "id-smime-cd"
313#define NID_id_smime_cd 193
314#define OBJ_id_smime_cd OBJ_SMIME,4L
315
316#define SN_id_smime_spq "id-smime-spq"
317#define NID_id_smime_spq 194
318#define OBJ_id_smime_spq OBJ_SMIME,5L
319
320#define SN_id_smime_cti "id-smime-cti"
321#define NID_id_smime_cti 195
322#define OBJ_id_smime_cti OBJ_SMIME,6L
323
324#define SN_id_smime_mod_cms "id-smime-mod-cms"
325#define NID_id_smime_mod_cms 196
326#define OBJ_id_smime_mod_cms OBJ_id_smime_mod,1L
327
328#define SN_id_smime_mod_ess "id-smime-mod-ess"
329#define NID_id_smime_mod_ess 197
330#define OBJ_id_smime_mod_ess OBJ_id_smime_mod,2L
331
332#define SN_id_smime_mod_oid "id-smime-mod-oid"
333#define NID_id_smime_mod_oid 198
334#define OBJ_id_smime_mod_oid OBJ_id_smime_mod,3L
335
336#define SN_id_smime_mod_msg_v3 "id-smime-mod-msg-v3"
337#define NID_id_smime_mod_msg_v3 199
338#define OBJ_id_smime_mod_msg_v3 OBJ_id_smime_mod,4L
339
340#define SN_id_smime_mod_ets_eSignature_88 "id-smime-mod-ets-eSignature-88"
341#define NID_id_smime_mod_ets_eSignature_88 200
342#define OBJ_id_smime_mod_ets_eSignature_88 OBJ_id_smime_mod,5L
343
344#define SN_id_smime_mod_ets_eSignature_97 "id-smime-mod-ets-eSignature-97"
345#define NID_id_smime_mod_ets_eSignature_97 201
346#define OBJ_id_smime_mod_ets_eSignature_97 OBJ_id_smime_mod,6L
347
348#define SN_id_smime_mod_ets_eSigPolicy_88 "id-smime-mod-ets-eSigPolicy-88"
349#define NID_id_smime_mod_ets_eSigPolicy_88 202
350#define OBJ_id_smime_mod_ets_eSigPolicy_88 OBJ_id_smime_mod,7L
351
352#define SN_id_smime_mod_ets_eSigPolicy_97 "id-smime-mod-ets-eSigPolicy-97"
353#define NID_id_smime_mod_ets_eSigPolicy_97 203
354#define OBJ_id_smime_mod_ets_eSigPolicy_97 OBJ_id_smime_mod,8L
355
356#define SN_id_smime_ct_receipt "id-smime-ct-receipt"
357#define NID_id_smime_ct_receipt 204
358#define OBJ_id_smime_ct_receipt OBJ_id_smime_ct,1L
359
360#define SN_id_smime_ct_authData "id-smime-ct-authData"
361#define NID_id_smime_ct_authData 205
362#define OBJ_id_smime_ct_authData OBJ_id_smime_ct,2L
363
364#define SN_id_smime_ct_publishCert "id-smime-ct-publishCert"
365#define NID_id_smime_ct_publishCert 206
366#define OBJ_id_smime_ct_publishCert OBJ_id_smime_ct,3L
367
368#define SN_id_smime_ct_TSTInfo "id-smime-ct-TSTInfo"
369#define NID_id_smime_ct_TSTInfo 207
370#define OBJ_id_smime_ct_TSTInfo OBJ_id_smime_ct,4L
371
372#define SN_id_smime_ct_TDTInfo "id-smime-ct-TDTInfo"
373#define NID_id_smime_ct_TDTInfo 208
374#define OBJ_id_smime_ct_TDTInfo OBJ_id_smime_ct,5L
375
376#define SN_id_smime_ct_contentInfo "id-smime-ct-contentInfo"
377#define NID_id_smime_ct_contentInfo 209
378#define OBJ_id_smime_ct_contentInfo OBJ_id_smime_ct,6L
379
380#define SN_id_smime_ct_DVCSRequestData "id-smime-ct-DVCSRequestData"
381#define NID_id_smime_ct_DVCSRequestData 210
382#define OBJ_id_smime_ct_DVCSRequestData OBJ_id_smime_ct,7L
383
384#define SN_id_smime_ct_DVCSResponseData "id-smime-ct-DVCSResponseData"
385#define NID_id_smime_ct_DVCSResponseData 211
386#define OBJ_id_smime_ct_DVCSResponseData OBJ_id_smime_ct,8L
387
388#define SN_id_smime_aa_receiptRequest "id-smime-aa-receiptRequest"
389#define NID_id_smime_aa_receiptRequest 212
390#define OBJ_id_smime_aa_receiptRequest OBJ_id_smime_aa,1L
391
392#define SN_id_smime_aa_securityLabel "id-smime-aa-securityLabel"
393#define NID_id_smime_aa_securityLabel 213
394#define OBJ_id_smime_aa_securityLabel OBJ_id_smime_aa,2L
395
396#define SN_id_smime_aa_mlExpandHistory "id-smime-aa-mlExpandHistory"
397#define NID_id_smime_aa_mlExpandHistory 214
398#define OBJ_id_smime_aa_mlExpandHistory OBJ_id_smime_aa,3L
399
400#define SN_id_smime_aa_contentHint "id-smime-aa-contentHint"
401#define NID_id_smime_aa_contentHint 215
402#define OBJ_id_smime_aa_contentHint OBJ_id_smime_aa,4L
403
404#define SN_id_smime_aa_msgSigDigest "id-smime-aa-msgSigDigest"
405#define NID_id_smime_aa_msgSigDigest 216
406#define OBJ_id_smime_aa_msgSigDigest OBJ_id_smime_aa,5L
407
408#define SN_id_smime_aa_encapContentType "id-smime-aa-encapContentType"
409#define NID_id_smime_aa_encapContentType 217
410#define OBJ_id_smime_aa_encapContentType OBJ_id_smime_aa,6L
411
412#define SN_id_smime_aa_contentIdentifier "id-smime-aa-contentIdentifier"
413#define NID_id_smime_aa_contentIdentifier 218
414#define OBJ_id_smime_aa_contentIdentifier OBJ_id_smime_aa,7L
415
416#define SN_id_smime_aa_macValue "id-smime-aa-macValue"
417#define NID_id_smime_aa_macValue 219
418#define OBJ_id_smime_aa_macValue OBJ_id_smime_aa,8L
419
420#define SN_id_smime_aa_equivalentLabels "id-smime-aa-equivalentLabels"
421#define NID_id_smime_aa_equivalentLabels 220
422#define OBJ_id_smime_aa_equivalentLabels OBJ_id_smime_aa,9L
423
424#define SN_id_smime_aa_contentReference "id-smime-aa-contentReference"
425#define NID_id_smime_aa_contentReference 221
426#define OBJ_id_smime_aa_contentReference OBJ_id_smime_aa,10L
427
428#define SN_id_smime_aa_encrypKeyPref "id-smime-aa-encrypKeyPref"
429#define NID_id_smime_aa_encrypKeyPref 222
430#define OBJ_id_smime_aa_encrypKeyPref OBJ_id_smime_aa,11L
431
432#define SN_id_smime_aa_signingCertificate "id-smime-aa-signingCertificate"
433#define NID_id_smime_aa_signingCertificate 223
434#define OBJ_id_smime_aa_signingCertificate OBJ_id_smime_aa,12L
435
436#define SN_id_smime_aa_smimeEncryptCerts "id-smime-aa-smimeEncryptCerts"
437#define NID_id_smime_aa_smimeEncryptCerts 224
438#define OBJ_id_smime_aa_smimeEncryptCerts OBJ_id_smime_aa,13L
439
440#define SN_id_smime_aa_timeStampToken "id-smime-aa-timeStampToken"
441#define NID_id_smime_aa_timeStampToken 225
442#define OBJ_id_smime_aa_timeStampToken OBJ_id_smime_aa,14L
443
444#define SN_id_smime_aa_ets_sigPolicyId "id-smime-aa-ets-sigPolicyId"
445#define NID_id_smime_aa_ets_sigPolicyId 226
446#define OBJ_id_smime_aa_ets_sigPolicyId OBJ_id_smime_aa,15L
447
448#define SN_id_smime_aa_ets_commitmentType "id-smime-aa-ets-commitmentType"
449#define NID_id_smime_aa_ets_commitmentType 227
450#define OBJ_id_smime_aa_ets_commitmentType OBJ_id_smime_aa,16L
451
452#define SN_id_smime_aa_ets_signerLocation "id-smime-aa-ets-signerLocation"
453#define NID_id_smime_aa_ets_signerLocation 228
454#define OBJ_id_smime_aa_ets_signerLocation OBJ_id_smime_aa,17L
455
456#define SN_id_smime_aa_ets_signerAttr "id-smime-aa-ets-signerAttr"
457#define NID_id_smime_aa_ets_signerAttr 229
458#define OBJ_id_smime_aa_ets_signerAttr OBJ_id_smime_aa,18L
459
460#define SN_id_smime_aa_ets_otherSigCert "id-smime-aa-ets-otherSigCert"
461#define NID_id_smime_aa_ets_otherSigCert 230
462#define OBJ_id_smime_aa_ets_otherSigCert OBJ_id_smime_aa,19L
463
464#define SN_id_smime_aa_ets_contentTimestamp "id-smime-aa-ets-contentTimestamp"
465#define NID_id_smime_aa_ets_contentTimestamp 231
466#define OBJ_id_smime_aa_ets_contentTimestamp OBJ_id_smime_aa,20L
467
468#define SN_id_smime_aa_ets_CertificateRefs "id-smime-aa-ets-CertificateRefs"
469#define NID_id_smime_aa_ets_CertificateRefs 232
470#define OBJ_id_smime_aa_ets_CertificateRefs OBJ_id_smime_aa,21L
471
472#define SN_id_smime_aa_ets_RevocationRefs "id-smime-aa-ets-RevocationRefs"
473#define NID_id_smime_aa_ets_RevocationRefs 233
474#define OBJ_id_smime_aa_ets_RevocationRefs OBJ_id_smime_aa,22L
475
476#define SN_id_smime_aa_ets_certValues "id-smime-aa-ets-certValues"
477#define NID_id_smime_aa_ets_certValues 234
478#define OBJ_id_smime_aa_ets_certValues OBJ_id_smime_aa,23L
479
480#define SN_id_smime_aa_ets_revocationValues "id-smime-aa-ets-revocationValues"
481#define NID_id_smime_aa_ets_revocationValues 235
482#define OBJ_id_smime_aa_ets_revocationValues OBJ_id_smime_aa,24L
483
484#define SN_id_smime_aa_ets_escTimeStamp "id-smime-aa-ets-escTimeStamp"
485#define NID_id_smime_aa_ets_escTimeStamp 236
486#define OBJ_id_smime_aa_ets_escTimeStamp OBJ_id_smime_aa,25L
487
488#define SN_id_smime_aa_ets_certCRLTimestamp "id-smime-aa-ets-certCRLTimestamp"
489#define NID_id_smime_aa_ets_certCRLTimestamp 237
490#define OBJ_id_smime_aa_ets_certCRLTimestamp OBJ_id_smime_aa,26L
491
492#define SN_id_smime_aa_ets_archiveTimeStamp "id-smime-aa-ets-archiveTimeStamp"
493#define NID_id_smime_aa_ets_archiveTimeStamp 238
494#define OBJ_id_smime_aa_ets_archiveTimeStamp OBJ_id_smime_aa,27L
495
496#define SN_id_smime_aa_signatureType "id-smime-aa-signatureType"
497#define NID_id_smime_aa_signatureType 239
498#define OBJ_id_smime_aa_signatureType OBJ_id_smime_aa,28L
499
500#define SN_id_smime_aa_dvcs_dvc "id-smime-aa-dvcs-dvc"
501#define NID_id_smime_aa_dvcs_dvc 240
502#define OBJ_id_smime_aa_dvcs_dvc OBJ_id_smime_aa,29L
503
504#define SN_id_smime_alg_ESDHwith3DES "id-smime-alg-ESDHwith3DES"
505#define NID_id_smime_alg_ESDHwith3DES 241
506#define OBJ_id_smime_alg_ESDHwith3DES OBJ_id_smime_alg,1L
507
508#define SN_id_smime_alg_ESDHwithRC2 "id-smime-alg-ESDHwithRC2"
509#define NID_id_smime_alg_ESDHwithRC2 242
510#define OBJ_id_smime_alg_ESDHwithRC2 OBJ_id_smime_alg,2L
511
512#define SN_id_smime_alg_3DESwrap "id-smime-alg-3DESwrap"
513#define NID_id_smime_alg_3DESwrap 243
514#define OBJ_id_smime_alg_3DESwrap OBJ_id_smime_alg,3L
515
516#define SN_id_smime_alg_RC2wrap "id-smime-alg-RC2wrap"
517#define NID_id_smime_alg_RC2wrap 244
518#define OBJ_id_smime_alg_RC2wrap OBJ_id_smime_alg,4L
519
520#define SN_id_smime_alg_ESDH "id-smime-alg-ESDH"
521#define NID_id_smime_alg_ESDH 245
522#define OBJ_id_smime_alg_ESDH OBJ_id_smime_alg,5L
523
524#define SN_id_smime_alg_CMS3DESwrap "id-smime-alg-CMS3DESwrap"
525#define NID_id_smime_alg_CMS3DESwrap 246
526#define OBJ_id_smime_alg_CMS3DESwrap OBJ_id_smime_alg,6L
527
528#define SN_id_smime_alg_CMSRC2wrap "id-smime-alg-CMSRC2wrap"
529#define NID_id_smime_alg_CMSRC2wrap 247
530#define OBJ_id_smime_alg_CMSRC2wrap OBJ_id_smime_alg,7L
531
532#define SN_id_smime_cd_ldap "id-smime-cd-ldap"
533#define NID_id_smime_cd_ldap 248
534#define OBJ_id_smime_cd_ldap OBJ_id_smime_cd,1L
535
536#define SN_id_smime_spq_ets_sqt_uri "id-smime-spq-ets-sqt-uri"
537#define NID_id_smime_spq_ets_sqt_uri 249
538#define OBJ_id_smime_spq_ets_sqt_uri OBJ_id_smime_spq,1L
539
540#define SN_id_smime_spq_ets_sqt_unotice "id-smime-spq-ets-sqt-unotice"
541#define NID_id_smime_spq_ets_sqt_unotice 250
542#define OBJ_id_smime_spq_ets_sqt_unotice OBJ_id_smime_spq,2L
543
544#define SN_id_smime_cti_ets_proofOfOrigin "id-smime-cti-ets-proofOfOrigin"
545#define NID_id_smime_cti_ets_proofOfOrigin 251
546#define OBJ_id_smime_cti_ets_proofOfOrigin OBJ_id_smime_cti,1L
547
548#define SN_id_smime_cti_ets_proofOfReceipt "id-smime-cti-ets-proofOfReceipt"
549#define NID_id_smime_cti_ets_proofOfReceipt 252
550#define OBJ_id_smime_cti_ets_proofOfReceipt OBJ_id_smime_cti,2L
551
552#define SN_id_smime_cti_ets_proofOfDelivery "id-smime-cti-ets-proofOfDelivery"
553#define NID_id_smime_cti_ets_proofOfDelivery 253
554#define OBJ_id_smime_cti_ets_proofOfDelivery OBJ_id_smime_cti,3L
555
556#define SN_id_smime_cti_ets_proofOfSender "id-smime-cti-ets-proofOfSender"
557#define NID_id_smime_cti_ets_proofOfSender 254
558#define OBJ_id_smime_cti_ets_proofOfSender OBJ_id_smime_cti,4L
559
560#define SN_id_smime_cti_ets_proofOfApproval "id-smime-cti-ets-proofOfApproval"
561#define NID_id_smime_cti_ets_proofOfApproval 255
562#define OBJ_id_smime_cti_ets_proofOfApproval OBJ_id_smime_cti,5L
563
564#define SN_id_smime_cti_ets_proofOfCreation "id-smime-cti-ets-proofOfCreation"
565#define NID_id_smime_cti_ets_proofOfCreation 256
566#define OBJ_id_smime_cti_ets_proofOfCreation OBJ_id_smime_cti,6L
567
568#define LN_friendlyName "friendlyName"
569#define NID_friendlyName 156
570#define OBJ_friendlyName OBJ_pkcs9,20L
571
572#define LN_localKeyID "localKeyID"
573#define NID_localKeyID 157
574#define OBJ_localKeyID OBJ_pkcs9,21L
575
576#define OBJ_certTypes OBJ_pkcs9,22L
577
578#define LN_x509Certificate "x509Certificate"
579#define NID_x509Certificate 158
580#define OBJ_x509Certificate OBJ_certTypes,1L
581
582#define LN_sdsiCertificate "sdsiCertificate"
583#define NID_sdsiCertificate 159
584#define OBJ_sdsiCertificate OBJ_certTypes,2L
585
586#define OBJ_crlTypes OBJ_pkcs9,23L
587
588#define LN_x509Crl "x509Crl"
589#define NID_x509Crl 160
590#define OBJ_x509Crl OBJ_crlTypes,1L
591
592#define OBJ_pkcs12 OBJ_pkcs,12L
593
594#define OBJ_pkcs12_pbeids OBJ_pkcs12,1L
595
596#define SN_pbe_WithSHA1And128BitRC4 "PBE-SHA1-RC4-128"
597#define LN_pbe_WithSHA1And128BitRC4 "pbeWithSHA1And128BitRC4"
598#define NID_pbe_WithSHA1And128BitRC4 144
599#define OBJ_pbe_WithSHA1And128BitRC4 OBJ_pkcs12_pbeids,1L
600
601#define SN_pbe_WithSHA1And40BitRC4 "PBE-SHA1-RC4-40"
602#define LN_pbe_WithSHA1And40BitRC4 "pbeWithSHA1And40BitRC4"
603#define NID_pbe_WithSHA1And40BitRC4 145
604#define OBJ_pbe_WithSHA1And40BitRC4 OBJ_pkcs12_pbeids,2L
605
606#define SN_pbe_WithSHA1And3_Key_TripleDES_CBC "PBE-SHA1-3DES"
607#define LN_pbe_WithSHA1And3_Key_TripleDES_CBC "pbeWithSHA1And3-KeyTripleDES-CBC"
608#define NID_pbe_WithSHA1And3_Key_TripleDES_CBC 146
609#define OBJ_pbe_WithSHA1And3_Key_TripleDES_CBC OBJ_pkcs12_pbeids,3L
610
611#define SN_pbe_WithSHA1And2_Key_TripleDES_CBC "PBE-SHA1-2DES"
612#define LN_pbe_WithSHA1And2_Key_TripleDES_CBC "pbeWithSHA1And2-KeyTripleDES-CBC"
613#define NID_pbe_WithSHA1And2_Key_TripleDES_CBC 147
614#define OBJ_pbe_WithSHA1And2_Key_TripleDES_CBC OBJ_pkcs12_pbeids,4L
615
616#define SN_pbe_WithSHA1And128BitRC2_CBC "PBE-SHA1-RC2-128"
617#define LN_pbe_WithSHA1And128BitRC2_CBC "pbeWithSHA1And128BitRC2-CBC"
618#define NID_pbe_WithSHA1And128BitRC2_CBC 148
619#define OBJ_pbe_WithSHA1And128BitRC2_CBC OBJ_pkcs12_pbeids,5L
620
621#define SN_pbe_WithSHA1And40BitRC2_CBC "PBE-SHA1-RC2-40"
622#define LN_pbe_WithSHA1And40BitRC2_CBC "pbeWithSHA1And40BitRC2-CBC"
623#define NID_pbe_WithSHA1And40BitRC2_CBC 149
624#define OBJ_pbe_WithSHA1And40BitRC2_CBC OBJ_pkcs12_pbeids,6L
625
626#define OBJ_pkcs12_Version1 OBJ_pkcs12,10L
627
628#define OBJ_pkcs12_BagIds OBJ_pkcs12_Version1,1L
629
630#define LN_keyBag "keyBag"
631#define NID_keyBag 150
632#define OBJ_keyBag OBJ_pkcs12_BagIds,1L
633
634#define LN_pkcs8ShroudedKeyBag "pkcs8ShroudedKeyBag"
635#define NID_pkcs8ShroudedKeyBag 151
636#define OBJ_pkcs8ShroudedKeyBag OBJ_pkcs12_BagIds,2L
637
638#define LN_certBag "certBag"
639#define NID_certBag 152
640#define OBJ_certBag OBJ_pkcs12_BagIds,3L
641
642#define LN_crlBag "crlBag"
643#define NID_crlBag 153
644#define OBJ_crlBag OBJ_pkcs12_BagIds,4L
645
646#define LN_secretBag "secretBag"
647#define NID_secretBag 154
648#define OBJ_secretBag OBJ_pkcs12_BagIds,5L
649
650#define LN_safeContentsBag "safeContentsBag"
651#define NID_safeContentsBag 155
652#define OBJ_safeContentsBag OBJ_pkcs12_BagIds,6L
653
654#define SN_md2 "MD2"
655#define LN_md2 "md2"
656#define NID_md2 3
657#define OBJ_md2 OBJ_rsadsi,2L,2L
658
659#define SN_md4 "MD4"
660#define LN_md4 "md4"
661#define NID_md4 257
662#define OBJ_md4 OBJ_rsadsi,2L,4L
663
664#define SN_md5 "MD5"
665#define LN_md5 "md5"
666#define NID_md5 4
667#define OBJ_md5 OBJ_rsadsi,2L,5L
668
669#define SN_md5_sha1 "MD5-SHA1"
670#define LN_md5_sha1 "md5-sha1"
671#define NID_md5_sha1 114
672
673#define LN_hmacWithSHA1 "hmacWithSHA1"
674#define NID_hmacWithSHA1 163
675#define OBJ_hmacWithSHA1 OBJ_rsadsi,2L,7L
676
677#define SN_rc2_cbc "RC2-CBC"
678#define LN_rc2_cbc "rc2-cbc"
679#define NID_rc2_cbc 37
680#define OBJ_rc2_cbc OBJ_rsadsi,3L,2L
681
682#define SN_rc2_ecb "RC2-ECB"
683#define LN_rc2_ecb "rc2-ecb"
684#define NID_rc2_ecb 38
685
686#define SN_rc2_cfb64 "RC2-CFB"
687#define LN_rc2_cfb64 "rc2-cfb"
688#define NID_rc2_cfb64 39
689
690#define SN_rc2_ofb64 "RC2-OFB"
691#define LN_rc2_ofb64 "rc2-ofb"
692#define NID_rc2_ofb64 40
693
694#define SN_rc2_40_cbc "RC2-40-CBC"
695#define LN_rc2_40_cbc "rc2-40-cbc"
696#define NID_rc2_40_cbc 98
697
698#define SN_rc2_64_cbc "RC2-64-CBC"
699#define LN_rc2_64_cbc "rc2-64-cbc"
700#define NID_rc2_64_cbc 166
701
702#define SN_rc4 "RC4"
703#define LN_rc4 "rc4"
704#define NID_rc4 5
705#define OBJ_rc4 OBJ_rsadsi,3L,4L
706
707#define SN_rc4_40 "RC4-40"
708#define LN_rc4_40 "rc4-40"
709#define NID_rc4_40 97
710
711#define SN_des_ede3_cbc "DES-EDE3-CBC"
712#define LN_des_ede3_cbc "des-ede3-cbc"
713#define NID_des_ede3_cbc 44
714#define OBJ_des_ede3_cbc OBJ_rsadsi,3L,7L
715
716#define SN_rc5_cbc "RC5-CBC"
717#define LN_rc5_cbc "rc5-cbc"
718#define NID_rc5_cbc 120
719#define OBJ_rc5_cbc OBJ_rsadsi,3L,8L
720
721#define SN_rc5_ecb "RC5-ECB"
722#define LN_rc5_ecb "rc5-ecb"
723#define NID_rc5_ecb 121
724
725#define SN_rc5_cfb64 "RC5-CFB"
726#define LN_rc5_cfb64 "rc5-cfb"
727#define NID_rc5_cfb64 122
728
729#define SN_rc5_ofb64 "RC5-OFB"
730#define LN_rc5_ofb64 "rc5-ofb"
731#define NID_rc5_ofb64 123
732
733#define SN_ms_ext_req "msExtReq"
734#define LN_ms_ext_req "Microsoft Extension Request"
735#define NID_ms_ext_req 171
736#define OBJ_ms_ext_req 1L,3L,6L,1L,4L,1L,311L,2L,1L,14L
737
738#define SN_ms_code_ind "msCodeInd"
739#define LN_ms_code_ind "Microsoft Individual Code Signing"
740#define NID_ms_code_ind 134
741#define OBJ_ms_code_ind 1L,3L,6L,1L,4L,1L,311L,2L,1L,21L
742
743#define SN_ms_code_com "msCodeCom"
744#define LN_ms_code_com "Microsoft Commercial Code Signing"
745#define NID_ms_code_com 135
746#define OBJ_ms_code_com 1L,3L,6L,1L,4L,1L,311L,2L,1L,22L
747
748#define SN_ms_ctl_sign "msCTLSign"
749#define LN_ms_ctl_sign "Microsoft Trust List Signing"
750#define NID_ms_ctl_sign 136
751#define OBJ_ms_ctl_sign 1L,3L,6L,1L,4L,1L,311L,10L,3L,1L
752
753#define SN_ms_sgc "msSGC"
754#define LN_ms_sgc "Microsoft Server Gated Crypto"
755#define NID_ms_sgc 137
756#define OBJ_ms_sgc 1L,3L,6L,1L,4L,1L,311L,10L,3L,3L
757
758#define SN_ms_efs "msEFS"
759#define LN_ms_efs "Microsoft Encrypted File System"
760#define NID_ms_efs 138
761#define OBJ_ms_efs 1L,3L,6L,1L,4L,1L,311L,10L,3L,4L
762
763#define SN_idea_cbc "IDEA-CBC"
764#define LN_idea_cbc "idea-cbc"
765#define NID_idea_cbc 34
766#define OBJ_idea_cbc 1L,3L,6L,1L,4L,1L,188L,7L,1L,1L,2L
767
768#define SN_idea_ecb "IDEA-ECB"
769#define LN_idea_ecb "idea-ecb"
770#define NID_idea_ecb 36
771
772#define SN_idea_cfb64 "IDEA-CFB"
773#define LN_idea_cfb64 "idea-cfb"
774#define NID_idea_cfb64 35
775
776#define SN_idea_ofb64 "IDEA-OFB"
777#define LN_idea_ofb64 "idea-ofb"
778#define NID_idea_ofb64 46
779
780#define SN_bf_cbc "BF-CBC"
781#define LN_bf_cbc "bf-cbc"
782#define NID_bf_cbc 91
783#define OBJ_bf_cbc 1L,3L,6L,1L,4L,1L,3029L,1L,2L
784
785#define SN_bf_ecb "BF-ECB"
786#define LN_bf_ecb "bf-ecb"
787#define NID_bf_ecb 92
788
789#define SN_bf_cfb64 "BF-CFB"
790#define LN_bf_cfb64 "bf-cfb"
791#define NID_bf_cfb64 93
792
793#define SN_bf_ofb64 "BF-OFB"
794#define LN_bf_ofb64 "bf-ofb"
795#define NID_bf_ofb64 94
796
797#define SN_id_pkix "PKIX"
798#define NID_id_pkix 127
799#define OBJ_id_pkix 1L,3L,6L,1L,5L,5L,7L
800
801#define SN_id_pkix_mod "id-pkix-mod"
802#define NID_id_pkix_mod 258
803#define OBJ_id_pkix_mod OBJ_id_pkix,0L
804
805#define SN_id_pe "id-pe"
806#define NID_id_pe 175
807#define OBJ_id_pe OBJ_id_pkix,1L
808
809#define SN_id_qt "id-qt"
810#define NID_id_qt 259
811#define OBJ_id_qt OBJ_id_pkix,2L
812
813#define SN_id_kp "id-kp"
814#define NID_id_kp 128
815#define OBJ_id_kp OBJ_id_pkix,3L
816
817#define SN_id_it "id-it"
818#define NID_id_it 260
819#define OBJ_id_it OBJ_id_pkix,4L
820
821#define SN_id_pkip "id-pkip"
822#define NID_id_pkip 261
823#define OBJ_id_pkip OBJ_id_pkix,5L
824
825#define SN_id_alg "id-alg"
826#define NID_id_alg 262
827#define OBJ_id_alg OBJ_id_pkix,6L
828
829#define SN_id_cmc "id-cmc"
830#define NID_id_cmc 263
831#define OBJ_id_cmc OBJ_id_pkix,7L
832
833#define SN_id_on "id-on"
834#define NID_id_on 264
835#define OBJ_id_on OBJ_id_pkix,8L
836
837#define SN_id_pda "id-pda"
838#define NID_id_pda 265
839#define OBJ_id_pda OBJ_id_pkix,9L
840
841#define SN_id_aca "id-aca"
842#define NID_id_aca 266
843#define OBJ_id_aca OBJ_id_pkix,10L
844
845#define SN_id_qcs "id-qcs"
846#define NID_id_qcs 267
847#define OBJ_id_qcs OBJ_id_pkix,11L
848
849#define SN_id_cct "id-cct"
850#define NID_id_cct 268
851#define OBJ_id_cct OBJ_id_pkix,12L
852
853#define SN_id_ad "id-ad"
854#define NID_id_ad 176
855#define OBJ_id_ad OBJ_id_pkix,48L
856
857#define SN_id_pkix1_explicit_88 "id-pkix1-explicit-88"
858#define NID_id_pkix1_explicit_88 269
859#define OBJ_id_pkix1_explicit_88 OBJ_id_pkix_mod,1L
860
861#define SN_id_pkix1_implicit_88 "id-pkix1-implicit-88"
862#define NID_id_pkix1_implicit_88 270
863#define OBJ_id_pkix1_implicit_88 OBJ_id_pkix_mod,2L
864
865#define SN_id_pkix1_explicit_93 "id-pkix1-explicit-93"
866#define NID_id_pkix1_explicit_93 271
867#define OBJ_id_pkix1_explicit_93 OBJ_id_pkix_mod,3L
868
869#define SN_id_pkix1_implicit_93 "id-pkix1-implicit-93"
870#define NID_id_pkix1_implicit_93 272
871#define OBJ_id_pkix1_implicit_93 OBJ_id_pkix_mod,4L
872
873#define SN_id_mod_crmf "id-mod-crmf"
874#define NID_id_mod_crmf 273
875#define OBJ_id_mod_crmf OBJ_id_pkix_mod,5L
876
877#define SN_id_mod_cmc "id-mod-cmc"
878#define NID_id_mod_cmc 274
879#define OBJ_id_mod_cmc OBJ_id_pkix_mod,6L
880
881#define SN_id_mod_kea_profile_88 "id-mod-kea-profile-88"
882#define NID_id_mod_kea_profile_88 275
883#define OBJ_id_mod_kea_profile_88 OBJ_id_pkix_mod,7L
884
885#define SN_id_mod_kea_profile_93 "id-mod-kea-profile-93"
886#define NID_id_mod_kea_profile_93 276
887#define OBJ_id_mod_kea_profile_93 OBJ_id_pkix_mod,8L
888
889#define SN_id_mod_cmp "id-mod-cmp"
890#define NID_id_mod_cmp 277
891#define OBJ_id_mod_cmp OBJ_id_pkix_mod,9L
892
893#define SN_id_mod_qualified_cert_88 "id-mod-qualified-cert-88"
894#define NID_id_mod_qualified_cert_88 278
895#define OBJ_id_mod_qualified_cert_88 OBJ_id_pkix_mod,10L
896
897#define SN_id_mod_qualified_cert_93 "id-mod-qualified-cert-93"
898#define NID_id_mod_qualified_cert_93 279
899#define OBJ_id_mod_qualified_cert_93 OBJ_id_pkix_mod,11L
900
901#define SN_id_mod_attribute_cert "id-mod-attribute-cert"
902#define NID_id_mod_attribute_cert 280
903#define OBJ_id_mod_attribute_cert OBJ_id_pkix_mod,12L
904
905#define SN_id_mod_timestamp_protocol "id-mod-timestamp-protocol"
906#define NID_id_mod_timestamp_protocol 281
907#define OBJ_id_mod_timestamp_protocol OBJ_id_pkix_mod,13L
908
909#define SN_id_mod_ocsp "id-mod-ocsp"
910#define NID_id_mod_ocsp 282
911#define OBJ_id_mod_ocsp OBJ_id_pkix_mod,14L
912
913#define SN_id_mod_dvcs "id-mod-dvcs"
914#define NID_id_mod_dvcs 283
915#define OBJ_id_mod_dvcs OBJ_id_pkix_mod,15L
916
917#define SN_id_mod_cmp2000 "id-mod-cmp2000"
918#define NID_id_mod_cmp2000 284
919#define OBJ_id_mod_cmp2000 OBJ_id_pkix_mod,16L
920
921#define SN_info_access "authorityInfoAccess"
922#define LN_info_access "Authority Information Access"
923#define NID_info_access 177
924#define OBJ_info_access OBJ_id_pe,1L
925
926#define SN_biometricInfo "biometricInfo"
927#define LN_biometricInfo "Biometric Info"
928#define NID_biometricInfo 285
929#define OBJ_biometricInfo OBJ_id_pe,2L
930
931#define SN_qcStatements "qcStatements"
932#define NID_qcStatements 286
933#define OBJ_qcStatements OBJ_id_pe,3L
934
935#define SN_ac_auditEntity "ac-auditEntity"
936#define NID_ac_auditEntity 287
937#define OBJ_ac_auditEntity OBJ_id_pe,4L
938
939#define SN_ac_targeting "ac-targeting"
940#define NID_ac_targeting 288
941#define OBJ_ac_targeting OBJ_id_pe,5L
942
943#define SN_aaControls "aaControls"
944#define NID_aaControls 289
945#define OBJ_aaControls OBJ_id_pe,6L
946
947#define SN_sbqp_ipAddrBlock "sbqp-ipAddrBlock"
948#define NID_sbqp_ipAddrBlock 290
949#define OBJ_sbqp_ipAddrBlock OBJ_id_pe,7L
950
951#define SN_sbqp_autonomousSysNum "sbqp-autonomousSysNum"
952#define NID_sbqp_autonomousSysNum 291
953#define OBJ_sbqp_autonomousSysNum OBJ_id_pe,8L
954
955#define SN_sbqp_routerIdentifier "sbqp-routerIdentifier"
956#define NID_sbqp_routerIdentifier 292
957#define OBJ_sbqp_routerIdentifier OBJ_id_pe,9L
958
959#define SN_id_qt_cps "id-qt-cps"
960#define LN_id_qt_cps "Policy Qualifier CPS"
961#define NID_id_qt_cps 164
962#define OBJ_id_qt_cps OBJ_id_qt,1L
963
964#define SN_id_qt_unotice "id-qt-unotice"
965#define LN_id_qt_unotice "Policy Qualifier User Notice"
966#define NID_id_qt_unotice 165
967#define OBJ_id_qt_unotice OBJ_id_qt,2L
968
969#define SN_textNotice "textNotice"
970#define NID_textNotice 293
971#define OBJ_textNotice OBJ_id_qt,3L
972
973#define SN_server_auth "serverAuth"
974#define LN_server_auth "TLS Web Server Authentication"
975#define NID_server_auth 129
976#define OBJ_server_auth OBJ_id_kp,1L
977
978#define SN_client_auth "clientAuth"
979#define LN_client_auth "TLS Web Client Authentication"
980#define NID_client_auth 130
981#define OBJ_client_auth OBJ_id_kp,2L
982
983#define SN_code_sign "codeSigning"
984#define LN_code_sign "Code Signing"
985#define NID_code_sign 131
986#define OBJ_code_sign OBJ_id_kp,3L
987
988#define SN_email_protect "emailProtection"
989#define LN_email_protect "E-mail Protection"
990#define NID_email_protect 132
991#define OBJ_email_protect OBJ_id_kp,4L
992
993#define SN_ipsecEndSystem "ipsecEndSystem"
994#define LN_ipsecEndSystem "IPSec End System"
995#define NID_ipsecEndSystem 294
996#define OBJ_ipsecEndSystem OBJ_id_kp,5L
997
998#define SN_ipsecTunnel "ipsecTunnel"
999#define LN_ipsecTunnel "IPSec Tunnel"
1000#define NID_ipsecTunnel 295
1001#define OBJ_ipsecTunnel OBJ_id_kp,6L
1002
1003#define SN_ipsecUser "ipsecUser"
1004#define LN_ipsecUser "IPSec User"
1005#define NID_ipsecUser 296
1006#define OBJ_ipsecUser OBJ_id_kp,7L
1007
1008#define SN_time_stamp "timeStamping"
1009#define LN_time_stamp "Time Stamping"
1010#define NID_time_stamp 133
1011#define OBJ_time_stamp OBJ_id_kp,8L
1012
1013#define SN_OCSP_sign "OCSPSigning"
1014#define LN_OCSP_sign "OCSP Signing"
1015#define NID_OCSP_sign 180
1016#define OBJ_OCSP_sign OBJ_id_kp,9L
1017
1018#define SN_dvcs "DVCS"
1019#define LN_dvcs "dvcs"
1020#define NID_dvcs 297
1021#define OBJ_dvcs OBJ_id_kp,10L
1022
1023#define SN_id_it_caProtEncCert "id-it-caProtEncCert"
1024#define NID_id_it_caProtEncCert 298
1025#define OBJ_id_it_caProtEncCert OBJ_id_it,1L
1026
1027#define SN_id_it_signKeyPairTypes "id-it-signKeyPairTypes"
1028#define NID_id_it_signKeyPairTypes 299
1029#define OBJ_id_it_signKeyPairTypes OBJ_id_it,2L
1030
1031#define SN_id_it_encKeyPairTypes "id-it-encKeyPairTypes"
1032#define NID_id_it_encKeyPairTypes 300
1033#define OBJ_id_it_encKeyPairTypes OBJ_id_it,3L
1034
1035#define SN_id_it_preferredSymmAlg "id-it-preferredSymmAlg"
1036#define NID_id_it_preferredSymmAlg 301
1037#define OBJ_id_it_preferredSymmAlg OBJ_id_it,4L
1038
1039#define SN_id_it_caKeyUpdateInfo "id-it-caKeyUpdateInfo"
1040#define NID_id_it_caKeyUpdateInfo 302
1041#define OBJ_id_it_caKeyUpdateInfo OBJ_id_it,5L
1042
1043#define SN_id_it_currentCRL "id-it-currentCRL"
1044#define NID_id_it_currentCRL 303
1045#define OBJ_id_it_currentCRL OBJ_id_it,6L
1046
1047#define SN_id_it_unsupportedOIDs "id-it-unsupportedOIDs"
1048#define NID_id_it_unsupportedOIDs 304
1049#define OBJ_id_it_unsupportedOIDs OBJ_id_it,7L
1050
1051#define SN_id_it_subscriptionRequest "id-it-subscriptionRequest"
1052#define NID_id_it_subscriptionRequest 305
1053#define OBJ_id_it_subscriptionRequest OBJ_id_it,8L
1054
1055#define SN_id_it_subscriptionResponse "id-it-subscriptionResponse"
1056#define NID_id_it_subscriptionResponse 306
1057#define OBJ_id_it_subscriptionResponse OBJ_id_it,9L
1058
1059#define SN_id_it_keyPairParamReq "id-it-keyPairParamReq"
1060#define NID_id_it_keyPairParamReq 307
1061#define OBJ_id_it_keyPairParamReq OBJ_id_it,10L
1062
1063#define SN_id_it_keyPairParamRep "id-it-keyPairParamRep"
1064#define NID_id_it_keyPairParamRep 308
1065#define OBJ_id_it_keyPairParamRep OBJ_id_it,11L
1066
1067#define SN_id_it_revPassphrase "id-it-revPassphrase"
1068#define NID_id_it_revPassphrase 309
1069#define OBJ_id_it_revPassphrase OBJ_id_it,12L
1070
1071#define SN_id_it_implicitConfirm "id-it-implicitConfirm"
1072#define NID_id_it_implicitConfirm 310
1073#define OBJ_id_it_implicitConfirm OBJ_id_it,13L
1074
1075#define SN_id_it_confirmWaitTime "id-it-confirmWaitTime"
1076#define NID_id_it_confirmWaitTime 311
1077#define OBJ_id_it_confirmWaitTime OBJ_id_it,14L
1078
1079#define SN_id_it_origPKIMessage "id-it-origPKIMessage"
1080#define NID_id_it_origPKIMessage 312
1081#define OBJ_id_it_origPKIMessage OBJ_id_it,15L
1082
1083#define SN_id_regCtrl "id-regCtrl"
1084#define NID_id_regCtrl 313
1085#define OBJ_id_regCtrl OBJ_id_pkip,1L
1086
1087#define SN_id_regInfo "id-regInfo"
1088#define NID_id_regInfo 314
1089#define OBJ_id_regInfo OBJ_id_pkip,2L
1090
1091#define SN_id_regCtrl_regToken "id-regCtrl-regToken"
1092#define NID_id_regCtrl_regToken 315
1093#define OBJ_id_regCtrl_regToken OBJ_id_regCtrl,1L
1094
1095#define SN_id_regCtrl_authenticator "id-regCtrl-authenticator"
1096#define NID_id_regCtrl_authenticator 316
1097#define OBJ_id_regCtrl_authenticator OBJ_id_regCtrl,2L
1098
1099#define SN_id_regCtrl_pkiPublicationInfo "id-regCtrl-pkiPublicationInfo"
1100#define NID_id_regCtrl_pkiPublicationInfo 317
1101#define OBJ_id_regCtrl_pkiPublicationInfo OBJ_id_regCtrl,3L
1102
1103#define SN_id_regCtrl_pkiArchiveOptions "id-regCtrl-pkiArchiveOptions"
1104#define NID_id_regCtrl_pkiArchiveOptions 318
1105#define OBJ_id_regCtrl_pkiArchiveOptions OBJ_id_regCtrl,4L
1106
1107#define SN_id_regCtrl_oldCertID "id-regCtrl-oldCertID"
1108#define NID_id_regCtrl_oldCertID 319
1109#define OBJ_id_regCtrl_oldCertID OBJ_id_regCtrl,5L
1110
1111#define SN_id_regCtrl_protocolEncrKey "id-regCtrl-protocolEncrKey"
1112#define NID_id_regCtrl_protocolEncrKey 320
1113#define OBJ_id_regCtrl_protocolEncrKey OBJ_id_regCtrl,6L
1114
1115#define SN_id_regInfo_utf8Pairs "id-regInfo-utf8Pairs"
1116#define NID_id_regInfo_utf8Pairs 321
1117#define OBJ_id_regInfo_utf8Pairs OBJ_id_regInfo,1L
1118
1119#define SN_id_regInfo_certReq "id-regInfo-certReq"
1120#define NID_id_regInfo_certReq 322
1121#define OBJ_id_regInfo_certReq OBJ_id_regInfo,2L
1122
1123#define SN_id_alg_des40 "id-alg-des40"
1124#define NID_id_alg_des40 323
1125#define OBJ_id_alg_des40 OBJ_id_alg,1L
1126
1127#define SN_id_alg_noSignature "id-alg-noSignature"
1128#define NID_id_alg_noSignature 324
1129#define OBJ_id_alg_noSignature OBJ_id_alg,2L
1130
1131#define SN_id_alg_dh_sig_hmac_sha1 "id-alg-dh-sig-hmac-sha1"
1132#define NID_id_alg_dh_sig_hmac_sha1 325
1133#define OBJ_id_alg_dh_sig_hmac_sha1 OBJ_id_alg,3L
1134
1135#define SN_id_alg_dh_pop "id-alg-dh-pop"
1136#define NID_id_alg_dh_pop 326
1137#define OBJ_id_alg_dh_pop OBJ_id_alg,4L
1138
1139#define SN_id_cmc_statusInfo "id-cmc-statusInfo"
1140#define NID_id_cmc_statusInfo 327
1141#define OBJ_id_cmc_statusInfo OBJ_id_cmc,1L
1142
1143#define SN_id_cmc_identification "id-cmc-identification"
1144#define NID_id_cmc_identification 328
1145#define OBJ_id_cmc_identification OBJ_id_cmc,2L
1146
1147#define SN_id_cmc_identityProof "id-cmc-identityProof"
1148#define NID_id_cmc_identityProof 329
1149#define OBJ_id_cmc_identityProof OBJ_id_cmc,3L
1150
1151#define SN_id_cmc_dataReturn "id-cmc-dataReturn"
1152#define NID_id_cmc_dataReturn 330
1153#define OBJ_id_cmc_dataReturn OBJ_id_cmc,4L
1154
1155#define SN_id_cmc_transactionId "id-cmc-transactionId"
1156#define NID_id_cmc_transactionId 331
1157#define OBJ_id_cmc_transactionId OBJ_id_cmc,5L
1158
1159#define SN_id_cmc_senderNonce "id-cmc-senderNonce"
1160#define NID_id_cmc_senderNonce 332
1161#define OBJ_id_cmc_senderNonce OBJ_id_cmc,6L
1162
1163#define SN_id_cmc_recipientNonce "id-cmc-recipientNonce"
1164#define NID_id_cmc_recipientNonce 333
1165#define OBJ_id_cmc_recipientNonce OBJ_id_cmc,7L
1166
1167#define SN_id_cmc_addExtensions "id-cmc-addExtensions"
1168#define NID_id_cmc_addExtensions 334
1169#define OBJ_id_cmc_addExtensions OBJ_id_cmc,8L
1170
1171#define SN_id_cmc_encryptedPOP "id-cmc-encryptedPOP"
1172#define NID_id_cmc_encryptedPOP 335
1173#define OBJ_id_cmc_encryptedPOP OBJ_id_cmc,9L
1174
1175#define SN_id_cmc_decryptedPOP "id-cmc-decryptedPOP"
1176#define NID_id_cmc_decryptedPOP 336
1177#define OBJ_id_cmc_decryptedPOP OBJ_id_cmc,10L
1178
1179#define SN_id_cmc_lraPOPWitness "id-cmc-lraPOPWitness"
1180#define NID_id_cmc_lraPOPWitness 337
1181#define OBJ_id_cmc_lraPOPWitness OBJ_id_cmc,11L
1182
1183#define SN_id_cmc_getCert "id-cmc-getCert"
1184#define NID_id_cmc_getCert 338
1185#define OBJ_id_cmc_getCert OBJ_id_cmc,15L
1186
1187#define SN_id_cmc_getCRL "id-cmc-getCRL"
1188#define NID_id_cmc_getCRL 339
1189#define OBJ_id_cmc_getCRL OBJ_id_cmc,16L
1190
1191#define SN_id_cmc_revokeRequest "id-cmc-revokeRequest"
1192#define NID_id_cmc_revokeRequest 340
1193#define OBJ_id_cmc_revokeRequest OBJ_id_cmc,17L
1194
1195#define SN_id_cmc_regInfo "id-cmc-regInfo"
1196#define NID_id_cmc_regInfo 341
1197#define OBJ_id_cmc_regInfo OBJ_id_cmc,18L
1198
1199#define SN_id_cmc_responseInfo "id-cmc-responseInfo"
1200#define NID_id_cmc_responseInfo 342
1201#define OBJ_id_cmc_responseInfo OBJ_id_cmc,19L
1202
1203#define SN_id_cmc_queryPending "id-cmc-queryPending"
1204#define NID_id_cmc_queryPending 343
1205#define OBJ_id_cmc_queryPending OBJ_id_cmc,21L
1206
1207#define SN_id_cmc_popLinkRandom "id-cmc-popLinkRandom"
1208#define NID_id_cmc_popLinkRandom 344
1209#define OBJ_id_cmc_popLinkRandom OBJ_id_cmc,22L
1210
1211#define SN_id_cmc_popLinkWitness "id-cmc-popLinkWitness"
1212#define NID_id_cmc_popLinkWitness 345
1213#define OBJ_id_cmc_popLinkWitness OBJ_id_cmc,23L
1214
1215#define SN_id_cmc_confirmCertAcceptance "id-cmc-confirmCertAcceptance"
1216#define NID_id_cmc_confirmCertAcceptance 346
1217#define OBJ_id_cmc_confirmCertAcceptance OBJ_id_cmc,24L
1218
1219#define SN_id_on_personalData "id-on-personalData"
1220#define NID_id_on_personalData 347
1221#define OBJ_id_on_personalData OBJ_id_on,1L
1222
1223#define SN_id_pda_dateOfBirth "id-pda-dateOfBirth"
1224#define NID_id_pda_dateOfBirth 348
1225#define OBJ_id_pda_dateOfBirth OBJ_id_pda,1L
1226
1227#define SN_id_pda_placeOfBirth "id-pda-placeOfBirth"
1228#define NID_id_pda_placeOfBirth 349
1229#define OBJ_id_pda_placeOfBirth OBJ_id_pda,2L
1230
1231#define SN_id_pda_pseudonym "id-pda-pseudonym"
1232#define NID_id_pda_pseudonym 350
1233#define OBJ_id_pda_pseudonym OBJ_id_pda,3L
1234
1235#define SN_id_pda_gender "id-pda-gender"
1236#define NID_id_pda_gender 351
1237#define OBJ_id_pda_gender OBJ_id_pda,4L
1238
1239#define SN_id_pda_countryOfCitizenship "id-pda-countryOfCitizenship"
1240#define NID_id_pda_countryOfCitizenship 352
1241#define OBJ_id_pda_countryOfCitizenship OBJ_id_pda,5L
1242
1243#define SN_id_pda_countryOfResidence "id-pda-countryOfResidence"
1244#define NID_id_pda_countryOfResidence 353
1245#define OBJ_id_pda_countryOfResidence OBJ_id_pda,6L
1246
1247#define SN_id_aca_authenticationInfo "id-aca-authenticationInfo"
1248#define NID_id_aca_authenticationInfo 354
1249#define OBJ_id_aca_authenticationInfo OBJ_id_aca,1L
1250
1251#define SN_id_aca_accessIdentity "id-aca-accessIdentity"
1252#define NID_id_aca_accessIdentity 355
1253#define OBJ_id_aca_accessIdentity OBJ_id_aca,2L
1254
1255#define SN_id_aca_chargingIdentity "id-aca-chargingIdentity"
1256#define NID_id_aca_chargingIdentity 356
1257#define OBJ_id_aca_chargingIdentity OBJ_id_aca,3L
1258
1259#define SN_id_aca_group "id-aca-group"
1260#define NID_id_aca_group 357
1261#define OBJ_id_aca_group OBJ_id_aca,4L
1262
1263#define SN_id_aca_role "id-aca-role"
1264#define NID_id_aca_role 358
1265#define OBJ_id_aca_role OBJ_id_aca,5L
1266
1267#define SN_id_qcs_pkixQCSyntax_v1 "id-qcs-pkixQCSyntax-v1"
1268#define NID_id_qcs_pkixQCSyntax_v1 359
1269#define OBJ_id_qcs_pkixQCSyntax_v1 OBJ_id_qcs,1L
1270
1271#define SN_id_cct_crs "id-cct-crs"
1272#define NID_id_cct_crs 360
1273#define OBJ_id_cct_crs OBJ_id_cct,1L
1274
1275#define SN_id_cct_PKIData "id-cct-PKIData"
1276#define NID_id_cct_PKIData 361
1277#define OBJ_id_cct_PKIData OBJ_id_cct,2L
1278
1279#define SN_id_cct_PKIResponse "id-cct-PKIResponse"
1280#define NID_id_cct_PKIResponse 362
1281#define OBJ_id_cct_PKIResponse OBJ_id_cct,3L
1282
1283#define SN_ad_OCSP "OCSP"
1284#define LN_ad_OCSP "OCSP"
1285#define NID_ad_OCSP 178
1286#define OBJ_ad_OCSP OBJ_id_ad,1L
1287
1288#define SN_ad_ca_issuers "caIssuers"
1289#define LN_ad_ca_issuers "CA Issuers"
1290#define NID_ad_ca_issuers 179
1291#define OBJ_ad_ca_issuers OBJ_id_ad,2L
1292
1293#define SN_ad_timeStamping "ad_timestamping"
1294#define LN_ad_timeStamping "AD Time Stamping"
1295#define NID_ad_timeStamping 363
1296#define OBJ_ad_timeStamping OBJ_id_ad,3L
1297
1298#define SN_ad_dvcs "AD_DVCS"
1299#define LN_ad_dvcs "ad dvcs"
1300#define NID_ad_dvcs 364
1301#define OBJ_ad_dvcs OBJ_id_ad,4L
1302
1303#define OBJ_id_pkix_OCSP OBJ_ad_OCSP
1304
1305#define SN_id_pkix_OCSP_basic "basicOCSPResponse"
1306#define LN_id_pkix_OCSP_basic "Basic OCSP Response"
1307#define NID_id_pkix_OCSP_basic 365
1308#define OBJ_id_pkix_OCSP_basic OBJ_id_pkix_OCSP,1L
1309
1310#define SN_id_pkix_OCSP_Nonce "Nonce"
1311#define LN_id_pkix_OCSP_Nonce "OCSP Nonce"
1312#define NID_id_pkix_OCSP_Nonce 366
1313#define OBJ_id_pkix_OCSP_Nonce OBJ_id_pkix_OCSP,2L
1314
1315#define SN_id_pkix_OCSP_CrlID "CrlID"
1316#define LN_id_pkix_OCSP_CrlID "OCSP CRL ID"
1317#define NID_id_pkix_OCSP_CrlID 367
1318#define OBJ_id_pkix_OCSP_CrlID OBJ_id_pkix_OCSP,3L
1319
1320#define SN_id_pkix_OCSP_acceptableResponses "acceptableResponses"
1321#define LN_id_pkix_OCSP_acceptableResponses "Acceptable OCSP Responses"
1322#define NID_id_pkix_OCSP_acceptableResponses 368
1323#define OBJ_id_pkix_OCSP_acceptableResponses OBJ_id_pkix_OCSP,4L
1324
1325#define SN_id_pkix_OCSP_noCheck "noCheck"
1326#define NID_id_pkix_OCSP_noCheck 369
1327#define OBJ_id_pkix_OCSP_noCheck OBJ_id_pkix_OCSP,5L
1328
1329#define SN_id_pkix_OCSP_archiveCutoff "archiveCutoff"
1330#define LN_id_pkix_OCSP_archiveCutoff "OCSP Archive Cutoff"
1331#define NID_id_pkix_OCSP_archiveCutoff 370
1332#define OBJ_id_pkix_OCSP_archiveCutoff OBJ_id_pkix_OCSP,6L
1333
1334#define SN_id_pkix_OCSP_serviceLocator "serviceLocator"
1335#define LN_id_pkix_OCSP_serviceLocator "OCSP Service Locator"
1336#define NID_id_pkix_OCSP_serviceLocator 371
1337#define OBJ_id_pkix_OCSP_serviceLocator OBJ_id_pkix_OCSP,7L
1338
1339#define SN_id_pkix_OCSP_extendedStatus "extendedStatus"
1340#define LN_id_pkix_OCSP_extendedStatus "Extended OCSP Status"
1341#define NID_id_pkix_OCSP_extendedStatus 372
1342#define OBJ_id_pkix_OCSP_extendedStatus OBJ_id_pkix_OCSP,8L
1343
1344#define SN_id_pkix_OCSP_valid "valid"
1345#define NID_id_pkix_OCSP_valid 373
1346#define OBJ_id_pkix_OCSP_valid OBJ_id_pkix_OCSP,9L
1347
1348#define SN_id_pkix_OCSP_path "path"
1349#define NID_id_pkix_OCSP_path 374
1350#define OBJ_id_pkix_OCSP_path OBJ_id_pkix_OCSP,10L
1351
1352#define SN_id_pkix_OCSP_trustRoot "trustRoot"
1353#define LN_id_pkix_OCSP_trustRoot "Trust Root"
1354#define NID_id_pkix_OCSP_trustRoot 375
1355#define OBJ_id_pkix_OCSP_trustRoot OBJ_id_pkix_OCSP,11L
1356
1357#define SN_algorithm "algorithm"
1358#define LN_algorithm "algorithm"
1359#define NID_algorithm 376
1360#define OBJ_algorithm 1L,3L,14L,3L,2L
1361
1362#define SN_md5WithRSA "RSA-NP-MD5"
1363#define LN_md5WithRSA "md5WithRSA"
1364#define NID_md5WithRSA 104
1365#define OBJ_md5WithRSA OBJ_algorithm,3L
1366
1367#define SN_des_ecb "DES-ECB"
1368#define LN_des_ecb "des-ecb"
1369#define NID_des_ecb 29
1370#define OBJ_des_ecb OBJ_algorithm,6L
1371
1372#define SN_des_cbc "DES-CBC"
1373#define LN_des_cbc "des-cbc"
1374#define NID_des_cbc 31
1375#define OBJ_des_cbc OBJ_algorithm,7L
1376
1377#define SN_des_ofb64 "DES-OFB"
1378#define LN_des_ofb64 "des-ofb"
1379#define NID_des_ofb64 45
1380#define OBJ_des_ofb64 OBJ_algorithm,8L
1381
1382#define SN_des_cfb64 "DES-CFB"
1383#define LN_des_cfb64 "des-cfb"
1384#define NID_des_cfb64 30
1385#define OBJ_des_cfb64 OBJ_algorithm,9L
1386
1387#define SN_rsaSignature "rsaSignature"
1388#define NID_rsaSignature 377
1389#define OBJ_rsaSignature OBJ_algorithm,11L
1390
1391#define SN_dsa_2 "DSA-old"
1392#define LN_dsa_2 "dsaEncryption-old"
1393#define NID_dsa_2 67
1394#define OBJ_dsa_2 OBJ_algorithm,12L
1395
1396#define SN_dsaWithSHA "DSA-SHA"
1397#define LN_dsaWithSHA "dsaWithSHA"
1398#define NID_dsaWithSHA 66
1399#define OBJ_dsaWithSHA OBJ_algorithm,13L
1400
1401#define SN_shaWithRSAEncryption "RSA-SHA"
1402#define LN_shaWithRSAEncryption "shaWithRSAEncryption"
1403#define NID_shaWithRSAEncryption 42
1404#define OBJ_shaWithRSAEncryption OBJ_algorithm,15L
1405
1406#define SN_des_ede "DES-EDE"
1407#define LN_des_ede "des-ede"
1408#define NID_des_ede 32
1409#define OBJ_des_ede OBJ_algorithm,17L
1410
1411#define SN_des_ede3 "DES-EDE3"
1412#define LN_des_ede3 "des-ede3"
1413#define NID_des_ede3 33
1414
1415#define SN_des_ede_cbc "DES-EDE-CBC"
1416#define LN_des_ede_cbc "des-ede-cbc"
1417#define NID_des_ede_cbc 43
1418
1419#define SN_des_ede_cfb64 "DES-EDE-CFB"
1420#define LN_des_ede_cfb64 "des-ede-cfb"
1421#define NID_des_ede_cfb64 60
1422
1423#define SN_des_ede3_cfb64 "DES-EDE3-CFB"
1424#define LN_des_ede3_cfb64 "des-ede3-cfb"
1425#define NID_des_ede3_cfb64 61
1426
1427#define SN_des_ede_ofb64 "DES-EDE-OFB"
1428#define LN_des_ede_ofb64 "des-ede-ofb"
1429#define NID_des_ede_ofb64 62
1430
1431#define SN_des_ede3_ofb64 "DES-EDE3-OFB"
1432#define LN_des_ede3_ofb64 "des-ede3-ofb"
1433#define NID_des_ede3_ofb64 63
1434
1435#define SN_desx_cbc "DESX-CBC"
1436#define LN_desx_cbc "desx-cbc"
1437#define NID_desx_cbc 80
1438
1439#define SN_sha "SHA"
1440#define LN_sha "sha"
1441#define NID_sha 41
1442#define OBJ_sha OBJ_algorithm,18L
1443
1444#define SN_sha1 "SHA1"
1445#define LN_sha1 "sha1"
1446#define NID_sha1 64
1447#define OBJ_sha1 OBJ_algorithm,26L
1448
1449#define SN_dsaWithSHA1_2 "DSA-SHA1-old"
1450#define LN_dsaWithSHA1_2 "dsaWithSHA1-old"
1451#define NID_dsaWithSHA1_2 70
1452#define OBJ_dsaWithSHA1_2 OBJ_algorithm,27L
1453
1454#define SN_sha1WithRSA "RSA-SHA1-2"
1455#define LN_sha1WithRSA "sha1WithRSA"
1456#define NID_sha1WithRSA 115
1457#define OBJ_sha1WithRSA OBJ_algorithm,29L
1458
1459#define SN_ripemd160 "RIPEMD160"
1460#define LN_ripemd160 "ripemd160"
1461#define NID_ripemd160 117
1462#define OBJ_ripemd160 1L,3L,36L,3L,2L,1L
1463
1464#define SN_ripemd160WithRSA "RSA-RIPEMD160"
1465#define LN_ripemd160WithRSA "ripemd160WithRSA"
1466#define NID_ripemd160WithRSA 119
1467#define OBJ_ripemd160WithRSA 1L,3L,36L,3L,3L,1L,2L
1468
1469#define SN_sxnet "SXNetID"
1470#define LN_sxnet "Strong Extranet ID"
1471#define NID_sxnet 143
1472#define OBJ_sxnet 1L,3L,101L,1L,4L,1L
1473
1474#define SN_X500 "X500"
1475#define LN_X500 "directory services (X.500)"
1476#define NID_X500 11
1477#define OBJ_X500 2L,5L
1478
1479#define SN_X509 "X509"
1480#define NID_X509 12
1481#define OBJ_X509 OBJ_X500,4L
1482
1483#define SN_commonName "CN"
1484#define LN_commonName "commonName"
1485#define NID_commonName 13
1486#define OBJ_commonName OBJ_X509,3L
1487
1488#define SN_surname "S"
1489#define LN_surname "surname"
1490#define NID_surname 100
1491#define OBJ_surname OBJ_X509,4L
1492
1493#define SN_serialNumber "SN"
1494#define LN_serialNumber "serialNumber"
1495#define NID_serialNumber 105
1496#define OBJ_serialNumber OBJ_X509,5L
1497
1498#define SN_countryName "C"
1499#define LN_countryName "countryName"
1500#define NID_countryName 14
1501#define OBJ_countryName OBJ_X509,6L
1502
1503#define SN_localityName "L"
1504#define LN_localityName "localityName"
1505#define NID_localityName 15
1506#define OBJ_localityName OBJ_X509,7L
1507
1508#define SN_stateOrProvinceName "ST"
1509#define LN_stateOrProvinceName "stateOrProvinceName"
1510#define NID_stateOrProvinceName 16
1511#define OBJ_stateOrProvinceName OBJ_X509,8L
1512
1513#define SN_organizationName "O"
1514#define LN_organizationName "organizationName"
1515#define NID_organizationName 17
1516#define OBJ_organizationName OBJ_X509,10L
1517
1518#define SN_organizationalUnitName "OU"
1519#define LN_organizationalUnitName "organizationalUnitName"
1520#define NID_organizationalUnitName 18
1521#define OBJ_organizationalUnitName OBJ_X509,11L
1522
1523#define SN_title "T"
1524#define LN_title "title"
1525#define NID_title 106
1526#define OBJ_title OBJ_X509,12L
1527
1528#define SN_description "D"
1529#define LN_description "description"
1530#define NID_description 107
1531#define OBJ_description OBJ_X509,13L
1532
1533#define SN_name "name"
1534#define LN_name "name"
1535#define NID_name 173
1536#define OBJ_name OBJ_X509,41L
1537
1538#define SN_givenName "G"
1539#define LN_givenName "givenName"
1540#define NID_givenName 99
1541#define OBJ_givenName OBJ_X509,42L
1542
1543#define SN_initials "I"
1544#define LN_initials "initials"
1545#define NID_initials 101
1546#define OBJ_initials OBJ_X509,43L
1547
1548#define SN_uniqueIdentifier "UID"
1549#define LN_uniqueIdentifier "uniqueIdentifier"
1550#define NID_uniqueIdentifier 102
1551#define OBJ_uniqueIdentifier OBJ_X509,45L
1552
1553#define SN_dnQualifier "dnQualifier"
1554#define LN_dnQualifier "dnQualifier"
1555#define NID_dnQualifier 174
1556#define OBJ_dnQualifier OBJ_X509,46L
1557
1558#define SN_X500algorithms "X500algorithms"
1559#define LN_X500algorithms "directory services - algorithms"
1560#define NID_X500algorithms 378
1561#define OBJ_X500algorithms OBJ_X500,8L
1562
1563#define SN_rsa "RSA"
1564#define LN_rsa "rsa"
1565#define NID_rsa 19
1566#define OBJ_rsa OBJ_X500algorithms,1L,1L
1567
1568#define SN_mdc2WithRSA "RSA-MDC2"
1569#define LN_mdc2WithRSA "mdc2WithRSA"
1570#define NID_mdc2WithRSA 96
1571#define OBJ_mdc2WithRSA OBJ_X500algorithms,3L,100L
1572
1573#define SN_mdc2 "MDC2"
1574#define LN_mdc2 "mdc2"
1575#define NID_mdc2 95
1576#define OBJ_mdc2 OBJ_X500algorithms,3L,101L
1577
1578#define SN_id_ce "id-ce"
1579#define NID_id_ce 81
1580#define OBJ_id_ce OBJ_X500,29L
1581
1582#define SN_subject_key_identifier "subjectKeyIdentifier"
1583#define LN_subject_key_identifier "X509v3 Subject Key Identifier"
1584#define NID_subject_key_identifier 82
1585#define OBJ_subject_key_identifier OBJ_id_ce,14L
1586
1587#define SN_key_usage "keyUsage"
1588#define LN_key_usage "X509v3 Key Usage"
1589#define NID_key_usage 83
1590#define OBJ_key_usage OBJ_id_ce,15L
1591
1592#define SN_private_key_usage_period "privateKeyUsagePeriod"
1593#define LN_private_key_usage_period "X509v3 Private Key Usage Period"
1594#define NID_private_key_usage_period 84
1595#define OBJ_private_key_usage_period OBJ_id_ce,16L
1596
1597#define SN_subject_alt_name "subjectAltName"
1598#define LN_subject_alt_name "X509v3 Subject Alternative Name"
1599#define NID_subject_alt_name 85
1600#define OBJ_subject_alt_name OBJ_id_ce,17L
1601
1602#define SN_issuer_alt_name "issuerAltName"
1603#define LN_issuer_alt_name "X509v3 Issuer Alternative Name"
1604#define NID_issuer_alt_name 86
1605#define OBJ_issuer_alt_name OBJ_id_ce,18L
1606
1607#define SN_basic_constraints "basicConstraints"
1608#define LN_basic_constraints "X509v3 Basic Constraints"
1609#define NID_basic_constraints 87
1610#define OBJ_basic_constraints OBJ_id_ce,19L
1611
1612#define SN_crl_number "crlNumber"
1613#define LN_crl_number "X509v3 CRL Number"
1614#define NID_crl_number 88
1615#define OBJ_crl_number OBJ_id_ce,20L
1616
1617#define SN_crl_reason "CRLReason"
1618#define LN_crl_reason "X509v3 CRL Reason Code"
1619#define NID_crl_reason 141
1620#define OBJ_crl_reason OBJ_id_ce,21L
1621
1622#define SN_invalidity_date "invalidityDate"
1623#define LN_invalidity_date "Invalidity Date"
1624#define NID_invalidity_date 142
1625#define OBJ_invalidity_date OBJ_id_ce,24L
1626
1627#define SN_delta_crl "deltaCRL"
1628#define LN_delta_crl "X509v3 Delta CRL Indicator"
1629#define NID_delta_crl 140
1630#define OBJ_delta_crl OBJ_id_ce,27L
1631
1632#define SN_crl_distribution_points "crlDistributionPoints"
1633#define LN_crl_distribution_points "X509v3 CRL Distribution Points"
1634#define NID_crl_distribution_points 103
1635#define OBJ_crl_distribution_points OBJ_id_ce,31L
1636
1637#define SN_certificate_policies "certificatePolicies"
1638#define LN_certificate_policies "X509v3 Certificate Policies"
1639#define NID_certificate_policies 89
1640#define OBJ_certificate_policies OBJ_id_ce,32L
1641
1642#define SN_authority_key_identifier "authorityKeyIdentifier"
1643#define LN_authority_key_identifier "X509v3 Authority Key Identifier"
1644#define NID_authority_key_identifier 90
1645#define OBJ_authority_key_identifier OBJ_id_ce,35L
1646
1647#define SN_ext_key_usage "extendedKeyUsage"
1648#define LN_ext_key_usage "X509v3 Extended Key Usage"
1649#define NID_ext_key_usage 126
1650#define OBJ_ext_key_usage OBJ_id_ce,37L
1651
1652#define SN_netscape "Netscape"
1653#define LN_netscape "Netscape Communications Corp."
1654#define NID_netscape 57
1655#define OBJ_netscape 2L,16L,840L,1L,113730L
1656
1657#define SN_netscape_cert_extension "nsCertExt"
1658#define LN_netscape_cert_extension "Netscape Certificate Extension"
1659#define NID_netscape_cert_extension 58
1660#define OBJ_netscape_cert_extension OBJ_netscape,1L
1661
1662#define SN_netscape_data_type "nsDataType"
1663#define LN_netscape_data_type "Netscape Data Type"
1664#define NID_netscape_data_type 59
1665#define OBJ_netscape_data_type OBJ_netscape,2L
1666
1667#define SN_netscape_cert_type "nsCertType"
1668#define LN_netscape_cert_type "Netscape Cert Type"
1669#define NID_netscape_cert_type 71
1670#define OBJ_netscape_cert_type OBJ_netscape_cert_extension,1L
1671
1672#define SN_netscape_base_url "nsBaseUrl"
1673#define LN_netscape_base_url "Netscape Base Url"
1674#define NID_netscape_base_url 72
1675#define OBJ_netscape_base_url OBJ_netscape_cert_extension,2L
1676
1677#define SN_netscape_revocation_url "nsRevocationUrl"
1678#define LN_netscape_revocation_url "Netscape Revocation Url"
1679#define NID_netscape_revocation_url 73
1680#define OBJ_netscape_revocation_url OBJ_netscape_cert_extension,3L
1681
1682#define SN_netscape_ca_revocation_url "nsCaRevocationUrl"
1683#define LN_netscape_ca_revocation_url "Netscape CA Revocation Url"
1684#define NID_netscape_ca_revocation_url 74
1685#define OBJ_netscape_ca_revocation_url OBJ_netscape_cert_extension,4L
1686
1687#define SN_netscape_renewal_url "nsRenewalUrl"
1688#define LN_netscape_renewal_url "Netscape Renewal Url"
1689#define NID_netscape_renewal_url 75
1690#define OBJ_netscape_renewal_url OBJ_netscape_cert_extension,7L
1691
1692#define SN_netscape_ca_policy_url "nsCaPolicyUrl"
1693#define LN_netscape_ca_policy_url "Netscape CA Policy Url"
1694#define NID_netscape_ca_policy_url 76
1695#define OBJ_netscape_ca_policy_url OBJ_netscape_cert_extension,8L
1696
1697#define SN_netscape_ssl_server_name "nsSslServerName"
1698#define LN_netscape_ssl_server_name "Netscape SSL Server Name"
1699#define NID_netscape_ssl_server_name 77
1700#define OBJ_netscape_ssl_server_name OBJ_netscape_cert_extension,12L
1701
1702#define SN_netscape_comment "nsComment"
1703#define LN_netscape_comment "Netscape Comment"
1704#define NID_netscape_comment 78
1705#define OBJ_netscape_comment OBJ_netscape_cert_extension,13L
1706
1707#define SN_netscape_cert_sequence "nsCertSequence"
1708#define LN_netscape_cert_sequence "Netscape Certificate Sequence"
1709#define NID_netscape_cert_sequence 79
1710#define OBJ_netscape_cert_sequence OBJ_netscape_data_type,5L
1711
1712#define SN_ns_sgc "nsSGC"
1713#define LN_ns_sgc "Netscape Server Gated Crypto"
1714#define NID_ns_sgc 139
1715#define OBJ_ns_sgc OBJ_netscape,4L,1L
1716
1717#define SN_org "ORG"
1718#define LN_org "org"
1719#define NID_org 379
1720#define OBJ_org OBJ_iso,3L
1721
1722#define SN_dod "DOD"
1723#define LN_dod "dod"
1724#define NID_dod 380
1725#define OBJ_dod OBJ_org,6L
1726
1727#define SN_iana "IANA"
1728#define LN_iana "iana"
1729#define NID_iana 381
1730#define OBJ_iana OBJ_dod,1L
1731
1732#define OBJ_internet OBJ_iana
1733
1734#define SN_Directory "directory"
1735#define LN_Directory "Directory"
1736#define NID_Directory 382
1737#define OBJ_Directory OBJ_internet,1L
1738
1739#define SN_Management "mgmt"
1740#define LN_Management "Management"
1741#define NID_Management 383
1742#define OBJ_Management OBJ_internet,2L
1743
1744#define SN_Experimental "experimental"
1745#define LN_Experimental "Experimental"
1746#define NID_Experimental 384
1747#define OBJ_Experimental OBJ_internet,3L
1748
1749#define SN_Private "private"
1750#define LN_Private "Private"
1751#define NID_Private 385
1752#define OBJ_Private OBJ_internet,4L
1753
1754#define SN_Security "security"
1755#define LN_Security "Security"
1756#define NID_Security 386
1757#define OBJ_Security OBJ_internet,5L
1758
1759#define SN_SNMPv2 "snmpv2"
1760#define LN_SNMPv2 "SNMPv2"
1761#define NID_SNMPv2 387
1762#define OBJ_SNMPv2 OBJ_internet,6L
1763
1764#define SN_Mail "mail"
1765#define LN_Mail "Mail"
1766#define NID_Mail 388
1767#define OBJ_Mail OBJ_internet,7L
1768
1769#define SN_Enterprises "enterprises"
1770#define LN_Enterprises "Enterprises"
1771#define NID_Enterprises 389
1772#define OBJ_Enterprises OBJ_private,1L
1773
1774#define SN_dcObject "dcobject"
1775#define LN_dcObject "dcObject"
1776#define NID_dcObject 390
1777#define OBJ_dcObject OBJ_enterprises,1466L,344L
1778
1779#define SN_domainComponent "DC"
1780#define LN_domainComponent "domainComponent"
1781#define NID_domainComponent 391
1782#define OBJ_domainComponent 0L,9L,2342L,19200300L,100L,1L,25L
1783
1784#define SN_Domain "domain"
1785#define LN_Domain "Domain"
1786#define NID_Domain 392
1787#define OBJ_Domain 0L,9L,2342L,19200300L,100L,4L,13L
1788
1789#define SN_rle_compression "RLE"
1790#define LN_rle_compression "run length compression"
1791#define NID_rle_compression 124
1792#define OBJ_rle_compression 1L,1L,1L,1L,666L,1L
1793
1794#define SN_zlib_compression "ZLIB"
1795#define LN_zlib_compression "zlib compression"
1796#define NID_zlib_compression 125
1797#define OBJ_zlib_compression 1L,1L,1L,1L,666L,2L
1798
diff --git a/src/lib/libcrypto/opensslconf.h.in b/src/lib/libcrypto/opensslconf.h.in
new file mode 100644
index 0000000000..e4a8f8ad54
--- /dev/null
+++ b/src/lib/libcrypto/opensslconf.h.in
@@ -0,0 +1,142 @@
1/* crypto/opensslconf.h */
2/* WARNING: This file is autogenerated by Configure */
3
4/* Generate 80386 code? */
5#undef I386_ONLY
6
7#if !(defined(VMS) || defined(__VMS)) /* VMS uses logical names instead */
8#if defined(HEADER_CRYPTLIB_H) && !defined(OPENSSLDIR)
9#define OPENSSLDIR "/usr/local/ssl"
10#endif
11#endif
12
13#define OPENSSL_UNISTD <unistd.h>
14
15#if defined(HEADER_IDEA_H) && !defined(IDEA_INT)
16#define IDEA_INT unsigned int
17#endif
18
19#if defined(HEADER_MD2_H) && !defined(MD2_INT)
20#define MD2_INT unsigned int
21#endif
22
23#if defined(HEADER_RC2_H) && !defined(RC2_INT)
24/* I need to put in a mod for the alpha - eay */
25#define RC2_INT unsigned int
26#endif
27
28#if defined(HEADER_RC4_H) && !defined(RC4_INT)
29/* using int types make the structure larger but make the code faster
30 * on most boxes I have tested - up to %20 faster. */
31#define RC4_INT unsigned int
32#endif
33
34#if defined(HEADER_DES_H) && !defined(DES_LONG)
35/* If this is set to 'unsigned int' on a DEC Alpha, this gives about a
36 * %20 speed up (longs are 8 bytes, int's are 4). */
37#ifndef DES_LONG
38#define DES_LONG unsigned long
39#endif
40#endif
41
42#if defined(HEADER_BN_H) && !defined(CONFIG_HEADER_BN_H)
43#define CONFIG_HEADER_BN_H
44#undef BN_LLONG
45
46/* Should we define BN_DIV2W here? */
47
48/* Only one for the following should be defined */
49/* The prime number generation stuff may not work when
50 * EIGHT_BIT but I don't care since I've only used this mode
51 * for debuging the bignum libraries */
52#undef SIXTY_FOUR_BIT_LONG
53#undef SIXTY_FOUR_BIT
54#define THIRTY_TWO_BIT
55#undef SIXTEEN_BIT
56#undef EIGHT_BIT
57#endif
58
59#if defined(HEADER_RC4_LOCL_H) && !defined(CONFIG_HEADER_RC4_LOCL_H)
60#define CONFIG_HEADER_RC4_LOCL_H
61/* if this is defined data[i] is used instead of *data, this is a %20
62 * speedup on x86 */
63#undef RC4_INDEX
64#endif
65
66#if defined(HEADER_BF_LOCL_H) && !defined(CONFIG_HEADER_BF_LOCL_H)
67#define CONFIG_HEADER_BF_LOCL_H
68#undef BF_PTR
69#endif /* HEADER_BF_LOCL_H */
70
71#if defined(HEADER_DES_LOCL_H) && !defined(CONFIG_HEADER_DES_LOCL_H)
72#define CONFIG_HEADER_DES_LOCL_H
73#ifndef DES_DEFAULT_OPTIONS
74/* the following is tweaked from a config script, that is why it is a
75 * protected undef/define */
76#ifndef DES_PTR
77#undef DES_PTR
78#endif
79
80/* This helps C compiler generate the correct code for multiple functional
81 * units. It reduces register dependancies at the expense of 2 more
82 * registers */
83#ifndef DES_RISC1
84#undef DES_RISC1
85#endif
86
87#ifndef DES_RISC2
88#undef DES_RISC2
89#endif
90
91#if defined(DES_RISC1) && defined(DES_RISC2)
92YOU SHOULD NOT HAVE BOTH DES_RISC1 AND DES_RISC2 DEFINED!!!!!
93#endif
94
95/* Unroll the inner loop, this sometimes helps, sometimes hinders.
96 * Very mucy CPU dependant */
97#ifndef DES_UNROLL
98#undef DES_UNROLL
99#endif
100
101/* These default values were supplied by
102 * Peter Gutman <pgut001@cs.auckland.ac.nz>
103 * They are only used if nothing else has been defined */
104#if !defined(DES_PTR) && !defined(DES_RISC1) && !defined(DES_RISC2) && !defined(DES_UNROLL)
105/* Special defines which change the way the code is built depending on the
106 CPU and OS. For SGI machines you can use _MIPS_SZLONG (32 or 64) to find
107 even newer MIPS CPU's, but at the moment one size fits all for
108 optimization options. Older Sparc's work better with only UNROLL, but
109 there's no way to tell at compile time what it is you're running on */
110
111#if defined( sun ) /* Newer Sparc's */
112# define DES_PTR
113# define DES_RISC1
114# define DES_UNROLL
115#elif defined( __ultrix ) /* Older MIPS */
116# define DES_PTR
117# define DES_RISC2
118# define DES_UNROLL
119#elif defined( __osf1__ ) /* Alpha */
120# define DES_PTR
121# define DES_RISC2
122#elif defined ( _AIX ) /* RS6000 */
123 /* Unknown */
124#elif defined( __hpux ) /* HP-PA */
125 /* Unknown */
126#elif defined( __aux ) /* 68K */
127 /* Unknown */
128#elif defined( __dgux ) /* 88K (but P6 in latest boxes) */
129# define DES_UNROLL
130#elif defined( __sgi ) /* Newer MIPS */
131# define DES_PTR
132# define DES_RISC2
133# define DES_UNROLL
134#elif defined( i386 ) /* x86 boxes, should be gcc */
135# define DES_PTR
136# define DES_RISC1
137# define DES_UNROLL
138#endif /* Systems-specific speed defines */
139#endif
140
141#endif /* DES_DEFAULT_OPTIONS */
142#endif /* HEADER_DES_LOCL_H */
diff --git a/src/lib/libcrypto/perlasm/alpha.pl b/src/lib/libcrypto/perlasm/alpha.pl
new file mode 100644
index 0000000000..3dac571743
--- /dev/null
+++ b/src/lib/libcrypto/perlasm/alpha.pl
@@ -0,0 +1,434 @@
1#!/usr/local/bin/perl
2
3package alpha;
4use Carp qw(croak cluck);
5
6$label="100";
7
8$n_debug=0;
9$smear_regs=1;
10$reg_alloc=1;
11
12$align="3";
13$com_start="#";
14
15sub main'asm_init_output { @out=(); }
16sub main'asm_get_output { return(@out); }
17sub main'get_labels { return(@labels); }
18sub main'external_label { push(@labels,@_); }
19
20# General registers
21
22%regs=( 'r0', '$0',
23 'r1', '$1',
24 'r2', '$2',
25 'r3', '$3',
26 'r4', '$4',
27 'r5', '$5',
28 'r6', '$6',
29 'r7', '$7',
30 'r8', '$8',
31 'r9', '$22',
32 'r10', '$23',
33 'r11', '$24',
34 'r12', '$25',
35 'r13', '$27',
36 'r14', '$28',
37 'r15', '$21', # argc == 5
38 'r16', '$20', # argc == 4
39 'r17', '$19', # argc == 3
40 'r18', '$18', # argc == 2
41 'r19', '$17', # argc == 1
42 'r20', '$16', # argc == 0
43 'r21', '$9', # save 0
44 'r22', '$10', # save 1
45 'r23', '$11', # save 2
46 'r24', '$12', # save 3
47 'r25', '$13', # save 4
48 'r26', '$14', # save 5
49
50 'a0', '$16',
51 'a1', '$17',
52 'a2', '$18',
53 'a3', '$19',
54 'a4', '$20',
55 'a5', '$21',
56
57 's0', '$9',
58 's1', '$10',
59 's2', '$11',
60 's3', '$12',
61 's4', '$13',
62 's5', '$14',
63 'zero', '$31',
64 'sp', '$30',
65 );
66
67$main'reg_s0="r21";
68$main'reg_s1="r22";
69$main'reg_s2="r23";
70$main'reg_s3="r24";
71$main'reg_s4="r25";
72$main'reg_s5="r26";
73
74@reg=( '$0', '$1' ,'$2' ,'$3' ,'$4' ,'$5' ,'$6' ,'$7' ,'$8',
75 '$22','$23','$24','$25','$20','$21','$27','$28');
76
77
78sub main'sub { &out3("subq",@_); }
79sub main'add { &out3("addq",@_); }
80sub main'mov { &out3("bis",$_[0],$_[0],$_[1]); }
81sub main'or { &out3("bis",@_); }
82sub main'bis { &out3("bis",@_); }
83sub main'br { &out1("br",@_); }
84sub main'ld { &out2("ldq",@_); }
85sub main'st { &out2("stq",@_); }
86sub main'cmpult { &out3("cmpult",@_); }
87sub main'cmplt { &out3("cmplt",@_); }
88sub main'bgt { &out2("bgt",@_); }
89sub main'ble { &out2("ble",@_); }
90sub main'blt { &out2("blt",@_); }
91sub main'mul { &out3("mulq",@_); }
92sub main'muh { &out3("umulh",@_); }
93
94$main'QWS=8;
95
96sub main'asm_add
97 {
98 push(@out,@_);
99 }
100
101sub main'asm_finish
102 {
103 &main'file_end();
104 print &main'asm_get_output();
105 }
106
107sub main'asm_init
108 {
109 ($type,$fn)=@_;
110 $filename=$fn;
111
112 &main'asm_init_output();
113 &main'comment("Don't even think of reading this code");
114 &main'comment("It was automatically generated by $filename");
115 &main'comment("Which is a perl program used to generate the alpha assember.");
116 &main'comment("eric <eay\@cryptsoft.com>");
117 &main'comment("");
118
119 $filename =~ s/\.pl$//;
120 &main'file($filename);
121 }
122
123sub conv
124 {
125 local($r)=@_;
126 local($v);
127
128 return($regs{$r}) if defined($regs{$r});
129 return($r);
130 }
131
132sub main'QWPw
133 {
134 local($off,$reg)=@_;
135
136 return(&main'QWP($off*8,$reg));
137 }
138
139sub main'QWP
140 {
141 local($off,$reg)=@_;
142
143 $ret="$off(".&conv($reg).")";
144 return($ret);
145 }
146
147sub out3
148 {
149 local($name,$p1,$p2,$p3)=@_;
150
151 $p1=&conv($p1);
152 $p2=&conv($p2);
153 $p3=&conv($p3);
154 push(@out,"\t$name\t");
155 $l=length($p1)+1;
156 push(@out,$p1.",");
157 $ll=3-($l+9)/8;
158 $tmp1=sprintf("\t" x $ll);
159 push(@out,$tmp1);
160
161 $l=length($p2)+1;
162 push(@out,$p2.",");
163 $ll=3-($l+9)/8;
164 $tmp1=sprintf("\t" x $ll);
165 push(@out,$tmp1);
166
167 push(@out,&conv($p3)."\n");
168 }
169
170sub out2
171 {
172 local($name,$p1,$p2,$p3)=@_;
173
174 $p1=&conv($p1);
175 $p2=&conv($p2);
176 push(@out,"\t$name\t");
177 $l=length($p1)+1;
178 push(@out,$p1.",");
179 $ll=3-($l+9)/8;
180 $tmp1=sprintf("\t" x $ll);
181 push(@out,$tmp1);
182
183 push(@out,&conv($p2)."\n");
184 }
185
186sub out1
187 {
188 local($name,$p1)=@_;
189
190 $p1=&conv($p1);
191 push(@out,"\t$name\t".$p1."\n");
192 }
193
194sub out0
195 {
196 push(@out,"\t$_[0]\n");
197 }
198
199sub main'file
200 {
201 local($file)=@_;
202
203 local($tmp)=<<"EOF";
204 # DEC Alpha assember
205 # Generated from perl scripts contains in SSLeay
206 .file 1 "$file.s"
207 .set noat
208EOF
209 push(@out,$tmp);
210 }
211
212sub main'function_begin
213 {
214 local($func)=@_;
215
216print STDERR "$func\n";
217 local($tmp)=<<"EOF";
218 .text
219 .align $align
220 .globl $func
221 .ent $func
222${func}:
223${func}..ng:
224 .frame \$30,0,\$26,0
225 .prologue 0
226EOF
227 push(@out,$tmp);
228 $stack=0;
229 }
230
231sub main'function_end
232 {
233 local($func)=@_;
234
235 local($tmp)=<<"EOF";
236 ret \$31,(\$26),1
237 .end $func
238EOF
239 push(@out,$tmp);
240 $stack=0;
241 %label=();
242 }
243
244sub main'function_end_A
245 {
246 local($func)=@_;
247
248 local($tmp)=<<"EOF";
249 ret \$31,(\$26),1
250EOF
251 push(@out,$tmp);
252 }
253
254sub main'function_end_B
255 {
256 local($func)=@_;
257
258 $func=$under.$func;
259
260 push(@out,"\t.end $func\n");
261 $stack=0;
262 %label=();
263 }
264
265sub main'wparam
266 {
267 local($num)=@_;
268
269 if ($num < 6)
270 {
271 $num=20-$num;
272 return("r$num");
273 }
274 else
275 { return(&main'QWP($stack+$num*8,"sp")); }
276 }
277
278sub main'stack_push
279 {
280 local($num)=@_;
281 $stack+=$num*8;
282 &main'sub("sp",$num*8,"sp");
283 }
284
285sub main'stack_pop
286 {
287 local($num)=@_;
288 $stack-=$num*8;
289 &main'add("sp",$num*8,"sp");
290 }
291
292sub main'swtmp
293 {
294 return(&main'QWP(($_[0])*8,"sp"));
295 }
296
297# Should use swtmp, which is above sp. Linix can trash the stack above esp
298#sub main'wtmp
299# {
300# local($num)=@_;
301#
302# return(&main'QWP(-($num+1)*4,"esp","",0));
303# }
304
305sub main'comment
306 {
307 foreach (@_)
308 {
309 if (/^\s*$/)
310 { push(@out,"\n"); }
311 else
312 { push(@out,"\t$com_start $_ $com_end\n"); }
313 }
314 }
315
316sub main'label
317 {
318 if (!defined($label{$_[0]}))
319 {
320 $label{$_[0]}=$label;
321 $label++;
322 }
323 return('$'.$label{$_[0]});
324 }
325
326sub main'set_label
327 {
328 if (!defined($label{$_[0]}))
329 {
330 $label{$_[0]}=$label;
331 $label++;
332 }
333# push(@out,".align $align\n") if ($_[1] != 0);
334 push(@out,'$'."$label{$_[0]}:\n");
335 }
336
337sub main'file_end
338 {
339 }
340
341sub main'data_word
342 {
343 push(@out,"\t.long $_[0]\n");
344 }
345
346@pool_free=();
347@pool_taken=();
348$curr_num=0;
349$max=0;
350
351sub main'init_pool
352 {
353 local($args)=@_;
354 local($i);
355
356 @pool_free=();
357 for ($i=(14+(6-$args)); $i >= 0; $i--)
358 {
359 push(@pool_free,"r$i");
360 }
361 print STDERR "START :register pool:@pool_free\n";
362 $curr_num=$max=0;
363 }
364
365sub main'fin_pool
366 {
367 printf STDERR "END %2d:register pool:@pool_free\n",$max;
368 }
369
370sub main'GR
371 {
372 local($r)=@_;
373 local($i,@n,$_);
374
375 foreach (@pool_free)
376 {
377 if ($r ne $_)
378 { push(@n,$_); }
379 else
380 {
381 $curr_num++;
382 $max=$curr_num if ($curr_num > $max);
383 }
384 }
385 @pool_free=@n;
386print STDERR "GR:@pool_free\n" if $reg_alloc;
387 return(@_);
388 }
389
390sub main'NR
391 {
392 local($num)=@_;
393 local(@ret);
394
395 $num=1 if $num == 0;
396 ($#pool_free >= ($num-1)) || croak "out of registers: want $num, have @pool_free";
397 while ($num > 0)
398 {
399 push(@ret,pop @pool_free);
400 $curr_num++;
401 $max=$curr_num if ($curr_num > $max);
402 $num--
403 }
404 print STDERR "nr @ret\n" if $n_debug;
405print STDERR "NR:@pool_free\n" if $reg_alloc;
406 return(@ret);
407
408 }
409
410sub main'FR
411 {
412 local(@r)=@_;
413 local(@a,$v,$w);
414
415 print STDERR "fr @r\n" if $n_debug;
416# cluck "fr @r";
417 for $w (@pool_free)
418 {
419 foreach $v (@r)
420 {
421 croak "double register free of $v (@pool_free)" if $w eq $v;
422 }
423 }
424 foreach $v (@r)
425 {
426 croak "bad argument to FR" if ($v !~ /^r\d+$/);
427 if ($smear_regs)
428 { unshift(@pool_free,$v); }
429 else { push(@pool_free,$v); }
430 $curr_num--;
431 }
432print STDERR "FR:@pool_free\n" if $reg_alloc;
433 }
4341;
diff --git a/src/lib/libcrypto/perlasm/x86nasm.pl b/src/lib/libcrypto/perlasm/x86nasm.pl
new file mode 100644
index 0000000000..b4da364bbf
--- /dev/null
+++ b/src/lib/libcrypto/perlasm/x86nasm.pl
@@ -0,0 +1,342 @@
1#!/usr/local/bin/perl
2
3package x86nasm;
4
5$label="L000";
6
7%lb=( 'eax', 'al',
8 'ebx', 'bl',
9 'ecx', 'cl',
10 'edx', 'dl',
11 'ax', 'al',
12 'bx', 'bl',
13 'cx', 'cl',
14 'dx', 'dl',
15 );
16
17%hb=( 'eax', 'ah',
18 'ebx', 'bh',
19 'ecx', 'ch',
20 'edx', 'dh',
21 'ax', 'ah',
22 'bx', 'bh',
23 'cx', 'ch',
24 'dx', 'dh',
25 );
26
27sub main'asm_init_output { @out=(); }
28sub main'asm_get_output { return(@out); }
29sub main'get_labels { return(@labels); }
30
31sub main'external_label
32{
33 push(@labels,@_);
34 foreach (@_) {
35 push(@out, "extern\t_$_\n");
36 }
37}
38
39sub main'LB
40 {
41 (defined($lb{$_[0]})) || die "$_[0] does not have a 'low byte'\n";
42 return($lb{$_[0]});
43 }
44
45sub main'HB
46 {
47 (defined($hb{$_[0]})) || die "$_[0] does not have a 'high byte'\n";
48 return($hb{$_[0]});
49 }
50
51sub main'BP
52 {
53 &get_mem("BYTE",@_);
54 }
55
56sub main'DWP
57 {
58 &get_mem("DWORD",@_);
59 }
60
61sub main'BC
62 {
63 return "BYTE @_";
64 }
65
66sub main'DWC
67 {
68 return "DWORD @_";
69 }
70
71sub main'stack_push
72 {
73 my($num)=@_;
74 $stack+=$num*4;
75 &main'sub("esp",$num*4);
76 }
77
78sub main'stack_pop
79 {
80 my($num)=@_;
81 $stack-=$num*4;
82 &main'add("esp",$num*4);
83 }
84
85sub get_mem
86 {
87 my($size,$addr,$reg1,$reg2,$idx)=@_;
88 my($t,$post);
89 my($ret)="[";
90 $addr =~ s/^\s+//;
91 if ($addr =~ /^(.+)\+(.+)$/)
92 {
93 $reg2=&conv($1);
94 $addr="_$2";
95 }
96 elsif ($addr =~ /^[_a-zA-Z]/)
97 {
98 $addr="_$addr";
99 }
100
101 $reg1="$regs{$reg1}" if defined($regs{$reg1});
102 $reg2="$regs{$reg2}" if defined($regs{$reg2});
103 if (($addr ne "") && ($addr ne 0))
104 {
105 if ($addr !~ /^-/)
106 { $ret.="${addr}+"; }
107 else { $post=$addr; }
108 }
109 if ($reg2 ne "")
110 {
111 $t="";
112 $t="*$idx" if ($idx != 0);
113 $reg1="+".$reg1 if ("$reg1$post" ne "");
114 $ret.="$reg2$t$reg1$post]";
115 }
116 else
117 {
118 $ret.="$reg1$post]"
119 }
120 return($ret);
121 }
122
123sub main'mov { &out2("mov",@_); }
124sub main'movb { &out2("mov",@_); }
125sub main'and { &out2("and",@_); }
126sub main'or { &out2("or",@_); }
127sub main'shl { &out2("shl",@_); }
128sub main'shr { &out2("shr",@_); }
129sub main'xor { &out2("xor",@_); }
130sub main'xorb { &out2("xor",@_); }
131sub main'add { &out2("add",@_); }
132sub main'adc { &out2("adc",@_); }
133sub main'sub { &out2("sub",@_); }
134sub main'rotl { &out2("rol",@_); }
135sub main'rotr { &out2("ror",@_); }
136sub main'exch { &out2("xchg",@_); }
137sub main'cmp { &out2("cmp",@_); }
138sub main'lea { &out2("lea",@_); }
139sub main'mul { &out1("mul",@_); }
140sub main'div { &out1("div",@_); }
141sub main'dec { &out1("dec",@_); }
142sub main'inc { &out1("inc",@_); }
143sub main'jmp { &out1("jmp",@_); }
144sub main'jmp_ptr { &out1p("jmp",@_); }
145
146# This is a bit of a kludge: declare all branches as NEAR.
147sub main'je { &out1("je NEAR",@_); }
148sub main'jle { &out1("jle NEAR",@_); }
149sub main'jz { &out1("jz NEAR",@_); }
150sub main'jge { &out1("jge NEAR",@_); }
151sub main'jl { &out1("jl NEAR",@_); }
152sub main'jb { &out1("jb NEAR",@_); }
153sub main'jc { &out1("jc NEAR",@_); }
154sub main'jnc { &out1("jnc NEAR",@_); }
155sub main'jnz { &out1("jnz NEAR",@_); }
156sub main'jne { &out1("jne NEAR",@_); }
157sub main'jno { &out1("jno NEAR",@_); }
158
159sub main'push { &out1("push",@_); $stack+=4; }
160sub main'pop { &out1("pop",@_); $stack-=4; }
161sub main'bswap { &out1("bswap",@_); &using486(); }
162sub main'not { &out1("not",@_); }
163sub main'call { &out1("call",'_'.$_[0]); }
164sub main'ret { &out0("ret"); }
165sub main'nop { &out0("nop"); }
166
167sub out2
168 {
169 my($name,$p1,$p2)=@_;
170 my($l,$t);
171
172 push(@out,"\t$name\t");
173 $t=&conv($p1).",";
174 $l=length($t);
175 push(@out,$t);
176 $l=4-($l+9)/8;
177 push(@out,"\t" x $l);
178 push(@out,&conv($p2));
179 push(@out,"\n");
180 }
181
182sub out0
183 {
184 my($name)=@_;
185
186 push(@out,"\t$name\n");
187 }
188
189sub out1
190 {
191 my($name,$p1)=@_;
192 my($l,$t);
193 push(@out,"\t$name\t".&conv($p1)."\n");
194 }
195
196sub conv
197 {
198 my($p)=@_;
199 $p =~ s/0x([0-9A-Fa-f]+)/0$1h/;
200 return $p;
201 }
202
203sub using486
204 {
205 return if $using486;
206 $using486++;
207 grep(s/\.386/\.486/,@out);
208 }
209
210sub main'file
211 {
212 push(@out, "segment .text\n");
213 }
214
215sub main'function_begin
216 {
217 my($func,$extra)=@_;
218
219 push(@labels,$func);
220 my($tmp)=<<"EOF";
221global _$func
222_$func:
223 push ebp
224 push ebx
225 push esi
226 push edi
227EOF
228 push(@out,$tmp);
229 $stack=20;
230 }
231
232sub main'function_begin_B
233 {
234 my($func,$extra)=@_;
235 my($tmp)=<<"EOF";
236global _$func
237_$func:
238EOF
239 push(@out,$tmp);
240 $stack=4;
241 }
242
243sub main'function_end
244 {
245 my($func)=@_;
246
247 my($tmp)=<<"EOF";
248 pop edi
249 pop esi
250 pop ebx
251 pop ebp
252 ret
253EOF
254 push(@out,$tmp);
255 $stack=0;
256 %label=();
257 }
258
259sub main'function_end_B
260 {
261 $stack=0;
262 %label=();
263 }
264
265sub main'function_end_A
266 {
267 my($func)=@_;
268
269 my($tmp)=<<"EOF";
270 pop edi
271 pop esi
272 pop ebx
273 pop ebp
274 ret
275EOF
276 push(@out,$tmp);
277 }
278
279sub main'file_end
280 {
281 }
282
283sub main'wparam
284 {
285 my($num)=@_;
286
287 return(&main'DWP($stack+$num*4,"esp","",0));
288 }
289
290sub main'swtmp
291 {
292 return(&main'DWP($_[0]*4,"esp","",0));
293 }
294
295# Should use swtmp, which is above esp. Linix can trash the stack above esp
296#sub main'wtmp
297# {
298# my($num)=@_;
299#
300# return(&main'DWP(-(($num+1)*4),"esp","",0));
301# }
302
303sub main'comment
304 {
305 foreach (@_)
306 {
307 push(@out,"\t; $_\n");
308 }
309 }
310
311sub main'label
312 {
313 if (!defined($label{$_[0]}))
314 {
315 $label{$_[0]}="\$${label}${_[0]}";
316 $label++;
317 }
318 return($label{$_[0]});
319 }
320
321sub main'set_label
322 {
323 if (!defined($label{$_[0]}))
324 {
325 $label{$_[0]}="${label}${_[0]}";
326 $label++;
327 }
328 push(@out,"$label{$_[0]}:\n");
329 }
330
331sub main'data_word
332 {
333 push(@out,"\tDD\t$_[0]\n");
334 }
335
336sub out1p
337 {
338 my($name,$p1)=@_;
339 my($l,$t);
340
341 push(@out,"\t$name\t ".&conv($p1)."\n");
342 }
diff --git a/src/lib/libcrypto/pkcs7/bio_ber.c b/src/lib/libcrypto/pkcs7/bio_ber.c
new file mode 100644
index 0000000000..2f17723e98
--- /dev/null
+++ b/src/lib/libcrypto/pkcs7/bio_ber.c
@@ -0,0 +1,450 @@
1/* crypto/evp/bio_ber.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <errno.h>
61#include "cryptlib.h"
62#include <openssl/buffer.h>
63#include <openssl/evp.h>
64
65static int ber_write(BIO *h,char *buf,int num);
66static int ber_read(BIO *h,char *buf,int size);
67/*static int ber_puts(BIO *h,char *str); */
68/*static int ber_gets(BIO *h,char *str,int size); */
69static long ber_ctrl(BIO *h,int cmd,long arg1,char *arg2);
70static int ber_new(BIO *h);
71static int ber_free(BIO *data);
72#define BER_BUF_SIZE (32)
73
74/* This is used to hold the state of the BER objects being read. */
75typedef struct ber_struct
76 {
77 int tag;
78 int class;
79 long length;
80 int inf;
81 int num_left;
82 int depth;
83 } BER_CTX;
84
85typedef struct bio_ber_struct
86 {
87 int tag;
88 int class;
89 long length;
90 int inf;
91
92 /* most of the following are used when doing non-blocking IO */
93 /* reading */
94 long num_left; /* number of bytes still to read/write in block */
95 int depth; /* used with idefinite encoding. */
96 int finished; /* No more read data */
97
98 /* writting */
99 char *w_addr;
100 int w_offset;
101 int w_left;
102
103 int buf_len;
104 int buf_off;
105 unsigned char buf[BER_BUF_SIZE];
106 } BIO_BER_CTX;
107
108static BIO_METHOD methods_ber=
109 {
110 BIO_TYPE_CIPHER,"cipher",
111 ber_write,
112 ber_read,
113 NULL, /* ber_puts, */
114 NULL, /* ber_gets, */
115 ber_ctrl,
116 ber_new,
117 ber_free,
118 };
119
120BIO_METHOD *BIO_f_ber(void)
121 {
122 return(&methods_ber);
123 }
124
125static int ber_new(BIO *bi)
126 {
127 BIO_BER_CTX *ctx;
128
129 ctx=(BIO_BER_CTX *)Malloc(sizeof(BIO_BER_CTX));
130 if (ctx == NULL) return(0);
131
132 memset((char *)ctx,0,sizeof(BIO_BER_CTX));
133
134 bi->init=0;
135 bi->ptr=(char *)ctx;
136 bi->flags=0;
137 return(1);
138 }
139
140static int ber_free(BIO *a)
141 {
142 BIO_BER_CTX *b;
143
144 if (a == NULL) return(0);
145 b=(BIO_BER_CTX *)a->ptr;
146 memset(a->ptr,0,sizeof(BIO_BER_CTX));
147 Free(a->ptr);
148 a->ptr=NULL;
149 a->init=0;
150 a->flags=0;
151 return(1);
152 }
153
154int bio_ber_get_header(BIO *bio, BIO_BER_CTX *ctx)
155 {
156 char buf[64];
157 int i,j,n;
158 int ret;
159 unsigned char *p;
160 unsigned long length
161 int tag;
162 int class;
163 long max;
164
165 BIO_clear_retry_flags(b);
166
167 /* Pack the buffer down if there is a hole at the front */
168 if (ctx->buf_off != 0)
169 {
170 p=ctx->buf;
171 j=ctx->buf_off;
172 n=ctx->buf_len-j;
173 for (i=0; i<n; i++)
174 {
175 p[0]=p[j];
176 p++;
177 }
178 ctx->buf_len-j;
179 ctx->buf_off=0;
180 }
181
182 /* If there is more room, read some more data */
183 i=BER_BUF_SIZE-ctx->buf_len;
184 if (i)
185 {
186 i=BIO_read(bio->next_bio,&(ctx->buf[ctx->buf_len]),i);
187 if (i <= 0)
188 {
189 BIO_copy_next_retry(b);
190 return(i);
191 }
192 else
193 ctx->buf_len+=i;
194 }
195
196 max=ctx->buf_len;
197 p=ctx->buf;
198 ret=ASN1_get_object(&p,&length,&tag,&class,max);
199
200 if (ret & 0x80)
201 {
202 if ((ctx->buf_len < BER_BUF_SIZE) &&
203 (ERR_GET_REASON(ERR_peek_error()) == ASN1_R_TOO_LONG))
204 {
205 ERR_get_error(); /* clear the error */
206 BIO_set_retry_read(b);
207 }
208 return(-1);
209 }
210
211 /* We have no error, we have a header, so make use of it */
212
213 if ((ctx->tag >= 0) && (ctx->tag != tag))
214 {
215 BIOerr(BIO_F_BIO_BER_GET_HEADER,BIO_R_TAG_MISMATCH);
216 sprintf(buf,"tag=%d, got %d",ctx->tag,tag);
217 ERR_add_error_data(1,buf);
218 return(-1);
219 }
220 if (ret & 0x01)
221 if (ret & V_ASN1_CONSTRUCTED)
222 }
223
224static int ber_read(BIO *b, char *out, int outl)
225 {
226 int ret=0,i,n;
227 BIO_BER_CTX *ctx;
228
229 BIO_clear_retry_flags(b);
230
231 if (out == NULL) return(0);
232 ctx=(BIO_BER_CTX *)b->ptr;
233
234 if ((ctx == NULL) || (b->next_bio == NULL)) return(0);
235
236 if (ctx->finished) return(0);
237
238again:
239 /* First see if we are half way through reading a block */
240 if (ctx->num_left > 0)
241 {
242 if (ctx->num_left < outl)
243 n=ctx->num_left;
244 else
245 n=outl;
246 i=BIO_read(b->next_bio,out,n);
247 if (i <= 0)
248 {
249 BIO_copy_next_retry(b);
250 return(i);
251 }
252 ctx->num_left-=i;
253 outl-=i;
254 ret+=i;
255 if (ctx->num_left <= 0)
256 {
257 ctx->depth--;
258 if (ctx->depth <= 0)
259 ctx->finished=1;
260 }
261 if (outl <= 0)
262 return(ret);
263 else
264 goto again;
265 }
266 else /* we need to read another BER header */
267 {
268 }
269 }
270
271static int ber_write(BIO *b, char *in, int inl)
272 {
273 int ret=0,n,i;
274 BIO_ENC_CTX *ctx;
275
276 ctx=(BIO_ENC_CTX *)b->ptr;
277 ret=inl;
278
279 BIO_clear_retry_flags(b);
280 n=ctx->buf_len-ctx->buf_off;
281 while (n > 0)
282 {
283 i=BIO_write(b->next_bio,&(ctx->buf[ctx->buf_off]),n);
284 if (i <= 0)
285 {
286 BIO_copy_next_retry(b);
287 return(i);
288 }
289 ctx->buf_off+=i;
290 n-=i;
291 }
292 /* at this point all pending data has been written */
293
294 if ((in == NULL) || (inl <= 0)) return(0);
295
296 ctx->buf_off=0;
297 while (inl > 0)
298 {
299 n=(inl > ENC_BLOCK_SIZE)?ENC_BLOCK_SIZE:inl;
300 EVP_CipherUpdate(&(ctx->cipher),
301 (unsigned char *)ctx->buf,&ctx->buf_len,
302 (unsigned char *)in,n);
303 inl-=n;
304 in+=n;
305
306 ctx->buf_off=0;
307 n=ctx->buf_len;
308 while (n > 0)
309 {
310 i=BIO_write(b->next_bio,&(ctx->buf[ctx->buf_off]),n);
311 if (i <= 0)
312 {
313 BIO_copy_next_retry(b);
314 return(i);
315 }
316 n-=i;
317 ctx->buf_off+=i;
318 }
319 ctx->buf_len=0;
320 ctx->buf_off=0;
321 }
322 BIO_copy_next_retry(b);
323 return(ret);
324 }
325
326static long ber_ctrl(BIO *b, int cmd, long num, char *ptr)
327 {
328 BIO *dbio;
329 BIO_ENC_CTX *ctx,*dctx;
330 long ret=1;
331 int i;
332
333 ctx=(BIO_ENC_CTX *)b->ptr;
334
335 switch (cmd)
336 {
337 case BIO_CTRL_RESET:
338 ctx->ok=1;
339 ctx->finished=0;
340 EVP_CipherInit(&(ctx->cipher),NULL,NULL,NULL,
341 ctx->cipher.berrypt);
342 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
343 break;
344 case BIO_CTRL_EOF: /* More to read */
345 if (ctx->cont <= 0)
346 ret=1;
347 else
348 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
349 break;
350 case BIO_CTRL_WPENDING:
351 ret=ctx->buf_len-ctx->buf_off;
352 if (ret <= 0)
353 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
354 break;
355 case BIO_CTRL_PENDING: /* More to read in buffer */
356 ret=ctx->buf_len-ctx->buf_off;
357 if (ret <= 0)
358 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
359 break;
360 case BIO_CTRL_FLUSH:
361 /* do a final write */
362again:
363 while (ctx->buf_len != ctx->buf_off)
364 {
365 i=ber_write(b,NULL,0);
366 if (i < 0)
367 {
368 ret=i;
369 break;
370 }
371 }
372
373 if (!ctx->finished)
374 {
375 ctx->finished=1;
376 ctx->buf_off=0;
377 ret=EVP_CipherFinal(&(ctx->cipher),
378 (unsigned char *)ctx->buf,
379 &(ctx->buf_len));
380 ctx->ok=(int)ret;
381 if (ret <= 0) break;
382
383 /* push out the bytes */
384 goto again;
385 }
386
387 /* Finally flush the underlying BIO */
388 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
389 break;
390 case BIO_C_GET_CIPHER_STATUS:
391 ret=(long)ctx->ok;
392 break;
393 case BIO_C_DO_STATE_MACHINE:
394 BIO_clear_retry_flags(b);
395 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
396 BIO_copy_next_retry(b);
397 break;
398
399 case BIO_CTRL_DUP:
400 dbio=(BIO *)ptr;
401 dctx=(BIO_ENC_CTX *)dbio->ptr;
402 memcpy(&(dctx->cipher),&(ctx->cipher),sizeof(ctx->cipher));
403 dbio->init=1;
404 break;
405 default:
406 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
407 break;
408 }
409 return(ret);
410 }
411
412/*
413void BIO_set_cipher_ctx(b,c)
414BIO *b;
415EVP_CIPHER_ctx *c;
416 {
417 if (b == NULL) return;
418
419 if ((b->callback != NULL) &&
420 (b->callback(b,BIO_CB_CTRL,(char *)c,BIO_CTRL_SET,e,0L) <= 0))
421 return;
422
423 b->init=1;
424 ctx=(BIO_ENC_CTX *)b->ptr;
425 memcpy(ctx->cipher,c,sizeof(EVP_CIPHER_CTX));
426
427 if (b->callback != NULL)
428 b->callback(b,BIO_CB_CTRL,(char *)c,BIO_CTRL_SET,e,1L);
429 }
430*/
431
432void BIO_set_cipher(BIO *b, EVP_CIPHER *c, unsigned char *k, unsigned char *i,
433 int e)
434 {
435 BIO_ENC_CTX *ctx;
436
437 if (b == NULL) return;
438
439 if ((b->callback != NULL) &&
440 (b->callback(b,BIO_CB_CTRL,(char *)c,BIO_CTRL_SET,e,0L) <= 0))
441 return;
442
443 b->init=1;
444 ctx=(BIO_ENC_CTX *)b->ptr;
445 EVP_CipherInit(&(ctx->cipher),c,k,i,e);
446
447 if (b->callback != NULL)
448 b->callback(b,BIO_CB_CTRL,(char *)c,BIO_CTRL_SET,e,1L);
449 }
450
diff --git a/src/lib/libcrypto/pkcs7/dec.c b/src/lib/libcrypto/pkcs7/dec.c
new file mode 100644
index 0000000000..b3661f28d3
--- /dev/null
+++ b/src/lib/libcrypto/pkcs7/dec.c
@@ -0,0 +1,246 @@
1/* crypto/pkcs7/verify.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58#include <stdio.h>
59#include <stdlib.h>
60#include <openssl/bio.h>
61#include <openssl/x509.h>
62#include <openssl/pem.h>
63#include <openssl/err.h>
64#include <openssl/asn1.h>
65
66int verify_callback(int ok, X509_STORE_CTX *ctx);
67
68BIO *bio_err=NULL;
69
70int main(argc,argv)
71int argc;
72char *argv[];
73 {
74 char *keyfile=NULL;
75 BIO *in;
76 EVP_PKEY *pkey;
77 X509 *x509;
78 PKCS7 *p7;
79 PKCS7_SIGNER_INFO *si;
80 X509_STORE_CTX cert_ctx;
81 X509_STORE *cert_store=NULL;
82 BIO *data,*detached=NULL,*p7bio=NULL;
83 char buf[1024*4];
84 unsigned char *pp;
85 int i,printit=0;
86 STACK_OF(PKCS7_SIGNER_INFO) *sk;
87
88 SSLeay_add_all_algorithms();
89 bio_err=BIO_new_fp(stderr,BIO_NOCLOSE);
90
91 data=BIO_new(BIO_s_file());
92 pp=NULL;
93 while (argc > 1)
94 {
95 argc--;
96 argv++;
97 if (strcmp(argv[0],"-p") == 0)
98 {
99 printit=1;
100 }
101 else if ((strcmp(argv[0],"-k") == 0) && (argc >= 2)) {
102 keyfile = argv[1];
103 argc-=1;
104 argv+=1;
105 } else if ((strcmp(argv[0],"-d") == 0) && (argc >= 2))
106 {
107 detached=BIO_new(BIO_s_file());
108 if (!BIO_read_filename(detached,argv[1]))
109 goto err;
110 argc-=1;
111 argv+=1;
112 }
113 else break;
114 }
115
116 if (!BIO_read_filename(data,argv[0])) goto err;
117
118 if(!keyfile) {
119 fprintf(stderr, "No private key file specified\n");
120 goto err;
121 }
122
123 if ((in=BIO_new_file(keyfile,"r")) == NULL) goto err;
124 if ((x509=PEM_read_bio_X509(in,NULL,NULL)) == NULL) goto err;
125 BIO_reset(in);
126 if ((pkey=PEM_read_bio_PrivateKey(in,NULL,NULL)) == NULL) goto err;
127 BIO_free(in);
128
129 if (pp == NULL)
130 BIO_set_fp(data,stdin,BIO_NOCLOSE);
131
132
133 /* Load the PKCS7 object from a file */
134 if ((p7=PEM_read_bio_PKCS7(data,NULL,NULL)) == NULL) goto err;
135
136
137
138 /* This stuff is being setup for certificate verification.
139 * When using SSL, it could be replaced with a
140 * cert_stre=SSL_CTX_get_cert_store(ssl_ctx); */
141 cert_store=X509_STORE_new();
142 X509_STORE_set_default_paths(cert_store);
143 X509_STORE_load_locations(cert_store,NULL,"../../certs");
144 X509_STORE_set_verify_cb_func(cert_store,verify_callback);
145
146 ERR_clear_error();
147
148 /* We need to process the data */
149 /* We cannot support detached encryption */
150 p7bio=PKCS7_dataDecode(p7,pkey,detached,x509);
151
152 if (p7bio == NULL)
153 {
154 printf("problems decoding\n");
155 goto err;
156 }
157
158 /* We now have to 'read' from p7bio to calculate digests etc. */
159 for (;;)
160 {
161 i=BIO_read(p7bio,buf,sizeof(buf));
162 /* print it? */
163 if (i <= 0) break;
164 fwrite(buf,1, i, stdout);
165 }
166
167 /* We can now verify signatures */
168 sk=PKCS7_get_signer_info(p7);
169 if (sk == NULL)
170 {
171 fprintf(stderr, "there are no signatures on this data\n");
172 }
173 else
174 {
175 /* Ok, first we need to, for each subject entry,
176 * see if we can verify */
177 ERR_clear_error();
178 for (i=0; i<sk_PKCS7_SIGNER_INFO_num(sk); i++)
179 {
180 si=sk_PKCS7_SIGNER_INFO_value(sk,i);
181 i=PKCS7_dataVerify(cert_store,&cert_ctx,p7bio,p7,si);
182 if (i <= 0)
183 goto err;
184 else
185 fprintf(stderr,"Signature verified\n");
186 }
187 }
188 X509_STORE_free(cert_store);
189
190 exit(0);
191err:
192 ERR_load_crypto_strings();
193 ERR_print_errors_fp(stderr);
194 exit(1);
195 }
196
197/* should be X509 * but we can just have them as char *. */
198int verify_callback(int ok, X509_STORE_CTX *ctx)
199 {
200 char buf[256];
201 X509 *err_cert;
202 int err,depth;
203
204 err_cert=X509_STORE_CTX_get_current_cert(ctx);
205 err= X509_STORE_CTX_get_error(ctx);
206 depth= X509_STORE_CTX_get_error_depth(ctx);
207
208 X509_NAME_oneline(X509_get_subject_name(err_cert),buf,256);
209 BIO_printf(bio_err,"depth=%d %s\n",depth,buf);
210 if (!ok)
211 {
212 BIO_printf(bio_err,"verify error:num=%d:%s\n",err,
213 X509_verify_cert_error_string(err));
214 if (depth < 6)
215 {
216 ok=1;
217 X509_STORE_CTX_set_error(ctx,X509_V_OK);
218 }
219 else
220 {
221 ok=0;
222 X509_STORE_CTX_set_error(ctx,X509_V_ERR_CERT_CHAIN_TOO_LONG);
223 }
224 }
225 switch (ctx->error)
226 {
227 case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT:
228 X509_NAME_oneline(X509_get_issuer_name(ctx->current_cert),buf,256);
229 BIO_printf(bio_err,"issuer= %s\n",buf);
230 break;
231 case X509_V_ERR_CERT_NOT_YET_VALID:
232 case X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD:
233 BIO_printf(bio_err,"notBefore=");
234 ASN1_UTCTIME_print(bio_err,X509_get_notBefore(ctx->current_cert));
235 BIO_printf(bio_err,"\n");
236 break;
237 case X509_V_ERR_CERT_HAS_EXPIRED:
238 case X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD:
239 BIO_printf(bio_err,"notAfter=");
240 ASN1_UTCTIME_print(bio_err,X509_get_notAfter(ctx->current_cert));
241 BIO_printf(bio_err,"\n");
242 break;
243 }
244 BIO_printf(bio_err,"verify return:%d\n",ok);
245 return(ok);
246 }
diff --git a/src/lib/libcrypto/pkcs7/des.pem b/src/lib/libcrypto/pkcs7/des.pem
new file mode 100644
index 0000000000..62d1657e3e
--- /dev/null
+++ b/src/lib/libcrypto/pkcs7/des.pem
@@ -0,0 +1,15 @@
1
2MIAGCSqGSIb3DQEHA6CAMIACAQAxggHmMIHwAgEAMIGZMIGSMQswCQYDVQQGEwJBVTETMBEG
3A1UECBMKUXVlZW5zbGFuZDERMA8GA1UEBxMIQnJpc2JhbmUxGjAYBgNVBAoTEUNyeXB0c29m
4dCBQdHkgTHRkMSIwIAYDVQQLExlERU1PTlNUUkFUSU9OIEFORCBURVNUSU5HMRswGQYDVQQD
5ExJERU1PIFpFUk8gVkFMVUUgQ0ECAgR+MA0GCSqGSIb3DQEBAQUABEC2vXI1xQDW6lUHM3zQ
6/9uBEBOO5A3TtkrklAXq7v01gsIC21t52qSk36REXY+slhNZ0OQ349tgkTsoETHFLoEwMIHw
7AgEAMIGZMIGSMQswCQYDVQQGEwJBVTETMBEGA1UECBMKUXVlZW5zbGFuZDERMA8GA1UEBxMI
8QnJpc2JhbmUxGjAYBgNVBAoTEUNyeXB0c29mdCBQdHkgTHRkMSIwIAYDVQQLExlERU1PTlNU
9UkFUSU9OIEFORCBURVNUSU5HMRswGQYDVQQDExJERU1PIFpFUk8gVkFMVUUgQ0ECAgR9MA0G
10CSqGSIb3DQEBAQUABEB8ujxbabxXUYJhopuDm3oDq4JNqX6Io4p3ro+ShqfIndsXTZ1v5a2N
11WtLLCWlHn/habjBwZ/DgQgcKASbZ7QxNMIAGCSqGSIb3DQEHATAaBggqhkiG9w0DAjAOAgIA
12oAQIbsL5v1wX98KggAQoAaJ4WHm68fXY1WE5OIjfVBIDpO1K+i8dmKhjnAjrjoyZ9Bwc8rDL
13lgQg4CXb805h5xl+GfvSwUaHJayte1m2mcOhs3J2YyqbQ+MEIMIiJQccmhO3oDKm36CFvYR8
145PjpclVcZyX2ngbwPFMnBAgy0clOAE6UKAAAAAAAAAAAAAA=
15
diff --git a/src/lib/libcrypto/pkcs7/es1.pem b/src/lib/libcrypto/pkcs7/es1.pem
new file mode 100644
index 0000000000..47112a238f
--- /dev/null
+++ b/src/lib/libcrypto/pkcs7/es1.pem
@@ -0,0 +1,66 @@
1-----BEGIN PKCS7-----
2MIAGCSqGSIb3DQEHA6CAMIACAQAxggHmMIHwAgEAMIGZMIGSMQswCQYDVQQGEwJBVTETMBEG
3A1UECBMKUXVlZW5zbGFuZDERMA8GA1UEBxMIQnJpc2JhbmUxGjAYBgNVBAoTEUNyeXB0c29m
4dCBQdHkgTHRkMSIwIAYDVQQLExlERU1PTlNUUkFUSU9OIEFORCBURVNUSU5HMRswGQYDVQQD
5ExJERU1PIFpFUk8gVkFMVUUgQ0ECAgRuMA0GCSqGSIb3DQEBAQUABEDWak0y/5XZJhQJeCLo
6KECcHXkTEbjzYkYNHIinbiPmRK4QbNfs9z2mA3z/c2ykQ4eAqFR2jyNrUMN/+I5XEiv6MIHw
7AgEAMIGZMIGSMQswCQYDVQQGEwJBVTETMBEGA1UECBMKUXVlZW5zbGFuZDERMA8GA1UEBxMI
8QnJpc2JhbmUxGjAYBgNVBAoTEUNyeXB0c29mdCBQdHkgTHRkMSIwIAYDVQQLExlERU1PTlNU
9UkFUSU9OIEFORCBURVNUSU5HMRswGQYDVQQDExJERU1PIFpFUk8gVkFMVUUgQ0ECAgR9MA0G
10CSqGSIb3DQEBAQUABEAWg9+KgtCjc77Jdj1Ve4wGgHjVHbbSYEA1ZqKFDoi15vSr9hfpHmC4
11ycZzcRo16JkTfolefiHZzmyjVz94vSN6MIAGCSqGSIb3DQEHATAaBggqhkiG9w0DAjAOAgIA
12oAQI7X4Tk4mcbV6ggASBsHl1mCaJ3RhXWlNPCgCRU53d7M5x6TDZRkvwdtdvW96m1lupT03F
13XtonkBqk7oMkH7kGfs5/REQOPjx0QE2Ixmgt1W3szum82EZwA7pZNppcraK7W/odw/7bYZO+
14II3HPmRklE2N9qiu1LPaPUsnYogkO6SennyeL5tZ382vBweL/8pnG0qsbT1OBb65v+llnsjT
15pa1T/p+fIx/iJJGE6K9fYFokC6gXLQ6ozXRdOu5oBDB8mPCYYvAqKycidM/MrGGUkpEtS4f0
16lS31PwQi5YTim8Ig3/TOwVpPX32i46FTuEIEIMHkD/OvpfwCCzXUHHJnKnKUAUvIsSY3vGBs
178ezpUDfBBBj9LHDy32hZ2tQilkDefP5VM2LLdrWgamYEgfiyITQvn08Ul5lQOQxbFKBheFq5
18otCCN4MR+w5eq12xQu6y+f9z0159ag2ru87D0lLtUtXXtCELbO1nUkT2sJ0k/iDs9TOXr6Cx
19go1XKYho83hlkXYiCteVizdAbgVGNsNRD4wtIdajsorET/LuJECgp11YeL9w1dlDB0HLEZfi
20XCsUphH4jGagba3hDeUSibnjSiJlN0ukfuQurBBbI2UkBAujiEAubKPn7C1FZJRSw6CPPX5t
21KEpmcqT1JNk6LO8Js6/1sCmmBh1VGCy1+EuTI9J1p7Dagf4nQ8cHitoCRpHuKZlFHnZyv7tw
22Rn/KOhHaYP2VzAh40gQIvKMAAWh9oFsEEIMwIoOmLwLH5wf+8QdbDhoECH8HwZt9a12dBAjL
23r4j2zlvtfgQIt7nmEM3wz1EECKlc3EIy1irCBBCAKINcermK3A+jI6ISN2RzBFA3dsh/xwMu
24l61aWMBBZzEz/SF92k6n35KZhCC0d6fIVC/1WMv0fnCwQ8oEDynSre216VEFiYKBaQLJe5o/
25mTAxC7Ht3goXnuc+i1FItOkLrgRI/wyvTICEn2WsNZiMADnGaee2bqPnUopo+VMGexJEtCPk
26l0ZNlDJGquPDkpUwaEtecVZzCNyVPYyyF4J/l8rmGDhDdYUIC8IKBEg/ip/E0BuubBLWVbv+
27HRl4QrnGpyCyeXRXXK603QP3sT1Zbbm1v5pI/loOhVHi724LmtXHSyp5qv9MDcxE1PoX10LY
28gBRtlwwESPeCF8bK5jk4xIQMhK5NMHj1Y1KQWTZ9NGITBL4hjRq2qp4Qk5GIpGgOVPopAuCo
29TIyPikpqBRNtLSPRSsDs6QPUPzWBh6JgxwRQblnDKKUkxUcnJiD4i9QtGa/ZabMn4KxtNOBL
305JSh1nJkaLXCZY070131WWPAByLcd5TiXq8x84pmzV5NNk4tiMpoXhJNsx8e4rskQQlKd6ME
31SCe2eYDHKcKPX3WJbUzhrJSQ92/aWnI2iUY8WQ+kSNyiZ2QUjyuUg9Z66g/0d2STlvPOBHT/
32y5ODP2CwbcWX4QmCbUc9TT66fQRIrRVuwvtOfnUueyGgYhJ3HpAJfVaB/7kap5bj7Fi/azW4
339JDfd1bC/W9h0Kyk7RO2gxvE0hIHc26mZJHTm9MNP5D328MnM2MdBEjKjQBtgrp+lFIii7MP
34nGHFTKUkG4WAIZJCf/CsT+p6/SW0qG71Me/YcSw5STB24j+a+HgMV8RVIeUlkP4z0IWWrSoB
35Gh4d/Z0EUMCVHs/HZ/bWgiyhtHpvuVAzidm8D81p1LJ5BQX5/5f/m+q5+fS/npL27dTEbNqs
36LSB6ij3MZAi7LwHWpTn9zWnDajCMEj9vlaV7mcKtHK5iBEg85agFi1h3MvicqLtoFe5hVv9T
37tG0j6CRkjkixPzivltlrf44KHv14gLM0XJxCGyq7vd3l8QYr3+9at0zNnX/yqTiBnsnE5dUE
38SIgrYuz87M2gi/ER9PcDoTtONH3+CkcqVy03q/Sj8cVWD/b1KgEhqnNOfc8Ak9PctyR/ItcR
398Me5XVn1GJKkQJk4O29fxvgNoAQIrIESvUWGshAEQByXiFoFTDUByjTlgjcy77H1lrH+y3P/
40wAInJjJAut9kCNyGJV0PA4kdPB5USWltuO6t8gk4Pd2YBMl09zqUWkAEUCjFrtZ3mapjcGZI
41uQTASKR5LSjXoWxTT5gae/+64MerF/oCEeO3ehRTpjnPrsiRDo0rWIQTaj9+Nro8Z2xtWstw
42RnfoAHIxV1lEamPwjsceBEi2SD9hiifFeO5ECiVoaE1FdXUXhU+jwYAMx6jHWO9hMkYzS9pM
43Y3IyWR5ybtOjiQgkUdvRJPUPGf5DVVMPnymGX25aDh5PYpIESPbsM9akCpOOVuscywcUswmU
44o7dXvlB48WWCfg/al3BQKAZbn5ZXtWNwpUZkrEdHsrxAVv3rxRcdkT3Z1fzUbIuYkLJN200o
45WgRIJvn6RO8KEj7/HOg2sYuuM8nz1kR0TSgwX7/0y/7JfjBa0JIlP7o75sNJscE8oyoIMzuy
46Dvn6/U9g3BCDXn83A/s+ke60qn9gBFC6NAeLOlXal1YVWYhMQNOqCyUfAjiXBTawaysQb1Mk
47YgeNlF8xuEFcUQWIP+vNG7FJ5JPMaMRL4YEoaQ3sVFhYOERJR1cSb+8xt4QCYtBKQgRIUOmJ
48CHW5o1hXJWJiTkZK2qWFcEMzTINSj5EpYFySr8aVBjkRnI7vxegRT/+XZZXoYedQ3UNsnGI3
49DdkWii5VzX0PNF6C60pfBEiVpausYuX7Wjb3Lfm8cBj7GgN69i6Pm2gxtobVcmpo2nS4D714
50ePyhlX9n8kJ6QAcqWMRj22smDPrHVGNTizfzHBh5zNllK9gESJizILOWI327og3ZWp+qUht5
51kNDJCzMK7Z09UAy+h+vq0VTQuEo3FgLzVdqkJujjSL4Nx97lXg51AovrEn3nd4evydwcjKLX
521wRIo72NaeWuUEQ+rt1SlCsOJ7k1ioJSqhrPOfvwcaFcb4beVet1JWiy4yvowTjLDGbUje2s
53xjrlVt4BJWI/uA6jbQsrxSe89ADZBAi5YAlR4qszeAQIXD3VSBVKbRUECNTtyvw9vvqXBAhb
54IZNn4H4cxgQI+XW7GkfL+ekECCCCg2reMyGDBAh1PYqkg3lw3gQQkNlggEPU+BH8eh7Gm7n7
557AQIjC5EWbkil5cEEKcpuqwTWww/X89KnQAg8TcECJPomqHvrlZFBBiRSuIiHpmN+PaujXpv
56qZV2VhjkB2j09GEECOIdv8AVOJgKBAjlHgIqAD9jZQQIXHbs44+wogcEIGGqTACRJxrhMcMG
57X8drNjksIPt+snxTXUBIkTVpZWoABAh6unXPTyIr8QQgBF8xKoX27MWk7iTNmkSNZggZXa2a
58DWCGHSYLngbSOHIECD9XmO6VsvTgBAjfqB70CEW4WwQIVIBkbCocznUEEHB/zFXy/sR4OYHe
59UfbNPnIEEDWBB/NTCLMGE+o8BfyujcAECFik7GQnnF9VBBAhLXExQeWAofZNc6NtN7qZBCC1
60gVIS3ruTwKltmcrgx3heT3M8ZJhCfWa+6KzchnmKygQQ+1NL5sSzR4m/fdrqxHFyUAQYCT2x
61PamQr3wK3h0lyZER+4H0zPM86AhFBBC3CkmvL2vjflMfujnzPBVpBBge9rMbI5+0q9DLrTiT
625F3AIgXLpD8PQWAECHkHVo6RomV3BAgMbi8E271UeAQIqtS8wnI3XngECG3TWmOMb3/iBEha
63y+mvCS6I3n3JfL8e1B5P4qX9/czJRaERLuKpGNjLiL4A+zxN0LZ0UHd0qfmJjwOTxAx3iJAC
64lGXX4nB9ATYPUT5EU+o1Y4sECN01pP6vWNIdBDAsiE0Ts8/9ltJlqX2B3AoOM4qOt9EaCjXf
65lB+aEmrhtjUwuZ6GqS5Ke7P6XnakTk4ECCLIMatNdootAAAAAAAAAAAAAA==
66-----END PKCS7-----
diff --git a/src/lib/libcrypto/pkcs7/example.c b/src/lib/libcrypto/pkcs7/example.c
new file mode 100644
index 0000000000..7354890084
--- /dev/null
+++ b/src/lib/libcrypto/pkcs7/example.c
@@ -0,0 +1,327 @@
1#include <stdio.h>
2#include <stdlib.h>
3#include <openssl/pkcs7.h>
4#include <openssl/asn1_mac.h>
5
6int add_signed_time(PKCS7_SIGNER_INFO *si)
7 {
8 ASN1_UTCTIME *sign_time;
9
10 /* The last parameter is the amount to add/subtract from the current
11 * time (in seconds) */
12 sign_time=X509_gmtime_adj(NULL,0);
13 PKCS7_add_signed_attribute(si,NID_pkcs9_signingTime,
14 V_ASN1_UTCTIME,(char *)sign_time);
15 return(1);
16 }
17
18ASN1_UTCTIME *get_signed_time(PKCS7_SIGNER_INFO *si)
19 {
20 ASN1_TYPE *so;
21
22 so=PKCS7_get_signed_attribute(si,NID_pkcs9_signingTime);
23 if (so->type == V_ASN1_UTCTIME)
24 return so->value.utctime;
25 return NULL;
26 }
27
28static int signed_string_nid= -1;
29
30void add_signed_string(PKCS7_SIGNER_INFO *si, char *str)
31 {
32 ASN1_OCTET_STRING *os;
33
34 /* To a an object of OID 1.2.3.4.5, which is an octet string */
35 if (signed_string_nid == -1)
36 signed_string_nid=
37 OBJ_create("1.2.3.4.5","OID_example","Our example OID");
38 os=ASN1_OCTET_STRING_new();
39 ASN1_OCTET_STRING_set(os,str,strlen(str));
40 /* When we add, we do not free */
41 PKCS7_add_signed_attribute(si,signed_string_nid,
42 V_ASN1_OCTET_STRING,(char *)os);
43 }
44
45int get_signed_string(PKCS7_SIGNER_INFO *si, char *buf, int len)
46 {
47 ASN1_TYPE *so;
48 ASN1_OCTET_STRING *os;
49 int i;
50
51 if (signed_string_nid == -1)
52 signed_string_nid=
53 OBJ_create("1.2.3.4.5","OID_example","Our example OID");
54 /* To retrieve */
55 so=PKCS7_get_signed_attribute(si,signed_string_nid);
56 if (so != NULL)
57 {
58 if (so->type == V_ASN1_OCTET_STRING)
59 {
60 os=so->value.octet_string;
61 i=os->length;
62 if ((i+1) > len)
63 i=len-1;
64 memcpy(buf,os->data,i);
65 return(i);
66 }
67 }
68 return(0);
69 }
70
71static signed_seq2string_nid= -1;
72/* ########################################### */
73int add_signed_seq2string(PKCS7_SIGNER_INFO *si, char *str1, char *str2)
74 {
75 /* To add an object of OID 1.9.999, which is a sequence containing
76 * 2 octet strings */
77 unsigned char *p;
78 ASN1_OCTET_STRING *os1,*os2;
79 ASN1_STRING *seq;
80 unsigned char *data;
81 int i,total;
82
83 if (signed_seq2string_nid == -1)
84 signed_seq2string_nid=
85 OBJ_create("1.9.9999","OID_example","Our example OID");
86
87 os1=ASN1_OCTET_STRING_new();
88 os2=ASN1_OCTET_STRING_new();
89 ASN1_OCTET_STRING_set(os1,str1,strlen(str1));
90 ASN1_OCTET_STRING_set(os2,str1,strlen(str1));
91 i =i2d_ASN1_OCTET_STRING(os1,NULL);
92 i+=i2d_ASN1_OCTET_STRING(os2,NULL);
93 total=ASN1_object_size(1,i,V_ASN1_SEQUENCE);
94
95 data=malloc(total);
96 p=data;
97 ASN1_put_object(&p,1,i,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL);
98 i2d_ASN1_OCTET_STRING(os1,&p);
99 i2d_ASN1_OCTET_STRING(os2,&p);
100
101 seq=ASN1_STRING_new();
102 ASN1_STRING_set(seq,data,total);
103 free(data);
104 ASN1_OCTET_STRING_free(os1);
105 ASN1_OCTET_STRING_free(os2);
106
107 PKCS7_add_signed_attribute(si,signed_seq2string_nid,
108 V_ASN1_SEQUENCE,(char *)seq);
109 return(1);
110 }
111
112/* For this case, I will malloc the return strings */
113int get_signed_seq2string(PKCS7_SIGNER_INFO *si, char **str1, char **str2)
114 {
115 ASN1_TYPE *so;
116
117 if (signed_seq2string_nid == -1)
118 signed_seq2string_nid=
119 OBJ_create("1.9.9999","OID_example","Our example OID");
120 /* To retrieve */
121 so=PKCS7_get_signed_attribute(si,signed_seq2string_nid);
122 if (so && (so->type == V_ASN1_SEQUENCE))
123 {
124 ASN1_CTX c;
125 ASN1_STRING *s;
126 long length;
127 ASN1_OCTET_STRING *os1,*os2;
128
129 s=so->value.sequence;
130 c.p=ASN1_STRING_data(s);
131 c.max=c.p+ASN1_STRING_length(s);
132 if (!asn1_GetSequence(&c,&length)) goto err;
133 /* Length is the length of the seqence */
134
135 c.q=c.p;
136 if ((os1=d2i_ASN1_OCTET_STRING(NULL,&c.p,c.slen)) == NULL)
137 goto err;
138 c.slen-=(c.p-c.q);
139
140 c.q=c.p;
141 if ((os2=d2i_ASN1_OCTET_STRING(NULL,&c.p,c.slen)) == NULL)
142 goto err;
143 c.slen-=(c.p-c.q);
144
145 if (!asn1_Finish(&c)) goto err;
146 *str1=malloc(os1->length+1);
147 *str2=malloc(os2->length+1);
148 memcpy(*str1,os1->data,os1->length);
149 memcpy(*str2,os2->data,os2->length);
150 (*str1)[os1->length]='\0';
151 (*str2)[os2->length]='\0';
152 ASN1_OCTET_STRING_free(os1);
153 ASN1_OCTET_STRING_free(os2);
154 return(1);
155 }
156err:
157 return(0);
158 }
159
160
161/* #######################################
162 * THE OTHER WAY TO DO THINGS
163 * #######################################
164 */
165X509_ATTRIBUTE *create_time(void)
166 {
167 ASN1_UTCTIME *sign_time;
168 X509_ATTRIBUTE *ret;
169
170 /* The last parameter is the amount to add/subtract from the current
171 * time (in seconds) */
172 sign_time=X509_gmtime_adj(NULL,0);
173 ret=X509_ATTRIBUTE_create(NID_pkcs9_signingTime,
174 V_ASN1_UTCTIME,(char *)sign_time);
175 return(ret);
176 }
177
178ASN1_UTCTIME *sk_get_time(STACK_OF(X509_ATTRIBUTE) *sk)
179 {
180 ASN1_TYPE *so;
181 PKCS7_SIGNER_INFO si;
182
183 si.auth_attr=sk;
184 so=PKCS7_get_signed_attribute(&si,NID_pkcs9_signingTime);
185 if (so->type == V_ASN1_UTCTIME)
186 return so->value.utctime;
187 return NULL;
188 }
189
190X509_ATTRIBUTE *create_string(char *str)
191 {
192 ASN1_OCTET_STRING *os;
193 X509_ATTRIBUTE *ret;
194
195 /* To a an object of OID 1.2.3.4.5, which is an octet string */
196 if (signed_string_nid == -1)
197 signed_string_nid=
198 OBJ_create("1.2.3.4.5","OID_example","Our example OID");
199 os=ASN1_OCTET_STRING_new();
200 ASN1_OCTET_STRING_set(os,str,strlen(str));
201 /* When we add, we do not free */
202 ret=X509_ATTRIBUTE_create(signed_string_nid,
203 V_ASN1_OCTET_STRING,(char *)os);
204 return(ret);
205 }
206
207int sk_get_string(STACK_OF(X509_ATTRIBUTE) *sk, char *buf, int len)
208 {
209 ASN1_TYPE *so;
210 ASN1_OCTET_STRING *os;
211 int i;
212 PKCS7_SIGNER_INFO si;
213
214 si.auth_attr=sk;
215
216 if (signed_string_nid == -1)
217 signed_string_nid=
218 OBJ_create("1.2.3.4.5","OID_example","Our example OID");
219 /* To retrieve */
220 so=PKCS7_get_signed_attribute(&si,signed_string_nid);
221 if (so != NULL)
222 {
223 if (so->type == V_ASN1_OCTET_STRING)
224 {
225 os=so->value.octet_string;
226 i=os->length;
227 if ((i+1) > len)
228 i=len-1;
229 memcpy(buf,os->data,i);
230 return(i);
231 }
232 }
233 return(0);
234 }
235
236X509_ATTRIBUTE *add_seq2string(PKCS7_SIGNER_INFO *si, char *str1, char *str2)
237 {
238 /* To add an object of OID 1.9.999, which is a sequence containing
239 * 2 octet strings */
240 unsigned char *p;
241 ASN1_OCTET_STRING *os1,*os2;
242 ASN1_STRING *seq;
243 X509_ATTRIBUTE *ret;
244 unsigned char *data;
245 int i,total;
246
247 if (signed_seq2string_nid == -1)
248 signed_seq2string_nid=
249 OBJ_create("1.9.9999","OID_example","Our example OID");
250
251 os1=ASN1_OCTET_STRING_new();
252 os2=ASN1_OCTET_STRING_new();
253 ASN1_OCTET_STRING_set(os1,str1,strlen(str1));
254 ASN1_OCTET_STRING_set(os2,str1,strlen(str1));
255 i =i2d_ASN1_OCTET_STRING(os1,NULL);
256 i+=i2d_ASN1_OCTET_STRING(os2,NULL);
257 total=ASN1_object_size(1,i,V_ASN1_SEQUENCE);
258
259 data=malloc(total);
260 p=data;
261 ASN1_put_object(&p,1,i,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL);
262 i2d_ASN1_OCTET_STRING(os1,&p);
263 i2d_ASN1_OCTET_STRING(os2,&p);
264
265 seq=ASN1_STRING_new();
266 ASN1_STRING_set(seq,data,total);
267 free(data);
268 ASN1_OCTET_STRING_free(os1);
269 ASN1_OCTET_STRING_free(os2);
270
271 ret=X509_ATTRIBUTE_create(signed_seq2string_nid,
272 V_ASN1_SEQUENCE,(char *)seq);
273 return(ret);
274 }
275
276/* For this case, I will malloc the return strings */
277int sk_get_seq2string(STACK_OF(X509_ATTRIBUTE) *sk, char **str1, char **str2)
278 {
279 ASN1_TYPE *so;
280 PKCS7_SIGNER_INFO si;
281
282 if (signed_seq2string_nid == -1)
283 signed_seq2string_nid=
284 OBJ_create("1.9.9999","OID_example","Our example OID");
285
286 si.auth_attr=sk;
287 /* To retrieve */
288 so=PKCS7_get_signed_attribute(&si,signed_seq2string_nid);
289 if (so->type == V_ASN1_SEQUENCE)
290 {
291 ASN1_CTX c;
292 ASN1_STRING *s;
293 long length;
294 ASN1_OCTET_STRING *os1,*os2;
295
296 s=so->value.sequence;
297 c.p=ASN1_STRING_data(s);
298 c.max=c.p+ASN1_STRING_length(s);
299 if (!asn1_GetSequence(&c,&length)) goto err;
300 /* Length is the length of the seqence */
301
302 c.q=c.p;
303 if ((os1=d2i_ASN1_OCTET_STRING(NULL,&c.p,c.slen)) == NULL)
304 goto err;
305 c.slen-=(c.p-c.q);
306
307 c.q=c.p;
308 if ((os2=d2i_ASN1_OCTET_STRING(NULL,&c.p,c.slen)) == NULL)
309 goto err;
310 c.slen-=(c.p-c.q);
311
312 if (!asn1_Finish(&c)) goto err;
313 *str1=malloc(os1->length+1);
314 *str2=malloc(os2->length+1);
315 memcpy(*str1,os1->data,os1->length);
316 memcpy(*str2,os2->data,os2->length);
317 (*str1)[os1->length]='\0';
318 (*str2)[os2->length]='\0';
319 ASN1_OCTET_STRING_free(os1);
320 ASN1_OCTET_STRING_free(os2);
321 return(1);
322 }
323err:
324 return(0);
325 }
326
327
diff --git a/src/lib/libcrypto/pkcs7/example.h b/src/lib/libcrypto/pkcs7/example.h
new file mode 100644
index 0000000000..96167de188
--- /dev/null
+++ b/src/lib/libcrypto/pkcs7/example.h
@@ -0,0 +1,57 @@
1/* ====================================================================
2 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * 3. All advertising materials mentioning features or use of this
17 * software must display the following acknowledgment:
18 * "This product includes software developed by the OpenSSL Project
19 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
20 *
21 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission. For written permission, please contact
24 * openssl-core@openssl.org.
25 *
26 * 5. Products derived from this software may not be called "OpenSSL"
27 * nor may "OpenSSL" appear in their names without prior written
28 * permission of the OpenSSL Project.
29 *
30 * 6. Redistributions of any form whatsoever must retain the following
31 * acknowledgment:
32 * "This product includes software developed by the OpenSSL Project
33 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46 * OF THE POSSIBILITY OF SUCH DAMAGE.
47 * ====================================================================
48 *
49 * This product includes cryptographic software written by Eric Young
50 * (eay@cryptsoft.com). This product includes software written by Tim
51 * Hudson (tjh@cryptsoft.com).
52 *
53 */
54
55int add_signed_time(PKCS7_SIGNER_INFO *si);
56ASN1_UTCTIME *get_signed_time(PKCS7_SIGNER_INFO *si);
57int get_signed_seq2string(PKCS7_SIGNER_INFO *si, char **str1, char **str2);
diff --git a/src/lib/libcrypto/pkcs7/info.pem b/src/lib/libcrypto/pkcs7/info.pem
new file mode 100644
index 0000000000..989baf8709
--- /dev/null
+++ b/src/lib/libcrypto/pkcs7/info.pem
@@ -0,0 +1,57 @@
1issuer :/C=AU/SP=Queensland/L=Brisbane/O=Cryptsoft Pty Ltd/OU=DEMONSTRATION AND TESTING/CN=DEMO ZERO VALUE CA
2subject:/C=AU/SP=Queensland/L=Brisbane/O=Cryptsoft Pty Ltd/OU=SMIME 003/CN=Information/Email=info@cryptsoft.com
3serial :047D
4
5Certificate:
6 Data:
7 Version: 3 (0x2)
8 Serial Number: 1149 (0x47d)
9 Signature Algorithm: md5withRSAEncryption
10 Issuer: C=AU, SP=Queensland, L=Brisbane, O=Cryptsoft Pty Ltd, OU=DEMONSTRATION AND TESTING, CN=DEMO ZERO VALUE CA
11 Validity
12 Not Before: May 13 05:40:58 1998 GMT
13 Not After : May 12 05:40:58 2000 GMT
14 Subject: C=AU, SP=Queensland, L=Brisbane, O=Cryptsoft Pty Ltd, OU=SMIME 003, CN=Information/Email=info@cryptsoft.com
15 Subject Public Key Info:
16 Public Key Algorithm: rsaEncryption
17 Modulus:
18 00:ad:e7:23:89:ee:0d:87:b7:9c:32:44:4b:95:81:
19 73:dd:22:80:4b:2d:c5:60:b8:fe:1e:18:63:ef:dc:
20 89:89:22:df:95:3c:7a:db:3d:9a:06:a8:08:d6:29:
21 fd:ef:41:09:91:ed:bc:ad:98:f9:f6:28:90:62:6f:
22 e7:e7:0c:4d:0b
23 Exponent: 65537 (0x10001)
24 X509v3 extensions:
25 Netscape Comment:
26 Generated with SSLeay
27 Signature Algorithm: md5withRSAEncryption
28 52:15:ea:88:f4:f0:f9:0b:ef:ce:d5:f8:83:40:61:16:5e:55:
29 f9:ce:2d:d1:8b:31:5c:03:c6:2d:10:7c:61:d5:5c:0a:42:97:
30 d1:fd:65:b6:b6:84:a5:39:ec:46:ec:fc:e0:0d:d9:22:da:1b:
31 50:74:ad:92:cb:4e:90:e5:fa:7d
32
33-----BEGIN CERTIFICATE-----
34MIICTDCCAfagAwIBAgICBH0wDQYJKoZIhvcNAQEEBQAwgZIxCzAJBgNVBAYTAkFV
35MRMwEQYDVQQIEwpRdWVlbnNsYW5kMREwDwYDVQQHEwhCcmlzYmFuZTEaMBgGA1UE
36ChMRQ3J5cHRzb2Z0IFB0eSBMdGQxIjAgBgNVBAsTGURFTU9OU1RSQVRJT04gQU5E
37IFRFU1RJTkcxGzAZBgNVBAMTEkRFTU8gWkVSTyBWQUxVRSBDQTAeFw05ODA1MTMw
38NTQwNThaFw0wMDA1MTIwNTQwNThaMIGeMQswCQYDVQQGEwJBVTETMBEGA1UECBMK
39UXVlZW5zbGFuZDERMA8GA1UEBxMIQnJpc2JhbmUxGjAYBgNVBAoTEUNyeXB0c29m
40dCBQdHkgTHRkMRIwEAYDVQQLEwlTTUlNRSAwMDMxFDASBgNVBAMTC0luZm9ybWF0
41aW9uMSEwHwYJKoZIhvcNAQkBFhJpbmZvQGNyeXB0c29mdC5jb20wXDANBgkqhkiG
429w0BAQEFAANLADBIAkEArecjie4Nh7ecMkRLlYFz3SKASy3FYLj+Hhhj79yJiSLf
43lTx62z2aBqgI1in970EJke28rZj59iiQYm/n5wxNCwIDAQABoygwJjAkBglghkgB
44hvhCAQ0EFxYVR2VuZXJhdGVkIHdpdGggU1NMZWF5MA0GCSqGSIb3DQEBBAUAA0EA
45UhXqiPTw+QvvztX4g0BhFl5V+c4t0YsxXAPGLRB8YdVcCkKX0f1ltraEpTnsRuz8
464A3ZItobUHStkstOkOX6fQ==
47-----END CERTIFICATE-----
48
49-----BEGIN RSA PRIVATE KEY-----
50MIIBOgIBAAJBAK3nI4nuDYe3nDJES5WBc90igEstxWC4/h4YY+/ciYki35U8ets9
51mgaoCNYp/e9BCZHtvK2Y+fYokGJv5+cMTQsCAwEAAQJBAIHpvXvqEcOEoDRRHuIG
52fkcB4jPHcr9KE9TpxabH6xs9beN6OJnkePXAHwaz5MnUgSnbpOKq+cw8miKjXwe/
53zVECIQDVLwncT2lRmXarEYHzb+q/0uaSvKhWKKt3kJasLNTrAwIhANDUc/ghut29
54p3jJYjurzUKuG774/5eLjPLsxPPIZzNZAiA/10hSq41UnGqHLEUIS9m2/EeEZe7b
55bm567dfRU9OnVQIgDo8ROrZXSchEGbaog5J5r/Fle83uO8l93R3GqVxKXZkCIFfk
56IPD5PIYQAyyod3hyKKza7ZP4CGY4oOfZetbkSGGG
57-----END RSA PRIVATE KEY-----
diff --git a/src/lib/libcrypto/pkcs7/infokey.pem b/src/lib/libcrypto/pkcs7/infokey.pem
new file mode 100644
index 0000000000..1e2acc954d
--- /dev/null
+++ b/src/lib/libcrypto/pkcs7/infokey.pem
@@ -0,0 +1,9 @@
1-----BEGIN RSA PRIVATE KEY-----
2MIIBOgIBAAJBAK3nI4nuDYe3nDJES5WBc90igEstxWC4/h4YY+/ciYki35U8ets9
3mgaoCNYp/e9BCZHtvK2Y+fYokGJv5+cMTQsCAwEAAQJBAIHpvXvqEcOEoDRRHuIG
4fkcB4jPHcr9KE9TpxabH6xs9beN6OJnkePXAHwaz5MnUgSnbpOKq+cw8miKjXwe/
5zVECIQDVLwncT2lRmXarEYHzb+q/0uaSvKhWKKt3kJasLNTrAwIhANDUc/ghut29
6p3jJYjurzUKuG774/5eLjPLsxPPIZzNZAiA/10hSq41UnGqHLEUIS9m2/EeEZe7b
7bm567dfRU9OnVQIgDo8ROrZXSchEGbaog5J5r/Fle83uO8l93R3GqVxKXZkCIFfk
8IPD5PIYQAyyod3hyKKza7ZP4CGY4oOfZetbkSGGG
9-----END RSA PRIVATE KEY-----
diff --git a/src/lib/libcrypto/pkcs7/t/3des.pem b/src/lib/libcrypto/pkcs7/t/3des.pem
new file mode 100644
index 0000000000..b2b5081a10
--- /dev/null
+++ b/src/lib/libcrypto/pkcs7/t/3des.pem
@@ -0,0 +1,16 @@
1-----BEGIN PKCS7-----
2MIAGCSqGSIb3DQEHA6CAMIACAQAxggHmMIHwAgEAMIGZMIGSMQswCQYDVQQGEwJBVTETMBEG
3A1UECBMKUXVlZW5zbGFuZDERMA8GA1UEBxMIQnJpc2JhbmUxGjAYBgNVBAoTEUNyeXB0c29m
4dCBQdHkgTHRkMSIwIAYDVQQLExlERU1PTlNUUkFUSU9OIEFORCBURVNUSU5HMRswGQYDVQQD
5ExJERU1PIFpFUk8gVkFMVUUgQ0ECAgR+MA0GCSqGSIb3DQEBAQUABEC2vXI1xQDW6lUHM3zQ
6/9uBEBOO5A3TtkrklAXq7v01gsIC21t52qSk36REXY+slhNZ0OQ349tgkTsoETHFLoEwMIHw
7AgEAMIGZMIGSMQswCQYDVQQGEwJBVTETMBEGA1UECBMKUXVlZW5zbGFuZDERMA8GA1UEBxMI
8QnJpc2JhbmUxGjAYBgNVBAoTEUNyeXB0c29mdCBQdHkgTHRkMSIwIAYDVQQLExlERU1PTlNU
9UkFUSU9OIEFORCBURVNUSU5HMRswGQYDVQQDExJERU1PIFpFUk8gVkFMVUUgQ0ECAgR9MA0G
10CSqGSIb3DQEBAQUABEB8ujxbabxXUYJhopuDm3oDq4JNqX6Io4p3ro+ShqfIndsXTZ1v5a2N
11WtLLCWlHn/habjBwZ/DgQgcKASbZ7QxNMIAGCSqGSIb3DQEHATAaBggqhkiG9w0DAjAOAgIA
12oAQIbsL5v1wX98KggAQoAaJ4WHm68fXY1WE5OIjfVBIDpO1K+i8dmKhjnAjrjoyZ9Bwc8rDL
13lgQg4CXb805h5xl+GfvSwUaHJayte1m2mcOhs3J2YyqbQ+MEIMIiJQccmhO3oDKm36CFvYR8
145PjpclVcZyX2ngbwPFMnBAgy0clOAE6UKAAAAAAAAAAAAAA=
15-----END PKCS7-----
16
diff --git a/src/lib/libcrypto/pkcs7/t/3dess.pem b/src/lib/libcrypto/pkcs7/t/3dess.pem
new file mode 100644
index 0000000000..23f013516a
--- /dev/null
+++ b/src/lib/libcrypto/pkcs7/t/3dess.pem
@@ -0,0 +1,32 @@
1-----BEGIN PKCS7-----
2MIIGHgYJKoZIhvcNAQcCoIIGDzCCBgsCAQExCzAJBgUrDgMCGgUAMAsGCSqGSIb3DQEHAaCC
3BGswggJTMIIB/aADAgECAgIEfjANBgkqhkiG9w0BAQQFADCBkjELMAkGA1UEBhMCQVUxEzAR
4BgNVBAgTClF1ZWVuc2xhbmQxETAPBgNVBAcTCEJyaXNiYW5lMRowGAYDVQQKExFDcnlwdHNv
5ZnQgUHR5IEx0ZDEiMCAGA1UECxMZREVNT05TVFJBVElPTiBBTkQgVEVTVElORzEbMBkGA1UE
6AxMSREVNTyBaRVJPIFZBTFVFIENBMB4XDTk4MDUxMzA2MjY1NloXDTAwMDUxMjA2MjY1Nlow
7gaUxCzAJBgNVBAYTAkFVMRMwEQYDVQQIEwpRdWVlbnNsYW5kMREwDwYDVQQHEwhCcmlzYmFu
8ZTEaMBgGA1UEChMRQ3J5cHRzb2Z0IFB0eSBMdGQxEjAQBgNVBAsTCVNNSU1FIDAwMzEZMBcG
9A1UEAxMQQW5nZWxhIHZhbiBMZWVudDEjMCEGCSqGSIb3DQEJARYUYW5nZWxhQGNyeXB0c29m
10dC5jb20wXDANBgkqhkiG9w0BAQEFAANLADBIAkEAuC3+7dAb2LhuO7gt2cTM8vsNjhG5JfDh
11hX1Vl/wVGbKEEj0MA6vWEolvefQlxB+EzwCtR0YZ7eEC/T/4JoCyeQIDAQABoygwJjAkBglg
12hkgBhvhCAQ0EFxYVR2VuZXJhdGVkIHdpdGggU1NMZWF5MA0GCSqGSIb3DQEBBAUAA0EAUnSP
13igs6TMFISTjw8cBtJYb98czgAVkVFjKyJQwYMH8FbDnCyx6NocM555nsyDstaw8fKR11Khds
14syd3ikkrhDCCAhAwggG6AgEDMA0GCSqGSIb3DQEBBAUAMIGSMQswCQYDVQQGEwJBVTETMBEG
15A1UECBMKUXVlZW5zbGFuZDERMA8GA1UEBxMIQnJpc2JhbmUxGjAYBgNVBAoTEUNyeXB0c29m
16dCBQdHkgTHRkMSIwIAYDVQQLExlERU1PTlNUUkFUSU9OIEFORCBURVNUSU5HMRswGQYDVQQD
17ExJERU1PIFpFUk8gVkFMVUUgQ0EwHhcNOTgwMzAzMDc0MTMyWhcNMDgwMjI5MDc0MTMyWjCB
18kjELMAkGA1UEBhMCQVUxEzARBgNVBAgTClF1ZWVuc2xhbmQxETAPBgNVBAcTCEJyaXNiYW5l
19MRowGAYDVQQKExFDcnlwdHNvZnQgUHR5IEx0ZDEiMCAGA1UECxMZREVNT05TVFJBVElPTiBB
20TkQgVEVTVElORzEbMBkGA1UEAxMSREVNTyBaRVJPIFZBTFVFIENBMFwwDQYJKoZIhvcNAQEB
21BQADSwAwSAJBAL+0E2fLej3FSCwe2A2iRnMuC3z12qHIp6Ky1wo2zZcxft7AI+RfkrWrSGtf
22mfzBEuPrLdfulncC5Y1pNcM8RTUCAwEAATANBgkqhkiG9w0BAQQFAANBAGSbLMphL6F5pp3s
238o0Xyh86FHFdpVOwYx09ELLkuG17V/P9pgIc0Eo/gDMbN+KT3IdgECf8S//pCRA6RrNjcXIx
24ggF7MIIBdwIBATCBmTCBkjELMAkGA1UEBhMCQVUxEzARBgNVBAgTClF1ZWVuc2xhbmQxETAP
25BgNVBAcTCEJyaXNiYW5lMRowGAYDVQQKExFDcnlwdHNvZnQgUHR5IEx0ZDEiMCAGA1UECxMZ
26REVNT05TVFJBVElPTiBBTkQgVEVTVElORzEbMBkGA1UEAxMSREVNTyBaRVJPIFZBTFVFIENB
27AgIEfjAJBgUrDgMCGgUAoHowGAYJKoZIhvcNAQkDMQsGCSqGSIb3DQEHATAbBgkqhkiG9w0B
28CQ8xDjAMMAoGCCqGSIb3DQMHMBwGCSqGSIb3DQEJBTEPFw05ODA1MTQwMzM5MzdaMCMGCSqG
29SIb3DQEJBDEWBBQstNMnSV26ba8PapQEDhO21yNFrjANBgkqhkiG9w0BAQEFAARAW9Xb9YXv
30BfcNkutgFX9Gr8iXhBVsNtGEVrjrpkQwpKa7jHI8SjAlLhk/4RFwDHf+ISB9Np3Z1WDWnLcA
319CWR6g==
32-----END PKCS7-----
diff --git a/src/lib/libcrypto/pkcs7/t/c.pem b/src/lib/libcrypto/pkcs7/t/c.pem
new file mode 100644
index 0000000000..a4b55e321a
--- /dev/null
+++ b/src/lib/libcrypto/pkcs7/t/c.pem
@@ -0,0 +1,48 @@
1issuer :/C=AU/SP=Queensland/L=Brisbane/O=Cryptsoft Pty Ltd/OU=DEMONSTRATION AND TESTING/CN=DEMO ZERO VALUE CA
2subject:/C=AU/SP=Queensland/L=Brisbane/O=Cryptsoft Pty Ltd/OU=SMIME 003/CN=Information/Email=info@cryptsoft.com
3serial :047D
4
5Certificate:
6 Data:
7 Version: 3 (0x2)
8 Serial Number: 1149 (0x47d)
9 Signature Algorithm: md5withRSAEncryption
10 Issuer: C=AU, SP=Queensland, L=Brisbane, O=Cryptsoft Pty Ltd, OU=DEMONSTRATION AND TESTING, CN=DEMO ZERO VALUE CA
11 Validity
12 Not Before: May 13 05:40:58 1998 GMT
13 Not After : May 12 05:40:58 2000 GMT
14 Subject: C=AU, SP=Queensland, L=Brisbane, O=Cryptsoft Pty Ltd, OU=SMIME 003, CN=Information/Email=info@cryptsoft.com
15 Subject Public Key Info:
16 Public Key Algorithm: rsaEncryption
17 Modulus:
18 00:ad:e7:23:89:ee:0d:87:b7:9c:32:44:4b:95:81:
19 73:dd:22:80:4b:2d:c5:60:b8:fe:1e:18:63:ef:dc:
20 89:89:22:df:95:3c:7a:db:3d:9a:06:a8:08:d6:29:
21 fd:ef:41:09:91:ed:bc:ad:98:f9:f6:28:90:62:6f:
22 e7:e7:0c:4d:0b
23 Exponent: 65537 (0x10001)
24 X509v3 extensions:
25 Netscape Comment:
26 Generated with SSLeay
27 Signature Algorithm: md5withRSAEncryption
28 52:15:ea:88:f4:f0:f9:0b:ef:ce:d5:f8:83:40:61:16:5e:55:
29 f9:ce:2d:d1:8b:31:5c:03:c6:2d:10:7c:61:d5:5c:0a:42:97:
30 d1:fd:65:b6:b6:84:a5:39:ec:46:ec:fc:e0:0d:d9:22:da:1b:
31 50:74:ad:92:cb:4e:90:e5:fa:7d
32
33-----BEGIN CERTIFICATE-----
34MIICTDCCAfagAwIBAgICBH0wDQYJKoZIhvcNAQEEBQAwgZIxCzAJBgNVBAYTAkFV
35MRMwEQYDVQQIEwpRdWVlbnNsYW5kMREwDwYDVQQHEwhCcmlzYmFuZTEaMBgGA1UE
36ChMRQ3J5cHRzb2Z0IFB0eSBMdGQxIjAgBgNVBAsTGURFTU9OU1RSQVRJT04gQU5E
37IFRFU1RJTkcxGzAZBgNVBAMTEkRFTU8gWkVSTyBWQUxVRSBDQTAeFw05ODA1MTMw
38NTQwNThaFw0wMDA1MTIwNTQwNThaMIGeMQswCQYDVQQGEwJBVTETMBEGA1UECBMK
39UXVlZW5zbGFuZDERMA8GA1UEBxMIQnJpc2JhbmUxGjAYBgNVBAoTEUNyeXB0c29m
40dCBQdHkgTHRkMRIwEAYDVQQLEwlTTUlNRSAwMDMxFDASBgNVBAMTC0luZm9ybWF0
41aW9uMSEwHwYJKoZIhvcNAQkBFhJpbmZvQGNyeXB0c29mdC5jb20wXDANBgkqhkiG
429w0BAQEFAANLADBIAkEArecjie4Nh7ecMkRLlYFz3SKASy3FYLj+Hhhj79yJiSLf
43lTx62z2aBqgI1in970EJke28rZj59iiQYm/n5wxNCwIDAQABoygwJjAkBglghkgB
44hvhCAQ0EFxYVR2VuZXJhdGVkIHdpdGggU1NMZWF5MA0GCSqGSIb3DQEBBAUAA0EA
45UhXqiPTw+QvvztX4g0BhFl5V+c4t0YsxXAPGLRB8YdVcCkKX0f1ltraEpTnsRuz8
464A3ZItobUHStkstOkOX6fQ==
47-----END CERTIFICATE-----
48
diff --git a/src/lib/libcrypto/pkcs7/t/ff b/src/lib/libcrypto/pkcs7/t/ff
new file mode 100644
index 0000000000..23f013516a
--- /dev/null
+++ b/src/lib/libcrypto/pkcs7/t/ff
@@ -0,0 +1,32 @@
1-----BEGIN PKCS7-----
2MIIGHgYJKoZIhvcNAQcCoIIGDzCCBgsCAQExCzAJBgUrDgMCGgUAMAsGCSqGSIb3DQEHAaCC
3BGswggJTMIIB/aADAgECAgIEfjANBgkqhkiG9w0BAQQFADCBkjELMAkGA1UEBhMCQVUxEzAR
4BgNVBAgTClF1ZWVuc2xhbmQxETAPBgNVBAcTCEJyaXNiYW5lMRowGAYDVQQKExFDcnlwdHNv
5ZnQgUHR5IEx0ZDEiMCAGA1UECxMZREVNT05TVFJBVElPTiBBTkQgVEVTVElORzEbMBkGA1UE
6AxMSREVNTyBaRVJPIFZBTFVFIENBMB4XDTk4MDUxMzA2MjY1NloXDTAwMDUxMjA2MjY1Nlow
7gaUxCzAJBgNVBAYTAkFVMRMwEQYDVQQIEwpRdWVlbnNsYW5kMREwDwYDVQQHEwhCcmlzYmFu
8ZTEaMBgGA1UEChMRQ3J5cHRzb2Z0IFB0eSBMdGQxEjAQBgNVBAsTCVNNSU1FIDAwMzEZMBcG
9A1UEAxMQQW5nZWxhIHZhbiBMZWVudDEjMCEGCSqGSIb3DQEJARYUYW5nZWxhQGNyeXB0c29m
10dC5jb20wXDANBgkqhkiG9w0BAQEFAANLADBIAkEAuC3+7dAb2LhuO7gt2cTM8vsNjhG5JfDh
11hX1Vl/wVGbKEEj0MA6vWEolvefQlxB+EzwCtR0YZ7eEC/T/4JoCyeQIDAQABoygwJjAkBglg
12hkgBhvhCAQ0EFxYVR2VuZXJhdGVkIHdpdGggU1NMZWF5MA0GCSqGSIb3DQEBBAUAA0EAUnSP
13igs6TMFISTjw8cBtJYb98czgAVkVFjKyJQwYMH8FbDnCyx6NocM555nsyDstaw8fKR11Khds
14syd3ikkrhDCCAhAwggG6AgEDMA0GCSqGSIb3DQEBBAUAMIGSMQswCQYDVQQGEwJBVTETMBEG
15A1UECBMKUXVlZW5zbGFuZDERMA8GA1UEBxMIQnJpc2JhbmUxGjAYBgNVBAoTEUNyeXB0c29m
16dCBQdHkgTHRkMSIwIAYDVQQLExlERU1PTlNUUkFUSU9OIEFORCBURVNUSU5HMRswGQYDVQQD
17ExJERU1PIFpFUk8gVkFMVUUgQ0EwHhcNOTgwMzAzMDc0MTMyWhcNMDgwMjI5MDc0MTMyWjCB
18kjELMAkGA1UEBhMCQVUxEzARBgNVBAgTClF1ZWVuc2xhbmQxETAPBgNVBAcTCEJyaXNiYW5l
19MRowGAYDVQQKExFDcnlwdHNvZnQgUHR5IEx0ZDEiMCAGA1UECxMZREVNT05TVFJBVElPTiBB
20TkQgVEVTVElORzEbMBkGA1UEAxMSREVNTyBaRVJPIFZBTFVFIENBMFwwDQYJKoZIhvcNAQEB
21BQADSwAwSAJBAL+0E2fLej3FSCwe2A2iRnMuC3z12qHIp6Ky1wo2zZcxft7AI+RfkrWrSGtf
22mfzBEuPrLdfulncC5Y1pNcM8RTUCAwEAATANBgkqhkiG9w0BAQQFAANBAGSbLMphL6F5pp3s
238o0Xyh86FHFdpVOwYx09ELLkuG17V/P9pgIc0Eo/gDMbN+KT3IdgECf8S//pCRA6RrNjcXIx
24ggF7MIIBdwIBATCBmTCBkjELMAkGA1UEBhMCQVUxEzARBgNVBAgTClF1ZWVuc2xhbmQxETAP
25BgNVBAcTCEJyaXNiYW5lMRowGAYDVQQKExFDcnlwdHNvZnQgUHR5IEx0ZDEiMCAGA1UECxMZ
26REVNT05TVFJBVElPTiBBTkQgVEVTVElORzEbMBkGA1UEAxMSREVNTyBaRVJPIFZBTFVFIENB
27AgIEfjAJBgUrDgMCGgUAoHowGAYJKoZIhvcNAQkDMQsGCSqGSIb3DQEHATAbBgkqhkiG9w0B
28CQ8xDjAMMAoGCCqGSIb3DQMHMBwGCSqGSIb3DQEJBTEPFw05ODA1MTQwMzM5MzdaMCMGCSqG
29SIb3DQEJBDEWBBQstNMnSV26ba8PapQEDhO21yNFrjANBgkqhkiG9w0BAQEFAARAW9Xb9YXv
30BfcNkutgFX9Gr8iXhBVsNtGEVrjrpkQwpKa7jHI8SjAlLhk/4RFwDHf+ISB9Np3Z1WDWnLcA
319CWR6g==
32-----END PKCS7-----
diff --git a/src/lib/libcrypto/pkcs7/t/msie-e b/src/lib/libcrypto/pkcs7/t/msie-e
new file mode 100644
index 0000000000..aafae69fc9
--- /dev/null
+++ b/src/lib/libcrypto/pkcs7/t/msie-e
@@ -0,0 +1,20 @@
1
2MIAGCSqGSIb3DQEHA6CAMIACAQAxggHCMIHMAgEAMHYwYjERMA8GA1UEBxMISW50ZXJuZXQxFzAV
3BgNVBAoTDlZlcmlTaWduLCBJbmMuMTQwMgYDVQQLEytWZXJpU2lnbiBDbGFzcyAxIENBIC0gSW5k
4aXZpZHVhbCBTdWJzY3JpYmVyAhBgQJiC3qfbCbjdj5INYLnKMA0GCSqGSIb3DQEBAQUABECMzu8y
5wQ/qZbO8cAGMRBF+mPruv3+Dvb9aWNZ2k8njUgqF6mcdhVB2MkGcsG3memRXJBixvMYWVkU3qK4Z
6VuKsMIHwAgEAMIGZMIGSMQswCQYDVQQGEwJBVTETMBEGA1UECBMKUXVlZW5zbGFuZDERMA8GA1UE
7BxMIQnJpc2JhbmUxGjAYBgNVBAoTEUNyeXB0c29mdCBQdHkgTHRkMSIwIAYDVQQLExlERU1PTlNU
8UkFUSU9OIEFORCBURVNUSU5HMRswGQYDVQQDExJERU1PIFpFUk8gVkFMVUUgQ0ECAgRuMA0GCSqG
9SIb3DQEBAQUABEBcWwYFHJbJGhiztt7lzue3Lc9CH5WAbyR+2BZ3uv+JxZfRs1PuaWPOwRa0Vgs3
10YwSJoRfxQj2Gk0wFqG1qt6d1MIAGCSqGSIb3DQEHATAaBggqhkiG9w0DAjAOAgIAoAQI8vRlP/Nx
112iSggASCAZhR5srxyspy7DfomRJ9ff8eMCtaNwEoEx7G25PZRonC57hBvGoScLtEPU3Wp9FEbPN7
12oJESeC+AqMTyTLNy8aQsyC5s53E9UkoIvg62ekYZBbXZqXsrxx4PhiiX3NH8GVh42phB0Chjw0nK
13HZeRDmxGY3Cmk+J+l0uVKxbNIfJIKOguLBnhqmnKH/PrnzDt591u0ULy2aTLqRm+4/1Yat/QPb6J
14eoKGwNPBbS9ogBdrCNCp9ZFg3Xar2AtQHzyTQIfYeH3SRQUpKmRm5U5o9p5emgEdT+ZfJm/J4tSH
15OmbgAFsbHQakA4MBZ4J5qfDJhOA2g5lWk1hIeu5Dn/AaLRZd0yz3oY0Ieo/erPWx/bCqtBzYbMe9
16qSFTedKlbc9EGe3opOTdBZVzK8KH3w3zsy5luxKdOUG59YYb5F1IZiWGiDyuo/HuacX+griu5LeD
17bEzOtZnko+TZXvWIko30fD79j3T4MRRhWXbgj2HKza+4vJ0mzcC/1+GPsJjAEAA/JgIEDU4w6/DI
18/HQHhLAO3G+9xKD7MvmrzkoAAAAAAAAAAAAA
19
20
diff --git a/src/lib/libcrypto/pkcs7/t/msie-e.pem b/src/lib/libcrypto/pkcs7/t/msie-e.pem
new file mode 100644
index 0000000000..a2a5e24e74
--- /dev/null
+++ b/src/lib/libcrypto/pkcs7/t/msie-e.pem
@@ -0,0 +1,22 @@
1-----BEGIN PKCS7-----
2MIAGCSqGSIb3DQEHA6CAMIIDkAIBADGCAcIwgcwCAQAwdjBiMREwDwYDVQQHEwhJ
3bnRlcm5ldDEXMBUGA1UEChMOVmVyaVNpZ24sIEluYy4xNDAyBgNVBAsTK1ZlcmlT
4aWduIENsYXNzIDEgQ0EgLSBJbmRpdmlkdWFsIFN1YnNjcmliZXICEGBAmILep9sJ
5uN2Pkg1gucowDQYJKoZIhvcNAQEBBQAEQIzO7zLBD+pls7xwAYxEEX6Y+u6/f4O9
6v1pY1naTyeNSCoXqZx2FUHYyQZywbeZ6ZFckGLG8xhZWRTeorhlW4qwwgfACAQAw
7gZkwgZIxCzAJBgNVBAYTAkFVMRMwEQYDVQQIEwpRdWVlbnNsYW5kMREwDwYDVQQH
8EwhCcmlzYmFuZTEaMBgGA1UEChMRQ3J5cHRzb2Z0IFB0eSBMdGQxIjAgBgNVBAsT
9GURFTU9OU1RSQVRJT04gQU5EIFRFU1RJTkcxGzAZBgNVBAMTEkRFTU8gWkVSTyBW
10QUxVRSBDQQICBG4wDQYJKoZIhvcNAQEBBQAEQFxbBgUclskaGLO23uXO57ctz0If
11lYBvJH7YFne6/4nFl9GzU+5pY87BFrRWCzdjBImhF/FCPYaTTAWobWq3p3UwggHD
12BgkqhkiG9w0BBwEwGgYIKoZIhvcNAwIwDgICAKAECPL0ZT/zcdokgIIBmFHmyvHK
13ynLsN+iZEn19/x4wK1o3ASgTHsbbk9lGicLnuEG8ahJwu0Q9Tdan0URs83ugkRJ4
14L4CoxPJMs3LxpCzILmzncT1SSgi+DrZ6RhkFtdmpeyvHHg+GKJfc0fwZWHjamEHQ
15KGPDScodl5EObEZjcKaT4n6XS5UrFs0h8kgo6C4sGeGqacof8+ufMO3n3W7RQvLZ
16pMupGb7j/Vhq39A9vol6gobA08FtL2iAF2sI0Kn1kWDddqvYC1AfPJNAh9h4fdJF
17BSkqZGblTmj2nl6aAR1P5l8mb8ni1Ic6ZuAAWxsdBqQDgwFngnmp8MmE4DaDmVaT
18WEh67kOf8BotFl3TLPehjQh6j96s9bH9sKq0HNhsx72pIVN50qVtz0QZ7eik5N0F
19lXMrwoffDfOzLmW7Ep05Qbn1hhvkXUhmJYaIPK6j8e5pxf6CuK7kt4NsTM61meSj
205Nle9YiSjfR8Pv2PdPgxFGFZduCPYcrNr7i8nSbNwL/X4Y+wmMAQAD8mAgQNTjDr
218Mj8dAeEsA7cb73EoPsy+avOSgAAAAA=
22-----END PKCS7-----
diff --git a/src/lib/libcrypto/pkcs7/t/msie-enc-01 b/src/lib/libcrypto/pkcs7/t/msie-enc-01
new file mode 100644
index 0000000000..2c93ab6462
--- /dev/null
+++ b/src/lib/libcrypto/pkcs7/t/msie-enc-01
@@ -0,0 +1,62 @@
1
2MIAGCSqGSIb3DQEHA6CAMIACAQAxgfMwgfACAQAwgZkwgZIxCzAJBgNVBAYTAkFVMRMwEQYD
3VQQIEwpRdWVlbnNsYW5kMREwDwYDVQQHEwhCcmlzYmFuZTEaMBgGA1UEChMRQ3J5cHRzb2Z0
4IFB0eSBMdGQxIjAgBgNVBAsTGURFTU9OU1RSQVRJT04gQU5EIFRFU1RJTkcxGzAZBgNVBAMT
5EkRFTU8gWkVSTyBWQUxVRSBDQQICBG4wDQYJKoZIhvcNAQEBBQAEQKvMaW8xh6oF/X+CJivz
6IZV7yHxlp4O3NHQtWG0A8MOZB+CtKlU7/6g5e/a9Du/TOqxRMqtYRp63pa2Q/mM4IYMwgAYJ
7KoZIhvcNAQcBMBoGCCqGSIb3DQMCMA4CAgCgBAifz6RvzOPYlKCABIGwxtGA/FLBBRs1wbBP
8gDCbSG0yCwjJNsFg89/k6xuXo8c5YTwsw8+XlIVq03navpew6XxxzY090rD2OJ0t6HA6GqrI
9pd8WiSh/Atqn0yfLFmkLqgIAPRfzxUxqUocxLpQsLIFp2YNUGE+yps+UZmIjw/WHfdqrcWTm
10STSvKuy3UkIJZCkGDBpTvqk4BFaHh4oTXEpgpNY+GKxjf9TDN9GQPqQZR7sgQki4t2g4/Saq
11Kl4EMISgluk6swdND0tiHY7v5d6YR29ePCl2/STJ98eJpWkEEC22GNNvOy7ru/Rv2He4MgQg
12optd7sk9MMd9xhJppg7CcH/yDx//HrtgpOcWmn6VxpgECFqon4uXkQtIBIH4PaNclFn7/hLx
13Pw2VmBGaC0SYF3U1jyN96EBxdjqy8Aa6ByMXYDW5BcfqniD5mYXfw+b81lh1kutxaPaV4YJ9
14ZlRUW752N7VHo/fG0/fukoe5W9a8kIhgLpygllb/GP4oSF4wM6n1/OgRzZj2IWFiobKO4d/t
15Mnh+C+PoEVAuFZcxQwi9GqvsK5OoIjVwNx0XcVSOl1TTYS9SwC7ugMBCab73JiruC24pL78Y
16M+NaIpIQ3On4DokJA2ZHtjBjZIxF4tKA144RvFN6pBd6TVE5XM6KD/Vh9bjSmujtEAfdQ3Te
17dvKJsbZuu0stErbvWcRy11I328l557EECAJT7d44OJ3rBBBj6bnnx6dDU2SRqp2CEoQaBAhK
18RBuyhNxkygQIOY9/NhwqAJAECOvX0Zd0DqgoBAjobPpMHhVV3gQQWLU2vEoZ51BwzxdzCmxO
19wwQI4oKfudaNqoAESKzBNAqv5kGumHOlMKsRfrs7jZCcSaOuEj97pYx08FLEgF23cav39MOQ
20NUEM1dNU+EYslL4o3RoSHRjUgPU+2t9c0prS9A/bPARIEOP94PynaTNxwHi3VTK7SzuQmgzA
214n942E9joSiqsQPlsKAb3sPUaLC3SuUxSjNBgfpvD0bmrA/5h+WZoYXvIogFpwjkSmnFBEie
220lh5Ov1aRrvCw5/j3Q/W/4ZtN5U+aeVBJMtA8n0Mxd5kPxHbNVh4oGprZ6wEegV8ht3voyZa
23mZ5Cyxc8ffMYnM/JJI6/oEYEUEMyyiS5FnYyvxKzfMtyn2lZ2st9nZGNNgMc9N62r5HgNbdD
24FHuRdKKzV+8kQfuMc3mOPpK1t9TFY+QgrxiB5p6S7VooI97YtP3PbfknszCEBEh4PdXYbbaR
253AacN3Q5kYYmWsq3WW6xgrg0mmEGosGvwSQxBBuiXZrxScCa4ivEq05UZwyShePvKduOvnUE
262zDO6IXFLZxhTZAESEm9/FovLgGAiJ7iMGmYvsISLJScwG4n+wrSaQNQXizs9N3ykys54wBN
27d/+BQ4F7pncHhDQ2Dyt5MekB8Y8iNOocUTFCu524vQRIaWCXmXP3vU7D21dp0XnAMzRQJ565
28JV3aHRoY7XDa4LePa7PP9ywyafOE5yCW7ndqx3J+2JhTDvSFsW8/q3H3iyeFhykuJVS6BFDK
296CmKbnyyjOfE2iLGJmTFa905V2KrVDCmlEu/xyGMs80yTyZC+ySzM83FMVvLEQmSzcTNUZVp
30DfA1kNXbXkPouBXXT6g8r8JCRljaKKABmgRIlMheOJQRUUU4cgvhMreXPayhq5Ao4VMSCkA5
31hYRCBczm4Di/MMohF0SxIsdRY6gY9CPnrBXAsY6h1RbR7Tw0iQZmeXi52DCiBEj0by+SYMAa
329z0CReIzl8JLL6EVIFz8kFxlkGWjr4dnOzhhPOq/mCpp0WxbavDfdhE87MdXJZBnLwoT62QG
33955HlAoEQBOGJbcESCgd5XSirZ9Y3AbCfuKOqoMBvEUGn+w/pMaqnGvnr5FZhuBDKrhRXqtx
34QsxA//drGUxsrZOuSL/0+fbvo7n2h1Z8Ny86jOvVZAQIAjw2l1Yc5RAESNc9i3I8pKEOVQf/
35UBczJ0NR9aTEF80dRg2lpXwD0ho4N0AvSiVbgxC7cPZHQwIqvq9LHRUs/4n+Vu3SVYU3cAxo
36lUTiCGUSlARIF+TD57SI5+RI+MNtnD9rs4E1ml51YoHGWFj3UPriDmY0FKEwIgqtMXMY3fZ9
37Kq8d83bjDzxwbDX7WwR7KbSeJWT42pCz7kM+BEjjPsOnZHuusXT3x2rrsBnYtYsbt98mSFiS
38KzTtFmXfkOBbCQdit1P76QnYJ1aXMGs6zP6GypQTadK/zYWvlm38QkVwueaJ0woESKW2pqKA
3970h2UMDHOrpepU1lj0YMzmotDHSTU3L909VvUMNg9uqfrQ6mSkb9j5Tl8oF2otOw5EzA1Yda
40KPmgsv62RWLYl80wXQRQwG0e/mgG75jp9lOhJdVXqcYbQpS9viwVaVkwH+69mu/bQI4gjoEs
41UYX6O71Re2z+cYhcm9UrK+DXuSFBXQOIlAFxKMW4B0apd6fU84FsZLMESOorXE5OE0A2B2ji
42J8QI0Exk4hUvWrMNJfUZwFyS7E05xV9ORuX1xmsKqkT4tVR5Nqln4vhvAY860VBoloz0CDkd
438seSBEjeMgRI9FvpYuflIeHg9urkwp6N+1f0DrJJhJY9ZQ0HTQhziJmIfvbEjNqCl7hEC28+
44F8I5tuViLgfSwcFFCvnS6WFoN4X6QdFdqMCbBEjdlI1c+IQGA/IuTDMJYCuQ/v+8BG5ZeWVH
45icPZmXfRat9eFK1dGKAJef6+Tf9HPuDjSpDyffrifsp7Dc34lmm7GN1+ON3ZMtwEUNm6epb8
461RKWjoI7jIKUV/M2p/0eeGSqs4b06KF/VR6dBwsJVL5DpnTsp3MV4j/CAOlRdSPZ5++tsKbM
47aplk+ceqQtpEFz1MYTtVV4+rlrWaBEA1okJyNZ5/tNOwM7B+XfOZ0xw+uyVi9v4byTZM2Qds
48J+d3YGYLAugTGHISLqQEerD8/gGK+/SL06b2gNedXPHtBAiBKX+Mdy3wFQQIqE9gVgvrFNUE
49CKKoTFoMGqnPBAjDPgLCklNfrwQI3Ek1vSq68w8ECBodu2FOZJVkBAgzwjfSr2N9WQQQTCoQ
50KkAbrS9tnjXn1I3+ZwQIrPx3eINo/YUECIeYWCFskxlYBAiDUdvZXwD3vgQIkEyZbbZWbUUE
51CH4+odl1Isk3BBj68fkqJ0fKJRWVLWuW/O3VE4BOPKwFlaIECFseVTdDUho8BAj+cOKvV2WA
52hgQgaXr+wwq+ItblG0Qxz8IVUXX6PV2mIdHwz4SCCvnCsaIECJhBYxdfLI/XBCDswamPn9MR
53yXi2HVQBineV+GtWVkIoZ2dCLFB9mQRMoAQI0nUR5a5AOJoECA+AunKlAlx8BAi5RtFeF4g1
54FQQIz/ie+16LlQcECOmNuVg5DXjMBAjH2nkfpXZgWwQIVdLuO/+kuHAECO/5rEHmyI9vBBD4
5516BU4Rd3YerDQnHtrwOQBCCkho1XxK5Maz8KLCNi20wvcGt8wsIXlj2h5q9ITBq7IgQQvKVY
564OfJ7bKbItP2dylwQgQYPIGxwkkbRXNraONYvN19G8UdF35rFOuIBAjf0sKz/618ZQQIxObr
57xJkRe0sECIC+ssnjEb2NBBBI+XM4OntVWGsRV9Td3sFgBAinGwIroo8O0gQQMGAwgc9PaLaG
58gBCiwSTrYQQIVHjfCQgOtygEUIoraFoANfhZgIShpOd/RRxFU4/7xZR5tMdGoYz/g0thR0lM
59+Hi88FtFD4mAh/Oat4Ri8B7bv04aokjN2UHz6nPbHHjZ8zIqpbYTCy043GNZBAhOqjyB2JbD
60NwQoR23XCYD9x6E20ChHJRXmaHwyMdYXKl5CUxypl7ois+sy2D7jDukS3wQIsTyyPgJi0GsA
61AAAAAAAAAAAA
62
diff --git a/src/lib/libcrypto/pkcs7/t/msie-enc-01.pem b/src/lib/libcrypto/pkcs7/t/msie-enc-01.pem
new file mode 100644
index 0000000000..9abf00b2f2
--- /dev/null
+++ b/src/lib/libcrypto/pkcs7/t/msie-enc-01.pem
@@ -0,0 +1,66 @@
1-----BEGIN PKCS7-----
2MIAGCSqGSIb3DQEHA6CAMIILyAIBADGB8zCB8AIBADCBmTCBkjELMAkGA1UEBhMC
3QVUxEzARBgNVBAgTClF1ZWVuc2xhbmQxETAPBgNVBAcTCEJyaXNiYW5lMRowGAYD
4VQQKExFDcnlwdHNvZnQgUHR5IEx0ZDEiMCAGA1UECxMZREVNT05TVFJBVElPTiBB
5TkQgVEVTVElORzEbMBkGA1UEAxMSREVNTyBaRVJPIFZBTFVFIENBAgIEbjANBgkq
6hkiG9w0BAQEFAARAq8xpbzGHqgX9f4ImK/MhlXvIfGWng7c0dC1YbQDww5kH4K0q
7VTv/qDl79r0O79M6rFEyq1hGnrelrZD+YzghgzCCCssGCSqGSIb3DQEHATAaBggq
8hkiG9w0DAjAOAgIAoAQIn8+kb8zj2JSAggqgxtGA/FLBBRs1wbBPgDCbSG0yCwjJ
9NsFg89/k6xuXo8c5YTwsw8+XlIVq03navpew6XxxzY090rD2OJ0t6HA6GqrIpd8W
10iSh/Atqn0yfLFmkLqgIAPRfzxUxqUocxLpQsLIFp2YNUGE+yps+UZmIjw/WHfdqr
11cWTmSTSvKuy3UkIJZCkGDBpTvqk4BFaHh4oTXEpgpNY+GKxjf9TDN9GQPqQZR7sg
12Qki4t2g4/SaqKl6EoJbpOrMHTQ9LYh2O7+XemEdvXjwpdv0kyffHiaVpBBAtthjT
13bzsu67v0b9h3uDKim13uyT0wx33GEmmmDsJwf/IPH/8eu2Ck5xaafpXGmFqon4uX
14kQtIPaNclFn7/hLxPw2VmBGaC0SYF3U1jyN96EBxdjqy8Aa6ByMXYDW5BcfqniD5
15mYXfw+b81lh1kutxaPaV4YJ9ZlRUW752N7VHo/fG0/fukoe5W9a8kIhgLpygllb/
16GP4oSF4wM6n1/OgRzZj2IWFiobKO4d/tMnh+C+PoEVAuFZcxQwi9GqvsK5OoIjVw
17Nx0XcVSOl1TTYS9SwC7ugMBCab73JiruC24pL78YM+NaIpIQ3On4DokJA2ZHtjBj
18ZIxF4tKA144RvFN6pBd6TVE5XM6KD/Vh9bjSmujtEAfdQ3TedvKJsbZuu0stErbv
19WcRy11I328l557ECU+3eODid62PpuefHp0NTZJGqnYIShBpKRBuyhNxkyjmPfzYc
20KgCQ69fRl3QOqCjobPpMHhVV3li1NrxKGedQcM8XcwpsTsPigp+51o2qgKzBNAqv
215kGumHOlMKsRfrs7jZCcSaOuEj97pYx08FLEgF23cav39MOQNUEM1dNU+EYslL4o
223RoSHRjUgPU+2t9c0prS9A/bPBDj/eD8p2kzccB4t1Uyu0s7kJoMwOJ/eNhPY6Eo
23qrED5bCgG97D1Giwt0rlMUozQYH6bw9G5qwP+YflmaGF7yKIBacI5EppxZ7SWHk6
24/VpGu8LDn+PdD9b/hm03lT5p5UEky0DyfQzF3mQ/Eds1WHigamtnrAR6BXyG3e+j
25JlqZnkLLFzx98xicz8kkjr+gRkMyyiS5FnYyvxKzfMtyn2lZ2st9nZGNNgMc9N62
26r5HgNbdDFHuRdKKzV+8kQfuMc3mOPpK1t9TFY+QgrxiB5p6S7VooI97YtP3Pbfkn
27szCEeD3V2G22kdwGnDd0OZGGJlrKt1lusYK4NJphBqLBr8EkMQQbol2a8UnAmuIr
28xKtOVGcMkoXj7ynbjr51BNswzuiFxS2cYU2QSb38Wi8uAYCInuIwaZi+whIslJzA
29bif7CtJpA1BeLOz03fKTKznjAE13/4FDgXumdweENDYPK3kx6QHxjyI06hxRMUK7
30nbi9aWCXmXP3vU7D21dp0XnAMzRQJ565JV3aHRoY7XDa4LePa7PP9ywyafOE5yCW
317ndqx3J+2JhTDvSFsW8/q3H3iyeFhykuJVS6yugpim58soznxNoixiZkxWvdOVdi
32q1QwppRLv8chjLPNMk8mQvskszPNxTFbyxEJks3EzVGVaQ3wNZDV215D6LgV10+o
33PK/CQkZY2iigAZqUyF44lBFRRThyC+Eyt5c9rKGrkCjhUxIKQDmFhEIFzObgOL8w
34yiEXRLEix1FjqBj0I+esFcCxjqHVFtHtPDSJBmZ5eLnYMKL0by+SYMAa9z0CReIz
35l8JLL6EVIFz8kFxlkGWjr4dnOzhhPOq/mCpp0WxbavDfdhE87MdXJZBnLwoT62QG
36955HlAoEQBOGJbcoHeV0oq2fWNwGwn7ijqqDAbxFBp/sP6TGqpxr56+RWYbgQyq4
37UV6rcULMQP/3axlMbK2Trki/9Pn276O59odWfDcvOozr1WQCPDaXVhzlENc9i3I8
38pKEOVQf/UBczJ0NR9aTEF80dRg2lpXwD0ho4N0AvSiVbgxC7cPZHQwIqvq9LHRUs
39/4n+Vu3SVYU3cAxolUTiCGUSlBfkw+e0iOfkSPjDbZw/a7OBNZpedWKBxlhY91D6
404g5mNBShMCIKrTFzGN32fSqvHfN24w88cGw1+1sEeym0niVk+NqQs+5DPuM+w6dk
41e66xdPfHauuwGdi1ixu33yZIWJIrNO0WZd+Q4FsJB2K3U/vpCdgnVpcwazrM/obK
42lBNp0r/Nha+WbfxCRXC55onTCqW2pqKA70h2UMDHOrpepU1lj0YMzmotDHSTU3L9
4309VvUMNg9uqfrQ6mSkb9j5Tl8oF2otOw5EzA1YdaKPmgsv62RWLYl80wXcBtHv5o
44Bu+Y6fZToSXVV6nGG0KUvb4sFWlZMB/uvZrv20COII6BLFGF+ju9UXts/nGIXJvV
45Kyvg17khQV0DiJQBcSjFuAdGqXen1POBbGSz6itcTk4TQDYHaOInxAjQTGTiFS9a
46sw0l9RnAXJLsTTnFX05G5fXGawqqRPi1VHk2qWfi+G8BjzrRUGiWjPQIOR3yx5IE
47SN4y9FvpYuflIeHg9urkwp6N+1f0DrJJhJY9ZQ0HTQhziJmIfvbEjNqCl7hEC28+
48F8I5tuViLgfSwcFFCvnS6WFoN4X6QdFdqMCb3ZSNXPiEBgPyLkwzCWArkP7/vARu
49WXllR4nD2Zl30WrfXhStXRigCXn+vk3/Rz7g40qQ8n364n7Kew3N+JZpuxjdfjjd
502TLc2bp6lvzVEpaOgjuMgpRX8zan/R54ZKqzhvTooX9VHp0HCwlUvkOmdOyncxXi
51P8IA6VF1I9nn762wpsxqmWT5x6pC2kQXPUxhO1VXj6uWtZo1okJyNZ5/tNOwM7B+
52XfOZ0xw+uyVi9v4byTZM2QdsJ+d3YGYLAugTGHISLqQEerD8/gGK+/SL06b2gNed
53XPHtgSl/jHct8BWoT2BWC+sU1aKoTFoMGqnPwz4CwpJTX6/cSTW9KrrzDxodu2FO
54ZJVkM8I30q9jfVlMKhAqQButL22eNefUjf5nrPx3eINo/YWHmFghbJMZWINR29lf
55APe+kEyZbbZWbUV+PqHZdSLJN/rx+SonR8olFZUta5b87dUTgE48rAWVolseVTdD
56Uho8/nDir1dlgIZpev7DCr4i1uUbRDHPwhVRdfo9XaYh0fDPhIIK+cKxophBYxdf
57LI/X7MGpj5/TEcl4th1UAYp3lfhrVlZCKGdnQixQfZkETKDSdRHlrkA4mg+AunKl
58Alx8uUbRXheINRXP+J77XouVB+mNuVg5DXjMx9p5H6V2YFtV0u47/6S4cO/5rEHm
59yI9v+NegVOEXd2Hqw0Jx7a8DkKSGjVfErkxrPwosI2LbTC9wa3zCwheWPaHmr0hM
60GrsivKVY4OfJ7bKbItP2dylwQjyBscJJG0Vza2jjWLzdfRvFHRd+axTriN/SwrP/
61rXxlxObrxJkRe0uAvrLJ4xG9jUj5czg6e1VYaxFX1N3ewWCnGwIroo8O0jBgMIHP
62T2i2hoAQosEk62FUeN8JCA63KIoraFoANfhZgIShpOd/RRxFU4/7xZR5tMdGoYz/
63g0thR0lM+Hi88FtFD4mAh/Oat4Ri8B7bv04aokjN2UHz6nPbHHjZ8zIqpbYTCy04
643GNZTqo8gdiWwzdHbdcJgP3HoTbQKEclFeZofDIx1hcqXkJTHKmXuiKz6zLYPuMO
656RLfsTyyPgJi0GsAAAAA
66-----END PKCS7-----
diff --git a/src/lib/libcrypto/pkcs7/t/msie-enc-02 b/src/lib/libcrypto/pkcs7/t/msie-enc-02
new file mode 100644
index 0000000000..7017055965
--- /dev/null
+++ b/src/lib/libcrypto/pkcs7/t/msie-enc-02
@@ -0,0 +1,90 @@
1
2MIAGCSqGSIb3DQEHA6CAMIACAQAxggHCMIHMAgEAMHYwYjERMA8GA1UEBxMISW50ZXJuZXQxFzAV
3BgNVBAoTDlZlcmlTaWduLCBJbmMuMTQwMgYDVQQLEytWZXJpU2lnbiBDbGFzcyAxIENBIC0gSW5k
4aXZpZHVhbCBTdWJzY3JpYmVyAhBgQJiC3qfbCbjdj5INYLnKMA0GCSqGSIb3DQEBAQUABEACr4tn
5kSzvo3aIlHfJLGbfokNCV6FjdDP1vQhL+kdXONqcFCEf9ReETCvaHslIr/Wepc5j2hjZselzgqLn
6rM1ZMIHwAgEAMIGZMIGSMQswCQYDVQQGEwJBVTETMBEGA1UECBMKUXVlZW5zbGFuZDERMA8GA1UE
7BxMIQnJpc2JhbmUxGjAYBgNVBAoTEUNyeXB0c29mdCBQdHkgTHRkMSIwIAYDVQQLExlERU1PTlNU
8UkFUSU9OIEFORCBURVNUSU5HMRswGQYDVQQDExJERU1PIFpFUk8gVkFMVUUgQ0ECAgRuMA0GCSqG
9SIb3DQEBAQUABEBanBxKOvUoRn3DiFY55lly2TPu2Cv+dI/GLrzW6qvnUMZPWGPGaUlPyWLMZrXJ
10xGXZUiRJKTBwDu91fnodUEK9MIAGCSqGSIb3DQEHATAaBggqhkiG9w0DAjAOAgIAoAQImxKZEDWP
11EuOggASCBACBi1bX/qc3geqFyfRpX7JyIo/g4CDr62GlwvassAGlIO8zJ5Z/UDIIooeV6QS4D4OW
12PymKd0WXhwcJI0yBcJTWEoxND27LM7CWFJpA07AoxVCRHTOPgm794NynLecNUOqVTFyS4CRuLhVG
13PAk0nFZG/RE2yMtx4rAkSiVgOexES7wq/xWuoDSSmuTMNQOTbKfkEKqdFLkM/d62gD2wnaph7vKk
14PPK82wdZP8rF3nUUC5c4ahbNoa8g+5B3tIF/Jz3ZZK3vGLU0IWO+i7W451dna13MglDDjXOeikNl
15XLsQdAVo0nsjfGu+f66besJojPzysNA+IEZl6gNWUetl9lim4SqrxubUExdS2rmXnXXmEuEW/HC7
16dlTAeYq5Clqx5id6slhC2C2oegMww3XH9yxHw6OqzvXY6pVPEScEtBMQLgaKFQT+m2SRtbTVFG7c
17QcnUODyVB1IbpQTF1DHeeOX1W/HfpWZym8dzkti6SCyeumHmqO406xDiIMVKtHOqM86nEHuAMZsr
18cLy+ey6TEJvR6S4N8QRzng8JJDZDTJXQN6q84aEudsnOrw2KyOVwPpI6ey4qBsHUgQ8kAFy5lsQa
19WV45h6exgUwbBcKLgPZGFj+OdD2RKJsTb83/UqbJS5Q/lGXhzBlnaYucyJxEprRxbntmcnOEPFJe
20+tRDUwOTd7qlJljdhIJL+uDcooL9Ahgo6Cwep6tduekv2cSEohJeTE8Dvy34YRhMbLvnFNdmnpNy
21rNZDYVVxxaKoyd2AfB8NPFZh1VdAYfI3R1QAQ2kXEef5NNIfVQfMzD9akJn4RP+Kv32Qaxm4FrnK
22xmwRyGJShavIBc2ax+F1r1+NZXuSBHn5vfoRTxOk0ST4dXsw74dnlYUMRaSu4qqUdM9jsXSyeX4Z
23gQgkR2bkaYO6ezFgenFIa7QWVw8rXZAEZ5aibCxbnY1VE41PYIvhlLdbFJhH9gY22s+fFAuwnzyA
24SRjC40A9aAEItRlaPStWSGiqlLRgNkBBwdpv2l2YPBd2QzHx6ek6XGrvRJuAC+Nh62rtQKwpNH54
25YAOHW55maBFW2SQ3TF+cZ6NbbqhCmHTyyR7mcSYc9sXSVDWEhYKQ1iyU870zhHWVpvglZizZetJC
26ZFjYex3b1ngVdcgargOvpPq9urCKKi2mbkqv/EFpzSWGXkKSpfCG/XfMnEOtkNrB8S06vnk2JcJB
27OBqJot+uuSH5hOg0vTpxX2DuONJSiWSWyfRE/lTfJJFXwhod7SXclUyXPeSyibcSic2hVAzDmwjD
2831js/j2k02PI/agPhr3UQ8cMgcNAiaoCKbNaWfn6BGbCAbTchxzUlo2cSJiLlrX2IDZmfXbXmZCo
29m1smWIG+BIIEALiuAxDb6dWLAYyVBoN9hYI4AiPeZAY9MtvQ6AV8o2/EFm6PvYGXy3Hei5830CH0
30PBeX7Kdd6ff1y33TW/l5qSkIL1ULTGR7okFfJePHDmq1dFt6/JOMptiQ8WSu7CsJQvZ9VTFXeYFc
31ZqCPPZc1NrPegNK70Zf9QxWIbDAevJ5KLBf1c6j8pU2/6LnvDY6VjaTvYSgr7vTR8eVzH4Rm77W0
32iOHxg5VcODv6cGSVyuvbX8UAGo8Cmb58ERDtBDJBQXVpWKLNAuDJ9GX8n2zNkpjZLbPSkcmuhqGa
33BJBE/BaCTkUQWlY9dIbRtEnxIU1mfbPPdx1Ppa8DqGDjSOsQdKcKYNNZtayEw++EIpmpdBNsKphC
34fB8UEK2Wkk4ZVW+qyGoi/r0MFsvO1NmSOOZ0o/jy/YHmoeURHhPy97AO3eVTkEAa5CfJEJybmo56
357CDw/FwoGAUCgsoz7rlxzMudr/IhHIH+APinncxXlHO2ecvHD9i8DaHGA8tVifgsUhqQoZieULut
36eF94O5UAxOkv41UZssYTwN4nYrN1QkesZl3BX4ORS4EE30/PQ23ARf3WZptZrCJevGm2ZYzGeh8x
37g17mCDfiLO+bff4qP/4mC96Pu4ia6j4to5BwKIJS/+DCuoD8WeSKF4pugXQkMUiHdQnNnVP9Sp2O
38/4ly5mO8JzrQC59V2bnTNBqPhpno8kfJvK5TypPSVC+bTzern3rJ6UceB3srcn9zxKx9GdNydJQj
39yWjv8ec3n3d1nuQwhz5Q053NBhIjwoGg3Go7LO6i78ZOlpF7dcoAO13NfHLyNjnyHCaiWtVRTct9
40rLf5vN00urSn8YJngHk1eTKK8nHGIcOg6YdYDOD2nE5XwRijKmieG8Xa3eKRzfbL06GrBQENle6J
41mC131bp3cRVxpjq+o6RAbGoMm4yICsL4eTarCQrsyHmoPHqr91UHo91avyxU7knWmEhX27ybmsrs
428aeZwPHixL14TeyhruCqRVvkf1Ks7P+z8MPUboGNqQe2WLN8ktCGEr15O8MJR/em86G03Jfo4oaw
43/DVUH5RwLT6acedOGuzMh/2r8BcmemhVQ8/cWvV4YJ0tOW4hzyVHC5hQf8sZ3LzxXLH6Ohnrbprh
44xvrdbaSdChWZDDP0bCCbxEhkwuBkBeKZrMbwRTP+TPTPYLVTH/CmKLzKh/114tkGkyO3hHS4qExU
45V39F2Sj4mylx+hD0+20D9pntpNi7htccGlOm6yNM69at/3+kLgJJyoIlaxLcCUYHNMifDt+T3p/t
465U4XmD53uUQ6M8dvj/udqPekNSUfse15yrd9pjOt5PcJuqW28q0sFHf9pHIgz3XZFMe5PD7ppw6r
47S+C6Ir4PrYIEggQA7ZDVtiCm+BbtNNB/UJm79/OQ5mp5bTI0kPmDeycaWTa0Ojpum+c/dpG/iJOB
48DICj7jHOXSHT7JlGyX6aSFJUltucAnZvwzhPDmdDaIDiKSk85GqgdDWVfGosSCX9Ph/T3WpIxnwf
49WSDRtIHkWTjly+pe4yy5K6/XISy/L5Zh/fhiI5fjHjgzmlibs2ru4nVw6hBhUvlSSe2BEs5d9h/y
50NH8Wy3qvb2D3jh7hkepFtZJGNTHp8ZUC7Ns2JIpQYObsaxdI65i3mMOu7fRwI+0/4ejsWhP6KCEi
51LgwvLg0qM82ma6YB7qHAHboaczRVEffDcJUG4a5uycB0DoZFn+uEaEFyili20hCn4hVfsqUQk2PT
528Mo1tSl5e30xI1YJZrRgiJm9nHRX6fLizngP+ILJLPHZsPvlSVIfY+/v/FR8feKOjaGhyGF51BAx
53aM2NIQ4jMP5/X+U5gQybi0E6u7rroDhaHsKmCMgXqszwXWCpedA/sEbeHpiTC59YlPPSlIOMc9vP
54Ko/mQCfWy/9icUaIfKQldvkllUxxNkqu6AbIpHVscbAEzSPs5xbQXU8EZNNCDisFnnpY3nQ3eLnl
55m89saTJxRb7NWHRMlmPv7qgD7uMIq3vdOGA7i5wT9MeoNIgK1/DsgH30s6RWjJy4YyyLmRTXPzbj
56hbQVpEmiMRbEidIvUx2OjKVxVQIcgtLsa2lvHQ4XL1cpLr5GVtOgy0fMg5OCDUUDsvjgjgLQ3P2U
57p2nVY5FM6/QpPc5DTLuuR9ekI2/c9Biz09RtcYDUQK2ajdo8h1IyKqHFoB7h48OXxXKKY94DY0TG
58x6PonB/epj8orAw4QKmm5M0vXYwBOqRymCTHTqOJGObdLx1euFFyqguzHJOU2gAGZI0z9Lg1yRuF
59yhdPZyuniIcmtLNxRZ1duYHErcAyX56qndmLXt7UVkATai/rIMuoJLfAsUnVuTUS5p7tJM754UZT
607lTcXvDJgOUNnBRaIcxC3pxvbrYDJ2iFJ72xkxUP2p74gucqg25XnCVmQuLg6zDDxF6CLuw9isxy
61Xg4pkneMN//7fpp8GYl9nyZm2yqYYM+jcw0fcVc64L+X4w/gL3H2UMGgxIHSJp7HIG7VKHtXrNyj
62dPXXPVUsMsAAimqOr0Lr2sZWirfuivLaPTqhbkvG5PF7K3gT80AOIcd/6EIHBy2hZ7ukfjHmdP4L
63yQOhTQklaKzGHI0mypq0uFLWJOUlZnVrMiLP1xrWkpC8Ro9eo6mfjjQ45z8adC43a47klwTEzvod
643rNEFIGJJUEjAN3mbqie7IxoSJknBBJK0D9lZEQ8lZWlq7vuN8JdqPM6xh155jMVsPwjLK6Tzkj5
65BpRD9Tgm3u6HPQSCBADgkWEN75Mu9TGosXY0xm1k6K6sPv8L949CrLWo4r1I2LA072bTGvQP28Vs
66hUA76jgcT1ocC++9PoktIK10YCq5w+FfMAQ04KeCXuAdmiY2iAT4Slea61PMCMta3mVGyLUZCLEm
67P+I0UKR5mlO0fGEcjU9j8TmbjZqxNFqloLsU7oSi7Os0EtYHkdAVrExUyOc/ZDie6fBjdLTmLdCm
68bE9JNwjlbXypdTZupGgLNhKGDIskUAAMwZYayI6YfSIMkNCeAYTnjOuGZZ1msCXGXsfMBR1sfUIj
699UeGjwD8gq+UVVHX/oeoH/m0eJ5ppqi3+nUlgc9DvpYsC/Fg0G2KuYb9B+VJ+a4GMzQSPREoFtQp
70B9dtLkBb7Ha/hpGWTIdqzW0eAo5llyN8FNvl2Fu2IcLaNmWFO69gLjRKQopp0dvFOuwAVI6fvGDj
71p1WigoNbFZl8N+iiWmzKOjoG2ZLbez1clZCms/JPJrXhEMMOxWpVzkQyN336VWHmGgMcjaKCGSeA
722nnESIGuiCXMrkHlGfabYIsKcHFCo2t13uXyZPf0zSPTkuD0Eh92wqC9pvA3gvrrCUfo9Mn3bs+e
73KWKmDlpcs8mDn032oIg+zrQhIduMqXVn3evzeVM3B5MBOGMvg51/SXg7R+MC/463juQQEb9IVe/I
74YGnO//oWm9lw/377Af/qH+FnN02obJw1FvesQIs9e5RHNQykKbO+vmVJQl1nd9DZWrHDNO7/80Yz
752hCm7Tws5nSRN2iFlyRaYJHr7ypxkU2rCak2r6ua7XDwu1qU2RT3+qPjT1RuxQ2oTlHyGkKPMZGC
76Rc+CSWz5aeeCmHZVwdb3nC8YpfsujMiYqygLeuQ82pjKuR7DIKGmnfcOLdv5F+Ek2Wyy0D98iSgk
77+aoQGYLhL9llU13pn21uRsDY5uGcXiIw1IETFlTdgENEv8futZuJsegrp7fmFXyNoNyFNyypeDrM
786ZqR4vKxFjg3tKKeVpkw/W4EAklzMxmNiazGNDBHsnYV3rwPlKa+HeeE2YxnsKwGLCNgRYUXTaJk
79461vS160z3dvh/mLfdZ7MYCkmO3bNE3ELUDAw7YQkSuo9ujzdFKte9LC34sjg9fOex3ThAg5Y50n
80wYm4zBmGM7yEqL8O6QgnM6tIDFS9XryDaLNzcGhMWqMvhzO6sC/AA2WfLgwS517Cp03IkJQWqG9q
81w52+E+GAtpioJfczEhlv9BrhjttdugRSjJrG8SYVYE4zG3Aur5eNBoGaALIOHOtPw8+JovQmIWcF
82oaJ/WQuglFrWtew51IK6F8RiHAOBVavZOuZcO7tV+5enVfreOd0rX8ZOy4hYmHhmF1hOrrWOn+Ee
83E0SYKonXN01BM9xMBIIBSLCvNAppnGPTUGjwbMJRg1VJ2KMiBWH5oJp8tyfIAxMuWFdtaLYbRSOD
84XbOAshPVK8JAY8DQDkzqaCTAkLTfSRAt9yY6SbUpMsRv7xa8nMZNJBJzJT9b/wNjgiOJgaGuJMkV
852g/DX2jfP3PrMM/Sbnz7edORXHj1Pa5XTT8nG5MS0FuZgvevdq3o/gVVAz+ZCKOH3ShMzZvfp01l
86SX5gaJTflmU6cdNwtn2yZ6IScF7OrjUeA9iEoSVR9dQcA+4lB3RAG3LMwcnxXY35D7+PMJzHIZdF
87cSnq+n03ACY2/E/T31iijRH29rvYHGI+mP/ieYs45iq4fTWo6i1HofeWLdP0fX7xW3XO0/hWYFiw
88BxKu66whAbRhaib3XJNvetVs25ToYXyiDpjG+cd5rCMei8sGQwTBj9Zeh0URoeMW1inTP0JvCmMU
89rZgAAAAAAAAAAAAA
90
diff --git a/src/lib/libcrypto/pkcs7/t/msie-enc-02.pem b/src/lib/libcrypto/pkcs7/t/msie-enc-02.pem
new file mode 100644
index 0000000000..279c5d830b
--- /dev/null
+++ b/src/lib/libcrypto/pkcs7/t/msie-enc-02.pem
@@ -0,0 +1,106 @@
1-----BEGIN PKCS7-----
2MIAGCSqGSIb3DQEHA6CAMIITQAIBADGCAcIwgcwCAQAwdjBiMREwDwYDVQQHEwhJ
3bnRlcm5ldDEXMBUGA1UEChMOVmVyaVNpZ24sIEluYy4xNDAyBgNVBAsTK1ZlcmlT
4aWduIENsYXNzIDEgQ0EgLSBJbmRpdmlkdWFsIFN1YnNjcmliZXICEGBAmILep9sJ
5uN2Pkg1gucowDQYJKoZIhvcNAQEBBQAEQAKvi2eRLO+jdoiUd8ksZt+iQ0JXoWN0
6M/W9CEv6R1c42pwUIR/1F4RMK9oeyUiv9Z6lzmPaGNmx6XOCoueszVkwgfACAQAw
7gZkwgZIxCzAJBgNVBAYTAkFVMRMwEQYDVQQIEwpRdWVlbnNsYW5kMREwDwYDVQQH
8EwhCcmlzYmFuZTEaMBgGA1UEChMRQ3J5cHRzb2Z0IFB0eSBMdGQxIjAgBgNVBAsT
9GURFTU9OU1RSQVRJT04gQU5EIFRFU1RJTkcxGzAZBgNVBAMTEkRFTU8gWkVSTyBW
10QUxVRSBDQQICBG4wDQYJKoZIhvcNAQEBBQAEQFqcHEo69ShGfcOIVjnmWXLZM+7Y
11K/50j8YuvNbqq+dQxk9YY8ZpSU/JYsxmtcnEZdlSJEkpMHAO73V+eh1QQr0wghFz
12BgkqhkiG9w0BBwEwGgYIKoZIhvcNAwIwDgICAKAECJsSmRA1jxLjgIIRSIGLVtf+
13pzeB6oXJ9GlfsnIij+DgIOvrYaXC9qywAaUg7zMnln9QMgiih5XpBLgPg5Y/KYp3
14RZeHBwkjTIFwlNYSjE0PbsszsJYUmkDTsCjFUJEdM4+Cbv3g3Kct5w1Q6pVMXJLg
15JG4uFUY8CTScVkb9ETbIy3HisCRKJWA57ERLvCr/Fa6gNJKa5Mw1A5Nsp+QQqp0U
16uQz93raAPbCdqmHu8qQ88rzbB1k/ysXedRQLlzhqFs2hryD7kHe0gX8nPdlkre8Y
17tTQhY76LtbjnV2drXcyCUMONc56KQ2VcuxB0BWjSeyN8a75/rpt6wmiM/PKw0D4g
18RmXqA1ZR62X2WKbhKqvG5tQTF1LauZeddeYS4Rb8cLt2VMB5irkKWrHmJ3qyWELY
19Lah6AzDDdcf3LEfDo6rO9djqlU8RJwS0ExAuBooVBP6bZJG1tNUUbtxBydQ4PJUH
20UhulBMXUMd545fVb8d+lZnKbx3OS2LpILJ66Yeao7jTrEOIgxUq0c6ozzqcQe4Ax
21mytwvL57LpMQm9HpLg3xBHOeDwkkNkNMldA3qrzhoS52yc6vDYrI5XA+kjp7LioG
22wdSBDyQAXLmWxBpZXjmHp7GBTBsFwouA9kYWP450PZEomxNvzf9SpslLlD+UZeHM
23GWdpi5zInESmtHFue2Zyc4Q8Ul761ENTA5N3uqUmWN2Egkv64Nyigv0CGCjoLB6n
24q1256S/ZxISiEl5MTwO/LfhhGExsu+cU12aek3Ks1kNhVXHFoqjJ3YB8Hw08VmHV
25V0Bh8jdHVABDaRcR5/k00h9VB8zMP1qQmfhE/4q/fZBrGbgWucrGbBHIYlKFq8gF
26zZrH4XWvX41le5IEefm9+hFPE6TRJPh1ezDvh2eVhQxFpK7iqpR0z2OxdLJ5fhmB
27CCRHZuRpg7p7MWB6cUhrtBZXDytdkARnlqJsLFudjVUTjU9gi+GUt1sUmEf2Bjba
28z58UC7CfPIBJGMLjQD1oAQi1GVo9K1ZIaKqUtGA2QEHB2m/aXZg8F3ZDMfHp6Tpc
29au9Em4AL42Hrau1ArCk0fnhgA4dbnmZoEVbZJDdMX5xno1tuqEKYdPLJHuZxJhz2
30xdJUNYSFgpDWLJTzvTOEdZWm+CVmLNl60kJkWNh7HdvWeBV1yBquA6+k+r26sIoq
31LaZuSq/8QWnNJYZeQpKl8Ib9d8ycQ62Q2sHxLTq+eTYlwkE4Gomi3665IfmE6DS9
32OnFfYO440lKJZJbJ9ET+VN8kkVfCGh3tJdyVTJc95LKJtxKJzaFUDMObCMPfWOz+
33PaTTY8j9qA+GvdRDxwyBw0CJqgIps1pZ+foEZsIBtNyHHNSWjZxImIuWtfYgNmZ9
34dteZkKibWyZYgb64rgMQ2+nViwGMlQaDfYWCOAIj3mQGPTLb0OgFfKNvxBZuj72B
35l8tx3oufN9Ah9DwXl+ynXen39ct901v5eakpCC9VC0xke6JBXyXjxw5qtXRbevyT
36jKbYkPFkruwrCUL2fVUxV3mBXGagjz2XNTaz3oDSu9GX/UMViGwwHryeSiwX9XOo
37/KVNv+i57w2OlY2k72EoK+700fHlcx+EZu+1tIjh8YOVXDg7+nBklcrr21/FABqP
38Apm+fBEQ7QQyQUF1aViizQLgyfRl/J9szZKY2S2z0pHJroahmgSQRPwWgk5FEFpW
39PXSG0bRJ8SFNZn2zz3cdT6WvA6hg40jrEHSnCmDTWbWshMPvhCKZqXQTbCqYQnwf
40FBCtlpJOGVVvqshqIv69DBbLztTZkjjmdKP48v2B5qHlER4T8vewDt3lU5BAGuQn
41yRCcm5qOeuwg8PxcKBgFAoLKM+65cczLna/yIRyB/gD4p53MV5RztnnLxw/YvA2h
42xgPLVYn4LFIakKGYnlC7rXhfeDuVAMTpL+NVGbLGE8DeJ2KzdUJHrGZdwV+DkUuB
43BN9Pz0NtwEX91mabWawiXrxptmWMxnofMYNe5gg34izvm33+Kj/+Jgvej7uImuo+
44LaOQcCiCUv/gwrqA/FnkiheKboF0JDFIh3UJzZ1T/Uqdjv+JcuZjvCc60AufVdm5
450zQaj4aZ6PJHybyuU8qT0lQvm083q596yelHHgd7K3J/c8SsfRnTcnSUI8lo7/Hn
46N593dZ7kMIc+UNOdzQYSI8KBoNxqOyzuou/GTpaRe3XKADtdzXxy8jY58hwmolrV
47UU3Lfay3+bzdNLq0p/GCZ4B5NXkyivJxxiHDoOmHWAzg9pxOV8EYoyponhvF2t3i
48kc32y9OhqwUBDZXuiZgtd9W6d3EVcaY6vqOkQGxqDJuMiArC+Hk2qwkK7Mh5qDx6
49q/dVB6PdWr8sVO5J1phIV9u8m5rK7PGnmcDx4sS9eE3soa7gqkVb5H9SrOz/s/DD
501G6BjakHtlizfJLQhhK9eTvDCUf3pvOhtNyX6OKGsPw1VB+UcC0+mnHnThrszIf9
51q/AXJnpoVUPP3Fr1eGCdLTluIc8lRwuYUH/LGdy88Vyx+joZ626a4cb63W2knQoV
52mQwz9Gwgm8RIZMLgZAXimazG8EUz/kz0z2C1Ux/wpii8yof9deLZBpMjt4R0uKhM
53VFd/Rdko+JspcfoQ9PttA/aZ7aTYu4bXHBpTpusjTOvWrf9/pC4CScqCJWsS3AlG
54BzTInw7fk96f7eVOF5g+d7lEOjPHb4/7naj3pDUlH7Htecq3faYzreT3CbqltvKt
55LBR3/aRyIM912RTHuTw+6acOq0vguiK+D62C7ZDVtiCm+BbtNNB/UJm79/OQ5mp5
56bTI0kPmDeycaWTa0Ojpum+c/dpG/iJOBDICj7jHOXSHT7JlGyX6aSFJUltucAnZv
57wzhPDmdDaIDiKSk85GqgdDWVfGosSCX9Ph/T3WpIxnwfWSDRtIHkWTjly+pe4yy5
58K6/XISy/L5Zh/fhiI5fjHjgzmlibs2ru4nVw6hBhUvlSSe2BEs5d9h/yNH8Wy3qv
59b2D3jh7hkepFtZJGNTHp8ZUC7Ns2JIpQYObsaxdI65i3mMOu7fRwI+0/4ejsWhP6
60KCEiLgwvLg0qM82ma6YB7qHAHboaczRVEffDcJUG4a5uycB0DoZFn+uEaEFyili2
610hCn4hVfsqUQk2PT8Mo1tSl5e30xI1YJZrRgiJm9nHRX6fLizngP+ILJLPHZsPvl
62SVIfY+/v/FR8feKOjaGhyGF51BAxaM2NIQ4jMP5/X+U5gQybi0E6u7rroDhaHsKm
63CMgXqszwXWCpedA/sEbeHpiTC59YlPPSlIOMc9vPKo/mQCfWy/9icUaIfKQldvkl
64lUxxNkqu6AbIpHVscbAEzSPs5xbQXU8EZNNCDisFnnpY3nQ3eLnlm89saTJxRb7N
65WHRMlmPv7qgD7uMIq3vdOGA7i5wT9MeoNIgK1/DsgH30s6RWjJy4YyyLmRTXPzbj
66hbQVpEmiMRbEidIvUx2OjKVxVQIcgtLsa2lvHQ4XL1cpLr5GVtOgy0fMg5OCDUUD
67svjgjgLQ3P2Up2nVY5FM6/QpPc5DTLuuR9ekI2/c9Biz09RtcYDUQK2ajdo8h1Iy
68KqHFoB7h48OXxXKKY94DY0TGx6PonB/epj8orAw4QKmm5M0vXYwBOqRymCTHTqOJ
69GObdLx1euFFyqguzHJOU2gAGZI0z9Lg1yRuFyhdPZyuniIcmtLNxRZ1duYHErcAy
70X56qndmLXt7UVkATai/rIMuoJLfAsUnVuTUS5p7tJM754UZT7lTcXvDJgOUNnBRa
71IcxC3pxvbrYDJ2iFJ72xkxUP2p74gucqg25XnCVmQuLg6zDDxF6CLuw9isxyXg4p
72kneMN//7fpp8GYl9nyZm2yqYYM+jcw0fcVc64L+X4w/gL3H2UMGgxIHSJp7HIG7V
73KHtXrNyjdPXXPVUsMsAAimqOr0Lr2sZWirfuivLaPTqhbkvG5PF7K3gT80AOIcd/
746EIHBy2hZ7ukfjHmdP4LyQOhTQklaKzGHI0mypq0uFLWJOUlZnVrMiLP1xrWkpC8
75Ro9eo6mfjjQ45z8adC43a47klwTEzvod3rNEFIGJJUEjAN3mbqie7IxoSJknBBJK
760D9lZEQ8lZWlq7vuN8JdqPM6xh155jMVsPwjLK6Tzkj5BpRD9Tgm3u6HPeCRYQ3v
77ky71MaixdjTGbWTorqw+/wv3j0KstajivUjYsDTvZtMa9A/bxWyFQDvqOBxPWhwL
78770+iS0grXRgKrnD4V8wBDTgp4Je4B2aJjaIBPhKV5rrU8wIy1reZUbItRkIsSY/
794jRQpHmaU7R8YRyNT2PxOZuNmrE0WqWguxTuhKLs6zQS1geR0BWsTFTI5z9kOJ7p
808GN0tOYt0KZsT0k3COVtfKl1Nm6kaAs2EoYMiyRQAAzBlhrIjph9IgyQ0J4BhOeM
8164ZlnWawJcZex8wFHWx9QiP1R4aPAPyCr5RVUdf+h6gf+bR4nmmmqLf6dSWBz0O+
82liwL8WDQbYq5hv0H5Un5rgYzNBI9ESgW1CkH120uQFvsdr+GkZZMh2rNbR4CjmWX
83I3wU2+XYW7Yhwto2ZYU7r2AuNEpCimnR28U67ABUjp+8YOOnVaKCg1sVmXw36KJa
84bMo6OgbZktt7PVyVkKaz8k8mteEQww7FalXORDI3ffpVYeYaAxyNooIZJ4DaecRI
85ga6IJcyuQeUZ9ptgiwpwcUKja3Xe5fJk9/TNI9OS4PQSH3bCoL2m8DeC+usJR+j0
86yfduz54pYqYOWlyzyYOfTfagiD7OtCEh24ypdWfd6/N5UzcHkwE4Yy+DnX9JeDtH
874wL/jreO5BARv0hV78hgac7/+hab2XD/fvsB/+of4Wc3TahsnDUW96xAiz17lEc1
88DKQps76+ZUlCXWd30NlascM07v/zRjPaEKbtPCzmdJE3aIWXJFpgkevvKnGRTasJ
89qTavq5rtcPC7WpTZFPf6o+NPVG7FDahOUfIaQo8xkYJFz4JJbPlp54KYdlXB1vec
90Lxil+y6MyJirKAt65DzamMq5HsMgoaad9w4t2/kX4STZbLLQP3yJKCT5qhAZguEv
912WVTXemfbW5GwNjm4ZxeIjDUgRMWVN2AQ0S/x+61m4mx6Cunt+YVfI2g3IU3LKl4
92OszpmpHi8rEWODe0op5WmTD9bgQCSXMzGY2JrMY0MEeydhXevA+Upr4d54TZjGew
93rAYsI2BFhRdNomTjrW9LXrTPd2+H+Yt91nsxgKSY7ds0TcQtQMDDthCRK6j26PN0
94Uq170sLfiyOD1857HdOECDljnSfBibjMGYYzvISovw7pCCczq0gMVL1evINos3Nw
95aExaoy+HM7qwL8ADZZ8uDBLnXsKnTciQlBaob2rDnb4T4YC2mKgl9zMSGW/0GuGO
962126BFKMmsbxJhVgTjMbcC6vl40GgZoAsg4c60/Dz4mi9CYhZwWhon9ZC6CUWta1
977DnUgroXxGIcA4FVq9k65lw7u1X7l6dV+t453Stfxk7LiFiYeGYXWE6utY6f4R4T
98RJgqidc3TUEz3EywrzQKaZxj01Bo8GzCUYNVSdijIgVh+aCafLcnyAMTLlhXbWi2
99G0Ujg12zgLIT1SvCQGPA0A5M6mgkwJC030kQLfcmOkm1KTLEb+8WvJzGTSQScyU/
100W/8DY4IjiYGhriTJFdoPw19o3z9z6zDP0m58+3nTkVx49T2uV00/JxuTEtBbmYL3
101r3at6P4FVQM/mQijh90oTM2b36dNZUl+YGiU35ZlOnHTcLZ9smeiEnBezq41HgPY
102hKElUfXUHAPuJQd0QBtyzMHJ8V2N+Q+/jzCcxyGXRXEp6vp9NwAmNvxP099Yoo0R
1039va72BxiPpj/4nmLOOYquH01qOotR6H3li3T9H1+8Vt1ztP4VmBYsAcSruusIQG0
104YWom91yTb3rVbNuU6GF8og6YxvnHeawjHovLBkMEwY/WXodFEaHjFtYp0z9Cbwpj
105FK2YAAAAAA==
106-----END PKCS7-----
diff --git a/src/lib/libcrypto/pkcs7/t/msie-s-a-e b/src/lib/libcrypto/pkcs7/t/msie-s-a-e
new file mode 100644
index 0000000000..0067794d70
--- /dev/null
+++ b/src/lib/libcrypto/pkcs7/t/msie-s-a-e
@@ -0,0 +1,91 @@
1
2MIAGCSqGSIb3DQEHA6CAMIACAQAxggHCMIHMAgEAMHYwYjERMA8GA1UEBxMISW50ZXJuZXQxFzAV
3BgNVBAoTDlZlcmlTaWduLCBJbmMuMTQwMgYDVQQLEytWZXJpU2lnbiBDbGFzcyAxIENBIC0gSW5k
4aXZpZHVhbCBTdWJzY3JpYmVyAhBgQJiC3qfbCbjdj5INYLnKMA0GCSqGSIb3DQEBAQUABECjscaS
5G0U299fqiEAgTqTFQBp8Ai6zzjl557cVb3k6z4QZ7CbqBjSXAjLbh5e7S5Hd/FrFcDnxl1Ka06ha
6VHGPMIHwAgEAMIGZMIGSMQswCQYDVQQGEwJBVTETMBEGA1UECBMKUXVlZW5zbGFuZDERMA8GA1UE
7BxMIQnJpc2JhbmUxGjAYBgNVBAoTEUNyeXB0c29mdCBQdHkgTHRkMSIwIAYDVQQLExlERU1PTlNU
8UkFUSU9OIEFORCBURVNUSU5HMRswGQYDVQQDExJERU1PIFpFUk8gVkFMVUUgQ0ECAgRuMA0GCSqG
9SIb3DQEBAQUABECsyHXZ1xaiv0UQRvOmVYsaF38AL2XX75wxbCsz5/wOg7g3RP4aicZxaR4sBog0
10f2G1o9om/hu+A0rIYF/L4/GUMIAGCSqGSIb3DQEHATAaBggqhkiG9w0DAjAOAgIAoAQIsozQrnwj
11cc2ggASCBAAQz/LPoJe/+iYWeTwSebz6Q9UeKZzQ2UWm7GLtEM3s3c9SCvpmkwIRdEhLjWaBJMyI
12DiL7t1I1vMf9inB8LXgAcIEYkpNScjS8ERA9Ebb7ieNKSBg7w7B8ATHFxLSlDADqRgoZrB1Ctfgf
13ximp3EgxTgnhtyQhZxXW7kBQyFRwumplrJXOp7albP7IothrOKncw30IJT1fwPxWNMItI9juXF0U
14CbWVSjPzGBo4+XNXMvUO6MplOQEz/ywEQ9E8OZAQex1Zw9qq5ppsXB2pMsYV5sLJGikukMYKquiz
153YK+tN6J8ahLcDUs+VGwqvZi17gpBTlbEP+ZmXJpnO63t1yTEB0V5AZcRKWUOhzlCBM5YUagqNoY
16cpsmSvOK6bYzkUKOrzWpDCAtGZ/Dvul5dTZZmxs2WpM+iyeHXMxO3huy8K1brPTqt1f1sHhuq1jD
171eXedaCjIgUW9qV18vNAQCof/Yb6T/1fxztf/jD7pPLQJ+7LJkKCAEHGcaizpoKqhYcttaEhLq1G
18O+Ohqf7yFegMdTJ3wwP324w5ZYSU5fLo2Z34/Edf6EGvXyTIqVfAmEBALd6JGVdN5GlYYTxrL+eO
19P80Z4ao4YKoxwEmRp5bmQsQ8B29QhOFKmC6eiG5B96qLMtp7Zmu1grDNxTd6OXShWVwYARD0/B1P
20Sy0PAfk9Gb4fAkO9fZJDQYZ7s0mM5iOPEeSR7820TolOb+KfRabLA9d714jsc2jEykKlpP66Bh4j
21aCsyqJ0uUQcE8SnzrKAqGwgWiCGQpiTa+HBiP6eRlRGOKQj5Y06vcNx6Ija4cGe6+yCN8HV8tCY0
22okZK98NQCl5t79R/ZB2c3NvBJH+/g3ulU48ikT3tVmDxE3mOZofZyGFEM99P+YCMScLDxTl3hzGy
230YkI8U855P7qOAbcFfh2T5n+LSELwLhbkymEfZT917GWTfmypBWMvJx0WHeDhKwQYPdzbKgWETnc
24yeKasaCW+oLdhBwrd6Ws2r4MA8cwiYXDLbwYmCxJA8VF++8kubF2HJOjSyMBS+QT2PSV/0D9UWoi
25Vfk7R4OvWBJVvq7nV+lXS0O5igjExxlmx1OaBfg7+Cr/MbK4zVNrKSJn82NnKKt6LC6RaTmvFYay
260sDFxQ7Xo+Th6tDNKmKWJt6Kegfjc+qTWJTKb3kL+UI8vS0zTLy1+M/rZ4ekos/JiS5rYIcAswvg
2758kBgp/0rc6upBeWjBaK5O0aLAeBQfLulo1axWX04OSVKmYeoAltyR6UO9ME3acurQyg7Ta24yqO
28whi/PrIaEiO7dsWvFtzsshVzBLic02NlAkPkMUzliPYnZHWQglDAVxL5K2qhvK1OFCkQpIgBsBDM
296KYRL/mkBIIEALIl927rIkaN37/BQIcxLcSa05YfC0Hl3mxWESt1A0D4lA37A9S8EbYmDfAYlMc0
303HhZGdZEtawfpJFyDHzNZceNWBch6nxeNZCY4YFdsbzuGS0RKpwNA9S/czOJ4p9ymBCxuhGepI3U
31PKbC8C749Www1/wMdAot1n+K7M/PBGR8hWmaH5SS7U3yMwAB1fq2NDjx4ur+Um+MclSdN01MDXzG
32EO+eAo1pdAY8479234l8dB2YVAhZ1ZlJ4KmbqMKJrGJXnQUEYS6/cTDRjsUocsoW7uGg1ci2GiHa
33qjlkfpBfie3SdhFW/K8hwAH0HALs56oFN66wUkP/AaJAPfIUNhR6RpHKzZ9zCC42oB2mNawQRMnF
34ETBl1s/SwMxLKRp7jAfKs4NZxSY6I9z/2dTpzS3tsHMjxVDuxkolvRNWBILEMeL1CBvip2HhmoUw
35/Sz5NDgyzk1aQLV6DQNJ2RZLMZDRCtSwZSBu6lhhSgTJGazP0+NbqXXC5aQTrqrFIcWyDXz+ADle
36kszzYM/gSaQTCALTwfDDaU9Ek3xVgW+XBtExtJ3U+0AN3l0j86rUIdIvp6eWdxWQqv9LtpoorKMD
37KfUc5PYV09Z1JgsT4X51Zzq+74l5dz7udIM7UNbdTpmRm9PDj3TUbGCvNR9hqOEGTLbkvb1ZR24a
38h6uGRl2znB25IpDAGRhNRb9is/pO2tvHwHTDMOjrgvZG/pNvXgSUxz0pRjUjXIcqBe2X2gcQfeal
39r8gY76o83WEGL6ODryV9vTQVHt52+izgpYoBZaVlpgqbZl54c+OE0Zxf9RwXwDbcYu5Ku5E0MPL0
40qUjc0y2+Y6E4P5bAWaZGMGT+ORkyVUzcaWmM/+XlO7PER5wrWlCIMZCX1L/nvioY0q0CKqALn7DJ
41QU+qenbwrb6uwS7uNZY6V86s0aDYpU7yRyqxC5SbuyNJb02gdxUCgpIscFaMUjMVRml4M4BIjX/b
42U+HgHoVMUm8SnN9gRcT2izPrgOGVcMTJjfenzoCKoCPo9RjgGMctgB4DvKamErNU7OrilIfuoqzE
43PNSeP9SPw/zkDmNvMebM499We9CVnsHUWqF00/ZJWoua77+0f1bLS/tmci1JBvIcMo/4SJvgH+KF
44o0gijP9gqAPd5iCOnpnJlHUqRIym42SmyKEDuzdSwXKjAR6j7uXda39JyMJr8gGzEsu0jYRkAmj1
45YdiqwKXUcLMkcj1AKeU/PxTUVw0YKsv/rowrPYww3xQUWqNivrXB7GCHE3BzsYNdHsmziaGIXQbA
46+EBHdkuKrM8BcC+fxhF/l/KUxngsD1E75IcUv8zFDF+sk4CBYHqks9S4JYlcubuizqsILbdGzIMN
47Z7w34k0XT+sEggQAyzr8MHeIJGsT+AYnZr08PeTbyr01JEoT7lPYT6PzX4F63QKKDl+mB+PwLMzY
48CXrxZcUmuay6/MV8w/f5T6vQXdoSw5puWodBYwVReYh1IaEN+jiTapm9YBVmcIsJPO6abHowknSV
49OWSvST0AtAX57fFOTckm+facfBK9s9T1lUUgF44Bh5e8f9qKqfOV44nqdCOEyUm0Dao497ieN4Eg
50XBLNvOZY9+irMiXjp0lcyFvhrJOczfyCr9EiiaiH1TfSzKGKsf2W84iKn/JH6x2eOo7xjwJ40BQD
51c6S1cUNEuqBhP6by0FioOXYOKVyifpxk84Eb+F/4CNdTJTvCPwsiegdfsX/Q53DvKVtXp9Ycam5J
52TmKRHXK/bMHF4ONv3p/O/kn/BqRx+fbbP2eMX8Z1F/ltHKfp6B+06HljUwQLBJs9XtCfqH5Zgdz9
53gad5WZF5ykFArmHDgeFlgggvbZ7z9vqnjN/TH68TxJzauYQ5vLHQ6wGXik4/4uq7/TqNmhxlQEM4
54zVkwsn203bUmKLyz+yl1zItDpn5zy1uXfGo99rBdUzdbdE9LmEFPMaFsaHd4a8oDaUroD7FgCbeD
55JJVld3ac6F8+3QbExPs48OrgA1kI3/UwXr52ldjiYzTLfAGR9BjqNFTw45FUHuMf8TEM5hcHx56w
5695eKAqraDk28o9k+M2UKpcmrdlWoWzdqVVFeWGpM8x9Y9Nt0lf/4VUQgrXjqTkUCQkJyqTeTeGgH
57rn3QBk2XAgpxZhaJs3InW0BkAlBmK99cMinUiJeFt5a4p5wPeXrVuh6V9m7Mpl9hzpogg++EZqah
58fzzNnDgxOZfW342DX052PdgXo0NnkhCk005LvFt6M2mRn0fLgNVfyUZZoOp8cO5ZWbhXXlrhrgUt
59j2zKPK6Q94Zj4kdXHBGpAkrB8ZQ4EGGODE0Dqusm8WPXzB+9236IMHPU7lFbyjBrFNI7O4jg+qRI
60Ipi+7tX0FsilqEbmjG+OPwhZXrdqUqyF+rjKQuSRq7lOeDB4c6S2dq4OOny01i5HCbbyc9UvSHRm
61hOhGqUlzHyHLo3W7j+26V/MhkDXJ+Tx+qfylv4pbliwTteJJj+CZwzjv29qb6lxYi+38Bw10ERap
62m8UCRFBecVN7xXlcIfyeAl666Vi7EBJZv3EdFNrx1nlLwM65nYya7uj6L7IwJWotIUx8E0XH0/cU
63xS/dG8bxf9L/8652h5gq3LI+wTNGuEX0DMuz7BGQG+NtgabrZ6SsKGthGa7eULTpz0McWTLRU0y/
64/tkckpm5pDnXSFbIMskwwjECz82UZBSPpigdN/Pjg5d+0yWu7s3VJxw4ENWPPpzZ+j7sOXmdvn9P
65O1tQd60EO+3awASCBAAZQvWV3/yJ6FxPttbP+qeURpJoPEZfpN2UYZmd8HqtR0YbaOZ6Rln9nvpd
66K9fylXdw9z2xeCbjDWUttJB4VqZxGJM8eCTC1VDVyAOsQ5n7SY55dMkQbU+o4Z/4J5m8+wz50BBI
67LfruL1eZ6/CF6CdvxVRiJ10sXc0Tn2sVMXqkw7Adp1GYoCI9c6VFSFK74+n+y7LVFQ5HBnbQyKJc
68dvdLOXwZOPaFHC5UNXRmOpcwdPqyXUe+xIsOMYbzdlAnI9eGDNeRDktUa/Rh0CbZCxjmJzoZEYOE
69ZjsYZlEfp1Kb61t8z4m28hGLEg88T1Ihmxa2HeUWes1RpmgIOP+/2Lb3smj/l/fpSu4gabFgyCAV
70H5HdCYMScUv8SVu55+tpeO8ELoHHQUXV4rr084O4budzhgNSOPyLGDl5sfDUXiyusPCxS4JVO/KY
716V2Qrtg/q2wtmXpEkZnGT+Qi3WDzwt4W81alztnYMP17oGLmxX71KV9OEiMZjI4WaaGt+OOINLtR
72qefioZ1NI2L1s5M0tybwTsyU9WERM+3pUwXIfJVsbMZRlNaO2OogcHbaR4UWvhOj+3CTG1sThiYQ
73MxMnp1Rpqx3nhyzqLO3TRrkYvxnA3cdPBn9EeqpgBMg7X3hCiMV3Fl5cj/WOMhtHYgY7BgeCXo46
74EFVZ4+WroGZ46xGiRDiIblo8bzLd7QCxvukzxy3mUDgsZQ8pds4N28weSUhBk5MAPbfBpRvXUVJx
75MhKqXucQU1Md1qSGLbuuIQuz9pAGp1JFUx/vEkCgm74daSoVWCZuB+1ZE4f48clvrBj51xMNf8CP
76EFE7vySzVb6X2H1i5X3Z+Y3DdIcWw4Y2FClfcJk4Mwq8Cq2GALGFEge9YSEE9YmyuU6OFeU0ICon
77iXAgZ72SM8fBwJPruLFbdsNYKW+oAfmPisXSWMcZmdSbfk0GYv+vKtu3eegSbWw1UsCVtZOh9E5Z
78uQ83l59CBqO9sV/SFU3WrrJ0qNWxrmXu9nJn5Qf5iCRoFGYNHYHkIG5FS6N00GEDZxGkxmro2d++
79Adj5LVHc/b1cYWmrux+jEqI8ZK8cyTB0XMbBA/HYbx9NXazr7znP4/Mlv3pZToEcYt+lgLHAArtU
80AdhybhbLIwNMq0gr6EwtDklBa3ns4Wx/rJU8H7LGs6gV8uqeaSketv+nz+sQhfctxZ1rx+5qzXfy
81FOQVpO23KDQunBi1Bl9k61Di4q9JWcyADBXPHXJzp7mL8Fk7zdvMAEfuED1phdRm6GgDYoYUs4yQ
82IrhSjFlWyk7hT8475xk3BIv++obvWSAv/3+pF6A6U2RXDChVmnG0JnPa9wYYtdzBmLfZKBjX+DjD
83yEMsuhPsCzuN4R6tBIIBWCVRKmKwdkatmpsQBgDw48u0/Arffl5/DRlS9ee+QffFecUitDdCK+kt
84X5L2fGYrL5g6SltncMIeV1ptx4nuSjC/O944q1KYtqvQiPFWJqEXIRMNbbYOC47sjLza0tEFrimN
85wxcrWGSzsy5R9beFQ1aHPcMrDWfCoviNRk2qPtxuKIC5Qk2ZuOmJLjCiLwUGEb0/1Mpzv3MqQa7d
86mRayXg3DZWJPajxNZv6eS357ElMvwGQmqafb2mlQJwWLsg9m9PG7uqEoyrqSc6MiuY+icLEFib9j
87OfRQrx70rTSKUfTr4MtP0aZZAefjCrpVIyTekhFDOk0Nmx057eonlyGgmGpl5/Uo+t1J1Z11Ya/l
88bNbfmebRISJeTVW0I8FhseAZMI1GSwp/ludJxSLYOgyRkh+GX134MexNo7O9F1SxLCfWaSG9Fc3s
895ify04ua9/t8SGrYZPm/l3MkAAAAAAAAAAAAAA==
90
91
diff --git a/src/lib/libcrypto/pkcs7/t/msie-s-a-e.pem b/src/lib/libcrypto/pkcs7/t/msie-s-a-e.pem
new file mode 100644
index 0000000000..55dbd8f80b
--- /dev/null
+++ b/src/lib/libcrypto/pkcs7/t/msie-s-a-e.pem
@@ -0,0 +1,106 @@
1-----BEGIN PKCS7-----
2MIAGCSqGSIb3DQEHA6CAMIITUAIBADGCAcIwgcwCAQAwdjBiMREwDwYDVQQHEwhJ
3bnRlcm5ldDEXMBUGA1UEChMOVmVyaVNpZ24sIEluYy4xNDAyBgNVBAsTK1ZlcmlT
4aWduIENsYXNzIDEgQ0EgLSBJbmRpdmlkdWFsIFN1YnNjcmliZXICEGBAmILep9sJ
5uN2Pkg1gucowDQYJKoZIhvcNAQEBBQAEQKOxxpIbRTb31+qIQCBOpMVAGnwCLrPO
6OXnntxVveTrPhBnsJuoGNJcCMtuHl7tLkd38WsVwOfGXUprTqFpUcY8wgfACAQAw
7gZkwgZIxCzAJBgNVBAYTAkFVMRMwEQYDVQQIEwpRdWVlbnNsYW5kMREwDwYDVQQH
8EwhCcmlzYmFuZTEaMBgGA1UEChMRQ3J5cHRzb2Z0IFB0eSBMdGQxIjAgBgNVBAsT
9GURFTU9OU1RSQVRJT04gQU5EIFRFU1RJTkcxGzAZBgNVBAMTEkRFTU8gWkVSTyBW
10QUxVRSBDQQICBG4wDQYJKoZIhvcNAQEBBQAEQKzIddnXFqK/RRBG86ZVixoXfwAv
11ZdfvnDFsKzPn/A6DuDdE/hqJxnFpHiwGiDR/YbWj2ib+G74DSshgX8vj8ZQwghGD
12BgkqhkiG9w0BBwEwGgYIKoZIhvcNAwIwDgICAKAECLKM0K58I3HNgIIRWBDP8s+g
13l7/6JhZ5PBJ5vPpD1R4pnNDZRabsYu0Qzezdz1IK+maTAhF0SEuNZoEkzIgOIvu3
14UjW8x/2KcHwteABwgRiSk1JyNLwRED0RtvuJ40pIGDvDsHwBMcXEtKUMAOpGChms
15HUK1+B/GKancSDFOCeG3JCFnFdbuQFDIVHC6amWslc6ntqVs/sii2Gs4qdzDfQgl
16PV/A/FY0wi0j2O5cXRQJtZVKM/MYGjj5c1cy9Q7oymU5ATP/LARD0Tw5kBB7HVnD
172qrmmmxcHakyxhXmwskaKS6Qxgqq6LPdgr603onxqEtwNSz5UbCq9mLXuCkFOVsQ
18/5mZcmmc7re3XJMQHRXkBlxEpZQ6HOUIEzlhRqCo2hhymyZK84rptjORQo6vNakM
19IC0Zn8O+6Xl1NlmbGzZakz6LJ4dczE7eG7LwrVus9Oq3V/WweG6rWMPV5d51oKMi
20BRb2pXXy80BAKh/9hvpP/V/HO1/+MPuk8tAn7ssmQoIAQcZxqLOmgqqFhy21oSEu
21rUY746Gp/vIV6Ax1MnfDA/fbjDllhJTl8ujZnfj8R1/oQa9fJMipV8CYQEAt3okZ
22V03kaVhhPGsv544/zRnhqjhgqjHASZGnluZCxDwHb1CE4UqYLp6IbkH3qosy2ntm
23a7WCsM3FN3o5dKFZXBgBEPT8HU9LLQ8B+T0Zvh8CQ719kkNBhnuzSYzmI48R5JHv
24zbROiU5v4p9FpssD13vXiOxzaMTKQqWk/roGHiNoKzKonS5RBwTxKfOsoCobCBaI
25IZCmJNr4cGI/p5GVEY4pCPljTq9w3HoiNrhwZ7r7II3wdXy0JjSiRkr3w1AKXm3v
261H9kHZzc28Ekf7+De6VTjyKRPe1WYPETeY5mh9nIYUQz30/5gIxJwsPFOXeHMbLR
27iQjxTznk/uo4BtwV+HZPmf4tIQvAuFuTKYR9lP3XsZZN+bKkFYy8nHRYd4OErBBg
2893NsqBYROdzJ4pqxoJb6gt2EHCt3pazavgwDxzCJhcMtvBiYLEkDxUX77yS5sXYc
29k6NLIwFL5BPY9JX/QP1RaiJV+TtHg69YElW+rudX6VdLQ7mKCMTHGWbHU5oF+Dv4
30Kv8xsrjNU2spImfzY2coq3osLpFpOa8VhrLSwMXFDtej5OHq0M0qYpYm3op6B+Nz
316pNYlMpveQv5Qjy9LTNMvLX4z+tnh6Siz8mJLmtghwCzC+DnyQGCn/Stzq6kF5aM
32Fork7RosB4FB8u6WjVrFZfTg5JUqZh6gCW3JHpQ70wTdpy6tDKDtNrbjKo7CGL8+
33shoSI7t2xa8W3OyyFXMEuJzTY2UCQ+QxTOWI9idkdZCCUMBXEvkraqG8rU4UKRCk
34iAGwEMzophEv+aSyJfdu6yJGjd+/wUCHMS3EmtOWHwtB5d5sVhErdQNA+JQN+wPU
35vBG2Jg3wGJTHNNx4WRnWRLWsH6SRcgx8zWXHjVgXIep8XjWQmOGBXbG87hktESqc
36DQPUv3MzieKfcpgQsboRnqSN1DymwvAu+PVsMNf8DHQKLdZ/iuzPzwRkfIVpmh+U
37ku1N8jMAAdX6tjQ48eLq/lJvjHJUnTdNTA18xhDvngKNaXQGPOO/dt+JfHQdmFQI
38WdWZSeCpm6jCiaxiV50FBGEuv3Ew0Y7FKHLKFu7hoNXIthoh2qo5ZH6QX4nt0nYR
39VvyvIcAB9BwC7OeqBTeusFJD/wGiQD3yFDYUekaRys2fcwguNqAdpjWsEETJxREw
40ZdbP0sDMSykae4wHyrODWcUmOiPc/9nU6c0t7bBzI8VQ7sZKJb0TVgSCxDHi9Qgb
414qdh4ZqFMP0s+TQ4Ms5NWkC1eg0DSdkWSzGQ0QrUsGUgbupYYUoEyRmsz9PjW6l1
42wuWkE66qxSHFsg18/gA5XpLM82DP4EmkEwgC08Hww2lPRJN8VYFvlwbRMbSd1PtA
43Dd5dI/Oq1CHSL6enlncVkKr/S7aaKKyjAyn1HOT2FdPWdSYLE+F+dWc6vu+JeXc+
447nSDO1DW3U6ZkZvTw4901GxgrzUfYajhBky25L29WUduGoerhkZds5wduSKQwBkY
45TUW/YrP6Ttrbx8B0wzDo64L2Rv6Tb14ElMc9KUY1I1yHKgXtl9oHEH3mpa/IGO+q
46PN1hBi+jg68lfb00FR7edvos4KWKAWWlZaYKm2ZeeHPjhNGcX/UcF8A23GLuSruR
47NDDy9KlI3NMtvmOhOD+WwFmmRjBk/jkZMlVM3GlpjP/l5TuzxEecK1pQiDGQl9S/
48574qGNKtAiqgC5+wyUFPqnp28K2+rsEu7jWWOlfOrNGg2KVO8kcqsQuUm7sjSW9N
49oHcVAoKSLHBWjFIzFUZpeDOASI1/21Ph4B6FTFJvEpzfYEXE9osz64DhlXDEyY33
50p86AiqAj6PUY4BjHLYAeA7ymphKzVOzq4pSH7qKsxDzUnj/Uj8P85A5jbzHmzOPf
51VnvQlZ7B1FqhdNP2SVqLmu+/tH9Wy0v7ZnItSQbyHDKP+Eib4B/ihaNIIoz/YKgD
523eYgjp6ZyZR1KkSMpuNkpsihA7s3UsFyowEeo+7l3Wt/ScjCa/IBsxLLtI2EZAJo
539WHYqsCl1HCzJHI9QCnlPz8U1FcNGCrL/66MKz2MMN8UFFqjYr61wexghxNwc7GD
54XR7Js4mhiF0GwPhAR3ZLiqzPAXAvn8YRf5fylMZ4LA9RO+SHFL/MxQxfrJOAgWB6
55pLPUuCWJXLm7os6rCC23RsyDDWe8N+JNF0/ryzr8MHeIJGsT+AYnZr08PeTbyr01
56JEoT7lPYT6PzX4F63QKKDl+mB+PwLMzYCXrxZcUmuay6/MV8w/f5T6vQXdoSw5pu
57WodBYwVReYh1IaEN+jiTapm9YBVmcIsJPO6abHowknSVOWSvST0AtAX57fFOTckm
58+facfBK9s9T1lUUgF44Bh5e8f9qKqfOV44nqdCOEyUm0Dao497ieN4EgXBLNvOZY
599+irMiXjp0lcyFvhrJOczfyCr9EiiaiH1TfSzKGKsf2W84iKn/JH6x2eOo7xjwJ4
600BQDc6S1cUNEuqBhP6by0FioOXYOKVyifpxk84Eb+F/4CNdTJTvCPwsiegdfsX/Q
6153DvKVtXp9Ycam5JTmKRHXK/bMHF4ONv3p/O/kn/BqRx+fbbP2eMX8Z1F/ltHKfp
626B+06HljUwQLBJs9XtCfqH5Zgdz9gad5WZF5ykFArmHDgeFlgggvbZ7z9vqnjN/T
63H68TxJzauYQ5vLHQ6wGXik4/4uq7/TqNmhxlQEM4zVkwsn203bUmKLyz+yl1zItD
64pn5zy1uXfGo99rBdUzdbdE9LmEFPMaFsaHd4a8oDaUroD7FgCbeDJJVld3ac6F8+
653QbExPs48OrgA1kI3/UwXr52ldjiYzTLfAGR9BjqNFTw45FUHuMf8TEM5hcHx56w
6695eKAqraDk28o9k+M2UKpcmrdlWoWzdqVVFeWGpM8x9Y9Nt0lf/4VUQgrXjqTkUC
67QkJyqTeTeGgHrn3QBk2XAgpxZhaJs3InW0BkAlBmK99cMinUiJeFt5a4p5wPeXrV
68uh6V9m7Mpl9hzpogg++EZqahfzzNnDgxOZfW342DX052PdgXo0NnkhCk005LvFt6
69M2mRn0fLgNVfyUZZoOp8cO5ZWbhXXlrhrgUtj2zKPK6Q94Zj4kdXHBGpAkrB8ZQ4
70EGGODE0Dqusm8WPXzB+9236IMHPU7lFbyjBrFNI7O4jg+qRIIpi+7tX0FsilqEbm
71jG+OPwhZXrdqUqyF+rjKQuSRq7lOeDB4c6S2dq4OOny01i5HCbbyc9UvSHRmhOhG
72qUlzHyHLo3W7j+26V/MhkDXJ+Tx+qfylv4pbliwTteJJj+CZwzjv29qb6lxYi+38
73Bw10ERapm8UCRFBecVN7xXlcIfyeAl666Vi7EBJZv3EdFNrx1nlLwM65nYya7uj6
74L7IwJWotIUx8E0XH0/cUxS/dG8bxf9L/8652h5gq3LI+wTNGuEX0DMuz7BGQG+Nt
75gabrZ6SsKGthGa7eULTpz0McWTLRU0y//tkckpm5pDnXSFbIMskwwjECz82UZBSP
76pigdN/Pjg5d+0yWu7s3VJxw4ENWPPpzZ+j7sOXmdvn9PO1tQd60EO+3awBlC9ZXf
77/InoXE+21s/6p5RGkmg8Rl+k3ZRhmZ3weq1HRhto5npGWf2e+l0r1/KVd3D3PbF4
78JuMNZS20kHhWpnEYkzx4JMLVUNXIA6xDmftJjnl0yRBtT6jhn/gnmbz7DPnQEEgt
79+u4vV5nr8IXoJ2/FVGInXSxdzROfaxUxeqTDsB2nUZigIj1zpUVIUrvj6f7LstUV
80DkcGdtDIolx290s5fBk49oUcLlQ1dGY6lzB0+rJdR77Eiw4xhvN2UCcj14YM15EO
81S1Rr9GHQJtkLGOYnOhkRg4RmOxhmUR+nUpvrW3zPibbyEYsSDzxPUiGbFrYd5RZ6
82zVGmaAg4/7/YtveyaP+X9+lK7iBpsWDIIBUfkd0JgxJxS/xJW7nn62l47wQugcdB
83RdXiuvTzg7hu53OGA1I4/IsYOXmx8NReLK6w8LFLglU78pjpXZCu2D+rbC2ZekSR
84mcZP5CLdYPPC3hbzVqXO2dgw/XugYubFfvUpX04SIxmMjhZpoa3444g0u1Gp5+Kh
85nU0jYvWzkzS3JvBOzJT1YREz7elTBch8lWxsxlGU1o7Y6iBwdtpHhRa+E6P7cJMb
86WxOGJhAzEyenVGmrHeeHLOos7dNGuRi/GcDdx08Gf0R6qmAEyDtfeEKIxXcWXlyP
879Y4yG0diBjsGB4JejjoQVVnj5augZnjrEaJEOIhuWjxvMt3tALG+6TPHLeZQOCxl
88Dyl2zg3bzB5JSEGTkwA9t8GlG9dRUnEyEqpe5xBTUx3WpIYtu64hC7P2kAanUkVT
89H+8SQKCbvh1pKhVYJm4H7VkTh/jxyW+sGPnXEw1/wI8QUTu/JLNVvpfYfWLlfdn5
90jcN0hxbDhjYUKV9wmTgzCrwKrYYAsYUSB71hIQT1ibK5To4V5TQgKieJcCBnvZIz
91x8HAk+u4sVt2w1gpb6gB+Y+KxdJYxxmZ1Jt+TQZi/68q27d56BJtbDVSwJW1k6H0
92Tlm5DzeXn0IGo72xX9IVTdausnSo1bGuZe72cmflB/mIJGgUZg0dgeQgbkVLo3TQ
93YQNnEaTGaujZ374B2PktUdz9vVxhaau7H6MSojxkrxzJMHRcxsED8dhvH01drOvv
94Oc/j8yW/ellOgRxi36WAscACu1QB2HJuFssjA0yrSCvoTC0OSUFreezhbH+slTwf
95ssazqBXy6p5pKR62/6fP6xCF9y3FnWvH7mrNd/IU5BWk7bcoNC6cGLUGX2TrUOLi
96r0lZzIAMFc8dcnOnuYvwWTvN28wAR+4QPWmF1GboaANihhSzjJAiuFKMWVbKTuFP
97zjvnGTcEi/76hu9ZIC//f6kXoDpTZFcMKFWacbQmc9r3Bhi13MGYt9koGNf4OMPI
98Qyy6E+wLO43hHq0lUSpisHZGrZqbEAYA8OPLtPwK335efw0ZUvXnvkH3xXnFIrQ3
99QivpLV+S9nxmKy+YOkpbZ3DCHldabceJ7kowvzveOKtSmLar0IjxViahFyETDW22
100DguO7Iy82tLRBa4pjcMXK1hks7MuUfW3hUNWhz3DKw1nwqL4jUZNqj7cbiiAuUJN
101mbjpiS4woi8FBhG9P9TKc79zKkGu3ZkWsl4Nw2ViT2o8TWb+nkt+exJTL8BkJqmn
10229ppUCcFi7IPZvTxu7qhKMq6knOjIrmPonCxBYm/Yzn0UK8e9K00ilH06+DLT9Gm
103WQHn4wq6VSMk3pIRQzpNDZsdOe3qJ5choJhqZef1KPrdSdWddWGv5WzW35nm0SEi
104Xk1VtCPBYbHgGTCNRksKf5bnScUi2DoMkZIfhl9d+DHsTaOzvRdUsSwn1mkhvRXN
1057OYn8tOLmvf7fEhq2GT5v5dzJAAAAAA=
106-----END PKCS7-----
diff --git a/src/lib/libcrypto/pkcs7/t/nav-smime b/src/lib/libcrypto/pkcs7/t/nav-smime
new file mode 100644
index 0000000000..6ee4b597a1
--- /dev/null
+++ b/src/lib/libcrypto/pkcs7/t/nav-smime
@@ -0,0 +1,157 @@
1From angela@c2.net.au Thu May 14 13:32:27 1998
2X-UIDL: 83c94dd550e54329bf9571b72038b8c8
3Return-Path: angela@c2.net.au
4Received: from cryptsoft.com (play.cryptsoft.com [203.56.44.3]) by pandora.cryptsoft.com (8.8.3/8.7.3) with ESMTP id NAA27838 for <tjh@cryptsoft.com>; Thu, 14 May 1998 13:32:26 +1000 (EST)
5Message-ID: <355A6779.4B63E64C@cryptsoft.com>
6Date: Thu, 14 May 1998 13:39:37 +1000
7From: Angela van Lent <angela@c2.net.au>
8X-Mailer: Mozilla 4.03 [en] (Win95; U)
9MIME-Version: 1.0
10To: tjh@cryptsoft.com
11Subject: signed
12Content-Type: multipart/signed; protocol="application/x-pkcs7-signature"; micalg=sha1; boundary="------------ms9A58844C95949ECC78A1C54C"
13Content-Length: 2604
14Status: OR
15
16This is a cryptographically signed message in MIME format.
17
18--------------ms9A58844C95949ECC78A1C54C
19Content-Type: text/plain; charset=us-ascii
20Content-Transfer-Encoding: 7bit
21
22signed body
23
24--------------ms9A58844C95949ECC78A1C54C
25Content-Type: application/x-pkcs7-signature; name="smime.p7s"
26Content-Transfer-Encoding: base64
27Content-Disposition: attachment; filename="smime.p7s"
28Content-Description: S/MIME Cryptographic Signature
29
30MIIGHgYJKoZIhvcNAQcCoIIGDzCCBgsCAQExCzAJBgUrDgMCGgUAMAsGCSqGSIb3DQEHAaCC
31BGswggJTMIIB/aADAgECAgIEfjANBgkqhkiG9w0BAQQFADCBkjELMAkGA1UEBhMCQVUxEzAR
32BgNVBAgTClF1ZWVuc2xhbmQxETAPBgNVBAcTCEJyaXNiYW5lMRowGAYDVQQKExFDcnlwdHNv
33ZnQgUHR5IEx0ZDEiMCAGA1UECxMZREVNT05TVFJBVElPTiBBTkQgVEVTVElORzEbMBkGA1UE
34AxMSREVNTyBaRVJPIFZBTFVFIENBMB4XDTk4MDUxMzA2MjY1NloXDTAwMDUxMjA2MjY1Nlow
35gaUxCzAJBgNVBAYTAkFVMRMwEQYDVQQIEwpRdWVlbnNsYW5kMREwDwYDVQQHEwhCcmlzYmFu
36ZTEaMBgGA1UEChMRQ3J5cHRzb2Z0IFB0eSBMdGQxEjAQBgNVBAsTCVNNSU1FIDAwMzEZMBcG
37A1UEAxMQQW5nZWxhIHZhbiBMZWVudDEjMCEGCSqGSIb3DQEJARYUYW5nZWxhQGNyeXB0c29m
38dC5jb20wXDANBgkqhkiG9w0BAQEFAANLADBIAkEAuC3+7dAb2LhuO7gt2cTM8vsNjhG5JfDh
39hX1Vl/wVGbKEEj0MA6vWEolvefQlxB+EzwCtR0YZ7eEC/T/4JoCyeQIDAQABoygwJjAkBglg
40hkgBhvhCAQ0EFxYVR2VuZXJhdGVkIHdpdGggU1NMZWF5MA0GCSqGSIb3DQEBBAUAA0EAUnSP
41igs6TMFISTjw8cBtJYb98czgAVkVFjKyJQwYMH8FbDnCyx6NocM555nsyDstaw8fKR11Khds
42syd3ikkrhDCCAhAwggG6AgEDMA0GCSqGSIb3DQEBBAUAMIGSMQswCQYDVQQGEwJBVTETMBEG
43A1UECBMKUXVlZW5zbGFuZDERMA8GA1UEBxMIQnJpc2JhbmUxGjAYBgNVBAoTEUNyeXB0c29m
44dCBQdHkgTHRkMSIwIAYDVQQLExlERU1PTlNUUkFUSU9OIEFORCBURVNUSU5HMRswGQYDVQQD
45ExJERU1PIFpFUk8gVkFMVUUgQ0EwHhcNOTgwMzAzMDc0MTMyWhcNMDgwMjI5MDc0MTMyWjCB
46kjELMAkGA1UEBhMCQVUxEzARBgNVBAgTClF1ZWVuc2xhbmQxETAPBgNVBAcTCEJyaXNiYW5l
47MRowGAYDVQQKExFDcnlwdHNvZnQgUHR5IEx0ZDEiMCAGA1UECxMZREVNT05TVFJBVElPTiBB
48TkQgVEVTVElORzEbMBkGA1UEAxMSREVNTyBaRVJPIFZBTFVFIENBMFwwDQYJKoZIhvcNAQEB
49BQADSwAwSAJBAL+0E2fLej3FSCwe2A2iRnMuC3z12qHIp6Ky1wo2zZcxft7AI+RfkrWrSGtf
50mfzBEuPrLdfulncC5Y1pNcM8RTUCAwEAATANBgkqhkiG9w0BAQQFAANBAGSbLMphL6F5pp3s
518o0Xyh86FHFdpVOwYx09ELLkuG17V/P9pgIc0Eo/gDMbN+KT3IdgECf8S//pCRA6RrNjcXIx
52ggF7MIIBdwIBATCBmTCBkjELMAkGA1UEBhMCQVUxEzARBgNVBAgTClF1ZWVuc2xhbmQxETAP
53BgNVBAcTCEJyaXNiYW5lMRowGAYDVQQKExFDcnlwdHNvZnQgUHR5IEx0ZDEiMCAGA1UECxMZ
54REVNT05TVFJBVElPTiBBTkQgVEVTVElORzEbMBkGA1UEAxMSREVNTyBaRVJPIFZBTFVFIENB
55AgIEfjAJBgUrDgMCGgUAoHowGAYJKoZIhvcNAQkDMQsGCSqGSIb3DQEHATAbBgkqhkiG9w0B
56CQ8xDjAMMAoGCCqGSIb3DQMHMBwGCSqGSIb3DQEJBTEPFw05ODA1MTQwMzM5MzdaMCMGCSqG
57SIb3DQEJBDEWBBQstNMnSV26ba8PapQEDhO21yNFrjANBgkqhkiG9w0BAQEFAARAW9Xb9YXv
58BfcNkutgFX9Gr8iXhBVsNtGEVrjrpkQwpKa7jHI8SjAlLhk/4RFwDHf+ISB9Np3Z1WDWnLcA
599CWR6g==
60--------------ms9A58844C95949ECC78A1C54C--
61
62
63From angela@c2.net.au Thu May 14 13:33:16 1998
64X-UIDL: 8f076c44ff7c5967fd5b00c4588a8731
65Return-Path: angela@c2.net.au
66Received: from cryptsoft.com (play.cryptsoft.com [203.56.44.3]) by pandora.cryptsoft.com (8.8.3/8.7.3) with ESMTP id NAA27847 for <tjh@cryptsoft.com>; Thu, 14 May 1998 13:33:15 +1000 (EST)
67Message-ID: <355A67AB.2AF38806@cryptsoft.com>
68Date: Thu, 14 May 1998 13:40:27 +1000
69From: Angela van Lent <angela@c2.net.au>
70X-Mailer: Mozilla 4.03 [en] (Win95; U)
71MIME-Version: 1.0
72To: tjh@cryptsoft.com
73Subject: signed
74Content-Type: multipart/signed; protocol="application/x-pkcs7-signature"; micalg=sha1; boundary="------------msD7863B84BD61E02C407F2F5E"
75Content-Length: 2679
76Status: OR
77
78This is a cryptographically signed message in MIME format.
79
80--------------msD7863B84BD61E02C407F2F5E
81Content-Type: text/plain; charset=us-ascii
82Content-Transfer-Encoding: 7bit
83
84signed body 2
85
86--------------msD7863B84BD61E02C407F2F5E
87Content-Type: application/x-pkcs7-signature; name="smime.p7s"
88Content-Transfer-Encoding: base64
89Content-Disposition: attachment; filename="smime.p7s"
90Content-Description: S/MIME Cryptographic Signature
91
92MIIGVgYJKoZIhvcNAQcCoIIGRzCCBkMCAQExCzAJBgUrDgMCGgUAMAsGCSqGSIb3DQEHAaCC
93BGswggJTMIIB/aADAgECAgIEfjANBgkqhkiG9w0BAQQFADCBkjELMAkGA1UEBhMCQVUxEzAR
94BgNVBAgTClF1ZWVuc2xhbmQxETAPBgNVBAcTCEJyaXNiYW5lMRowGAYDVQQKExFDcnlwdHNv
95ZnQgUHR5IEx0ZDEiMCAGA1UECxMZREVNT05TVFJBVElPTiBBTkQgVEVTVElORzEbMBkGA1UE
96AxMSREVNTyBaRVJPIFZBTFVFIENBMB4XDTk4MDUxMzA2MjY1NloXDTAwMDUxMjA2MjY1Nlow
97gaUxCzAJBgNVBAYTAkFVMRMwEQYDVQQIEwpRdWVlbnNsYW5kMREwDwYDVQQHEwhCcmlzYmFu
98ZTEaMBgGA1UEChMRQ3J5cHRzb2Z0IFB0eSBMdGQxEjAQBgNVBAsTCVNNSU1FIDAwMzEZMBcG
99A1UEAxMQQW5nZWxhIHZhbiBMZWVudDEjMCEGCSqGSIb3DQEJARYUYW5nZWxhQGNyeXB0c29m
100dC5jb20wXDANBgkqhkiG9w0BAQEFAANLADBIAkEAuC3+7dAb2LhuO7gt2cTM8vsNjhG5JfDh
101hX1Vl/wVGbKEEj0MA6vWEolvefQlxB+EzwCtR0YZ7eEC/T/4JoCyeQIDAQABoygwJjAkBglg
102hkgBhvhCAQ0EFxYVR2VuZXJhdGVkIHdpdGggU1NMZWF5MA0GCSqGSIb3DQEBBAUAA0EAUnSP
103igs6TMFISTjw8cBtJYb98czgAVkVFjKyJQwYMH8FbDnCyx6NocM555nsyDstaw8fKR11Khds
104syd3ikkrhDCCAhAwggG6AgEDMA0GCSqGSIb3DQEBBAUAMIGSMQswCQYDVQQGEwJBVTETMBEG
105A1UECBMKUXVlZW5zbGFuZDERMA8GA1UEBxMIQnJpc2JhbmUxGjAYBgNVBAoTEUNyeXB0c29m
106dCBQdHkgTHRkMSIwIAYDVQQLExlERU1PTlNUUkFUSU9OIEFORCBURVNUSU5HMRswGQYDVQQD
107ExJERU1PIFpFUk8gVkFMVUUgQ0EwHhcNOTgwMzAzMDc0MTMyWhcNMDgwMjI5MDc0MTMyWjCB
108kjELMAkGA1UEBhMCQVUxEzARBgNVBAgTClF1ZWVuc2xhbmQxETAPBgNVBAcTCEJyaXNiYW5l
109MRowGAYDVQQKExFDcnlwdHNvZnQgUHR5IEx0ZDEiMCAGA1UECxMZREVNT05TVFJBVElPTiBB
110TkQgVEVTVElORzEbMBkGA1UEAxMSREVNTyBaRVJPIFZBTFVFIENBMFwwDQYJKoZIhvcNAQEB
111BQADSwAwSAJBAL+0E2fLej3FSCwe2A2iRnMuC3z12qHIp6Ky1wo2zZcxft7AI+RfkrWrSGtf
112mfzBEuPrLdfulncC5Y1pNcM8RTUCAwEAATANBgkqhkiG9w0BAQQFAANBAGSbLMphL6F5pp3s
1138o0Xyh86FHFdpVOwYx09ELLkuG17V/P9pgIc0Eo/gDMbN+KT3IdgECf8S//pCRA6RrNjcXIx
114ggGzMIIBrwIBATCBmTCBkjELMAkGA1UEBhMCQVUxEzARBgNVBAgTClF1ZWVuc2xhbmQxETAP
115BgNVBAcTCEJyaXNiYW5lMRowGAYDVQQKExFDcnlwdHNvZnQgUHR5IEx0ZDEiMCAGA1UECxMZ
116REVNT05TVFJBVElPTiBBTkQgVEVTVElORzEbMBkGA1UEAxMSREVNTyBaRVJPIFZBTFVFIENB
117AgIEfjAJBgUrDgMCGgUAoIGxMBgGCSqGSIb3DQEJAzELBgkqhkiG9w0BBwEwHAYJKoZIhvcN
118AQkFMQ8XDTk4MDUxNDAzNDAyN1owIwYJKoZIhvcNAQkEMRYEFOKcV8mNYJnM8rHQajcSEqJN
119rwdDMFIGCSqGSIb3DQEJDzFFMEMwCgYIKoZIhvcNAwcwDgYIKoZIhvcNAwICAgCAMAcGBSsO
120AwIHMA0GCCqGSIb3DQMCAgFAMA0GCCqGSIb3DQMCAgEoMA0GCSqGSIb3DQEBAQUABEADPE/N
121coH+zTFuX5YpolupTKxKK8eEjc48TuADuO8bIHHDE/fEYaWunlwDuTlcFJl1ig0idffPB1qC
122Zp8SSVVY
123--------------msD7863B84BD61E02C407F2F5E--
124
125
126From angela@c2.net.au Thu May 14 14:05:32 1998
127X-UIDL: a7d629b4b9acacaee8b39371b860a32a
128Return-Path: angela@c2.net.au
129Received: from cryptsoft.com (play.cryptsoft.com [203.56.44.3]) by pandora.cryptsoft.com (8.8.3/8.7.3) with ESMTP id OAA28033 for <tjh@cryptsoft.com>; Thu, 14 May 1998 14:05:32 +1000 (EST)
130Message-ID: <355A6F3B.AC385981@cryptsoft.com>
131Date: Thu, 14 May 1998 14:12:43 +1000
132From: Angela van Lent <angela@c2.net.au>
133X-Mailer: Mozilla 4.03 [en] (Win95; U)
134MIME-Version: 1.0
135To: tjh@cryptsoft.com
136Subject: encrypted
137Content-Type: application/x-pkcs7-mime; name="smime.p7m"
138Content-Transfer-Encoding: base64
139Content-Disposition: attachment; filename="smime.p7m"
140Content-Description: S/MIME Encrypted Message
141Content-Length: 905
142Status: OR
143
144MIAGCSqGSIb3DQEHA6CAMIACAQAxggHmMIHwAgEAMIGZMIGSMQswCQYDVQQGEwJBVTETMBEG
145A1UECBMKUXVlZW5zbGFuZDERMA8GA1UEBxMIQnJpc2JhbmUxGjAYBgNVBAoTEUNyeXB0c29m
146dCBQdHkgTHRkMSIwIAYDVQQLExlERU1PTlNUUkFUSU9OIEFORCBURVNUSU5HMRswGQYDVQQD
147ExJERU1PIFpFUk8gVkFMVUUgQ0ECAgR+MA0GCSqGSIb3DQEBAQUABEA92N29Yk39RUY2tIVd
148exGT2MFX3J6H8LB8aDRJjw7843ALgJ5zXpM5+f80QkAWwEN2A6Pl3VxiCeKLi435zXVyMIHw
149AgEAMIGZMIGSMQswCQYDVQQGEwJBVTETMBEGA1UECBMKUXVlZW5zbGFuZDERMA8GA1UEBxMI
150QnJpc2JhbmUxGjAYBgNVBAoTEUNyeXB0c29mdCBQdHkgTHRkMSIwIAYDVQQLExlERU1PTlNU
151UkFUSU9OIEFORCBURVNUSU5HMRswGQYDVQQDExJERU1PIFpFUk8gVkFMVUUgQ0ECAgRuMA0G
152CSqGSIb3DQEBAQUABECR9IfyHtvnjFmZ8B2oUCEs1vxMsG0u1kxKE4RMPFyDqDCEARq7zXMg
153nzSUI7Wgv5USSKDqcLRJeW+jvYURv/nJMIAGCSqGSIb3DQEHATAaBggqhkiG9w0DAjAOAgIA
154oAQIrLqrij2ZMpeggAQoibtn6reRZWuWk5Iv5IAhgitr8EYE4w4ySQ7EMB6mTlBoFpccUMWX
155BwQgQn1UoWCvYAlhDzURdbui64Dc0rS2wtj+kE/InS6y25EEEPe4NUKaF8/UlE+lo3LtILQE
156CL3uV8k7m0iqAAAAAAAAAAAAAA==
157
diff --git a/src/lib/libcrypto/pkcs7/t/s.pem b/src/lib/libcrypto/pkcs7/t/s.pem
new file mode 100644
index 0000000000..4fa925b182
--- /dev/null
+++ b/src/lib/libcrypto/pkcs7/t/s.pem
@@ -0,0 +1,57 @@
1-----BEGIN RSA PRIVATE KEY-----
2MIIBOgIBAAJBAK3nI4nuDYe3nDJES5WBc90igEstxWC4/h4YY+/ciYki35U8ets9
3mgaoCNYp/e9BCZHtvK2Y+fYokGJv5+cMTQsCAwEAAQJBAIHpvXvqEcOEoDRRHuIG
4fkcB4jPHcr9KE9TpxabH6xs9beN6OJnkePXAHwaz5MnUgSnbpOKq+cw8miKjXwe/
5zVECIQDVLwncT2lRmXarEYHzb+q/0uaSvKhWKKt3kJasLNTrAwIhANDUc/ghut29
6p3jJYjurzUKuG774/5eLjPLsxPPIZzNZAiA/10hSq41UnGqHLEUIS9m2/EeEZe7b
7bm567dfRU9OnVQIgDo8ROrZXSchEGbaog5J5r/Fle83uO8l93R3GqVxKXZkCIFfk
8IPD5PIYQAyyod3hyKKza7ZP4CGY4oOfZetbkSGGG
9-----END RSA PRIVATE KEY-----
10issuer :/C=AU/SP=Queensland/L=Brisbane/O=Cryptsoft Pty Ltd/OU=DEMONSTRATION AND TESTING/CN=DEMO ZERO VALUE CA
11subject:/C=AU/SP=Queensland/L=Brisbane/O=Cryptsoft Pty Ltd/OU=SMIME 003/CN=Information/Email=info@cryptsoft.com
12serial :047D
13
14Certificate:
15 Data:
16 Version: 3 (0x2)
17 Serial Number: 1149 (0x47d)
18 Signature Algorithm: md5withRSAEncryption
19 Issuer: C=AU, SP=Queensland, L=Brisbane, O=Cryptsoft Pty Ltd, OU=DEMONSTRATION AND TESTING, CN=DEMO ZERO VALUE CA
20 Validity
21 Not Before: May 13 05:40:58 1998 GMT
22 Not After : May 12 05:40:58 2000 GMT
23 Subject: C=AU, SP=Queensland, L=Brisbane, O=Cryptsoft Pty Ltd, OU=SMIME 003, CN=Information/Email=info@cryptsoft.com
24 Subject Public Key Info:
25 Public Key Algorithm: rsaEncryption
26 Modulus:
27 00:ad:e7:23:89:ee:0d:87:b7:9c:32:44:4b:95:81:
28 73:dd:22:80:4b:2d:c5:60:b8:fe:1e:18:63:ef:dc:
29 89:89:22:df:95:3c:7a:db:3d:9a:06:a8:08:d6:29:
30 fd:ef:41:09:91:ed:bc:ad:98:f9:f6:28:90:62:6f:
31 e7:e7:0c:4d:0b
32 Exponent: 65537 (0x10001)
33 X509v3 extensions:
34 Netscape Comment:
35 Generated with SSLeay
36 Signature Algorithm: md5withRSAEncryption
37 52:15:ea:88:f4:f0:f9:0b:ef:ce:d5:f8:83:40:61:16:5e:55:
38 f9:ce:2d:d1:8b:31:5c:03:c6:2d:10:7c:61:d5:5c:0a:42:97:
39 d1:fd:65:b6:b6:84:a5:39:ec:46:ec:fc:e0:0d:d9:22:da:1b:
40 50:74:ad:92:cb:4e:90:e5:fa:7d
41
42-----BEGIN CERTIFICATE-----
43MIICTDCCAfagAwIBAgICBH0wDQYJKoZIhvcNAQEEBQAwgZIxCzAJBgNVBAYTAkFV
44MRMwEQYDVQQIEwpRdWVlbnNsYW5kMREwDwYDVQQHEwhCcmlzYmFuZTEaMBgGA1UE
45ChMRQ3J5cHRzb2Z0IFB0eSBMdGQxIjAgBgNVBAsTGURFTU9OU1RSQVRJT04gQU5E
46IFRFU1RJTkcxGzAZBgNVBAMTEkRFTU8gWkVSTyBWQUxVRSBDQTAeFw05ODA1MTMw
47NTQwNThaFw0wMDA1MTIwNTQwNThaMIGeMQswCQYDVQQGEwJBVTETMBEGA1UECBMK
48UXVlZW5zbGFuZDERMA8GA1UEBxMIQnJpc2JhbmUxGjAYBgNVBAoTEUNyeXB0c29m
49dCBQdHkgTHRkMRIwEAYDVQQLEwlTTUlNRSAwMDMxFDASBgNVBAMTC0luZm9ybWF0
50aW9uMSEwHwYJKoZIhvcNAQkBFhJpbmZvQGNyeXB0c29mdC5jb20wXDANBgkqhkiG
519w0BAQEFAANLADBIAkEArecjie4Nh7ecMkRLlYFz3SKASy3FYLj+Hhhj79yJiSLf
52lTx62z2aBqgI1in970EJke28rZj59iiQYm/n5wxNCwIDAQABoygwJjAkBglghkgB
53hvhCAQ0EFxYVR2VuZXJhdGVkIHdpdGggU1NMZWF5MA0GCSqGSIb3DQEBBAUAA0EA
54UhXqiPTw+QvvztX4g0BhFl5V+c4t0YsxXAPGLRB8YdVcCkKX0f1ltraEpTnsRuz8
554A3ZItobUHStkstOkOX6fQ==
56-----END CERTIFICATE-----
57
diff --git a/src/lib/libcrypto/pkcs7/t/server.pem b/src/lib/libcrypto/pkcs7/t/server.pem
new file mode 100644
index 0000000000..989baf8709
--- /dev/null
+++ b/src/lib/libcrypto/pkcs7/t/server.pem
@@ -0,0 +1,57 @@
1issuer :/C=AU/SP=Queensland/L=Brisbane/O=Cryptsoft Pty Ltd/OU=DEMONSTRATION AND TESTING/CN=DEMO ZERO VALUE CA
2subject:/C=AU/SP=Queensland/L=Brisbane/O=Cryptsoft Pty Ltd/OU=SMIME 003/CN=Information/Email=info@cryptsoft.com
3serial :047D
4
5Certificate:
6 Data:
7 Version: 3 (0x2)
8 Serial Number: 1149 (0x47d)
9 Signature Algorithm: md5withRSAEncryption
10 Issuer: C=AU, SP=Queensland, L=Brisbane, O=Cryptsoft Pty Ltd, OU=DEMONSTRATION AND TESTING, CN=DEMO ZERO VALUE CA
11 Validity
12 Not Before: May 13 05:40:58 1998 GMT
13 Not After : May 12 05:40:58 2000 GMT
14 Subject: C=AU, SP=Queensland, L=Brisbane, O=Cryptsoft Pty Ltd, OU=SMIME 003, CN=Information/Email=info@cryptsoft.com
15 Subject Public Key Info:
16 Public Key Algorithm: rsaEncryption
17 Modulus:
18 00:ad:e7:23:89:ee:0d:87:b7:9c:32:44:4b:95:81:
19 73:dd:22:80:4b:2d:c5:60:b8:fe:1e:18:63:ef:dc:
20 89:89:22:df:95:3c:7a:db:3d:9a:06:a8:08:d6:29:
21 fd:ef:41:09:91:ed:bc:ad:98:f9:f6:28:90:62:6f:
22 e7:e7:0c:4d:0b
23 Exponent: 65537 (0x10001)
24 X509v3 extensions:
25 Netscape Comment:
26 Generated with SSLeay
27 Signature Algorithm: md5withRSAEncryption
28 52:15:ea:88:f4:f0:f9:0b:ef:ce:d5:f8:83:40:61:16:5e:55:
29 f9:ce:2d:d1:8b:31:5c:03:c6:2d:10:7c:61:d5:5c:0a:42:97:
30 d1:fd:65:b6:b6:84:a5:39:ec:46:ec:fc:e0:0d:d9:22:da:1b:
31 50:74:ad:92:cb:4e:90:e5:fa:7d
32
33-----BEGIN CERTIFICATE-----
34MIICTDCCAfagAwIBAgICBH0wDQYJKoZIhvcNAQEEBQAwgZIxCzAJBgNVBAYTAkFV
35MRMwEQYDVQQIEwpRdWVlbnNsYW5kMREwDwYDVQQHEwhCcmlzYmFuZTEaMBgGA1UE
36ChMRQ3J5cHRzb2Z0IFB0eSBMdGQxIjAgBgNVBAsTGURFTU9OU1RSQVRJT04gQU5E
37IFRFU1RJTkcxGzAZBgNVBAMTEkRFTU8gWkVSTyBWQUxVRSBDQTAeFw05ODA1MTMw
38NTQwNThaFw0wMDA1MTIwNTQwNThaMIGeMQswCQYDVQQGEwJBVTETMBEGA1UECBMK
39UXVlZW5zbGFuZDERMA8GA1UEBxMIQnJpc2JhbmUxGjAYBgNVBAoTEUNyeXB0c29m
40dCBQdHkgTHRkMRIwEAYDVQQLEwlTTUlNRSAwMDMxFDASBgNVBAMTC0luZm9ybWF0
41aW9uMSEwHwYJKoZIhvcNAQkBFhJpbmZvQGNyeXB0c29mdC5jb20wXDANBgkqhkiG
429w0BAQEFAANLADBIAkEArecjie4Nh7ecMkRLlYFz3SKASy3FYLj+Hhhj79yJiSLf
43lTx62z2aBqgI1in970EJke28rZj59iiQYm/n5wxNCwIDAQABoygwJjAkBglghkgB
44hvhCAQ0EFxYVR2VuZXJhdGVkIHdpdGggU1NMZWF5MA0GCSqGSIb3DQEBBAUAA0EA
45UhXqiPTw+QvvztX4g0BhFl5V+c4t0YsxXAPGLRB8YdVcCkKX0f1ltraEpTnsRuz8
464A3ZItobUHStkstOkOX6fQ==
47-----END CERTIFICATE-----
48
49-----BEGIN RSA PRIVATE KEY-----
50MIIBOgIBAAJBAK3nI4nuDYe3nDJES5WBc90igEstxWC4/h4YY+/ciYki35U8ets9
51mgaoCNYp/e9BCZHtvK2Y+fYokGJv5+cMTQsCAwEAAQJBAIHpvXvqEcOEoDRRHuIG
52fkcB4jPHcr9KE9TpxabH6xs9beN6OJnkePXAHwaz5MnUgSnbpOKq+cw8miKjXwe/
53zVECIQDVLwncT2lRmXarEYHzb+q/0uaSvKhWKKt3kJasLNTrAwIhANDUc/ghut29
54p3jJYjurzUKuG774/5eLjPLsxPPIZzNZAiA/10hSq41UnGqHLEUIS9m2/EeEZe7b
55bm567dfRU9OnVQIgDo8ROrZXSchEGbaog5J5r/Fle83uO8l93R3GqVxKXZkCIFfk
56IPD5PIYQAyyod3hyKKza7ZP4CGY4oOfZetbkSGGG
57-----END RSA PRIVATE KEY-----
diff --git a/src/lib/libcrypto/rand/rand_egd.c b/src/lib/libcrypto/rand/rand_egd.c
new file mode 100644
index 0000000000..d834408bd4
--- /dev/null
+++ b/src/lib/libcrypto/rand/rand_egd.c
@@ -0,0 +1,110 @@
1/* crypto/rand/rand_egd.c */
2/* Written by Ulf Moeller for the OpenSSL project. */
3/* ====================================================================
4 * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
16 * distribution.
17 *
18 * 3. All advertising materials mentioning features or use of this
19 * software must display the following acknowledgment:
20 * "This product includes software developed by the OpenSSL Project
21 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
22 *
23 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
24 * endorse or promote products derived from this software without
25 * prior written permission. For written permission, please contact
26 * openssl-core@openssl.org.
27 *
28 * 5. Products derived from this software may not be called "OpenSSL"
29 * nor may "OpenSSL" appear in their names without prior written
30 * permission of the OpenSSL Project.
31 *
32 * 6. Redistributions of any form whatsoever must retain the following
33 * acknowledgment:
34 * "This product includes software developed by the OpenSSL Project
35 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
36 *
37 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
38 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
39 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
40 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
41 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
43 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
44 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
45 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
46 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
47 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
48 * OF THE POSSIBILITY OF SUCH DAMAGE.
49 * ====================================================================
50 *
51 * This product includes cryptographic software written by Eric Young
52 * (eay@cryptsoft.com). This product includes software written by Tim
53 * Hudson (tjh@cryptsoft.com).
54 *
55 */
56
57#include <openssl/rand.h>
58
59/* Query the EGD <URL: http://www.lothar.com/tech/crypto/>.
60 */
61
62#if defined(WIN32) || defined(VMS) || defined(__VMS)
63int RAND_egd(const char *path)
64 {
65 return(-1);
66 }
67#else
68#include <openssl/opensslconf.h>
69#include OPENSSL_UNISTD
70#include <sys/types.h>
71#include <sys/socket.h>
72#include <sys/un.h>
73#include <string.h>
74
75#ifndef offsetof
76# define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
77#endif
78
79int RAND_egd(const char *path)
80 {
81 int ret = -1;
82 struct sockaddr_un addr;
83 int len, num;
84 int fd = -1;
85 unsigned char buf[256];
86
87 memset(&addr, 0, sizeof(addr));
88 addr.sun_family = AF_UNIX;
89 if (strlen(path) > sizeof(addr.sun_path))
90 return (-1);
91 strcpy(addr.sun_path,path);
92 len = offsetof(struct sockaddr_un, sun_path) + strlen(path);
93 fd = socket(AF_UNIX, SOCK_STREAM, 0);
94 if (fd == -1) return (-1);
95 if (connect(fd, (struct sockaddr *)&addr, len) == -1) goto err;
96 buf[0] = 1;
97 buf[1] = 255;
98 write(fd, buf, 2);
99 if (read(fd, buf, 1) != 1) goto err;
100 if (buf[0] == 0) goto err;
101 num = read(fd, buf, 255);
102 if (num < 1) goto err;
103 RAND_seed(buf, num);
104 if (RAND_status() == 1)
105 ret = num;
106 err:
107 if (fd != -1) close(fd);
108 return(ret);
109 }
110#endif
diff --git a/src/lib/libcrypto/rand/rand_lcl.h b/src/lib/libcrypto/rand/rand_lcl.h
new file mode 100644
index 0000000000..120e9366d2
--- /dev/null
+++ b/src/lib/libcrypto/rand/rand_lcl.h
@@ -0,0 +1,184 @@
1/* crypto/rand/md_rand.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58/* ====================================================================
59 * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved.
60 *
61 * Redistribution and use in source and binary forms, with or without
62 * modification, are permitted provided that the following conditions
63 * are met:
64 *
65 * 1. Redistributions of source code must retain the above copyright
66 * notice, this list of conditions and the following disclaimer.
67 *
68 * 2. Redistributions in binary form must reproduce the above copyright
69 * notice, this list of conditions and the following disclaimer in
70 * the documentation and/or other materials provided with the
71 * distribution.
72 *
73 * 3. All advertising materials mentioning features or use of this
74 * software must display the following acknowledgment:
75 * "This product includes software developed by the OpenSSL Project
76 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
77 *
78 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
79 * endorse or promote products derived from this software without
80 * prior written permission. For written permission, please contact
81 * openssl-core@openssl.org.
82 *
83 * 5. Products derived from this software may not be called "OpenSSL"
84 * nor may "OpenSSL" appear in their names without prior written
85 * permission of the OpenSSL Project.
86 *
87 * 6. Redistributions of any form whatsoever must retain the following
88 * acknowledgment:
89 * "This product includes software developed by the OpenSSL Project
90 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
91 *
92 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
93 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
94 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
95 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
96 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
97 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
98 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
99 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
100 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
101 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
102 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
103 * OF THE POSSIBILITY OF SUCH DAMAGE.
104 * ====================================================================
105 *
106 * This product includes cryptographic software written by Eric Young
107 * (eay@cryptsoft.com). This product includes software written by Tim
108 * Hudson (tjh@cryptsoft.com).
109 *
110 */
111
112#ifndef HEADER_RAND_LCL_H
113#define HEADER_RAND_LCL_H
114
115#define ENTROPY_NEEDED 20 /* require 160 bits = 20 bytes of randomness */
116
117
118#if !defined(USE_MD5_RAND) && !defined(USE_SHA1_RAND) && !defined(USE_MDC2_RAND) && !defined(USE_MD2_RAND)
119#if !defined(NO_SHA) && !defined(NO_SHA1)
120#define USE_SHA1_RAND
121#elif !defined(NO_MD5)
122#define USE_MD5_RAND
123#elif !defined(NO_MDC2) && !defined(NO_DES)
124#define USE_MDC2_RAND
125#elif !defined(NO_MD2)
126#define USE_MD2_RAND
127#else
128#error No message digest algorithm available
129#endif
130#endif
131
132#if defined(USE_MD5_RAND)
133#include <openssl/md5.h>
134#define MD_DIGEST_LENGTH MD5_DIGEST_LENGTH
135#define MD(a,b,c) MD5(a,b,c)
136#elif defined(USE_SHA1_RAND)
137#include <openssl/sha.h>
138#define MD_DIGEST_LENGTH SHA_DIGEST_LENGTH
139#define MD(a,b,c) SHA1(a,b,c)
140#elif defined(USE_MDC2_RAND)
141#include <openssl/mdc2.h>
142#define MD_DIGEST_LENGTH MDC2_DIGEST_LENGTH
143#define MD(a,b,c) MDC2(a,b,c)
144#elif defined(USE_MD2_RAND)
145#include <openssl/md2.h>
146#define MD_DIGEST_LENGTH MD2_DIGEST_LENGTH
147#define MD(a,b,c) MD2(a,b,c)
148#endif
149#if defined(USE_MD5_RAND)
150#include <openssl/md5.h>
151#define MD_DIGEST_LENGTH MD5_DIGEST_LENGTH
152#define MD_CTX MD5_CTX
153#define MD_Init(a) MD5_Init(a)
154#define MD_Update(a,b,c) MD5_Update(a,b,c)
155#define MD_Final(a,b) MD5_Final(a,b)
156#define MD(a,b,c) MD5(a,b,c)
157#elif defined(USE_SHA1_RAND)
158#include <openssl/sha.h>
159#define MD_DIGEST_LENGTH SHA_DIGEST_LENGTH
160#define MD_CTX SHA_CTX
161#define MD_Init(a) SHA1_Init(a)
162#define MD_Update(a,b,c) SHA1_Update(a,b,c)
163#define MD_Final(a,b) SHA1_Final(a,b)
164#define MD(a,b,c) SHA1(a,b,c)
165#elif defined(USE_MDC2_RAND)
166#include <openssl/mdc2.h>
167#define MD_DIGEST_LENGTH MDC2_DIGEST_LENGTH
168#define MD_CTX MDC2_CTX
169#define MD_Init(a) MDC2_Init(a)
170#define MD_Update(a,b,c) MDC2_Update(a,b,c)
171#define MD_Final(a,b) MDC2_Final(a,b)
172#define MD(a,b,c) MDC2(a,b,c)
173#elif defined(USE_MD2_RAND)
174#include <openssl/md2.h>
175#define MD_DIGEST_LENGTH MD2_DIGEST_LENGTH
176#define MD_CTX MD2_CTX
177#define MD_Init(a) MD2_Init(a)
178#define MD_Update(a,b,c) MD2_Update(a,b,c)
179#define MD_Final(a,b) MD2_Final(a,b)
180#define MD(a,b,c) MD2(a,b,c)
181#endif
182
183
184#endif
diff --git a/src/lib/libcrypto/rand/rand_os2.c b/src/lib/libcrypto/rand/rand_os2.c
new file mode 100644
index 0000000000..c3e36d4e5e
--- /dev/null
+++ b/src/lib/libcrypto/rand/rand_os2.c
@@ -0,0 +1,147 @@
1/* crypto/rand/rand_os2.c */
2/* ====================================================================
3 * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56#include "cryptlib.h"
57#include <openssl/rand.h>
58#include "rand_lcl.h"
59
60#ifdef OPENSSL_SYS_OS2
61
62#define INCL_DOSPROCESS
63#define INCL_DOSPROFILE
64#define INCL_DOSMISC
65#define INCL_DOSMODULEMGR
66#include <os2.h>
67
68#define CMD_KI_RDCNT (0x63)
69
70typedef struct _CPUUTIL {
71 ULONG ulTimeLow; /* Low 32 bits of time stamp */
72 ULONG ulTimeHigh; /* High 32 bits of time stamp */
73 ULONG ulIdleLow; /* Low 32 bits of idle time */
74 ULONG ulIdleHigh; /* High 32 bits of idle time */
75 ULONG ulBusyLow; /* Low 32 bits of busy time */
76 ULONG ulBusyHigh; /* High 32 bits of busy time */
77 ULONG ulIntrLow; /* Low 32 bits of interrupt time */
78 ULONG ulIntrHigh; /* High 32 bits of interrupt time */
79} CPUUTIL;
80
81APIRET APIENTRY(*DosPerfSysCall) (ULONG ulCommand, ULONG ulParm1, ULONG ulParm2, ULONG ulParm3) = NULL;
82APIRET APIENTRY(*DosQuerySysState) (ULONG func, ULONG arg1, ULONG pid, ULONG _res_, PVOID buf, ULONG bufsz) = NULL;
83HMODULE hDoscalls = 0;
84
85int RAND_poll(void)
86{
87 char failed_module[20];
88 QWORD qwTime;
89 ULONG SysVars[QSV_FOREGROUND_PROCESS];
90
91 if (hDoscalls == 0) {
92 ULONG rc = DosLoadModule(failed_module, sizeof(failed_module), "DOSCALLS", &hDoscalls);
93
94 if (rc == 0) {
95 rc = DosQueryProcAddr(hDoscalls, 976, NULL, (PFN *)&DosPerfSysCall);
96
97 if (rc)
98 DosPerfSysCall = NULL;
99
100 rc = DosQueryProcAddr(hDoscalls, 368, NULL, (PFN *)&DosQuerySysState);
101
102 if (rc)
103 DosQuerySysState = NULL;
104 }
105 }
106
107 /* Sample the hi-res timer, runs at around 1.1 MHz */
108 DosTmrQueryTime(&qwTime);
109 RAND_add(&qwTime, sizeof(qwTime), 2);
110
111 /* Sample a bunch of system variables, includes various process & memory statistics */
112 DosQuerySysInfo(1, QSV_FOREGROUND_PROCESS, SysVars, sizeof(SysVars));
113 RAND_add(SysVars, sizeof(SysVars), 4);
114
115 /* If available, sample CPU registers that count at CPU MHz
116 * Only fairly new CPUs (PPro & K6 onwards) & OS/2 versions support this
117 */
118 if (DosPerfSysCall) {
119 CPUUTIL util;
120
121 if (DosPerfSysCall(CMD_KI_RDCNT, (ULONG)&util, 0, 0) == 0) {
122 RAND_add(&util, sizeof(util), 10);
123 }
124 else {
125 DosPerfSysCall = NULL;
126 }
127 }
128
129 /* DosQuerySysState() gives us a huge quantity of process, thread, memory & handle stats */
130 if (DosQuerySysState) {
131 char *buffer = OPENSSL_malloc(256 * 1024);
132
133 if (DosQuerySysState(0x1F, 0, 0, 0, buffer, 256 * 1024) == 0) {
134 /* First 4 bytes in buffer is a pointer to the thread count
135 * there should be at least 1 byte of entropy per thread
136 */
137 RAND_add(buffer, 256 * 1024, **(ULONG **)buffer);
138 }
139
140 OPENSSL_free(buffer);
141 return 1;
142 }
143
144 return 0;
145}
146
147#endif /* OPENSSL_SYS_OS2 */
diff --git a/src/lib/libcrypto/rand/rand_unix.c b/src/lib/libcrypto/rand/rand_unix.c
new file mode 100644
index 0000000000..0b29235130
--- /dev/null
+++ b/src/lib/libcrypto/rand/rand_unix.c
@@ -0,0 +1,274 @@
1/* crypto/rand/rand_unix.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58/* ====================================================================
59 * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved.
60 *
61 * Redistribution and use in source and binary forms, with or without
62 * modification, are permitted provided that the following conditions
63 * are met:
64 *
65 * 1. Redistributions of source code must retain the above copyright
66 * notice, this list of conditions and the following disclaimer.
67 *
68 * 2. Redistributions in binary form must reproduce the above copyright
69 * notice, this list of conditions and the following disclaimer in
70 * the documentation and/or other materials provided with the
71 * distribution.
72 *
73 * 3. All advertising materials mentioning features or use of this
74 * software must display the following acknowledgment:
75 * "This product includes software developed by the OpenSSL Project
76 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
77 *
78 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
79 * endorse or promote products derived from this software without
80 * prior written permission. For written permission, please contact
81 * openssl-core@openssl.org.
82 *
83 * 5. Products derived from this software may not be called "OpenSSL"
84 * nor may "OpenSSL" appear in their names without prior written
85 * permission of the OpenSSL Project.
86 *
87 * 6. Redistributions of any form whatsoever must retain the following
88 * acknowledgment:
89 * "This product includes software developed by the OpenSSL Project
90 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
91 *
92 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
93 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
94 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
95 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
96 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
97 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
98 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
99 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
100 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
101 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
102 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
103 * OF THE POSSIBILITY OF SUCH DAMAGE.
104 * ====================================================================
105 *
106 * This product includes cryptographic software written by Eric Young
107 * (eay@cryptsoft.com). This product includes software written by Tim
108 * Hudson (tjh@cryptsoft.com).
109 *
110 */
111
112#include "cryptlib.h"
113#include <openssl/rand.h>
114#include "rand_lcl.h"
115
116#if !(defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_OS2))
117
118#include <sys/types.h>
119#include <sys/time.h>
120#include <sys/times.h>
121#include <fcntl.h>
122#include <unistd.h>
123#include <time.h>
124
125#ifdef __OpenBSD__
126#undef DEVRANDOM
127#define DEVRANDOM "/dev/arandom"
128int RAND_poll(void)
129{
130 unsigned long l;
131 pid_t curr_pid = getpid();
132 FILE *fh;
133
134 /* Use a random entropy pool device. Linux, FreeBSD and OpenBSD
135 * have this. Use /dev/urandom if you can as /dev/random may block
136 * if it runs out of random entries. */
137
138 if ((fh = fopen(DEVRANDOM, "r")) != NULL)
139 {
140 unsigned char tmpbuf[ENTROPY_NEEDED];
141 int n;
142
143 setvbuf(fh, NULL, _IONBF, 0);
144 n=fread((unsigned char *)tmpbuf,1,ENTROPY_NEEDED,fh);
145 fclose(fh);
146 RAND_add(tmpbuf,sizeof tmpbuf,n);
147 memset(tmpbuf,0,n);
148 }
149
150 /* put in some default random data, we need more than just this */
151 l=curr_pid;
152 RAND_add(&l,sizeof(l),0);
153 l=getuid();
154 RAND_add(&l,sizeof(l),0);
155
156 l=time(NULL);
157 RAND_add(&l,sizeof(l),0);
158
159 return 1;
160}
161#else
162int RAND_poll(void)
163{
164 unsigned long l;
165 pid_t curr_pid = getpid();
166#if defined(DEVRANDOM) || defined(DEVRANDOM_EGD)
167 unsigned char tmpbuf[ENTROPY_NEEDED];
168 int n = 0;
169#endif
170#ifdef DEVRANDOM
171 static const char *randomfiles[] = { DEVRANDOM, NULL };
172 const char **randomfile = NULL;
173 int fd;
174#endif
175#ifdef DEVRANDOM_EGD
176 static const char *egdsockets[] = { DEVRANDOM_EGD, NULL };
177 const char **egdsocket = NULL;
178#endif
179
180#ifdef DEVRANDOM
181 /* Use a random entropy pool device. Linux, FreeBSD and OpenBSD
182 * have this. Use /dev/urandom if you can as /dev/random may block
183 * if it runs out of random entries. */
184
185 for (randomfile = randomfiles; *randomfile && n < ENTROPY_NEEDED; randomfile++)
186 {
187 if ((fd = open(*randomfile, O_RDONLY|O_NONBLOCK
188#ifdef O_NOCTTY /* If it happens to be a TTY (god forbid), do not make it
189 our controlling tty */
190 |O_NOCTTY
191#endif
192#ifdef O_NOFOLLOW /* Fail if the file is a symbolic link */
193 |O_NOFOLLOW
194#endif
195 )) >= 0)
196 {
197 struct timeval t = { 0, 10*1000 }; /* Spend 10ms on
198 each file. */
199 int r;
200 fd_set fset;
201
202 do
203 {
204 FD_ZERO(&fset);
205 FD_SET(fd, &fset);
206 r = -1;
207
208 if (select(fd+1,&fset,NULL,NULL,&t) < 0)
209 t.tv_usec=0;
210 else if (FD_ISSET(fd, &fset))
211 {
212 r=read(fd,(unsigned char *)tmpbuf+n,
213 ENTROPY_NEEDED-n);
214 if (r > 0)
215 n += r;
216 }
217
218 /* Some Unixen will update t, some
219 won't. For those who won't, give
220 up here, otherwise, we will do
221 this once again for the remaining
222 time. */
223 if (t.tv_usec == 10*1000)
224 t.tv_usec=0;
225 }
226 while ((r > 0 || (errno == EINTR || errno == EAGAIN))
227 && t.tv_usec != 0 && n < ENTROPY_NEEDED);
228
229 close(fd);
230 }
231 }
232#endif
233
234#ifdef DEVRANDOM_EGD
235 /* Use an EGD socket to read entropy from an EGD or PRNGD entropy
236 * collecting daemon. */
237
238 for (egdsocket = egdsockets; *egdsocket && n < ENTROPY_NEEDED; egdsocket++)
239 {
240 int r;
241
242 r = RAND_query_egd_bytes(*egdsocket, (unsigned char *)tmpbuf+n,
243 ENTROPY_NEEDED-n);
244 if (r > 0)
245 n += r;
246 }
247#endif
248
249#if defined(DEVRANDOM) || defined(DEVRANDOM_EGD)
250 if (n > 0)
251 {
252 RAND_add(tmpbuf,sizeof tmpbuf,n);
253 memset(tmpbuf,0,n);
254 }
255#endif
256
257 /* put in some default random data, we need more than just this */
258 l=curr_pid;
259 RAND_add(&l,sizeof(l),0);
260 l=getuid();
261 RAND_add(&l,sizeof(l),0);
262
263 l=time(NULL);
264 RAND_add(&l,sizeof(l),0);
265
266#if defined(DEVRANDOM) || defined(DEVRANDOM_EGD)
267 return 1;
268#else
269 return 0;
270#endif
271}
272
273#endif
274#endif
diff --git a/src/lib/libcrypto/rand/rand_vms.c b/src/lib/libcrypto/rand/rand_vms.c
new file mode 100644
index 0000000000..29b2d7af0b
--- /dev/null
+++ b/src/lib/libcrypto/rand/rand_vms.c
@@ -0,0 +1,135 @@
1/* crypto/rand/rand_vms.c -*- mode:C; c-file-style: "eay" -*- */
2/* Written by Richard Levitte <richard@levitte.org> for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 1998-2000 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/rand.h>
60#include "rand_lcl.h"
61
62#if defined(OPENSSL_SYS_VMS)
63
64#include <descrip.h>
65#include <jpidef.h>
66#include <ssdef.h>
67#include <starlet.h>
68#ifdef __DECC
69# pragma message disable DOLLARID
70#endif
71
72static struct items_data_st
73 {
74 short length, code; /* length is amount of bytes */
75 } items_data[] =
76 { { 4, JPI$_BUFIO },
77 { 4, JPI$_CPUTIM },
78 { 4, JPI$_DIRIO },
79 { 8, JPI$_LOGINTIM },
80 { 4, JPI$_PAGEFLTS },
81 { 4, JPI$_PID },
82 { 4, JPI$_WSSIZE },
83 { 0, 0 }
84 };
85
86int RAND_poll(void)
87 {
88 long pid, iosb[2];
89 int status = 0;
90 struct
91 {
92 short length, code;
93 long *buffer;
94 int *retlen;
95 } item[32], *pitem;
96 unsigned char data_buffer[256];
97 short total_length = 0;
98 struct items_data_st *pitems_data;
99
100 pitems_data = items_data;
101 pitem = item;
102
103 /* Setup */
104 while (pitems_data->length)
105 {
106 pitem->length = pitems_data->length;
107 pitem->code = pitems_data->code;
108 pitem->buffer = (long *)data_buffer[total_length];
109 pitem->retlen = 0;
110 total_length += pitems_data->length;
111 pitems_data++;
112 pitem++;
113 }
114 pitem->length = pitem->code = 0;
115
116 /*
117 * Scan through all the processes in the system and add entropy with
118 * results from the processes that were possible to look at.
119 * However, view the information as only half trustable.
120 */
121 pid = -1; /* search context */
122 while ((status = sys$getjpiw(0, &pid, 0, item, iosb, 0, 0))
123 != SS$_NOMOREPROC)
124 {
125 if (status == SS$_NORMAL)
126 {
127 RAND_add(data_buffer, total_length, total_length/2);
128 }
129 }
130 sys$gettim(iosb);
131 RAND_add((unsigned char *)iosb, sizeof(iosb), sizeof(iosb)/2);
132 return 1;
133}
134
135#endif
diff --git a/src/lib/libcrypto/rand/rand_win.c b/src/lib/libcrypto/rand/rand_win.c
new file mode 100644
index 0000000000..9f2dcff9a9
--- /dev/null
+++ b/src/lib/libcrypto/rand/rand_win.c
@@ -0,0 +1,732 @@
1/* crypto/rand/rand_win.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58/* ====================================================================
59 * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved.
60 *
61 * Redistribution and use in source and binary forms, with or without
62 * modification, are permitted provided that the following conditions
63 * are met:
64 *
65 * 1. Redistributions of source code must retain the above copyright
66 * notice, this list of conditions and the following disclaimer.
67 *
68 * 2. Redistributions in binary form must reproduce the above copyright
69 * notice, this list of conditions and the following disclaimer in
70 * the documentation and/or other materials provided with the
71 * distribution.
72 *
73 * 3. All advertising materials mentioning features or use of this
74 * software must display the following acknowledgment:
75 * "This product includes software developed by the OpenSSL Project
76 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
77 *
78 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
79 * endorse or promote products derived from this software without
80 * prior written permission. For written permission, please contact
81 * openssl-core@openssl.org.
82 *
83 * 5. Products derived from this software may not be called "OpenSSL"
84 * nor may "OpenSSL" appear in their names without prior written
85 * permission of the OpenSSL Project.
86 *
87 * 6. Redistributions of any form whatsoever must retain the following
88 * acknowledgment:
89 * "This product includes software developed by the OpenSSL Project
90 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
91 *
92 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
93 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
94 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
95 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
96 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
97 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
98 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
99 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
100 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
101 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
102 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
103 * OF THE POSSIBILITY OF SUCH DAMAGE.
104 * ====================================================================
105 *
106 * This product includes cryptographic software written by Eric Young
107 * (eay@cryptsoft.com). This product includes software written by Tim
108 * Hudson (tjh@cryptsoft.com).
109 *
110 */
111
112#include "cryptlib.h"
113#include <openssl/rand.h>
114#include "rand_lcl.h"
115
116#if defined(WINDOWS) || defined(WIN32)
117#include <windows.h>
118#ifndef _WIN32_WINNT
119# define _WIN32_WINNT 0x0400
120#endif
121#include <wincrypt.h>
122#include <tlhelp32.h>
123
124/* Intel hardware RNG CSP -- available from
125 * http://developer.intel.com/design/security/rng/redist_license.htm
126 */
127#define PROV_INTEL_SEC 22
128#define INTEL_DEF_PROV "Intel Hardware Cryptographic Service Provider"
129
130static void readtimer(void);
131static void readscreen(void);
132
133/* It appears like CURSORINFO, PCURSORINFO and LPCURSORINFO are only defined
134 when WINVER is 0x0500 and up, which currently only happens on Win2000.
135 Unfortunately, those are typedefs, so they're a little bit difficult to
136 detect properly. On the other hand, the macro CURSOR_SHOWING is defined
137 within the same conditional, so it can be use to detect the absence of said
138 typedefs. */
139
140#ifndef CURSOR_SHOWING
141/*
142 * Information about the global cursor.
143 */
144typedef struct tagCURSORINFO
145{
146 DWORD cbSize;
147 DWORD flags;
148 HCURSOR hCursor;
149 POINT ptScreenPos;
150} CURSORINFO, *PCURSORINFO, *LPCURSORINFO;
151
152#define CURSOR_SHOWING 0x00000001
153#endif /* CURSOR_SHOWING */
154
155typedef BOOL (WINAPI *CRYPTACQUIRECONTEXT)(HCRYPTPROV *, LPCTSTR, LPCTSTR,
156 DWORD, DWORD);
157typedef BOOL (WINAPI *CRYPTGENRANDOM)(HCRYPTPROV, DWORD, BYTE *);
158typedef BOOL (WINAPI *CRYPTRELEASECONTEXT)(HCRYPTPROV, DWORD);
159
160typedef HWND (WINAPI *GETFOREGROUNDWINDOW)(VOID);
161typedef BOOL (WINAPI *GETCURSORINFO)(PCURSORINFO);
162typedef DWORD (WINAPI *GETQUEUESTATUS)(UINT);
163
164typedef HANDLE (WINAPI *CREATETOOLHELP32SNAPSHOT)(DWORD, DWORD);
165typedef BOOL (WINAPI *HEAP32FIRST)(LPHEAPENTRY32, DWORD, DWORD);
166typedef BOOL (WINAPI *HEAP32NEXT)(LPHEAPENTRY32);
167typedef BOOL (WINAPI *HEAP32LIST)(HANDLE, LPHEAPLIST32);
168typedef BOOL (WINAPI *PROCESS32)(HANDLE, LPPROCESSENTRY32);
169typedef BOOL (WINAPI *THREAD32)(HANDLE, LPTHREADENTRY32);
170typedef BOOL (WINAPI *MODULE32)(HANDLE, LPMODULEENTRY32);
171
172#include <lmcons.h>
173#include <lmstats.h>
174#if 1 /* The NET API is Unicode only. It requires the use of the UNICODE
175 * macro. When UNICODE is defined LPTSTR becomes LPWSTR. LMSTR was
176 * was added to the Platform SDK to allow the NET API to be used in
177 * non-Unicode applications provided that Unicode strings were still
178 * used for input. LMSTR is defined as LPWSTR.
179 */
180typedef NET_API_STATUS (NET_API_FUNCTION * NETSTATGET)
181 (LPWSTR, LPWSTR, DWORD, DWORD, LPBYTE*);
182typedef NET_API_STATUS (NET_API_FUNCTION * NETFREE)(LPBYTE);
183#endif /* 1 */
184
185int RAND_poll(void)
186{
187 MEMORYSTATUS m;
188 HCRYPTPROV hProvider = 0;
189 BYTE buf[64];
190 DWORD w;
191 HWND h;
192
193 HMODULE advapi, kernel, user, netapi;
194 CRYPTACQUIRECONTEXT acquire = 0;
195 CRYPTGENRANDOM gen = 0;
196 CRYPTRELEASECONTEXT release = 0;
197#if 1 /* There was previously a problem with NETSTATGET. Currently, this
198 * section is still experimental, but if all goes well, this conditional
199 * will be removed
200 */
201 NETSTATGET netstatget = 0;
202 NETFREE netfree = 0;
203#endif /* 1 */
204
205 /* Determine the OS version we are on so we can turn off things
206 * that do not work properly.
207 */
208 OSVERSIONINFO osverinfo ;
209 osverinfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO) ;
210 GetVersionEx( &osverinfo ) ;
211
212 /* load functions dynamically - not available on all systems */
213 advapi = LoadLibrary("ADVAPI32.DLL");
214 kernel = LoadLibrary("KERNEL32.DLL");
215 user = LoadLibrary("USER32.DLL");
216 netapi = LoadLibrary("NETAPI32.DLL");
217
218#if 1 /* There was previously a problem with NETSTATGET. Currently, this
219 * section is still experimental, but if all goes well, this conditional
220 * will be removed
221 */
222 if (netapi)
223 {
224 netstatget = (NETSTATGET) GetProcAddress(netapi,"NetStatisticsGet");
225 netfree = (NETFREE) GetProcAddress(netapi,"NetApiBufferFree");
226 }
227
228 if (netstatget && netfree)
229 {
230 LPBYTE outbuf;
231 /* NetStatisticsGet() is a Unicode only function
232 * STAT_WORKSTATION_0 contains 45 fields and STAT_SERVER_0
233 * contains 17 fields. We treat each field as a source of
234 * one byte of entropy.
235 */
236
237 if (netstatget(NULL, L"LanmanWorkstation", 0, 0, &outbuf) == 0)
238 {
239 RAND_add(outbuf, sizeof(STAT_WORKSTATION_0), 45);
240 netfree(outbuf);
241 }
242 if (netstatget(NULL, L"LanmanServer", 0, 0, &outbuf) == 0)
243 {
244 RAND_add(outbuf, sizeof(STAT_SERVER_0), 17);
245 netfree(outbuf);
246 }
247 }
248
249 if (netapi)
250 FreeLibrary(netapi);
251#endif /* 1 */
252
253 /* It appears like this can cause an exception deep within ADVAPI32.DLL
254 * at random times on Windows 2000. Reported by Jeffrey Altman.
255 * Only use it on NT.
256 */
257 if ( osverinfo.dwPlatformId == VER_PLATFORM_WIN32_NT &&
258 osverinfo.dwMajorVersion < 5)
259 {
260 /* Read Performance Statistics from NT/2000 registry
261 * The size of the performance data can vary from call
262 * to call so we must guess the size of the buffer to use
263 * and increase its size if we get an ERROR_MORE_DATA
264 * return instead of ERROR_SUCCESS.
265 */
266 LONG rc=ERROR_MORE_DATA;
267 char * buf=NULL;
268 DWORD bufsz=0;
269 DWORD length;
270
271 while (rc == ERROR_MORE_DATA)
272 {
273 buf = realloc(buf,bufsz+8192);
274 if (!buf)
275 break;
276 bufsz += 8192;
277
278 length = bufsz;
279 rc = RegQueryValueEx(HKEY_PERFORMANCE_DATA, "Global",
280 NULL, NULL, buf, &length);
281 }
282 if (rc == ERROR_SUCCESS)
283 {
284 /* For entropy count assume only least significant
285 * byte of each DWORD is random.
286 */
287 RAND_add(&length, sizeof(length), 0);
288 RAND_add(buf, length, length / 4.0);
289 }
290 if (buf)
291 free(buf);
292 }
293
294 if (advapi)
295 {
296 acquire = (CRYPTACQUIRECONTEXT) GetProcAddress(advapi,
297 "CryptAcquireContextA");
298 gen = (CRYPTGENRANDOM) GetProcAddress(advapi,
299 "CryptGenRandom");
300 release = (CRYPTRELEASECONTEXT) GetProcAddress(advapi,
301 "CryptReleaseContext");
302 }
303
304 if (acquire && gen && release)
305 {
306 /* poll the CryptoAPI PRNG */
307 /* The CryptoAPI returns sizeof(buf) bytes of randomness */
308 if (acquire(&hProvider, 0, 0, PROV_RSA_FULL,
309 CRYPT_VERIFYCONTEXT))
310 {
311 if (gen(hProvider, sizeof(buf), buf) != 0)
312 {
313 RAND_add(buf, sizeof(buf), sizeof(buf));
314#ifdef DEBUG
315 printf("randomness from PROV_RSA_FULL\n");
316#endif
317 }
318 release(hProvider, 0);
319 }
320
321 /* poll the Pentium PRG with CryptoAPI */
322 if (acquire(&hProvider, 0, INTEL_DEF_PROV, PROV_INTEL_SEC, 0))
323 {
324 if (gen(hProvider, sizeof(buf), buf) != 0)
325 {
326 RAND_add(buf, sizeof(buf), sizeof(buf));
327#ifdef DEBUG
328 printf("randomness from PROV_INTEL_SEC\n");
329#endif
330 }
331 release(hProvider, 0);
332 }
333 }
334
335 if (advapi)
336 FreeLibrary(advapi);
337
338 /* timer data */
339 readtimer();
340
341 /* memory usage statistics */
342 GlobalMemoryStatus(&m);
343 RAND_add(&m, sizeof(m), 1);
344
345 /* process ID */
346 w = GetCurrentProcessId();
347 RAND_add(&w, sizeof(w), 1);
348
349 if (user)
350 {
351 GETCURSORINFO cursor;
352 GETFOREGROUNDWINDOW win;
353 GETQUEUESTATUS queue;
354
355 win = (GETFOREGROUNDWINDOW) GetProcAddress(user, "GetForegroundWindow");
356 cursor = (GETCURSORINFO) GetProcAddress(user, "GetCursorInfo");
357 queue = (GETQUEUESTATUS) GetProcAddress(user, "GetQueueStatus");
358
359 if (win)
360 {
361 /* window handle */
362 h = win();
363 RAND_add(&h, sizeof(h), 0);
364 }
365 if (cursor)
366 {
367 /* unfortunately, its not safe to call GetCursorInfo()
368 * on NT4 even though it exists in SP3 (or SP6) and
369 * higher.
370 */
371 if ( osverinfo.dwPlatformId == VER_PLATFORM_WIN32_NT &&
372 osverinfo.dwMajorVersion < 5)
373 cursor = 0;
374 }
375 if (cursor)
376 {
377 /* cursor position */
378 /* assume 2 bytes of entropy */
379 CURSORINFO ci;
380 ci.cbSize = sizeof(CURSORINFO);
381 if (cursor(&ci))
382 RAND_add(&ci, ci.cbSize, 2);
383 }
384
385 if (queue)
386 {
387 /* message queue status */
388 /* assume 1 byte of entropy */
389 w = queue(QS_ALLEVENTS);
390 RAND_add(&w, sizeof(w), 1);
391 }
392
393 FreeLibrary(user);
394 }
395
396 /* Toolhelp32 snapshot: enumerate processes, threads, modules and heap
397 * http://msdn.microsoft.com/library/psdk/winbase/toolhelp_5pfd.htm
398 * (Win 9x and 2000 only, not available on NT)
399 *
400 * This seeding method was proposed in Peter Gutmann, Software
401 * Generation of Practically Strong Random Numbers,
402 * http://www.usenix.org/publications/library/proceedings/sec98/gutmann.html
403 * revised version at http://www.cryptoengines.com/~peter/06_random.pdf
404 * (The assignment of entropy estimates below is arbitrary, but based
405 * on Peter's analysis the full poll appears to be safe. Additional
406 * interactive seeding is encouraged.)
407 */
408
409 if (kernel)
410 {
411 CREATETOOLHELP32SNAPSHOT snap;
412 HANDLE handle;
413
414 HEAP32FIRST heap_first;
415 HEAP32NEXT heap_next;
416 HEAP32LIST heaplist_first, heaplist_next;
417 PROCESS32 process_first, process_next;
418 THREAD32 thread_first, thread_next;
419 MODULE32 module_first, module_next;
420
421 HEAPLIST32 hlist;
422 HEAPENTRY32 hentry;
423 PROCESSENTRY32 p;
424 THREADENTRY32 t;
425 MODULEENTRY32 m;
426
427 snap = (CREATETOOLHELP32SNAPSHOT)
428 GetProcAddress(kernel, "CreateToolhelp32Snapshot");
429 heap_first = (HEAP32FIRST) GetProcAddress(kernel, "Heap32First");
430 heap_next = (HEAP32NEXT) GetProcAddress(kernel, "Heap32Next");
431 heaplist_first = (HEAP32LIST) GetProcAddress(kernel, "Heap32ListFirst");
432 heaplist_next = (HEAP32LIST) GetProcAddress(kernel, "Heap32ListNext");
433 process_first = (PROCESS32) GetProcAddress(kernel, "Process32First");
434 process_next = (PROCESS32) GetProcAddress(kernel, "Process32Next");
435 thread_first = (THREAD32) GetProcAddress(kernel, "Thread32First");
436 thread_next = (THREAD32) GetProcAddress(kernel, "Thread32Next");
437 module_first = (MODULE32) GetProcAddress(kernel, "Module32First");
438 module_next = (MODULE32) GetProcAddress(kernel, "Module32Next");
439
440 if (snap && heap_first && heap_next && heaplist_first &&
441 heaplist_next && process_first && process_next &&
442 thread_first && thread_next && module_first &&
443 module_next && (handle = snap(TH32CS_SNAPALL,0))
444 != NULL)
445 {
446 /* heap list and heap walking */
447 /* HEAPLIST32 contains 3 fields that will change with
448 * each entry. Consider each field a source of 1 byte
449 * of entropy.
450 * HEAPENTRY32 contains 5 fields that will change with
451 * each entry. Consider each field a source of 1 byte
452 * of entropy.
453 */
454 hlist.dwSize = sizeof(HEAPLIST32);
455 if (heaplist_first(handle, &hlist))
456 do
457 {
458 RAND_add(&hlist, hlist.dwSize, 3);
459 hentry.dwSize = sizeof(HEAPENTRY32);
460 if (heap_first(&hentry,
461 hlist.th32ProcessID,
462 hlist.th32HeapID))
463 {
464 int entrycnt = 50;
465 do
466 RAND_add(&hentry,
467 hentry.dwSize, 5);
468 while (heap_next(&hentry)
469 && --entrycnt > 0);
470 }
471 } while (heaplist_next(handle,
472 &hlist));
473
474 /* process walking */
475 /* PROCESSENTRY32 contains 9 fields that will change
476 * with each entry. Consider each field a source of
477 * 1 byte of entropy.
478 */
479 p.dwSize = sizeof(PROCESSENTRY32);
480 if (process_first(handle, &p))
481 do
482 RAND_add(&p, p.dwSize, 9);
483 while (process_next(handle, &p));
484
485 /* thread walking */
486 /* THREADENTRY32 contains 6 fields that will change
487 * with each entry. Consider each field a source of
488 * 1 byte of entropy.
489 */
490 t.dwSize = sizeof(THREADENTRY32);
491 if (thread_first(handle, &t))
492 do
493 RAND_add(&t, t.dwSize, 6);
494 while (thread_next(handle, &t));
495
496 /* module walking */
497 /* MODULEENTRY32 contains 9 fields that will change
498 * with each entry. Consider each field a source of
499 * 1 byte of entropy.
500 */
501 m.dwSize = sizeof(MODULEENTRY32);
502 if (module_first(handle, &m))
503 do
504 RAND_add(&m, m.dwSize, 9);
505 while (module_next(handle, &m));
506
507 CloseHandle(handle);
508 }
509
510 FreeLibrary(kernel);
511 }
512
513#ifdef DEBUG
514 printf("Exiting RAND_poll\n");
515#endif
516
517 return(1);
518}
519
520int RAND_event(UINT iMsg, WPARAM wParam, LPARAM lParam)
521 {
522 double add_entropy=0;
523
524 switch (iMsg)
525 {
526 case WM_KEYDOWN:
527 {
528 static WPARAM key;
529 if (key != wParam)
530 add_entropy = 0.05;
531 key = wParam;
532 }
533 break;
534 case WM_MOUSEMOVE:
535 {
536 static int lastx,lasty,lastdx,lastdy;
537 int x,y,dx,dy;
538
539 x=LOWORD(lParam);
540 y=HIWORD(lParam);
541 dx=lastx-x;
542 dy=lasty-y;
543 if (dx != 0 && dy != 0 && dx-lastdx != 0 && dy-lastdy != 0)
544 add_entropy=.2;
545 lastx=x, lasty=y;
546 lastdx=dx, lastdy=dy;
547 }
548 break;
549 }
550
551 readtimer();
552 RAND_add(&iMsg, sizeof(iMsg), add_entropy);
553 RAND_add(&wParam, sizeof(wParam), 0);
554 RAND_add(&lParam, sizeof(lParam), 0);
555
556 return (RAND_status());
557 }
558
559
560void RAND_screen(void) /* function available for backward compatibility */
561{
562 RAND_poll();
563 readscreen();
564}
565
566
567/* feed timing information to the PRNG */
568static void readtimer(void)
569{
570 DWORD w;
571 LARGE_INTEGER l;
572 static int have_perfc = 1;
573#ifndef __GNUC__
574 static int have_tsc = 1;
575 DWORD cyclecount;
576
577 if (have_tsc) {
578 __try {
579 __asm {
580 rdtsc
581 mov cyclecount, eax
582 }
583 RAND_add(&cyclecount, sizeof(cyclecount), 1);
584 } __except(EXCEPTION_EXECUTE_HANDLER) {
585 have_tsc = 0;
586 }
587 }
588#else
589# define have_tsc 0
590#endif
591
592 if (have_perfc) {
593 if (QueryPerformanceCounter(&l) == 0)
594 have_perfc = 0;
595 else
596 RAND_add(&l, sizeof(l), 0);
597 }
598
599 if (!have_tsc && !have_perfc) {
600 w = GetTickCount();
601 RAND_add(&w, sizeof(w), 0);
602 }
603}
604
605/* feed screen contents to PRNG */
606/*****************************************************************************
607 *
608 * Created 960901 by Gertjan van Oosten, gertjan@West.NL, West Consulting B.V.
609 *
610 * Code adapted from
611 * <URL:http://www.microsoft.com/kb/developr/win_dk/q97193.htm>;
612 * the original copyright message is:
613 *
614 * (C) Copyright Microsoft Corp. 1993. All rights reserved.
615 *
616 * You have a royalty-free right to use, modify, reproduce and
617 * distribute the Sample Files (and/or any modified version) in
618 * any way you find useful, provided that you agree that
619 * Microsoft has no warranty obligations or liability for any
620 * Sample Application Files which are modified.
621 */
622
623static void readscreen(void)
624{
625 HDC hScrDC; /* screen DC */
626 HDC hMemDC; /* memory DC */
627 HBITMAP hBitmap; /* handle for our bitmap */
628 HBITMAP hOldBitmap; /* handle for previous bitmap */
629 BITMAP bm; /* bitmap properties */
630 unsigned int size; /* size of bitmap */
631 char *bmbits; /* contents of bitmap */
632 int w; /* screen width */
633 int h; /* screen height */
634 int y; /* y-coordinate of screen lines to grab */
635 int n = 16; /* number of screen lines to grab at a time */
636
637 /* Create a screen DC and a memory DC compatible to screen DC */
638 hScrDC = CreateDC("DISPLAY", NULL, NULL, NULL);
639 hMemDC = CreateCompatibleDC(hScrDC);
640
641 /* Get screen resolution */
642 w = GetDeviceCaps(hScrDC, HORZRES);
643 h = GetDeviceCaps(hScrDC, VERTRES);
644
645 /* Create a bitmap compatible with the screen DC */
646 hBitmap = CreateCompatibleBitmap(hScrDC, w, n);
647
648 /* Select new bitmap into memory DC */
649 hOldBitmap = SelectObject(hMemDC, hBitmap);
650
651 /* Get bitmap properties */
652 GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bm);
653 size = (unsigned int)bm.bmWidthBytes * bm.bmHeight * bm.bmPlanes;
654
655 bmbits = OPENSSL_malloc(size);
656 if (bmbits) {
657 /* Now go through the whole screen, repeatedly grabbing n lines */
658 for (y = 0; y < h-n; y += n)
659 {
660 unsigned char md[MD_DIGEST_LENGTH];
661
662 /* Bitblt screen DC to memory DC */
663 BitBlt(hMemDC, 0, 0, w, n, hScrDC, 0, y, SRCCOPY);
664
665 /* Copy bitmap bits from memory DC to bmbits */
666 GetBitmapBits(hBitmap, size, bmbits);
667
668 /* Get the hash of the bitmap */
669 MD(bmbits,size,md);
670
671 /* Seed the random generator with the hash value */
672 RAND_add(md, MD_DIGEST_LENGTH, 0);
673 }
674
675 OPENSSL_free(bmbits);
676 }
677
678 /* Select old bitmap back into memory DC */
679 hBitmap = SelectObject(hMemDC, hOldBitmap);
680
681 /* Clean up */
682 DeleteObject(hBitmap);
683 DeleteDC(hMemDC);
684 DeleteDC(hScrDC);
685}
686
687#else /* Unix version */
688
689#include <time.h>
690
691int RAND_poll(void)
692{
693 unsigned long l;
694 pid_t curr_pid = getpid();
695#ifdef DEVRANDOM
696 FILE *fh;
697#endif
698
699#ifdef DEVRANDOM
700 /* Use a random entropy pool device. Linux, FreeBSD and OpenBSD
701 * have this. Use /dev/urandom if you can as /dev/random may block
702 * if it runs out of random entries. */
703
704 if ((fh = fopen(DEVRANDOM, "r")) != NULL)
705 {
706 unsigned char tmpbuf[ENTROPY_NEEDED];
707 int n;
708
709 setvbuf(fh, NULL, _IONBF, 0);
710 n=fread((unsigned char *)tmpbuf,1,ENTROPY_NEEDED,fh);
711 fclose(fh);
712 RAND_add(tmpbuf,sizeof tmpbuf,n);
713 memset(tmpbuf,0,n);
714 }
715#endif
716
717 /* put in some default random data, we need more than just this */
718 l=curr_pid;
719 RAND_add(&l,sizeof(l),0);
720 l=getuid();
721 RAND_add(&l,sizeof(l),0);
722
723 l=time(NULL);
724 RAND_add(&l,sizeof(l),0);
725
726#ifdef DEVRANDOM
727 return 1;
728#endif
729 return 0;
730}
731
732#endif
diff --git a/src/lib/libcrypto/rc2/tab.c b/src/lib/libcrypto/rc2/tab.c
new file mode 100644
index 0000000000..25dc14eeba
--- /dev/null
+++ b/src/lib/libcrypto/rc2/tab.c
@@ -0,0 +1,86 @@
1#include <stdio.h>
2
3unsigned char ebits_to_num[256]={
4 0xbd,0x56,0xea,0xf2,0xa2,0xf1,0xac,0x2a,
5 0xb0,0x93,0xd1,0x9c,0x1b,0x33,0xfd,0xd0,
6 0x30,0x04,0xb6,0xdc,0x7d,0xdf,0x32,0x4b,
7 0xf7,0xcb,0x45,0x9b,0x31,0xbb,0x21,0x5a,
8 0x41,0x9f,0xe1,0xd9,0x4a,0x4d,0x9e,0xda,
9 0xa0,0x68,0x2c,0xc3,0x27,0x5f,0x80,0x36,
10 0x3e,0xee,0xfb,0x95,0x1a,0xfe,0xce,0xa8,
11 0x34,0xa9,0x13,0xf0,0xa6,0x3f,0xd8,0x0c,
12 0x78,0x24,0xaf,0x23,0x52,0xc1,0x67,0x17,
13 0xf5,0x66,0x90,0xe7,0xe8,0x07,0xb8,0x60,
14 0x48,0xe6,0x1e,0x53,0xf3,0x92,0xa4,0x72,
15 0x8c,0x08,0x15,0x6e,0x86,0x00,0x84,0xfa,
16 0xf4,0x7f,0x8a,0x42,0x19,0xf6,0xdb,0xcd,
17 0x14,0x8d,0x50,0x12,0xba,0x3c,0x06,0x4e,
18 0xec,0xb3,0x35,0x11,0xa1,0x88,0x8e,0x2b,
19 0x94,0x99,0xb7,0x71,0x74,0xd3,0xe4,0xbf,
20 0x3a,0xde,0x96,0x0e,0xbc,0x0a,0xed,0x77,
21 0xfc,0x37,0x6b,0x03,0x79,0x89,0x62,0xc6,
22 0xd7,0xc0,0xd2,0x7c,0x6a,0x8b,0x22,0xa3,
23 0x5b,0x05,0x5d,0x02,0x75,0xd5,0x61,0xe3,
24 0x18,0x8f,0x55,0x51,0xad,0x1f,0x0b,0x5e,
25 0x85,0xe5,0xc2,0x57,0x63,0xca,0x3d,0x6c,
26 0xb4,0xc5,0xcc,0x70,0xb2,0x91,0x59,0x0d,
27 0x47,0x20,0xc8,0x4f,0x58,0xe0,0x01,0xe2,
28 0x16,0x38,0xc4,0x6f,0x3b,0x0f,0x65,0x46,
29 0xbe,0x7e,0x2d,0x7b,0x82,0xf9,0x40,0xb5,
30 0x1d,0x73,0xf8,0xeb,0x26,0xc7,0x87,0x97,
31 0x25,0x54,0xb1,0x28,0xaa,0x98,0x9d,0xa5,
32 0x64,0x6d,0x7a,0xd4,0x10,0x81,0x44,0xef,
33 0x49,0xd6,0xae,0x2e,0xdd,0x76,0x5c,0x2f,
34 0xa7,0x1c,0xc9,0x09,0x69,0x9a,0x83,0xcf,
35 0x29,0x39,0xb9,0xe9,0x4c,0xff,0x43,0xab,
36 };
37
38unsigned char num_to_ebits[256]={
39 0x5d,0xbe,0x9b,0x8b,0x11,0x99,0x6e,0x4d,
40 0x59,0xf3,0x85,0xa6,0x3f,0xb7,0x83,0xc5,
41 0xe4,0x73,0x6b,0x3a,0x68,0x5a,0xc0,0x47,
42 0xa0,0x64,0x34,0x0c,0xf1,0xd0,0x52,0xa5,
43 0xb9,0x1e,0x96,0x43,0x41,0xd8,0xd4,0x2c,
44 0xdb,0xf8,0x07,0x77,0x2a,0xca,0xeb,0xef,
45 0x10,0x1c,0x16,0x0d,0x38,0x72,0x2f,0x89,
46 0xc1,0xf9,0x80,0xc4,0x6d,0xae,0x30,0x3d,
47 0xce,0x20,0x63,0xfe,0xe6,0x1a,0xc7,0xb8,
48 0x50,0xe8,0x24,0x17,0xfc,0x25,0x6f,0xbb,
49 0x6a,0xa3,0x44,0x53,0xd9,0xa2,0x01,0xab,
50 0xbc,0xb6,0x1f,0x98,0xee,0x9a,0xa7,0x2d,
51 0x4f,0x9e,0x8e,0xac,0xe0,0xc6,0x49,0x46,
52 0x29,0xf4,0x94,0x8a,0xaf,0xe1,0x5b,0xc3,
53 0xb3,0x7b,0x57,0xd1,0x7c,0x9c,0xed,0x87,
54 0x40,0x8c,0xe2,0xcb,0x93,0x14,0xc9,0x61,
55 0x2e,0xe5,0xcc,0xf6,0x5e,0xa8,0x5c,0xd6,
56 0x75,0x8d,0x62,0x95,0x58,0x69,0x76,0xa1,
57 0x4a,0xb5,0x55,0x09,0x78,0x33,0x82,0xd7,
58 0xdd,0x79,0xf5,0x1b,0x0b,0xde,0x26,0x21,
59 0x28,0x74,0x04,0x97,0x56,0xdf,0x3c,0xf0,
60 0x37,0x39,0xdc,0xff,0x06,0xa4,0xea,0x42,
61 0x08,0xda,0xb4,0x71,0xb0,0xcf,0x12,0x7a,
62 0x4e,0xfa,0x6c,0x1d,0x84,0x00,0xc8,0x7f,
63 0x91,0x45,0xaa,0x2b,0xc2,0xb1,0x8f,0xd5,
64 0xba,0xf2,0xad,0x19,0xb2,0x67,0x36,0xf7,
65 0x0f,0x0a,0x92,0x7d,0xe3,0x9d,0xe9,0x90,
66 0x3e,0x23,0x27,0x66,0x13,0xec,0x81,0x15,
67 0xbd,0x22,0xbf,0x9f,0x7e,0xa9,0x51,0x4b,
68 0x4c,0xfb,0x02,0xd3,0x70,0x86,0x31,0xe7,
69 0x3b,0x05,0x03,0x54,0x60,0x48,0x65,0x18,
70 0xd2,0xcd,0x5f,0x32,0x88,0x0e,0x35,0xfd,
71 };
72
73main()
74 {
75 int i,j;
76
77 for (i=0; i<256; i++)
78 {
79 for (j=0; j<256; j++)
80 if (ebits_to_num[j] == i)
81 {
82 printf("0x%02x,",j);
83 break;
84 }
85 }
86 }
diff --git a/src/lib/libcrypto/rsa/rsa_null.c b/src/lib/libcrypto/rsa/rsa_null.c
new file mode 100644
index 0000000000..7b58a0eca3
--- /dev/null
+++ b/src/lib/libcrypto/rsa/rsa_null.c
@@ -0,0 +1,149 @@
1/* rsa_null.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 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 * licensing@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 <stdio.h>
60#include "cryptlib.h"
61#include <openssl/bn.h>
62#include <openssl/rsa.h>
63#include <openssl/rand.h>
64
65/* This is a dummy RSA implementation that just returns errors when called.
66 * It is designed to allow some RSA functions to work while stopping those
67 * covered by the RSA patent. That is RSA, encryption, decryption, signing
68 * and verify is not allowed but RSA key generation, key checking and other
69 * operations (like storing RSA keys) are permitted.
70 */
71
72static int RSA_null_public_encrypt(int flen, unsigned char *from,
73 unsigned char *to, RSA *rsa,int padding);
74static int RSA_null_private_encrypt(int flen, unsigned char *from,
75 unsigned char *to, RSA *rsa,int padding);
76static int RSA_null_public_decrypt(int flen, unsigned char *from,
77 unsigned char *to, RSA *rsa,int padding);
78static int RSA_null_private_decrypt(int flen, unsigned char *from,
79 unsigned char *to, RSA *rsa,int padding);
80#if 0 /* not currently used */
81static int RSA_null_mod_exp(BIGNUM *r0, BIGNUM *i, RSA *rsa);
82#endif
83static int RSA_null_init(RSA *rsa);
84static int RSA_null_finish(RSA *rsa);
85static RSA_METHOD rsa_null_meth={
86 "Null RSA",
87 RSA_null_public_encrypt,
88 RSA_null_public_decrypt,
89 RSA_null_private_encrypt,
90 RSA_null_private_decrypt,
91 NULL, NULL,
92 RSA_null_init,
93 RSA_null_finish,
94 0,
95 NULL,
96 };
97
98RSA_METHOD *RSA_null_method(void)
99 {
100 return(&rsa_null_meth);
101 }
102
103static int RSA_null_public_encrypt(int flen, unsigned char *from,
104 unsigned char *to, RSA *rsa, int padding)
105 {
106 RSAerr(RSA_F_RSA_NULL, RSA_R_RSA_OPERATIONS_NOT_SUPPORTED);
107 return -1;
108 }
109
110static int RSA_null_private_encrypt(int flen, unsigned char *from,
111 unsigned char *to, RSA *rsa, int padding)
112 {
113 RSAerr(RSA_F_RSA_NULL, RSA_R_RSA_OPERATIONS_NOT_SUPPORTED);
114 return -1;
115 }
116
117static int RSA_null_private_decrypt(int flen, unsigned char *from,
118 unsigned char *to, RSA *rsa, int padding)
119 {
120 RSAerr(RSA_F_RSA_NULL, RSA_R_RSA_OPERATIONS_NOT_SUPPORTED);
121 return -1;
122 }
123
124static int RSA_null_public_decrypt(int flen, unsigned char *from,
125 unsigned char *to, RSA *rsa, int padding)
126 {
127 RSAerr(RSA_F_RSA_NULL, RSA_R_RSA_OPERATIONS_NOT_SUPPORTED);
128 return -1;
129 }
130
131#if 0 /* not currently used */
132static int RSA_null_mod_exp(BIGNUM *r0, BIGNUM *I, RSA *rsa)
133 {
134 RSAerr(RSA_F_RSA_NULL, RSA_R_RSA_OPERATIONS_NOT_SUPPORTED);
135 return -1;
136 }
137#endif
138
139static int RSA_null_init(RSA *rsa)
140 {
141 return(1);
142 }
143
144static int RSA_null_finish(RSA *rsa)
145 {
146 return(1);
147 }
148
149
diff --git a/src/lib/libcrypto/rsa/rsa_test.c b/src/lib/libcrypto/rsa/rsa_test.c
new file mode 100644
index 0000000000..e5ae0c1f69
--- /dev/null
+++ b/src/lib/libcrypto/rsa/rsa_test.c
@@ -0,0 +1,314 @@
1/* test vectors from p1ovect1.txt */
2
3#include <stdio.h>
4#include <string.h>
5
6#include "openssl/e_os.h"
7
8#include <openssl/crypto.h>
9#include <openssl/err.h>
10#include <openssl/rand.h>
11#ifdef NO_RSA
12int main(int argc, char *argv[])
13{
14 printf("No RSA support\n");
15 return(0);
16}
17#else
18#include <openssl/rsa.h>
19
20#define SetKey \
21 key->n = BN_bin2bn(n, sizeof(n)-1, key->n); \
22 key->e = BN_bin2bn(e, sizeof(e)-1, key->e); \
23 key->d = BN_bin2bn(d, sizeof(d)-1, key->d); \
24 key->p = BN_bin2bn(p, sizeof(p)-1, key->p); \
25 key->q = BN_bin2bn(q, sizeof(q)-1, key->q); \
26 key->dmp1 = BN_bin2bn(dmp1, sizeof(dmp1)-1, key->dmp1); \
27 key->dmq1 = BN_bin2bn(dmq1, sizeof(dmq1)-1, key->dmq1); \
28 key->iqmp = BN_bin2bn(iqmp, sizeof(iqmp)-1, key->iqmp); \
29 memcpy(c, ctext_ex, sizeof(ctext_ex) - 1); \
30 return (sizeof(ctext_ex) - 1);
31
32static int key1(RSA *key, unsigned char *c)
33 {
34 static unsigned char n[] =
35"\x00\xAA\x36\xAB\xCE\x88\xAC\xFD\xFF\x55\x52\x3C\x7F\xC4\x52\x3F"
36"\x90\xEF\xA0\x0D\xF3\x77\x4A\x25\x9F\x2E\x62\xB4\xC5\xD9\x9C\xB5"
37"\xAD\xB3\x00\xA0\x28\x5E\x53\x01\x93\x0E\x0C\x70\xFB\x68\x76\x93"
38"\x9C\xE6\x16\xCE\x62\x4A\x11\xE0\x08\x6D\x34\x1E\xBC\xAC\xA0\xA1"
39"\xF5";
40
41 static unsigned char e[] = "\x11";
42
43 static unsigned char d[] =
44"\x0A\x03\x37\x48\x62\x64\x87\x69\x5F\x5F\x30\xBC\x38\xB9\x8B\x44"
45"\xC2\xCD\x2D\xFF\x43\x40\x98\xCD\x20\xD8\xA1\x38\xD0\x90\xBF\x64"
46"\x79\x7C\x3F\xA7\xA2\xCD\xCB\x3C\xD1\xE0\xBD\xBA\x26\x54\xB4\xF9"
47"\xDF\x8E\x8A\xE5\x9D\x73\x3D\x9F\x33\xB3\x01\x62\x4A\xFD\x1D\x51";
48
49 static unsigned char p[] =
50"\x00\xD8\x40\xB4\x16\x66\xB4\x2E\x92\xEA\x0D\xA3\xB4\x32\x04\xB5"
51"\xCF\xCE\x33\x52\x52\x4D\x04\x16\xA5\xA4\x41\xE7\x00\xAF\x46\x12"
52"\x0D";
53
54 static unsigned char q[] =
55"\x00\xC9\x7F\xB1\xF0\x27\xF4\x53\xF6\x34\x12\x33\xEA\xAA\xD1\xD9"
56"\x35\x3F\x6C\x42\xD0\x88\x66\xB1\xD0\x5A\x0F\x20\x35\x02\x8B\x9D"
57"\x89";
58
59 static unsigned char dmp1[] =
60"\x59\x0B\x95\x72\xA2\xC2\xA9\xC4\x06\x05\x9D\xC2\xAB\x2F\x1D\xAF"
61"\xEB\x7E\x8B\x4F\x10\xA7\x54\x9E\x8E\xED\xF5\xB4\xFC\xE0\x9E\x05";
62
63 static unsigned char dmq1[] =
64"\x00\x8E\x3C\x05\x21\xFE\x15\xE0\xEA\x06\xA3\x6F\xF0\xF1\x0C\x99"
65"\x52\xC3\x5B\x7A\x75\x14\xFD\x32\x38\xB8\x0A\xAD\x52\x98\x62\x8D"
66"\x51";
67
68 static unsigned char iqmp[] =
69"\x36\x3F\xF7\x18\x9D\xA8\xE9\x0B\x1D\x34\x1F\x71\xD0\x9B\x76\xA8"
70"\xA9\x43\xE1\x1D\x10\xB2\x4D\x24\x9F\x2D\xEA\xFE\xF8\x0C\x18\x26";
71
72 static unsigned char ctext_ex[] =
73"\x1b\x8f\x05\xf9\xca\x1a\x79\x52\x6e\x53\xf3\xcc\x51\x4f\xdb\x89"
74"\x2b\xfb\x91\x93\x23\x1e\x78\xb9\x92\xe6\x8d\x50\xa4\x80\xcb\x52"
75"\x33\x89\x5c\x74\x95\x8d\x5d\x02\xab\x8c\x0f\xd0\x40\xeb\x58\x44"
76"\xb0\x05\xc3\x9e\xd8\x27\x4a\x9d\xbf\xa8\x06\x71\x40\x94\x39\xd2";
77
78 SetKey;
79 }
80
81static int key2(RSA *key, unsigned char *c)
82 {
83 static unsigned char n[] =
84"\x00\xA3\x07\x9A\x90\xDF\x0D\xFD\x72\xAC\x09\x0C\xCC\x2A\x78\xB8"
85"\x74\x13\x13\x3E\x40\x75\x9C\x98\xFA\xF8\x20\x4F\x35\x8A\x0B\x26"
86"\x3C\x67\x70\xE7\x83\xA9\x3B\x69\x71\xB7\x37\x79\xD2\x71\x7B\xE8"
87"\x34\x77\xCF";
88
89 static unsigned char e[] = "\x3";
90
91 static unsigned char d[] =
92"\x6C\xAF\xBC\x60\x94\xB3\xFE\x4C\x72\xB0\xB3\x32\xC6\xFB\x25\xA2"
93"\xB7\x62\x29\x80\x4E\x68\x65\xFC\xA4\x5A\x74\xDF\x0F\x8F\xB8\x41"
94"\x3B\x52\xC0\xD0\xE5\x3D\x9B\x59\x0F\xF1\x9B\xE7\x9F\x49\xDD\x21"
95"\xE5\xEB";
96
97 static unsigned char p[] =
98"\x00\xCF\x20\x35\x02\x8B\x9D\x86\x98\x40\xB4\x16\x66\xB4\x2E\x92"
99"\xEA\x0D\xA3\xB4\x32\x04\xB5\xCF\xCE\x91";
100
101 static unsigned char q[] =
102"\x00\xC9\x7F\xB1\xF0\x27\xF4\x53\xF6\x34\x12\x33\xEA\xAA\xD1\xD9"
103"\x35\x3F\x6C\x42\xD0\x88\x66\xB1\xD0\x5F";
104
105 static unsigned char dmp1[] =
106"\x00\x8A\x15\x78\xAC\x5D\x13\xAF\x10\x2B\x22\xB9\x99\xCD\x74\x61"
107"\xF1\x5E\x6D\x22\xCC\x03\x23\xDF\xDF\x0B";
108
109 static unsigned char dmq1[] =
110"\x00\x86\x55\x21\x4A\xC5\x4D\x8D\x4E\xCD\x61\x77\xF1\xC7\x36\x90"
111"\xCE\x2A\x48\x2C\x8B\x05\x99\xCB\xE0\x3F";
112
113 static unsigned char iqmp[] =
114"\x00\x83\xEF\xEF\xB8\xA9\xA4\x0D\x1D\xB6\xED\x98\xAD\x84\xED\x13"
115"\x35\xDC\xC1\x08\xF3\x22\xD0\x57\xCF\x8D";
116
117 static unsigned char ctext_ex[] =
118"\x14\xbd\xdd\x28\xc9\x83\x35\x19\x23\x80\xe8\xe5\x49\xb1\x58\x2a"
119"\x8b\x40\xb4\x48\x6d\x03\xa6\xa5\x31\x1f\x1f\xd5\xf0\xa1\x80\xe4"
120"\x17\x53\x03\x29\xa9\x34\x90\x74\xb1\x52\x13\x54\x29\x08\x24\x52"
121"\x62\x51";
122
123 SetKey;
124 }
125
126static int key3(RSA *key, unsigned char *c)
127 {
128 static unsigned char n[] =
129"\x00\xBB\xF8\x2F\x09\x06\x82\xCE\x9C\x23\x38\xAC\x2B\x9D\xA8\x71"
130"\xF7\x36\x8D\x07\xEE\xD4\x10\x43\xA4\x40\xD6\xB6\xF0\x74\x54\xF5"
131"\x1F\xB8\xDF\xBA\xAF\x03\x5C\x02\xAB\x61\xEA\x48\xCE\xEB\x6F\xCD"
132"\x48\x76\xED\x52\x0D\x60\xE1\xEC\x46\x19\x71\x9D\x8A\x5B\x8B\x80"
133"\x7F\xAF\xB8\xE0\xA3\xDF\xC7\x37\x72\x3E\xE6\xB4\xB7\xD9\x3A\x25"
134"\x84\xEE\x6A\x64\x9D\x06\x09\x53\x74\x88\x34\xB2\x45\x45\x98\x39"
135"\x4E\xE0\xAA\xB1\x2D\x7B\x61\xA5\x1F\x52\x7A\x9A\x41\xF6\xC1\x68"
136"\x7F\xE2\x53\x72\x98\xCA\x2A\x8F\x59\x46\xF8\xE5\xFD\x09\x1D\xBD"
137"\xCB";
138
139 static unsigned char e[] = "\x11";
140
141 static unsigned char d[] =
142"\x00\xA5\xDA\xFC\x53\x41\xFA\xF2\x89\xC4\xB9\x88\xDB\x30\xC1\xCD"
143"\xF8\x3F\x31\x25\x1E\x06\x68\xB4\x27\x84\x81\x38\x01\x57\x96\x41"
144"\xB2\x94\x10\xB3\xC7\x99\x8D\x6B\xC4\x65\x74\x5E\x5C\x39\x26\x69"
145"\xD6\x87\x0D\xA2\xC0\x82\xA9\x39\xE3\x7F\xDC\xB8\x2E\xC9\x3E\xDA"
146"\xC9\x7F\xF3\xAD\x59\x50\xAC\xCF\xBC\x11\x1C\x76\xF1\xA9\x52\x94"
147"\x44\xE5\x6A\xAF\x68\xC5\x6C\x09\x2C\xD3\x8D\xC3\xBE\xF5\xD2\x0A"
148"\x93\x99\x26\xED\x4F\x74\xA1\x3E\xDD\xFB\xE1\xA1\xCE\xCC\x48\x94"
149"\xAF\x94\x28\xC2\xB7\xB8\x88\x3F\xE4\x46\x3A\x4B\xC8\x5B\x1C\xB3"
150"\xC1";
151
152 static unsigned char p[] =
153"\x00\xEE\xCF\xAE\x81\xB1\xB9\xB3\xC9\x08\x81\x0B\x10\xA1\xB5\x60"
154"\x01\x99\xEB\x9F\x44\xAE\xF4\xFD\xA4\x93\xB8\x1A\x9E\x3D\x84\xF6"
155"\x32\x12\x4E\xF0\x23\x6E\x5D\x1E\x3B\x7E\x28\xFA\xE7\xAA\x04\x0A"
156"\x2D\x5B\x25\x21\x76\x45\x9D\x1F\x39\x75\x41\xBA\x2A\x58\xFB\x65"
157"\x99";
158
159 static unsigned char q[] =
160"\x00\xC9\x7F\xB1\xF0\x27\xF4\x53\xF6\x34\x12\x33\xEA\xAA\xD1\xD9"
161"\x35\x3F\x6C\x42\xD0\x88\x66\xB1\xD0\x5A\x0F\x20\x35\x02\x8B\x9D"
162"\x86\x98\x40\xB4\x16\x66\xB4\x2E\x92\xEA\x0D\xA3\xB4\x32\x04\xB5"
163"\xCF\xCE\x33\x52\x52\x4D\x04\x16\xA5\xA4\x41\xE7\x00\xAF\x46\x15"
164"\x03";
165
166 static unsigned char dmp1[] =
167"\x54\x49\x4C\xA6\x3E\xBA\x03\x37\xE4\xE2\x40\x23\xFC\xD6\x9A\x5A"
168"\xEB\x07\xDD\xDC\x01\x83\xA4\xD0\xAC\x9B\x54\xB0\x51\xF2\xB1\x3E"
169"\xD9\x49\x09\x75\xEA\xB7\x74\x14\xFF\x59\xC1\xF7\x69\x2E\x9A\x2E"
170"\x20\x2B\x38\xFC\x91\x0A\x47\x41\x74\xAD\xC9\x3C\x1F\x67\xC9\x81";
171
172 static unsigned char dmq1[] =
173"\x47\x1E\x02\x90\xFF\x0A\xF0\x75\x03\x51\xB7\xF8\x78\x86\x4C\xA9"
174"\x61\xAD\xBD\x3A\x8A\x7E\x99\x1C\x5C\x05\x56\xA9\x4C\x31\x46\xA7"
175"\xF9\x80\x3F\x8F\x6F\x8A\xE3\x42\xE9\x31\xFD\x8A\xE4\x7A\x22\x0D"
176"\x1B\x99\xA4\x95\x84\x98\x07\xFE\x39\xF9\x24\x5A\x98\x36\xDA\x3D";
177
178 static unsigned char iqmp[] =
179"\x00\xB0\x6C\x4F\xDA\xBB\x63\x01\x19\x8D\x26\x5B\xDB\xAE\x94\x23"
180"\xB3\x80\xF2\x71\xF7\x34\x53\x88\x50\x93\x07\x7F\xCD\x39\xE2\x11"
181"\x9F\xC9\x86\x32\x15\x4F\x58\x83\xB1\x67\xA9\x67\xBF\x40\x2B\x4E"
182"\x9E\x2E\x0F\x96\x56\xE6\x98\xEA\x36\x66\xED\xFB\x25\x79\x80\x39"
183"\xF7";
184
185 static unsigned char ctext_ex[] =
186"\xb8\x24\x6b\x56\xa6\xed\x58\x81\xae\xb5\x85\xd9\xa2\x5b\x2a\xd7"
187"\x90\xc4\x17\xe0\x80\x68\x1b\xf1\xac\x2b\xc3\xde\xb6\x9d\x8b\xce"
188"\xf0\xc4\x36\x6f\xec\x40\x0a\xf0\x52\xa7\x2e\x9b\x0e\xff\xb5\xb3"
189"\xf2\xf1\x92\xdb\xea\xca\x03\xc1\x27\x40\x05\x71\x13\xbf\x1f\x06"
190"\x69\xac\x22\xe9\xf3\xa7\x85\x2e\x3c\x15\xd9\x13\xca\xb0\xb8\x86"
191"\x3a\x95\xc9\x92\x94\xce\x86\x74\x21\x49\x54\x61\x03\x46\xf4\xd4"
192"\x74\xb2\x6f\x7c\x48\xb4\x2e\xe6\x8e\x1f\x57\x2a\x1f\xc4\x02\x6a"
193"\xc4\x56\xb4\xf5\x9f\x7b\x62\x1e\xa1\xb9\xd8\x8f\x64\x20\x2f\xb1";
194
195 SetKey;
196 }
197
198static int pad_unknown(void)
199{
200 unsigned long l;
201 while ((l = ERR_get_error()) != 0)
202 if (ERR_GET_REASON(l) == RSA_R_UNKNOWN_PADDING_TYPE)
203 return(1);
204 return(0);
205}
206
207static const char rnd_seed[] = "string to make the random number generator think it has entropy";
208
209int main(int argc, char *argv[])
210 {
211 int err=0;
212 int v;
213 RSA *key;
214 unsigned char ptext[256];
215 unsigned char ctext[256];
216 static unsigned char ptext_ex[] = "\x54\x85\x9b\x34\x2c\x49\xea\x2a";
217 unsigned char ctext_ex[256];
218 int plen;
219 int clen = 0;
220 int num;
221
222 RAND_seed(rnd_seed, sizeof rnd_seed); /* or OAEP may fail */
223
224 CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
225
226 plen = sizeof(ptext_ex) - 1;
227
228 for (v = 0; v < 3; v++)
229 {
230 key = RSA_new();
231 switch (v) {
232 case 0:
233 clen = key1(key, ctext_ex);
234 break;
235 case 1:
236 clen = key2(key, ctext_ex);
237 break;
238 case 2:
239 clen = key3(key, ctext_ex);
240 break;
241 }
242
243 num = RSA_public_encrypt(plen, ptext_ex, ctext, key,
244 RSA_PKCS1_PADDING);
245 if (num != clen)
246 {
247 printf("PKCS#1 v1.5 encryption failed!\n");
248 err=1;
249 goto oaep;
250 }
251
252 num = RSA_private_decrypt(num, ctext, ptext, key,
253 RSA_PKCS1_PADDING);
254 if (num != plen || memcmp(ptext, ptext_ex, num) != 0)
255 {
256 printf("PKCS#1 v1.5 decryption failed!\n");
257 err=1;
258 }
259 else
260 printf("PKCS #1 v1.5 encryption/decryption ok\n");
261
262 oaep:
263 ERR_clear_error();
264 num = RSA_public_encrypt(plen, ptext_ex, ctext, key,
265 RSA_PKCS1_OAEP_PADDING);
266 if (num == -1 && pad_unknown())
267 {
268 printf("No OAEP support\n");
269 goto next;
270 }
271 if (num != clen)
272 {
273 printf("OAEP encryption failed!\n");
274 err=1;
275 goto next;
276 }
277
278 num = RSA_private_decrypt(num, ctext, ptext, key,
279 RSA_PKCS1_OAEP_PADDING);
280 if (num != plen || memcmp(ptext, ptext_ex, num) != 0)
281 {
282 printf("OAEP decryption (encrypted data) failed!\n");
283 err=1;
284 }
285 else if (memcmp(ctext, ctext_ex, num) == 0)
286 {
287 printf("OAEP test vector %d passed!\n", v);
288 goto next;
289 }
290
291 /* Different ciphertexts (rsa_oaep.c without -DPKCS_TESTVECT).
292 Try decrypting ctext_ex */
293
294 num = RSA_private_decrypt(clen, ctext_ex, ptext, key,
295 RSA_PKCS1_OAEP_PADDING);
296
297 if (num != plen || memcmp(ptext, ptext_ex, num) != 0)
298 {
299 printf("OAEP decryption (test vector data) failed!\n");
300 err=1;
301 }
302 else
303 printf("OAEP encryption/decryption ok\n");
304 next:
305 RSA_free(key);
306 }
307
308 ERR_remove_state(0);
309
310 CRYPTO_mem_leaks_fp(stdout);
311
312 return err;
313 }
314#endif
diff --git a/src/lib/libcrypto/symhacks.h b/src/lib/libcrypto/symhacks.h
new file mode 100644
index 0000000000..358ad355bb
--- /dev/null
+++ b/src/lib/libcrypto/symhacks.h
@@ -0,0 +1,154 @@
1/* ====================================================================
2 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * 3. All advertising materials mentioning features or use of this
17 * software must display the following acknowledgment:
18 * "This product includes software developed by the OpenSSL Project
19 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
20 *
21 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission. For written permission, please contact
24 * openssl-core@openssl.org.
25 *
26 * 5. Products derived from this software may not be called "OpenSSL"
27 * nor may "OpenSSL" appear in their names without prior written
28 * permission of the OpenSSL Project.
29 *
30 * 6. Redistributions of any form whatsoever must retain the following
31 * acknowledgment:
32 * "This product includes software developed by the OpenSSL Project
33 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46 * OF THE POSSIBILITY OF SUCH DAMAGE.
47 * ====================================================================
48 *
49 * This product includes cryptographic software written by Eric Young
50 * (eay@cryptsoft.com). This product includes software written by Tim
51 * Hudson (tjh@cryptsoft.com).
52 *
53 */
54
55#ifndef HEADER_SYMHACKS_H
56#define HEADER_SYMHACKS_H
57
58/* Hacks to solve the problem with linkers incapable of handling very long
59 symbol names. In the case of VMS, the limit is 31 characters on VMS for
60 VAX. */
61#ifdef VMS
62
63/* Hack a long name in crypto/asn1/a_mbstr.c */
64#undef ASN1_STRING_set_default_mask_asc
65#define ASN1_STRING_set_default_mask_asc ASN1_STRING_set_def_mask_asc
66
67#if 0 /* No longer needed, since safestack macro magic does the job */
68/* Hack the names created with DECLARE_ASN1_SET_OF(PKCS7_SIGNER_INFO) */
69#undef i2d_ASN1_SET_OF_PKCS7_SIGNER_INFO
70#define i2d_ASN1_SET_OF_PKCS7_SIGNER_INFO i2d_ASN1_SET_OF_PKCS7_SIGINF
71#undef d2i_ASN1_SET_OF_PKCS7_SIGNER_INFO
72#define d2i_ASN1_SET_OF_PKCS7_SIGNER_INFO d2i_ASN1_SET_OF_PKCS7_SIGINF
73#endif
74
75#if 0 /* No longer needed, since safestack macro magic does the job */
76/* Hack the names created with DECLARE_ASN1_SET_OF(PKCS7_RECIP_INFO) */
77#undef i2d_ASN1_SET_OF_PKCS7_RECIP_INFO
78#define i2d_ASN1_SET_OF_PKCS7_RECIP_INFO i2d_ASN1_SET_OF_PKCS7_RECINF
79#undef d2i_ASN1_SET_OF_PKCS7_RECIP_INFO
80#define d2i_ASN1_SET_OF_PKCS7_RECIP_INFO d2i_ASN1_SET_OF_PKCS7_RECINF
81#endif
82
83#if 0 /* No longer needed, since safestack macro magic does the job */
84/* Hack the names created with DECLARE_ASN1_SET_OF(ACCESS_DESCRIPTION) */
85#undef i2d_ASN1_SET_OF_ACCESS_DESCRIPTION
86#define i2d_ASN1_SET_OF_ACCESS_DESCRIPTION i2d_ASN1_SET_OF_ACC_DESC
87#undef d2i_ASN1_SET_OF_ACCESS_DESCRIPTION
88#define d2i_ASN1_SET_OF_ACCESS_DESCRIPTION d2i_ASN1_SET_OF_ACC_DESC
89#endif
90
91/* Hack the names created with DECLARE_PEM_rw(NETSCAPE_CERT_SEQUENCE) */
92#undef PEM_read_NETSCAPE_CERT_SEQUENCE
93#define PEM_read_NETSCAPE_CERT_SEQUENCE PEM_read_NS_CERT_SEQ
94#undef PEM_write_NETSCAPE_CERT_SEQUENCE
95#define PEM_write_NETSCAPE_CERT_SEQUENCE PEM_write_NS_CERT_SEQ
96#undef PEM_read_bio_NETSCAPE_CERT_SEQUENCE
97#define PEM_read_bio_NETSCAPE_CERT_SEQUENCE PEM_read_bio_NS_CERT_SEQ
98#undef PEM_write_bio_NETSCAPE_CERT_SEQUENCE
99#define PEM_write_bio_NETSCAPE_CERT_SEQUENCE PEM_write_bio_NS_CERT_SEQ
100#undef PEM_write_cb_bio_NETSCAPE_CERT_SEQUENCE
101#define PEM_write_cb_bio_NETSCAPE_CERT_SEQUENCE PEM_write_cb_bio_NS_CERT_SEQ
102
103/* Hack the names created with DECLARE_PEM_rw(PKCS8_PRIV_KEY_INFO) */
104#undef PEM_read_PKCS8_PRIV_KEY_INFO
105#define PEM_read_PKCS8_PRIV_KEY_INFO PEM_read_P8_PRIV_KEY_INFO
106#undef PEM_write_PKCS8_PRIV_KEY_INFO
107#define PEM_write_PKCS8_PRIV_KEY_INFO PEM_write_P8_PRIV_KEY_INFO
108#undef PEM_read_bio_PKCS8_PRIV_KEY_INFO
109#define PEM_read_bio_PKCS8_PRIV_KEY_INFO PEM_read_bio_P8_PRIV_KEY_INFO
110#undef PEM_write_bio_PKCS8_PRIV_KEY_INFO
111#define PEM_write_bio_PKCS8_PRIV_KEY_INFO PEM_write_bio_P8_PRIV_KEY_INFO
112#undef PEM_write_cb_bio_PKCS8_PRIV_KEY_INFO
113#define PEM_write_cb_bio_PKCS8_PRIV_KEY_INFO PEM_wrt_cb_bio_P8_PRIV_KEY_INFO
114
115/* Hack other PEM names */
116#undef PEM_write_bio_PKCS8PrivateKey_nid
117#define PEM_write_bio_PKCS8PrivateKey_nid PEM_write_bio_PKCS8PrivKey_nid
118
119/* Hack some long X509 names */
120#undef X509_REVOKED_get_ext_by_critical
121#define X509_REVOKED_get_ext_by_critical X509_REVOKED_get_ext_by_critic
122
123/* Hack some long CRYPTO names */
124#define CRYPTO_set_dynlock_destroy_callback CRYPTO_set_dynlock_destroy_cb
125#define CRYPTO_set_dynlock_create_callback CRYPTO_set_dynlock_create_cb
126#define CRYPTO_set_dynlock_lock_callback CRYPTO_set_dynlock_lock_cb
127#define CRYPTO_get_dynlock_lock_callback CRYPTO_get_dynlock_lock_cb
128#define CRYPTO_get_dynlock_destroy_callback CRYPTO_get_dynlock_destroy_cb
129#define CRYPTO_get_dynlock_create_callback CRYPTO_get_dynlock_create_cb
130
131/* Hack some long SSL names */
132#define SSL_CTX_set_default_verify_paths SSL_CTX_set_def_verify_paths
133#define SSL_get_ex_data_X509_STORE_CTX_idx SSL_get_ex_d_X509_STORE_CTX_idx
134#define SSL_add_file_cert_subjects_to_stack SSL_add_file_cert_subjs_to_stk
135#define SSL_add_dir_cert_subjects_to_stack SSL_add_dir_cert_subjs_to_stk
136#define SSL_CTX_use_certificate_chain_file SSL_CTX_use_cert_chain_file
137#define SSL_CTX_set_cert_verify_callback SSL_CTX_set_cert_verify_cb
138#define SSL_CTX_set_default_passwd_cb_userdata SSL_CTX_set_def_passwd_cb_ud
139
140/* Hack some long ENGINE names */
141#define ENGINE_get_default_BN_mod_exp_crt ENGINE_get_def_BN_mod_exp_crt
142#define ENGINE_set_default_BN_mod_exp_crt ENGINE_set_def_BN_mod_exp_crt
143
144#endif /* defined VMS */
145
146
147/* Case insensiteve linking causes problems.... */
148#if defined(WIN16) || defined(VMS)
149#undef ERR_load_CRYPTO_strings
150#define ERR_load_CRYPTO_strings ERR_load_CRYPTOlib_strings
151#endif
152
153
154#endif /* ! defined HEADER_VMS_IDHACKS_H */
diff --git a/src/lib/libcrypto/threads/README b/src/lib/libcrypto/threads/README
new file mode 100644
index 0000000000..df6b26e146
--- /dev/null
+++ b/src/lib/libcrypto/threads/README
@@ -0,0 +1,14 @@
1Mutithreading testing area.
2
3Since this stuff is very very platorm specific, this is not part of the
4normal build. Have a read of doc/threads.doc.
5
6mttest will do some testing and will currently build under Windows NT/95,
7Solaris and Linux. The IRIX stuff is not finished.
8
9I have tested this program on a 12 CPU ultra sparc box (solaris 2.5.1)
10and things seem to work ok.
11
12The Linux pthreads package can be retrieved from
13http://www.mit.edu:8001/people/proven/pthreads.html
14
diff --git a/src/lib/libcrypto/threads/profile.sh b/src/lib/libcrypto/threads/profile.sh
new file mode 100644
index 0000000000..6e3e342fc0
--- /dev/null
+++ b/src/lib/libcrypto/threads/profile.sh
@@ -0,0 +1,4 @@
1#!/bin/sh
2/bin/rm -f mttest
3cc -p -DSOLARIS -I../../include -g mttest.c -o mttest -L/usr/lib/libc -ldl -L../.. -lthread -lssl -lcrypto -lnsl -lsocket
4
diff --git a/src/lib/libcrypto/threads/ptest.bat b/src/lib/libcrypto/threads/ptest.bat
new file mode 100644
index 0000000000..4071b5ffea
--- /dev/null
+++ b/src/lib/libcrypto/threads/ptest.bat
@@ -0,0 +1,4 @@
1del mttest.exe
2
3purify cl /O2 -DWIN32 /MD -I..\..\out mttest.c /Femttest ..\..\out\ssl32.lib ..\..\out\crypt32.lib
4
diff --git a/src/lib/libcrypto/threads/pthread.sh b/src/lib/libcrypto/threads/pthread.sh
new file mode 100644
index 0000000000..f1c49821d2
--- /dev/null
+++ b/src/lib/libcrypto/threads/pthread.sh
@@ -0,0 +1,9 @@
1#!/bin/sh
2#
3# build using pthreads
4#
5# http://www.mit.edu:8001/people/proven/pthreads.html
6#
7/bin/rm -f mttest
8pgcc -DPTHREADS -I../../include -g mttest.c -o mttest -L../.. -lssl -lcrypto
9
diff --git a/src/lib/libcrypto/threads/pthread2.sh b/src/lib/libcrypto/threads/pthread2.sh
new file mode 100644
index 0000000000..41264c6a50
--- /dev/null
+++ b/src/lib/libcrypto/threads/pthread2.sh
@@ -0,0 +1,7 @@
1#!/bin/sh
2#
3# build using pthreads where it's already built into the system
4#
5/bin/rm -f mttest
6gcc -DPTHREADS -I../../include -g mttest.c -o mttest -L../.. -lssl -lcrypto -lpthread
7
diff --git a/src/lib/libcrypto/threads/pthreads-vms.com b/src/lib/libcrypto/threads/pthreads-vms.com
new file mode 100644
index 0000000000..63f5b8cc2e
--- /dev/null
+++ b/src/lib/libcrypto/threads/pthreads-vms.com
@@ -0,0 +1,9 @@
1$! To compile mttest on VMS.
2$!
3$! WARNING: only tested with DEC C so far.
4$
5$ arch := vax
6$ if f$getsyi("CPU") .ge. 128 then arch := axp
7$ define/user openssl [--.include.openssl]
8$ cc/def=PTHREADS mttest.c
9$ link mttest,[--.'arch'.exe.ssl]libssl/lib,[--.'arch'.exe.crypto]libcrypto/lib
diff --git a/src/lib/libcrypto/threads/purify.sh b/src/lib/libcrypto/threads/purify.sh
new file mode 100644
index 0000000000..6d44fe26b7
--- /dev/null
+++ b/src/lib/libcrypto/threads/purify.sh
@@ -0,0 +1,4 @@
1#!/bin/sh
2/bin/rm -f mttest
3purify cc -DSOLARIS -I../../include -g mttest.c -o mttest -L../.. -lthread -lssl -lcrypto -lnsl -lsocket
4
diff --git a/src/lib/libcrypto/threads/solaris.sh b/src/lib/libcrypto/threads/solaris.sh
new file mode 100644
index 0000000000..bc93094a27
--- /dev/null
+++ b/src/lib/libcrypto/threads/solaris.sh
@@ -0,0 +1,4 @@
1#!/bin/sh
2/bin/rm -f mttest
3cc -DSOLARIS -I../../include -g mttest.c -o mttest -L../.. -lthread -lssl -lcrypto -lnsl -lsocket
4
diff --git a/src/lib/libcrypto/threads/win32.bat b/src/lib/libcrypto/threads/win32.bat
new file mode 100644
index 0000000000..ee6da80a07
--- /dev/null
+++ b/src/lib/libcrypto/threads/win32.bat
@@ -0,0 +1,4 @@
1del mttest.exe
2
3cl /O2 -DWIN32 /MD -I..\..\out mttest.c /Femttest ..\..\out\ssleay32.lib ..\..\out\libeay32.lib
4
diff --git a/src/lib/libcrypto/tmdiff.h b/src/lib/libcrypto/tmdiff.h
new file mode 100644
index 0000000000..41a8a1e0e0
--- /dev/null
+++ b/src/lib/libcrypto/tmdiff.h
@@ -0,0 +1,81 @@
1/* crypto/tmdiff.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59/* Header for dynamic hash table routines
60 * Author - Eric Young
61 */
62
63#ifndef HEADER_TMDIFF_H
64#define HEADER_TMDIFF_H
65
66#ifdef __cplusplus
67extern "C" {
68#endif
69
70char *ms_time_new(void );
71void ms_time_free(char *a);
72void ms_time_get(char *a);
73double ms_time_diff(char *start,char *end);
74int ms_time_cmp(char *ap,char *bp);
75
76#ifdef __cplusplus
77}
78#endif
79
80#endif
81
diff --git a/src/lib/libcrypto/ui/ui_compat.c b/src/lib/libcrypto/ui/ui_compat.c
new file mode 100644
index 0000000000..13e0f70d90
--- /dev/null
+++ b/src/lib/libcrypto/ui/ui_compat.c
@@ -0,0 +1,67 @@
1/* crypto/ui/ui_compat.c -*- mode:C; c-file-style: "eay" -*- */
2/* ====================================================================
3 * Copyright (c) 2001-2002 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56#include <string.h>
57#include <openssl/ui_compat.h>
58
59int _ossl_old_des_read_pw_string(char *buf,int length,const char *prompt,int verify)
60 {
61 return UI_UTIL_read_pw_string(buf, length, prompt, verify);
62 }
63
64int _ossl_old_des_read_pw(char *buf,char *buff,int size,const char *prompt,int verify)
65 {
66 return UI_UTIL_read_pw(buf, buff, size, prompt, verify);
67 }
diff --git a/src/lib/libcrypto/uid.c b/src/lib/libcrypto/uid.c
new file mode 100644
index 0000000000..b5b61b76d4
--- /dev/null
+++ b/src/lib/libcrypto/uid.c
@@ -0,0 +1,88 @@
1/* crypto/uid.c */
2/* ====================================================================
3 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * licensing@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56#include <openssl/crypto.h>
57
58#if defined(__OpenBSD__) || (defined(__FreeBSD__) && __FreeBSD__ > 2)
59
60#include <unistd.h>
61
62int OPENSSL_issetugid(void)
63 {
64 return issetugid();
65 }
66
67#elif defined(WIN32)
68
69int OPENSSL_issetugid(void)
70 {
71 return 0;
72 }
73
74#else
75
76#include <unistd.h>
77#include <sys/types.h>
78
79int OPENSSL_issetugid(void)
80 {
81 if (getuid() != geteuid()) return 1;
82 if (getgid() != getegid()) return 1;
83 return 0;
84 }
85#endif
86
87
88
diff --git a/src/lib/libcrypto/util/clean-depend.pl b/src/lib/libcrypto/util/clean-depend.pl
new file mode 100644
index 0000000000..af676af751
--- /dev/null
+++ b/src/lib/libcrypto/util/clean-depend.pl
@@ -0,0 +1,38 @@
1#!/usr/local/bin/perl -w
2# Clean the dependency list in a makefile of standard includes...
3# Written by Ben Laurie <ben@algroup.co.uk> 19 Jan 1999
4
5use strict;
6
7while(<STDIN>) {
8 print;
9 last if /^# DO NOT DELETE THIS LINE/;
10}
11
12my %files;
13
14while(<STDIN>) {
15 my ($file,$deps)=/^(.*): (.*)$/;
16 next if !defined $deps;
17 my @deps=split ' ',$deps;
18 @deps=grep(!/^\/usr\/include/,@deps);
19 @deps=grep(!/^\/usr\/lib\/gcc-lib/,@deps);
20 push @{$files{$file}},@deps;
21}
22
23my $file;
24foreach $file (sort keys %files) {
25 my $len=0;
26 my $dep;
27 foreach $dep (sort @{$files{$file}}) {
28 $len=0 if $len+length($dep)+1 >= 80;
29 if($len == 0) {
30 print "\n$file:";
31 $len=length($file)+1;
32 }
33 print " $dep";
34 $len+=length($dep)+1;
35 }
36}
37
38print "\n";
diff --git a/src/lib/libcrypto/util/cygwin.sh b/src/lib/libcrypto/util/cygwin.sh
new file mode 100644
index 0000000000..b607399b02
--- /dev/null
+++ b/src/lib/libcrypto/util/cygwin.sh
@@ -0,0 +1,125 @@
1#!/bin/bash
2#
3# This script configures, builds and packs the binary package for
4# the Cygwin net distribution version of OpenSSL
5#
6
7# Uncomment when debugging
8#set -x
9
10CONFIG_OPTIONS="--prefix=/usr shared no-idea no-rc5 no-mdc2"
11INSTALL_PREFIX=/tmp/install
12
13VERSION=
14SUBVERSION=$1
15
16function cleanup()
17{
18 rm -rf ${INSTALL_PREFIX}/etc
19 rm -rf ${INSTALL_PREFIX}/usr
20}
21
22function get_openssl_version()
23{
24 eval `grep '^VERSION=' Makefile.ssl`
25 if [ -z "${VERSION}" ]
26 then
27 echo "Error: Couldn't retrieve OpenSSL version from Makefile.ssl."
28 echo " Check value of variable VERSION in Makefile.ssl."
29 exit 1
30 fi
31}
32
33function base_install()
34{
35 mkdir -p ${INSTALL_PREFIX}
36 cleanup
37 make install INSTALL_PREFIX="${INSTALL_PREFIX}"
38}
39
40function doc_install()
41{
42 DOC_DIR=${INSTALL_PREFIX}/usr/doc/openssl
43
44 mkdir -p ${DOC_DIR}
45 cp CHANGES CHANGES.SSLeay INSTALL LICENSE NEWS README ${DOC_DIR}
46
47 create_cygwin_readme
48}
49
50function create_cygwin_readme()
51{
52 README_DIR=${INSTALL_PREFIX}/usr/doc/Cygwin
53 README_FILE=${README_DIR}/openssl-${VERSION}.README
54
55 mkdir -p ${README_DIR}
56 cat > ${README_FILE} <<- EOF
57 The Cygwin version has been built using the following configure:
58
59 ./config ${CONFIG_OPTIONS}
60
61 The IDEA, RC5 and MDC2 algorithms are disabled due to patent and/or
62 licensing issues.
63 EOF
64}
65
66function create_profile_files()
67{
68 PROFILE_DIR=${INSTALL_PREFIX}/etc/profile.d
69
70 mkdir -p $PROFILE_DIR
71 cat > ${PROFILE_DIR}/openssl.sh <<- "EOF"
72 export MANPATH="${MANPATH}:/usr/ssl/man"
73 EOF
74 cat > ${PROFILE_DIR}/openssl.csh <<- "EOF"
75 if ( $?MANPATH ) then
76 setenv MANPATH "${MANPATH}:/usr/ssl/man"
77 else
78 setenv MANPATH ":/usr/ssl/man"
79 endif
80 EOF
81}
82
83if [ -z "${SUBVERSION}" ]
84then
85 echo "Usage: $0 subversion"
86 exit 1
87fi
88
89if [ ! -f config ]
90then
91 echo "You must start this script in the OpenSSL toplevel source dir."
92 exit 1
93fi
94
95./config ${CONFIG_OPTIONS}
96
97get_openssl_version
98
99make || exit 1
100
101base_install
102
103doc_install
104
105create_cygwin_readme
106
107create_profile_files
108
109cd ${INSTALL_PREFIX}
110strip usr/bin/*.exe usr/bin/*.dll
111
112# Runtime package
113find etc usr/bin usr/doc usr/ssl/certs usr/ssl/man/man[157] usr/ssl/misc \
114 usr/ssl/openssl.cnf usr/ssl/private -empty -o \! -type d |
115tar cjfT openssl-${VERSION}-${SUBVERSION}.tar.bz2 -
116# Development package
117find usr/include usr/lib usr/ssl/man/man3 -empty -o \! -type d |
118tar cjfT openssl-devel-${VERSION}-${SUBVERSION}.tar.bz2 -
119
120ls -l openssl-${VERSION}-${SUBVERSION}.tar.bz2
121ls -l openssl-devel-${VERSION}-${SUBVERSION}.tar.bz2
122
123cleanup
124
125exit 0
diff --git a/src/lib/libcrypto/util/domd b/src/lib/libcrypto/util/domd
new file mode 100644
index 0000000000..324051f60b
--- /dev/null
+++ b/src/lib/libcrypto/util/domd
@@ -0,0 +1,11 @@
1#!/bin/sh
2# Do a makedepend, only leave out the standard headers
3# Written by Ben Laurie <ben@algroup.co.uk> 19 Jan 1999
4
5TOP=$1
6shift
7
8cp Makefile.ssl Makefile.save
9makedepend -f Makefile.ssl $@
10$TOP/util/clean-depend.pl < Makefile.ssl > Makefile.new
11mv Makefile.new Makefile.ssl
diff --git a/src/lib/libcrypto/util/mkdir-p.pl b/src/lib/libcrypto/util/mkdir-p.pl
new file mode 100644
index 0000000000..6c69c2daa4
--- /dev/null
+++ b/src/lib/libcrypto/util/mkdir-p.pl
@@ -0,0 +1,33 @@
1#!/usr/local/bin/perl
2
3# mkdir-p.pl
4
5# On some systems, the -p option to mkdir (= also create any missing parent
6# directories) is not available.
7
8my $arg;
9
10foreach $arg (@ARGV) {
11 &do_mkdir_p($arg);
12}
13
14
15sub do_mkdir_p {
16 local($dir) = @_;
17
18 $dir =~ s|/*\Z(?!\n)||s;
19
20 if (-d $dir) {
21 return;
22 }
23
24 if ($dir =~ m|[^/]/|s) {
25 local($parent) = $dir;
26 $parent =~ s|[^/]*\Z(?!\n)||s;
27
28 do_mkdir_p($parent);
29 }
30
31 mkdir($dir, 0777) || die "Cannot create directory $dir: $!\n";
32 print "created directory `$dir'\n";
33}
diff --git a/src/lib/libcrypto/util/mkfiles.pl b/src/lib/libcrypto/util/mkfiles.pl
new file mode 100644
index 0000000000..6fa424bd19
--- /dev/null
+++ b/src/lib/libcrypto/util/mkfiles.pl
@@ -0,0 +1,110 @@
1#!/usr/local/bin/perl
2#
3# This is a hacked version of files.pl for systems that can't do a 'make files'.
4# Do a perl util/mkminfo.pl >MINFO to build MINFO
5# Written by Steve Henson 1999.
6
7# List of directories to process
8
9my @dirs = (
10".",
11"crypto",
12"crypto/md2",
13"crypto/md5",
14"crypto/sha",
15"crypto/mdc2",
16"crypto/hmac",
17"crypto/ripemd",
18"crypto/des",
19"crypto/rc2",
20"crypto/rc4",
21"crypto/rc5",
22"crypto/idea",
23"crypto/bf",
24"crypto/cast",
25"crypto/bn",
26"crypto/rsa",
27"crypto/dsa",
28"crypto/dh",
29"crypto/buffer",
30"crypto/bio",
31"crypto/stack",
32"crypto/lhash",
33"crypto/rand",
34"crypto/err",
35"crypto/objects",
36"crypto/evp",
37"crypto/asn1",
38"crypto/pem",
39"crypto/x509",
40"crypto/x509v3",
41"crypto/conf",
42"crypto/txt_db",
43"crypto/pkcs7",
44"crypto/pkcs12",
45"crypto/comp",
46"ssl",
47"rsaref",
48"apps",
49"test",
50"tools"
51);
52
53foreach (@dirs) {
54 &files_dir ($_, "Makefile.ssl");
55}
56
57exit(0);
58
59sub files_dir
60{
61my ($dir, $makefile) = @_;
62
63my %sym;
64
65open (IN, "$dir/$makefile") || die "Can't open $dir/$makefile";
66
67my $s="";
68
69while (<IN>)
70 {
71 chop;
72 s/#.*//;
73 if (/^(\S+)\s*=\s*(.*)$/)
74 {
75 $o="";
76 ($s,$b)=($1,$2);
77 for (;;)
78 {
79 if ($b =~ /\\$/)
80 {
81 chop($b);
82 $o.=$b." ";
83 $b=<IN>;
84 chop($b);
85 }
86 else
87 {
88 $o.=$b." ";
89 last;
90 }
91 }
92 $o =~ s/^\s+//;
93 $o =~ s/\s+$//;
94 $o =~ s/\s+/ /g;
95
96 $o =~ s/\$[({]([^)}]+)[)}]/$sym{$1}/g;
97 $sym{$s}=$o;
98 }
99 }
100
101print "RELATIVE_DIRECTORY=$dir\n";
102
103foreach (sort keys %sym)
104 {
105 print "$_=$sym{$_}\n";
106 }
107print "RELATIVE_DIRECTORY=\n";
108
109close (IN);
110}
diff --git a/src/lib/libcrypto/util/mklink.pl b/src/lib/libcrypto/util/mklink.pl
new file mode 100644
index 0000000000..de555820ec
--- /dev/null
+++ b/src/lib/libcrypto/util/mklink.pl
@@ -0,0 +1,55 @@
1#!/usr/local/bin/perl
2
3# mklink.pl
4
5# The first command line argument is a non-empty relative path
6# specifying the "from" directory.
7# Each other argument is a file name not containing / and
8# names a file in the current directory.
9#
10# For each of these files, we create in the "from" directory a link
11# of the same name pointing to the local file.
12#
13# We assume that the directory structure is a tree, i.e. that it does
14# not contain symbolic links and that the parent of / is never referenced.
15# Apart from this, this script should be able to handle even the most
16# pathological cases.
17
18my $from = shift;
19my @files = @ARGV;
20
21my @from_path = split(/\//, $from);
22my $pwd = `pwd`;
23chop($pwd);
24my @pwd_path = split(/\//, $pwd);
25
26my @to_path = ();
27
28my $dirname;
29foreach $dirname (@from_path) {
30
31 # In this loop, @to_path always is a relative path from
32 # @pwd_path (interpreted is an absolute path) to the original pwd.
33
34 # At the end, @from_path (as a relative path from the original pwd)
35 # designates the same directory as the absolute path @pwd_path,
36 # which means that @to_path then is a path from there to the original pwd.
37
38 next if ($dirname eq "" || $dirname eq ".");
39
40 if ($dirname eq "..") {
41 @to_path = (pop(@pwd_path), @to_path);
42 } else {
43 @to_path = ("..", @to_path);
44 push(@pwd_path, $dirname);
45 }
46}
47
48my $to = join('/', @to_path);
49
50my $file;
51foreach $file (@files) {
52# print "ln -s $to/$file $from/$file\n";
53 symlink("$to/$file", "$from/$file");
54 print $file . " => $from/$file\n";
55}
diff --git a/src/lib/libcrypto/util/pl/Mingw32.pl b/src/lib/libcrypto/util/pl/Mingw32.pl
new file mode 100644
index 0000000000..84c2a22db3
--- /dev/null
+++ b/src/lib/libcrypto/util/pl/Mingw32.pl
@@ -0,0 +1,79 @@
1#!/usr/local/bin/perl
2#
3# Mingw32.pl -- Mingw32 with GNU cp (Mingw32f.pl uses DOS tools)
4#
5
6$o='/';
7$cp='cp';
8$rm='rem'; # use 'rm -f' if using GNU file utilities
9$mkdir='gmkdir';
10
11# gcc wouldn't accept backslashes in paths
12#$o='\\';
13#$cp='copy';
14#$rm='del';
15
16# C compiler stuff
17
18$cc='gcc';
19if ($debug)
20 { $cflags="-g2 -ggdb"; }
21else
22 { $cflags="-DL_ENDIAN -fomit-frame-pointer -O3 -m486 -Wall"; }
23
24$obj='.o';
25$ofile='-o ';
26
27# EXE linking stuff
28$link='${CC}';
29$lflags='${CFLAGS}';
30$efile='-o ';
31$exep='';
32$ex_libs="-lwsock32 -lgdi32";
33
34# static library stuff
35$mklib='ar r';
36$mlflags='';
37$ranlib='ranlib';
38$plib='lib';
39$libp=".a";
40$shlibp=".a";
41$lfile='';
42
43$asm='as';
44$afile='-o ';
45$bn_asm_obj="";
46$bn_asm_src="";
47$des_enc_obj="";
48$des_enc_src="";
49$bf_enc_obj="";
50$bf_enc_src="";
51
52sub do_lib_rule
53 {
54 local($obj,$target,$name,$shlib)=@_;
55 local($ret,$_,$Name);
56
57 $target =~ s/\//$o/g if $o ne '/';
58 $target="$target";
59 ($Name=$name) =~ tr/a-z/A-Z/;
60
61 $ret.="$target: \$(${Name}OBJ)\n";
62 $ret.="\t\$(RM) $target\n";
63 $ret.="\t\$(MKLIB) $target \$(${Name}OBJ)\n";
64 $ret.="\t\$(RANLIB) $target\n\n";
65 }
66
67sub do_link_rule
68 {
69 local($target,$files,$dep_libs,$libs)=@_;
70 local($ret,$_);
71
72 $file =~ s/\//$o/g if $o ne '/';
73 $n=&bname($target);
74 $ret.="$target: $files $dep_libs\n";
75 $ret.="\t\$(LINK) ${efile}$target \$(LFLAGS) $files $libs\n\n";
76 return($ret);
77 }
781;
79
diff --git a/src/lib/libcrypto/util/pl/OS2-EMX.pl b/src/lib/libcrypto/util/pl/OS2-EMX.pl
new file mode 100644
index 0000000000..57180556ca
--- /dev/null
+++ b/src/lib/libcrypto/util/pl/OS2-EMX.pl
@@ -0,0 +1,96 @@
1#!/usr/local/bin/perl
2#
3# OS2-EMX.pl - for EMX GCC on OS/2
4#
5
6$o='\\';
7$cp='copy';
8$rm='rm -f';
9
10# C compiler stuff
11
12$cc='gcc';
13$cflags="-DL_ENDIAN -O3 -fomit-frame-pointer -m486 -Zmt -Wall ";
14
15if ($debug) {
16 $cflags.="-g ";
17}
18
19$obj='.o';
20$ofile='-o ';
21
22# EXE linking stuff
23$link='${CC}';
24$lflags='${CFLAGS} -Zbsd-signals';
25$efile='-o ';
26$exep='.exe';
27$ex_libs="-lsocket";
28
29# static library stuff
30$mklib='ar r';
31$mlflags='';
32$ranlib="ar s";
33$plib='lib';
34$libp=".a";
35$shlibp=".a";
36$lfile='';
37
38$asm='as';
39$afile='-o ';
40$bn_asm_obj="";
41$bn_asm_src="";
42$des_enc_obj="";
43$des_enc_src="";
44$bf_enc_obj="";
45$bf_enc_src="";
46
47if (!$no_asm)
48 {
49 $bn_asm_obj='crypto\bn\asm\bn-os2.o crypto\bn\asm\co-os2.o';
50 $bn_asm_src='crypto\bn\asm\bn-os2.asm crypto\bn\asm\co-os2.asm';
51 $des_enc_obj='crypto\des\asm\d-os2.o crypto\des\asm\y-os2.o';
52 $des_enc_src='crypto\des\asm\d-os2.asm crypto\des\asm\y-os2.asm';
53 $bf_enc_obj='crypto\bf\asm\b-os2.o';
54 $bf_enc_src='crypto\bf\asm\b-os2.asm';
55 $cast_enc_obj='crypto\cast\asm\c-os2.o';
56 $cast_enc_src='crypto\cast\asm\c-os2.asm';
57 $rc4_enc_obj='crypto\rc4\asm\r4-os2.o';
58 $rc4_enc_src='crypto\rc4\asm\r4-os2.asm';
59 $rc5_enc_obj='crypto\rc5\asm\r5-os2.o';
60 $rc5_enc_src='crypto\rc5\asm\r5-os2.asm';
61 $md5_asm_obj='crypto\md5\asm\m5-os2.o';
62 $md5_asm_src='crypto\md5\asm\m5-os2.asm';
63 $sha1_asm_obj='crypto\sha\asm\s1-os2.o';
64 $sha1_asm_src='crypto\sha\asm\s1-os2.asm';
65 $rmd160_asm_obj='crypto\ripemd\asm\rm-os2.o';
66 $rmd160_asm_src='crypto\ripemd\asm\rm-os2.asm';
67 }
68
69sub do_lib_rule
70 {
71 local($obj,$target,$name,$shlib)=@_;
72 local($ret,$_,$Name);
73
74 $target =~ s/\//$o/g if $o ne '/';
75 $target="$target";
76 ($Name=$name) =~ tr/a-z/A-Z/;
77
78 $ret.="$target: \$(${Name}OBJ)\n";
79 $ret.="\t\$(RM) $target\n";
80 $ret.="\t\$(MKLIB) $target \$(${Name}OBJ)\n";
81 $ret.="\t\$(RANLIB) $target\n\n";
82 }
83
84sub do_link_rule
85 {
86 local($target,$files,$dep_libs,$libs)=@_;
87 local($ret,$_);
88
89 $file =~ s/\//$o/g if $o ne '/';
90 $n=&bname($target);
91 $ret.="$target: $files $dep_libs\n";
92 $ret.="\t\$(LINK) ${efile}$target \$(LFLAGS) $files $libs\n\n";
93 return($ret);
94 }
95
961;
diff --git a/src/lib/libcrypto/util/pl/ultrix.pl b/src/lib/libcrypto/util/pl/ultrix.pl
new file mode 100644
index 0000000000..ea370c71f9
--- /dev/null
+++ b/src/lib/libcrypto/util/pl/ultrix.pl
@@ -0,0 +1,38 @@
1#!/usr/local/bin/perl
2#
3# linux.pl - the standard unix makefile stuff.
4#
5
6$o='/';
7$cp='/bin/cp';
8$rm='/bin/rm -f';
9
10# C compiler stuff
11
12$cc='cc';
13if ($debug)
14 { $cflags="-g -DREF_CHECK -DCRYPTO_MDEBUG"; }
15else
16 { $cflags="-O2"; }
17
18$cflags.=" -std1 -DL_ENDIAN";
19
20if (!$no_asm)
21 {
22 $bn_asm_obj='$(OBJ_D)/mips1.o';
23 $bn_asm_src='crypto/bn/asm/mips1.s';
24 }
25
26sub do_link_rule
27 {
28 local($target,$files,$dep_libs,$libs)=@_;
29 local($ret,$_);
30
31 $file =~ s/\//$o/g if $o ne '/';
32 $n=&bname($target);
33 $ret.="$target: $files $dep_libs\n";
34 $ret.="\t\$(LINK) ${efile}$target \$(LFLAGS) $files $libs\n\n";
35 return($ret);
36 }
37
381;
diff --git a/src/lib/libcrypto/util/pod2man.pl b/src/lib/libcrypto/util/pod2man.pl
new file mode 100644
index 0000000000..f5ec0767ed
--- /dev/null
+++ b/src/lib/libcrypto/util/pod2man.pl
@@ -0,0 +1,1181 @@
1: #!/usr/bin/perl-5.005
2 eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
3 if $running_under_some_shell;
4
5$DEF_PM_SECTION = '3pm' || '3';
6
7=head1 NAME
8
9pod2man - translate embedded Perl pod directives into man pages
10
11=head1 SYNOPSIS
12
13B<pod2man>
14[ B<--section=>I<manext> ]
15[ B<--release=>I<relpatch> ]
16[ B<--center=>I<string> ]
17[ B<--date=>I<string> ]
18[ B<--fixed=>I<font> ]
19[ B<--official> ]
20[ B<--lax> ]
21I<inputfile>
22
23=head1 DESCRIPTION
24
25B<pod2man> converts its input file containing embedded pod directives (see
26L<perlpod>) into nroff source suitable for viewing with nroff(1) or
27troff(1) using the man(7) macro set.
28
29Besides the obvious pod conversions, B<pod2man> also takes care of
30func(), func(n), and simple variable references like $foo or @bar so
31you don't have to use code escapes for them; complex expressions like
32C<$fred{'stuff'}> will still need to be escaped, though. Other nagging
33little roffish things that it catches include translating the minus in
34something like foo-bar, making a long dash--like this--into a real em
35dash, fixing up "paired quotes", putting a little space after the
36parens in something like func(), making C++ and PI look right, making
37double underbars have a little tiny space between them, making ALLCAPS
38a teeny bit smaller in troff(1), and escaping backslashes so you don't
39have to.
40
41=head1 OPTIONS
42
43=over 8
44
45=item center
46
47Set the centered header to a specific string. The default is
48"User Contributed Perl Documentation", unless the C<--official> flag is
49given, in which case the default is "Perl Programmers Reference Guide".
50
51=item date
52
53Set the left-hand footer string to this value. By default,
54the modification date of the input file will be used.
55
56=item fixed
57
58The fixed font to use for code refs. Defaults to CW.
59
60=item official
61
62Set the default header to indicate that this page is of
63the standard release in case C<--center> is not given.
64
65=item release
66
67Set the centered footer. By default, this is the current
68perl release.
69
70=item section
71
72Set the section for the C<.TH> macro. The standard conventions on
73sections are to use 1 for user commands, 2 for system calls, 3 for
74functions, 4 for devices, 5 for file formats, 6 for games, 7 for
75miscellaneous information, and 8 for administrator commands. This works
76best if you put your Perl man pages in a separate tree, like
77F</usr/local/perl/man/>. By default, section 1 will be used
78unless the file ends in F<.pm> in which case section 3 will be selected.
79
80=item lax
81
82Don't complain when required sections aren't present.
83
84=back
85
86=head1 Anatomy of a Proper Man Page
87
88For those not sure of the proper layout of a man page, here's
89an example of the skeleton of a proper man page. Head of the
90major headers should be setout as a C<=head1> directive, and
91are historically written in the rather startling ALL UPPER CASE
92format, although this is not mandatory.
93Minor headers may be included using C<=head2>, and are
94typically in mixed case.
95
96=over 10
97
98=item NAME
99
100Mandatory section; should be a comma-separated list of programs or
101functions documented by this podpage, such as:
102
103 foo, bar - programs to do something
104
105=item SYNOPSIS
106
107A short usage summary for programs and functions, which
108may someday be deemed mandatory.
109
110=item DESCRIPTION
111
112Long drawn out discussion of the program. It's a good idea to break this
113up into subsections using the C<=head2> directives, like
114
115 =head2 A Sample Subection
116
117 =head2 Yet Another Sample Subection
118
119=item OPTIONS
120
121Some people make this separate from the description.
122
123=item RETURN VALUE
124
125What the program or function returns if successful.
126
127=item ERRORS
128
129Exceptions, return codes, exit stati, and errno settings.
130
131=item EXAMPLES
132
133Give some example uses of the program.
134
135=item ENVIRONMENT
136
137Envariables this program might care about.
138
139=item FILES
140
141All files used by the program. You should probably use the FE<lt>E<gt>
142for these.
143
144=item SEE ALSO
145
146Other man pages to check out, like man(1), man(7), makewhatis(8), or catman(8).
147
148=item NOTES
149
150Miscellaneous commentary.
151
152=item CAVEATS
153
154Things to take special care with; sometimes called WARNINGS.
155
156=item DIAGNOSTICS
157
158All possible messages the program can print out--and
159what they mean.
160
161=item BUGS
162
163Things that are broken or just don't work quite right.
164
165=item RESTRICTIONS
166
167Bugs you don't plan to fix :-)
168
169=item AUTHOR
170
171Who wrote it (or AUTHORS if multiple).
172
173=item HISTORY
174
175Programs derived from other sources sometimes have this, or
176you might keep a modification log here.
177
178=back
179
180=head1 EXAMPLES
181
182 pod2man program > program.1
183 pod2man some_module.pm > /usr/perl/man/man3/some_module.3
184 pod2man --section=7 note.pod > note.7
185
186=head1 DIAGNOSTICS
187
188The following diagnostics are generated by B<pod2man>. Items
189marked "(W)" are non-fatal, whereas the "(F)" errors will cause
190B<pod2man> to immediately exit with a non-zero status.
191
192=over 4
193
194=item bad option in paragraph %d of %s: ``%s'' should be [%s]<%s>
195
196(W) If you start include an option, you should set it off
197as bold, italic, or code.
198
199=item can't open %s: %s
200
201(F) The input file wasn't available for the given reason.
202
203=item Improper man page - no dash in NAME header in paragraph %d of %s
204
205(W) The NAME header did not have an isolated dash in it. This is
206considered important.
207
208=item Invalid man page - no NAME line in %s
209
210(F) You did not include a NAME header, which is essential.
211
212=item roff font should be 1 or 2 chars, not `%s' (F)
213
214(F) The font specified with the C<--fixed> option was not
215a one- or two-digit roff font.
216
217=item %s is missing required section: %s
218
219(W) Required sections include NAME, DESCRIPTION, and if you're
220using a section starting with a 3, also a SYNOPSIS. Actually,
221not having a NAME is a fatal.
222
223=item Unknown escape: %s in %s
224
225(W) An unknown HTML entity (probably for an 8-bit character) was given via
226a C<EE<lt>E<gt>> directive. Besides amp, lt, gt, and quot, recognized
227entities are Aacute, aacute, Acirc, acirc, AElig, aelig, Agrave, agrave,
228Aring, aring, Atilde, atilde, Auml, auml, Ccedil, ccedil, Eacute, eacute,
229Ecirc, ecirc, Egrave, egrave, ETH, eth, Euml, euml, Iacute, iacute, Icirc,
230icirc, Igrave, igrave, Iuml, iuml, Ntilde, ntilde, Oacute, oacute, Ocirc,
231ocirc, Ograve, ograve, Oslash, oslash, Otilde, otilde, Ouml, ouml, szlig,
232THORN, thorn, Uacute, uacute, Ucirc, ucirc, Ugrave, ugrave, Uuml, uuml,
233Yacute, yacute, and yuml.
234
235=item Unmatched =back
236
237(W) You have a C<=back> without a corresponding C<=over>.
238
239=item Unrecognized pod directive: %s
240
241(W) You specified a pod directive that isn't in the known list of
242C<=head1>, C<=head2>, C<=item>, C<=over>, C<=back>, or C<=cut>.
243
244
245=back
246
247=head1 NOTES
248
249If you would like to print out a lot of man page continuously, you
250probably want to set the C and D registers to set contiguous page
251numbering and even/odd paging, at least on some versions of man(7).
252Settting the F register will get you some additional experimental
253indexing:
254
255 troff -man -rC1 -rD1 -rF1 perl.1 perldata.1 perlsyn.1 ...
256
257The indexing merely outputs messages via C<.tm> for each
258major page, section, subsection, item, and any C<XE<lt>E<gt>>
259directives.
260
261
262=head1 RESTRICTIONS
263
264None at this time.
265
266=head1 BUGS
267
268The =over and =back directives don't really work right. They
269take absolute positions instead of offsets, don't nest well, and
270making people count is suboptimal in any event.
271
272=head1 AUTHORS
273
274Original prototype by Larry Wall, but so massively hacked over by
275Tom Christiansen such that Larry probably doesn't recognize it anymore.
276
277=cut
278
279$/ = "";
280$cutting = 1;
281@Indices = ();
282
283# We try first to get the version number from a local binary, in case we're
284# running an installed version of Perl to produce documentation from an
285# uninstalled newer version's pod files.
286if ($^O ne 'plan9' and $^O ne 'dos' and $^O ne 'os2' and $^O ne 'MSWin32') {
287 my $perl = (-x './perl' && -f './perl' ) ?
288 './perl' :
289 ((-x '../perl' && -f '../perl') ?
290 '../perl' :
291 '');
292 ($version,$patch) = `$perl -e 'print $]'` =~ /^(\d\.\d{3})(\d{2})?/ if $perl;
293}
294# No luck; we'll just go with the running Perl's version
295($version,$patch) = $] =~ /^(.{5})(\d{2})?/ unless $version;
296$DEF_RELEASE = "perl $version";
297$DEF_RELEASE .= ", patch $patch" if $patch;
298
299
300sub makedate {
301 my $secs = shift;
302 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($secs);
303 my $mname = (qw{Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec})[$mon];
304 $year += 1900;
305 return "$mday/$mname/$year";
306}
307
308use Getopt::Long;
309
310$DEF_SECTION = 1;
311$DEF_CENTER = "User Contributed Perl Documentation";
312$STD_CENTER = "Perl Programmers Reference Guide";
313$DEF_FIXED = 'CW';
314$DEF_LAX = 0;
315
316sub usage {
317 warn "$0: @_\n" if @_;
318 die <<EOF;
319usage: $0 [options] podpage
320Options are:
321 --section=manext (default "$DEF_SECTION")
322 --release=relpatch (default "$DEF_RELEASE")
323 --center=string (default "$DEF_CENTER")
324 --date=string (default "$DEF_DATE")
325 --fixed=font (default "$DEF_FIXED")
326 --official (default NOT)
327 --lax (default NOT)
328EOF
329}
330
331$uok = GetOptions( qw(
332 section=s
333 release=s
334 center=s
335 date=s
336 fixed=s
337 official
338 lax
339 help));
340
341$DEF_DATE = makedate((stat($ARGV[0]))[9] || time());
342
343usage("Usage error!") unless $uok;
344usage() if $opt_help;
345usage("Need one and only one podpage argument") unless @ARGV == 1;
346
347$section = $opt_section || ($ARGV[0] =~ /\.pm$/
348 ? $DEF_PM_SECTION : $DEF_SECTION);
349$RP = $opt_release || $DEF_RELEASE;
350$center = $opt_center || ($opt_official ? $STD_CENTER : $DEF_CENTER);
351$lax = $opt_lax || $DEF_LAX;
352
353$CFont = $opt_fixed || $DEF_FIXED;
354
355if (length($CFont) == 2) {
356 $CFont_embed = "\\f($CFont";
357}
358elsif (length($CFont) == 1) {
359 $CFont_embed = "\\f$CFont";
360}
361else {
362 die "roff font should be 1 or 2 chars, not `$CFont_embed'";
363}
364
365$date = $opt_date || $DEF_DATE;
366
367for (qw{NAME DESCRIPTION}) {
368# for (qw{NAME DESCRIPTION AUTHOR}) {
369 $wanna_see{$_}++;
370}
371$wanna_see{SYNOPSIS}++ if $section =~ /^3/;
372
373
374$name = @ARGV ? $ARGV[0] : "<STDIN>";
375$Filename = $name;
376if ($section =~ /^1/) {
377 require File::Basename;
378 $name = uc File::Basename::basename($name);
379}
380$name =~ s/\.(pod|p[lm])$//i;
381
382# Lose everything up to the first of
383# */lib/*perl* standard or site_perl module
384# */*perl*/lib from -D prefix=/opt/perl
385# */*perl*/ random module hierarchy
386# which works.
387$name =~ s-//+-/-g;
388if ($name =~ s-^.*?/lib/[^/]*perl[^/]*/--i
389 or $name =~ s-^.*?/[^/]*perl[^/]*/lib/--i
390 or $name =~ s-^.*?/[^/]*perl[^/]*/--i) {
391 # Lose ^site(_perl)?/.
392 $name =~ s-^site(_perl)?/--;
393 # Lose ^arch/. (XXX should we use Config? Just for archname?)
394 $name =~ s~^(.*-$^O|$^O-.*)/~~o;
395 # Lose ^version/.
396 $name =~ s-^\d+\.\d+/--;
397}
398
399# Translate Getopt/Long to Getopt::Long, etc.
400$name =~ s(/)(::)g;
401
402if ($name ne 'something') {
403 FCHECK: {
404 open(F, "< $ARGV[0]") || die "can't open $ARGV[0]: $!";
405 while (<F>) {
406 next unless /^=\b/;
407 if (/^=head1\s+NAME\s*$/) { # an /m would forgive mistakes
408 $_ = <F>;
409 unless (/\s*-+\s+/) {
410 $oops++;
411 warn "$0: Improper man page - no dash in NAME header in paragraph $. of $ARGV[0]\n"
412 } else {
413 my @n = split /\s+-+\s+/;
414 if (@n != 2) {
415 $oops++;
416 warn "$0: Improper man page - malformed NAME header in paragraph $. of $ARGV[0]\n"
417 }
418 else {
419 %namedesc = @n;
420 }
421 }
422 last FCHECK;
423 }
424 next if /^=cut\b/; # DB_File and Net::Ping have =cut before NAME
425 next if /^=pod\b/; # It is OK to have =pod before NAME
426 die "$0: Invalid man page - 1st pod line is not NAME in $ARGV[0]\n" unless $lax;
427 }
428 die "$0: Invalid man page - no documentation in $ARGV[0]\n" unless $lax;
429 }
430 close F;
431}
432
433print <<"END";
434.rn '' }`
435''' \$RCSfile\$\$Revision\$\$Date\$
436'''
437''' \$Log\$
438'''
439.de Sh
440.br
441.if t .Sp
442.ne 5
443.PP
444\\fB\\\\\$1\\fR
445.PP
446..
447.de Sp
448.if t .sp .5v
449.if n .sp
450..
451.de Ip
452.br
453.ie \\\\n(.\$>=3 .ne \\\\\$3
454.el .ne 3
455.IP "\\\\\$1" \\\\\$2
456..
457.de Vb
458.ft $CFont
459.nf
460.ne \\\\\$1
461..
462.de Ve
463.ft R
464
465.fi
466..
467'''
468'''
469''' Set up \\*(-- to give an unbreakable dash;
470''' string Tr holds user defined translation string.
471''' Bell System Logo is used as a dummy character.
472'''
473.tr \\(*W-|\\(bv\\*(Tr
474.ie n \\{\\
475.ds -- \\(*W-
476.ds PI pi
477.if (\\n(.H=4u)&(1m=24u) .ds -- \\(*W\\h'-12u'\\(*W\\h'-12u'-\\" diablo 10 pitch
478.if (\\n(.H=4u)&(1m=20u) .ds -- \\(*W\\h'-12u'\\(*W\\h'-8u'-\\" diablo 12 pitch
479.ds L" ""
480.ds R" ""
481''' \\*(M", \\*(S", \\*(N" and \\*(T" are the equivalent of
482''' \\*(L" and \\*(R", except that they are used on ".xx" lines,
483''' such as .IP and .SH, which do another additional levels of
484''' double-quote interpretation
485.ds M" """
486.ds S" """
487.ds N" """""
488.ds T" """""
489.ds L' '
490.ds R' '
491.ds M' '
492.ds S' '
493.ds N' '
494.ds T' '
495'br\\}
496.el\\{\\
497.ds -- \\(em\\|
498.tr \\*(Tr
499.ds L" ``
500.ds R" ''
501.ds M" ``
502.ds S" ''
503.ds N" ``
504.ds T" ''
505.ds L' `
506.ds R' '
507.ds M' `
508.ds S' '
509.ds N' `
510.ds T' '
511.ds PI \\(*p
512'br\\}
513END
514
515print <<'END';
516.\" If the F register is turned on, we'll generate
517.\" index entries out stderr for the following things:
518.\" TH Title
519.\" SH Header
520.\" Sh Subsection
521.\" Ip Item
522.\" X<> Xref (embedded
523.\" Of course, you have to process the output yourself
524.\" in some meaninful fashion.
525.if \nF \{
526.de IX
527.tm Index:\\$1\t\\n%\t"\\$2"
528..
529.nr % 0
530.rr F
531.\}
532END
533
534print <<"END";
535.TH $name $section "$RP" "$date" "$center"
536.UC
537END
538
539push(@Indices, qq{.IX Title "$name $section"});
540
541while (($name, $desc) = each %namedesc) {
542 for ($name, $desc) { s/^\s+//; s/\s+$//; }
543 push(@Indices, qq(.IX Name "$name - $desc"\n));
544}
545
546print <<'END';
547.if n .hy 0
548.if n .na
549.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
550.de CQ \" put $1 in typewriter font
551END
552print ".ft $CFont\n";
553print <<'END';
554'if n "\c
555'if t \\&\\$1\c
556'if n \\&\\$1\c
557'if n \&"
558\\&\\$2 \\$3 \\$4 \\$5 \\$6 \\$7
559'.ft R
560..
561.\" @(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2
562. \" AM - accent mark definitions
563.bd B 3
564. \" fudge factors for nroff and troff
565.if n \{\
566. ds #H 0
567. ds #V .8m
568. ds #F .3m
569. ds #[ \f1
570. ds #] \fP
571.\}
572.if t \{\
573. ds #H ((1u-(\\\\n(.fu%2u))*.13m)
574. ds #V .6m
575. ds #F 0
576. ds #[ \&
577. ds #] \&
578.\}
579. \" simple accents for nroff and troff
580.if n \{\
581. ds ' \&
582. ds ` \&
583. ds ^ \&
584. ds , \&
585. ds ~ ~
586. ds ? ?
587. ds ! !
588. ds /
589. ds q
590.\}
591.if t \{\
592. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
593. ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
594. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
595. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
596. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
597. ds ? \s-2c\h'-\w'c'u*7/10'\u\h'\*(#H'\zi\d\s+2\h'\w'c'u*8/10'
598. ds ! \s-2\(or\s+2\h'-\w'\(or'u'\v'-.8m'.\v'.8m'
599. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
600. ds q o\h'-\w'o'u*8/10'\s-4\v'.4m'\z\(*i\v'-.4m'\s+4\h'\w'o'u*8/10'
601.\}
602. \" troff and (daisy-wheel) nroff accents
603.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
604.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
605.ds v \\k:\h'-(\\n(.wu*9/10-\*(#H)'\v'-\*(#V'\*(#[\s-4v\s0\v'\*(#V'\h'|\\n:u'\*(#]
606.ds _ \\k:\h'-(\\n(.wu*9/10-\*(#H+(\*(#F*2/3))'\v'-.4m'\z\(hy\v'.4m'\h'|\\n:u'
607.ds . \\k:\h'-(\\n(.wu*8/10)'\v'\*(#V*4/10'\z.\v'-\*(#V*4/10'\h'|\\n:u'
608.ds 3 \*(#[\v'.2m'\s-2\&3\s0\v'-.2m'\*(#]
609.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
610.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
611.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
612.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
613.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
614.ds ae a\h'-(\w'a'u*4/10)'e
615.ds Ae A\h'-(\w'A'u*4/10)'E
616.ds oe o\h'-(\w'o'u*4/10)'e
617.ds Oe O\h'-(\w'O'u*4/10)'E
618. \" corrections for vroff
619.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
620.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
621. \" for low resolution devices (crt and lpr)
622.if \n(.H>23 .if \n(.V>19 \
623\{\
624. ds : e
625. ds 8 ss
626. ds v \h'-1'\o'\(aa\(ga'
627. ds _ \h'-1'^
628. ds . \h'-1'.
629. ds 3 3
630. ds o a
631. ds d- d\h'-1'\(ga
632. ds D- D\h'-1'\(hy
633. ds th \o'bp'
634. ds Th \o'LP'
635. ds ae ae
636. ds Ae AE
637. ds oe oe
638. ds Oe OE
639.\}
640.rm #[ #] #H #V #F C
641END
642
643$indent = 0;
644
645$begun = "";
646
647# Unrolling [^A-Z>]|[A-Z](?!<) gives: // MRE pp 165.
648my $nonest = '(?:[^A-Z>]*(?:[A-Z](?!<)[^A-Z>]*)*)';
649
650while (<>) {
651 if ($cutting) {
652 next unless /^=/;
653 $cutting = 0;
654 }
655 if ($begun) {
656 if (/^=end\s+$begun/) {
657 $begun = "";
658 }
659 elsif ($begun =~ /^(roff|man)$/) {
660 print STDOUT $_;
661 }
662 next;
663 }
664 chomp;
665
666 # Translate verbatim paragraph
667
668 if (/^\s/) {
669 @lines = split(/\n/);
670 for (@lines) {
671 1 while s
672 {^( [^\t]* ) \t ( \t* ) }
673 { $1 . ' ' x (8 - (length($1)%8) + 8 * (length($2))) }ex;
674 s/\\/\\e/g;
675 s/\A/\\&/s;
676 }
677 $lines = @lines;
678 makespace() unless $verbatim++;
679 print ".Vb $lines\n";
680 print join("\n", @lines), "\n";
681 print ".Ve\n";
682 $needspace = 0;
683 next;
684 }
685
686 $verbatim = 0;
687
688 if (/^=for\s+(\S+)\s*/s) {
689 if ($1 eq "man" or $1 eq "roff") {
690 print STDOUT $',"\n\n";
691 } else {
692 # ignore unknown for
693 }
694 next;
695 }
696 elsif (/^=begin\s+(\S+)\s*/s) {
697 $begun = $1;
698 if ($1 eq "man" or $1 eq "roff") {
699 print STDOUT $'."\n\n";
700 }
701 next;
702 }
703
704 # check for things that'll hosed our noremap scheme; affects $_
705 init_noremap();
706
707 if (!/^=item/) {
708
709 # trofficate backslashes; must do it before what happens below
710 s/\\/noremap('\\e')/ge;
711
712 # protect leading periods and quotes against *roff
713 # mistaking them for directives
714 s/^(?:[A-Z]<)?[.']/\\&$&/gm;
715
716 # first hide the escapes in case we need to
717 # intuit something and get it wrong due to fmting
718
719 1 while s/([A-Z]<$nonest>)/noremap($1)/ge;
720
721 # func() is a reference to a perl function
722 s{
723 \b
724 (
725 [:\w]+ \(\)
726 )
727 } {I<$1>}gx;
728
729 # func(n) is a reference to a perl function or a man page
730 s{
731 ([:\w]+)
732 (
733 \( [^\051]+ \)
734 )
735 } {I<$1>\\|$2}gx;
736
737 # convert simple variable references
738 s/(\s+)([\$\@%][\w:]+)(?!\()/${1}C<$2>/g;
739
740 if (m{ (
741 [\-\w]+
742 \(
743 [^\051]*?
744 [\@\$,]
745 [^\051]*?
746 \)
747 )
748 }x && $` !~ /([LCI]<[^<>]*|-)$/ && !/^=\w/)
749 {
750 warn "$0: bad option in paragraph $. of $ARGV: ``$1'' should be [LCI]<$1>\n";
751 $oops++;
752 }
753
754 while (/(-[a-zA-Z])\b/g && $` !~ /[\w\-]$/) {
755 warn "$0: bad option in paragraph $. of $ARGV: ``$1'' should be [CB]<$1>\n";
756 $oops++;
757 }
758
759 # put it back so we get the <> processed again;
760 clear_noremap(0); # 0 means leave the E's
761
762 } else {
763 # trofficate backslashes
764 s/\\/noremap('\\e')/ge;
765
766 }
767
768 # need to hide E<> first; they're processed in clear_noremap
769 s/(E<[^<>]+>)/noremap($1)/ge;
770
771
772 $maxnest = 10;
773 while ($maxnest-- && /[A-Z]</) {
774
775 # can't do C font here
776 s/([BI])<($nonest)>/font($1) . $2 . font('R')/eg;
777
778 # files and filelike refs in italics
779 s/F<($nonest)>/I<$1>/g;
780
781 # no break -- usually we want C<> for this
782 s/S<($nonest)>/nobreak($1)/eg;
783
784 # LREF: a la HREF L<show this text|man/section>
785 s:L<([^|>]+)\|[^>]+>:$1:g;
786
787 # LREF: a manpage(3f)
788 s:L<([a-zA-Z][^\s\/]+)(\([^\)]+\))?>:the I<$1>$2 manpage:g;
789
790 # LREF: an =item on another manpage
791 s{
792 L<
793 ([^/]+)
794 /
795 (
796 [:\w]+
797 (\(\))?
798 )
799 >
800 } {the C<$2> entry in the I<$1> manpage}gx;
801
802 # LREF: an =item on this manpage
803 s{
804 ((?:
805 L<
806 /
807 (
808 [:\w]+
809 (\(\))?
810 )
811 >
812 (,?\s+(and\s+)?)?
813 )+)
814 } { internal_lrefs($1) }gex;
815
816 # LREF: a =head2 (head1?), maybe on a manpage, maybe right here
817 # the "func" can disambiguate
818 s{
819 L<
820 (?:
821 ([a-zA-Z]\S+?) /
822 )?
823 "?(.*?)"?
824 >
825 }{
826 do {
827 $1 # if no $1, assume it means on this page.
828 ? "the section on I<$2> in the I<$1> manpage"
829 : "the section on I<$2>"
830 }
831 }gesx; # s in case it goes over multiple lines, so . matches \n
832
833 s/Z<>/\\&/g;
834
835 # comes last because not subject to reprocessing
836 s/C<($nonest)>/noremap("${CFont_embed}${1}\\fR")/eg;
837 }
838
839 if (s/^=//) {
840 $needspace = 0; # Assume this.
841
842 s/\n/ /g;
843
844 ($Cmd, $_) = split(' ', $_, 2);
845
846 $dotlevel = 1;
847 if ($Cmd eq 'head1') {
848 $dotlevel = 1;
849 }
850 elsif ($Cmd eq 'head2') {
851 $dotlevel = 1;
852 }
853 elsif ($Cmd eq 'item') {
854 $dotlevel = 2;
855 }
856
857 if (defined $_) {
858 &escapes($dotlevel);
859 s/"/""/g;
860 }
861
862 clear_noremap(1);
863
864 if ($Cmd eq 'cut') {
865 $cutting = 1;
866 }
867 elsif ($Cmd eq 'head1') {
868 s/\s+$//;
869 delete $wanna_see{$_} if exists $wanna_see{$_};
870 print qq{.SH "$_"\n};
871 push(@Indices, qq{.IX Header "$_"\n});
872 }
873 elsif ($Cmd eq 'head2') {
874 print qq{.Sh "$_"\n};
875 push(@Indices, qq{.IX Subsection "$_"\n});
876 }
877 elsif ($Cmd eq 'over') {
878 push(@indent,$indent);
879 $indent += ($_ + 0) || 5;
880 }
881 elsif ($Cmd eq 'back') {
882 $indent = pop(@indent);
883 warn "$0: Unmatched =back in paragraph $. of $ARGV\n" unless defined $indent;
884 $needspace = 1;
885 }
886 elsif ($Cmd eq 'item') {
887 s/^\*( |$)/\\(bu$1/g;
888 # if you know how to get ":s please do
889 s/\\\*\(L"([^"]+?)\\\*\(R"/'$1'/g;
890 s/\\\*\(L"([^"]+?)""/'$1'/g;
891 s/[^"]""([^"]+?)""[^"]/'$1'/g;
892 # here do something about the $" in perlvar?
893 print STDOUT qq{.Ip "$_" $indent\n};
894 push(@Indices, qq{.IX Item "$_"\n});
895 }
896 elsif ($Cmd eq 'pod') {
897 # this is just a comment
898 }
899 else {
900 warn "$0: Unrecognized pod directive in paragraph $. of $ARGV: $Cmd\n";
901 }
902 }
903 else {
904 if ($needspace) {
905 &makespace;
906 }
907 &escapes(0);
908 clear_noremap(1);
909 print $_, "\n";
910 $needspace = 1;
911 }
912}
913
914print <<"END";
915
916.rn }` ''
917END
918
919if (%wanna_see && !$lax) {
920 @missing = keys %wanna_see;
921 warn "$0: $Filename is missing required section"
922 . (@missing > 1 && "s")
923 . ": @missing\n";
924 $oops++;
925}
926
927foreach (@Indices) { print "$_\n"; }
928
929exit;
930#exit ($oops != 0);
931
932#########################################################################
933
934sub nobreak {
935 my $string = shift;
936 $string =~ s/ /\\ /g;
937 $string;
938}
939
940sub escapes {
941 my $indot = shift;
942
943 s/X<(.*?)>/mkindex($1)/ge;
944
945 # translate the minus in foo-bar into foo\-bar for roff
946 s/([^0-9a-z-])-([^-])/$1\\-$2/g;
947
948 # make -- into the string version \*(-- (defined above)
949 s/\b--\b/\\*(--/g;
950 s/"--([^"])/"\\*(--$1/g; # should be a better way
951 s/([^"])--"/$1\\*(--"/g;
952
953 # fix up quotes; this is somewhat tricky
954 my $dotmacroL = 'L';
955 my $dotmacroR = 'R';
956 if ( $indot == 1 ) {
957 $dotmacroL = 'M';
958 $dotmacroR = 'S';
959 }
960 elsif ( $indot >= 2 ) {
961 $dotmacroL = 'N';
962 $dotmacroR = 'T';
963 }
964 if (!/""/) {
965 s/(^|\s)(['"])/noremap("$1\\*($dotmacroL$2")/ge;
966 s/(['"])($|[\-\s,;\\!?.])/noremap("\\*($dotmacroR$1$2")/ge;
967 }
968
969 #s/(?!")(?:.)--(?!")(?:.)/\\*(--/g;
970 #s/(?:(?!")(?:.)--(?:"))|(?:(?:")--(?!")(?:.))/\\*(--/g;
971
972
973 # make sure that func() keeps a bit a space tween the parens
974 ### s/\b\(\)/\\|()/g;
975 ### s/\b\(\)/(\\|)/g;
976
977 # make C++ into \*C+, which is a squinched version (defined above)
978 s/\bC\+\+/\\*(C+/g;
979
980 # make double underbars have a little tiny space between them
981 s/__/_\\|_/g;
982
983 # PI goes to \*(PI (defined above)
984 s/\bPI\b/noremap('\\*(PI')/ge;
985
986 # make all caps a teeny bit smaller, but don't muck with embedded code literals
987 my $hidCFont = font('C');
988 if ($Cmd !~ /^head1/) { # SH already makes smaller
989 # /g isn't enough; 1 while or we'll be off
990
991# 1 while s{
992# (?!$hidCFont)(..|^.|^)
993# \b
994# (
995# [A-Z][\/A-Z+:\-\d_$.]+
996# )
997# (s?)
998# \b
999# } {$1\\s-1$2\\s0}gmox;
1000
1001 1 while s{
1002 (?!$hidCFont)(..|^.|^)
1003 (
1004 \b[A-Z]{2,}[\/A-Z+:\-\d_\$]*\b
1005 )
1006 } {
1007 $1 . noremap( '\\s-1' . $2 . '\\s0' )
1008 }egmox;
1009
1010 }
1011}
1012
1013# make troff just be normal, but make small nroff get quoted
1014# decided to just put the quotes in the text; sigh;
1015sub ccvt {
1016 local($_,$prev) = @_;
1017 noremap(qq{.CQ "$_" \n\\&});
1018}
1019
1020sub makespace {
1021 if ($indent) {
1022 print ".Sp\n";
1023 }
1024 else {
1025 print ".PP\n";
1026 }
1027}
1028
1029sub mkindex {
1030 my ($entry) = @_;
1031 my @entries = split m:\s*/\s*:, $entry;
1032 push @Indices, ".IX Xref " . join ' ', map {qq("$_")} @entries;
1033 return '';
1034}
1035
1036sub font {
1037 local($font) = shift;
1038 return '\\f' . noremap($font);
1039}
1040
1041sub noremap {
1042 local($thing_to_hide) = shift;
1043 $thing_to_hide =~ tr/\000-\177/\200-\377/;
1044 return $thing_to_hide;
1045}
1046
1047sub init_noremap {
1048 # escape high bit characters in input stream
1049 s/([\200-\377])/"E<".ord($1).">"/ge;
1050}
1051
1052sub clear_noremap {
1053 my $ready_to_print = $_[0];
1054
1055 tr/\200-\377/\000-\177/;
1056
1057 # trofficate backslashes
1058 # s/(?!\\e)(?:..|^.|^)\\/\\e/g;
1059
1060 # now for the E<>s, which have been hidden until now
1061 # otherwise the interative \w<> processing would have
1062 # been hosed by the E<gt>
1063 s {
1064 E<
1065 (
1066 ( \d + )
1067 | ( [A-Za-z]+ )
1068 )
1069 >
1070 } {
1071 do {
1072 defined $2
1073 ? chr($2)
1074 :
1075 exists $HTML_Escapes{$3}
1076 ? do { $HTML_Escapes{$3} }
1077 : do {
1078 warn "$0: Unknown escape in paragraph $. of $ARGV: ``$&''\n";
1079 "E<$1>";
1080 }
1081 }
1082 }egx if $ready_to_print;
1083}
1084
1085sub internal_lrefs {
1086 local($_) = shift;
1087 local $trailing_and = s/and\s+$// ? "and " : "";
1088
1089 s{L</([^>]+)>}{$1}g;
1090 my(@items) = split( /(?:,?\s+(?:and\s+)?)/ );
1091 my $retstr = "the ";
1092 my $i;
1093 for ($i = 0; $i <= $#items; $i++) {
1094 $retstr .= "C<$items[$i]>";
1095 $retstr .= ", " if @items > 2 && $i != $#items;
1096 $retstr .= " and " if $i+2 == @items;
1097 }
1098
1099 $retstr .= " entr" . ( @items > 1 ? "ies" : "y" )
1100 . " elsewhere in this document";
1101 # terminal space to avoid words running together (pattern used
1102 # strips terminal spaces)
1103 $retstr .= " " if length $trailing_and;
1104 $retstr .= $trailing_and;
1105
1106 return $retstr;
1107
1108}
1109
1110BEGIN {
1111%HTML_Escapes = (
1112 'amp' => '&', # ampersand
1113 'lt' => '<', # left chevron, less-than
1114 'gt' => '>', # right chevron, greater-than
1115 'quot' => '"', # double quote
1116
1117 "Aacute" => "A\\*'", # capital A, acute accent
1118 "aacute" => "a\\*'", # small a, acute accent
1119 "Acirc" => "A\\*^", # capital A, circumflex accent
1120 "acirc" => "a\\*^", # small a, circumflex accent
1121 "AElig" => '\*(AE', # capital AE diphthong (ligature)
1122 "aelig" => '\*(ae', # small ae diphthong (ligature)
1123 "Agrave" => "A\\*`", # capital A, grave accent
1124 "agrave" => "A\\*`", # small a, grave accent
1125 "Aring" => 'A\\*o', # capital A, ring
1126 "aring" => 'a\\*o', # small a, ring
1127 "Atilde" => 'A\\*~', # capital A, tilde
1128 "atilde" => 'a\\*~', # small a, tilde
1129 "Auml" => 'A\\*:', # capital A, dieresis or umlaut mark
1130 "auml" => 'a\\*:', # small a, dieresis or umlaut mark
1131 "Ccedil" => 'C\\*,', # capital C, cedilla
1132 "ccedil" => 'c\\*,', # small c, cedilla
1133 "Eacute" => "E\\*'", # capital E, acute accent
1134 "eacute" => "e\\*'", # small e, acute accent
1135 "Ecirc" => "E\\*^", # capital E, circumflex accent
1136 "ecirc" => "e\\*^", # small e, circumflex accent
1137 "Egrave" => "E\\*`", # capital E, grave accent
1138 "egrave" => "e\\*`", # small e, grave accent
1139 "ETH" => '\\*(D-', # capital Eth, Icelandic
1140 "eth" => '\\*(d-', # small eth, Icelandic
1141 "Euml" => "E\\*:", # capital E, dieresis or umlaut mark
1142 "euml" => "e\\*:", # small e, dieresis or umlaut mark
1143 "Iacute" => "I\\*'", # capital I, acute accent
1144 "iacute" => "i\\*'", # small i, acute accent
1145 "Icirc" => "I\\*^", # capital I, circumflex accent
1146 "icirc" => "i\\*^", # small i, circumflex accent
1147 "Igrave" => "I\\*`", # capital I, grave accent
1148 "igrave" => "i\\*`", # small i, grave accent
1149 "Iuml" => "I\\*:", # capital I, dieresis or umlaut mark
1150 "iuml" => "i\\*:", # small i, dieresis or umlaut mark
1151 "Ntilde" => 'N\*~', # capital N, tilde
1152 "ntilde" => 'n\*~', # small n, tilde
1153 "Oacute" => "O\\*'", # capital O, acute accent
1154 "oacute" => "o\\*'", # small o, acute accent
1155 "Ocirc" => "O\\*^", # capital O, circumflex accent
1156 "ocirc" => "o\\*^", # small o, circumflex accent
1157 "Ograve" => "O\\*`", # capital O, grave accent
1158 "ograve" => "o\\*`", # small o, grave accent
1159 "Oslash" => "O\\*/", # capital O, slash
1160 "oslash" => "o\\*/", # small o, slash
1161 "Otilde" => "O\\*~", # capital O, tilde
1162 "otilde" => "o\\*~", # small o, tilde
1163 "Ouml" => "O\\*:", # capital O, dieresis or umlaut mark
1164 "ouml" => "o\\*:", # small o, dieresis or umlaut mark
1165 "szlig" => '\*8', # small sharp s, German (sz ligature)
1166 "THORN" => '\\*(Th', # capital THORN, Icelandic
1167 "thorn" => '\\*(th',, # small thorn, Icelandic
1168 "Uacute" => "U\\*'", # capital U, acute accent
1169 "uacute" => "u\\*'", # small u, acute accent
1170 "Ucirc" => "U\\*^", # capital U, circumflex accent
1171 "ucirc" => "u\\*^", # small u, circumflex accent
1172 "Ugrave" => "U\\*`", # capital U, grave accent
1173 "ugrave" => "u\\*`", # small u, grave accent
1174 "Uuml" => "U\\*:", # capital U, dieresis or umlaut mark
1175 "uuml" => "u\\*:", # small u, dieresis or umlaut mark
1176 "Yacute" => "Y\\*'", # capital Y, acute accent
1177 "yacute" => "y\\*'", # small y, acute accent
1178 "yuml" => "y\\*:", # small y, dieresis or umlaut mark
1179);
1180}
1181
diff --git a/src/lib/libcrypto/util/selftest.pl b/src/lib/libcrypto/util/selftest.pl
new file mode 100644
index 0000000000..91e962a312
--- /dev/null
+++ b/src/lib/libcrypto/util/selftest.pl
@@ -0,0 +1,174 @@
1#!/usr/local/bin/perl -w
2#
3# Run the test suite and generate a report
4#
5
6if (! -f "Configure") {
7 print "Please run perl util/selftest.pl in the OpenSSL directory.\n";
8 exit 1;
9}
10
11my $report="testlog";
12my $os="??";
13my $version="??";
14my $platform0="??";
15my $platform="??";
16my $options="??";
17my $last="??";
18my $ok=0;
19my $cc="cc";
20my $cversion="??";
21my $sep="-----------------------------------------------------------------------------\n";
22
23open(OUT,">$report") or die;
24
25print OUT "OpenSSL self-test report:\n\n";
26
27$uname=`uname -a`;
28$uname="??" if $uname eq "";
29
30$c=`sh config -t`;
31foreach $_ (split("\n",$c)) {
32 $os=$1 if (/Operating system: (.*)$/);
33 $platform0=$1 if (/Configuring for (.*)$/);
34}
35
36system "sh config" if (! -f "Makefile.ssl");
37
38if (open(IN,"<Makefile.ssl")) {
39 while (<IN>) {
40 $version=$1 if (/^VERSION=(.*)$/);
41 $platform=$1 if (/^PLATFORM=(.*)$/);
42 $options=$1 if (/^OPTIONS=(.*)$/);
43 $cc=$1 if (/^CC= *(.*)$/);
44 }
45 close(IN);
46} else {
47 print OUT "Error running config!\n";
48}
49
50$cversion=`$cc -v 2>&1`;
51$cversion=`$cc -V 2>&1` if $cversion =~ "usage";
52$cversion=`$cc --version` if $cversion eq "";
53$cversion =~ s/Reading specs.*\n//;
54$cversion =~ s/usage.*\n//;
55chomp $cversion;
56
57if (open(IN,"<CHANGES")) {
58 while(<IN>) {
59 if (/\*\) (.{0,55})/) {
60 $last=$1;
61 last;
62 }
63 }
64 close(IN);
65}
66
67print OUT "OpenSSL version: $version\n";
68print OUT "Last change: $last...\n";
69print OUT "Options: $options\n" if $options ne "";
70print OUT "OS (uname): $uname";
71print OUT "OS (config): $os\n";
72print OUT "Target (default): $platform0\n";
73print OUT "Target: $platform\n";
74print OUT "Compiler: $cversion\n";
75print OUT "\n";
76
77print "Checking compiler...\n";
78if (open(TEST,">cctest.c")) {
79 print TEST "#include <stdio.h>\nmain(){printf(\"Hello world\\n\");}\n";
80 close(TEST);
81 system("$cc -o cctest cctest.c");
82 if (`./cctest` !~ /Hello world/) {
83 print OUT "Compiler doesn't work.\n";
84 goto err;
85 }
86} else {
87 print OUT "Can't create cctest.c\n";
88}
89if (open(TEST,">cctest.c")) {
90 print TEST "#include <openssl/opensslv.h>\nmain(){printf(OPENSSL_VERSION_TEXT);}\n";
91 close(TEST);
92 system("$cc -o cctest -Iinclude cctest.c");
93 $cctest = `./cctest`;
94 if ($cctest !~ /OpenSSL $version/) {
95 if ($cctest =~ /OpenSSL/) {
96 print OUT "#include uses headers from different OpenSSL version!\n";
97 } else {
98 print OUT "Can't compile test program!\n";
99 }
100 goto err;
101 }
102} else {
103 print OUT "Can't create cctest.c\n";
104}
105
106print "Running make...\n";
107if (system("make 2>&1 | tee make.log") > 255) {
108
109 print OUT "make failed!\n";
110 if (open(IN,"<make.log")) {
111 print OUT $sep;
112 while (<IN>) {
113 print OUT;
114 }
115 close(IN);
116 print OUT $sep;
117 } else {
118 print OUT "make.log not found!\n";
119 }
120 goto err;
121}
122
123$_=$options;
124s/no-asm//;
125if (/no-/)
126{
127 print OUT "Test skipped.\n";
128 goto err;
129}
130
131print "Running make test...\n";
132if (system("make test 2>&1 | tee make.log") > 255)
133 {
134 print OUT "make test failed!\n";
135} else {
136 $ok=1;
137}
138
139if ($ok and open(IN,"<make.log")) {
140 while (<IN>) {
141 $ok=2 if /^platform: $platform/;
142 }
143 close(IN);
144}
145
146if ($ok != 2) {
147 print OUT "Failure!\n";
148 if (open(IN,"<make.log")) {
149 print OUT $sep;
150 while (<IN>) {
151 print OUT;
152 }
153 close(IN);
154 print OUT $sep;
155 } else {
156 print OUT "make.log not found!\n";
157 }
158} else {
159 print OUT "Test passed.\n";
160}
161err:
162close(OUT);
163
164print "\n";
165open(IN,"<$report") or die;
166while (<IN>) {
167 if (/$sep/) {
168 print "[...]\n";
169 last;
170 }
171 print;
172}
173print "\nTest report in file $report\n";
174
diff --git a/src/lib/libcrypto/x509v3/tabtest.c b/src/lib/libcrypto/x509v3/tabtest.c
new file mode 100644
index 0000000000..dad0d38dd5
--- /dev/null
+++ b/src/lib/libcrypto/x509v3/tabtest.c
@@ -0,0 +1,88 @@
1/* tabtest.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 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 * licensing@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/* Simple program to check the ext_dat.h is correct and print out
60 * problems if it is not.
61 */
62
63#include <stdio.h>
64
65#include <openssl/x509v3.h>
66
67#include "ext_dat.h"
68
69main()
70{
71 int i, prev = -1, bad = 0;
72 X509V3_EXT_METHOD **tmp;
73 i = sizeof(standard_exts) / sizeof(X509V3_EXT_METHOD *);
74 if(i != STANDARD_EXTENSION_COUNT)
75 fprintf(stderr, "Extension number invalid expecting %d\n", i);
76 tmp = standard_exts;
77 for(i = 0; i < STANDARD_EXTENSION_COUNT; i++, tmp++) {
78 if((*tmp)->ext_nid < prev) bad = 1;
79 prev = (*tmp)->ext_nid;
80
81 }
82 if(bad) {
83 tmp = standard_exts;
84 fprintf(stderr, "Extensions out of order!\n");
85 for(i = 0; i < STANDARD_EXTENSION_COUNT; i++, tmp++)
86 printf("%d : %s\n", (*tmp)->ext_nid, OBJ_nid2sn((*tmp)->ext_nid));
87 } else fprintf(stderr, "Order OK\n");
88}
diff --git a/src/lib/libcrypto/x509v3/v3conf.c b/src/lib/libcrypto/x509v3/v3conf.c
new file mode 100644
index 0000000000..21cf746f45
--- /dev/null
+++ b/src/lib/libcrypto/x509v3/v3conf.c
@@ -0,0 +1,128 @@
1/* v3conf.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 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 * licensing@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
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/asn1.h>
63#include <openssl/asn1_mac.h>
64#include <openssl/conf.h>
65#include <openssl/x509.h>
66#include <openssl/x509v3.h>
67
68/* Test application to add extensions from a config file */
69
70int main(int argc, char **argv)
71{
72 LHASH *conf;
73 X509 *cert;
74 FILE *inf;
75 char *conf_file;
76 int i;
77 int count;
78 X509_EXTENSION *ext;
79 X509V3_add_standard_extensions();
80 ERR_load_crypto_strings();
81 if(!argv[1]) {
82 fprintf(stderr, "Usage: v3conf cert.pem [file.cnf]\n");
83 exit(1);
84 }
85 conf_file = argv[2];
86 if(!conf_file) conf_file = "test.cnf";
87 conf = CONF_load(NULL, "test.cnf", NULL);
88 if(!conf) {
89 fprintf(stderr, "Error opening Config file %s\n", conf_file);
90 ERR_print_errors_fp(stderr);
91 exit(1);
92 }
93
94 inf = fopen(argv[1], "r");
95 if(!inf) {
96 fprintf(stderr, "Can't open certificate file %s\n", argv[1]);
97 exit(1);
98 }
99 cert = PEM_read_X509(inf, NULL, NULL);
100 if(!cert) {
101 fprintf(stderr, "Error reading certificate file %s\n", argv[1]);
102 exit(1);
103 }
104 fclose(inf);
105
106 sk_pop_free(cert->cert_info->extensions, X509_EXTENSION_free);
107 cert->cert_info->extensions = NULL;
108
109 if(!X509V3_EXT_add_conf(conf, NULL, "test_section", cert)) {
110 fprintf(stderr, "Error adding extensions\n");
111 ERR_print_errors_fp(stderr);
112 exit(1);
113 }
114
115 count = X509_get_ext_count(cert);
116 printf("%d extensions\n", count);
117 for(i = 0; i < count; i++) {
118 ext = X509_get_ext(cert, i);
119 printf("%s", OBJ_nid2ln(OBJ_obj2nid(ext->object)));
120 if(ext->critical) printf(",critical:\n");
121 else printf(":\n");
122 X509V3_EXT_print_fp(stdout, ext, 0);
123 printf("\n");
124
125 }
126 return 0;
127}
128
diff --git a/src/lib/libcrypto/x509v3/v3prin.c b/src/lib/libcrypto/x509v3/v3prin.c
new file mode 100644
index 0000000000..ee798859f0
--- /dev/null
+++ b/src/lib/libcrypto/x509v3/v3prin.c
@@ -0,0 +1,101 @@
1/* v3prin.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 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 * licensing@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
60
61#include <stdio.h>
62#include "cryptlib.h"
63#include <openssl/asn1.h>
64#include <openssl/asn1_mac.h>
65#include <openssl/conf.h>
66#include <openssl/x509.h>
67#include <openssl/x509v3.h>
68
69int main(int argc, char **argv)
70{
71 X509 *cert;
72 FILE *inf;
73 int i, count;
74 X509_EXTENSION *ext;
75 X509V3_add_standard_extensions();
76 ERR_load_crypto_strings();
77 if(!argv[1]) {
78 fprintf(stderr, "Usage v3prin cert.pem\n");
79 exit(1);
80 }
81 if(!(inf = fopen(argv[1], "r"))) {
82 fprintf(stderr, "Can't open %s\n", argv[1]);
83 exit(1);
84 }
85 if(!(cert = PEM_read_X509(inf, NULL, NULL))) {
86 fprintf(stderr, "Can't read certificate %s\n", argv[1]);
87 ERR_print_errors_fp(stderr);
88 exit(1);
89 }
90 fclose(inf);
91 count = X509_get_ext_count(cert);
92 printf("%d extensions\n", count);
93 for(i = 0; i < count; i++) {
94 ext = X509_get_ext(cert, i);
95 printf("%s\n", OBJ_nid2ln(OBJ_obj2nid(ext->object)));
96 if(!X509V3_EXT_print_fp(stdout, ext, 0, 0)) ERR_print_errors_fp(stderr);
97 printf("\n");
98
99 }
100 return 0;
101}