diff options
author | djm <> | 2012-10-13 21:30:34 +0000 |
---|---|---|
committer | djm <> | 2012-10-13 21:30:34 +0000 |
commit | 89d6af5bf262e3e549c575ee56ad8c11b03f8c35 (patch) | |
tree | cd107d258df89184dd5e2f254edf999531ff9d35 | |
parent | 93723b50b639d8dc717bc1bf463fd46e1b321239 (diff) | |
download | openbsd-89d6af5bf262e3e549c575ee56ad8c11b03f8c35.tar.gz openbsd-89d6af5bf262e3e549c575ee56ad8c11b03f8c35.tar.bz2 openbsd-89d6af5bf262e3e549c575ee56ad8c11b03f8c35.zip |
import files that CVS missed; sigh
-rw-r--r-- | src/lib/libcrypto/bn/bn_x931p.c | 272 | ||||
-rw-r--r-- | src/lib/libcrypto/buffer/buf_str.c | 119 | ||||
-rw-r--r-- | src/lib/libcrypto/mdc2/mdc2_one.c | 76 | ||||
-rw-r--r-- | src/lib/libcrypto/mdc2/mdc2dgst.c | 200 | ||||
-rw-r--r-- | src/lib/libcrypto/o_init.c | 82 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/bn/bn_x931p.c | 272 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/buffer/buf_str.c | 119 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/mdc2/mdc2_one.c | 76 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/mdc2/mdc2dgst.c | 200 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/o_init.c | 82 |
10 files changed, 1498 insertions, 0 deletions
diff --git a/src/lib/libcrypto/bn/bn_x931p.c b/src/lib/libcrypto/bn/bn_x931p.c new file mode 100644 index 0000000000..04c5c874ec --- /dev/null +++ b/src/lib/libcrypto/bn/bn_x931p.c | |||
@@ -0,0 +1,272 @@ | |||
1 | /* bn_x931p.c */ | ||
2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | ||
3 | * project 2005. | ||
4 | */ | ||
5 | /* ==================================================================== | ||
6 | * Copyright (c) 2005 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/bn.h> | ||
61 | |||
62 | /* X9.31 routines for prime derivation */ | ||
63 | |||
64 | /* X9.31 prime derivation. This is used to generate the primes pi | ||
65 | * (p1, p2, q1, q2) from a parameter Xpi by checking successive odd | ||
66 | * integers. | ||
67 | */ | ||
68 | |||
69 | static int bn_x931_derive_pi(BIGNUM *pi, const BIGNUM *Xpi, BN_CTX *ctx, | ||
70 | BN_GENCB *cb) | ||
71 | { | ||
72 | int i = 0; | ||
73 | if (!BN_copy(pi, Xpi)) | ||
74 | return 0; | ||
75 | if (!BN_is_odd(pi) && !BN_add_word(pi, 1)) | ||
76 | return 0; | ||
77 | for(;;) | ||
78 | { | ||
79 | i++; | ||
80 | BN_GENCB_call(cb, 0, i); | ||
81 | /* NB 27 MR is specificed in X9.31 */ | ||
82 | if (BN_is_prime_fasttest_ex(pi, 27, ctx, 1, cb)) | ||
83 | break; | ||
84 | if (!BN_add_word(pi, 2)) | ||
85 | return 0; | ||
86 | } | ||
87 | BN_GENCB_call(cb, 2, i); | ||
88 | return 1; | ||
89 | } | ||
90 | |||
91 | /* This is the main X9.31 prime derivation function. From parameters | ||
92 | * Xp1, Xp2 and Xp derive the prime p. If the parameters p1 or p2 are | ||
93 | * not NULL they will be returned too: this is needed for testing. | ||
94 | */ | ||
95 | |||
96 | int BN_X931_derive_prime_ex(BIGNUM *p, BIGNUM *p1, BIGNUM *p2, | ||
97 | const BIGNUM *Xp, const BIGNUM *Xp1, const BIGNUM *Xp2, | ||
98 | const BIGNUM *e, BN_CTX *ctx, BN_GENCB *cb) | ||
99 | { | ||
100 | int ret = 0; | ||
101 | |||
102 | BIGNUM *t, *p1p2, *pm1; | ||
103 | |||
104 | /* Only even e supported */ | ||
105 | if (!BN_is_odd(e)) | ||
106 | return 0; | ||
107 | |||
108 | BN_CTX_start(ctx); | ||
109 | if (!p1) | ||
110 | p1 = BN_CTX_get(ctx); | ||
111 | |||
112 | if (!p2) | ||
113 | p2 = BN_CTX_get(ctx); | ||
114 | |||
115 | t = BN_CTX_get(ctx); | ||
116 | |||
117 | p1p2 = BN_CTX_get(ctx); | ||
118 | |||
119 | pm1 = BN_CTX_get(ctx); | ||
120 | |||
121 | if (!bn_x931_derive_pi(p1, Xp1, ctx, cb)) | ||
122 | goto err; | ||
123 | |||
124 | if (!bn_x931_derive_pi(p2, Xp2, ctx, cb)) | ||
125 | goto err; | ||
126 | |||
127 | if (!BN_mul(p1p2, p1, p2, ctx)) | ||
128 | goto err; | ||
129 | |||
130 | /* First set p to value of Rp */ | ||
131 | |||
132 | if (!BN_mod_inverse(p, p2, p1, ctx)) | ||
133 | goto err; | ||
134 | |||
135 | if (!BN_mul(p, p, p2, ctx)) | ||
136 | goto err; | ||
137 | |||
138 | if (!BN_mod_inverse(t, p1, p2, ctx)) | ||
139 | goto err; | ||
140 | |||
141 | if (!BN_mul(t, t, p1, ctx)) | ||
142 | goto err; | ||
143 | |||
144 | if (!BN_sub(p, p, t)) | ||
145 | goto err; | ||
146 | |||
147 | if (p->neg && !BN_add(p, p, p1p2)) | ||
148 | goto err; | ||
149 | |||
150 | /* p now equals Rp */ | ||
151 | |||
152 | if (!BN_mod_sub(p, p, Xp, p1p2, ctx)) | ||
153 | goto err; | ||
154 | |||
155 | if (!BN_add(p, p, Xp)) | ||
156 | goto err; | ||
157 | |||
158 | /* p now equals Yp0 */ | ||
159 | |||
160 | for (;;) | ||
161 | { | ||
162 | int i = 1; | ||
163 | BN_GENCB_call(cb, 0, i++); | ||
164 | if (!BN_copy(pm1, p)) | ||
165 | goto err; | ||
166 | if (!BN_sub_word(pm1, 1)) | ||
167 | goto err; | ||
168 | if (!BN_gcd(t, pm1, e, ctx)) | ||
169 | goto err; | ||
170 | if (BN_is_one(t) | ||
171 | /* X9.31 specifies 8 MR and 1 Lucas test or any prime test | ||
172 | * offering similar or better guarantees 50 MR is considerably | ||
173 | * better. | ||
174 | */ | ||
175 | && BN_is_prime_fasttest_ex(p, 50, ctx, 1, cb)) | ||
176 | break; | ||
177 | if (!BN_add(p, p, p1p2)) | ||
178 | goto err; | ||
179 | } | ||
180 | |||
181 | BN_GENCB_call(cb, 3, 0); | ||
182 | |||
183 | ret = 1; | ||
184 | |||
185 | err: | ||
186 | |||
187 | BN_CTX_end(ctx); | ||
188 | |||
189 | return ret; | ||
190 | } | ||
191 | |||
192 | /* Generate pair of paramters Xp, Xq for X9.31 prime generation. | ||
193 | * Note: nbits paramter is sum of number of bits in both. | ||
194 | */ | ||
195 | |||
196 | int BN_X931_generate_Xpq(BIGNUM *Xp, BIGNUM *Xq, int nbits, BN_CTX *ctx) | ||
197 | { | ||
198 | BIGNUM *t; | ||
199 | int i; | ||
200 | /* Number of bits for each prime is of the form | ||
201 | * 512+128s for s = 0, 1, ... | ||
202 | */ | ||
203 | if ((nbits < 1024) || (nbits & 0xff)) | ||
204 | return 0; | ||
205 | nbits >>= 1; | ||
206 | /* The random value Xp must be between sqrt(2) * 2^(nbits-1) and | ||
207 | * 2^nbits - 1. By setting the top two bits we ensure that the lower | ||
208 | * bound is exceeded. | ||
209 | */ | ||
210 | if (!BN_rand(Xp, nbits, 1, 0)) | ||
211 | return 0; | ||
212 | |||
213 | BN_CTX_start(ctx); | ||
214 | t = BN_CTX_get(ctx); | ||
215 | |||
216 | for (i = 0; i < 1000; i++) | ||
217 | { | ||
218 | if (!BN_rand(Xq, nbits, 1, 0)) | ||
219 | return 0; | ||
220 | /* Check that |Xp - Xq| > 2^(nbits - 100) */ | ||
221 | BN_sub(t, Xp, Xq); | ||
222 | if (BN_num_bits(t) > (nbits - 100)) | ||
223 | break; | ||
224 | } | ||
225 | |||
226 | BN_CTX_end(ctx); | ||
227 | |||
228 | if (i < 1000) | ||
229 | return 1; | ||
230 | |||
231 | return 0; | ||
232 | |||
233 | } | ||
234 | |||
235 | /* Generate primes using X9.31 algorithm. Of the values p, p1, p2, Xp1 | ||
236 | * and Xp2 only 'p' needs to be non-NULL. If any of the others are not NULL | ||
237 | * the relevant parameter will be stored in it. | ||
238 | * | ||
239 | * Due to the fact that |Xp - Xq| > 2^(nbits - 100) must be satisfied Xp and Xq | ||
240 | * are generated using the previous function and supplied as input. | ||
241 | */ | ||
242 | |||
243 | int BN_X931_generate_prime_ex(BIGNUM *p, BIGNUM *p1, BIGNUM *p2, | ||
244 | BIGNUM *Xp1, BIGNUM *Xp2, | ||
245 | const BIGNUM *Xp, | ||
246 | const BIGNUM *e, BN_CTX *ctx, | ||
247 | BN_GENCB *cb) | ||
248 | { | ||
249 | int ret = 0; | ||
250 | |||
251 | BN_CTX_start(ctx); | ||
252 | if (!Xp1) | ||
253 | Xp1 = BN_CTX_get(ctx); | ||
254 | if (!Xp2) | ||
255 | Xp2 = BN_CTX_get(ctx); | ||
256 | |||
257 | if (!BN_rand(Xp1, 101, 0, 0)) | ||
258 | goto error; | ||
259 | if (!BN_rand(Xp2, 101, 0, 0)) | ||
260 | goto error; | ||
261 | if (!BN_X931_derive_prime_ex(p, p1, p2, Xp, Xp1, Xp2, e, ctx, cb)) | ||
262 | goto error; | ||
263 | |||
264 | ret = 1; | ||
265 | |||
266 | error: | ||
267 | BN_CTX_end(ctx); | ||
268 | |||
269 | return ret; | ||
270 | |||
271 | } | ||
272 | |||
diff --git a/src/lib/libcrypto/buffer/buf_str.c b/src/lib/libcrypto/buffer/buf_str.c new file mode 100644 index 0000000000..151f5ea971 --- /dev/null +++ b/src/lib/libcrypto/buffer/buf_str.c | |||
@@ -0,0 +1,119 @@ | |||
1 | /* crypto/buffer/buffer.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/buffer.h> | ||
62 | |||
63 | char *BUF_strdup(const char *str) | ||
64 | { | ||
65 | if (str == NULL) return(NULL); | ||
66 | return BUF_strndup(str, strlen(str)); | ||
67 | } | ||
68 | |||
69 | char *BUF_strndup(const char *str, size_t siz) | ||
70 | { | ||
71 | char *ret; | ||
72 | |||
73 | if (str == NULL) return(NULL); | ||
74 | |||
75 | ret=OPENSSL_malloc(siz+1); | ||
76 | if (ret == NULL) | ||
77 | { | ||
78 | BUFerr(BUF_F_BUF_STRNDUP,ERR_R_MALLOC_FAILURE); | ||
79 | return(NULL); | ||
80 | } | ||
81 | BUF_strlcpy(ret,str,siz+1); | ||
82 | return(ret); | ||
83 | } | ||
84 | |||
85 | void *BUF_memdup(const void *data, size_t siz) | ||
86 | { | ||
87 | void *ret; | ||
88 | |||
89 | if (data == NULL) return(NULL); | ||
90 | |||
91 | ret=OPENSSL_malloc(siz); | ||
92 | if (ret == NULL) | ||
93 | { | ||
94 | BUFerr(BUF_F_BUF_MEMDUP,ERR_R_MALLOC_FAILURE); | ||
95 | return(NULL); | ||
96 | } | ||
97 | return memcpy(ret, data, siz); | ||
98 | } | ||
99 | |||
100 | size_t BUF_strlcpy(char *dst, const char *src, size_t size) | ||
101 | { | ||
102 | size_t l = 0; | ||
103 | for(; size > 1 && *src; size--) | ||
104 | { | ||
105 | *dst++ = *src++; | ||
106 | l++; | ||
107 | } | ||
108 | if (size) | ||
109 | *dst = '\0'; | ||
110 | return l + strlen(src); | ||
111 | } | ||
112 | |||
113 | size_t BUF_strlcat(char *dst, const char *src, size_t size) | ||
114 | { | ||
115 | size_t l = 0; | ||
116 | for(; size > 0 && *dst; size--, dst++) | ||
117 | l++; | ||
118 | return l + BUF_strlcpy(dst, src, size); | ||
119 | } | ||
diff --git a/src/lib/libcrypto/mdc2/mdc2_one.c b/src/lib/libcrypto/mdc2/mdc2_one.c new file mode 100644 index 0000000000..72647f67ed --- /dev/null +++ b/src/lib/libcrypto/mdc2/mdc2_one.c | |||
@@ -0,0 +1,76 @@ | |||
1 | /* crypto/mdc2/mdc2_one.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/mdc2.h> | ||
62 | |||
63 | unsigned char *MDC2(const unsigned char *d, size_t n, unsigned char *md) | ||
64 | { | ||
65 | MDC2_CTX c; | ||
66 | static unsigned char m[MDC2_DIGEST_LENGTH]; | ||
67 | |||
68 | if (md == NULL) md=m; | ||
69 | if (!MDC2_Init(&c)) | ||
70 | return NULL; | ||
71 | MDC2_Update(&c,d,n); | ||
72 | MDC2_Final(md,&c); | ||
73 | OPENSSL_cleanse(&c,sizeof(c)); /* security consideration */ | ||
74 | return(md); | ||
75 | } | ||
76 | |||
diff --git a/src/lib/libcrypto/mdc2/mdc2dgst.c b/src/lib/libcrypto/mdc2/mdc2dgst.c new file mode 100644 index 0000000000..b74bb1a759 --- /dev/null +++ b/src/lib/libcrypto/mdc2/mdc2dgst.c | |||
@@ -0,0 +1,200 @@ | |||
1 | /* crypto/mdc2/mdc2dgst.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 <string.h> | ||
62 | #include <openssl/des.h> | ||
63 | #include <openssl/mdc2.h> | ||
64 | #include <openssl/crypto.h> | ||
65 | |||
66 | #undef c2l | ||
67 | #define c2l(c,l) (l =((DES_LONG)(*((c)++))) , \ | ||
68 | l|=((DES_LONG)(*((c)++)))<< 8L, \ | ||
69 | l|=((DES_LONG)(*((c)++)))<<16L, \ | ||
70 | l|=((DES_LONG)(*((c)++)))<<24L) | ||
71 | |||
72 | #undef l2c | ||
73 | #define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \ | ||
74 | *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \ | ||
75 | *((c)++)=(unsigned char)(((l)>>16L)&0xff), \ | ||
76 | *((c)++)=(unsigned char)(((l)>>24L)&0xff)) | ||
77 | |||
78 | static void mdc2_body(MDC2_CTX *c, const unsigned char *in, size_t len); | ||
79 | fips_md_init(MDC2) | ||
80 | { | ||
81 | c->num=0; | ||
82 | c->pad_type=1; | ||
83 | memset(&(c->h[0]),0x52,MDC2_BLOCK); | ||
84 | memset(&(c->hh[0]),0x25,MDC2_BLOCK); | ||
85 | return 1; | ||
86 | } | ||
87 | |||
88 | int MDC2_Update(MDC2_CTX *c, const unsigned char *in, size_t len) | ||
89 | { | ||
90 | size_t i,j; | ||
91 | |||
92 | i=c->num; | ||
93 | if (i != 0) | ||
94 | { | ||
95 | if (i+len < MDC2_BLOCK) | ||
96 | { | ||
97 | /* partial block */ | ||
98 | memcpy(&(c->data[i]),in,len); | ||
99 | c->num+=(int)len; | ||
100 | return 1; | ||
101 | } | ||
102 | else | ||
103 | { | ||
104 | /* filled one */ | ||
105 | j=MDC2_BLOCK-i; | ||
106 | memcpy(&(c->data[i]),in,j); | ||
107 | len-=j; | ||
108 | in+=j; | ||
109 | c->num=0; | ||
110 | mdc2_body(c,&(c->data[0]),MDC2_BLOCK); | ||
111 | } | ||
112 | } | ||
113 | i=len&~((size_t)MDC2_BLOCK-1); | ||
114 | if (i > 0) mdc2_body(c,in,i); | ||
115 | j=len-i; | ||
116 | if (j > 0) | ||
117 | { | ||
118 | memcpy(&(c->data[0]),&(in[i]),j); | ||
119 | c->num=(int)j; | ||
120 | } | ||
121 | return 1; | ||
122 | } | ||
123 | |||
124 | static void mdc2_body(MDC2_CTX *c, const unsigned char *in, size_t len) | ||
125 | { | ||
126 | register DES_LONG tin0,tin1; | ||
127 | register DES_LONG ttin0,ttin1; | ||
128 | DES_LONG d[2],dd[2]; | ||
129 | DES_key_schedule k; | ||
130 | unsigned char *p; | ||
131 | size_t i; | ||
132 | |||
133 | for (i=0; i<len; i+=8) | ||
134 | { | ||
135 | c2l(in,tin0); d[0]=dd[0]=tin0; | ||
136 | c2l(in,tin1); d[1]=dd[1]=tin1; | ||
137 | c->h[0]=(c->h[0]&0x9f)|0x40; | ||
138 | c->hh[0]=(c->hh[0]&0x9f)|0x20; | ||
139 | |||
140 | DES_set_odd_parity(&c->h); | ||
141 | DES_set_key_unchecked(&c->h,&k); | ||
142 | DES_encrypt1(d,&k,1); | ||
143 | |||
144 | DES_set_odd_parity(&c->hh); | ||
145 | DES_set_key_unchecked(&c->hh,&k); | ||
146 | DES_encrypt1(dd,&k,1); | ||
147 | |||
148 | ttin0=tin0^dd[0]; | ||
149 | ttin1=tin1^dd[1]; | ||
150 | tin0^=d[0]; | ||
151 | tin1^=d[1]; | ||
152 | |||
153 | p=c->h; | ||
154 | l2c(tin0,p); | ||
155 | l2c(ttin1,p); | ||
156 | p=c->hh; | ||
157 | l2c(ttin0,p); | ||
158 | l2c(tin1,p); | ||
159 | } | ||
160 | } | ||
161 | |||
162 | int MDC2_Final(unsigned char *md, MDC2_CTX *c) | ||
163 | { | ||
164 | unsigned int i; | ||
165 | int j; | ||
166 | |||
167 | i=c->num; | ||
168 | j=c->pad_type; | ||
169 | if ((i > 0) || (j == 2)) | ||
170 | { | ||
171 | if (j == 2) | ||
172 | c->data[i++]=0x80; | ||
173 | memset(&(c->data[i]),0,MDC2_BLOCK-i); | ||
174 | mdc2_body(c,c->data,MDC2_BLOCK); | ||
175 | } | ||
176 | memcpy(md,(char *)c->h,MDC2_BLOCK); | ||
177 | memcpy(&(md[MDC2_BLOCK]),(char *)c->hh,MDC2_BLOCK); | ||
178 | return 1; | ||
179 | } | ||
180 | |||
181 | #undef TEST | ||
182 | |||
183 | #ifdef TEST | ||
184 | main() | ||
185 | { | ||
186 | unsigned char md[MDC2_DIGEST_LENGTH]; | ||
187 | int i; | ||
188 | MDC2_CTX c; | ||
189 | static char *text="Now is the time for all "; | ||
190 | |||
191 | MDC2_Init(&c); | ||
192 | MDC2_Update(&c,text,strlen(text)); | ||
193 | MDC2_Final(&(md[0]),&c); | ||
194 | |||
195 | for (i=0; i<MDC2_DIGEST_LENGTH; i++) | ||
196 | printf("%02X",md[i]); | ||
197 | printf("\n"); | ||
198 | } | ||
199 | |||
200 | #endif | ||
diff --git a/src/lib/libcrypto/o_init.c b/src/lib/libcrypto/o_init.c new file mode 100644 index 0000000000..db4cdc443b --- /dev/null +++ b/src/lib/libcrypto/o_init.c | |||
@@ -0,0 +1,82 @@ | |||
1 | /* o_init.c */ | ||
2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | ||
3 | * project. | ||
4 | */ | ||
5 | /* ==================================================================== | ||
6 | * Copyright (c) 2011 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 | */ | ||
54 | |||
55 | #include <e_os.h> | ||
56 | #include <openssl/err.h> | ||
57 | #ifdef OPENSSL_FIPS | ||
58 | #include <openssl/fips.h> | ||
59 | #include <openssl/rand.h> | ||
60 | #endif | ||
61 | |||
62 | /* Perform any essential OpenSSL initialization operations. | ||
63 | * Currently only sets FIPS callbacks | ||
64 | */ | ||
65 | |||
66 | void OPENSSL_init(void) | ||
67 | { | ||
68 | static int done = 0; | ||
69 | if (done) | ||
70 | return; | ||
71 | done = 1; | ||
72 | #ifdef OPENSSL_FIPS | ||
73 | FIPS_set_locking_callbacks(CRYPTO_lock, CRYPTO_add_lock); | ||
74 | FIPS_set_error_callbacks(ERR_put_error, ERR_add_error_vdata); | ||
75 | FIPS_set_malloc_callbacks(CRYPTO_malloc, CRYPTO_free); | ||
76 | RAND_init_fips(); | ||
77 | #endif | ||
78 | #if 0 | ||
79 | fprintf(stderr, "Called OPENSSL_init\n"); | ||
80 | #endif | ||
81 | } | ||
82 | |||
diff --git a/src/lib/libssl/src/crypto/bn/bn_x931p.c b/src/lib/libssl/src/crypto/bn/bn_x931p.c new file mode 100644 index 0000000000..04c5c874ec --- /dev/null +++ b/src/lib/libssl/src/crypto/bn/bn_x931p.c | |||
@@ -0,0 +1,272 @@ | |||
1 | /* bn_x931p.c */ | ||
2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | ||
3 | * project 2005. | ||
4 | */ | ||
5 | /* ==================================================================== | ||
6 | * Copyright (c) 2005 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/bn.h> | ||
61 | |||
62 | /* X9.31 routines for prime derivation */ | ||
63 | |||
64 | /* X9.31 prime derivation. This is used to generate the primes pi | ||
65 | * (p1, p2, q1, q2) from a parameter Xpi by checking successive odd | ||
66 | * integers. | ||
67 | */ | ||
68 | |||
69 | static int bn_x931_derive_pi(BIGNUM *pi, const BIGNUM *Xpi, BN_CTX *ctx, | ||
70 | BN_GENCB *cb) | ||
71 | { | ||
72 | int i = 0; | ||
73 | if (!BN_copy(pi, Xpi)) | ||
74 | return 0; | ||
75 | if (!BN_is_odd(pi) && !BN_add_word(pi, 1)) | ||
76 | return 0; | ||
77 | for(;;) | ||
78 | { | ||
79 | i++; | ||
80 | BN_GENCB_call(cb, 0, i); | ||
81 | /* NB 27 MR is specificed in X9.31 */ | ||
82 | if (BN_is_prime_fasttest_ex(pi, 27, ctx, 1, cb)) | ||
83 | break; | ||
84 | if (!BN_add_word(pi, 2)) | ||
85 | return 0; | ||
86 | } | ||
87 | BN_GENCB_call(cb, 2, i); | ||
88 | return 1; | ||
89 | } | ||
90 | |||
91 | /* This is the main X9.31 prime derivation function. From parameters | ||
92 | * Xp1, Xp2 and Xp derive the prime p. If the parameters p1 or p2 are | ||
93 | * not NULL they will be returned too: this is needed for testing. | ||
94 | */ | ||
95 | |||
96 | int BN_X931_derive_prime_ex(BIGNUM *p, BIGNUM *p1, BIGNUM *p2, | ||
97 | const BIGNUM *Xp, const BIGNUM *Xp1, const BIGNUM *Xp2, | ||
98 | const BIGNUM *e, BN_CTX *ctx, BN_GENCB *cb) | ||
99 | { | ||
100 | int ret = 0; | ||
101 | |||
102 | BIGNUM *t, *p1p2, *pm1; | ||
103 | |||
104 | /* Only even e supported */ | ||
105 | if (!BN_is_odd(e)) | ||
106 | return 0; | ||
107 | |||
108 | BN_CTX_start(ctx); | ||
109 | if (!p1) | ||
110 | p1 = BN_CTX_get(ctx); | ||
111 | |||
112 | if (!p2) | ||
113 | p2 = BN_CTX_get(ctx); | ||
114 | |||
115 | t = BN_CTX_get(ctx); | ||
116 | |||
117 | p1p2 = BN_CTX_get(ctx); | ||
118 | |||
119 | pm1 = BN_CTX_get(ctx); | ||
120 | |||
121 | if (!bn_x931_derive_pi(p1, Xp1, ctx, cb)) | ||
122 | goto err; | ||
123 | |||
124 | if (!bn_x931_derive_pi(p2, Xp2, ctx, cb)) | ||
125 | goto err; | ||
126 | |||
127 | if (!BN_mul(p1p2, p1, p2, ctx)) | ||
128 | goto err; | ||
129 | |||
130 | /* First set p to value of Rp */ | ||
131 | |||
132 | if (!BN_mod_inverse(p, p2, p1, ctx)) | ||
133 | goto err; | ||
134 | |||
135 | if (!BN_mul(p, p, p2, ctx)) | ||
136 | goto err; | ||
137 | |||
138 | if (!BN_mod_inverse(t, p1, p2, ctx)) | ||
139 | goto err; | ||
140 | |||
141 | if (!BN_mul(t, t, p1, ctx)) | ||
142 | goto err; | ||
143 | |||
144 | if (!BN_sub(p, p, t)) | ||
145 | goto err; | ||
146 | |||
147 | if (p->neg && !BN_add(p, p, p1p2)) | ||
148 | goto err; | ||
149 | |||
150 | /* p now equals Rp */ | ||
151 | |||
152 | if (!BN_mod_sub(p, p, Xp, p1p2, ctx)) | ||
153 | goto err; | ||
154 | |||
155 | if (!BN_add(p, p, Xp)) | ||
156 | goto err; | ||
157 | |||
158 | /* p now equals Yp0 */ | ||
159 | |||
160 | for (;;) | ||
161 | { | ||
162 | int i = 1; | ||
163 | BN_GENCB_call(cb, 0, i++); | ||
164 | if (!BN_copy(pm1, p)) | ||
165 | goto err; | ||
166 | if (!BN_sub_word(pm1, 1)) | ||
167 | goto err; | ||
168 | if (!BN_gcd(t, pm1, e, ctx)) | ||
169 | goto err; | ||
170 | if (BN_is_one(t) | ||
171 | /* X9.31 specifies 8 MR and 1 Lucas test or any prime test | ||
172 | * offering similar or better guarantees 50 MR is considerably | ||
173 | * better. | ||
174 | */ | ||
175 | && BN_is_prime_fasttest_ex(p, 50, ctx, 1, cb)) | ||
176 | break; | ||
177 | if (!BN_add(p, p, p1p2)) | ||
178 | goto err; | ||
179 | } | ||
180 | |||
181 | BN_GENCB_call(cb, 3, 0); | ||
182 | |||
183 | ret = 1; | ||
184 | |||
185 | err: | ||
186 | |||
187 | BN_CTX_end(ctx); | ||
188 | |||
189 | return ret; | ||
190 | } | ||
191 | |||
192 | /* Generate pair of paramters Xp, Xq for X9.31 prime generation. | ||
193 | * Note: nbits paramter is sum of number of bits in both. | ||
194 | */ | ||
195 | |||
196 | int BN_X931_generate_Xpq(BIGNUM *Xp, BIGNUM *Xq, int nbits, BN_CTX *ctx) | ||
197 | { | ||
198 | BIGNUM *t; | ||
199 | int i; | ||
200 | /* Number of bits for each prime is of the form | ||
201 | * 512+128s for s = 0, 1, ... | ||
202 | */ | ||
203 | if ((nbits < 1024) || (nbits & 0xff)) | ||
204 | return 0; | ||
205 | nbits >>= 1; | ||
206 | /* The random value Xp must be between sqrt(2) * 2^(nbits-1) and | ||
207 | * 2^nbits - 1. By setting the top two bits we ensure that the lower | ||
208 | * bound is exceeded. | ||
209 | */ | ||
210 | if (!BN_rand(Xp, nbits, 1, 0)) | ||
211 | return 0; | ||
212 | |||
213 | BN_CTX_start(ctx); | ||
214 | t = BN_CTX_get(ctx); | ||
215 | |||
216 | for (i = 0; i < 1000; i++) | ||
217 | { | ||
218 | if (!BN_rand(Xq, nbits, 1, 0)) | ||
219 | return 0; | ||
220 | /* Check that |Xp - Xq| > 2^(nbits - 100) */ | ||
221 | BN_sub(t, Xp, Xq); | ||
222 | if (BN_num_bits(t) > (nbits - 100)) | ||
223 | break; | ||
224 | } | ||
225 | |||
226 | BN_CTX_end(ctx); | ||
227 | |||
228 | if (i < 1000) | ||
229 | return 1; | ||
230 | |||
231 | return 0; | ||
232 | |||
233 | } | ||
234 | |||
235 | /* Generate primes using X9.31 algorithm. Of the values p, p1, p2, Xp1 | ||
236 | * and Xp2 only 'p' needs to be non-NULL. If any of the others are not NULL | ||
237 | * the relevant parameter will be stored in it. | ||
238 | * | ||
239 | * Due to the fact that |Xp - Xq| > 2^(nbits - 100) must be satisfied Xp and Xq | ||
240 | * are generated using the previous function and supplied as input. | ||
241 | */ | ||
242 | |||
243 | int BN_X931_generate_prime_ex(BIGNUM *p, BIGNUM *p1, BIGNUM *p2, | ||
244 | BIGNUM *Xp1, BIGNUM *Xp2, | ||
245 | const BIGNUM *Xp, | ||
246 | const BIGNUM *e, BN_CTX *ctx, | ||
247 | BN_GENCB *cb) | ||
248 | { | ||
249 | int ret = 0; | ||
250 | |||
251 | BN_CTX_start(ctx); | ||
252 | if (!Xp1) | ||
253 | Xp1 = BN_CTX_get(ctx); | ||
254 | if (!Xp2) | ||
255 | Xp2 = BN_CTX_get(ctx); | ||
256 | |||
257 | if (!BN_rand(Xp1, 101, 0, 0)) | ||
258 | goto error; | ||
259 | if (!BN_rand(Xp2, 101, 0, 0)) | ||
260 | goto error; | ||
261 | if (!BN_X931_derive_prime_ex(p, p1, p2, Xp, Xp1, Xp2, e, ctx, cb)) | ||
262 | goto error; | ||
263 | |||
264 | ret = 1; | ||
265 | |||
266 | error: | ||
267 | BN_CTX_end(ctx); | ||
268 | |||
269 | return ret; | ||
270 | |||
271 | } | ||
272 | |||
diff --git a/src/lib/libssl/src/crypto/buffer/buf_str.c b/src/lib/libssl/src/crypto/buffer/buf_str.c new file mode 100644 index 0000000000..151f5ea971 --- /dev/null +++ b/src/lib/libssl/src/crypto/buffer/buf_str.c | |||
@@ -0,0 +1,119 @@ | |||
1 | /* crypto/buffer/buffer.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/buffer.h> | ||
62 | |||
63 | char *BUF_strdup(const char *str) | ||
64 | { | ||
65 | if (str == NULL) return(NULL); | ||
66 | return BUF_strndup(str, strlen(str)); | ||
67 | } | ||
68 | |||
69 | char *BUF_strndup(const char *str, size_t siz) | ||
70 | { | ||
71 | char *ret; | ||
72 | |||
73 | if (str == NULL) return(NULL); | ||
74 | |||
75 | ret=OPENSSL_malloc(siz+1); | ||
76 | if (ret == NULL) | ||
77 | { | ||
78 | BUFerr(BUF_F_BUF_STRNDUP,ERR_R_MALLOC_FAILURE); | ||
79 | return(NULL); | ||
80 | } | ||
81 | BUF_strlcpy(ret,str,siz+1); | ||
82 | return(ret); | ||
83 | } | ||
84 | |||
85 | void *BUF_memdup(const void *data, size_t siz) | ||
86 | { | ||
87 | void *ret; | ||
88 | |||
89 | if (data == NULL) return(NULL); | ||
90 | |||
91 | ret=OPENSSL_malloc(siz); | ||
92 | if (ret == NULL) | ||
93 | { | ||
94 | BUFerr(BUF_F_BUF_MEMDUP,ERR_R_MALLOC_FAILURE); | ||
95 | return(NULL); | ||
96 | } | ||
97 | return memcpy(ret, data, siz); | ||
98 | } | ||
99 | |||
100 | size_t BUF_strlcpy(char *dst, const char *src, size_t size) | ||
101 | { | ||
102 | size_t l = 0; | ||
103 | for(; size > 1 && *src; size--) | ||
104 | { | ||
105 | *dst++ = *src++; | ||
106 | l++; | ||
107 | } | ||
108 | if (size) | ||
109 | *dst = '\0'; | ||
110 | return l + strlen(src); | ||
111 | } | ||
112 | |||
113 | size_t BUF_strlcat(char *dst, const char *src, size_t size) | ||
114 | { | ||
115 | size_t l = 0; | ||
116 | for(; size > 0 && *dst; size--, dst++) | ||
117 | l++; | ||
118 | return l + BUF_strlcpy(dst, src, size); | ||
119 | } | ||
diff --git a/src/lib/libssl/src/crypto/mdc2/mdc2_one.c b/src/lib/libssl/src/crypto/mdc2/mdc2_one.c new file mode 100644 index 0000000000..72647f67ed --- /dev/null +++ b/src/lib/libssl/src/crypto/mdc2/mdc2_one.c | |||
@@ -0,0 +1,76 @@ | |||
1 | /* crypto/mdc2/mdc2_one.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/mdc2.h> | ||
62 | |||
63 | unsigned char *MDC2(const unsigned char *d, size_t n, unsigned char *md) | ||
64 | { | ||
65 | MDC2_CTX c; | ||
66 | static unsigned char m[MDC2_DIGEST_LENGTH]; | ||
67 | |||
68 | if (md == NULL) md=m; | ||
69 | if (!MDC2_Init(&c)) | ||
70 | return NULL; | ||
71 | MDC2_Update(&c,d,n); | ||
72 | MDC2_Final(md,&c); | ||
73 | OPENSSL_cleanse(&c,sizeof(c)); /* security consideration */ | ||
74 | return(md); | ||
75 | } | ||
76 | |||
diff --git a/src/lib/libssl/src/crypto/mdc2/mdc2dgst.c b/src/lib/libssl/src/crypto/mdc2/mdc2dgst.c new file mode 100644 index 0000000000..b74bb1a759 --- /dev/null +++ b/src/lib/libssl/src/crypto/mdc2/mdc2dgst.c | |||
@@ -0,0 +1,200 @@ | |||
1 | /* crypto/mdc2/mdc2dgst.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 <string.h> | ||
62 | #include <openssl/des.h> | ||
63 | #include <openssl/mdc2.h> | ||
64 | #include <openssl/crypto.h> | ||
65 | |||
66 | #undef c2l | ||
67 | #define c2l(c,l) (l =((DES_LONG)(*((c)++))) , \ | ||
68 | l|=((DES_LONG)(*((c)++)))<< 8L, \ | ||
69 | l|=((DES_LONG)(*((c)++)))<<16L, \ | ||
70 | l|=((DES_LONG)(*((c)++)))<<24L) | ||
71 | |||
72 | #undef l2c | ||
73 | #define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \ | ||
74 | *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \ | ||
75 | *((c)++)=(unsigned char)(((l)>>16L)&0xff), \ | ||
76 | *((c)++)=(unsigned char)(((l)>>24L)&0xff)) | ||
77 | |||
78 | static void mdc2_body(MDC2_CTX *c, const unsigned char *in, size_t len); | ||
79 | fips_md_init(MDC2) | ||
80 | { | ||
81 | c->num=0; | ||
82 | c->pad_type=1; | ||
83 | memset(&(c->h[0]),0x52,MDC2_BLOCK); | ||
84 | memset(&(c->hh[0]),0x25,MDC2_BLOCK); | ||
85 | return 1; | ||
86 | } | ||
87 | |||
88 | int MDC2_Update(MDC2_CTX *c, const unsigned char *in, size_t len) | ||
89 | { | ||
90 | size_t i,j; | ||
91 | |||
92 | i=c->num; | ||
93 | if (i != 0) | ||
94 | { | ||
95 | if (i+len < MDC2_BLOCK) | ||
96 | { | ||
97 | /* partial block */ | ||
98 | memcpy(&(c->data[i]),in,len); | ||
99 | c->num+=(int)len; | ||
100 | return 1; | ||
101 | } | ||
102 | else | ||
103 | { | ||
104 | /* filled one */ | ||
105 | j=MDC2_BLOCK-i; | ||
106 | memcpy(&(c->data[i]),in,j); | ||
107 | len-=j; | ||
108 | in+=j; | ||
109 | c->num=0; | ||
110 | mdc2_body(c,&(c->data[0]),MDC2_BLOCK); | ||
111 | } | ||
112 | } | ||
113 | i=len&~((size_t)MDC2_BLOCK-1); | ||
114 | if (i > 0) mdc2_body(c,in,i); | ||
115 | j=len-i; | ||
116 | if (j > 0) | ||
117 | { | ||
118 | memcpy(&(c->data[0]),&(in[i]),j); | ||
119 | c->num=(int)j; | ||
120 | } | ||
121 | return 1; | ||
122 | } | ||
123 | |||
124 | static void mdc2_body(MDC2_CTX *c, const unsigned char *in, size_t len) | ||
125 | { | ||
126 | register DES_LONG tin0,tin1; | ||
127 | register DES_LONG ttin0,ttin1; | ||
128 | DES_LONG d[2],dd[2]; | ||
129 | DES_key_schedule k; | ||
130 | unsigned char *p; | ||
131 | size_t i; | ||
132 | |||
133 | for (i=0; i<len; i+=8) | ||
134 | { | ||
135 | c2l(in,tin0); d[0]=dd[0]=tin0; | ||
136 | c2l(in,tin1); d[1]=dd[1]=tin1; | ||
137 | c->h[0]=(c->h[0]&0x9f)|0x40; | ||
138 | c->hh[0]=(c->hh[0]&0x9f)|0x20; | ||
139 | |||
140 | DES_set_odd_parity(&c->h); | ||
141 | DES_set_key_unchecked(&c->h,&k); | ||
142 | DES_encrypt1(d,&k,1); | ||
143 | |||
144 | DES_set_odd_parity(&c->hh); | ||
145 | DES_set_key_unchecked(&c->hh,&k); | ||
146 | DES_encrypt1(dd,&k,1); | ||
147 | |||
148 | ttin0=tin0^dd[0]; | ||
149 | ttin1=tin1^dd[1]; | ||
150 | tin0^=d[0]; | ||
151 | tin1^=d[1]; | ||
152 | |||
153 | p=c->h; | ||
154 | l2c(tin0,p); | ||
155 | l2c(ttin1,p); | ||
156 | p=c->hh; | ||
157 | l2c(ttin0,p); | ||
158 | l2c(tin1,p); | ||
159 | } | ||
160 | } | ||
161 | |||
162 | int MDC2_Final(unsigned char *md, MDC2_CTX *c) | ||
163 | { | ||
164 | unsigned int i; | ||
165 | int j; | ||
166 | |||
167 | i=c->num; | ||
168 | j=c->pad_type; | ||
169 | if ((i > 0) || (j == 2)) | ||
170 | { | ||
171 | if (j == 2) | ||
172 | c->data[i++]=0x80; | ||
173 | memset(&(c->data[i]),0,MDC2_BLOCK-i); | ||
174 | mdc2_body(c,c->data,MDC2_BLOCK); | ||
175 | } | ||
176 | memcpy(md,(char *)c->h,MDC2_BLOCK); | ||
177 | memcpy(&(md[MDC2_BLOCK]),(char *)c->hh,MDC2_BLOCK); | ||
178 | return 1; | ||
179 | } | ||
180 | |||
181 | #undef TEST | ||
182 | |||
183 | #ifdef TEST | ||
184 | main() | ||
185 | { | ||
186 | unsigned char md[MDC2_DIGEST_LENGTH]; | ||
187 | int i; | ||
188 | MDC2_CTX c; | ||
189 | static char *text="Now is the time for all "; | ||
190 | |||
191 | MDC2_Init(&c); | ||
192 | MDC2_Update(&c,text,strlen(text)); | ||
193 | MDC2_Final(&(md[0]),&c); | ||
194 | |||
195 | for (i=0; i<MDC2_DIGEST_LENGTH; i++) | ||
196 | printf("%02X",md[i]); | ||
197 | printf("\n"); | ||
198 | } | ||
199 | |||
200 | #endif | ||
diff --git a/src/lib/libssl/src/crypto/o_init.c b/src/lib/libssl/src/crypto/o_init.c new file mode 100644 index 0000000000..db4cdc443b --- /dev/null +++ b/src/lib/libssl/src/crypto/o_init.c | |||
@@ -0,0 +1,82 @@ | |||
1 | /* o_init.c */ | ||
2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | ||
3 | * project. | ||
4 | */ | ||
5 | /* ==================================================================== | ||
6 | * Copyright (c) 2011 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 | */ | ||
54 | |||
55 | #include <e_os.h> | ||
56 | #include <openssl/err.h> | ||
57 | #ifdef OPENSSL_FIPS | ||
58 | #include <openssl/fips.h> | ||
59 | #include <openssl/rand.h> | ||
60 | #endif | ||
61 | |||
62 | /* Perform any essential OpenSSL initialization operations. | ||
63 | * Currently only sets FIPS callbacks | ||
64 | */ | ||
65 | |||
66 | void OPENSSL_init(void) | ||
67 | { | ||
68 | static int done = 0; | ||
69 | if (done) | ||
70 | return; | ||
71 | done = 1; | ||
72 | #ifdef OPENSSL_FIPS | ||
73 | FIPS_set_locking_callbacks(CRYPTO_lock, CRYPTO_add_lock); | ||
74 | FIPS_set_error_callbacks(ERR_put_error, ERR_add_error_vdata); | ||
75 | FIPS_set_malloc_callbacks(CRYPTO_malloc, CRYPTO_free); | ||
76 | RAND_init_fips(); | ||
77 | #endif | ||
78 | #if 0 | ||
79 | fprintf(stderr, "Called OPENSSL_init\n"); | ||
80 | #endif | ||
81 | } | ||
82 | |||