diff options
author | markus <> | 2003-05-11 21:36:58 +0000 |
---|---|---|
committer | markus <> | 2003-05-11 21:36:58 +0000 |
commit | 1c98a87f0daac81245653c227eb2f2508a22a965 (patch) | |
tree | 3de6d603296ec563b936da4e6a8a1e33d48f8884 /src | |
parent | 31392c89d1135cf2a416f97295f6d21681b3fbc4 (diff) | |
download | openbsd-1c98a87f0daac81245653c227eb2f2508a22a965.tar.gz openbsd-1c98a87f0daac81245653c227eb2f2508a22a965.tar.bz2 openbsd-1c98a87f0daac81245653c227eb2f2508a22a965.zip |
import 0.9.7b (without idea and rc5)
Diffstat (limited to 'src')
248 files changed, 4861 insertions, 1460 deletions
diff --git a/src/lib/libcrypto/aes/aes.h b/src/lib/libcrypto/aes/aes.h index e8da921ec5..8294a41a3a 100644 --- a/src/lib/libcrypto/aes/aes.h +++ b/src/lib/libcrypto/aes/aes.h | |||
@@ -56,8 +56,9 @@ | |||
56 | #error AES is disabled. | 56 | #error AES is disabled. |
57 | #endif | 57 | #endif |
58 | 58 | ||
59 | static const int AES_DECRYPT = 0; | 59 | #define AES_ENCRYPT 1 |
60 | static const int AES_ENCRYPT = 1; | 60 | #define AES_DECRYPT 0 |
61 | |||
61 | /* Because array size can't be a const in C, the following two are macros. | 62 | /* Because array size can't be a const in C, the following two are macros. |
62 | Both sizes are in bytes. */ | 63 | Both sizes are in bytes. */ |
63 | #define AES_MAXNR 14 | 64 | #define AES_MAXNR 14 |
@@ -99,7 +100,9 @@ void AES_ofb128_encrypt(const unsigned char *in, unsigned char *out, | |||
99 | unsigned char *ivec, int *num); | 100 | unsigned char *ivec, int *num); |
100 | void AES_ctr128_encrypt(const unsigned char *in, unsigned char *out, | 101 | void AES_ctr128_encrypt(const unsigned char *in, unsigned char *out, |
101 | const unsigned long length, const AES_KEY *key, | 102 | const unsigned long length, const AES_KEY *key, |
102 | unsigned char *counter, unsigned int *num); | 103 | unsigned char counter[AES_BLOCK_SIZE], |
104 | unsigned char ecount_buf[AES_BLOCK_SIZE], | ||
105 | unsigned int *num); | ||
103 | 106 | ||
104 | 107 | ||
105 | #ifdef __cplusplus | 108 | #ifdef __cplusplus |
diff --git a/src/lib/libcrypto/aes/aes_cbc.c b/src/lib/libcrypto/aes/aes_cbc.c index 3dfd7aba2a..de438306b1 100644 --- a/src/lib/libcrypto/aes/aes_cbc.c +++ b/src/lib/libcrypto/aes/aes_cbc.c | |||
@@ -49,7 +49,13 @@ | |||
49 | * | 49 | * |
50 | */ | 50 | */ |
51 | 51 | ||
52 | #ifndef AES_DEBUG | ||
53 | # ifndef NDEBUG | ||
54 | # define NDEBUG | ||
55 | # endif | ||
56 | #endif | ||
52 | #include <assert.h> | 57 | #include <assert.h> |
58 | |||
53 | #include <openssl/aes.h> | 59 | #include <openssl/aes.h> |
54 | #include "aes_locl.h" | 60 | #include "aes_locl.h" |
55 | 61 | ||
@@ -57,33 +63,49 @@ void AES_cbc_encrypt(const unsigned char *in, unsigned char *out, | |||
57 | const unsigned long length, const AES_KEY *key, | 63 | const unsigned long length, const AES_KEY *key, |
58 | unsigned char *ivec, const int enc) { | 64 | unsigned char *ivec, const int enc) { |
59 | 65 | ||
60 | int n; | 66 | unsigned long n; |
61 | unsigned long len = length; | 67 | unsigned long len = length; |
62 | unsigned char tmp[16]; | 68 | unsigned char tmp[AES_BLOCK_SIZE]; |
63 | 69 | ||
64 | assert(in && out && key && ivec); | 70 | assert(in && out && key && ivec); |
65 | assert(length % AES_BLOCK_SIZE == 0); | ||
66 | assert((AES_ENCRYPT == enc)||(AES_DECRYPT == enc)); | 71 | assert((AES_ENCRYPT == enc)||(AES_DECRYPT == enc)); |
67 | 72 | ||
68 | if (AES_ENCRYPT == enc) | 73 | if (AES_ENCRYPT == enc) { |
69 | while (len > 0) { | 74 | while (len >= AES_BLOCK_SIZE) { |
70 | for(n=0; n < 16; ++n) | 75 | for(n=0; n < sizeof tmp; ++n) |
71 | tmp[n] = in[n] ^ ivec[n]; | 76 | tmp[n] = in[n] ^ ivec[n]; |
72 | AES_encrypt(tmp, out, key); | 77 | AES_encrypt(tmp, out, key); |
73 | memcpy(ivec, out, 16); | 78 | memcpy(ivec, out, AES_BLOCK_SIZE); |
74 | len -= 16; | 79 | len -= AES_BLOCK_SIZE; |
75 | in += 16; | 80 | in += AES_BLOCK_SIZE; |
76 | out += 16; | 81 | out += AES_BLOCK_SIZE; |
77 | } | 82 | } |
78 | else | 83 | if (len) { |
79 | while (len > 0) { | 84 | for(n=0; n < len; ++n) |
80 | memcpy(tmp, in, 16); | 85 | tmp[n] = in[n] ^ ivec[n]; |
86 | for(n=len; n < AES_BLOCK_SIZE; ++n) | ||
87 | tmp[n] = ivec[n]; | ||
88 | AES_encrypt(tmp, tmp, key); | ||
89 | memcpy(out, tmp, len); | ||
90 | memcpy(ivec, tmp, sizeof tmp); | ||
91 | } | ||
92 | } else { | ||
93 | while (len >= AES_BLOCK_SIZE) { | ||
94 | memcpy(tmp, in, sizeof tmp); | ||
81 | AES_decrypt(in, out, key); | 95 | AES_decrypt(in, out, key); |
82 | for(n=0; n < 16; ++n) | 96 | for(n=0; n < AES_BLOCK_SIZE; ++n) |
83 | out[n] ^= ivec[n]; | 97 | out[n] ^= ivec[n]; |
84 | memcpy(ivec, tmp, 16); | 98 | memcpy(ivec, tmp, AES_BLOCK_SIZE); |
85 | len -= 16; | 99 | len -= AES_BLOCK_SIZE; |
86 | in += 16; | 100 | in += AES_BLOCK_SIZE; |
87 | out += 16; | 101 | out += AES_BLOCK_SIZE; |
88 | } | 102 | } |
103 | if (len) { | ||
104 | memcpy(tmp, in, sizeof tmp); | ||
105 | AES_decrypt(tmp, tmp, key); | ||
106 | for(n=0; n < len; ++n) | ||
107 | out[n] ^= ivec[n]; | ||
108 | memcpy(ivec, tmp, sizeof tmp); | ||
109 | } | ||
110 | } | ||
89 | } | 111 | } |
diff --git a/src/lib/libcrypto/aes/aes_cfb.c b/src/lib/libcrypto/aes/aes_cfb.c index 41c2a5ec3d..9b569dda90 100644 --- a/src/lib/libcrypto/aes/aes_cfb.c +++ b/src/lib/libcrypto/aes/aes_cfb.c | |||
@@ -105,7 +105,13 @@ | |||
105 | * [including the GNU Public Licence.] | 105 | * [including the GNU Public Licence.] |
106 | */ | 106 | */ |
107 | 107 | ||
108 | #ifndef AES_DEBUG | ||
109 | # ifndef NDEBUG | ||
110 | # define NDEBUG | ||
111 | # endif | ||
112 | #endif | ||
108 | #include <assert.h> | 113 | #include <assert.h> |
114 | |||
109 | #include <openssl/aes.h> | 115 | #include <openssl/aes.h> |
110 | #include "aes_locl.h" | 116 | #include "aes_locl.h" |
111 | 117 | ||
diff --git a/src/lib/libcrypto/aes/aes_core.c b/src/lib/libcrypto/aes/aes_core.c index 937988dd8c..2f41a825f8 100644 --- a/src/lib/libcrypto/aes/aes_core.c +++ b/src/lib/libcrypto/aes/aes_core.c | |||
@@ -28,7 +28,13 @@ | |||
28 | /* Note: rewritten a little bit to provide error control and an OpenSSL- | 28 | /* Note: rewritten a little bit to provide error control and an OpenSSL- |
29 | compatible API */ | 29 | compatible API */ |
30 | 30 | ||
31 | #ifndef AES_DEBUG | ||
32 | # ifndef NDEBUG | ||
33 | # define NDEBUG | ||
34 | # endif | ||
35 | #endif | ||
31 | #include <assert.h> | 36 | #include <assert.h> |
37 | |||
32 | #include <stdlib.h> | 38 | #include <stdlib.h> |
33 | #include <openssl/aes.h> | 39 | #include <openssl/aes.h> |
34 | #include "aes_locl.h" | 40 | #include "aes_locl.h" |
@@ -744,7 +750,7 @@ int AES_set_encrypt_key(const unsigned char *userKey, const int bits, | |||
744 | rk[2] = GETU32(userKey + 8); | 750 | rk[2] = GETU32(userKey + 8); |
745 | rk[3] = GETU32(userKey + 12); | 751 | rk[3] = GETU32(userKey + 12); |
746 | if (bits == 128) { | 752 | if (bits == 128) { |
747 | for (;;) { | 753 | while (1) { |
748 | temp = rk[3]; | 754 | temp = rk[3]; |
749 | rk[4] = rk[0] ^ | 755 | rk[4] = rk[0] ^ |
750 | (Te4[(temp >> 16) & 0xff] & 0xff000000) ^ | 756 | (Te4[(temp >> 16) & 0xff] & 0xff000000) ^ |
@@ -764,7 +770,7 @@ int AES_set_encrypt_key(const unsigned char *userKey, const int bits, | |||
764 | rk[4] = GETU32(userKey + 16); | 770 | rk[4] = GETU32(userKey + 16); |
765 | rk[5] = GETU32(userKey + 20); | 771 | rk[5] = GETU32(userKey + 20); |
766 | if (bits == 192) { | 772 | if (bits == 192) { |
767 | for (;;) { | 773 | while (1) { |
768 | temp = rk[ 5]; | 774 | temp = rk[ 5]; |
769 | rk[ 6] = rk[ 0] ^ | 775 | rk[ 6] = rk[ 0] ^ |
770 | (Te4[(temp >> 16) & 0xff] & 0xff000000) ^ | 776 | (Te4[(temp >> 16) & 0xff] & 0xff000000) ^ |
@@ -786,7 +792,7 @@ int AES_set_encrypt_key(const unsigned char *userKey, const int bits, | |||
786 | rk[6] = GETU32(userKey + 24); | 792 | rk[6] = GETU32(userKey + 24); |
787 | rk[7] = GETU32(userKey + 28); | 793 | rk[7] = GETU32(userKey + 28); |
788 | if (bits == 256) { | 794 | if (bits == 256) { |
789 | for (;;) { | 795 | while (1) { |
790 | temp = rk[ 7]; | 796 | temp = rk[ 7]; |
791 | rk[ 8] = rk[ 0] ^ | 797 | rk[ 8] = rk[ 0] ^ |
792 | (Te4[(temp >> 16) & 0xff] & 0xff000000) ^ | 798 | (Te4[(temp >> 16) & 0xff] & 0xff000000) ^ |
diff --git a/src/lib/libcrypto/aes/aes_ctr.c b/src/lib/libcrypto/aes/aes_ctr.c index aea3db2092..59088499a0 100644 --- a/src/lib/libcrypto/aes/aes_ctr.c +++ b/src/lib/libcrypto/aes/aes_ctr.c | |||
@@ -49,7 +49,13 @@ | |||
49 | * | 49 | * |
50 | */ | 50 | */ |
51 | 51 | ||
52 | #ifndef AES_DEBUG | ||
53 | # ifndef NDEBUG | ||
54 | # define NDEBUG | ||
55 | # endif | ||
56 | #endif | ||
52 | #include <assert.h> | 57 | #include <assert.h> |
58 | |||
53 | #include <openssl/aes.h> | 59 | #include <openssl/aes.h> |
54 | #include "aes_locl.h" | 60 | #include "aes_locl.h" |
55 | 61 | ||
@@ -90,26 +96,31 @@ static void AES_ctr128_inc(unsigned char *counter) { | |||
90 | 96 | ||
91 | /* The input encrypted as though 128bit counter mode is being | 97 | /* The input encrypted as though 128bit counter mode is being |
92 | * used. The extra state information to record how much of the | 98 | * used. The extra state information to record how much of the |
93 | * 128bit block we have used is contained in *num; | 99 | * 128bit block we have used is contained in *num, and the |
100 | * encrypted counter is kept in ecount_buf. Both *num and | ||
101 | * ecount_buf must be initialised with zeros before the first | ||
102 | * call to AES_ctr128_encrypt(). | ||
94 | */ | 103 | */ |
95 | void AES_ctr128_encrypt(const unsigned char *in, unsigned char *out, | 104 | void AES_ctr128_encrypt(const unsigned char *in, unsigned char *out, |
96 | const unsigned long length, const AES_KEY *key, | 105 | const unsigned long length, const AES_KEY *key, |
97 | unsigned char *counter, unsigned int *num) { | 106 | unsigned char counter[AES_BLOCK_SIZE], |
107 | unsigned char ecount_buf[AES_BLOCK_SIZE], | ||
108 | unsigned int *num) { | ||
98 | 109 | ||
99 | unsigned int n; | 110 | unsigned int n; |
100 | unsigned long l=length; | 111 | unsigned long l=length; |
101 | unsigned char tmp[AES_BLOCK_SIZE]; | ||
102 | 112 | ||
103 | assert(in && out && key && counter && num); | 113 | assert(in && out && key && counter && num); |
114 | assert(*num < AES_BLOCK_SIZE); | ||
104 | 115 | ||
105 | n = *num; | 116 | n = *num; |
106 | 117 | ||
107 | while (l--) { | 118 | while (l--) { |
108 | if (n == 0) { | 119 | if (n == 0) { |
109 | AES_encrypt(counter, tmp, key); | 120 | AES_encrypt(counter, ecount_buf, key); |
110 | AES_ctr128_inc(counter); | 121 | AES_ctr128_inc(counter); |
111 | } | 122 | } |
112 | *(out++) = *(in++) ^ tmp[n]; | 123 | *(out++) = *(in++) ^ ecount_buf[n]; |
113 | n = (n+1) % AES_BLOCK_SIZE; | 124 | n = (n+1) % AES_BLOCK_SIZE; |
114 | } | 125 | } |
115 | 126 | ||
diff --git a/src/lib/libcrypto/aes/aes_ecb.c b/src/lib/libcrypto/aes/aes_ecb.c index 1cb2e07d3d..28aa561c2d 100644 --- a/src/lib/libcrypto/aes/aes_ecb.c +++ b/src/lib/libcrypto/aes/aes_ecb.c | |||
@@ -49,7 +49,13 @@ | |||
49 | * | 49 | * |
50 | */ | 50 | */ |
51 | 51 | ||
52 | #ifndef AES_DEBUG | ||
53 | # ifndef NDEBUG | ||
54 | # define NDEBUG | ||
55 | # endif | ||
56 | #endif | ||
52 | #include <assert.h> | 57 | #include <assert.h> |
58 | |||
53 | #include <openssl/aes.h> | 59 | #include <openssl/aes.h> |
54 | #include "aes_locl.h" | 60 | #include "aes_locl.h" |
55 | 61 | ||
diff --git a/src/lib/libcrypto/aes/aes_locl.h b/src/lib/libcrypto/aes/aes_locl.h index 18fc2d0747..f290946058 100644 --- a/src/lib/libcrypto/aes/aes_locl.h +++ b/src/lib/libcrypto/aes/aes_locl.h | |||
@@ -62,7 +62,7 @@ | |||
62 | #include <stdlib.h> | 62 | #include <stdlib.h> |
63 | #include <string.h> | 63 | #include <string.h> |
64 | 64 | ||
65 | #ifdef _MSC_VER | 65 | #if defined(_MSC_VER) && !defined(OPENSSL_SYS_WINCE) |
66 | # define SWAP(x) (_lrotl(x, 8) & 0x00ff00ff | _lrotr(x, 8) & 0xff00ff00) | 66 | # define SWAP(x) (_lrotl(x, 8) & 0x00ff00ff | _lrotr(x, 8) & 0xff00ff00) |
67 | # define GETU32(p) SWAP(*((u32 *)(p))) | 67 | # define GETU32(p) SWAP(*((u32 *)(p))) |
68 | # define PUTU32(ct, st) { *((u32 *)(ct)) = SWAP((st)); } | 68 | # define PUTU32(ct, st) { *((u32 *)(ct)) = SWAP((st)); } |
diff --git a/src/lib/libcrypto/aes/aes_ofb.c b/src/lib/libcrypto/aes/aes_ofb.c index e33bdaea28..f358bb39e2 100644 --- a/src/lib/libcrypto/aes/aes_ofb.c +++ b/src/lib/libcrypto/aes/aes_ofb.c | |||
@@ -105,7 +105,13 @@ | |||
105 | * [including the GNU Public Licence.] | 105 | * [including the GNU Public Licence.] |
106 | */ | 106 | */ |
107 | 107 | ||
108 | #ifndef AES_DEBUG | ||
109 | # ifndef NDEBUG | ||
110 | # define NDEBUG | ||
111 | # endif | ||
112 | #endif | ||
108 | #include <assert.h> | 113 | #include <assert.h> |
114 | |||
109 | #include <openssl/aes.h> | 115 | #include <openssl/aes.h> |
110 | #include "aes_locl.h" | 116 | #include "aes_locl.h" |
111 | 117 | ||
diff --git a/src/lib/libcrypto/asn1/a_bitstr.c b/src/lib/libcrypto/asn1/a_bitstr.c index e0265f69d2..f4ea96cd54 100644 --- a/src/lib/libcrypto/asn1/a_bitstr.c +++ b/src/lib/libcrypto/asn1/a_bitstr.c | |||
@@ -191,7 +191,9 @@ int ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a, int n, int value) | |||
191 | if (a->data == NULL) | 191 | if (a->data == NULL) |
192 | c=(unsigned char *)OPENSSL_malloc(w+1); | 192 | c=(unsigned char *)OPENSSL_malloc(w+1); |
193 | else | 193 | else |
194 | c=(unsigned char *)OPENSSL_realloc(a->data,w+1); | 194 | c=(unsigned char *)OPENSSL_realloc_clean(a->data, |
195 | a->length, | ||
196 | w+1); | ||
195 | if (c == NULL) return(0); | 197 | if (c == NULL) return(0); |
196 | if (w+1-a->length > 0) memset(c+a->length, 0, w+1-a->length); | 198 | if (w+1-a->length > 0) memset(c+a->length, 0, w+1-a->length); |
197 | a->data=c; | 199 | a->data=c; |
diff --git a/src/lib/libcrypto/asn1/a_bytes.c b/src/lib/libcrypto/asn1/a_bytes.c index bb88660f58..afd27b80e1 100644 --- a/src/lib/libcrypto/asn1/a_bytes.c +++ b/src/lib/libcrypto/asn1/a_bytes.c | |||
@@ -285,7 +285,7 @@ static int asn1_collate_primitive(ASN1_STRING *a, ASN1_CTX *c) | |||
285 | goto err; | 285 | goto err; |
286 | } | 286 | } |
287 | 287 | ||
288 | if (!BUF_MEM_grow(&b,num+os->length)) | 288 | if (!BUF_MEM_grow_clean(&b,num+os->length)) |
289 | { | 289 | { |
290 | c->error=ERR_R_BUF_LIB; | 290 | c->error=ERR_R_BUF_LIB; |
291 | goto err; | 291 | goto err; |
diff --git a/src/lib/libcrypto/asn1/a_d2i_fp.c b/src/lib/libcrypto/asn1/a_d2i_fp.c index a80fbe9ff7..b67b75e7c2 100644 --- a/src/lib/libcrypto/asn1/a_d2i_fp.c +++ b/src/lib/libcrypto/asn1/a_d2i_fp.c | |||
@@ -149,7 +149,12 @@ static int asn1_d2i_read_bio(BIO *in, BUF_MEM **pb) | |||
149 | ASN1_CTX c; | 149 | ASN1_CTX c; |
150 | int want=HEADER_SIZE; | 150 | int want=HEADER_SIZE; |
151 | int eos=0; | 151 | int eos=0; |
152 | #if defined(__GNUC__) && defined(__ia64) | ||
153 | /* pathetic compiler bug in all known versions as of Nov. 2002 */ | ||
154 | long off=0; | ||
155 | #else | ||
152 | int off=0; | 156 | int off=0; |
157 | #endif | ||
153 | int len=0; | 158 | int len=0; |
154 | 159 | ||
155 | b=BUF_MEM_new(); | 160 | b=BUF_MEM_new(); |
@@ -166,7 +171,7 @@ static int asn1_d2i_read_bio(BIO *in, BUF_MEM **pb) | |||
166 | { | 171 | { |
167 | want-=(len-off); | 172 | want-=(len-off); |
168 | 173 | ||
169 | if (!BUF_MEM_grow(b,len+want)) | 174 | if (!BUF_MEM_grow_clean(b,len+want)) |
170 | { | 175 | { |
171 | ASN1err(ASN1_F_ASN1_D2I_BIO,ERR_R_MALLOC_FAILURE); | 176 | ASN1err(ASN1_F_ASN1_D2I_BIO,ERR_R_MALLOC_FAILURE); |
172 | goto err; | 177 | goto err; |
@@ -221,18 +226,23 @@ static int asn1_d2i_read_bio(BIO *in, BUF_MEM **pb) | |||
221 | if (want > (len-off)) | 226 | if (want > (len-off)) |
222 | { | 227 | { |
223 | want-=(len-off); | 228 | want-=(len-off); |
224 | if (!BUF_MEM_grow(b,len+want)) | 229 | if (!BUF_MEM_grow_clean(b,len+want)) |
225 | { | 230 | { |
226 | ASN1err(ASN1_F_ASN1_D2I_BIO,ERR_R_MALLOC_FAILURE); | 231 | ASN1err(ASN1_F_ASN1_D2I_BIO,ERR_R_MALLOC_FAILURE); |
227 | goto err; | 232 | goto err; |
228 | } | 233 | } |
229 | i=BIO_read(in,&(b->data[len]),want); | 234 | while (want > 0) |
230 | if (i <= 0) | ||
231 | { | 235 | { |
232 | ASN1err(ASN1_F_ASN1_D2I_BIO,ASN1_R_NOT_ENOUGH_DATA); | 236 | i=BIO_read(in,&(b->data[len]),want); |
233 | goto err; | 237 | if (i <= 0) |
238 | { | ||
239 | ASN1err(ASN1_F_ASN1_D2I_BIO, | ||
240 | ASN1_R_NOT_ENOUGH_DATA); | ||
241 | goto err; | ||
242 | } | ||
243 | len+=i; | ||
244 | want -= i; | ||
234 | } | 245 | } |
235 | len+=i; | ||
236 | } | 246 | } |
237 | off+=(int)c.slen; | 247 | off+=(int)c.slen; |
238 | if (eos <= 0) | 248 | if (eos <= 0) |
diff --git a/src/lib/libcrypto/asn1/a_object.c b/src/lib/libcrypto/asn1/a_object.c index 71ce7c3896..0a8e6c287c 100644 --- a/src/lib/libcrypto/asn1/a_object.c +++ b/src/lib/libcrypto/asn1/a_object.c | |||
@@ -183,8 +183,8 @@ int i2a_ASN1_OBJECT(BIO *bp, ASN1_OBJECT *a) | |||
183 | 183 | ||
184 | if ((a == NULL) || (a->data == NULL)) | 184 | if ((a == NULL) || (a->data == NULL)) |
185 | return(BIO_write(bp,"NULL",4)); | 185 | return(BIO_write(bp,"NULL",4)); |
186 | i=i2t_ASN1_OBJECT(buf,80,a); | 186 | i=i2t_ASN1_OBJECT(buf,sizeof buf,a); |
187 | if (i > 80) i=80; | 187 | if (i > sizeof buf) i=sizeof buf; |
188 | BIO_write(bp,buf,i); | 188 | BIO_write(bp,buf,i); |
189 | return(i); | 189 | return(i); |
190 | } | 190 | } |
diff --git a/src/lib/libcrypto/asn1/a_sign.c b/src/lib/libcrypto/asn1/a_sign.c index de53b44144..52ce7e3974 100644 --- a/src/lib/libcrypto/asn1/a_sign.c +++ b/src/lib/libcrypto/asn1/a_sign.c | |||
@@ -204,9 +204,9 @@ int ASN1_sign(int (*i2d)(), X509_ALGOR *algor1, X509_ALGOR *algor2, | |||
204 | err: | 204 | err: |
205 | EVP_MD_CTX_cleanup(&ctx); | 205 | EVP_MD_CTX_cleanup(&ctx); |
206 | if (buf_in != NULL) | 206 | if (buf_in != NULL) |
207 | { memset((char *)buf_in,0,(unsigned int)inl); OPENSSL_free(buf_in); } | 207 | { OPENSSL_cleanse((char *)buf_in,(unsigned int)inl); OPENSSL_free(buf_in); } |
208 | if (buf_out != NULL) | 208 | if (buf_out != NULL) |
209 | { memset((char *)buf_out,0,outll); OPENSSL_free(buf_out); } | 209 | { OPENSSL_cleanse((char *)buf_out,outll); OPENSSL_free(buf_out); } |
210 | return(outl); | 210 | return(outl); |
211 | } | 211 | } |
212 | 212 | ||
@@ -287,8 +287,8 @@ int ASN1_item_sign(const ASN1_ITEM *it, X509_ALGOR *algor1, X509_ALGOR *algor2, | |||
287 | err: | 287 | err: |
288 | EVP_MD_CTX_cleanup(&ctx); | 288 | EVP_MD_CTX_cleanup(&ctx); |
289 | if (buf_in != NULL) | 289 | if (buf_in != NULL) |
290 | { memset((char *)buf_in,0,(unsigned int)inl); OPENSSL_free(buf_in); } | 290 | { OPENSSL_cleanse((char *)buf_in,(unsigned int)inl); OPENSSL_free(buf_in); } |
291 | if (buf_out != NULL) | 291 | if (buf_out != NULL) |
292 | { memset((char *)buf_out,0,outll); OPENSSL_free(buf_out); } | 292 | { OPENSSL_cleanse((char *)buf_out,outll); OPENSSL_free(buf_out); } |
293 | return(outl); | 293 | return(outl); |
294 | } | 294 | } |
diff --git a/src/lib/libcrypto/asn1/a_strex.c b/src/lib/libcrypto/asn1/a_strex.c index 7ddb7662f1..1def6c6549 100644 --- a/src/lib/libcrypto/asn1/a_strex.c +++ b/src/lib/libcrypto/asn1/a_strex.c | |||
@@ -63,6 +63,7 @@ | |||
63 | #include <openssl/asn1.h> | 63 | #include <openssl/asn1.h> |
64 | 64 | ||
65 | #include "charmap.h" | 65 | #include "charmap.h" |
66 | #include "cryptlib.h" | ||
66 | 67 | ||
67 | /* ASN1_STRING_print_ex() and X509_NAME_print_ex(). | 68 | /* ASN1_STRING_print_ex() and X509_NAME_print_ex(). |
68 | * Enhanced string and name printing routines handling | 69 | * Enhanced string and name printing routines handling |
@@ -114,14 +115,17 @@ typedef int char_io(void *arg, const void *buf, int len); | |||
114 | static int do_esc_char(unsigned long c, unsigned char flags, char *do_quotes, char_io *io_ch, void *arg) | 115 | static int do_esc_char(unsigned long c, unsigned char flags, char *do_quotes, char_io *io_ch, void *arg) |
115 | { | 116 | { |
116 | unsigned char chflgs, chtmp; | 117 | unsigned char chflgs, chtmp; |
117 | char tmphex[11]; | 118 | char tmphex[HEX_SIZE(long)+3]; |
119 | |||
120 | if(c > 0xffffffffL) | ||
121 | return -1; | ||
118 | if(c > 0xffff) { | 122 | if(c > 0xffff) { |
119 | BIO_snprintf(tmphex, 11, "\\W%08lX", c); | 123 | BIO_snprintf(tmphex, sizeof tmphex, "\\W%08lX", c); |
120 | if(!io_ch(arg, tmphex, 10)) return -1; | 124 | if(!io_ch(arg, tmphex, 10)) return -1; |
121 | return 10; | 125 | return 10; |
122 | } | 126 | } |
123 | if(c > 0xff) { | 127 | if(c > 0xff) { |
124 | BIO_snprintf(tmphex, 11, "\\U%04lX", c); | 128 | BIO_snprintf(tmphex, sizeof tmphex, "\\U%04lX", c); |
125 | if(!io_ch(arg, tmphex, 6)) return -1; | 129 | if(!io_ch(arg, tmphex, 6)) return -1; |
126 | return 6; | 130 | return 6; |
127 | } | 131 | } |
@@ -195,7 +199,7 @@ static int do_buf(unsigned char *buf, int buflen, | |||
195 | if(type & BUF_TYPE_CONVUTF8) { | 199 | if(type & BUF_TYPE_CONVUTF8) { |
196 | unsigned char utfbuf[6]; | 200 | unsigned char utfbuf[6]; |
197 | int utflen; | 201 | int utflen; |
198 | utflen = UTF8_putc(utfbuf, 6, c); | 202 | utflen = UTF8_putc(utfbuf, sizeof utfbuf, c); |
199 | for(i = 0; i < utflen; i++) { | 203 | for(i = 0; i < utflen; i++) { |
200 | /* We don't need to worry about setting orflags correctly | 204 | /* We don't need to worry about setting orflags correctly |
201 | * because if utflen==1 its value will be correct anyway | 205 | * because if utflen==1 its value will be correct anyway |
@@ -461,7 +465,7 @@ static int do_name_ex(char_io *io_ch, void *arg, X509_NAME *n, | |||
461 | if(fn_opt != XN_FLAG_FN_NONE) { | 465 | if(fn_opt != XN_FLAG_FN_NONE) { |
462 | int objlen, fld_len; | 466 | int objlen, fld_len; |
463 | if((fn_opt == XN_FLAG_FN_OID) || (fn_nid==NID_undef) ) { | 467 | if((fn_opt == XN_FLAG_FN_OID) || (fn_nid==NID_undef) ) { |
464 | OBJ_obj2txt(objtmp, 80, fn, 1); | 468 | OBJ_obj2txt(objtmp, sizeof objtmp, fn, 1); |
465 | fld_len = 0; /* XXX: what should this be? */ | 469 | fld_len = 0; /* XXX: what should this be? */ |
466 | objbuf = objtmp; | 470 | objbuf = objtmp; |
467 | } else { | 471 | } else { |
diff --git a/src/lib/libcrypto/asn1/a_strnid.c b/src/lib/libcrypto/asn1/a_strnid.c index 04789d1c63..aa49e9d7d0 100644 --- a/src/lib/libcrypto/asn1/a_strnid.c +++ b/src/lib/libcrypto/asn1/a_strnid.c | |||
@@ -173,6 +173,7 @@ static ASN1_STRING_TABLE tbl_standard[] = { | |||
173 | {NID_friendlyName, -1, -1, B_ASN1_BMPSTRING, STABLE_NO_MASK}, | 173 | {NID_friendlyName, -1, -1, B_ASN1_BMPSTRING, STABLE_NO_MASK}, |
174 | {NID_name, 1, ub_name, DIRSTRING_TYPE, 0}, | 174 | {NID_name, 1, ub_name, DIRSTRING_TYPE, 0}, |
175 | {NID_dnQualifier, -1, -1, B_ASN1_PRINTABLESTRING, STABLE_NO_MASK}, | 175 | {NID_dnQualifier, -1, -1, B_ASN1_PRINTABLESTRING, STABLE_NO_MASK}, |
176 | {NID_domainComponent, 1, -1, B_ASN1_IA5STRING, STABLE_NO_MASK}, | ||
176 | {NID_ms_csp_name, -1, -1, B_ASN1_BMPSTRING, STABLE_NO_MASK} | 177 | {NID_ms_csp_name, -1, -1, B_ASN1_BMPSTRING, STABLE_NO_MASK} |
177 | }; | 178 | }; |
178 | 179 | ||
@@ -249,4 +250,38 @@ static void st_free(ASN1_STRING_TABLE *tbl) | |||
249 | if(tbl->flags & STABLE_FLAGS_MALLOC) OPENSSL_free(tbl); | 250 | if(tbl->flags & STABLE_FLAGS_MALLOC) OPENSSL_free(tbl); |
250 | } | 251 | } |
251 | 252 | ||
253 | |||
252 | IMPLEMENT_STACK_OF(ASN1_STRING_TABLE) | 254 | IMPLEMENT_STACK_OF(ASN1_STRING_TABLE) |
255 | |||
256 | #ifdef STRING_TABLE_TEST | ||
257 | |||
258 | main() | ||
259 | { | ||
260 | ASN1_STRING_TABLE *tmp; | ||
261 | int i, last_nid = -1; | ||
262 | |||
263 | for (tmp = tbl_standard, i = 0; | ||
264 | i < sizeof(tbl_standard)/sizeof(ASN1_STRING_TABLE); i++, tmp++) | ||
265 | { | ||
266 | if (tmp->nid < last_nid) | ||
267 | { | ||
268 | last_nid = 0; | ||
269 | break; | ||
270 | } | ||
271 | last_nid = tmp->nid; | ||
272 | } | ||
273 | |||
274 | if (last_nid != 0) | ||
275 | { | ||
276 | printf("Table order OK\n"); | ||
277 | exit(0); | ||
278 | } | ||
279 | |||
280 | for (tmp = tbl_standard, i = 0; | ||
281 | i < sizeof(tbl_standard)/sizeof(ASN1_STRING_TABLE); i++, tmp++) | ||
282 | printf("Index %d, NID %d, Name=%s\n", i, tmp->nid, | ||
283 | OBJ_nid2ln(tmp->nid)); | ||
284 | |||
285 | } | ||
286 | |||
287 | #endif | ||
diff --git a/src/lib/libcrypto/asn1/a_time.c b/src/lib/libcrypto/asn1/a_time.c index 27ddd30899..7348da9457 100644 --- a/src/lib/libcrypto/asn1/a_time.c +++ b/src/lib/libcrypto/asn1/a_time.c | |||
@@ -105,7 +105,10 @@ ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s, time_t t) | |||
105 | 105 | ||
106 | ts=OPENSSL_gmtime(&t,&data); | 106 | ts=OPENSSL_gmtime(&t,&data); |
107 | if (ts == NULL) | 107 | if (ts == NULL) |
108 | { | ||
109 | ASN1err(ASN1_F_ASN1_TIME_SET, ASN1_R_ERROR_GETTING_TIME); | ||
108 | return NULL; | 110 | return NULL; |
111 | } | ||
109 | if((ts->tm_year >= 50) && (ts->tm_year < 150)) | 112 | if((ts->tm_year >= 50) && (ts->tm_year < 150)) |
110 | return ASN1_UTCTIME_set(s, t); | 113 | return ASN1_UTCTIME_set(s, t); |
111 | return ASN1_GENERALIZEDTIME_set(s,t); | 114 | return ASN1_GENERALIZEDTIME_set(s,t); |
@@ -152,7 +155,7 @@ ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(ASN1_TIME *t, ASN1_GENERALIZE | |||
152 | if (t->data[0] >= '5') strcpy(str, "19"); | 155 | if (t->data[0] >= '5') strcpy(str, "19"); |
153 | else strcpy(str, "20"); | 156 | else strcpy(str, "20"); |
154 | 157 | ||
155 | strcat(str, (char *)t->data); | 158 | BUF_strlcat(str, (char *)t->data, t->length+3); /* Include space for a '\0' */ |
156 | 159 | ||
157 | return ret; | 160 | return ret; |
158 | } | 161 | } |
diff --git a/src/lib/libcrypto/asn1/a_type.c b/src/lib/libcrypto/asn1/a_type.c index 96e111cf23..fe3fcd40b0 100644 --- a/src/lib/libcrypto/asn1/a_type.c +++ b/src/lib/libcrypto/asn1/a_type.c | |||
@@ -62,7 +62,7 @@ | |||
62 | 62 | ||
63 | int ASN1_TYPE_get(ASN1_TYPE *a) | 63 | int ASN1_TYPE_get(ASN1_TYPE *a) |
64 | { | 64 | { |
65 | if (a->value.ptr != NULL) | 65 | if ((a->value.ptr != NULL) || (a->type == V_ASN1_NULL)) |
66 | return(a->type); | 66 | return(a->type); |
67 | else | 67 | else |
68 | return(0); | 68 | return(0); |
diff --git a/src/lib/libcrypto/asn1/a_verify.c b/src/lib/libcrypto/asn1/a_verify.c index bf41de5146..da2a0a6d69 100644 --- a/src/lib/libcrypto/asn1/a_verify.c +++ b/src/lib/libcrypto/asn1/a_verify.c | |||
@@ -103,7 +103,7 @@ int ASN1_verify(int (*i2d)(), X509_ALGOR *a, ASN1_BIT_STRING *signature, | |||
103 | EVP_VerifyInit_ex(&ctx,type, NULL); | 103 | EVP_VerifyInit_ex(&ctx,type, NULL); |
104 | EVP_VerifyUpdate(&ctx,(unsigned char *)buf_in,inl); | 104 | EVP_VerifyUpdate(&ctx,(unsigned char *)buf_in,inl); |
105 | 105 | ||
106 | memset(buf_in,0,(unsigned int)inl); | 106 | OPENSSL_cleanse(buf_in,(unsigned int)inl); |
107 | OPENSSL_free(buf_in); | 107 | OPENSSL_free(buf_in); |
108 | 108 | ||
109 | if (EVP_VerifyFinal(&ctx,(unsigned char *)signature->data, | 109 | if (EVP_VerifyFinal(&ctx,(unsigned char *)signature->data, |
@@ -153,7 +153,7 @@ int ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *a, ASN1_BIT_STRING *signat | |||
153 | EVP_VerifyInit_ex(&ctx,type, NULL); | 153 | EVP_VerifyInit_ex(&ctx,type, NULL); |
154 | EVP_VerifyUpdate(&ctx,(unsigned char *)buf_in,inl); | 154 | EVP_VerifyUpdate(&ctx,(unsigned char *)buf_in,inl); |
155 | 155 | ||
156 | memset(buf_in,0,(unsigned int)inl); | 156 | OPENSSL_cleanse(buf_in,(unsigned int)inl); |
157 | OPENSSL_free(buf_in); | 157 | OPENSSL_free(buf_in); |
158 | 158 | ||
159 | if (EVP_VerifyFinal(&ctx,(unsigned char *)signature->data, | 159 | if (EVP_VerifyFinal(&ctx,(unsigned char *)signature->data, |
diff --git a/src/lib/libcrypto/asn1/asn1.h b/src/lib/libcrypto/asn1/asn1.h index dbb30f4f22..3414509f1b 100644 --- a/src/lib/libcrypto/asn1/asn1.h +++ b/src/lib/libcrypto/asn1/asn1.h | |||
@@ -70,7 +70,6 @@ | |||
70 | 70 | ||
71 | #include <openssl/symhacks.h> | 71 | #include <openssl/symhacks.h> |
72 | 72 | ||
73 | #include <openssl/e_os2.h> | ||
74 | #include <openssl/ossl_typ.h> | 73 | #include <openssl/ossl_typ.h> |
75 | 74 | ||
76 | #ifdef OPENSSL_BUILD_SHLIBCRYPTO | 75 | #ifdef OPENSSL_BUILD_SHLIBCRYPTO |
@@ -133,7 +132,7 @@ extern "C" { | |||
133 | #define B_ASN1_NUMERICSTRING 0x0001 | 132 | #define B_ASN1_NUMERICSTRING 0x0001 |
134 | #define B_ASN1_PRINTABLESTRING 0x0002 | 133 | #define B_ASN1_PRINTABLESTRING 0x0002 |
135 | #define B_ASN1_T61STRING 0x0004 | 134 | #define B_ASN1_T61STRING 0x0004 |
136 | #define B_ASN1_TELETEXSTRING 0x0008 | 135 | #define B_ASN1_TELETEXSTRING 0x0004 |
137 | #define B_ASN1_VIDEOTEXSTRING 0x0008 | 136 | #define B_ASN1_VIDEOTEXSTRING 0x0008 |
138 | #define B_ASN1_IA5STRING 0x0010 | 137 | #define B_ASN1_IA5STRING 0x0010 |
139 | #define B_ASN1_GRAPHICSTRING 0x0020 | 138 | #define B_ASN1_GRAPHICSTRING 0x0020 |
@@ -981,6 +980,7 @@ void ERR_load_ASN1_strings(void); | |||
981 | #define ASN1_F_ASN1_TEMPLATE_D2I 131 | 980 | #define ASN1_F_ASN1_TEMPLATE_D2I 131 |
982 | #define ASN1_F_ASN1_TEMPLATE_EX_D2I 132 | 981 | #define ASN1_F_ASN1_TEMPLATE_EX_D2I 132 |
983 | #define ASN1_F_ASN1_TEMPLATE_NEW 133 | 982 | #define ASN1_F_ASN1_TEMPLATE_NEW 133 |
983 | #define ASN1_F_ASN1_TIME_SET 175 | ||
984 | #define ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING 134 | 984 | #define ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING 134 |
985 | #define ASN1_F_ASN1_TYPE_GET_OCTETSTRING 135 | 985 | #define ASN1_F_ASN1_TYPE_GET_OCTETSTRING 135 |
986 | #define ASN1_F_ASN1_UNPACK_STRING 136 | 986 | #define ASN1_F_ASN1_UNPACK_STRING 136 |
@@ -1038,6 +1038,7 @@ void ERR_load_ASN1_strings(void); | |||
1038 | #define ASN1_R_DECODE_ERROR 110 | 1038 | #define ASN1_R_DECODE_ERROR 110 |
1039 | #define ASN1_R_DECODING_ERROR 111 | 1039 | #define ASN1_R_DECODING_ERROR 111 |
1040 | #define ASN1_R_ENCODE_ERROR 112 | 1040 | #define ASN1_R_ENCODE_ERROR 112 |
1041 | #define ASN1_R_ERROR_GETTING_TIME 173 | ||
1041 | #define ASN1_R_ERROR_LOADING_SECTION 172 | 1042 | #define ASN1_R_ERROR_LOADING_SECTION 172 |
1042 | #define ASN1_R_ERROR_PARSING_SET_ELEMENT 113 | 1043 | #define ASN1_R_ERROR_PARSING_SET_ELEMENT 113 |
1043 | #define ASN1_R_ERROR_SETTING_CIPHER_PARAMS 114 | 1044 | #define ASN1_R_ERROR_SETTING_CIPHER_PARAMS 114 |
diff --git a/src/lib/libcrypto/asn1/asn1_err.c b/src/lib/libcrypto/asn1/asn1_err.c index c4c3d2a91d..094ec06fda 100644 --- a/src/lib/libcrypto/asn1/asn1_err.c +++ b/src/lib/libcrypto/asn1/asn1_err.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* crypto/asn1/asn1_err.c */ | 1 | /* crypto/asn1/asn1_err.c */ |
2 | /* ==================================================================== | 2 | /* ==================================================================== |
3 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | 3 | * Copyright (c) 1999-2002 The OpenSSL Project. All rights reserved. |
4 | * | 4 | * |
5 | * Redistribution and use in source and binary forms, with or without | 5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions | 6 | * modification, are permitted provided that the following conditions |
@@ -100,6 +100,7 @@ static ERR_STRING_DATA ASN1_str_functs[]= | |||
100 | {ERR_PACK(0,ASN1_F_ASN1_TEMPLATE_D2I,0), "ASN1_TEMPLATE_D2I"}, | 100 | {ERR_PACK(0,ASN1_F_ASN1_TEMPLATE_D2I,0), "ASN1_TEMPLATE_D2I"}, |
101 | {ERR_PACK(0,ASN1_F_ASN1_TEMPLATE_EX_D2I,0), "ASN1_TEMPLATE_EX_D2I"}, | 101 | {ERR_PACK(0,ASN1_F_ASN1_TEMPLATE_EX_D2I,0), "ASN1_TEMPLATE_EX_D2I"}, |
102 | {ERR_PACK(0,ASN1_F_ASN1_TEMPLATE_NEW,0), "ASN1_TEMPLATE_NEW"}, | 102 | {ERR_PACK(0,ASN1_F_ASN1_TEMPLATE_NEW,0), "ASN1_TEMPLATE_NEW"}, |
103 | {ERR_PACK(0,ASN1_F_ASN1_TIME_SET,0), "ASN1_TIME_set"}, | ||
103 | {ERR_PACK(0,ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING,0), "ASN1_TYPE_get_int_octetstring"}, | 104 | {ERR_PACK(0,ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING,0), "ASN1_TYPE_get_int_octetstring"}, |
104 | {ERR_PACK(0,ASN1_F_ASN1_TYPE_GET_OCTETSTRING,0), "ASN1_TYPE_get_octetstring"}, | 105 | {ERR_PACK(0,ASN1_F_ASN1_TYPE_GET_OCTETSTRING,0), "ASN1_TYPE_get_octetstring"}, |
105 | {ERR_PACK(0,ASN1_F_ASN1_UNPACK_STRING,0), "ASN1_unpack_string"}, | 106 | {ERR_PACK(0,ASN1_F_ASN1_UNPACK_STRING,0), "ASN1_unpack_string"}, |
@@ -160,6 +161,7 @@ static ERR_STRING_DATA ASN1_str_reasons[]= | |||
160 | {ASN1_R_DECODE_ERROR ,"decode error"}, | 161 | {ASN1_R_DECODE_ERROR ,"decode error"}, |
161 | {ASN1_R_DECODING_ERROR ,"decoding error"}, | 162 | {ASN1_R_DECODING_ERROR ,"decoding error"}, |
162 | {ASN1_R_ENCODE_ERROR ,"encode error"}, | 163 | {ASN1_R_ENCODE_ERROR ,"encode error"}, |
164 | {ASN1_R_ERROR_GETTING_TIME ,"error getting time"}, | ||
163 | {ASN1_R_ERROR_LOADING_SECTION ,"error loading section"}, | 165 | {ASN1_R_ERROR_LOADING_SECTION ,"error loading section"}, |
164 | {ASN1_R_ERROR_PARSING_SET_ELEMENT ,"error parsing set element"}, | 166 | {ASN1_R_ERROR_PARSING_SET_ELEMENT ,"error parsing set element"}, |
165 | {ASN1_R_ERROR_SETTING_CIPHER_PARAMS ,"error setting cipher params"}, | 167 | {ASN1_R_ERROR_SETTING_CIPHER_PARAMS ,"error setting cipher params"}, |
diff --git a/src/lib/libcrypto/asn1/asn1_par.c b/src/lib/libcrypto/asn1/asn1_par.c index facfdd27fc..e48532a24d 100644 --- a/src/lib/libcrypto/asn1/asn1_par.c +++ b/src/lib/libcrypto/asn1/asn1_par.c | |||
@@ -79,12 +79,7 @@ static int asn1_print_info(BIO *bp, int tag, int xclass, int constructed, | |||
79 | else | 79 | else |
80 | p="prim: "; | 80 | p="prim: "; |
81 | if (BIO_write(bp,p,6) < 6) goto err; | 81 | if (BIO_write(bp,p,6) < 6) goto err; |
82 | if (indent) | 82 | BIO_indent(bp,indent,128); |
83 | { | ||
84 | if (indent > 128) indent=128; | ||
85 | memset(str,' ',indent); | ||
86 | if (BIO_write(bp,str,indent) < indent) goto err; | ||
87 | } | ||
88 | 83 | ||
89 | p=str; | 84 | p=str; |
90 | if ((xclass & V_ASN1_PRIVATE) == V_ASN1_PRIVATE) | 85 | if ((xclass & V_ASN1_PRIVATE) == V_ASN1_PRIVATE) |
diff --git a/src/lib/libcrypto/asn1/f_int.c b/src/lib/libcrypto/asn1/f_int.c index 48cc3bfb90..9494e597ab 100644 --- a/src/lib/libcrypto/asn1/f_int.c +++ b/src/lib/libcrypto/asn1/f_int.c | |||
@@ -169,8 +169,7 @@ int a2i_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *bs, char *buf, int size) | |||
169 | sp=(unsigned char *)OPENSSL_malloc( | 169 | sp=(unsigned char *)OPENSSL_malloc( |
170 | (unsigned int)num+i*2); | 170 | (unsigned int)num+i*2); |
171 | else | 171 | else |
172 | sp=(unsigned char *)OPENSSL_realloc(s, | 172 | sp=OPENSSL_realloc_clean(s,slen,num+i*2); |
173 | (unsigned int)num+i*2); | ||
174 | if (sp == NULL) | 173 | if (sp == NULL) |
175 | { | 174 | { |
176 | ASN1err(ASN1_F_A2I_ASN1_INTEGER,ERR_R_MALLOC_FAILURE); | 175 | ASN1err(ASN1_F_A2I_ASN1_INTEGER,ERR_R_MALLOC_FAILURE); |
diff --git a/src/lib/libcrypto/asn1/n_pkey.c b/src/lib/libcrypto/asn1/n_pkey.c index 9146ee02c9..766b51c538 100644 --- a/src/lib/libcrypto/asn1/n_pkey.c +++ b/src/lib/libcrypto/asn1/n_pkey.c | |||
@@ -187,7 +187,7 @@ int i2d_RSA_NET(const RSA *a, unsigned char **pp, int (*cb)(), int sgckey) | |||
187 | i2d_NETSCAPE_PKEY(pkey,&zz); | 187 | i2d_NETSCAPE_PKEY(pkey,&zz); |
188 | 188 | ||
189 | /* Wipe the private key encoding */ | 189 | /* Wipe the private key encoding */ |
190 | memset(pkey->private_key->data, 0, rsalen); | 190 | OPENSSL_cleanse(pkey->private_key->data, rsalen); |
191 | 191 | ||
192 | if (cb == NULL) | 192 | if (cb == NULL) |
193 | cb=EVP_read_pw_string; | 193 | cb=EVP_read_pw_string; |
@@ -206,7 +206,7 @@ int i2d_RSA_NET(const RSA *a, unsigned char **pp, int (*cb)(), int sgckey) | |||
206 | } | 206 | } |
207 | 207 | ||
208 | EVP_BytesToKey(EVP_rc4(),EVP_md5(),NULL,buf,i,1,key,NULL); | 208 | EVP_BytesToKey(EVP_rc4(),EVP_md5(),NULL,buf,i,1,key,NULL); |
209 | memset(buf,0,256); | 209 | OPENSSL_cleanse(buf,256); |
210 | 210 | ||
211 | /* Encrypt private key in place */ | 211 | /* Encrypt private key in place */ |
212 | zz = enckey->enckey->digest->data; | 212 | zz = enckey->enckey->digest->data; |
@@ -294,7 +294,7 @@ static RSA *d2i_RSA_NET_2(RSA **a, ASN1_OCTET_STRING *os, | |||
294 | } | 294 | } |
295 | 295 | ||
296 | EVP_BytesToKey(EVP_rc4(),EVP_md5(),NULL,buf,i,1,key,NULL); | 296 | EVP_BytesToKey(EVP_rc4(),EVP_md5(),NULL,buf,i,1,key,NULL); |
297 | memset(buf,0,256); | 297 | OPENSSL_cleanse(buf,256); |
298 | 298 | ||
299 | EVP_CIPHER_CTX_init(&ctx); | 299 | EVP_CIPHER_CTX_init(&ctx); |
300 | EVP_DecryptInit_ex(&ctx,EVP_rc4(),NULL, key,NULL); | 300 | EVP_DecryptInit_ex(&ctx,EVP_rc4(),NULL, key,NULL); |
diff --git a/src/lib/libcrypto/asn1/p8_pkey.c b/src/lib/libcrypto/asn1/p8_pkey.c index b634d5bc85..24b409132f 100644 --- a/src/lib/libcrypto/asn1/p8_pkey.c +++ b/src/lib/libcrypto/asn1/p8_pkey.c | |||
@@ -68,8 +68,8 @@ static int pkey_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it) | |||
68 | if(operation == ASN1_OP_FREE_PRE) { | 68 | if(operation == ASN1_OP_FREE_PRE) { |
69 | PKCS8_PRIV_KEY_INFO *key = (PKCS8_PRIV_KEY_INFO *)*pval; | 69 | PKCS8_PRIV_KEY_INFO *key = (PKCS8_PRIV_KEY_INFO *)*pval; |
70 | if (key->pkey->value.octet_string) | 70 | if (key->pkey->value.octet_string) |
71 | memset(key->pkey->value.octet_string->data, | 71 | OPENSSL_cleanse(key->pkey->value.octet_string->data, |
72 | 0, key->pkey->value.octet_string->length); | 72 | key->pkey->value.octet_string->length); |
73 | } | 73 | } |
74 | return 1; | 74 | return 1; |
75 | } | 75 | } |
diff --git a/src/lib/libcrypto/asn1/t_crl.c b/src/lib/libcrypto/asn1/t_crl.c index 60db305756..757c148df8 100644 --- a/src/lib/libcrypto/asn1/t_crl.c +++ b/src/lib/libcrypto/asn1/t_crl.c | |||
@@ -84,11 +84,11 @@ int X509_CRL_print_fp(FILE *fp, X509_CRL *x) | |||
84 | 84 | ||
85 | int X509_CRL_print(BIO *out, X509_CRL *x) | 85 | int X509_CRL_print(BIO *out, X509_CRL *x) |
86 | { | 86 | { |
87 | char buf[256]; | ||
88 | STACK_OF(X509_REVOKED) *rev; | 87 | STACK_OF(X509_REVOKED) *rev; |
89 | X509_REVOKED *r; | 88 | X509_REVOKED *r; |
90 | long l; | 89 | long l; |
91 | int i, n; | 90 | int i, n; |
91 | char *p; | ||
92 | 92 | ||
93 | BIO_printf(out, "Certificate Revocation List (CRL):\n"); | 93 | BIO_printf(out, "Certificate Revocation List (CRL):\n"); |
94 | l = X509_CRL_get_version(x); | 94 | l = X509_CRL_get_version(x); |
@@ -96,8 +96,9 @@ int X509_CRL_print(BIO *out, X509_CRL *x) | |||
96 | i = OBJ_obj2nid(x->sig_alg->algorithm); | 96 | i = OBJ_obj2nid(x->sig_alg->algorithm); |
97 | BIO_printf(out, "%8sSignature Algorithm: %s\n", "", | 97 | BIO_printf(out, "%8sSignature Algorithm: %s\n", "", |
98 | (i == NID_undef) ? "NONE" : OBJ_nid2ln(i)); | 98 | (i == NID_undef) ? "NONE" : OBJ_nid2ln(i)); |
99 | X509_NAME_oneline(X509_CRL_get_issuer(x),buf,256); | 99 | p=X509_NAME_oneline(X509_CRL_get_issuer(x),NULL,0); |
100 | BIO_printf(out,"%8sIssuer: %s\n","",buf); | 100 | BIO_printf(out,"%8sIssuer: %s\n","",p); |
101 | OPENSSL_free(p); | ||
101 | BIO_printf(out,"%8sLast Update: ",""); | 102 | BIO_printf(out,"%8sLast Update: ",""); |
102 | ASN1_TIME_print(out,X509_CRL_get_lastUpdate(x)); | 103 | ASN1_TIME_print(out,X509_CRL_get_lastUpdate(x)); |
103 | BIO_printf(out,"\n%8sNext Update: ",""); | 104 | BIO_printf(out,"\n%8sNext Update: ",""); |
diff --git a/src/lib/libcrypto/asn1/t_pkey.c b/src/lib/libcrypto/asn1/t_pkey.c index 2d46914cb1..4e09c9e44e 100644 --- a/src/lib/libcrypto/asn1/t_pkey.c +++ b/src/lib/libcrypto/asn1/t_pkey.c | |||
@@ -130,14 +130,10 @@ int RSA_print(BIO *bp, const RSA *x, int off) | |||
130 | goto err; | 130 | goto err; |
131 | } | 131 | } |
132 | 132 | ||
133 | if (off) | ||
134 | { | ||
135 | if (off > 128) off=128; | ||
136 | memset(str,' ',off); | ||
137 | } | ||
138 | if (x->d != NULL) | 133 | if (x->d != NULL) |
139 | { | 134 | { |
140 | if (off && (BIO_write(bp,str,off) <= 0)) goto err; | 135 | if(!BIO_indent(bp,off,128)) |
136 | goto err; | ||
141 | if (BIO_printf(bp,"Private-Key: (%d bit)\n",BN_num_bits(x->n)) | 137 | if (BIO_printf(bp,"Private-Key: (%d bit)\n",BN_num_bits(x->n)) |
142 | <= 0) goto err; | 138 | <= 0) goto err; |
143 | } | 139 | } |
@@ -183,7 +179,6 @@ int DSA_print_fp(FILE *fp, const DSA *x, int off) | |||
183 | 179 | ||
184 | int DSA_print(BIO *bp, const DSA *x, int off) | 180 | int DSA_print(BIO *bp, const DSA *x, int off) |
185 | { | 181 | { |
186 | char str[128]; | ||
187 | unsigned char *m=NULL; | 182 | unsigned char *m=NULL; |
188 | int ret=0; | 183 | int ret=0; |
189 | size_t buf_len=0,i; | 184 | size_t buf_len=0,i; |
@@ -210,14 +205,10 @@ int DSA_print(BIO *bp, const DSA *x, int off) | |||
210 | goto err; | 205 | goto err; |
211 | } | 206 | } |
212 | 207 | ||
213 | if (off) | ||
214 | { | ||
215 | if (off > 128) off=128; | ||
216 | memset(str,' ',off); | ||
217 | } | ||
218 | if (x->priv_key != NULL) | 208 | if (x->priv_key != NULL) |
219 | { | 209 | { |
220 | if (off && (BIO_write(bp,str,off) <= 0)) goto err; | 210 | if(!BIO_indent(bp,off,128)) |
211 | goto err; | ||
221 | if (BIO_printf(bp,"Private-Key: (%d bit)\n",BN_num_bits(x->p)) | 212 | if (BIO_printf(bp,"Private-Key: (%d bit)\n",BN_num_bits(x->p)) |
222 | <= 0) goto err; | 213 | <= 0) goto err; |
223 | } | 214 | } |
@@ -240,17 +231,12 @@ static int print(BIO *bp, const char *number, BIGNUM *num, unsigned char *buf, | |||
240 | int off) | 231 | int off) |
241 | { | 232 | { |
242 | int n,i; | 233 | int n,i; |
243 | char str[128]; | ||
244 | const char *neg; | 234 | const char *neg; |
245 | 235 | ||
246 | if (num == NULL) return(1); | 236 | if (num == NULL) return(1); |
247 | neg=(num->neg)?"-":""; | 237 | neg=(num->neg)?"-":""; |
248 | if (off) | 238 | if(!BIO_indent(bp,off,128)) |
249 | { | 239 | return 0; |
250 | if (off > 128) off=128; | ||
251 | memset(str,' ',off); | ||
252 | if (BIO_write(bp,str,off) <= 0) return(0); | ||
253 | } | ||
254 | 240 | ||
255 | if (BN_num_bytes(num) <= BN_BYTES) | 241 | if (BN_num_bytes(num) <= BN_BYTES) |
256 | { | 242 | { |
@@ -274,9 +260,9 @@ static int print(BIO *bp, const char *number, BIGNUM *num, unsigned char *buf, | |||
274 | { | 260 | { |
275 | if ((i%15) == 0) | 261 | if ((i%15) == 0) |
276 | { | 262 | { |
277 | str[0]='\n'; | 263 | if(BIO_puts(bp,"\n") <= 0 |
278 | memset(&(str[1]),' ',off+4); | 264 | || !BIO_indent(bp,off+4,128)) |
279 | if (BIO_write(bp,str,off+1+4) <= 0) return(0); | 265 | return 0; |
280 | } | 266 | } |
281 | if (BIO_printf(bp,"%02x%s",buf[i],((i+1) == n)?"":":") | 267 | if (BIO_printf(bp,"%02x%s",buf[i],((i+1) == n)?"":":") |
282 | <= 0) return(0); | 268 | <= 0) return(0); |
diff --git a/src/lib/libcrypto/asn1/t_req.c b/src/lib/libcrypto/asn1/t_req.c index 739f272ecf..740cee80c0 100644 --- a/src/lib/libcrypto/asn1/t_req.c +++ b/src/lib/libcrypto/asn1/t_req.c | |||
@@ -91,7 +91,6 @@ int X509_REQ_print_ex(BIO *bp, X509_REQ *x, unsigned long nmflags, unsigned long | |||
91 | EVP_PKEY *pkey; | 91 | EVP_PKEY *pkey; |
92 | STACK_OF(X509_ATTRIBUTE) *sk; | 92 | STACK_OF(X509_ATTRIBUTE) *sk; |
93 | STACK_OF(X509_EXTENSION) *exts; | 93 | STACK_OF(X509_EXTENSION) *exts; |
94 | char str[128]; | ||
95 | char mlch = ' '; | 94 | char mlch = ' '; |
96 | int nmindent = 0; | 95 | int nmindent = 0; |
97 | 96 | ||
@@ -116,8 +115,9 @@ int X509_REQ_print_ex(BIO *bp, X509_REQ *x, unsigned long nmflags, unsigned long | |||
116 | l=0; | 115 | l=0; |
117 | for (i=0; i<ri->version->length; i++) | 116 | for (i=0; i<ri->version->length; i++) |
118 | { l<<=8; l+=ri->version->data[i]; } | 117 | { l<<=8; l+=ri->version->data[i]; } |
119 | sprintf(str,"%8sVersion: %s%lu (%s0x%lx)\n","",neg,l,neg,l); | 118 | if(BIO_printf(bp,"%8sVersion: %s%lu (%s0x%lx)\n","",neg,l,neg, |
120 | if (BIO_puts(bp,str) <= 0) goto err; | 119 | l) <= 0) |
120 | goto err; | ||
121 | } | 121 | } |
122 | if(!(cflag & X509_FLAG_NO_SUBJECT)) | 122 | if(!(cflag & X509_FLAG_NO_SUBJECT)) |
123 | { | 123 | { |
@@ -168,14 +168,14 @@ int X509_REQ_print_ex(BIO *bp, X509_REQ *x, unsigned long nmflags, unsigned long | |||
168 | if(!(cflag & X509_FLAG_NO_ATTRIBUTES)) | 168 | if(!(cflag & X509_FLAG_NO_ATTRIBUTES)) |
169 | { | 169 | { |
170 | /* may not be */ | 170 | /* may not be */ |
171 | sprintf(str,"%8sAttributes:\n",""); | 171 | if(BIO_printf(bp,"%8sAttributes:\n","") <= 0) |
172 | if (BIO_puts(bp,str) <= 0) goto err; | 172 | goto err; |
173 | 173 | ||
174 | sk=x->req_info->attributes; | 174 | sk=x->req_info->attributes; |
175 | if (sk_X509_ATTRIBUTE_num(sk) == 0) | 175 | if (sk_X509_ATTRIBUTE_num(sk) == 0) |
176 | { | 176 | { |
177 | sprintf(str,"%12sa0:00\n",""); | 177 | if(BIO_printf(bp,"%12sa0:00\n","") <= 0) |
178 | if (BIO_puts(bp,str) <= 0) goto err; | 178 | goto err; |
179 | } | 179 | } |
180 | else | 180 | else |
181 | { | 181 | { |
@@ -190,8 +190,8 @@ int X509_REQ_print_ex(BIO *bp, X509_REQ *x, unsigned long nmflags, unsigned long | |||
190 | a=sk_X509_ATTRIBUTE_value(sk,i); | 190 | a=sk_X509_ATTRIBUTE_value(sk,i); |
191 | if(X509_REQ_extension_nid(OBJ_obj2nid(a->object))) | 191 | if(X509_REQ_extension_nid(OBJ_obj2nid(a->object))) |
192 | continue; | 192 | continue; |
193 | sprintf(str,"%12s",""); | 193 | if(BIO_printf(bp,"%12s","") <= 0) |
194 | if (BIO_puts(bp,str) <= 0) goto err; | 194 | goto err; |
195 | if ((j=i2a_ASN1_OBJECT(bp,a->object)) > 0) | 195 | if ((j=i2a_ASN1_OBJECT(bp,a->object)) > 0) |
196 | { | 196 | { |
197 | if (a->single) | 197 | if (a->single) |
diff --git a/src/lib/libcrypto/asn1/t_x509.c b/src/lib/libcrypto/asn1/t_x509.c index 5de4833ed0..d1034c47f8 100644 --- a/src/lib/libcrypto/asn1/t_x509.c +++ b/src/lib/libcrypto/asn1/t_x509.c | |||
@@ -433,15 +433,17 @@ err: | |||
433 | 433 | ||
434 | int X509_NAME_print(BIO *bp, X509_NAME *name, int obase) | 434 | int X509_NAME_print(BIO *bp, X509_NAME *name, int obase) |
435 | { | 435 | { |
436 | char *s,*c; | 436 | char *s,*c,*b; |
437 | int ret=0,l,ll,i,first=1; | 437 | int ret=0,l,ll,i,first=1; |
438 | char buf[256]; | ||
439 | 438 | ||
440 | ll=80-2-obase; | 439 | ll=80-2-obase; |
441 | 440 | ||
442 | s=X509_NAME_oneline(name,buf,256); | 441 | b=s=X509_NAME_oneline(name,NULL,0); |
443 | if (!*s) | 442 | if (!*s) |
443 | { | ||
444 | OPENSSL_free(b); | ||
444 | return 1; | 445 | return 1; |
446 | } | ||
445 | s++; /* skip the first slash */ | 447 | s++; /* skip the first slash */ |
446 | 448 | ||
447 | l=ll; | 449 | l=ll; |
@@ -497,6 +499,7 @@ int X509_NAME_print(BIO *bp, X509_NAME *name, int obase) | |||
497 | err: | 499 | err: |
498 | X509err(X509_F_X509_NAME_PRINT,ERR_R_BUF_LIB); | 500 | X509err(X509_F_X509_NAME_PRINT,ERR_R_BUF_LIB); |
499 | } | 501 | } |
502 | OPENSSL_free(b); | ||
500 | return(ret); | 503 | return(ret); |
501 | } | 504 | } |
502 | 505 | ||
diff --git a/src/lib/libcrypto/asn1/t_x509a.c b/src/lib/libcrypto/asn1/t_x509a.c index 7d4a6e6084..ffbbfb51f4 100644 --- a/src/lib/libcrypto/asn1/t_x509a.c +++ b/src/lib/libcrypto/asn1/t_x509a.c | |||
@@ -77,7 +77,7 @@ int X509_CERT_AUX_print(BIO *out, X509_CERT_AUX *aux, int indent) | |||
77 | for(i = 0; i < sk_ASN1_OBJECT_num(aux->trust); i++) { | 77 | for(i = 0; i < sk_ASN1_OBJECT_num(aux->trust); i++) { |
78 | if(!first) BIO_puts(out, ", "); | 78 | if(!first) BIO_puts(out, ", "); |
79 | else first = 0; | 79 | else first = 0; |
80 | OBJ_obj2txt(oidstr, 80, | 80 | OBJ_obj2txt(oidstr, sizeof oidstr, |
81 | sk_ASN1_OBJECT_value(aux->trust, i), 0); | 81 | sk_ASN1_OBJECT_value(aux->trust, i), 0); |
82 | BIO_puts(out, oidstr); | 82 | BIO_puts(out, oidstr); |
83 | } | 83 | } |
@@ -90,7 +90,7 @@ int X509_CERT_AUX_print(BIO *out, X509_CERT_AUX *aux, int indent) | |||
90 | for(i = 0; i < sk_ASN1_OBJECT_num(aux->reject); i++) { | 90 | for(i = 0; i < sk_ASN1_OBJECT_num(aux->reject); i++) { |
91 | if(!first) BIO_puts(out, ", "); | 91 | if(!first) BIO_puts(out, ", "); |
92 | else first = 0; | 92 | else first = 0; |
93 | OBJ_obj2txt(oidstr, 80, | 93 | OBJ_obj2txt(oidstr, sizeof oidstr, |
94 | sk_ASN1_OBJECT_value(aux->reject, i), 0); | 94 | sk_ASN1_OBJECT_value(aux->reject, i), 0); |
95 | BIO_puts(out, oidstr); | 95 | BIO_puts(out, oidstr); |
96 | } | 96 | } |
diff --git a/src/lib/libcrypto/asn1/tasn_dec.c b/src/lib/libcrypto/asn1/tasn_dec.c index f87c08793a..76fc023230 100644 --- a/src/lib/libcrypto/asn1/tasn_dec.c +++ b/src/lib/libcrypto/asn1/tasn_dec.c | |||
@@ -664,7 +664,7 @@ static int asn1_d2i_ex_primitive(ASN1_VALUE **pval, unsigned char **in, long inl | |||
664 | if(!asn1_collect(&buf, &p, plen, inf, -1, V_ASN1_UNIVERSAL)) goto err; | 664 | if(!asn1_collect(&buf, &p, plen, inf, -1, V_ASN1_UNIVERSAL)) goto err; |
665 | len = buf.length; | 665 | len = buf.length; |
666 | /* Append a final null to string */ | 666 | /* Append a final null to string */ |
667 | if(!BUF_MEM_grow(&buf, len + 1)) { | 667 | if(!BUF_MEM_grow_clean(&buf, len + 1)) { |
668 | ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ERR_R_MALLOC_FAILURE); | 668 | ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ERR_R_MALLOC_FAILURE); |
669 | return 0; | 669 | return 0; |
670 | } | 670 | } |
@@ -857,7 +857,7 @@ static int collect_data(BUF_MEM *buf, unsigned char **p, long plen) | |||
857 | int len; | 857 | int len; |
858 | if(buf) { | 858 | if(buf) { |
859 | len = buf->length; | 859 | len = buf->length; |
860 | if(!BUF_MEM_grow(buf, len + plen)) { | 860 | if(!BUF_MEM_grow_clean(buf, len + plen)) { |
861 | ASN1err(ASN1_F_COLLECT_DATA, ERR_R_MALLOC_FAILURE); | 861 | ASN1err(ASN1_F_COLLECT_DATA, ERR_R_MALLOC_FAILURE); |
862 | return 0; | 862 | return 0; |
863 | } | 863 | } |
diff --git a/src/lib/libcrypto/asn1/tasn_fre.c b/src/lib/libcrypto/asn1/tasn_fre.c index c7610776f2..2dd844159e 100644 --- a/src/lib/libcrypto/asn1/tasn_fre.c +++ b/src/lib/libcrypto/asn1/tasn_fre.c | |||
@@ -206,7 +206,10 @@ void ASN1_primitive_free(ASN1_VALUE **pval, const ASN1_ITEM *it) | |||
206 | break; | 206 | break; |
207 | 207 | ||
208 | case V_ASN1_BOOLEAN: | 208 | case V_ASN1_BOOLEAN: |
209 | *(ASN1_BOOLEAN *)pval = it->size; | 209 | if (it) |
210 | *(ASN1_BOOLEAN *)pval = it->size; | ||
211 | else | ||
212 | *(ASN1_BOOLEAN *)pval = -1; | ||
210 | return; | 213 | return; |
211 | 214 | ||
212 | case V_ASN1_NULL: | 215 | case V_ASN1_NULL: |
diff --git a/src/lib/libcrypto/asn1/tasn_new.c b/src/lib/libcrypto/asn1/tasn_new.c index e33861f864..a0e3db574f 100644 --- a/src/lib/libcrypto/asn1/tasn_new.c +++ b/src/lib/libcrypto/asn1/tasn_new.c | |||
@@ -305,7 +305,10 @@ int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it) | |||
305 | return 1; | 305 | return 1; |
306 | 306 | ||
307 | case V_ASN1_BOOLEAN: | 307 | case V_ASN1_BOOLEAN: |
308 | *(ASN1_BOOLEAN *)pval = it->size; | 308 | if (it) |
309 | *(ASN1_BOOLEAN *)pval = it->size; | ||
310 | else | ||
311 | *(ASN1_BOOLEAN *)pval = -1; | ||
309 | return 1; | 312 | return 1; |
310 | 313 | ||
311 | case V_ASN1_NULL: | 314 | case V_ASN1_NULL: |
diff --git a/src/lib/libcrypto/asn1/tasn_prn.c b/src/lib/libcrypto/asn1/tasn_prn.c index fab67ae5ac..719639b511 100644 --- a/src/lib/libcrypto/asn1/tasn_prn.c +++ b/src/lib/libcrypto/asn1/tasn_prn.c | |||
@@ -186,7 +186,7 @@ if(*bool == -1) printf("BOOL MISSING\n"); | |||
186 | char objbuf[80], *ln; | 186 | char objbuf[80], *ln; |
187 | ln = OBJ_nid2ln(OBJ_obj2nid(fld)); | 187 | ln = OBJ_nid2ln(OBJ_obj2nid(fld)); |
188 | if(!ln) ln = ""; | 188 | if(!ln) ln = ""; |
189 | OBJ_obj2txt(objbuf, 80, fld, 1); | 189 | OBJ_obj2txt(objbuf, sizeof objbuf, fld, 1); |
190 | BIO_printf(out, "%*s%s:%s (%s)", indent, "", "OBJECT", ln, objbuf); | 190 | BIO_printf(out, "%*s%s:%s (%s)", indent, "", "OBJECT", ln, objbuf); |
191 | } else { | 191 | } else { |
192 | BIO_printf(out, "%*s%s:", indent, "", name); | 192 | BIO_printf(out, "%*s%s:", indent, "", name); |
diff --git a/src/lib/libcrypto/bio/b_print.c b/src/lib/libcrypto/bio/b_print.c index 80c9cb69db..a9e552f245 100644 --- a/src/lib/libcrypto/bio/b_print.c +++ b/src/lib/libcrypto/bio/b_print.c | |||
@@ -378,7 +378,7 @@ _dopr( | |||
378 | case 'p': | 378 | case 'p': |
379 | value = (long)va_arg(args, void *); | 379 | value = (long)va_arg(args, void *); |
380 | fmtint(sbuffer, buffer, &currlen, maxlen, | 380 | fmtint(sbuffer, buffer, &currlen, maxlen, |
381 | value, 16, min, max, flags); | 381 | value, 16, min, max, flags|DP_F_NUM); |
382 | break; | 382 | break; |
383 | case 'n': /* XXX */ | 383 | case 'n': /* XXX */ |
384 | if (cflags == DP_C_SHORT) { | 384 | if (cflags == DP_C_SHORT) { |
@@ -482,8 +482,9 @@ fmtint( | |||
482 | int flags) | 482 | int flags) |
483 | { | 483 | { |
484 | int signvalue = 0; | 484 | int signvalue = 0; |
485 | char *prefix = ""; | ||
485 | unsigned LLONG uvalue; | 486 | unsigned LLONG uvalue; |
486 | char convert[20]; | 487 | char convert[DECIMAL_SIZE(value)+3]; |
487 | int place = 0; | 488 | int place = 0; |
488 | int spadlen = 0; | 489 | int spadlen = 0; |
489 | int zpadlen = 0; | 490 | int zpadlen = 0; |
@@ -501,6 +502,10 @@ fmtint( | |||
501 | else if (flags & DP_F_SPACE) | 502 | else if (flags & DP_F_SPACE) |
502 | signvalue = ' '; | 503 | signvalue = ' '; |
503 | } | 504 | } |
505 | if (flags & DP_F_NUM) { | ||
506 | if (base == 8) prefix = "0"; | ||
507 | if (base == 16) prefix = "0x"; | ||
508 | } | ||
504 | if (flags & DP_F_UP) | 509 | if (flags & DP_F_UP) |
505 | caps = 1; | 510 | caps = 1; |
506 | do { | 511 | do { |
@@ -508,13 +513,13 @@ fmtint( | |||
508 | (caps ? "0123456789ABCDEF" : "0123456789abcdef") | 513 | (caps ? "0123456789ABCDEF" : "0123456789abcdef") |
509 | [uvalue % (unsigned) base]; | 514 | [uvalue % (unsigned) base]; |
510 | uvalue = (uvalue / (unsigned) base); | 515 | uvalue = (uvalue / (unsigned) base); |
511 | } while (uvalue && (place < 20)); | 516 | } while (uvalue && (place < sizeof convert)); |
512 | if (place == 20) | 517 | if (place == sizeof convert) |
513 | place--; | 518 | place--; |
514 | convert[place] = 0; | 519 | convert[place] = 0; |
515 | 520 | ||
516 | zpadlen = max - place; | 521 | zpadlen = max - place; |
517 | spadlen = min - OSSL_MAX(max, place) - (signvalue ? 1 : 0); | 522 | spadlen = min - OSSL_MAX(max, place) - (signvalue ? 1 : 0) - strlen(prefix); |
518 | if (zpadlen < 0) | 523 | if (zpadlen < 0) |
519 | zpadlen = 0; | 524 | zpadlen = 0; |
520 | if (spadlen < 0) | 525 | if (spadlen < 0) |
@@ -536,6 +541,12 @@ fmtint( | |||
536 | if (signvalue) | 541 | if (signvalue) |
537 | doapr_outch(sbuffer, buffer, currlen, maxlen, signvalue); | 542 | doapr_outch(sbuffer, buffer, currlen, maxlen, signvalue); |
538 | 543 | ||
544 | /* prefix */ | ||
545 | while (*prefix) { | ||
546 | doapr_outch(sbuffer, buffer, currlen, maxlen, *prefix); | ||
547 | prefix++; | ||
548 | } | ||
549 | |||
539 | /* zeros */ | 550 | /* zeros */ |
540 | if (zpadlen > 0) { | 551 | if (zpadlen > 0) { |
541 | while (zpadlen > 0) { | 552 | while (zpadlen > 0) { |
@@ -641,8 +652,8 @@ fmtfp( | |||
641 | (caps ? "0123456789ABCDEF" | 652 | (caps ? "0123456789ABCDEF" |
642 | : "0123456789abcdef")[intpart % 10]; | 653 | : "0123456789abcdef")[intpart % 10]; |
643 | intpart = (intpart / 10); | 654 | intpart = (intpart / 10); |
644 | } while (intpart && (iplace < 20)); | 655 | } while (intpart && (iplace < sizeof iplace)); |
645 | if (iplace == 20) | 656 | if (iplace == sizeof iplace) |
646 | iplace--; | 657 | iplace--; |
647 | iconvert[iplace] = 0; | 658 | iconvert[iplace] = 0; |
648 | 659 | ||
@@ -653,7 +664,7 @@ fmtfp( | |||
653 | : "0123456789abcdef")[fracpart % 10]; | 664 | : "0123456789abcdef")[fracpart % 10]; |
654 | fracpart = (fracpart / 10); | 665 | fracpart = (fracpart / 10); |
655 | } while (fplace < max); | 666 | } while (fplace < max); |
656 | if (fplace == 20) | 667 | if (fplace == sizeof fplace) |
657 | fplace--; | 668 | fplace--; |
658 | fconvert[fplace] = 0; | 669 | fconvert[fplace] = 0; |
659 | 670 | ||
@@ -692,7 +703,7 @@ fmtfp( | |||
692 | * Decimal point. This should probably use locale to find the correct | 703 | * Decimal point. This should probably use locale to find the correct |
693 | * char to print out. | 704 | * char to print out. |
694 | */ | 705 | */ |
695 | if (max > 0) { | 706 | if (max > 0 || (flags & DP_F_NUM)) { |
696 | doapr_outch(sbuffer, buffer, currlen, maxlen, '.'); | 707 | doapr_outch(sbuffer, buffer, currlen, maxlen, '.'); |
697 | 708 | ||
698 | while (fplace > 0) | 709 | while (fplace > 0) |
diff --git a/src/lib/libcrypto/bio/b_sock.c b/src/lib/libcrypto/bio/b_sock.c index 45bd7c47e8..601a14f37c 100644 --- a/src/lib/libcrypto/bio/b_sock.c +++ b/src/lib/libcrypto/bio/b_sock.c | |||
@@ -83,6 +83,7 @@ | |||
83 | static int wsa_init_done=0; | 83 | static int wsa_init_done=0; |
84 | #endif | 84 | #endif |
85 | 85 | ||
86 | #if 0 | ||
86 | static unsigned long BIO_ghbn_hits=0L; | 87 | static unsigned long BIO_ghbn_hits=0L; |
87 | static unsigned long BIO_ghbn_miss=0L; | 88 | static unsigned long BIO_ghbn_miss=0L; |
88 | 89 | ||
@@ -93,6 +94,7 @@ static struct ghbn_cache_st | |||
93 | struct hostent *ent; | 94 | struct hostent *ent; |
94 | unsigned long order; | 95 | unsigned long order; |
95 | } ghbn_cache[GHBN_NUM]; | 96 | } ghbn_cache[GHBN_NUM]; |
97 | #endif | ||
96 | 98 | ||
97 | static int get_ip(const char *str,unsigned char *ip); | 99 | static int get_ip(const char *str,unsigned char *ip); |
98 | #if 0 | 100 | #if 0 |
@@ -230,6 +232,7 @@ int BIO_sock_error(int sock) | |||
230 | return(j); | 232 | return(j); |
231 | } | 233 | } |
232 | 234 | ||
235 | #if 0 | ||
233 | long BIO_ghbn_ctrl(int cmd, int iarg, char *parg) | 236 | long BIO_ghbn_ctrl(int cmd, int iarg, char *parg) |
234 | { | 237 | { |
235 | int i; | 238 | int i; |
@@ -267,6 +270,7 @@ long BIO_ghbn_ctrl(int cmd, int iarg, char *parg) | |||
267 | } | 270 | } |
268 | return(1); | 271 | return(1); |
269 | } | 272 | } |
273 | #endif | ||
270 | 274 | ||
271 | #if 0 | 275 | #if 0 |
272 | static struct hostent *ghbn_dup(struct hostent *a) | 276 | static struct hostent *ghbn_dup(struct hostent *a) |
@@ -463,6 +467,12 @@ int BIO_sock_init(void) | |||
463 | } | 467 | } |
464 | } | 468 | } |
465 | #endif /* OPENSSL_SYS_WINDOWS */ | 469 | #endif /* OPENSSL_SYS_WINDOWS */ |
470 | #ifdef WATT32 | ||
471 | extern int _watt_do_exit; | ||
472 | _watt_do_exit = 0; /* don't make sock_init() call exit() */ | ||
473 | if (sock_init()) | ||
474 | return (-1); | ||
475 | #endif | ||
466 | return(1); | 476 | return(1); |
467 | } | 477 | } |
468 | 478 | ||
@@ -472,7 +482,9 @@ void BIO_sock_cleanup(void) | |||
472 | if (wsa_init_done) | 482 | if (wsa_init_done) |
473 | { | 483 | { |
474 | wsa_init_done=0; | 484 | wsa_init_done=0; |
485 | #ifndef OPENSSL_SYS_WINCE | ||
475 | WSACancelBlockingCall(); | 486 | WSACancelBlockingCall(); |
487 | #endif | ||
476 | WSACleanup(); | 488 | WSACleanup(); |
477 | } | 489 | } |
478 | #endif | 490 | #endif |
@@ -480,7 +492,7 @@ void BIO_sock_cleanup(void) | |||
480 | 492 | ||
481 | #if !defined(OPENSSL_SYS_VMS) || __VMS_VER >= 70000000 | 493 | #if !defined(OPENSSL_SYS_VMS) || __VMS_VER >= 70000000 |
482 | 494 | ||
483 | int BIO_socket_ioctl(int fd, long type, unsigned long *arg) | 495 | int BIO_socket_ioctl(int fd, long type, void *arg) |
484 | { | 496 | { |
485 | int i; | 497 | int i; |
486 | 498 | ||
@@ -730,7 +742,7 @@ int BIO_set_tcp_ndelay(int s, int on) | |||
730 | int BIO_socket_nbio(int s, int mode) | 742 | int BIO_socket_nbio(int s, int mode) |
731 | { | 743 | { |
732 | int ret= -1; | 744 | int ret= -1; |
733 | unsigned long l; | 745 | int l; |
734 | 746 | ||
735 | l=mode; | 747 | l=mode; |
736 | #ifdef FIONBIO | 748 | #ifdef FIONBIO |
diff --git a/src/lib/libcrypto/bio/bf_buff.c b/src/lib/libcrypto/bio/bf_buff.c index 6ccda06596..1cecd70579 100644 --- a/src/lib/libcrypto/bio/bf_buff.c +++ b/src/lib/libcrypto/bio/bf_buff.c | |||
@@ -482,7 +482,7 @@ static int buffer_gets(BIO *b, char *buf, int size) | |||
482 | size-=i; | 482 | size-=i; |
483 | ctx->ibuf_len-=i; | 483 | ctx->ibuf_len-=i; |
484 | ctx->ibuf_off+=i; | 484 | ctx->ibuf_off+=i; |
485 | if ((flag) || (i == size)) | 485 | if (flag || size == 0) |
486 | { | 486 | { |
487 | *buf='\0'; | 487 | *buf='\0'; |
488 | return(num); | 488 | return(num); |
diff --git a/src/lib/libcrypto/bio/bio.h b/src/lib/libcrypto/bio/bio.h index c5caf253c9..fbbc16d00c 100644 --- a/src/lib/libcrypto/bio/bio.h +++ b/src/lib/libcrypto/bio/bio.h | |||
@@ -244,7 +244,7 @@ typedef struct bio_method_st | |||
244 | long (_far *ctrl)(); | 244 | long (_far *ctrl)(); |
245 | int (_far *create)(); | 245 | int (_far *create)(); |
246 | int (_far *destroy)(); | 246 | int (_far *destroy)(); |
247 | long (_fat *callback_ctrl)(); | 247 | long (_far *callback_ctrl)(); |
248 | } BIO_METHOD; | 248 | } BIO_METHOD; |
249 | #endif | 249 | #endif |
250 | 250 | ||
@@ -522,6 +522,7 @@ int BIO_read(BIO *b, void *data, int len); | |||
522 | int BIO_gets(BIO *bp,char *buf, int size); | 522 | int BIO_gets(BIO *bp,char *buf, int size); |
523 | int BIO_write(BIO *b, const void *data, int len); | 523 | int BIO_write(BIO *b, const void *data, int len); |
524 | int BIO_puts(BIO *bp,const char *buf); | 524 | int BIO_puts(BIO *bp,const char *buf); |
525 | int BIO_indent(BIO *b,int indent,int max); | ||
525 | long BIO_ctrl(BIO *bp,int cmd,long larg,void *parg); | 526 | long BIO_ctrl(BIO *bp,int cmd,long larg,void *parg); |
526 | long BIO_callback_ctrl(BIO *b, int cmd, void (*fp)(struct bio_st *, int, const char *, int, long, long)); | 527 | long BIO_callback_ctrl(BIO *b, int cmd, void (*fp)(struct bio_st *, int, const char *, int, long, long)); |
527 | char * BIO_ptr_ctrl(BIO *bp,int cmd,long larg); | 528 | char * BIO_ptr_ctrl(BIO *bp,int cmd,long larg); |
@@ -584,7 +585,7 @@ struct hostent *BIO_gethostbyname(const char *name); | |||
584 | * and an appropriate error code is set). | 585 | * and an appropriate error code is set). |
585 | */ | 586 | */ |
586 | int BIO_sock_error(int sock); | 587 | int BIO_sock_error(int sock); |
587 | int BIO_socket_ioctl(int fd, long type, unsigned long *arg); | 588 | int BIO_socket_ioctl(int fd, long type, void *arg); |
588 | int BIO_socket_nbio(int fd,int mode); | 589 | int BIO_socket_nbio(int fd,int mode); |
589 | int BIO_get_port(const char *str, unsigned short *port_ptr); | 590 | int BIO_get_port(const char *str, unsigned short *port_ptr); |
590 | int BIO_get_host_ip(const char *str, unsigned char *ip); | 591 | int BIO_get_host_ip(const char *str, unsigned char *ip); |
@@ -608,7 +609,7 @@ int BIO_new_bio_pair(BIO **bio1, size_t writebuf1, | |||
608 | 609 | ||
609 | void BIO_copy_next_retry(BIO *b); | 610 | void BIO_copy_next_retry(BIO *b); |
610 | 611 | ||
611 | long BIO_ghbn_ctrl(int cmd,int iarg,char *parg); | 612 | /*long BIO_ghbn_ctrl(int cmd,int iarg,char *parg);*/ |
612 | 613 | ||
613 | int BIO_printf(BIO *bio, const char *format, ...); | 614 | int BIO_printf(BIO *bio, const char *format, ...); |
614 | int BIO_vprintf(BIO *bio, const char *format, va_list args); | 615 | int BIO_vprintf(BIO *bio, const char *format, va_list args); |
diff --git a/src/lib/libcrypto/bio/bio_lib.c b/src/lib/libcrypto/bio/bio_lib.c index 50df2238fa..692c8fb5c6 100644 --- a/src/lib/libcrypto/bio/bio_lib.c +++ b/src/lib/libcrypto/bio/bio_lib.c | |||
@@ -272,6 +272,18 @@ int BIO_gets(BIO *b, char *in, int inl) | |||
272 | return(i); | 272 | return(i); |
273 | } | 273 | } |
274 | 274 | ||
275 | int BIO_indent(BIO *b,int indent,int max) | ||
276 | { | ||
277 | if(indent < 0) | ||
278 | indent=0; | ||
279 | if(indent > max) | ||
280 | indent=max; | ||
281 | while(indent--) | ||
282 | if(BIO_puts(b," ") != 1) | ||
283 | return 0; | ||
284 | return 1; | ||
285 | } | ||
286 | |||
275 | long BIO_int_ctrl(BIO *b, int cmd, long larg, int iarg) | 287 | long BIO_int_ctrl(BIO *b, int cmd, long larg, int iarg) |
276 | { | 288 | { |
277 | int i; | 289 | int i; |
@@ -383,6 +395,8 @@ BIO *BIO_pop(BIO *b) | |||
383 | if (b == NULL) return(NULL); | 395 | if (b == NULL) return(NULL); |
384 | ret=b->next_bio; | 396 | ret=b->next_bio; |
385 | 397 | ||
398 | BIO_ctrl(b,BIO_CTRL_POP,0,NULL); | ||
399 | |||
386 | if (b->prev_bio != NULL) | 400 | if (b->prev_bio != NULL) |
387 | b->prev_bio->next_bio=b->next_bio; | 401 | b->prev_bio->next_bio=b->next_bio; |
388 | if (b->next_bio != NULL) | 402 | if (b->next_bio != NULL) |
@@ -390,7 +404,6 @@ BIO *BIO_pop(BIO *b) | |||
390 | 404 | ||
391 | b->next_bio=NULL; | 405 | b->next_bio=NULL; |
392 | b->prev_bio=NULL; | 406 | b->prev_bio=NULL; |
393 | BIO_ctrl(b,BIO_CTRL_POP,0,NULL); | ||
394 | return(ret); | 407 | return(ret); |
395 | } | 408 | } |
396 | 409 | ||
diff --git a/src/lib/libcrypto/bio/bss_bio.c b/src/lib/libcrypto/bio/bss_bio.c index 1c485a4479..aa58dab046 100644 --- a/src/lib/libcrypto/bio/bss_bio.c +++ b/src/lib/libcrypto/bio/bss_bio.c | |||
@@ -28,13 +28,12 @@ | |||
28 | 28 | ||
29 | #include <openssl/bio.h> | 29 | #include <openssl/bio.h> |
30 | #include <openssl/err.h> | 30 | #include <openssl/err.h> |
31 | #include <openssl/err.h> | ||
32 | #include <openssl/crypto.h> | 31 | #include <openssl/crypto.h> |
33 | 32 | ||
34 | #include "e_os.h" | 33 | #include "e_os.h" |
35 | 34 | ||
36 | /* VxWorks defines SSIZE_MAX with an empty value causing compile errors */ | 35 | /* VxWorks defines SSIZE_MAX with an empty value causing compile errors */ |
37 | #if defined(OPENSSL_SYS_VSWORKS) | 36 | #if defined(OPENSSL_SYS_VXWORKS) |
38 | # undef SSIZE_MAX | 37 | # undef SSIZE_MAX |
39 | #endif | 38 | #endif |
40 | #ifndef SSIZE_MAX | 39 | #ifndef SSIZE_MAX |
diff --git a/src/lib/libcrypto/bio/bss_conn.c b/src/lib/libcrypto/bio/bss_conn.c index f91ae4c8c6..743db6ff94 100644 --- a/src/lib/libcrypto/bio/bss_conn.c +++ b/src/lib/libcrypto/bio/bss_conn.c | |||
@@ -519,7 +519,7 @@ static long conn_ctrl(BIO *b, int cmd, long num, void *ptr) | |||
519 | else if (num == 2) | 519 | else if (num == 2) |
520 | { | 520 | { |
521 | char buf[16]; | 521 | char buf[16]; |
522 | char *p = ptr; | 522 | unsigned char *p = ptr; |
523 | 523 | ||
524 | sprintf(buf,"%d.%d.%d.%d", | 524 | sprintf(buf,"%d.%d.%d.%d", |
525 | p[0],p[1],p[2],p[3]); | 525 | p[0],p[1],p[2],p[3]); |
@@ -530,7 +530,7 @@ static long conn_ctrl(BIO *b, int cmd, long num, void *ptr) | |||
530 | } | 530 | } |
531 | else if (num == 3) | 531 | else if (num == 3) |
532 | { | 532 | { |
533 | char buf[16]; | 533 | char buf[DECIMAL_SIZE(int)+1]; |
534 | 534 | ||
535 | sprintf(buf,"%d",*(int *)ptr); | 535 | sprintf(buf,"%d",*(int *)ptr); |
536 | if (data->param_port != NULL) | 536 | if (data->param_port != NULL) |
diff --git a/src/lib/libcrypto/bio/bss_file.c b/src/lib/libcrypto/bio/bss_file.c index 826b361fa2..a66600c1a3 100644 --- a/src/lib/libcrypto/bio/bss_file.c +++ b/src/lib/libcrypto/bio/bss_file.c | |||
@@ -247,7 +247,7 @@ static long MS_CALLBACK file_ctrl(BIO *b, int cmd, long num, void *ptr) | |||
247 | ret=0; | 247 | ret=0; |
248 | break; | 248 | break; |
249 | } | 249 | } |
250 | #if defined(OPENSSL_SYS_MSDOS) || defined(OPENSSL_SYS_WINDOWS) | 250 | #if defined(OPENSSL_SYS_MSDOS) || defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_OS2) |
251 | if (!(num & BIO_FP_TEXT)) | 251 | if (!(num & BIO_FP_TEXT)) |
252 | strcat(p,"b"); | 252 | strcat(p,"b"); |
253 | else | 253 | else |
diff --git a/src/lib/libcrypto/bio/bss_log.c b/src/lib/libcrypto/bio/bss_log.c index a39d95297c..1eb678cac0 100644 --- a/src/lib/libcrypto/bio/bss_log.c +++ b/src/lib/libcrypto/bio/bss_log.c | |||
@@ -68,7 +68,8 @@ | |||
68 | 68 | ||
69 | #include "cryptlib.h" | 69 | #include "cryptlib.h" |
70 | 70 | ||
71 | #if defined(OPENSSL_SYS_WIN32) | 71 | #if defined(OPENSSL_SYS_WINCE) |
72 | #elif defined(OPENSSL_SYS_WIN32) | ||
72 | # include <process.h> | 73 | # include <process.h> |
73 | #elif defined(OPENSSL_SYS_VMS) | 74 | #elif defined(OPENSSL_SYS_VMS) |
74 | # include <opcdef.h> | 75 | # include <opcdef.h> |
@@ -77,7 +78,7 @@ | |||
77 | # include <starlet.h> | 78 | # include <starlet.h> |
78 | #elif defined(__ultrix) | 79 | #elif defined(__ultrix) |
79 | # include <sys/syslog.h> | 80 | # include <sys/syslog.h> |
80 | #elif !defined(MSDOS) && !defined(OPENSSL_SYS_VXWORKS) && !defined(NO_SYSLOG) /* Unix */ | 81 | #elif (!defined(MSDOS) || defined(WATT32)) && !defined(OPENSSL_SYS_VXWORKS) && !defined(NO_SYSLOG) |
81 | # include <syslog.h> | 82 | # include <syslog.h> |
82 | #endif | 83 | #endif |
83 | 84 | ||
@@ -274,7 +275,7 @@ static void xsyslog(BIO *bp, int priority, const char *string) | |||
274 | LPCSTR lpszStrings[2]; | 275 | LPCSTR lpszStrings[2]; |
275 | WORD evtype= EVENTLOG_ERROR_TYPE; | 276 | WORD evtype= EVENTLOG_ERROR_TYPE; |
276 | int pid = _getpid(); | 277 | int pid = _getpid(); |
277 | char pidbuf[20]; | 278 | char pidbuf[DECIMAL_SIZE(pid)+4]; |
278 | 279 | ||
279 | switch (priority) | 280 | switch (priority) |
280 | { | 281 | { |
@@ -373,11 +374,15 @@ static void xcloselog(BIO* bp) | |||
373 | { | 374 | { |
374 | } | 375 | } |
375 | 376 | ||
376 | #else /* Unix */ | 377 | #else /* Unix/Watt32 */ |
377 | 378 | ||
378 | static void xopenlog(BIO* bp, char* name, int level) | 379 | static void xopenlog(BIO* bp, char* name, int level) |
379 | { | 380 | { |
381 | #ifdef WATT32 /* djgpp/DOS */ | ||
382 | openlog(name, LOG_PID|LOG_CONS|LOG_NDELAY, level); | ||
383 | #else | ||
380 | openlog(name, LOG_PID|LOG_CONS, level); | 384 | openlog(name, LOG_PID|LOG_CONS, level); |
385 | #endif | ||
381 | } | 386 | } |
382 | 387 | ||
383 | static void xsyslog(BIO *bp, int priority, const char *string) | 388 | static void xsyslog(BIO *bp, int priority, const char *string) |
diff --git a/src/lib/libcrypto/bio/bss_mem.c b/src/lib/libcrypto/bio/bss_mem.c index 28ff7582bf..a4edb711ae 100644 --- a/src/lib/libcrypto/bio/bss_mem.c +++ b/src/lib/libcrypto/bio/bss_mem.c | |||
@@ -190,7 +190,7 @@ static int mem_write(BIO *b, const char *in, int inl) | |||
190 | 190 | ||
191 | BIO_clear_retry_flags(b); | 191 | BIO_clear_retry_flags(b); |
192 | blen=bm->length; | 192 | blen=bm->length; |
193 | if (BUF_MEM_grow(bm,blen+inl) != (blen+inl)) | 193 | if (BUF_MEM_grow_clean(bm,blen+inl) != (blen+inl)) |
194 | goto end; | 194 | goto end; |
195 | memcpy(&(bm->data[blen]),in,inl); | 195 | memcpy(&(bm->data[blen]),in,inl); |
196 | ret=inl; | 196 | ret=inl; |
@@ -284,7 +284,11 @@ static int mem_gets(BIO *bp, char *buf, int size) | |||
284 | 284 | ||
285 | BIO_clear_retry_flags(bp); | 285 | BIO_clear_retry_flags(bp); |
286 | j=bm->length; | 286 | j=bm->length; |
287 | if (j <= 0) return(0); | 287 | if (j <= 0) |
288 | { | ||
289 | *buf='\0'; | ||
290 | return 0; | ||
291 | } | ||
288 | p=bm->data; | 292 | p=bm->data; |
289 | for (i=0; i<j; i++) | 293 | for (i=0; i<j; i++) |
290 | { | 294 | { |
diff --git a/src/lib/libcrypto/bio/bss_sock.c b/src/lib/libcrypto/bio/bss_sock.c index fdabd16d7e..2c1c405ec7 100644 --- a/src/lib/libcrypto/bio/bss_sock.c +++ b/src/lib/libcrypto/bio/bss_sock.c | |||
@@ -64,6 +64,12 @@ | |||
64 | #include "cryptlib.h" | 64 | #include "cryptlib.h" |
65 | #include <openssl/bio.h> | 65 | #include <openssl/bio.h> |
66 | 66 | ||
67 | #ifdef WATT32 | ||
68 | #define sock_write SockWrite /* Watt-32 uses same names */ | ||
69 | #define sock_read SockRead | ||
70 | #define sock_puts SockPuts | ||
71 | #endif | ||
72 | |||
67 | static int sock_write(BIO *h, const char *buf, int num); | 73 | static int sock_write(BIO *h, const char *buf, int num); |
68 | static int sock_read(BIO *h, char *buf, int size); | 74 | static int sock_read(BIO *h, char *buf, int size); |
69 | static int sock_puts(BIO *h, const char *str); | 75 | static int sock_puts(BIO *h, const char *str); |
diff --git a/src/lib/libcrypto/bn/asm/ia64.S b/src/lib/libcrypto/bn/asm/ia64.S index ae56066310..7dfda85566 100644 --- a/src/lib/libcrypto/bn/asm/ia64.S +++ b/src/lib/libcrypto/bn/asm/ia64.S | |||
@@ -1,6 +1,6 @@ | |||
1 | .explicit | 1 | .explicit |
2 | .text | 2 | .text |
3 | .ident "ia64.S, Version 1.1" | 3 | .ident "ia64.S, Version 2.0" |
4 | .ident "IA-64 ISA artwork by Andy Polyakov <appro@fy.chalmers.se>" | 4 | .ident "IA-64 ISA artwork by Andy Polyakov <appro@fy.chalmers.se>" |
5 | 5 | ||
6 | // | 6 | // |
@@ -13,6 +13,35 @@ | |||
13 | // disclaimed. | 13 | // disclaimed. |
14 | // ==================================================================== | 14 | // ==================================================================== |
15 | // | 15 | // |
16 | // Version 2.x is Itanium2 re-tune. Few words about how Itanum2 is | ||
17 | // different from Itanium to this module viewpoint. Most notably, is it | ||
18 | // "wider" than Itanium? Can you experience loop scalability as | ||
19 | // discussed in commentary sections? Not really:-( Itanium2 has 6 | ||
20 | // integer ALU ports, i.e. it's 2 ports wider, but it's not enough to | ||
21 | // spin twice as fast, as I need 8 IALU ports. Amount of floating point | ||
22 | // ports is the same, i.e. 2, while I need 4. In other words, to this | ||
23 | // module Itanium2 remains effectively as "wide" as Itanium. Yet it's | ||
24 | // essentially different in respect to this module, and a re-tune was | ||
25 | // required. Well, because some intruction latencies has changed. Most | ||
26 | // noticeably those intensively used: | ||
27 | // | ||
28 | // Itanium Itanium2 | ||
29 | // ldf8 9 6 L2 hit | ||
30 | // ld8 2 1 L1 hit | ||
31 | // getf 2 5 | ||
32 | // xma[->getf] 7[+1] 4[+0] | ||
33 | // add[->st8] 1[+1] 1[+0] | ||
34 | // | ||
35 | // What does it mean? You might ratiocinate that the original code | ||
36 | // should run just faster... Because sum of latencies is smaller... | ||
37 | // Wrong! Note that getf latency increased. This means that if a loop is | ||
38 | // scheduled for lower latency (and they are), then it will suffer from | ||
39 | // stall condition and the code will therefore turn anti-scalable, e.g. | ||
40 | // original bn_mul_words spun at 5*n or 2.5 times slower than expected | ||
41 | // on Itanium2! What to do? Reschedule loops for Itanium2? But then | ||
42 | // Itanium would exhibit anti-scalability. So I've chosen to reschedule | ||
43 | // for worst latency for every instruction aiming for best *all-round* | ||
44 | // performance. | ||
16 | 45 | ||
17 | // Q. How much faster does it get? | 46 | // Q. How much faster does it get? |
18 | // A. Here is the output from 'openssl speed rsa dsa' for vanilla | 47 | // A. Here is the output from 'openssl speed rsa dsa' for vanilla |
@@ -149,12 +178,27 @@ bn_add_words: | |||
149 | brp.loop.imp .L_bn_add_words_ctop,.L_bn_add_words_cend-16 | 178 | brp.loop.imp .L_bn_add_words_ctop,.L_bn_add_words_cend-16 |
150 | } | 179 | } |
151 | .body | 180 | .body |
152 | { .mib; mov r14=r32 // rp | 181 | { .mib; |
182 | #if defined(_HPUX_SOURCE) && defined(_ILP32) | ||
183 | addp4 r14=0,r32 // rp | ||
184 | #else | ||
185 | mov r14=r32 // rp | ||
186 | #endif | ||
153 | mov r9=pr };; | 187 | mov r9=pr };; |
154 | { .mii; mov r15=r33 // ap | 188 | { .mii; |
189 | #if defined(_HPUX_SOURCE) && defined(_ILP32) | ||
190 | addp4 r15=0,r33 // ap | ||
191 | #else | ||
192 | mov r15=r33 // ap | ||
193 | #endif | ||
155 | mov ar.lc=r10 | 194 | mov ar.lc=r10 |
156 | mov ar.ec=6 } | 195 | mov ar.ec=6 } |
157 | { .mib; mov r16=r34 // bp | 196 | { .mib; |
197 | #if defined(_HPUX_SOURCE) && defined(_ILP32) | ||
198 | addp4 r16=0,r34 // bp | ||
199 | #else | ||
200 | mov r16=r34 // bp | ||
201 | #endif | ||
158 | mov pr.rot=1<<16 };; | 202 | mov pr.rot=1<<16 };; |
159 | 203 | ||
160 | .L_bn_add_words_ctop: | 204 | .L_bn_add_words_ctop: |
@@ -174,7 +218,7 @@ bn_add_words: | |||
174 | 218 | ||
175 | { .mii; | 219 | { .mii; |
176 | (p59) add r8=1,r8 // return value | 220 | (p59) add r8=1,r8 // return value |
177 | mov pr=r9,-1 | 221 | mov pr=r9,0x1ffff |
178 | mov ar.lc=r3 } | 222 | mov ar.lc=r3 } |
179 | { .mbb; nop.b 0x0 | 223 | { .mbb; nop.b 0x0 |
180 | br.ret.sptk.many b0 };; | 224 | br.ret.sptk.many b0 };; |
@@ -202,12 +246,27 @@ bn_sub_words: | |||
202 | brp.loop.imp .L_bn_sub_words_ctop,.L_bn_sub_words_cend-16 | 246 | brp.loop.imp .L_bn_sub_words_ctop,.L_bn_sub_words_cend-16 |
203 | } | 247 | } |
204 | .body | 248 | .body |
205 | { .mib; mov r14=r32 // rp | 249 | { .mib; |
250 | #if defined(_HPUX_SOURCE) && defined(_ILP32) | ||
251 | addp4 r14=0,r32 // rp | ||
252 | #else | ||
253 | mov r14=r32 // rp | ||
254 | #endif | ||
206 | mov r9=pr };; | 255 | mov r9=pr };; |
207 | { .mii; mov r15=r33 // ap | 256 | { .mii; |
257 | #if defined(_HPUX_SOURCE) && defined(_ILP32) | ||
258 | addp4 r15=0,r33 // ap | ||
259 | #else | ||
260 | mov r15=r33 // ap | ||
261 | #endif | ||
208 | mov ar.lc=r10 | 262 | mov ar.lc=r10 |
209 | mov ar.ec=6 } | 263 | mov ar.ec=6 } |
210 | { .mib; mov r16=r34 // bp | 264 | { .mib; |
265 | #if defined(_HPUX_SOURCE) && defined(_ILP32) | ||
266 | addp4 r16=0,r34 // bp | ||
267 | #else | ||
268 | mov r16=r34 // bp | ||
269 | #endif | ||
211 | mov pr.rot=1<<16 };; | 270 | mov pr.rot=1<<16 };; |
212 | 271 | ||
213 | .L_bn_sub_words_ctop: | 272 | .L_bn_sub_words_ctop: |
@@ -227,7 +286,7 @@ bn_sub_words: | |||
227 | 286 | ||
228 | { .mii; | 287 | { .mii; |
229 | (p59) add r8=1,r8 // return value | 288 | (p59) add r8=1,r8 // return value |
230 | mov pr=r9,-1 | 289 | mov pr=r9,0x1ffff |
231 | mov ar.lc=r3 } | 290 | mov ar.lc=r3 } |
232 | { .mbb; nop.b 0x0 | 291 | { .mbb; nop.b 0x0 |
233 | br.ret.sptk.many b0 };; | 292 | br.ret.sptk.many b0 };; |
@@ -253,7 +312,7 @@ bn_mul_words: | |||
253 | #ifdef XMA_TEMPTATION | 312 | #ifdef XMA_TEMPTATION |
254 | { .mfi; alloc r2=ar.pfs,4,0,0,0 };; | 313 | { .mfi; alloc r2=ar.pfs,4,0,0,0 };; |
255 | #else | 314 | #else |
256 | { .mfi; alloc r2=ar.pfs,4,4,0,8 };; | 315 | { .mfi; alloc r2=ar.pfs,4,12,0,16 };; |
257 | #endif | 316 | #endif |
258 | { .mib; mov r8=r0 // return value | 317 | { .mib; mov r8=r0 // return value |
259 | cmp4.le p6,p0=r34,r0 | 318 | cmp4.le p6,p0=r34,r0 |
@@ -266,24 +325,30 @@ bn_mul_words: | |||
266 | 325 | ||
267 | .body | 326 | .body |
268 | { .mib; setf.sig f8=r35 // w | 327 | { .mib; setf.sig f8=r35 // w |
269 | mov pr.rot=0x400001<<16 | 328 | mov pr.rot=0x800001<<16 |
270 | // ------^----- serves as (p48) at first (p26) | 329 | // ------^----- serves as (p50) at first (p27) |
271 | brp.loop.imp .L_bn_mul_words_ctop,.L_bn_mul_words_cend-16 | 330 | brp.loop.imp .L_bn_mul_words_ctop,.L_bn_mul_words_cend-16 |
272 | } | 331 | } |
273 | 332 | ||
274 | #ifndef XMA_TEMPTATION | 333 | #ifndef XMA_TEMPTATION |
275 | 334 | ||
276 | { .mii; mov r14=r32 // rp | 335 | { .mii; |
277 | mov r15=r33 // ap | 336 | #if defined(_HPUX_SOURCE) && defined(_ILP32) |
337 | addp4 r14=0,r32 // rp | ||
338 | addp4 r15=0,r33 // ap | ||
339 | #else | ||
340 | mov r14=r32 // rp | ||
341 | mov r15=r33 // ap | ||
342 | #endif | ||
278 | mov ar.lc=r10 } | 343 | mov ar.lc=r10 } |
279 | { .mii; mov r39=0 // serves as r33 at first (p26) | 344 | { .mii; mov r40=0 // serves as r35 at first (p27) |
280 | mov ar.ec=12 };; | 345 | mov ar.ec=13 };; |
281 | 346 | ||
282 | // This loop spins in 2*(n+11) ticks. It's scheduled for data in L2 | 347 | // This loop spins in 2*(n+12) ticks. It's scheduled for data in Itanium |
283 | // cache (i.e. 9 ticks away) as floating point load/store instructions | 348 | // L2 cache (i.e. 9 ticks away) as floating point load/store instructions |
284 | // bypass L1 cache and L2 latency is actually best-case scenario for | 349 | // bypass L1 cache and L2 latency is actually best-case scenario for |
285 | // ldf8. The loop is not scalable and shall run in 2*(n+11) even on | 350 | // ldf8. The loop is not scalable and shall run in 2*(n+12) even on |
286 | // "wider" IA-64 implementations. It's a trade-off here. n+22 loop | 351 | // "wider" IA-64 implementations. It's a trade-off here. n+24 loop |
287 | // would give us ~5% in *overall* performance improvement on "wider" | 352 | // would give us ~5% in *overall* performance improvement on "wider" |
288 | // IA-64, but would hurt Itanium for about same because of longer | 353 | // IA-64, but would hurt Itanium for about same because of longer |
289 | // epilogue. As it's a matter of few percents in either case I've | 354 | // epilogue. As it's a matter of few percents in either case I've |
@@ -291,25 +356,25 @@ bn_mul_words: | |||
291 | // this very instruction sequence in bn_mul_add_words loop which in | 356 | // this very instruction sequence in bn_mul_add_words loop which in |
292 | // turn is scalable). | 357 | // turn is scalable). |
293 | .L_bn_mul_words_ctop: | 358 | .L_bn_mul_words_ctop: |
294 | { .mfi; (p25) getf.sig r36=f49 // low | 359 | { .mfi; (p25) getf.sig r36=f52 // low |
295 | (p21) xmpy.lu f45=f37,f8 | 360 | (p21) xmpy.lu f48=f37,f8 |
296 | (p27) cmp.ltu p52,p48=r39,r38 } | 361 | (p28) cmp.ltu p54,p50=r41,r39 } |
297 | { .mfi; (p16) ldf8 f32=[r15],8 | 362 | { .mfi; (p16) ldf8 f32=[r15],8 |
298 | (p21) xmpy.hu f38=f37,f8 | 363 | (p21) xmpy.hu f40=f37,f8 |
299 | (p0) nop.i 0x0 };; | 364 | (p0) nop.i 0x0 };; |
300 | { .mii; (p26) getf.sig r32=f43 // high | 365 | { .mii; (p25) getf.sig r32=f44 // high |
301 | .pred.rel "mutex",p48,p52 | 366 | .pred.rel "mutex",p50,p54 |
302 | (p48) add r38=r37,r33 // (p26) | 367 | (p50) add r40=r38,r35 // (p27) |
303 | (p52) add r38=r37,r33,1 } // (p26) | 368 | (p54) add r40=r38,r35,1 } // (p27) |
304 | { .mfb; (p27) st8 [r14]=r39,8 | 369 | { .mfb; (p28) st8 [r14]=r41,8 |
305 | (p0) nop.f 0x0 | 370 | (p0) nop.f 0x0 |
306 | br.ctop.sptk .L_bn_mul_words_ctop };; | 371 | br.ctop.sptk .L_bn_mul_words_ctop };; |
307 | .L_bn_mul_words_cend: | 372 | .L_bn_mul_words_cend: |
308 | 373 | ||
309 | { .mii; nop.m 0x0 | 374 | { .mii; nop.m 0x0 |
310 | .pred.rel "mutex",p49,p53 | 375 | .pred.rel "mutex",p51,p55 |
311 | (p49) add r8=r34,r0 | 376 | (p51) add r8=r36,r0 |
312 | (p53) add r8=r34,r0,1 } | 377 | (p55) add r8=r36,r0,1 } |
313 | { .mfb; nop.m 0x0 | 378 | { .mfb; nop.m 0x0 |
314 | nop.f 0x0 | 379 | nop.f 0x0 |
315 | nop.b 0x0 } | 380 | nop.b 0x0 } |
@@ -344,7 +409,7 @@ bn_mul_words: | |||
344 | #endif // XMA_TEMPTATION | 409 | #endif // XMA_TEMPTATION |
345 | 410 | ||
346 | { .mii; nop.m 0x0 | 411 | { .mii; nop.m 0x0 |
347 | mov pr=r9,-1 | 412 | mov pr=r9,0x1ffff |
348 | mov ar.lc=r3 } | 413 | mov ar.lc=r3 } |
349 | { .mfb; rum 1<<5 // clear um.mfh | 414 | { .mfb; rum 1<<5 // clear um.mfh |
350 | nop.f 0x0 | 415 | nop.f 0x0 |
@@ -376,59 +441,69 @@ bn_mul_add_words: | |||
376 | 441 | ||
377 | .body | 442 | .body |
378 | { .mib; setf.sig f8=r35 // w | 443 | { .mib; setf.sig f8=r35 // w |
379 | mov pr.rot=0x400001<<16 | 444 | mov pr.rot=0x800001<<16 |
380 | // ------^----- serves as (p48) at first (p26) | 445 | // ------^----- serves as (p50) at first (p27) |
381 | brp.loop.imp .L_bn_mul_add_words_ctop,.L_bn_mul_add_words_cend-16 | 446 | brp.loop.imp .L_bn_mul_add_words_ctop,.L_bn_mul_add_words_cend-16 |
382 | } | 447 | } |
383 | { .mii; mov r14=r32 // rp | 448 | { .mii; |
384 | mov r15=r33 // ap | 449 | #if defined(_HPUX_SOURCE) && defined(_ILP32) |
450 | addp4 r14=0,r32 // rp | ||
451 | addp4 r15=0,r33 // ap | ||
452 | #else | ||
453 | mov r14=r32 // rp | ||
454 | mov r15=r33 // ap | ||
455 | #endif | ||
385 | mov ar.lc=r10 } | 456 | mov ar.lc=r10 } |
386 | { .mii; mov r39=0 // serves as r33 at first (p26) | 457 | { .mii; mov r40=0 // serves as r35 at first (p27) |
387 | mov r18=r32 // rp copy | 458 | #if defined(_HPUX_SOURCE) && defined(_ILP32) |
388 | mov ar.ec=14 };; | 459 | addp4 r18=0,r32 // rp copy |
460 | #else | ||
461 | mov r18=r32 // rp copy | ||
462 | #endif | ||
463 | mov ar.ec=15 };; | ||
389 | 464 | ||
390 | // This loop spins in 3*(n+13) ticks on Itanium and should spin in | 465 | // This loop spins in 3*(n+14) ticks on Itanium and should spin in |
391 | // 2*(n+13) on "wider" IA-64 implementations (to be verified with new | 466 | // 2*(n+14) on "wider" IA-64 implementations (to be verified with new |
392 | // µ-architecture manuals as they become available). As usual it's | 467 | // µ-architecture manuals as they become available). As usual it's |
393 | // possible to compress the epilogue, down to 10 in this case, at the | 468 | // possible to compress the epilogue, down to 10 in this case, at the |
394 | // cost of scalability. Compressed (and therefore non-scalable) loop | 469 | // cost of scalability. Compressed (and therefore non-scalable) loop |
395 | // running at 3*(n+10) would buy you ~10% on Itanium but take ~35% | 470 | // running at 3*(n+11) would buy you ~10% on Itanium but take ~35% |
396 | // from "wider" IA-64 so let it be scalable! Special attention was | 471 | // from "wider" IA-64 so let it be scalable! Special attention was |
397 | // paid for having the loop body split at 64-byte boundary. ld8 is | 472 | // paid for having the loop body split at 64-byte boundary. ld8 is |
398 | // scheduled for L1 cache as the data is more than likely there. | 473 | // scheduled for L1 cache as the data is more than likely there. |
399 | // Indeed, bn_mul_words has put it there a moment ago:-) | 474 | // Indeed, bn_mul_words has put it there a moment ago:-) |
400 | .L_bn_mul_add_words_ctop: | 475 | .L_bn_mul_add_words_ctop: |
401 | { .mfi; (p25) getf.sig r36=f49 // low | 476 | { .mfi; (p25) getf.sig r36=f52 // low |
402 | (p21) xmpy.lu f45=f37,f8 | 477 | (p21) xmpy.lu f48=f37,f8 |
403 | (p27) cmp.ltu p52,p48=r39,r38 } | 478 | (p28) cmp.ltu p54,p50=r41,r39 } |
404 | { .mfi; (p16) ldf8 f32=[r15],8 | 479 | { .mfi; (p16) ldf8 f32=[r15],8 |
405 | (p21) xmpy.hu f38=f37,f8 | 480 | (p21) xmpy.hu f40=f37,f8 |
406 | (p27) add r43=r43,r39 };; | 481 | (p28) add r45=r45,r41 };; |
407 | { .mii; (p26) getf.sig r32=f43 // high | 482 | { .mii; (p25) getf.sig r32=f44 // high |
408 | .pred.rel "mutex",p48,p52 | 483 | .pred.rel "mutex",p50,p54 |
409 | (p48) add r38=r37,r33 // (p26) | 484 | (p50) add r40=r38,r35 // (p27) |
410 | (p52) add r38=r37,r33,1 } // (p26) | 485 | (p54) add r40=r38,r35,1 } // (p27) |
411 | { .mfb; (p27) cmp.ltu.unc p56,p0=r43,r39 | 486 | { .mfb; (p28) cmp.ltu.unc p60,p0=r45,r41 |
412 | (p0) nop.f 0x0 | 487 | (p0) nop.f 0x0 |
413 | (p0) nop.b 0x0 } | 488 | (p0) nop.b 0x0 } |
414 | { .mii; (p26) ld8 r42=[r18],8 | 489 | { .mii; (p27) ld8 r44=[r18],8 |
415 | (p58) cmp.eq.or p57,p0=-1,r44 | 490 | (p62) cmp.eq.or p61,p0=-1,r46 |
416 | (p58) add r44=1,r44 } | 491 | (p62) add r46=1,r46 } |
417 | { .mfb; (p29) st8 [r14]=r45,8 | 492 | { .mfb; (p30) st8 [r14]=r47,8 |
418 | (p0) nop.f 0x0 | 493 | (p0) nop.f 0x0 |
419 | br.ctop.sptk .L_bn_mul_add_words_ctop};; | 494 | br.ctop.sptk .L_bn_mul_add_words_ctop};; |
420 | .L_bn_mul_add_words_cend: | 495 | .L_bn_mul_add_words_cend: |
421 | 496 | ||
422 | { .mii; nop.m 0x0 | 497 | { .mii; nop.m 0x0 |
423 | .pred.rel "mutex",p51,p55 | 498 | .pred.rel "mutex",p53,p57 |
424 | (p51) add r8=r36,r0 | 499 | (p53) add r8=r38,r0 |
425 | (p55) add r8=r36,r0,1 } | 500 | (p57) add r8=r38,r0,1 } |
426 | { .mfb; nop.m 0x0 | 501 | { .mfb; nop.m 0x0 |
427 | nop.f 0x0 | 502 | nop.f 0x0 |
428 | nop.b 0x0 };; | 503 | nop.b 0x0 };; |
429 | { .mii; | 504 | { .mii; |
430 | (p59) add r8=1,r8 | 505 | (p63) add r8=1,r8 |
431 | mov pr=r9,-1 | 506 | mov pr=r9,0x1ffff |
432 | mov ar.lc=r3 } | 507 | mov ar.lc=r3 } |
433 | { .mfb; rum 1<<5 // clear um.mfh | 508 | { .mfb; rum 1<<5 // clear um.mfh |
434 | nop.f 0x0 | 509 | nop.f 0x0 |
@@ -461,6 +536,10 @@ bn_sqr_words: | |||
461 | mov r9=pr };; | 536 | mov r9=pr };; |
462 | 537 | ||
463 | .body | 538 | .body |
539 | #if defined(_HPUX_SOURCE) && defined(_ILP32) | ||
540 | { .mii; addp4 r32=0,r32 | ||
541 | addp4 r33=0,r33 };; | ||
542 | #endif | ||
464 | { .mib; | 543 | { .mib; |
465 | mov pr.rot=1<<16 | 544 | mov pr.rot=1<<16 |
466 | brp.loop.imp .L_bn_sqr_words_ctop,.L_bn_sqr_words_cend-16 | 545 | brp.loop.imp .L_bn_sqr_words_ctop,.L_bn_sqr_words_cend-16 |
@@ -492,7 +571,7 @@ bn_sqr_words: | |||
492 | .L_bn_sqr_words_cend: | 571 | .L_bn_sqr_words_cend: |
493 | 572 | ||
494 | { .mii; nop.m 0x0 | 573 | { .mii; nop.m 0x0 |
495 | mov pr=r9,-1 | 574 | mov pr=r9,0x1ffff |
496 | mov ar.lc=r3 } | 575 | mov ar.lc=r3 } |
497 | { .mfb; rum 1<<5 // clear um.mfh | 576 | { .mfb; rum 1<<5 // clear um.mfh |
498 | nop.f 0x0 | 577 | nop.f 0x0 |
@@ -526,7 +605,14 @@ bn_sqr_comba8: | |||
526 | .prologue | 605 | .prologue |
527 | .fframe 0 | 606 | .fframe 0 |
528 | .save ar.pfs,r2 | 607 | .save ar.pfs,r2 |
608 | #if defined(_HPUX_SOURCE) && defined(_ILP32) | ||
529 | { .mii; alloc r2=ar.pfs,2,1,0,0 | 609 | { .mii; alloc r2=ar.pfs,2,1,0,0 |
610 | addp4 r33=0,r33 | ||
611 | addp4 r32=0,r32 };; | ||
612 | { .mii; | ||
613 | #else | ||
614 | { .mii; alloc r2=ar.pfs,2,1,0,0 | ||
615 | #endif | ||
530 | mov r34=r33 | 616 | mov r34=r33 |
531 | add r14=8,r33 };; | 617 | add r14=8,r33 };; |
532 | .body | 618 | .body |
@@ -587,7 +673,14 @@ bn_mul_comba8: | |||
587 | .prologue | 673 | .prologue |
588 | .fframe 0 | 674 | .fframe 0 |
589 | .save ar.pfs,r2 | 675 | .save ar.pfs,r2 |
676 | #if defined(_HPUX_SOURCE) && defined(_ILP32) | ||
590 | { .mii; alloc r2=ar.pfs,3,0,0,0 | 677 | { .mii; alloc r2=ar.pfs,3,0,0,0 |
678 | addp4 r33=0,r33 | ||
679 | addp4 r34=0,r34 };; | ||
680 | { .mii; addp4 r32=0,r32 | ||
681 | #else | ||
682 | { .mii; alloc r2=ar.pfs,3,0,0,0 | ||
683 | #endif | ||
591 | add r14=8,r33 | 684 | add r14=8,r33 |
592 | add r17=8,r34 } | 685 | add r17=8,r34 } |
593 | .body | 686 | .body |
@@ -1138,7 +1231,14 @@ bn_sqr_comba4: | |||
1138 | .prologue | 1231 | .prologue |
1139 | .fframe 0 | 1232 | .fframe 0 |
1140 | .save ar.pfs,r2 | 1233 | .save ar.pfs,r2 |
1234 | #if defined(_HPUX_SOURCE) && defined(_ILP32) | ||
1235 | { .mii; alloc r2=ar.pfs,2,1,0,0 | ||
1236 | addp4 r32=0,r32 | ||
1237 | addp4 r33=0,r33 };; | ||
1238 | { .mii; | ||
1239 | #else | ||
1141 | { .mii; alloc r2=ar.pfs,2,1,0,0 | 1240 | { .mii; alloc r2=ar.pfs,2,1,0,0 |
1241 | #endif | ||
1142 | mov r34=r33 | 1242 | mov r34=r33 |
1143 | add r14=8,r33 };; | 1243 | add r14=8,r33 };; |
1144 | .body | 1244 | .body |
@@ -1164,7 +1264,14 @@ bn_mul_comba4: | |||
1164 | .prologue | 1264 | .prologue |
1165 | .fframe 0 | 1265 | .fframe 0 |
1166 | .save ar.pfs,r2 | 1266 | .save ar.pfs,r2 |
1267 | #if defined(_HPUX_SOURCE) && defined(_ILP32) | ||
1268 | { .mii; alloc r2=ar.pfs,3,0,0,0 | ||
1269 | addp4 r33=0,r33 | ||
1270 | addp4 r34=0,r34 };; | ||
1271 | { .mii; addp4 r32=0,r32 | ||
1272 | #else | ||
1167 | { .mii; alloc r2=ar.pfs,3,0,0,0 | 1273 | { .mii; alloc r2=ar.pfs,3,0,0,0 |
1274 | #endif | ||
1168 | add r14=8,r33 | 1275 | add r14=8,r33 |
1169 | add r17=8,r34 } | 1276 | add r17=8,r34 } |
1170 | .body | 1277 | .body |
@@ -1464,7 +1571,7 @@ bn_div_words: | |||
1464 | or r8=r8,r33 | 1571 | or r8=r8,r33 |
1465 | mov ar.pfs=r2 };; | 1572 | mov ar.pfs=r2 };; |
1466 | { .mii; shr.u r9=H,I // remainder if anybody wants it | 1573 | { .mii; shr.u r9=H,I // remainder if anybody wants it |
1467 | mov pr=r10,-1 } | 1574 | mov pr=r10,0x1ffff } |
1468 | { .mfb; br.ret.sptk.many b0 };; | 1575 | { .mfb; br.ret.sptk.many b0 };; |
1469 | 1576 | ||
1470 | // Unsigned 64 by 32 (well, by 64 for the moment) bit integer division | 1577 | // Unsigned 64 by 32 (well, by 64 for the moment) bit integer division |
diff --git a/src/lib/libcrypto/bn/asm/pa-risc2.s b/src/lib/libcrypto/bn/asm/pa-risc2.s index af9730d062..f3b16290eb 100644 --- a/src/lib/libcrypto/bn/asm/pa-risc2.s +++ b/src/lib/libcrypto/bn/asm/pa-risc2.s | |||
@@ -747,8 +747,8 @@ bn_div_words | |||
747 | .PROC | 747 | .PROC |
748 | .EXPORT bn_div_words,ENTRY,PRIV_LEV=3,ARGW0=GR,ARGW1=GR,ARGW2=GR,ARGW3=GR,RTNVAL=GR,LONG_RETURN | 748 | .EXPORT bn_div_words,ENTRY,PRIV_LEV=3,ARGW0=GR,ARGW1=GR,ARGW2=GR,ARGW3=GR,RTNVAL=GR,LONG_RETURN |
749 | .IMPORT BN_num_bits_word,CODE | 749 | .IMPORT BN_num_bits_word,CODE |
750 | .IMPORT __iob,DATA | 750 | ;--- not PIC .IMPORT __iob,DATA |
751 | .IMPORT fprintf,CODE | 751 | ;--- not PIC .IMPORT fprintf,CODE |
752 | .IMPORT abort,CODE | 752 | .IMPORT abort,CODE |
753 | .IMPORT $$div2U,MILLICODE | 753 | .IMPORT $$div2U,MILLICODE |
754 | .CALLINFO CALLER,FRAME=144,ENTRY_GR=%r9,SAVE_RP,ARGS_SAVED,ORDERING_AWARE | 754 | .CALLINFO CALLER,FRAME=144,ENTRY_GR=%r9,SAVE_RP,ARGS_SAVED,ORDERING_AWARE |
@@ -844,12 +844,12 @@ $0006001A | |||
844 | MOVIB,TR 2,%r8,$0006001C ;offset 0xa18 | 844 | MOVIB,TR 2,%r8,$0006001C ;offset 0xa18 |
845 | EXTRD,U %r3,63,32,%r7 ;offset 0xa1c | 845 | EXTRD,U %r3,63,32,%r7 ;offset 0xa1c |
846 | $D2 | 846 | $D2 |
847 | ADDIL LR'__iob-$global$,%r27,%r1 ;offset 0xa20 | 847 | ;--- not PIC ADDIL LR'__iob-$global$,%r27,%r1 ;offset 0xa20 |
848 | LDIL LR'C$7,%r21 ;offset 0xa24 | 848 | ;--- not PIC LDIL LR'C$7,%r21 ;offset 0xa24 |
849 | LDO RR'__iob-$global$+32(%r1),%r26 ;offset 0xa28 | 849 | ;--- not PIC LDO RR'__iob-$global$+32(%r1),%r26 ;offset 0xa28 |
850 | .CALL ARGW0=GR,ARGW1=GR,ARGW2=GR,RTNVAL=GR ;in=24,25,26;out=28; | 850 | ;--- not PIC .CALL ARGW0=GR,ARGW1=GR,ARGW2=GR,RTNVAL=GR ;in=24,25,26;out=28; |
851 | B,L fprintf,%r2 ;offset 0xa2c | 851 | ;--- not PIC B,L fprintf,%r2 ;offset 0xa2c |
852 | LDO RR'C$7(%r21),%r25 ;offset 0xa30 | 852 | ;--- not PIC LDO RR'C$7(%r21),%r25 ;offset 0xa30 |
853 | .CALL ; | 853 | .CALL ; |
854 | B,L abort,%r2 ;offset 0xa34 | 854 | B,L abort,%r2 ;offset 0xa34 |
855 | NOP ;offset 0xa38 | 855 | NOP ;offset 0xa38 |
@@ -1605,14 +1605,14 @@ bn_mul_comba4 | |||
1605 | .PROCEND | 1605 | .PROCEND |
1606 | 1606 | ||
1607 | 1607 | ||
1608 | .SPACE $TEXT$ | 1608 | ;--- not PIC .SPACE $TEXT$ |
1609 | .SUBSPA $CODE$ | 1609 | ;--- not PIC .SUBSPA $CODE$ |
1610 | .SPACE $PRIVATE$,SORT=16 | 1610 | ;--- not PIC .SPACE $PRIVATE$,SORT=16 |
1611 | .IMPORT $global$,DATA | 1611 | ;--- not PIC .IMPORT $global$,DATA |
1612 | .SPACE $TEXT$ | 1612 | ;--- not PIC .SPACE $TEXT$ |
1613 | .SUBSPA $CODE$ | 1613 | ;--- not PIC .SUBSPA $CODE$ |
1614 | .SUBSPA $LIT$,ACCESS=0x2c | 1614 | ;--- not PIC .SUBSPA $LIT$,ACCESS=0x2c |
1615 | C$7 | 1615 | ;--- not PIC C$7 |
1616 | .ALIGN 8 | 1616 | ;--- not PIC .ALIGN 8 |
1617 | .STRINGZ "Division would overflow (%d)\n" | 1617 | ;--- not PIC .STRINGZ "Division would overflow (%d)\n" |
1618 | .END | 1618 | .END |
diff --git a/src/lib/libcrypto/bn/asm/x86_64-gcc.c b/src/lib/libcrypto/bn/asm/x86_64-gcc.c new file mode 100644 index 0000000000..b97b394661 --- /dev/null +++ b/src/lib/libcrypto/bn/asm/x86_64-gcc.c | |||
@@ -0,0 +1,575 @@ | |||
1 | /* | ||
2 | * x86_64 BIGNUM accelerator version 0.1, December 2002. | ||
3 | * | ||
4 | * Implemented by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL | ||
5 | * project. | ||
6 | * | ||
7 | * Rights for redistribution and usage in source and binary forms are | ||
8 | * granted according to the OpenSSL license. Warranty of any kind is | ||
9 | * disclaimed. | ||
10 | * | ||
11 | * Q. Version 0.1? It doesn't sound like Andy, he used to assign real | ||
12 | * versions, like 1.0... | ||
13 | * A. Well, that's because this code is basically a quick-n-dirty | ||
14 | * proof-of-concept hack. As you can see it's implemented with | ||
15 | * inline assembler, which means that you're bound to GCC and that | ||
16 | * there must be a room for fine-tuning. | ||
17 | * | ||
18 | * Q. Why inline assembler? | ||
19 | * A. x86_64 features own ABI I'm not familiar with. Which is why | ||
20 | * I decided to let the compiler take care of subroutine | ||
21 | * prologue/epilogue as well as register allocation. | ||
22 | * | ||
23 | * Q. How much faster does it get? | ||
24 | * A. Unfortunately people sitting on x86_64 hardware are prohibited | ||
25 | * to disclose the performance numbers, so they (SuSE labs to be | ||
26 | * specific) wouldn't tell me. However! Very similar coding technique | ||
27 | * (reaching out for 128-bit result from 64x64-bit multiplication) | ||
28 | * results in >3 times performance improvement on MIPS and I see no | ||
29 | * reason why gain on x86_64 would be so much different:-) | ||
30 | */ | ||
31 | |||
32 | #define BN_ULONG unsigned long | ||
33 | |||
34 | /* | ||
35 | * "m"(a), "+m"(r) is the way to favor DirectPath µ-code; | ||
36 | * "g"(0) let the compiler to decide where does it | ||
37 | * want to keep the value of zero; | ||
38 | */ | ||
39 | #define mul_add(r,a,word,carry) do { \ | ||
40 | register BN_ULONG high,low; \ | ||
41 | asm ("mulq %3" \ | ||
42 | : "=a"(low),"=d"(high) \ | ||
43 | : "a"(word),"m"(a) \ | ||
44 | : "cc"); \ | ||
45 | asm ("addq %2,%0; adcq %3,%1" \ | ||
46 | : "+r"(carry),"+d"(high)\ | ||
47 | : "a"(low),"g"(0) \ | ||
48 | : "cc"); \ | ||
49 | asm ("addq %2,%0; adcq %3,%1" \ | ||
50 | : "+m"(r),"+d"(high) \ | ||
51 | : "r"(carry),"g"(0) \ | ||
52 | : "cc"); \ | ||
53 | carry=high; \ | ||
54 | } while (0) | ||
55 | |||
56 | #define mul(r,a,word,carry) do { \ | ||
57 | register BN_ULONG high,low; \ | ||
58 | asm ("mulq %3" \ | ||
59 | : "=a"(low),"=d"(high) \ | ||
60 | : "a"(word),"g"(a) \ | ||
61 | : "cc"); \ | ||
62 | asm ("addq %2,%0; adcq %3,%1" \ | ||
63 | : "+r"(carry),"+d"(high)\ | ||
64 | : "a"(low),"g"(0) \ | ||
65 | : "cc"); \ | ||
66 | (r)=carry, carry=high; \ | ||
67 | } while (0) | ||
68 | |||
69 | #define sqr(r0,r1,a) \ | ||
70 | asm ("mulq %2" \ | ||
71 | : "=a"(r0),"=d"(r1) \ | ||
72 | : "a"(a) \ | ||
73 | : "cc"); | ||
74 | |||
75 | BN_ULONG bn_mul_add_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w) | ||
76 | { | ||
77 | BN_ULONG c1=0; | ||
78 | |||
79 | if (num <= 0) return(c1); | ||
80 | |||
81 | while (num&~3) | ||
82 | { | ||
83 | mul_add(rp[0],ap[0],w,c1); | ||
84 | mul_add(rp[1],ap[1],w,c1); | ||
85 | mul_add(rp[2],ap[2],w,c1); | ||
86 | mul_add(rp[3],ap[3],w,c1); | ||
87 | ap+=4; rp+=4; num-=4; | ||
88 | } | ||
89 | if (num) | ||
90 | { | ||
91 | mul_add(rp[0],ap[0],w,c1); if (--num==0) return c1; | ||
92 | mul_add(rp[1],ap[1],w,c1); if (--num==0) return c1; | ||
93 | mul_add(rp[2],ap[2],w,c1); return c1; | ||
94 | } | ||
95 | |||
96 | return(c1); | ||
97 | } | ||
98 | |||
99 | BN_ULONG bn_mul_words(BN_ULONG *rp, BN_ULONG *ap, int num, BN_ULONG w) | ||
100 | { | ||
101 | BN_ULONG c1=0; | ||
102 | |||
103 | if (num <= 0) return(c1); | ||
104 | |||
105 | while (num&~3) | ||
106 | { | ||
107 | mul(rp[0],ap[0],w,c1); | ||
108 | mul(rp[1],ap[1],w,c1); | ||
109 | mul(rp[2],ap[2],w,c1); | ||
110 | mul(rp[3],ap[3],w,c1); | ||
111 | ap+=4; rp+=4; num-=4; | ||
112 | } | ||
113 | if (num) | ||
114 | { | ||
115 | mul(rp[0],ap[0],w,c1); if (--num == 0) return c1; | ||
116 | mul(rp[1],ap[1],w,c1); if (--num == 0) return c1; | ||
117 | mul(rp[2],ap[2],w,c1); | ||
118 | } | ||
119 | return(c1); | ||
120 | } | ||
121 | |||
122 | void bn_sqr_words(BN_ULONG *r, BN_ULONG *a, int n) | ||
123 | { | ||
124 | if (n <= 0) return; | ||
125 | |||
126 | while (n&~3) | ||
127 | { | ||
128 | sqr(r[0],r[1],a[0]); | ||
129 | sqr(r[2],r[3],a[1]); | ||
130 | sqr(r[4],r[5],a[2]); | ||
131 | sqr(r[6],r[7],a[3]); | ||
132 | a+=4; r+=8; n-=4; | ||
133 | } | ||
134 | if (n) | ||
135 | { | ||
136 | sqr(r[0],r[1],a[0]); if (--n == 0) return; | ||
137 | sqr(r[2],r[3],a[1]); if (--n == 0) return; | ||
138 | sqr(r[4],r[5],a[2]); | ||
139 | } | ||
140 | } | ||
141 | |||
142 | BN_ULONG bn_div_words(BN_ULONG h, BN_ULONG l, BN_ULONG d) | ||
143 | { BN_ULONG ret,waste; | ||
144 | |||
145 | asm ("divq %3" | ||
146 | : "=a"(ret),"=d"(waste) | ||
147 | : "a"(l),"d"(h),"g"(d) | ||
148 | : "cc"); | ||
149 | |||
150 | return ret; | ||
151 | } | ||
152 | |||
153 | BN_ULONG bn_add_words (BN_ULONG *rp, BN_ULONG *ap, BN_ULONG *bp,int n) | ||
154 | { BN_ULONG ret,i; | ||
155 | |||
156 | if (n <= 0) return 0; | ||
157 | |||
158 | asm ( | ||
159 | " subq %2,%2 \n" | ||
160 | ".align 16 \n" | ||
161 | "1: movq (%4,%2,8),%0 \n" | ||
162 | " adcq (%5,%2,8),%0 \n" | ||
163 | " movq %0,(%3,%2,8) \n" | ||
164 | " leaq 1(%2),%2 \n" | ||
165 | " loop 1b \n" | ||
166 | " sbbq %0,%0 \n" | ||
167 | : "+a"(ret),"+c"(n),"+r"(i) | ||
168 | : "r"(rp),"r"(ap),"r"(bp) | ||
169 | : "cc" | ||
170 | ); | ||
171 | |||
172 | return ret&1; | ||
173 | } | ||
174 | |||
175 | #ifndef SIMICS | ||
176 | BN_ULONG bn_sub_words (BN_ULONG *rp, BN_ULONG *ap, BN_ULONG *bp,int n) | ||
177 | { BN_ULONG ret,i; | ||
178 | |||
179 | if (n <= 0) return 0; | ||
180 | |||
181 | asm ( | ||
182 | " subq %2,%2 \n" | ||
183 | ".align 16 \n" | ||
184 | "1: movq (%4,%2,8),%0 \n" | ||
185 | " sbbq (%5,%2,8),%0 \n" | ||
186 | " movq %0,(%3,%2,8) \n" | ||
187 | " leaq 1(%2),%2 \n" | ||
188 | " loop 1b \n" | ||
189 | " sbbq %0,%0 \n" | ||
190 | : "+a"(ret),"+c"(n),"+r"(i) | ||
191 | : "r"(rp),"r"(ap),"r"(bp) | ||
192 | : "cc" | ||
193 | ); | ||
194 | |||
195 | return ret&1; | ||
196 | } | ||
197 | #else | ||
198 | /* Simics 1.4<7 has buggy sbbq:-( */ | ||
199 | #define BN_MASK2 0xffffffffffffffffL | ||
200 | BN_ULONG bn_sub_words(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n) | ||
201 | { | ||
202 | BN_ULONG t1,t2; | ||
203 | int c=0; | ||
204 | |||
205 | if (n <= 0) return((BN_ULONG)0); | ||
206 | |||
207 | for (;;) | ||
208 | { | ||
209 | t1=a[0]; t2=b[0]; | ||
210 | r[0]=(t1-t2-c)&BN_MASK2; | ||
211 | if (t1 != t2) c=(t1 < t2); | ||
212 | if (--n <= 0) break; | ||
213 | |||
214 | t1=a[1]; t2=b[1]; | ||
215 | r[1]=(t1-t2-c)&BN_MASK2; | ||
216 | if (t1 != t2) c=(t1 < t2); | ||
217 | if (--n <= 0) break; | ||
218 | |||
219 | t1=a[2]; t2=b[2]; | ||
220 | r[2]=(t1-t2-c)&BN_MASK2; | ||
221 | if (t1 != t2) c=(t1 < t2); | ||
222 | if (--n <= 0) break; | ||
223 | |||
224 | t1=a[3]; t2=b[3]; | ||
225 | r[3]=(t1-t2-c)&BN_MASK2; | ||
226 | if (t1 != t2) c=(t1 < t2); | ||
227 | if (--n <= 0) break; | ||
228 | |||
229 | a+=4; | ||
230 | b+=4; | ||
231 | r+=4; | ||
232 | } | ||
233 | return(c); | ||
234 | } | ||
235 | #endif | ||
236 | |||
237 | /* mul_add_c(a,b,c0,c1,c2) -- c+=a*b for three word number c=(c2,c1,c0) */ | ||
238 | /* mul_add_c2(a,b,c0,c1,c2) -- c+=2*a*b for three word number c=(c2,c1,c0) */ | ||
239 | /* sqr_add_c(a,i,c0,c1,c2) -- c+=a[i]^2 for three word number c=(c2,c1,c0) */ | ||
240 | /* sqr_add_c2(a,i,c0,c1,c2) -- c+=2*a[i]*a[j] for three word number c=(c2,c1,c0) */ | ||
241 | |||
242 | #if 0 | ||
243 | /* original macros are kept for reference purposes */ | ||
244 | #define mul_add_c(a,b,c0,c1,c2) { \ | ||
245 | BN_ULONG ta=(a),tb=(b); \ | ||
246 | t1 = ta * tb; \ | ||
247 | t2 = BN_UMULT_HIGH(ta,tb); \ | ||
248 | c0 += t1; t2 += (c0<t1)?1:0; \ | ||
249 | c1 += t2; c2 += (c1<t2)?1:0; \ | ||
250 | } | ||
251 | |||
252 | #define mul_add_c2(a,b,c0,c1,c2) { \ | ||
253 | BN_ULONG ta=(a),tb=(b),t0; \ | ||
254 | t1 = BN_UMULT_HIGH(ta,tb); \ | ||
255 | t0 = ta * tb; \ | ||
256 | t2 = t1+t1; c2 += (t2<t1)?1:0; \ | ||
257 | t1 = t0+t0; t2 += (t1<t0)?1:0; \ | ||
258 | c0 += t1; t2 += (c0<t1)?1:0; \ | ||
259 | c1 += t2; c2 += (c1<t2)?1:0; \ | ||
260 | } | ||
261 | #else | ||
262 | #define mul_add_c(a,b,c0,c1,c2) do { \ | ||
263 | asm ("mulq %3" \ | ||
264 | : "=a"(t1),"=d"(t2) \ | ||
265 | : "a"(a),"m"(b) \ | ||
266 | : "cc"); \ | ||
267 | asm ("addq %2,%0; adcq %3,%1" \ | ||
268 | : "+r"(c0),"+d"(t2) \ | ||
269 | : "a"(t1),"g"(0) \ | ||
270 | : "cc"); \ | ||
271 | asm ("addq %2,%0; adcq %3,%1" \ | ||
272 | : "+r"(c1),"+r"(c2) \ | ||
273 | : "d"(t2),"g"(0) \ | ||
274 | : "cc"); \ | ||
275 | } while (0) | ||
276 | |||
277 | #define sqr_add_c(a,i,c0,c1,c2) do { \ | ||
278 | asm ("mulq %2" \ | ||
279 | : "=a"(t1),"=d"(t2) \ | ||
280 | : "a"(a[i]) \ | ||
281 | : "cc"); \ | ||
282 | asm ("addq %2,%0; adcq %3,%1" \ | ||
283 | : "+r"(c0),"+d"(t2) \ | ||
284 | : "a"(t1),"g"(0) \ | ||
285 | : "cc"); \ | ||
286 | asm ("addq %2,%0; adcq %3,%1" \ | ||
287 | : "+r"(c1),"+r"(c2) \ | ||
288 | : "d"(t2),"g"(0) \ | ||
289 | : "cc"); \ | ||
290 | } while (0) | ||
291 | |||
292 | #define mul_add_c2(a,b,c0,c1,c2) do { \ | ||
293 | asm ("mulq %3" \ | ||
294 | : "=a"(t1),"=d"(t2) \ | ||
295 | : "a"(a),"m"(b) \ | ||
296 | : "cc"); \ | ||
297 | asm ("addq %0,%0; adcq %2,%1" \ | ||
298 | : "+d"(t2),"+r"(c2) \ | ||
299 | : "g"(0) \ | ||
300 | : "cc"); \ | ||
301 | asm ("addq %0,%0; adcq %2,%1" \ | ||
302 | : "+a"(t1),"+d"(t2) \ | ||
303 | : "g"(0) \ | ||
304 | : "cc"); \ | ||
305 | asm ("addq %2,%0; adcq %3,%1" \ | ||
306 | : "+r"(c0),"+d"(t2) \ | ||
307 | : "a"(t1),"g"(0) \ | ||
308 | : "cc"); \ | ||
309 | asm ("addq %2,%0; adcq %3,%1" \ | ||
310 | : "+r"(c1),"+r"(c2) \ | ||
311 | : "d"(t2),"g"(0) \ | ||
312 | : "cc"); \ | ||
313 | } while (0) | ||
314 | #endif | ||
315 | |||
316 | #define sqr_add_c2(a,i,j,c0,c1,c2) \ | ||
317 | mul_add_c2((a)[i],(a)[j],c0,c1,c2) | ||
318 | |||
319 | void bn_mul_comba8(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b) | ||
320 | { | ||
321 | BN_ULONG bl,bh; | ||
322 | BN_ULONG t1,t2; | ||
323 | BN_ULONG c1,c2,c3; | ||
324 | |||
325 | c1=0; | ||
326 | c2=0; | ||
327 | c3=0; | ||
328 | mul_add_c(a[0],b[0],c1,c2,c3); | ||
329 | r[0]=c1; | ||
330 | c1=0; | ||
331 | mul_add_c(a[0],b[1],c2,c3,c1); | ||
332 | mul_add_c(a[1],b[0],c2,c3,c1); | ||
333 | r[1]=c2; | ||
334 | c2=0; | ||
335 | mul_add_c(a[2],b[0],c3,c1,c2); | ||
336 | mul_add_c(a[1],b[1],c3,c1,c2); | ||
337 | mul_add_c(a[0],b[2],c3,c1,c2); | ||
338 | r[2]=c3; | ||
339 | c3=0; | ||
340 | mul_add_c(a[0],b[3],c1,c2,c3); | ||
341 | mul_add_c(a[1],b[2],c1,c2,c3); | ||
342 | mul_add_c(a[2],b[1],c1,c2,c3); | ||
343 | mul_add_c(a[3],b[0],c1,c2,c3); | ||
344 | r[3]=c1; | ||
345 | c1=0; | ||
346 | mul_add_c(a[4],b[0],c2,c3,c1); | ||
347 | mul_add_c(a[3],b[1],c2,c3,c1); | ||
348 | mul_add_c(a[2],b[2],c2,c3,c1); | ||
349 | mul_add_c(a[1],b[3],c2,c3,c1); | ||
350 | mul_add_c(a[0],b[4],c2,c3,c1); | ||
351 | r[4]=c2; | ||
352 | c2=0; | ||
353 | mul_add_c(a[0],b[5],c3,c1,c2); | ||
354 | mul_add_c(a[1],b[4],c3,c1,c2); | ||
355 | mul_add_c(a[2],b[3],c3,c1,c2); | ||
356 | mul_add_c(a[3],b[2],c3,c1,c2); | ||
357 | mul_add_c(a[4],b[1],c3,c1,c2); | ||
358 | mul_add_c(a[5],b[0],c3,c1,c2); | ||
359 | r[5]=c3; | ||
360 | c3=0; | ||
361 | mul_add_c(a[6],b[0],c1,c2,c3); | ||
362 | mul_add_c(a[5],b[1],c1,c2,c3); | ||
363 | mul_add_c(a[4],b[2],c1,c2,c3); | ||
364 | mul_add_c(a[3],b[3],c1,c2,c3); | ||
365 | mul_add_c(a[2],b[4],c1,c2,c3); | ||
366 | mul_add_c(a[1],b[5],c1,c2,c3); | ||
367 | mul_add_c(a[0],b[6],c1,c2,c3); | ||
368 | r[6]=c1; | ||
369 | c1=0; | ||
370 | mul_add_c(a[0],b[7],c2,c3,c1); | ||
371 | mul_add_c(a[1],b[6],c2,c3,c1); | ||
372 | mul_add_c(a[2],b[5],c2,c3,c1); | ||
373 | mul_add_c(a[3],b[4],c2,c3,c1); | ||
374 | mul_add_c(a[4],b[3],c2,c3,c1); | ||
375 | mul_add_c(a[5],b[2],c2,c3,c1); | ||
376 | mul_add_c(a[6],b[1],c2,c3,c1); | ||
377 | mul_add_c(a[7],b[0],c2,c3,c1); | ||
378 | r[7]=c2; | ||
379 | c2=0; | ||
380 | mul_add_c(a[7],b[1],c3,c1,c2); | ||
381 | mul_add_c(a[6],b[2],c3,c1,c2); | ||
382 | mul_add_c(a[5],b[3],c3,c1,c2); | ||
383 | mul_add_c(a[4],b[4],c3,c1,c2); | ||
384 | mul_add_c(a[3],b[5],c3,c1,c2); | ||
385 | mul_add_c(a[2],b[6],c3,c1,c2); | ||
386 | mul_add_c(a[1],b[7],c3,c1,c2); | ||
387 | r[8]=c3; | ||
388 | c3=0; | ||
389 | mul_add_c(a[2],b[7],c1,c2,c3); | ||
390 | mul_add_c(a[3],b[6],c1,c2,c3); | ||
391 | mul_add_c(a[4],b[5],c1,c2,c3); | ||
392 | mul_add_c(a[5],b[4],c1,c2,c3); | ||
393 | mul_add_c(a[6],b[3],c1,c2,c3); | ||
394 | mul_add_c(a[7],b[2],c1,c2,c3); | ||
395 | r[9]=c1; | ||
396 | c1=0; | ||
397 | mul_add_c(a[7],b[3],c2,c3,c1); | ||
398 | mul_add_c(a[6],b[4],c2,c3,c1); | ||
399 | mul_add_c(a[5],b[5],c2,c3,c1); | ||
400 | mul_add_c(a[4],b[6],c2,c3,c1); | ||
401 | mul_add_c(a[3],b[7],c2,c3,c1); | ||
402 | r[10]=c2; | ||
403 | c2=0; | ||
404 | mul_add_c(a[4],b[7],c3,c1,c2); | ||
405 | mul_add_c(a[5],b[6],c3,c1,c2); | ||
406 | mul_add_c(a[6],b[5],c3,c1,c2); | ||
407 | mul_add_c(a[7],b[4],c3,c1,c2); | ||
408 | r[11]=c3; | ||
409 | c3=0; | ||
410 | mul_add_c(a[7],b[5],c1,c2,c3); | ||
411 | mul_add_c(a[6],b[6],c1,c2,c3); | ||
412 | mul_add_c(a[5],b[7],c1,c2,c3); | ||
413 | r[12]=c1; | ||
414 | c1=0; | ||
415 | mul_add_c(a[6],b[7],c2,c3,c1); | ||
416 | mul_add_c(a[7],b[6],c2,c3,c1); | ||
417 | r[13]=c2; | ||
418 | c2=0; | ||
419 | mul_add_c(a[7],b[7],c3,c1,c2); | ||
420 | r[14]=c3; | ||
421 | r[15]=c1; | ||
422 | } | ||
423 | |||
424 | void bn_mul_comba4(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b) | ||
425 | { | ||
426 | BN_ULONG bl,bh; | ||
427 | BN_ULONG t1,t2; | ||
428 | BN_ULONG c1,c2,c3; | ||
429 | |||
430 | c1=0; | ||
431 | c2=0; | ||
432 | c3=0; | ||
433 | mul_add_c(a[0],b[0],c1,c2,c3); | ||
434 | r[0]=c1; | ||
435 | c1=0; | ||
436 | mul_add_c(a[0],b[1],c2,c3,c1); | ||
437 | mul_add_c(a[1],b[0],c2,c3,c1); | ||
438 | r[1]=c2; | ||
439 | c2=0; | ||
440 | mul_add_c(a[2],b[0],c3,c1,c2); | ||
441 | mul_add_c(a[1],b[1],c3,c1,c2); | ||
442 | mul_add_c(a[0],b[2],c3,c1,c2); | ||
443 | r[2]=c3; | ||
444 | c3=0; | ||
445 | mul_add_c(a[0],b[3],c1,c2,c3); | ||
446 | mul_add_c(a[1],b[2],c1,c2,c3); | ||
447 | mul_add_c(a[2],b[1],c1,c2,c3); | ||
448 | mul_add_c(a[3],b[0],c1,c2,c3); | ||
449 | r[3]=c1; | ||
450 | c1=0; | ||
451 | mul_add_c(a[3],b[1],c2,c3,c1); | ||
452 | mul_add_c(a[2],b[2],c2,c3,c1); | ||
453 | mul_add_c(a[1],b[3],c2,c3,c1); | ||
454 | r[4]=c2; | ||
455 | c2=0; | ||
456 | mul_add_c(a[2],b[3],c3,c1,c2); | ||
457 | mul_add_c(a[3],b[2],c3,c1,c2); | ||
458 | r[5]=c3; | ||
459 | c3=0; | ||
460 | mul_add_c(a[3],b[3],c1,c2,c3); | ||
461 | r[6]=c1; | ||
462 | r[7]=c2; | ||
463 | } | ||
464 | |||
465 | void bn_sqr_comba8(BN_ULONG *r, BN_ULONG *a) | ||
466 | { | ||
467 | BN_ULONG bl,bh; | ||
468 | BN_ULONG t1,t2; | ||
469 | BN_ULONG c1,c2,c3; | ||
470 | |||
471 | c1=0; | ||
472 | c2=0; | ||
473 | c3=0; | ||
474 | sqr_add_c(a,0,c1,c2,c3); | ||
475 | r[0]=c1; | ||
476 | c1=0; | ||
477 | sqr_add_c2(a,1,0,c2,c3,c1); | ||
478 | r[1]=c2; | ||
479 | c2=0; | ||
480 | sqr_add_c(a,1,c3,c1,c2); | ||
481 | sqr_add_c2(a,2,0,c3,c1,c2); | ||
482 | r[2]=c3; | ||
483 | c3=0; | ||
484 | sqr_add_c2(a,3,0,c1,c2,c3); | ||
485 | sqr_add_c2(a,2,1,c1,c2,c3); | ||
486 | r[3]=c1; | ||
487 | c1=0; | ||
488 | sqr_add_c(a,2,c2,c3,c1); | ||
489 | sqr_add_c2(a,3,1,c2,c3,c1); | ||
490 | sqr_add_c2(a,4,0,c2,c3,c1); | ||
491 | r[4]=c2; | ||
492 | c2=0; | ||
493 | sqr_add_c2(a,5,0,c3,c1,c2); | ||
494 | sqr_add_c2(a,4,1,c3,c1,c2); | ||
495 | sqr_add_c2(a,3,2,c3,c1,c2); | ||
496 | r[5]=c3; | ||
497 | c3=0; | ||
498 | sqr_add_c(a,3,c1,c2,c3); | ||
499 | sqr_add_c2(a,4,2,c1,c2,c3); | ||
500 | sqr_add_c2(a,5,1,c1,c2,c3); | ||
501 | sqr_add_c2(a,6,0,c1,c2,c3); | ||
502 | r[6]=c1; | ||
503 | c1=0; | ||
504 | sqr_add_c2(a,7,0,c2,c3,c1); | ||
505 | sqr_add_c2(a,6,1,c2,c3,c1); | ||
506 | sqr_add_c2(a,5,2,c2,c3,c1); | ||
507 | sqr_add_c2(a,4,3,c2,c3,c1); | ||
508 | r[7]=c2; | ||
509 | c2=0; | ||
510 | sqr_add_c(a,4,c3,c1,c2); | ||
511 | sqr_add_c2(a,5,3,c3,c1,c2); | ||
512 | sqr_add_c2(a,6,2,c3,c1,c2); | ||
513 | sqr_add_c2(a,7,1,c3,c1,c2); | ||
514 | r[8]=c3; | ||
515 | c3=0; | ||
516 | sqr_add_c2(a,7,2,c1,c2,c3); | ||
517 | sqr_add_c2(a,6,3,c1,c2,c3); | ||
518 | sqr_add_c2(a,5,4,c1,c2,c3); | ||
519 | r[9]=c1; | ||
520 | c1=0; | ||
521 | sqr_add_c(a,5,c2,c3,c1); | ||
522 | sqr_add_c2(a,6,4,c2,c3,c1); | ||
523 | sqr_add_c2(a,7,3,c2,c3,c1); | ||
524 | r[10]=c2; | ||
525 | c2=0; | ||
526 | sqr_add_c2(a,7,4,c3,c1,c2); | ||
527 | sqr_add_c2(a,6,5,c3,c1,c2); | ||
528 | r[11]=c3; | ||
529 | c3=0; | ||
530 | sqr_add_c(a,6,c1,c2,c3); | ||
531 | sqr_add_c2(a,7,5,c1,c2,c3); | ||
532 | r[12]=c1; | ||
533 | c1=0; | ||
534 | sqr_add_c2(a,7,6,c2,c3,c1); | ||
535 | r[13]=c2; | ||
536 | c2=0; | ||
537 | sqr_add_c(a,7,c3,c1,c2); | ||
538 | r[14]=c3; | ||
539 | r[15]=c1; | ||
540 | } | ||
541 | |||
542 | void bn_sqr_comba4(BN_ULONG *r, BN_ULONG *a) | ||
543 | { | ||
544 | BN_ULONG bl,bh; | ||
545 | BN_ULONG t1,t2; | ||
546 | BN_ULONG c1,c2,c3; | ||
547 | |||
548 | c1=0; | ||
549 | c2=0; | ||
550 | c3=0; | ||
551 | sqr_add_c(a,0,c1,c2,c3); | ||
552 | r[0]=c1; | ||
553 | c1=0; | ||
554 | sqr_add_c2(a,1,0,c2,c3,c1); | ||
555 | r[1]=c2; | ||
556 | c2=0; | ||
557 | sqr_add_c(a,1,c3,c1,c2); | ||
558 | sqr_add_c2(a,2,0,c3,c1,c2); | ||
559 | r[2]=c3; | ||
560 | c3=0; | ||
561 | sqr_add_c2(a,3,0,c1,c2,c3); | ||
562 | sqr_add_c2(a,2,1,c1,c2,c3); | ||
563 | r[3]=c1; | ||
564 | c1=0; | ||
565 | sqr_add_c(a,2,c2,c3,c1); | ||
566 | sqr_add_c2(a,3,1,c2,c3,c1); | ||
567 | r[4]=c2; | ||
568 | c2=0; | ||
569 | sqr_add_c2(a,3,2,c3,c1,c2); | ||
570 | r[5]=c3; | ||
571 | c3=0; | ||
572 | sqr_add_c(a,3,c1,c2,c3); | ||
573 | r[6]=c1; | ||
574 | r[7]=c2; | ||
575 | } | ||
diff --git a/src/lib/libcrypto/bn/bn.h b/src/lib/libcrypto/bn/bn.h index b40682f831..3da6d8ced9 100644 --- a/src/lib/libcrypto/bn/bn.h +++ b/src/lib/libcrypto/bn/bn.h | |||
@@ -248,6 +248,8 @@ typedef struct bn_blinding_st | |||
248 | BIGNUM *A; | 248 | BIGNUM *A; |
249 | BIGNUM *Ai; | 249 | BIGNUM *Ai; |
250 | BIGNUM *mod; /* just a reference */ | 250 | BIGNUM *mod; /* just a reference */ |
251 | unsigned long thread_id; /* added in OpenSSL 0.9.6j and 0.9.7b; | ||
252 | * used only by crypto/rsa/rsa_eay.c, rsa_lib.c */ | ||
251 | } BN_BLINDING; | 253 | } BN_BLINDING; |
252 | 254 | ||
253 | /* Used for montgomery multiplication */ | 255 | /* Used for montgomery multiplication */ |
diff --git a/src/lib/libcrypto/bn/bn_div.c b/src/lib/libcrypto/bn/bn_div.c index f9a095e3b3..580d1201bc 100644 --- a/src/lib/libcrypto/bn/bn_div.c +++ b/src/lib/libcrypto/bn/bn_div.c | |||
@@ -150,6 +150,20 @@ int BN_div(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m, const BIGNUM *d, | |||
150 | q; \ | 150 | q; \ |
151 | }) | 151 | }) |
152 | # define REMAINDER_IS_ALREADY_CALCULATED | 152 | # define REMAINDER_IS_ALREADY_CALCULATED |
153 | # elif defined(__x86_64) && defined(SIXTY_FOUR_BIT_LONG) | ||
154 | /* | ||
155 | * Same story here, but it's 128-bit by 64-bit division. Wow! | ||
156 | * <appro@fy.chalmers.se> | ||
157 | */ | ||
158 | # define bn_div_words(n0,n1,d0) \ | ||
159 | ({ asm volatile ( \ | ||
160 | "divq %4" \ | ||
161 | : "=a"(q), "=d"(rem) \ | ||
162 | : "a"(n1), "d"(n0), "g"(d0) \ | ||
163 | : "cc"); \ | ||
164 | q; \ | ||
165 | }) | ||
166 | # define REMAINDER_IS_ALREADY_CALCULATED | ||
153 | # endif /* __<cpu> */ | 167 | # endif /* __<cpu> */ |
154 | # endif /* __GNUC__ */ | 168 | # endif /* __GNUC__ */ |
155 | #endif /* OPENSSL_NO_ASM */ | 169 | #endif /* OPENSSL_NO_ASM */ |
@@ -268,6 +282,11 @@ int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor, | |||
268 | q=(BN_ULONG)(((((BN_ULLONG)n0)<<BN_BITS2)|n1)/d0); | 282 | q=(BN_ULONG)(((((BN_ULLONG)n0)<<BN_BITS2)|n1)/d0); |
269 | #else | 283 | #else |
270 | q=bn_div_words(n0,n1,d0); | 284 | q=bn_div_words(n0,n1,d0); |
285 | #ifdef BN_DEBUG_LEVITTE | ||
286 | fprintf(stderr,"DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\ | ||
287 | X) -> 0x%08X\n", | ||
288 | n0, n1, d0, q); | ||
289 | #endif | ||
271 | #endif | 290 | #endif |
272 | 291 | ||
273 | #ifndef REMAINDER_IS_ALREADY_CALCULATED | 292 | #ifndef REMAINDER_IS_ALREADY_CALCULATED |
@@ -292,11 +311,18 @@ int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor, | |||
292 | BN_ULONG t2l,t2h,ql,qh; | 311 | BN_ULONG t2l,t2h,ql,qh; |
293 | 312 | ||
294 | q=bn_div_words(n0,n1,d0); | 313 | q=bn_div_words(n0,n1,d0); |
314 | #ifdef BN_DEBUG_LEVITTE | ||
315 | fprintf(stderr,"DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\ | ||
316 | X) -> 0x%08X\n", | ||
317 | n0, n1, d0, q); | ||
318 | #endif | ||
295 | #ifndef REMAINDER_IS_ALREADY_CALCULATED | 319 | #ifndef REMAINDER_IS_ALREADY_CALCULATED |
296 | rem=(n1-q*d0)&BN_MASK2; | 320 | rem=(n1-q*d0)&BN_MASK2; |
297 | #endif | 321 | #endif |
298 | 322 | ||
299 | #ifdef BN_UMULT_HIGH | 323 | #if defined(BN_UMULT_LOHI) |
324 | BN_UMULT_LOHI(t2l,t2h,d1,q); | ||
325 | #elif defined(BN_UMULT_HIGH) | ||
300 | t2l = d1 * q; | 326 | t2l = d1 * q; |
301 | t2h = BN_UMULT_HIGH(d1,q); | 327 | t2h = BN_UMULT_HIGH(d1,q); |
302 | #else | 328 | #else |
diff --git a/src/lib/libcrypto/bn/bn_lcl.h b/src/lib/libcrypto/bn/bn_lcl.h index 8a4dba375a..5614bc6164 100644 --- a/src/lib/libcrypto/bn/bn_lcl.h +++ b/src/lib/libcrypto/bn/bn_lcl.h | |||
@@ -230,6 +230,21 @@ struct bignum_ctx | |||
230 | : "r"(a), "r"(b)); \ | 230 | : "r"(a), "r"(b)); \ |
231 | ret; }) | 231 | ret; }) |
232 | # endif /* compiler */ | 232 | # endif /* compiler */ |
233 | # elif defined(__x86_64) && defined(SIXTY_FOUR_BIT_LONG) | ||
234 | # if defined(__GNUC__) | ||
235 | # define BN_UMULT_HIGH(a,b) ({ \ | ||
236 | register BN_ULONG ret,discard; \ | ||
237 | asm ("mulq %3" \ | ||
238 | : "=a"(discard),"=d"(ret) \ | ||
239 | : "a"(a), "g"(b) \ | ||
240 | : "cc"); \ | ||
241 | ret; }) | ||
242 | # define BN_UMULT_LOHI(low,high,a,b) \ | ||
243 | asm ("mulq %3" \ | ||
244 | : "=a"(low),"=d"(high) \ | ||
245 | : "a"(a),"g"(b) \ | ||
246 | : "cc"); | ||
247 | # endif | ||
233 | # endif /* cpu */ | 248 | # endif /* cpu */ |
234 | #endif /* OPENSSL_NO_ASM */ | 249 | #endif /* OPENSSL_NO_ASM */ |
235 | 250 | ||
@@ -337,7 +352,7 @@ struct bignum_ctx | |||
337 | 352 | ||
338 | #define LBITS(a) ((a)&BN_MASK2l) | 353 | #define LBITS(a) ((a)&BN_MASK2l) |
339 | #define HBITS(a) (((a)>>BN_BITS4)&BN_MASK2l) | 354 | #define HBITS(a) (((a)>>BN_BITS4)&BN_MASK2l) |
340 | #define L2HBITS(a) ((BN_ULONG)((a)&BN_MASK2l)<<BN_BITS4) | 355 | #define L2HBITS(a) (((a)<<BN_BITS4)&BN_MASK2) |
341 | 356 | ||
342 | #define LLBITS(a) ((a)&BN_MASKl) | 357 | #define LLBITS(a) ((a)&BN_MASKl) |
343 | #define LHBITS(a) (((a)>>BN_BITS2)&BN_MASKl) | 358 | #define LHBITS(a) (((a)>>BN_BITS2)&BN_MASKl) |
@@ -353,7 +368,7 @@ struct bignum_ctx | |||
353 | lt=(bl)*(lt); \ | 368 | lt=(bl)*(lt); \ |
354 | m1=(bl)*(ht); \ | 369 | m1=(bl)*(ht); \ |
355 | ht =(bh)*(ht); \ | 370 | ht =(bh)*(ht); \ |
356 | m=(m+m1)&BN_MASK2; if (m < m1) ht+=L2HBITS(1L); \ | 371 | m=(m+m1)&BN_MASK2; if (m < m1) ht+=L2HBITS((BN_ULONG)1); \ |
357 | ht+=HBITS(m); \ | 372 | ht+=HBITS(m); \ |
358 | m1=L2HBITS(m); \ | 373 | m1=L2HBITS(m); \ |
359 | lt=(lt+m1)&BN_MASK2; if (lt < m1) ht++; \ | 374 | lt=(lt+m1)&BN_MASK2; if (lt < m1) ht++; \ |
@@ -418,20 +433,19 @@ void bn_sqr_comba4(BN_ULONG *r,const BN_ULONG *a); | |||
418 | int bn_cmp_words(const BN_ULONG *a,const BN_ULONG *b,int n); | 433 | int bn_cmp_words(const BN_ULONG *a,const BN_ULONG *b,int n); |
419 | int bn_cmp_part_words(const BN_ULONG *a, const BN_ULONG *b, | 434 | int bn_cmp_part_words(const BN_ULONG *a, const BN_ULONG *b, |
420 | int cl, int dl); | 435 | int cl, int dl); |
436 | #if 0 | ||
437 | /* bn_mul.c rollback <appro> */ | ||
421 | void bn_mul_recursive(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b,int n2, | 438 | void bn_mul_recursive(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b,int n2, |
422 | int dna,int dnb,BN_ULONG *t); | 439 | int dna,int dnb,BN_ULONG *t); |
423 | void bn_mul_part_recursive(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b, | 440 | void bn_mul_part_recursive(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b, |
424 | int n,int tna,int tnb,BN_ULONG *t); | 441 | int n,int tna,int tnb,BN_ULONG *t); |
442 | #endif | ||
425 | void bn_sqr_recursive(BN_ULONG *r,const BN_ULONG *a, int n2, BN_ULONG *t); | 443 | void bn_sqr_recursive(BN_ULONG *r,const BN_ULONG *a, int n2, BN_ULONG *t); |
426 | void bn_mul_low_normal(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b, int n); | 444 | void bn_mul_low_normal(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b, int n); |
427 | void bn_mul_low_recursive(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b,int n2, | 445 | void bn_mul_low_recursive(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b,int n2, |
428 | BN_ULONG *t); | 446 | BN_ULONG *t); |
429 | void bn_mul_high(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b,BN_ULONG *l,int n2, | 447 | void bn_mul_high(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b,BN_ULONG *l,int n2, |
430 | BN_ULONG *t); | 448 | BN_ULONG *t); |
431 | BN_ULONG bn_add_part_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *b, | ||
432 | int cl, int dl); | ||
433 | BN_ULONG bn_sub_part_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *b, | ||
434 | int cl, int dl); | ||
435 | 449 | ||
436 | #ifdef __cplusplus | 450 | #ifdef __cplusplus |
437 | } | 451 | } |
diff --git a/src/lib/libcrypto/bn/bn_lib.c b/src/lib/libcrypto/bn/bn_lib.c index 8abe095af2..fa0ff485ad 100644 --- a/src/lib/libcrypto/bn/bn_lib.c +++ b/src/lib/libcrypto/bn/bn_lib.c | |||
@@ -263,12 +263,12 @@ void BN_clear_free(BIGNUM *a) | |||
263 | if (a == NULL) return; | 263 | if (a == NULL) return; |
264 | if (a->d != NULL) | 264 | if (a->d != NULL) |
265 | { | 265 | { |
266 | memset(a->d,0,a->dmax*sizeof(a->d[0])); | 266 | OPENSSL_cleanse(a->d,a->dmax*sizeof(a->d[0])); |
267 | if (!(BN_get_flags(a,BN_FLG_STATIC_DATA))) | 267 | if (!(BN_get_flags(a,BN_FLG_STATIC_DATA))) |
268 | OPENSSL_free(a->d); | 268 | OPENSSL_free(a->d); |
269 | } | 269 | } |
270 | i=BN_get_flags(a,BN_FLG_MALLOCED); | 270 | i=BN_get_flags(a,BN_FLG_MALLOCED); |
271 | memset(a,0,sizeof(BIGNUM)); | 271 | OPENSSL_cleanse(a,sizeof(BIGNUM)); |
272 | if (i) | 272 | if (i) |
273 | OPENSSL_free(a); | 273 | OPENSSL_free(a); |
274 | } | 274 | } |
diff --git a/src/lib/libcrypto/bn/bn_mul.c b/src/lib/libcrypto/bn/bn_mul.c index b03458d002..cb93ac3356 100644 --- a/src/lib/libcrypto/bn/bn_mul.c +++ b/src/lib/libcrypto/bn/bn_mul.c | |||
@@ -56,325 +56,10 @@ | |||
56 | * [including the GNU Public Licence.] | 56 | * [including the GNU Public Licence.] |
57 | */ | 57 | */ |
58 | 58 | ||
59 | #ifndef BN_DEBUG | ||
60 | # undef NDEBUG /* avoid conflicting definitions */ | ||
61 | # define NDEBUG | ||
62 | #endif | ||
63 | |||
64 | #include <stdio.h> | 59 | #include <stdio.h> |
65 | #include <assert.h> | ||
66 | #include "cryptlib.h" | 60 | #include "cryptlib.h" |
67 | #include "bn_lcl.h" | 61 | #include "bn_lcl.h" |
68 | 62 | ||
69 | #if defined(OPENSSL_NO_ASM) || !(defined(__i386) || defined(__i386__)) || defined(__DJGPP__) /* Assembler implementation exists only for x86 */ | ||
70 | /* Here follows specialised variants of bn_add_words() and | ||
71 | bn_sub_words(). They have the property performing operations on | ||
72 | arrays of different sizes. The sizes of those arrays is expressed through | ||
73 | cl, which is the common length ( basicall, min(len(a),len(b)) ), and dl, | ||
74 | which is the delta between the two lengths, calculated as len(a)-len(b). | ||
75 | All lengths are the number of BN_ULONGs... For the operations that require | ||
76 | a result array as parameter, it must have the length cl+abs(dl). | ||
77 | These functions should probably end up in bn_asm.c as soon as there are | ||
78 | assembler counterparts for the systems that use assembler files. */ | ||
79 | |||
80 | BN_ULONG bn_sub_part_words(BN_ULONG *r, | ||
81 | const BN_ULONG *a, const BN_ULONG *b, | ||
82 | int cl, int dl) | ||
83 | { | ||
84 | BN_ULONG c, t; | ||
85 | |||
86 | assert(cl >= 0); | ||
87 | c = bn_sub_words(r, a, b, cl); | ||
88 | |||
89 | if (dl == 0) | ||
90 | return c; | ||
91 | |||
92 | r += cl; | ||
93 | a += cl; | ||
94 | b += cl; | ||
95 | |||
96 | if (dl < 0) | ||
97 | { | ||
98 | #ifdef BN_COUNT | ||
99 | fprintf(stderr, " bn_sub_part_words %d + %d (dl < 0, c = %d)\n", cl, dl, c); | ||
100 | #endif | ||
101 | for (;;) | ||
102 | { | ||
103 | t = b[0]; | ||
104 | r[0] = (0-t-c)&BN_MASK2; | ||
105 | if (t != 0) c=1; | ||
106 | if (++dl >= 0) break; | ||
107 | |||
108 | t = b[1]; | ||
109 | r[1] = (0-t-c)&BN_MASK2; | ||
110 | if (t != 0) c=1; | ||
111 | if (++dl >= 0) break; | ||
112 | |||
113 | t = b[2]; | ||
114 | r[2] = (0-t-c)&BN_MASK2; | ||
115 | if (t != 0) c=1; | ||
116 | if (++dl >= 0) break; | ||
117 | |||
118 | t = b[3]; | ||
119 | r[3] = (0-t-c)&BN_MASK2; | ||
120 | if (t != 0) c=1; | ||
121 | if (++dl >= 0) break; | ||
122 | |||
123 | b += 4; | ||
124 | r += 4; | ||
125 | } | ||
126 | } | ||
127 | else | ||
128 | { | ||
129 | int save_dl = dl; | ||
130 | #ifdef BN_COUNT | ||
131 | fprintf(stderr, " bn_sub_part_words %d + %d (dl > 0, c = %d)\n", cl, dl, c); | ||
132 | #endif | ||
133 | while(c) | ||
134 | { | ||
135 | t = a[0]; | ||
136 | r[0] = (t-c)&BN_MASK2; | ||
137 | if (t != 0) c=0; | ||
138 | if (--dl <= 0) break; | ||
139 | |||
140 | t = a[1]; | ||
141 | r[1] = (t-c)&BN_MASK2; | ||
142 | if (t != 0) c=0; | ||
143 | if (--dl <= 0) break; | ||
144 | |||
145 | t = a[2]; | ||
146 | r[2] = (t-c)&BN_MASK2; | ||
147 | if (t != 0) c=0; | ||
148 | if (--dl <= 0) break; | ||
149 | |||
150 | t = a[3]; | ||
151 | r[3] = (t-c)&BN_MASK2; | ||
152 | if (t != 0) c=0; | ||
153 | if (--dl <= 0) break; | ||
154 | |||
155 | save_dl = dl; | ||
156 | a += 4; | ||
157 | r += 4; | ||
158 | } | ||
159 | if (dl > 0) | ||
160 | { | ||
161 | #ifdef BN_COUNT | ||
162 | fprintf(stderr, " bn_sub_part_words %d + %d (dl > 0, c == 0)\n", cl, dl); | ||
163 | #endif | ||
164 | if (save_dl > dl) | ||
165 | { | ||
166 | switch (save_dl - dl) | ||
167 | { | ||
168 | case 1: | ||
169 | r[1] = a[1]; | ||
170 | if (--dl <= 0) break; | ||
171 | case 2: | ||
172 | r[2] = a[2]; | ||
173 | if (--dl <= 0) break; | ||
174 | case 3: | ||
175 | r[3] = a[3]; | ||
176 | if (--dl <= 0) break; | ||
177 | } | ||
178 | a += 4; | ||
179 | r += 4; | ||
180 | } | ||
181 | } | ||
182 | if (dl > 0) | ||
183 | { | ||
184 | #ifdef BN_COUNT | ||
185 | fprintf(stderr, " bn_sub_part_words %d + %d (dl > 0, copy)\n", cl, dl); | ||
186 | #endif | ||
187 | for(;;) | ||
188 | { | ||
189 | r[0] = a[0]; | ||
190 | if (--dl <= 0) break; | ||
191 | r[1] = a[1]; | ||
192 | if (--dl <= 0) break; | ||
193 | r[2] = a[2]; | ||
194 | if (--dl <= 0) break; | ||
195 | r[3] = a[3]; | ||
196 | if (--dl <= 0) break; | ||
197 | |||
198 | a += 4; | ||
199 | r += 4; | ||
200 | } | ||
201 | } | ||
202 | } | ||
203 | return c; | ||
204 | } | ||
205 | #endif | ||
206 | |||
207 | BN_ULONG bn_add_part_words(BN_ULONG *r, | ||
208 | const BN_ULONG *a, const BN_ULONG *b, | ||
209 | int cl, int dl) | ||
210 | { | ||
211 | BN_ULONG c, l, t; | ||
212 | |||
213 | assert(cl >= 0); | ||
214 | c = bn_add_words(r, a, b, cl); | ||
215 | |||
216 | if (dl == 0) | ||
217 | return c; | ||
218 | |||
219 | r += cl; | ||
220 | a += cl; | ||
221 | b += cl; | ||
222 | |||
223 | if (dl < 0) | ||
224 | { | ||
225 | int save_dl = dl; | ||
226 | #ifdef BN_COUNT | ||
227 | fprintf(stderr, " bn_add_part_words %d + %d (dl < 0, c = %d)\n", cl, dl, c); | ||
228 | #endif | ||
229 | while (c) | ||
230 | { | ||
231 | l=(c+b[0])&BN_MASK2; | ||
232 | c=(l < c); | ||
233 | r[0]=l; | ||
234 | if (++dl >= 0) break; | ||
235 | |||
236 | l=(c+b[1])&BN_MASK2; | ||
237 | c=(l < c); | ||
238 | r[1]=l; | ||
239 | if (++dl >= 0) break; | ||
240 | |||
241 | l=(c+b[2])&BN_MASK2; | ||
242 | c=(l < c); | ||
243 | r[2]=l; | ||
244 | if (++dl >= 0) break; | ||
245 | |||
246 | l=(c+b[3])&BN_MASK2; | ||
247 | c=(l < c); | ||
248 | r[3]=l; | ||
249 | if (++dl >= 0) break; | ||
250 | |||
251 | save_dl = dl; | ||
252 | b+=4; | ||
253 | r+=4; | ||
254 | } | ||
255 | if (dl < 0) | ||
256 | { | ||
257 | #ifdef BN_COUNT | ||
258 | fprintf(stderr, " bn_add_part_words %d + %d (dl < 0, c == 0)\n", cl, dl); | ||
259 | #endif | ||
260 | if (save_dl < dl) | ||
261 | { | ||
262 | switch (dl - save_dl) | ||
263 | { | ||
264 | case 1: | ||
265 | r[1] = b[1]; | ||
266 | if (++dl >= 0) break; | ||
267 | case 2: | ||
268 | r[2] = b[2]; | ||
269 | if (++dl >= 0) break; | ||
270 | case 3: | ||
271 | r[3] = b[3]; | ||
272 | if (++dl >= 0) break; | ||
273 | } | ||
274 | b += 4; | ||
275 | r += 4; | ||
276 | } | ||
277 | } | ||
278 | if (dl < 0) | ||
279 | { | ||
280 | #ifdef BN_COUNT | ||
281 | fprintf(stderr, " bn_add_part_words %d + %d (dl < 0, copy)\n", cl, dl); | ||
282 | #endif | ||
283 | for(;;) | ||
284 | { | ||
285 | r[0] = b[0]; | ||
286 | if (++dl >= 0) break; | ||
287 | r[1] = b[1]; | ||
288 | if (++dl >= 0) break; | ||
289 | r[2] = b[2]; | ||
290 | if (++dl >= 0) break; | ||
291 | r[3] = b[3]; | ||
292 | if (++dl >= 0) break; | ||
293 | |||
294 | b += 4; | ||
295 | r += 4; | ||
296 | } | ||
297 | } | ||
298 | } | ||
299 | else | ||
300 | { | ||
301 | int save_dl = dl; | ||
302 | #ifdef BN_COUNT | ||
303 | fprintf(stderr, " bn_add_part_words %d + %d (dl > 0)\n", cl, dl); | ||
304 | #endif | ||
305 | while (c) | ||
306 | { | ||
307 | t=(a[0]+c)&BN_MASK2; | ||
308 | c=(t < c); | ||
309 | r[0]=t; | ||
310 | if (--dl <= 0) break; | ||
311 | |||
312 | t=(a[1]+c)&BN_MASK2; | ||
313 | c=(t < c); | ||
314 | r[1]=t; | ||
315 | if (--dl <= 0) break; | ||
316 | |||
317 | t=(a[2]+c)&BN_MASK2; | ||
318 | c=(t < c); | ||
319 | r[2]=t; | ||
320 | if (--dl <= 0) break; | ||
321 | |||
322 | t=(a[3]+c)&BN_MASK2; | ||
323 | c=(t < c); | ||
324 | r[3]=t; | ||
325 | if (--dl <= 0) break; | ||
326 | |||
327 | save_dl = dl; | ||
328 | a+=4; | ||
329 | r+=4; | ||
330 | } | ||
331 | #ifdef BN_COUNT | ||
332 | fprintf(stderr, " bn_add_part_words %d + %d (dl > 0, c == 0)\n", cl, dl); | ||
333 | #endif | ||
334 | if (dl > 0) | ||
335 | { | ||
336 | if (save_dl > dl) | ||
337 | { | ||
338 | switch (save_dl - dl) | ||
339 | { | ||
340 | case 1: | ||
341 | r[1] = a[1]; | ||
342 | if (--dl <= 0) break; | ||
343 | case 2: | ||
344 | r[2] = a[2]; | ||
345 | if (--dl <= 0) break; | ||
346 | case 3: | ||
347 | r[3] = a[3]; | ||
348 | if (--dl <= 0) break; | ||
349 | } | ||
350 | a += 4; | ||
351 | r += 4; | ||
352 | } | ||
353 | } | ||
354 | if (dl > 0) | ||
355 | { | ||
356 | #ifdef BN_COUNT | ||
357 | fprintf(stderr, " bn_add_part_words %d + %d (dl > 0, copy)\n", cl, dl); | ||
358 | #endif | ||
359 | for(;;) | ||
360 | { | ||
361 | r[0] = a[0]; | ||
362 | if (--dl <= 0) break; | ||
363 | r[1] = a[1]; | ||
364 | if (--dl <= 0) break; | ||
365 | r[2] = a[2]; | ||
366 | if (--dl <= 0) break; | ||
367 | r[3] = a[3]; | ||
368 | if (--dl <= 0) break; | ||
369 | |||
370 | a += 4; | ||
371 | r += 4; | ||
372 | } | ||
373 | } | ||
374 | } | ||
375 | return c; | ||
376 | } | ||
377 | |||
378 | #ifdef BN_RECURSION | 63 | #ifdef BN_RECURSION |
379 | /* Karatsuba recursive multiplication algorithm | 64 | /* Karatsuba recursive multiplication algorithm |
380 | * (cf. Knuth, The Art of Computer Programming, Vol. 2) */ | 65 | * (cf. Knuth, The Art of Computer Programming, Vol. 2) */ |
@@ -390,15 +75,14 @@ BN_ULONG bn_add_part_words(BN_ULONG *r, | |||
390 | * a[1]*b[1] | 75 | * a[1]*b[1] |
391 | */ | 76 | */ |
392 | void bn_mul_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n2, | 77 | void bn_mul_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n2, |
393 | int dna, int dnb, BN_ULONG *t) | 78 | BN_ULONG *t) |
394 | { | 79 | { |
395 | int n=n2/2,c1,c2; | 80 | int n=n2/2,c1,c2; |
396 | int tna=n+dna, tnb=n+dnb; | ||
397 | unsigned int neg,zero; | 81 | unsigned int neg,zero; |
398 | BN_ULONG ln,lo,*p; | 82 | BN_ULONG ln,lo,*p; |
399 | 83 | ||
400 | # ifdef BN_COUNT | 84 | # ifdef BN_COUNT |
401 | fprintf(stderr," bn_mul_recursive %d * %d\n",n2,n2); | 85 | printf(" bn_mul_recursive %d * %d\n",n2,n2); |
402 | # endif | 86 | # endif |
403 | # ifdef BN_MUL_COMBA | 87 | # ifdef BN_MUL_COMBA |
404 | # if 0 | 88 | # if 0 |
@@ -408,40 +92,34 @@ void bn_mul_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n2, | |||
408 | return; | 92 | return; |
409 | } | 93 | } |
410 | # endif | 94 | # endif |
411 | /* Only call bn_mul_comba 8 if n2 == 8 and the | 95 | if (n2 == 8) |
412 | * two arrays are complete [steve] | ||
413 | */ | ||
414 | if (n2 == 8 && dna == 0 && dnb == 0) | ||
415 | { | 96 | { |
416 | bn_mul_comba8(r,a,b); | 97 | bn_mul_comba8(r,a,b); |
417 | return; | 98 | return; |
418 | } | 99 | } |
419 | # endif /* BN_MUL_COMBA */ | 100 | # endif /* BN_MUL_COMBA */ |
420 | /* Else do normal multiply */ | ||
421 | if (n2 < BN_MUL_RECURSIVE_SIZE_NORMAL) | 101 | if (n2 < BN_MUL_RECURSIVE_SIZE_NORMAL) |
422 | { | 102 | { |
423 | bn_mul_normal(r,a,n2+dna,b,n2+dnb); | 103 | /* This should not happen */ |
424 | if ((dna + dnb) < 0) | 104 | bn_mul_normal(r,a,n2,b,n2); |
425 | memset(&r[2*n2 + dna + dnb], 0, | ||
426 | sizeof(BN_ULONG) * -(dna + dnb)); | ||
427 | return; | 105 | return; |
428 | } | 106 | } |
429 | /* r=(a[0]-a[1])*(b[1]-b[0]) */ | 107 | /* r=(a[0]-a[1])*(b[1]-b[0]) */ |
430 | c1=bn_cmp_part_words(a,&(a[n]),tna,n-tna); | 108 | c1=bn_cmp_words(a,&(a[n]),n); |
431 | c2=bn_cmp_part_words(&(b[n]),b,tnb,tnb-n); | 109 | c2=bn_cmp_words(&(b[n]),b,n); |
432 | zero=neg=0; | 110 | zero=neg=0; |
433 | switch (c1*3+c2) | 111 | switch (c1*3+c2) |
434 | { | 112 | { |
435 | case -4: | 113 | case -4: |
436 | bn_sub_part_words(t, &(a[n]),a, tna,tna-n); /* - */ | 114 | bn_sub_words(t, &(a[n]),a, n); /* - */ |
437 | bn_sub_part_words(&(t[n]),b, &(b[n]),tnb,n-tnb); /* - */ | 115 | bn_sub_words(&(t[n]),b, &(b[n]),n); /* - */ |
438 | break; | 116 | break; |
439 | case -3: | 117 | case -3: |
440 | zero=1; | 118 | zero=1; |
441 | break; | 119 | break; |
442 | case -2: | 120 | case -2: |
443 | bn_sub_part_words(t, &(a[n]),a, tna,tna-n); /* - */ | 121 | bn_sub_words(t, &(a[n]),a, n); /* - */ |
444 | bn_sub_part_words(&(t[n]),&(b[n]),b, tnb,tnb-n); /* + */ | 122 | bn_sub_words(&(t[n]),&(b[n]),b, n); /* + */ |
445 | neg=1; | 123 | neg=1; |
446 | break; | 124 | break; |
447 | case -1: | 125 | case -1: |
@@ -450,22 +128,21 @@ void bn_mul_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n2, | |||
450 | zero=1; | 128 | zero=1; |
451 | break; | 129 | break; |
452 | case 2: | 130 | case 2: |
453 | bn_sub_part_words(t, a, &(a[n]),tna,n-tna); /* + */ | 131 | bn_sub_words(t, a, &(a[n]),n); /* + */ |
454 | bn_sub_part_words(&(t[n]),b, &(b[n]),tnb,n-tnb); /* - */ | 132 | bn_sub_words(&(t[n]),b, &(b[n]),n); /* - */ |
455 | neg=1; | 133 | neg=1; |
456 | break; | 134 | break; |
457 | case 3: | 135 | case 3: |
458 | zero=1; | 136 | zero=1; |
459 | break; | 137 | break; |
460 | case 4: | 138 | case 4: |
461 | bn_sub_part_words(t, a, &(a[n]),tna,n-tna); | 139 | bn_sub_words(t, a, &(a[n]),n); |
462 | bn_sub_part_words(&(t[n]),&(b[n]),b, tnb,tnb-n); | 140 | bn_sub_words(&(t[n]),&(b[n]),b, n); |
463 | break; | 141 | break; |
464 | } | 142 | } |
465 | 143 | ||
466 | # ifdef BN_MUL_COMBA | 144 | # ifdef BN_MUL_COMBA |
467 | if (n == 4 && dna == 0 && dnb == 0) /* XXX: bn_mul_comba4 could take | 145 | if (n == 4) |
468 | extra args to do this well */ | ||
469 | { | 146 | { |
470 | if (!zero) | 147 | if (!zero) |
471 | bn_mul_comba4(&(t[n2]),t,&(t[n])); | 148 | bn_mul_comba4(&(t[n2]),t,&(t[n])); |
@@ -475,9 +152,7 @@ void bn_mul_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n2, | |||
475 | bn_mul_comba4(r,a,b); | 152 | bn_mul_comba4(r,a,b); |
476 | bn_mul_comba4(&(r[n2]),&(a[n]),&(b[n])); | 153 | bn_mul_comba4(&(r[n2]),&(a[n]),&(b[n])); |
477 | } | 154 | } |
478 | else if (n == 8 && dna == 0 && dnb == 0) /* XXX: bn_mul_comba8 could | 155 | else if (n == 8) |
479 | take extra args to do this | ||
480 | well */ | ||
481 | { | 156 | { |
482 | if (!zero) | 157 | if (!zero) |
483 | bn_mul_comba8(&(t[n2]),t,&(t[n])); | 158 | bn_mul_comba8(&(t[n2]),t,&(t[n])); |
@@ -492,11 +167,11 @@ void bn_mul_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n2, | |||
492 | { | 167 | { |
493 | p= &(t[n2*2]); | 168 | p= &(t[n2*2]); |
494 | if (!zero) | 169 | if (!zero) |
495 | bn_mul_recursive(&(t[n2]),t,&(t[n]),n,0,0,p); | 170 | bn_mul_recursive(&(t[n2]),t,&(t[n]),n,p); |
496 | else | 171 | else |
497 | memset(&(t[n2]),0,n2*sizeof(BN_ULONG)); | 172 | memset(&(t[n2]),0,n2*sizeof(BN_ULONG)); |
498 | bn_mul_recursive(r,a,b,n,0,0,p); | 173 | bn_mul_recursive(r,a,b,n,p); |
499 | bn_mul_recursive(&(r[n2]),&(a[n]),&(b[n]),n,dna,dnb,p); | 174 | bn_mul_recursive(&(r[n2]),&(a[n]),&(b[n]),n,p); |
500 | } | 175 | } |
501 | 176 | ||
502 | /* t[32] holds (a[0]-a[1])*(b[1]-b[0]), c1 is the sign | 177 | /* t[32] holds (a[0]-a[1])*(b[1]-b[0]), c1 is the sign |
@@ -545,39 +220,39 @@ void bn_mul_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n2, | |||
545 | 220 | ||
546 | /* n+tn is the word length | 221 | /* n+tn is the word length |
547 | * t needs to be n*4 is size, as does r */ | 222 | * t needs to be n*4 is size, as does r */ |
548 | void bn_mul_part_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n, | 223 | void bn_mul_part_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int tn, |
549 | int tna, int tnb, BN_ULONG *t) | 224 | int n, BN_ULONG *t) |
550 | { | 225 | { |
551 | int i,j,n2=n*2; | 226 | int i,j,n2=n*2; |
552 | unsigned int c1,c2,neg,zero; | 227 | unsigned int c1,c2,neg,zero; |
553 | BN_ULONG ln,lo,*p; | 228 | BN_ULONG ln,lo,*p; |
554 | 229 | ||
555 | # ifdef BN_COUNT | 230 | # ifdef BN_COUNT |
556 | fprintf(stderr," bn_mul_part_recursive (%d+%d) * (%d+%d)\n", | 231 | printf(" bn_mul_part_recursive %d * %d\n",tn+n,tn+n); |
557 | tna, n, tnb, n); | ||
558 | # endif | 232 | # endif |
559 | if (n < 8) | 233 | if (n < 8) |
560 | { | 234 | { |
561 | bn_mul_normal(r,a,n+tna,b,n+tnb); | 235 | i=tn+n; |
236 | bn_mul_normal(r,a,i,b,i); | ||
562 | return; | 237 | return; |
563 | } | 238 | } |
564 | 239 | ||
565 | /* r=(a[0]-a[1])*(b[1]-b[0]) */ | 240 | /* r=(a[0]-a[1])*(b[1]-b[0]) */ |
566 | c1=bn_cmp_part_words(a,&(a[n]),tna,n-tna); | 241 | c1=bn_cmp_words(a,&(a[n]),n); |
567 | c2=bn_cmp_part_words(&(b[n]),b,tnb,tnb-n); | 242 | c2=bn_cmp_words(&(b[n]),b,n); |
568 | zero=neg=0; | 243 | zero=neg=0; |
569 | switch (c1*3+c2) | 244 | switch (c1*3+c2) |
570 | { | 245 | { |
571 | case -4: | 246 | case -4: |
572 | bn_sub_part_words(t, &(a[n]),a, tna,tna-n); /* - */ | 247 | bn_sub_words(t, &(a[n]),a, n); /* - */ |
573 | bn_sub_part_words(&(t[n]),b, &(b[n]),tnb,n-tnb); /* - */ | 248 | bn_sub_words(&(t[n]),b, &(b[n]),n); /* - */ |
574 | break; | 249 | break; |
575 | case -3: | 250 | case -3: |
576 | zero=1; | 251 | zero=1; |
577 | /* break; */ | 252 | /* break; */ |
578 | case -2: | 253 | case -2: |
579 | bn_sub_part_words(t, &(a[n]),a, tna,tna-n); /* - */ | 254 | bn_sub_words(t, &(a[n]),a, n); /* - */ |
580 | bn_sub_part_words(&(t[n]),&(b[n]),b, tnb,tnb-n); /* + */ | 255 | bn_sub_words(&(t[n]),&(b[n]),b, n); /* + */ |
581 | neg=1; | 256 | neg=1; |
582 | break; | 257 | break; |
583 | case -1: | 258 | case -1: |
@@ -586,16 +261,16 @@ void bn_mul_part_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n, | |||
586 | zero=1; | 261 | zero=1; |
587 | /* break; */ | 262 | /* break; */ |
588 | case 2: | 263 | case 2: |
589 | bn_sub_part_words(t, a, &(a[n]),tna,n-tna); /* + */ | 264 | bn_sub_words(t, a, &(a[n]),n); /* + */ |
590 | bn_sub_part_words(&(t[n]),b, &(b[n]),tnb,n-tnb); /* - */ | 265 | bn_sub_words(&(t[n]),b, &(b[n]),n); /* - */ |
591 | neg=1; | 266 | neg=1; |
592 | break; | 267 | break; |
593 | case 3: | 268 | case 3: |
594 | zero=1; | 269 | zero=1; |
595 | /* break; */ | 270 | /* break; */ |
596 | case 4: | 271 | case 4: |
597 | bn_sub_part_words(t, a, &(a[n]),tna,n-tna); | 272 | bn_sub_words(t, a, &(a[n]),n); |
598 | bn_sub_part_words(&(t[n]),&(b[n]),b, tnb,tnb-n); | 273 | bn_sub_words(&(t[n]),&(b[n]),b, n); |
599 | break; | 274 | break; |
600 | } | 275 | } |
601 | /* The zero case isn't yet implemented here. The speedup | 276 | /* The zero case isn't yet implemented here. The speedup |
@@ -614,59 +289,54 @@ void bn_mul_part_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n, | |||
614 | { | 289 | { |
615 | bn_mul_comba8(&(t[n2]),t,&(t[n])); | 290 | bn_mul_comba8(&(t[n2]),t,&(t[n])); |
616 | bn_mul_comba8(r,a,b); | 291 | bn_mul_comba8(r,a,b); |
617 | bn_mul_normal(&(r[n2]),&(a[n]),tna,&(b[n]),tnb); | 292 | bn_mul_normal(&(r[n2]),&(a[n]),tn,&(b[n]),tn); |
618 | memset(&(r[n2+tna+tnb]),0,sizeof(BN_ULONG)*(n2-tna-tnb)); | 293 | memset(&(r[n2+tn*2]),0,sizeof(BN_ULONG)*(n2-tn*2)); |
619 | } | 294 | } |
620 | else | 295 | else |
621 | { | 296 | { |
622 | p= &(t[n2*2]); | 297 | p= &(t[n2*2]); |
623 | bn_mul_recursive(&(t[n2]),t,&(t[n]),n,0,0,p); | 298 | bn_mul_recursive(&(t[n2]),t,&(t[n]),n,p); |
624 | bn_mul_recursive(r,a,b,n,0,0,p); | 299 | bn_mul_recursive(r,a,b,n,p); |
625 | i=n/2; | 300 | i=n/2; |
626 | /* If there is only a bottom half to the number, | 301 | /* If there is only a bottom half to the number, |
627 | * just do it */ | 302 | * just do it */ |
628 | if (tna > tnb) | 303 | j=tn-i; |
629 | j = tna - i; | ||
630 | else | ||
631 | j = tnb - i; | ||
632 | if (j == 0) | 304 | if (j == 0) |
633 | { | 305 | { |
634 | bn_mul_recursive(&(r[n2]),&(a[n]),&(b[n]), | 306 | bn_mul_recursive(&(r[n2]),&(a[n]),&(b[n]),i,p); |
635 | i,tna-i,tnb-i,p); | ||
636 | memset(&(r[n2+i*2]),0,sizeof(BN_ULONG)*(n2-i*2)); | 307 | memset(&(r[n2+i*2]),0,sizeof(BN_ULONG)*(n2-i*2)); |
637 | } | 308 | } |
638 | else if (j > 0) /* eg, n == 16, i == 8 and tn == 11 */ | 309 | else if (j > 0) /* eg, n == 16, i == 8 and tn == 11 */ |
639 | { | 310 | { |
640 | bn_mul_part_recursive(&(r[n2]),&(a[n]),&(b[n]), | 311 | bn_mul_part_recursive(&(r[n2]),&(a[n]),&(b[n]), |
641 | i,tna-i,tnb-i,p); | 312 | j,i,p); |
642 | memset(&(r[n2+tna+tnb]),0, | 313 | memset(&(r[n2+tn*2]),0, |
643 | sizeof(BN_ULONG)*(n2-tna-tnb)); | 314 | sizeof(BN_ULONG)*(n2-tn*2)); |
644 | } | 315 | } |
645 | else /* (j < 0) eg, n == 16, i == 8 and tn == 5 */ | 316 | else /* (j < 0) eg, n == 16, i == 8 and tn == 5 */ |
646 | { | 317 | { |
647 | memset(&(r[n2]),0,sizeof(BN_ULONG)*n2); | 318 | memset(&(r[n2]),0,sizeof(BN_ULONG)*n2); |
648 | if (tna < BN_MUL_RECURSIVE_SIZE_NORMAL | 319 | if (tn < BN_MUL_RECURSIVE_SIZE_NORMAL) |
649 | && tnb < BN_MUL_RECURSIVE_SIZE_NORMAL) | ||
650 | { | 320 | { |
651 | bn_mul_normal(&(r[n2]),&(a[n]),tna,&(b[n]),tnb); | 321 | bn_mul_normal(&(r[n2]),&(a[n]),tn,&(b[n]),tn); |
652 | } | 322 | } |
653 | else | 323 | else |
654 | { | 324 | { |
655 | for (;;) | 325 | for (;;) |
656 | { | 326 | { |
657 | i/=2; | 327 | i/=2; |
658 | if (i < tna && i < tnb) | 328 | if (i < tn) |
659 | { | 329 | { |
660 | bn_mul_part_recursive(&(r[n2]), | 330 | bn_mul_part_recursive(&(r[n2]), |
661 | &(a[n]),&(b[n]), | 331 | &(a[n]),&(b[n]), |
662 | i,tna-i,tnb-i,p); | 332 | tn-i,i,p); |
663 | break; | 333 | break; |
664 | } | 334 | } |
665 | else if (i <= tna && i <= tnb) | 335 | else if (i == tn) |
666 | { | 336 | { |
667 | bn_mul_recursive(&(r[n2]), | 337 | bn_mul_recursive(&(r[n2]), |
668 | &(a[n]),&(b[n]), | 338 | &(a[n]),&(b[n]), |
669 | i,tna-i,tnb-i,p); | 339 | i,p); |
670 | break; | 340 | break; |
671 | } | 341 | } |
672 | } | 342 | } |
@@ -727,10 +397,10 @@ void bn_mul_low_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n2, | |||
727 | int n=n2/2; | 397 | int n=n2/2; |
728 | 398 | ||
729 | # ifdef BN_COUNT | 399 | # ifdef BN_COUNT |
730 | fprintf(stderr," bn_mul_low_recursive %d * %d\n",n2,n2); | 400 | printf(" bn_mul_low_recursive %d * %d\n",n2,n2); |
731 | # endif | 401 | # endif |
732 | 402 | ||
733 | bn_mul_recursive(r,a,b,n,0,0,&(t[0])); | 403 | bn_mul_recursive(r,a,b,n,&(t[0])); |
734 | if (n >= BN_MUL_LOW_RECURSIVE_SIZE_NORMAL) | 404 | if (n >= BN_MUL_LOW_RECURSIVE_SIZE_NORMAL) |
735 | { | 405 | { |
736 | bn_mul_low_recursive(&(t[0]),&(a[0]),&(b[n]),n,&(t[n2])); | 406 | bn_mul_low_recursive(&(t[0]),&(a[0]),&(b[n]),n,&(t[n2])); |
@@ -761,7 +431,7 @@ void bn_mul_high(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, BN_ULONG *l, int n2, | |||
761 | BN_ULONG ll,lc,*lp,*mp; | 431 | BN_ULONG ll,lc,*lp,*mp; |
762 | 432 | ||
763 | # ifdef BN_COUNT | 433 | # ifdef BN_COUNT |
764 | fprintf(stderr," bn_mul_high %d * %d\n",n2,n2); | 434 | printf(" bn_mul_high %d * %d\n",n2,n2); |
765 | # endif | 435 | # endif |
766 | n=n2/2; | 436 | n=n2/2; |
767 | 437 | ||
@@ -814,8 +484,8 @@ void bn_mul_high(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, BN_ULONG *l, int n2, | |||
814 | else | 484 | else |
815 | # endif | 485 | # endif |
816 | { | 486 | { |
817 | bn_mul_recursive(&(t[0]),&(r[0]),&(r[n]),n,0,0,&(t[n2])); | 487 | bn_mul_recursive(&(t[0]),&(r[0]),&(r[n]),n,&(t[n2])); |
818 | bn_mul_recursive(r,&(a[n]),&(b[n]),n,0,0,&(t[n2])); | 488 | bn_mul_recursive(r,&(a[n]),&(b[n]),n,&(t[n2])); |
819 | } | 489 | } |
820 | 490 | ||
821 | /* s0 == low(al*bl) | 491 | /* s0 == low(al*bl) |
@@ -940,19 +610,19 @@ void bn_mul_high(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, BN_ULONG *l, int n2, | |||
940 | 610 | ||
941 | int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx) | 611 | int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx) |
942 | { | 612 | { |
943 | int ret=0; | ||
944 | int top,al,bl; | 613 | int top,al,bl; |
945 | BIGNUM *rr; | 614 | BIGNUM *rr; |
615 | int ret = 0; | ||
946 | #if defined(BN_MUL_COMBA) || defined(BN_RECURSION) | 616 | #if defined(BN_MUL_COMBA) || defined(BN_RECURSION) |
947 | int i; | 617 | int i; |
948 | #endif | 618 | #endif |
949 | #ifdef BN_RECURSION | 619 | #ifdef BN_RECURSION |
950 | BIGNUM *t=NULL; | 620 | BIGNUM *t; |
951 | int j=0,k; | 621 | int j,k; |
952 | #endif | 622 | #endif |
953 | 623 | ||
954 | #ifdef BN_COUNT | 624 | #ifdef BN_COUNT |
955 | fprintf(stderr,"BN_mul %d * %d\n",a->top,b->top); | 625 | printf("BN_mul %d * %d\n",a->top,b->top); |
956 | #endif | 626 | #endif |
957 | 627 | ||
958 | bn_check_top(a); | 628 | bn_check_top(a); |
@@ -1005,55 +675,21 @@ int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx) | |||
1005 | #ifdef BN_RECURSION | 675 | #ifdef BN_RECURSION |
1006 | if ((al >= BN_MULL_SIZE_NORMAL) && (bl >= BN_MULL_SIZE_NORMAL)) | 676 | if ((al >= BN_MULL_SIZE_NORMAL) && (bl >= BN_MULL_SIZE_NORMAL)) |
1007 | { | 677 | { |
1008 | if (i >= -1 && i <= 1) | 678 | if (i == 1 && !BN_get_flags(b,BN_FLG_STATIC_DATA) && bl<b->dmax) |
1009 | { | 679 | { |
1010 | int sav_j =0; | 680 | #if 0 /* tribute to const-ification, bl<b->dmax above covers for this */ |
1011 | /* Find out the power of two lower or equal | 681 | if (bn_wexpand(b,al) == NULL) goto err; |
1012 | to the longest of the two numbers */ | 682 | #endif |
1013 | if (i >= 0) | 683 | b->d[bl]=0; |
1014 | { | ||
1015 | j = BN_num_bits_word((BN_ULONG)al); | ||
1016 | } | ||
1017 | if (i == -1) | ||
1018 | { | ||
1019 | j = BN_num_bits_word((BN_ULONG)bl); | ||
1020 | } | ||
1021 | sav_j = j; | ||
1022 | j = 1<<(j-1); | ||
1023 | assert(j <= al || j <= bl); | ||
1024 | k = j+j; | ||
1025 | t = BN_CTX_get(ctx); | ||
1026 | if (al > j || bl > j) | ||
1027 | { | ||
1028 | bn_wexpand(t,k*4); | ||
1029 | bn_wexpand(rr,k*4); | ||
1030 | bn_mul_part_recursive(rr->d,a->d,b->d, | ||
1031 | j,al-j,bl-j,t->d); | ||
1032 | } | ||
1033 | else /* al <= j || bl <= j */ | ||
1034 | { | ||
1035 | bn_wexpand(t,k*2); | ||
1036 | bn_wexpand(rr,k*2); | ||
1037 | bn_mul_recursive(rr->d,a->d,b->d, | ||
1038 | j,al-j,bl-j,t->d); | ||
1039 | } | ||
1040 | rr->top=top; | ||
1041 | goto end; | ||
1042 | } | ||
1043 | #if 0 | ||
1044 | if (i == 1 && !BN_get_flags(b,BN_FLG_STATIC_DATA)) | ||
1045 | { | ||
1046 | BIGNUM *tmp_bn = (BIGNUM *)b; | ||
1047 | if (bn_wexpand(tmp_bn,al) == NULL) goto err; | ||
1048 | tmp_bn->d[bl]=0; | ||
1049 | bl++; | 684 | bl++; |
1050 | i--; | 685 | i--; |
1051 | } | 686 | } |
1052 | else if (i == -1 && !BN_get_flags(a,BN_FLG_STATIC_DATA)) | 687 | else if (i == -1 && !BN_get_flags(a,BN_FLG_STATIC_DATA) && al<a->dmax) |
1053 | { | 688 | { |
1054 | BIGNUM *tmp_bn = (BIGNUM *)a; | 689 | #if 0 /* tribute to const-ification, al<a->dmax above covers for this */ |
1055 | if (bn_wexpand(tmp_bn,bl) == NULL) goto err; | 690 | if (bn_wexpand(a,bl) == NULL) goto err; |
1056 | tmp_bn->d[al]=0; | 691 | #endif |
692 | a->d[al]=0; | ||
1057 | al++; | 693 | al++; |
1058 | i++; | 694 | i++; |
1059 | } | 695 | } |
@@ -1070,17 +706,26 @@ int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx) | |||
1070 | if (bn_wexpand(t,k*2) == NULL) goto err; | 706 | if (bn_wexpand(t,k*2) == NULL) goto err; |
1071 | if (bn_wexpand(rr,k*2) == NULL) goto err; | 707 | if (bn_wexpand(rr,k*2) == NULL) goto err; |
1072 | bn_mul_recursive(rr->d,a->d,b->d,al,t->d); | 708 | bn_mul_recursive(rr->d,a->d,b->d,al,t->d); |
709 | rr->top=top; | ||
710 | goto end; | ||
1073 | } | 711 | } |
712 | #if 0 /* tribute to const-ification, rsa/dsa performance is not affected */ | ||
1074 | else | 713 | else |
1075 | { | 714 | { |
1076 | if (bn_wexpand(t,k*4) == NULL) goto err; | 715 | if (bn_wexpand(a,k) == NULL ) goto err; |
1077 | if (bn_wexpand(rr,k*4) == NULL) goto err; | 716 | if (bn_wexpand(b,k) == NULL ) goto err; |
717 | if (bn_wexpand(t,k*4) == NULL ) goto err; | ||
718 | if (bn_wexpand(rr,k*4) == NULL ) goto err; | ||
719 | for (i=a->top; i<k; i++) | ||
720 | a->d[i]=0; | ||
721 | for (i=b->top; i<k; i++) | ||
722 | b->d[i]=0; | ||
1078 | bn_mul_part_recursive(rr->d,a->d,b->d,al-j,j,t->d); | 723 | bn_mul_part_recursive(rr->d,a->d,b->d,al-j,j,t->d); |
1079 | } | 724 | } |
1080 | rr->top=top; | 725 | rr->top=top; |
1081 | goto end; | 726 | goto end; |
1082 | } | ||
1083 | #endif | 727 | #endif |
728 | } | ||
1084 | } | 729 | } |
1085 | #endif /* BN_RECURSION */ | 730 | #endif /* BN_RECURSION */ |
1086 | if (bn_wexpand(rr,top) == NULL) goto err; | 731 | if (bn_wexpand(rr,top) == NULL) goto err; |
@@ -1103,7 +748,7 @@ void bn_mul_normal(BN_ULONG *r, BN_ULONG *a, int na, BN_ULONG *b, int nb) | |||
1103 | BN_ULONG *rr; | 748 | BN_ULONG *rr; |
1104 | 749 | ||
1105 | #ifdef BN_COUNT | 750 | #ifdef BN_COUNT |
1106 | fprintf(stderr," bn_mul_normal %d * %d\n",na,nb); | 751 | printf(" bn_mul_normal %d * %d\n",na,nb); |
1107 | #endif | 752 | #endif |
1108 | 753 | ||
1109 | if (na < nb) | 754 | if (na < nb) |
@@ -1116,13 +761,7 @@ void bn_mul_normal(BN_ULONG *r, BN_ULONG *a, int na, BN_ULONG *b, int nb) | |||
1116 | 761 | ||
1117 | } | 762 | } |
1118 | rr= &(r[na]); | 763 | rr= &(r[na]); |
1119 | if (nb <= 0) | 764 | rr[0]=bn_mul_words(r,a,na,b[0]); |
1120 | { | ||
1121 | (void)bn_mul_words(r,a,na,0); | ||
1122 | return; | ||
1123 | } | ||
1124 | else | ||
1125 | rr[0]=bn_mul_words(r,a,na,b[0]); | ||
1126 | 765 | ||
1127 | for (;;) | 766 | for (;;) |
1128 | { | 767 | { |
@@ -1143,7 +782,7 @@ void bn_mul_normal(BN_ULONG *r, BN_ULONG *a, int na, BN_ULONG *b, int nb) | |||
1143 | void bn_mul_low_normal(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n) | 782 | void bn_mul_low_normal(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n) |
1144 | { | 783 | { |
1145 | #ifdef BN_COUNT | 784 | #ifdef BN_COUNT |
1146 | fprintf(stderr," bn_mul_low_normal %d * %d\n",n,n); | 785 | printf(" bn_mul_low_normal %d * %d\n",n,n); |
1147 | #endif | 786 | #endif |
1148 | bn_mul_words(r,a,n,b[0]); | 787 | bn_mul_words(r,a,n,b[0]); |
1149 | 788 | ||
diff --git a/src/lib/libcrypto/bn/bn_prime.c b/src/lib/libcrypto/bn/bn_prime.c index 918b9237c6..e072d9255c 100644 --- a/src/lib/libcrypto/bn/bn_prime.c +++ b/src/lib/libcrypto/bn/bn_prime.c | |||
@@ -140,6 +140,7 @@ BIGNUM *BN_generate_prime(BIGNUM *ret, int bits, int safe, | |||
140 | BN_CTX *ctx; | 140 | BN_CTX *ctx; |
141 | int checks = BN_prime_checks_for_size(bits); | 141 | int checks = BN_prime_checks_for_size(bits); |
142 | 142 | ||
143 | BN_init(&t); | ||
143 | ctx=BN_CTX_new(); | 144 | ctx=BN_CTX_new(); |
144 | if (ctx == NULL) goto err; | 145 | if (ctx == NULL) goto err; |
145 | if (ret == NULL) | 146 | if (ret == NULL) |
@@ -148,7 +149,6 @@ BIGNUM *BN_generate_prime(BIGNUM *ret, int bits, int safe, | |||
148 | } | 149 | } |
149 | else | 150 | else |
150 | rnd=ret; | 151 | rnd=ret; |
151 | BN_init(&t); | ||
152 | loop: | 152 | loop: |
153 | /* make a random number and set the top and bottom bits */ | 153 | /* make a random number and set the top and bottom bits */ |
154 | if (add == NULL) | 154 | if (add == NULL) |
diff --git a/src/lib/libcrypto/bn/bn_rand.c b/src/lib/libcrypto/bn/bn_rand.c index 9e08ccd22e..893c9d2af9 100644 --- a/src/lib/libcrypto/bn/bn_rand.c +++ b/src/lib/libcrypto/bn/bn_rand.c | |||
@@ -201,7 +201,7 @@ static int bnrand(int pseudorand, BIGNUM *rnd, int bits, int top, int bottom) | |||
201 | err: | 201 | err: |
202 | if (buf != NULL) | 202 | if (buf != NULL) |
203 | { | 203 | { |
204 | memset(buf,0,bytes); | 204 | OPENSSL_cleanse(buf,bytes); |
205 | OPENSSL_free(buf); | 205 | OPENSSL_free(buf); |
206 | } | 206 | } |
207 | return(ret); | 207 | return(ret); |
diff --git a/src/lib/libcrypto/bn/bn_word.c b/src/lib/libcrypto/bn/bn_word.c index cd59baa2c4..988e0ca7b3 100644 --- a/src/lib/libcrypto/bn/bn_word.c +++ b/src/lib/libcrypto/bn/bn_word.c | |||
@@ -123,7 +123,10 @@ int BN_add_word(BIGNUM *a, BN_ULONG w) | |||
123 | i=0; | 123 | i=0; |
124 | for (;;) | 124 | for (;;) |
125 | { | 125 | { |
126 | l=(a->d[i]+(BN_ULONG)w)&BN_MASK2; | 126 | if (i >= a->top) |
127 | l=w; | ||
128 | else | ||
129 | l=(a->d[i]+(BN_ULONG)w)&BN_MASK2; | ||
127 | a->d[i]=l; | 130 | a->d[i]=l; |
128 | if (w > l) | 131 | if (w > l) |
129 | w=1; | 132 | w=1; |
diff --git a/src/lib/libcrypto/buffer/buffer.c b/src/lib/libcrypto/buffer/buffer.c index 9299baba9e..d96487e7db 100644 --- a/src/lib/libcrypto/buffer/buffer.c +++ b/src/lib/libcrypto/buffer/buffer.c | |||
@@ -125,6 +125,43 @@ int BUF_MEM_grow(BUF_MEM *str, int len) | |||
125 | return(len); | 125 | return(len); |
126 | } | 126 | } |
127 | 127 | ||
128 | int BUF_MEM_grow_clean(BUF_MEM *str, int len) | ||
129 | { | ||
130 | char *ret; | ||
131 | unsigned int n; | ||
132 | |||
133 | if (str->length >= len) | ||
134 | { | ||
135 | memset(&str->data[len],0,str->length-len); | ||
136 | str->length=len; | ||
137 | return(len); | ||
138 | } | ||
139 | if (str->max >= len) | ||
140 | { | ||
141 | memset(&str->data[str->length],0,len-str->length); | ||
142 | str->length=len; | ||
143 | return(len); | ||
144 | } | ||
145 | n=(len+3)/3*4; | ||
146 | if (str->data == NULL) | ||
147 | ret=OPENSSL_malloc(n); | ||
148 | else | ||
149 | ret=OPENSSL_realloc_clean(str->data,str->max,n); | ||
150 | if (ret == NULL) | ||
151 | { | ||
152 | BUFerr(BUF_F_BUF_MEM_GROW,ERR_R_MALLOC_FAILURE); | ||
153 | len=0; | ||
154 | } | ||
155 | else | ||
156 | { | ||
157 | str->data=ret; | ||
158 | str->max=n; | ||
159 | memset(&str->data[str->length],0,len-str->length); | ||
160 | str->length=len; | ||
161 | } | ||
162 | return(len); | ||
163 | } | ||
164 | |||
128 | char *BUF_strdup(const char *str) | 165 | char *BUF_strdup(const char *str) |
129 | { | 166 | { |
130 | char *ret; | 167 | char *ret; |
@@ -143,3 +180,23 @@ char *BUF_strdup(const char *str) | |||
143 | return(ret); | 180 | return(ret); |
144 | } | 181 | } |
145 | 182 | ||
183 | size_t BUF_strlcpy(char *dst, const char *src, size_t size) | ||
184 | { | ||
185 | size_t l = 0; | ||
186 | for(; size > 1 && *src; size--) | ||
187 | { | ||
188 | *dst++ = *src++; | ||
189 | l++; | ||
190 | } | ||
191 | if (size) | ||
192 | *dst = '\0'; | ||
193 | return l + strlen(src); | ||
194 | } | ||
195 | |||
196 | size_t BUF_strlcat(char *dst, const char *src, size_t size) | ||
197 | { | ||
198 | size_t l = 0; | ||
199 | for(; size > 0 && *dst; size--, dst++) | ||
200 | l++; | ||
201 | return l + BUF_strlcpy(dst, src, size); | ||
202 | } | ||
diff --git a/src/lib/libcrypto/buffer/buffer.h b/src/lib/libcrypto/buffer/buffer.h index 11e2d0359a..465dc34f3f 100644 --- a/src/lib/libcrypto/buffer/buffer.h +++ b/src/lib/libcrypto/buffer/buffer.h | |||
@@ -63,6 +63,9 @@ | |||
63 | extern "C" { | 63 | extern "C" { |
64 | #endif | 64 | #endif |
65 | 65 | ||
66 | #include <stddef.h> | ||
67 | #include <sys/types.h> | ||
68 | |||
66 | typedef struct buf_mem_st | 69 | typedef struct buf_mem_st |
67 | { | 70 | { |
68 | int length; /* current number of bytes */ | 71 | int length; /* current number of bytes */ |
@@ -73,8 +76,14 @@ typedef struct buf_mem_st | |||
73 | BUF_MEM *BUF_MEM_new(void); | 76 | BUF_MEM *BUF_MEM_new(void); |
74 | void BUF_MEM_free(BUF_MEM *a); | 77 | void BUF_MEM_free(BUF_MEM *a); |
75 | int BUF_MEM_grow(BUF_MEM *str, int len); | 78 | int BUF_MEM_grow(BUF_MEM *str, int len); |
79 | int BUF_MEM_grow_clean(BUF_MEM *str, int len); | ||
76 | char * BUF_strdup(const char *str); | 80 | char * BUF_strdup(const char *str); |
77 | 81 | ||
82 | /* safe string functions */ | ||
83 | size_t BUF_strlcpy(char *dst,const char *src,size_t siz); | ||
84 | size_t BUF_strlcat(char *dst,const char *src,size_t siz); | ||
85 | |||
86 | |||
78 | /* BEGIN ERROR CODES */ | 87 | /* BEGIN ERROR CODES */ |
79 | /* The following lines are auto generated by the script mkerr.pl. Any changes | 88 | /* The following lines are auto generated by the script mkerr.pl. Any changes |
80 | * made after this point may be overwritten when the script is next run. | 89 | * made after this point may be overwritten when the script is next run. |
diff --git a/src/lib/libcrypto/comp/c_zlib.c b/src/lib/libcrypto/comp/c_zlib.c index cd2f8a491b..8c0876151a 100644 --- a/src/lib/libcrypto/comp/c_zlib.c +++ b/src/lib/libcrypto/comp/c_zlib.c | |||
@@ -208,11 +208,11 @@ COMP_METHOD *COMP_zlib(void) | |||
208 | = (inflateInit__ft) DSO_bind_func(zlib_dso, | 208 | = (inflateInit__ft) DSO_bind_func(zlib_dso, |
209 | "inflateInit_"); | 209 | "inflateInit_"); |
210 | zlib_loaded++; | 210 | zlib_loaded++; |
211 | meth = &zlib_method; | ||
212 | } | 211 | } |
213 | } | 212 | } |
214 | 213 | ||
215 | #elif defined(ZLIB) | 214 | #endif |
215 | #if defined(ZLIB) || defined(ZLIB_SHARED) | ||
216 | meth = &zlib_method; | 216 | meth = &zlib_method; |
217 | #endif | 217 | #endif |
218 | 218 | ||
diff --git a/src/lib/libcrypto/conf/conf_def.c b/src/lib/libcrypto/conf/conf_def.c index 5e194de60e..57d2739ae0 100644 --- a/src/lib/libcrypto/conf/conf_def.c +++ b/src/lib/libcrypto/conf/conf_def.c | |||
@@ -208,7 +208,8 @@ static int def_load(CONF *conf, const char *name, long *line) | |||
208 | 208 | ||
209 | static int def_load_bio(CONF *conf, BIO *in, long *line) | 209 | static int def_load_bio(CONF *conf, BIO *in, long *line) |
210 | { | 210 | { |
211 | #define BUFSIZE 512 | 211 | /* The macro BUFSIZE conflicts with a system macro in VxWorks */ |
212 | #define CONFBUFSIZE 512 | ||
212 | int bufnum=0,i,ii; | 213 | int bufnum=0,i,ii; |
213 | BUF_MEM *buff=NULL; | 214 | BUF_MEM *buff=NULL; |
214 | char *s,*p,*end; | 215 | char *s,*p,*end; |
@@ -252,20 +253,21 @@ static int def_load_bio(CONF *conf, BIO *in, long *line) | |||
252 | section_sk=(STACK_OF(CONF_VALUE) *)sv->value; | 253 | section_sk=(STACK_OF(CONF_VALUE) *)sv->value; |
253 | 254 | ||
254 | bufnum=0; | 255 | bufnum=0; |
256 | again=0; | ||
255 | for (;;) | 257 | for (;;) |
256 | { | 258 | { |
257 | again=0; | 259 | if (!BUF_MEM_grow(buff,bufnum+CONFBUFSIZE)) |
258 | if (!BUF_MEM_grow(buff,bufnum+BUFSIZE)) | ||
259 | { | 260 | { |
260 | CONFerr(CONF_F_CONF_LOAD_BIO,ERR_R_BUF_LIB); | 261 | CONFerr(CONF_F_CONF_LOAD_BIO,ERR_R_BUF_LIB); |
261 | goto err; | 262 | goto err; |
262 | } | 263 | } |
263 | p= &(buff->data[bufnum]); | 264 | p= &(buff->data[bufnum]); |
264 | *p='\0'; | 265 | *p='\0'; |
265 | BIO_gets(in, p, BUFSIZE-1); | 266 | BIO_gets(in, p, CONFBUFSIZE-1); |
266 | p[BUFSIZE-1]='\0'; | 267 | p[CONFBUFSIZE-1]='\0'; |
267 | ii=i=strlen(p); | 268 | ii=i=strlen(p); |
268 | if (i == 0) break; | 269 | if (i == 0 && !again) break; |
270 | again=0; | ||
269 | while (i > 0) | 271 | while (i > 0) |
270 | { | 272 | { |
271 | if ((p[i-1] != '\r') && (p[i-1] != '\n')) | 273 | if ((p[i-1] != '\r') && (p[i-1] != '\n')) |
@@ -275,7 +277,7 @@ static int def_load_bio(CONF *conf, BIO *in, long *line) | |||
275 | } | 277 | } |
276 | /* we removed some trailing stuff so there is a new | 278 | /* we removed some trailing stuff so there is a new |
277 | * line on the end. */ | 279 | * line on the end. */ |
278 | if (i == ii) | 280 | if (ii && i == ii) |
279 | again=1; /* long line */ | 281 | again=1; /* long line */ |
280 | else | 282 | else |
281 | { | 283 | { |
@@ -627,7 +629,7 @@ static int str_copy(CONF *conf, char *section, char **pto, char *from) | |||
627 | CONFerr(CONF_F_STR_COPY,CONF_R_VARIABLE_HAS_NO_VALUE); | 629 | CONFerr(CONF_F_STR_COPY,CONF_R_VARIABLE_HAS_NO_VALUE); |
628 | goto err; | 630 | goto err; |
629 | } | 631 | } |
630 | BUF_MEM_grow(buf,(strlen(p)+len-(e-from))); | 632 | BUF_MEM_grow_clean(buf,(strlen(p)+len-(e-from))); |
631 | while (*p) | 633 | while (*p) |
632 | buf->data[to++]= *(p++); | 634 | buf->data[to++]= *(p++); |
633 | from=e; | 635 | from=e; |
diff --git a/src/lib/libcrypto/conf/conf_mall.c b/src/lib/libcrypto/conf/conf_mall.c index d702af689b..4ba40cf44c 100644 --- a/src/lib/libcrypto/conf/conf_mall.c +++ b/src/lib/libcrypto/conf/conf_mall.c | |||
@@ -63,7 +63,9 @@ | |||
63 | #include <openssl/dso.h> | 63 | #include <openssl/dso.h> |
64 | #include <openssl/x509.h> | 64 | #include <openssl/x509.h> |
65 | #include <openssl/asn1.h> | 65 | #include <openssl/asn1.h> |
66 | #ifndef OPENSSL_NO_ENGINE | ||
66 | #include <openssl/engine.h> | 67 | #include <openssl/engine.h> |
68 | #endif | ||
67 | 69 | ||
68 | /* Load all OpenSSL builtin modules */ | 70 | /* Load all OpenSSL builtin modules */ |
69 | 71 | ||
@@ -71,6 +73,8 @@ void OPENSSL_load_builtin_modules(void) | |||
71 | { | 73 | { |
72 | /* Add builtin modules here */ | 74 | /* Add builtin modules here */ |
73 | ASN1_add_oid_module(); | 75 | ASN1_add_oid_module(); |
76 | #ifndef OPENSSL_NO_ENGINE | ||
74 | ENGINE_add_conf_module(); | 77 | ENGINE_add_conf_module(); |
78 | #endif | ||
75 | } | 79 | } |
76 | 80 | ||
diff --git a/src/lib/libcrypto/conf/conf_sap.c b/src/lib/libcrypto/conf/conf_sap.c index 97fb174303..e15c2e5546 100644 --- a/src/lib/libcrypto/conf/conf_sap.c +++ b/src/lib/libcrypto/conf/conf_sap.c | |||
@@ -63,7 +63,9 @@ | |||
63 | #include <openssl/dso.h> | 63 | #include <openssl/dso.h> |
64 | #include <openssl/x509.h> | 64 | #include <openssl/x509.h> |
65 | #include <openssl/asn1.h> | 65 | #include <openssl/asn1.h> |
66 | #ifndef OPENSSL_NO_ENGINE | ||
66 | #include <openssl/engine.h> | 67 | #include <openssl/engine.h> |
68 | #endif | ||
67 | 69 | ||
68 | /* This is the automatic configuration loader: it is called automatically by | 70 | /* This is the automatic configuration loader: it is called automatically by |
69 | * OpenSSL when any of a number of standard initialisation functions are called, | 71 | * OpenSSL when any of a number of standard initialisation functions are called, |
@@ -78,8 +80,10 @@ void OPENSSL_config(const char *config_name) | |||
78 | return; | 80 | return; |
79 | 81 | ||
80 | OPENSSL_load_builtin_modules(); | 82 | OPENSSL_load_builtin_modules(); |
83 | #ifndef OPENSSL_NO_ENGINE | ||
81 | /* Need to load ENGINEs */ | 84 | /* Need to load ENGINEs */ |
82 | ENGINE_load_builtin_engines(); | 85 | ENGINE_load_builtin_engines(); |
86 | #endif | ||
83 | /* Add others here? */ | 87 | /* Add others here? */ |
84 | 88 | ||
85 | 89 | ||
diff --git a/src/lib/libcrypto/cryptlib.c b/src/lib/libcrypto/cryptlib.c index 612b3b93b4..2924def2bb 100644 --- a/src/lib/libcrypto/cryptlib.c +++ b/src/lib/libcrypto/cryptlib.c | |||
@@ -89,6 +89,7 @@ static const char* lock_names[CRYPTO_NUM_LOCKS] = | |||
89 | "ssl_session", | 89 | "ssl_session", |
90 | "ssl_sess_cert", | 90 | "ssl_sess_cert", |
91 | "ssl", | 91 | "ssl", |
92 | "ssl_method", | ||
92 | "rand", | 93 | "rand", |
93 | "rand2", | 94 | "rand2", |
94 | "debug_malloc", | 95 | "debug_malloc", |
@@ -103,7 +104,8 @@ static const char* lock_names[CRYPTO_NUM_LOCKS] = | |||
103 | "dynlock", | 104 | "dynlock", |
104 | "engine", | 105 | "engine", |
105 | "ui", | 106 | "ui", |
106 | #if CRYPTO_NUM_LOCKS != 31 | 107 | "hwcrhk", /* This is a HACK which will disappear in 0.9.8 */ |
108 | #if CRYPTO_NUM_LOCKS != 33 | ||
107 | # error "Inconsistency between crypto.h and cryptlib.c" | 109 | # error "Inconsistency between crypto.h and cryptlib.c" |
108 | #endif | 110 | #endif |
109 | }; | 111 | }; |
@@ -206,10 +208,18 @@ int CRYPTO_get_new_dynlockid(void) | |||
206 | i=sk_CRYPTO_dynlock_find(dyn_locks,NULL); | 208 | i=sk_CRYPTO_dynlock_find(dyn_locks,NULL); |
207 | /* If there was none, push, thereby creating a new one */ | 209 | /* If there was none, push, thereby creating a new one */ |
208 | if (i == -1) | 210 | if (i == -1) |
209 | i=sk_CRYPTO_dynlock_push(dyn_locks,pointer); | 211 | /* Since sk_push() returns the number of items on the |
212 | stack, not the location of the pushed item, we need | ||
213 | to transform the returned number into a position, | ||
214 | by decreasing it. */ | ||
215 | i=sk_CRYPTO_dynlock_push(dyn_locks,pointer) - 1; | ||
216 | else | ||
217 | /* If we found a place with a NULL pointer, put our pointer | ||
218 | in it. */ | ||
219 | sk_CRYPTO_dynlock_set(dyn_locks,i,pointer); | ||
210 | CRYPTO_w_unlock(CRYPTO_LOCK_DYNLOCK); | 220 | CRYPTO_w_unlock(CRYPTO_LOCK_DYNLOCK); |
211 | 221 | ||
212 | if (!i) | 222 | if (i == -1) |
213 | { | 223 | { |
214 | dynlock_destroy_callback(pointer->data,__FILE__,__LINE__); | 224 | dynlock_destroy_callback(pointer->data,__FILE__,__LINE__); |
215 | OPENSSL_free(pointer); | 225 | OPENSSL_free(pointer); |
@@ -401,15 +411,17 @@ void CRYPTO_lock(int mode, int type, const char *file, int line) | |||
401 | #endif | 411 | #endif |
402 | if (type < 0) | 412 | if (type < 0) |
403 | { | 413 | { |
404 | struct CRYPTO_dynlock_value *pointer | 414 | if (dynlock_lock_callback != NULL) |
405 | = CRYPTO_get_dynlock_value(type); | ||
406 | |||
407 | if (pointer && dynlock_lock_callback) | ||
408 | { | 415 | { |
416 | struct CRYPTO_dynlock_value *pointer | ||
417 | = CRYPTO_get_dynlock_value(type); | ||
418 | |||
419 | OPENSSL_assert(pointer != NULL); | ||
420 | |||
409 | dynlock_lock_callback(mode, pointer, file, line); | 421 | dynlock_lock_callback(mode, pointer, file, line); |
410 | } | ||
411 | 422 | ||
412 | CRYPTO_destroy_dynlockid(type); | 423 | CRYPTO_destroy_dynlockid(type); |
424 | } | ||
413 | } | 425 | } |
414 | else | 426 | else |
415 | if (locking_callback != NULL) | 427 | if (locking_callback != NULL) |
@@ -460,7 +472,7 @@ const char *CRYPTO_get_lock_name(int type) | |||
460 | return("dynamic"); | 472 | return("dynamic"); |
461 | else if (type < CRYPTO_NUM_LOCKS) | 473 | else if (type < CRYPTO_NUM_LOCKS) |
462 | return(lock_names[type]); | 474 | return(lock_names[type]); |
463 | else if (type-CRYPTO_NUM_LOCKS >= sk_num(app_locks)) | 475 | else if (type-CRYPTO_NUM_LOCKS > sk_num(app_locks)) |
464 | return("ERROR"); | 476 | return("ERROR"); |
465 | else | 477 | else |
466 | return(sk_value(app_locks,type-CRYPTO_NUM_LOCKS)); | 478 | return(sk_value(app_locks,type-CRYPTO_NUM_LOCKS)); |
@@ -492,3 +504,11 @@ BOOL WINAPI DLLEntryPoint(HINSTANCE hinstDLL, DWORD fdwReason, | |||
492 | #endif | 504 | #endif |
493 | 505 | ||
494 | #endif | 506 | #endif |
507 | |||
508 | void OpenSSLDie(const char *file,int line,const char *assertion) | ||
509 | { | ||
510 | fprintf(stderr, | ||
511 | "%s(%d): OpenSSL internal error, assertion failed: %s\n", | ||
512 | file,line,assertion); | ||
513 | abort(); | ||
514 | } | ||
diff --git a/src/lib/libcrypto/cryptlib.h b/src/lib/libcrypto/cryptlib.h index 88e4ae509f..0d6b9d59f0 100644 --- a/src/lib/libcrypto/cryptlib.h +++ b/src/lib/libcrypto/cryptlib.h | |||
@@ -89,9 +89,9 @@ extern "C" { | |||
89 | #define X509_CERT_DIR_EVP "SSL_CERT_DIR" | 89 | #define X509_CERT_DIR_EVP "SSL_CERT_DIR" |
90 | #define X509_CERT_FILE_EVP "SSL_CERT_FILE" | 90 | #define X509_CERT_FILE_EVP "SSL_CERT_FILE" |
91 | 91 | ||
92 | /* size of string represenations */ | 92 | /* size of string representations */ |
93 | #define DECIMAL_SIZE(type) ((sizeof(type)*8+2)/3+1) | 93 | #define DECIMAL_SIZE(type) ((sizeof(type)*8+2)/3+1) |
94 | #define HEX_SIZE(type) ((sizeof(type)*2) | 94 | #define HEX_SIZE(type) (sizeof(type)*2) |
95 | 95 | ||
96 | #ifdef __cplusplus | 96 | #ifdef __cplusplus |
97 | } | 97 | } |
diff --git a/src/lib/libcrypto/crypto.h b/src/lib/libcrypto/crypto.h index fc6ff860af..273bc5e3f8 100644 --- a/src/lib/libcrypto/crypto.h +++ b/src/lib/libcrypto/crypto.h | |||
@@ -96,37 +96,39 @@ extern "C" { | |||
96 | * names in cryptlib.c | 96 | * names in cryptlib.c |
97 | */ | 97 | */ |
98 | 98 | ||
99 | #define CRYPTO_LOCK_ERR 1 | 99 | #define CRYPTO_LOCK_ERR 1 |
100 | #define CRYPTO_LOCK_EX_DATA 2 | 100 | #define CRYPTO_LOCK_EX_DATA 2 |
101 | #define CRYPTO_LOCK_X509 3 | 101 | #define CRYPTO_LOCK_X509 3 |
102 | #define CRYPTO_LOCK_X509_INFO 4 | 102 | #define CRYPTO_LOCK_X509_INFO 4 |
103 | #define CRYPTO_LOCK_X509_PKEY 5 | 103 | #define CRYPTO_LOCK_X509_PKEY 5 |
104 | #define CRYPTO_LOCK_X509_CRL 6 | 104 | #define CRYPTO_LOCK_X509_CRL 6 |
105 | #define CRYPTO_LOCK_X509_REQ 7 | 105 | #define CRYPTO_LOCK_X509_REQ 7 |
106 | #define CRYPTO_LOCK_DSA 8 | 106 | #define CRYPTO_LOCK_DSA 8 |
107 | #define CRYPTO_LOCK_RSA 9 | 107 | #define CRYPTO_LOCK_RSA 9 |
108 | #define CRYPTO_LOCK_EVP_PKEY 10 | 108 | #define CRYPTO_LOCK_EVP_PKEY 10 |
109 | #define CRYPTO_LOCK_X509_STORE 11 | 109 | #define CRYPTO_LOCK_X509_STORE 11 |
110 | #define CRYPTO_LOCK_SSL_CTX 12 | 110 | #define CRYPTO_LOCK_SSL_CTX 12 |
111 | #define CRYPTO_LOCK_SSL_CERT 13 | 111 | #define CRYPTO_LOCK_SSL_CERT 13 |
112 | #define CRYPTO_LOCK_SSL_SESSION 14 | 112 | #define CRYPTO_LOCK_SSL_SESSION 14 |
113 | #define CRYPTO_LOCK_SSL_SESS_CERT 15 | 113 | #define CRYPTO_LOCK_SSL_SESS_CERT 15 |
114 | #define CRYPTO_LOCK_SSL 16 | 114 | #define CRYPTO_LOCK_SSL 16 |
115 | #define CRYPTO_LOCK_RAND 17 | 115 | #define CRYPTO_LOCK_SSL_METHOD 17 |
116 | #define CRYPTO_LOCK_RAND2 18 | 116 | #define CRYPTO_LOCK_RAND 18 |
117 | #define CRYPTO_LOCK_MALLOC 19 | 117 | #define CRYPTO_LOCK_RAND2 19 |
118 | #define CRYPTO_LOCK_BIO 20 | 118 | #define CRYPTO_LOCK_MALLOC 20 |
119 | #define CRYPTO_LOCK_GETHOSTBYNAME 21 | 119 | #define CRYPTO_LOCK_BIO 21 |
120 | #define CRYPTO_LOCK_GETSERVBYNAME 22 | 120 | #define CRYPTO_LOCK_GETHOSTBYNAME 22 |
121 | #define CRYPTO_LOCK_READDIR 23 | 121 | #define CRYPTO_LOCK_GETSERVBYNAME 23 |
122 | #define CRYPTO_LOCK_RSA_BLINDING 24 | 122 | #define CRYPTO_LOCK_READDIR 24 |
123 | #define CRYPTO_LOCK_DH 25 | 123 | #define CRYPTO_LOCK_RSA_BLINDING 25 |
124 | #define CRYPTO_LOCK_MALLOC2 26 | 124 | #define CRYPTO_LOCK_DH 26 |
125 | #define CRYPTO_LOCK_DSO 27 | 125 | #define CRYPTO_LOCK_MALLOC2 27 |
126 | #define CRYPTO_LOCK_DYNLOCK 28 | 126 | #define CRYPTO_LOCK_DSO 28 |
127 | #define CRYPTO_LOCK_ENGINE 29 | 127 | #define CRYPTO_LOCK_DYNLOCK 29 |
128 | #define CRYPTO_LOCK_UI 30 | 128 | #define CRYPTO_LOCK_ENGINE 30 |
129 | #define CRYPTO_NUM_LOCKS 31 | 129 | #define CRYPTO_LOCK_UI 31 |
130 | #define CRYPTO_LOCK_HWCRHK 32 /* This is a HACK which will disappear in 0.9.8 */ | ||
131 | #define CRYPTO_NUM_LOCKS 33 | ||
130 | 132 | ||
131 | #define CRYPTO_LOCK 1 | 133 | #define CRYPTO_LOCK 1 |
132 | #define CRYPTO_UNLOCK 2 | 134 | #define CRYPTO_UNLOCK 2 |
@@ -148,7 +150,7 @@ extern "C" { | |||
148 | #endif | 150 | #endif |
149 | #else | 151 | #else |
150 | #define CRYPTO_w_lock(a) | 152 | #define CRYPTO_w_lock(a) |
151 | #define CRYPTO_w_unlock(a) | 153 | #define CRYPTO_w_unlock(a) |
152 | #define CRYPTO_r_lock(a) | 154 | #define CRYPTO_r_lock(a) |
153 | #define CRYPTO_r_unlock(a) | 155 | #define CRYPTO_r_unlock(a) |
154 | #define CRYPTO_add(a,b,c) ((*(a))+=(b)) | 156 | #define CRYPTO_add(a,b,c) ((*(a))+=(b)) |
@@ -278,6 +280,8 @@ int CRYPTO_is_mem_check_on(void); | |||
278 | #define OPENSSL_malloc(num) CRYPTO_malloc((int)num,__FILE__,__LINE__) | 280 | #define OPENSSL_malloc(num) CRYPTO_malloc((int)num,__FILE__,__LINE__) |
279 | #define OPENSSL_realloc(addr,num) \ | 281 | #define OPENSSL_realloc(addr,num) \ |
280 | CRYPTO_realloc((char *)addr,(int)num,__FILE__,__LINE__) | 282 | CRYPTO_realloc((char *)addr,(int)num,__FILE__,__LINE__) |
283 | #define OPENSSL_realloc_clean(addr,old_num,num) \ | ||
284 | CRYPTO_realloc_clean(addr,old_num,num,__FILE__,__LINE__) | ||
281 | #define OPENSSL_remalloc(addr,num) \ | 285 | #define OPENSSL_remalloc(addr,num) \ |
282 | CRYPTO_remalloc((char **)addr,(int)num,__FILE__,__LINE__) | 286 | CRYPTO_remalloc((char **)addr,(int)num,__FILE__,__LINE__) |
283 | #define OPENSSL_freeFunc CRYPTO_free | 287 | #define OPENSSL_freeFunc CRYPTO_free |
@@ -380,8 +384,12 @@ void CRYPTO_free_locked(void *); | |||
380 | void *CRYPTO_malloc(int num, const char *file, int line); | 384 | void *CRYPTO_malloc(int num, const char *file, int line); |
381 | void CRYPTO_free(void *); | 385 | void CRYPTO_free(void *); |
382 | void *CRYPTO_realloc(void *addr,int num, const char *file, int line); | 386 | void *CRYPTO_realloc(void *addr,int num, const char *file, int line); |
387 | void *CRYPTO_realloc_clean(void *addr,int old_num,int num,const char *file, | ||
388 | int line); | ||
383 | void *CRYPTO_remalloc(void *addr,int num, const char *file, int line); | 389 | void *CRYPTO_remalloc(void *addr,int num, const char *file, int line); |
384 | 390 | ||
391 | void OPENSSL_cleanse(void *ptr, size_t len); | ||
392 | |||
385 | void CRYPTO_set_mem_debug_options(long bits); | 393 | void CRYPTO_set_mem_debug_options(long bits); |
386 | long CRYPTO_get_mem_debug_options(void); | 394 | long CRYPTO_get_mem_debug_options(void); |
387 | 395 | ||
@@ -422,6 +430,9 @@ void CRYPTO_mem_leaks(struct bio_st *bio); | |||
422 | typedef void *CRYPTO_MEM_LEAK_CB(unsigned long, const char *, int, int, void *); | 430 | typedef void *CRYPTO_MEM_LEAK_CB(unsigned long, const char *, int, int, void *); |
423 | void CRYPTO_mem_leaks_cb(CRYPTO_MEM_LEAK_CB *cb); | 431 | void CRYPTO_mem_leaks_cb(CRYPTO_MEM_LEAK_CB *cb); |
424 | 432 | ||
433 | /* die if we have to */ | ||
434 | void OpenSSLDie(const char *file,int line,const char *assertion); | ||
435 | #define OPENSSL_assert(e) ((e) ? (void)0 : OpenSSLDie(__FILE__, __LINE__, #e)) | ||
425 | 436 | ||
426 | /* BEGIN ERROR CODES */ | 437 | /* BEGIN ERROR CODES */ |
427 | /* The following lines are auto generated by the script mkerr.pl. Any changes | 438 | /* The following lines are auto generated by the script mkerr.pl. Any changes |
diff --git a/src/lib/libcrypto/des/asm/crypt586.pl b/src/lib/libcrypto/des/asm/crypt586.pl index 3d41d82f69..1d04ed6def 100644 --- a/src/lib/libcrypto/des/asm/crypt586.pl +++ b/src/lib/libcrypto/des/asm/crypt586.pl | |||
@@ -26,11 +26,18 @@ sub fcrypt_body | |||
26 | 26 | ||
27 | &comment(""); | 27 | &comment(""); |
28 | &comment("Load the 2 words"); | 28 | &comment("Load the 2 words"); |
29 | $ks="ebp"; | 29 | $trans="ebp"; |
30 | 30 | ||
31 | &xor( $L, $L); | 31 | &xor( $L, $L); |
32 | &xor( $R, $R); | 32 | &xor( $R, $R); |
33 | &mov($ks,&wparam(1)); | 33 | |
34 | # PIC-ification:-) | ||
35 | &picmeup("edx","DES_SPtrans"); | ||
36 | #if ($cpp) { &picmeup("edx","DES_SPtrans"); } | ||
37 | #else { &lea("edx",&DWP("DES_SPtrans")); } | ||
38 | &push("edx"); # becomes &swtmp(1) | ||
39 | # | ||
40 | &mov($trans,&wparam(1)); # reloaded with DES_SPtrans in D_ENCRYPT | ||
34 | 41 | ||
35 | &push(&DWC(25)); # add a variable | 42 | &push(&DWC(25)); # add a variable |
36 | 43 | ||
@@ -39,11 +46,11 @@ sub fcrypt_body | |||
39 | { | 46 | { |
40 | &comment(""); | 47 | &comment(""); |
41 | &comment("Round $i"); | 48 | &comment("Round $i"); |
42 | &D_ENCRYPT($i,$L,$R,$i*2,$ks,"DES_SPtrans","eax","ebx","ecx","edx"); | 49 | &D_ENCRYPT($i,$L,$R,$i*2,$trans,"eax","ebx","ecx","edx"); |
43 | 50 | ||
44 | &comment(""); | 51 | &comment(""); |
45 | &comment("Round ".sprintf("%d",$i+1)); | 52 | &comment("Round ".sprintf("%d",$i+1)); |
46 | &D_ENCRYPT($i+1,$R,$L,($i+1)*2,$ks,"DES_SPtrans","eax","ebx","ecx","edx"); | 53 | &D_ENCRYPT($i+1,$R,$L,($i+1)*2,$trans,"eax","ebx","ecx","edx"); |
47 | } | 54 | } |
48 | &mov("ebx", &swtmp(0)); | 55 | &mov("ebx", &swtmp(0)); |
49 | &mov("eax", $L); | 56 | &mov("eax", $L); |
@@ -61,14 +68,14 @@ sub fcrypt_body | |||
61 | &mov(&DWP(0,"edx","",0),"eax"); | 68 | &mov(&DWP(0,"edx","",0),"eax"); |
62 | &mov(&DWP(4,"edx","",0),$L); | 69 | &mov(&DWP(4,"edx","",0),$L); |
63 | 70 | ||
64 | &pop("ecx"); # remove variable | 71 | &add("esp",8); # remove variables |
65 | 72 | ||
66 | &function_end($name); | 73 | &function_end($name); |
67 | } | 74 | } |
68 | 75 | ||
69 | sub D_ENCRYPT | 76 | sub D_ENCRYPT |
70 | { | 77 | { |
71 | local($r,$L,$R,$S,$ks,$desSP,$u,$tmp1,$tmp2,$t)=@_; | 78 | local($r,$L,$R,$S,$trans,$u,$tmp1,$tmp2,$t)=@_; |
72 | 79 | ||
73 | &mov( $u, &wparam(2)); # 2 | 80 | &mov( $u, &wparam(2)); # 2 |
74 | &mov( $t, $R); | 81 | &mov( $t, $R); |
@@ -85,9 +92,9 @@ sub D_ENCRYPT | |||
85 | &shl( $tmp2, 16); # 1 | 92 | &shl( $tmp2, 16); # 1 |
86 | &xor( $u, $tmp1); # 2 | 93 | &xor( $u, $tmp1); # 2 |
87 | &xor( $t, $tmp2); # 2 | 94 | &xor( $t, $tmp2); # 2 |
88 | &mov( $tmp1, &DWP(&n2a($S*4),$ks,"",0)); # 2 | 95 | &mov( $tmp1, &DWP(&n2a($S*4),$trans,"",0)); # 2 |
89 | &xor( $u, $tmp1); | 96 | &xor( $u, $tmp1); |
90 | &mov( $tmp2, &DWP(&n2a(($S+1)*4),$ks,"",0)); # 2 | 97 | &mov( $tmp2, &DWP(&n2a(($S+1)*4),$trans,"",0)); # 2 |
91 | &xor( $u, $R); | 98 | &xor( $u, $R); |
92 | &xor( $t, $R); | 99 | &xor( $t, $R); |
93 | &xor( $t, $tmp2); | 100 | &xor( $t, $tmp2); |
@@ -99,31 +106,28 @@ sub D_ENCRYPT | |||
99 | &movb( &LB($tmp1), &LB($u) ); | 106 | &movb( &LB($tmp1), &LB($u) ); |
100 | &movb( &LB($tmp2), &HB($u) ); | 107 | &movb( &LB($tmp2), &HB($u) ); |
101 | &rotr( $t, 4 ); | 108 | &rotr( $t, 4 ); |
102 | &mov( $ks, &DWP(" $desSP",$tmp1,"",0)); | 109 | &mov( $trans, &swtmp(1)); |
110 | &xor( $L, &DWP(" ",$trans,$tmp1,0)); | ||
103 | &movb( &LB($tmp1), &LB($t) ); | 111 | &movb( &LB($tmp1), &LB($t) ); |
104 | &xor( $L, $ks); | 112 | &xor( $L, &DWP("0x200",$trans,$tmp2,0)); |
105 | &mov( $ks, &DWP("0x200+$desSP",$tmp2,"",0)); | ||
106 | &xor( $L, $ks); | ||
107 | &movb( &LB($tmp2), &HB($t) ); | 113 | &movb( &LB($tmp2), &HB($t) ); |
108 | &shr( $u, 16); | 114 | &shr( $u, 16); |
109 | &mov( $ks, &DWP("0x100+$desSP",$tmp1,"",0)); | 115 | &xor( $L, &DWP("0x100",$trans,$tmp1,0)); |
110 | &xor( $L, $ks); | ||
111 | &movb( &LB($tmp1), &HB($u) ); | 116 | &movb( &LB($tmp1), &HB($u) ); |
112 | &shr( $t, 16); | 117 | &shr( $t, 16); |
113 | &mov( $ks, &DWP("0x300+$desSP",$tmp2,"",0)); | 118 | &xor( $L, &DWP("0x300",$trans,$tmp2,0)); |
114 | &xor( $L, $ks); | ||
115 | &mov( $ks, &wparam(1)); | ||
116 | &movb( &LB($tmp2), &HB($t) ); | 119 | &movb( &LB($tmp2), &HB($t) ); |
117 | &and( $u, "0xff" ); | 120 | &and( $u, "0xff" ); |
118 | &and( $t, "0xff" ); | 121 | &and( $t, "0xff" ); |
119 | &mov( $tmp1, &DWP("0x600+$desSP",$tmp1,"",0)); | 122 | &mov( $tmp1, &DWP("0x600",$trans,$tmp1,0)); |
120 | &xor( $L, $tmp1); | 123 | &xor( $L, $tmp1); |
121 | &mov( $tmp1, &DWP("0x700+$desSP",$tmp2,"",0)); | 124 | &mov( $tmp1, &DWP("0x700",$trans,$tmp2,0)); |
122 | &xor( $L, $tmp1); | 125 | &xor( $L, $tmp1); |
123 | &mov( $tmp1, &DWP("0x400+$desSP",$u,"",0)); | 126 | &mov( $tmp1, &DWP("0x400",$trans,$u,0)); |
124 | &xor( $L, $tmp1); | 127 | &xor( $L, $tmp1); |
125 | &mov( $tmp1, &DWP("0x500+$desSP",$t,"",0)); | 128 | &mov( $tmp1, &DWP("0x500",$trans,$t,0)); |
126 | &xor( $L, $tmp1); | 129 | &xor( $L, $tmp1); |
130 | &mov( $trans, &wparam(1)); | ||
127 | } | 131 | } |
128 | 132 | ||
129 | sub n2a | 133 | sub n2a |
diff --git a/src/lib/libcrypto/des/asm/des-586.pl b/src/lib/libcrypto/des/asm/des-586.pl index 0d08e8a3a9..b75d3c6b3a 100644 --- a/src/lib/libcrypto/des/asm/des-586.pl +++ b/src/lib/libcrypto/des/asm/des-586.pl | |||
@@ -40,7 +40,7 @@ sub DES_encrypt | |||
40 | 40 | ||
41 | &comment(""); | 41 | &comment(""); |
42 | &comment("Load the 2 words"); | 42 | &comment("Load the 2 words"); |
43 | $ks="ebp"; | 43 | $trans="ebp"; |
44 | 44 | ||
45 | if ($do_ip) | 45 | if ($do_ip) |
46 | { | 46 | { |
@@ -72,7 +72,12 @@ sub DES_encrypt | |||
72 | &rotl($L,3); | 72 | &rotl($L,3); |
73 | } | 73 | } |
74 | 74 | ||
75 | &mov( $ks, &wparam(1) ); | 75 | # PIC-ification:-) |
76 | &picmeup($trans,"DES_SPtrans"); | ||
77 | #if ($cpp) { &picmeup($trans,"DES_SPtrans"); } | ||
78 | #else { &lea($trans,&DWP("DES_SPtrans")); } | ||
79 | |||
80 | &mov( "ecx", &wparam(1) ); | ||
76 | &cmp("ebx","0"); | 81 | &cmp("ebx","0"); |
77 | &je(&label("start_decrypt")); | 82 | &je(&label("start_decrypt")); |
78 | 83 | ||
@@ -80,11 +85,11 @@ sub DES_encrypt | |||
80 | { | 85 | { |
81 | &comment(""); | 86 | &comment(""); |
82 | &comment("Round $i"); | 87 | &comment("Round $i"); |
83 | &D_ENCRYPT($i,$L,$R,$i*2,$ks,"DES_SPtrans","eax","ebx","ecx","edx"); | 88 | &D_ENCRYPT($i,$L,$R,$i*2,$trans,"eax","ebx","ecx","edx"); |
84 | 89 | ||
85 | &comment(""); | 90 | &comment(""); |
86 | &comment("Round ".sprintf("%d",$i+1)); | 91 | &comment("Round ".sprintf("%d",$i+1)); |
87 | &D_ENCRYPT($i+1,$R,$L,($i+1)*2,$ks,"DES_SPtrans","eax","ebx","ecx","edx"); | 92 | &D_ENCRYPT($i+1,$R,$L,($i+1)*2,$trans,"eax","ebx","ecx","edx"); |
88 | } | 93 | } |
89 | &jmp(&label("end")); | 94 | &jmp(&label("end")); |
90 | 95 | ||
@@ -94,10 +99,10 @@ sub DES_encrypt | |||
94 | { | 99 | { |
95 | &comment(""); | 100 | &comment(""); |
96 | &comment("Round $i"); | 101 | &comment("Round $i"); |
97 | &D_ENCRYPT(15-$i,$L,$R,$i*2,$ks,"DES_SPtrans","eax","ebx","ecx","edx"); | 102 | &D_ENCRYPT(15-$i,$L,$R,$i*2,$trans,"eax","ebx","ecx","edx"); |
98 | &comment(""); | 103 | &comment(""); |
99 | &comment("Round ".sprintf("%d",$i-1)); | 104 | &comment("Round ".sprintf("%d",$i-1)); |
100 | &D_ENCRYPT(15-$i+1,$R,$L,($i-1)*2,$ks,"DES_SPtrans","eax","ebx","ecx","edx"); | 105 | &D_ENCRYPT(15-$i+1,$R,$L,($i-1)*2,$trans,"eax","ebx","ecx","edx"); |
101 | } | 106 | } |
102 | 107 | ||
103 | &set_label("end"); | 108 | &set_label("end"); |
@@ -134,43 +139,36 @@ sub DES_encrypt | |||
134 | 139 | ||
135 | sub D_ENCRYPT | 140 | sub D_ENCRYPT |
136 | { | 141 | { |
137 | local($r,$L,$R,$S,$ks,$desSP,$u,$tmp1,$tmp2,$t)=@_; | 142 | local($r,$L,$R,$S,$trans,$u,$tmp1,$tmp2,$t)=@_; |
138 | 143 | ||
139 | &mov( $u, &DWP(&n2a($S*4),$ks,"",0)); | 144 | &mov( $u, &DWP(&n2a($S*4),$tmp2,"",0)); |
140 | &xor( $tmp1, $tmp1); | 145 | &xor( $tmp1, $tmp1); |
141 | &mov( $t, &DWP(&n2a(($S+1)*4),$ks,"",0)); | 146 | &mov( $t, &DWP(&n2a(($S+1)*4),$tmp2,"",0)); |
142 | &xor( $u, $R); | 147 | &xor( $u, $R); |
148 | &xor( $tmp2, $tmp2); | ||
143 | &xor( $t, $R); | 149 | &xor( $t, $R); |
144 | &and( $u, "0xfcfcfcfc" ); | 150 | &and( $u, "0xfcfcfcfc" ); |
145 | &and( $t, "0xcfcfcfcf" ); | 151 | &and( $t, "0xcfcfcfcf" ); |
146 | &movb( &LB($tmp1), &LB($u) ); | 152 | &movb( &LB($tmp1), &LB($u) ); |
147 | &movb( &LB($tmp2), &HB($u) ); | 153 | &movb( &LB($tmp2), &HB($u) ); |
148 | &rotr( $t, 4 ); | 154 | &rotr( $t, 4 ); |
149 | &mov( $ks, &DWP(" $desSP",$tmp1,"",0)); | 155 | &xor( $L, &DWP(" ",$trans,$tmp1,0)); |
150 | &movb( &LB($tmp1), &LB($t) ); | 156 | &movb( &LB($tmp1), &LB($t) ); |
151 | &xor( $L, $ks); | 157 | &xor( $L, &DWP("0x200",$trans,$tmp2,0)); |
152 | &mov( $ks, &DWP("0x200+$desSP",$tmp2,"",0)); | ||
153 | &xor( $L, $ks); ###### | ||
154 | &movb( &LB($tmp2), &HB($t) ); | 158 | &movb( &LB($tmp2), &HB($t) ); |
155 | &shr( $u, 16); | 159 | &shr( $u, 16); |
156 | &mov( $ks, &DWP("0x100+$desSP",$tmp1,"",0)); | 160 | &xor( $L, &DWP("0x100",$trans,$tmp1,0)); |
157 | &xor( $L, $ks); ###### | ||
158 | &movb( &LB($tmp1), &HB($u) ); | 161 | &movb( &LB($tmp1), &HB($u) ); |
159 | &shr( $t, 16); | 162 | &shr( $t, 16); |
160 | &mov( $ks, &DWP("0x300+$desSP",$tmp2,"",0)); | 163 | &xor( $L, &DWP("0x300",$trans,$tmp2,0)); |
161 | &xor( $L, $ks); | ||
162 | &mov( $ks, &wparam(1) ); | ||
163 | &movb( &LB($tmp2), &HB($t) ); | 164 | &movb( &LB($tmp2), &HB($t) ); |
164 | &and( $u, "0xff" ); | 165 | &and( $u, "0xff" ); |
165 | &and( $t, "0xff" ); | 166 | &and( $t, "0xff" ); |
166 | &mov( $tmp1, &DWP("0x600+$desSP",$tmp1,"",0)); | 167 | &xor( $L, &DWP("0x600",$trans,$tmp1,0)); |
167 | &xor( $L, $tmp1); | 168 | &xor( $L, &DWP("0x700",$trans,$tmp2,0)); |
168 | &mov( $tmp1, &DWP("0x700+$desSP",$tmp2,"",0)); | 169 | &mov( $tmp2, &wparam(1) ); |
169 | &xor( $L, $tmp1); | 170 | &xor( $L, &DWP("0x400",$trans,$u,0)); |
170 | &mov( $tmp1, &DWP("0x400+$desSP",$u,"",0)); | 171 | &xor( $L, &DWP("0x500",$trans,$t,0)); |
171 | &xor( $L, $tmp1); | ||
172 | &mov( $tmp1, &DWP("0x500+$desSP",$t,"",0)); | ||
173 | &xor( $L, $tmp1); | ||
174 | } | 172 | } |
175 | 173 | ||
176 | sub n2a | 174 | sub n2a |
diff --git a/src/lib/libcrypto/des/cbc_cksm.c b/src/lib/libcrypto/des/cbc_cksm.c index 6c5305b99d..09a7ba56aa 100644 --- a/src/lib/libcrypto/des/cbc_cksm.c +++ b/src/lib/libcrypto/des/cbc_cksm.c | |||
@@ -93,5 +93,14 @@ DES_LONG DES_cbc_cksum(const unsigned char *in, DES_cblock *output, | |||
93 | l2c(tout1,out); | 93 | l2c(tout1,out); |
94 | } | 94 | } |
95 | tout0=tin0=tin1=tin[0]=tin[1]=0; | 95 | tout0=tin0=tin1=tin[0]=tin[1]=0; |
96 | /* | ||
97 | Transform the data in tout1 so that it will | ||
98 | match the return value that the MIT Kerberos | ||
99 | mit_des_cbc_cksum API returns. | ||
100 | */ | ||
101 | tout1 = ((tout1 >> 24L) & 0x000000FF) | ||
102 | | ((tout1 >> 8L) & 0x0000FF00) | ||
103 | | ((tout1 << 8L) & 0x00FF0000) | ||
104 | | ((tout1 << 24L) & 0xFF000000); | ||
96 | return(tout1); | 105 | return(tout1); |
97 | } | 106 | } |
diff --git a/src/lib/libcrypto/des/des.h b/src/lib/libcrypto/des/des.h index 4cb9d84fdf..daaf239dbe 100644 --- a/src/lib/libcrypto/des/des.h +++ b/src/lib/libcrypto/des/des.h | |||
@@ -56,8 +56,8 @@ | |||
56 | * [including the GNU Public Licence.] | 56 | * [including the GNU Public Licence.] |
57 | */ | 57 | */ |
58 | 58 | ||
59 | #ifndef HEADER_DES_H | 59 | #ifndef HEADER_NEW_DES_H |
60 | #define HEADER_DES_H | 60 | #define HEADER_NEW_DES_H |
61 | 61 | ||
62 | #ifdef OPENSSL_NO_DES | 62 | #ifdef OPENSSL_NO_DES |
63 | #error DES is disabled. | 63 | #error DES is disabled. |
diff --git a/src/lib/libcrypto/des/des_locl.h b/src/lib/libcrypto/des/des_locl.h index 70e833be3f..e44e8e98b2 100644 --- a/src/lib/libcrypto/des/des_locl.h +++ b/src/lib/libcrypto/des/des_locl.h | |||
@@ -162,7 +162,18 @@ | |||
162 | 162 | ||
163 | #if defined(OPENSSL_SYS_WIN32) && defined(_MSC_VER) | 163 | #if defined(OPENSSL_SYS_WIN32) && defined(_MSC_VER) |
164 | #define ROTATE(a,n) (_lrotr(a,n)) | 164 | #define ROTATE(a,n) (_lrotr(a,n)) |
165 | #else | 165 | #elif defined(__GNUC__) && __GNUC__>=2 && !defined(__STRICT_ANSI__) && !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_NO_INLINE_ASM) && !defined(PEDANTIC) |
166 | # if defined(__i386) || defined(__i386__) || defined(__x86_64) || defined(__x86_64__) | ||
167 | # define ROTATE(a,n) ({ register unsigned int ret; \ | ||
168 | asm ("rorl %1,%0" \ | ||
169 | : "=r"(ret) \ | ||
170 | : "I"(n),"0"(a) \ | ||
171 | : "cc"); \ | ||
172 | ret; \ | ||
173 | }) | ||
174 | # endif | ||
175 | #endif | ||
176 | #ifndef ROTATE | ||
166 | #define ROTATE(a,n) (((a)>>(n))+((a)<<(32-(n)))) | 177 | #define ROTATE(a,n) (((a)>>(n))+((a)<<(32-(n)))) |
167 | #endif | 178 | #endif |
168 | 179 | ||
diff --git a/src/lib/libcrypto/des/str2key.c b/src/lib/libcrypto/des/str2key.c index 36c3f81d99..0373db469c 100644 --- a/src/lib/libcrypto/des/str2key.c +++ b/src/lib/libcrypto/des/str2key.c | |||
@@ -94,7 +94,7 @@ void DES_string_to_key(const char *str, DES_cblock *key) | |||
94 | DES_set_key_unchecked(key,&ks); | 94 | DES_set_key_unchecked(key,&ks); |
95 | #endif | 95 | #endif |
96 | DES_cbc_cksum((const unsigned char*)str,key,length,&ks,key); | 96 | DES_cbc_cksum((const unsigned char*)str,key,length,&ks,key); |
97 | memset(&ks,0,sizeof(ks)); | 97 | OPENSSL_cleanse(&ks,sizeof(ks)); |
98 | DES_set_odd_parity(key); | 98 | DES_set_odd_parity(key); |
99 | } | 99 | } |
100 | 100 | ||
@@ -167,7 +167,7 @@ void DES_string_to_2keys(const char *str, DES_cblock *key1, DES_cblock *key2) | |||
167 | DES_set_key_unchecked(key2,&ks); | 167 | DES_set_key_unchecked(key2,&ks); |
168 | #endif | 168 | #endif |
169 | DES_cbc_cksum((const unsigned char*)str,key2,length,&ks,key2); | 169 | DES_cbc_cksum((const unsigned char*)str,key2,length,&ks,key2); |
170 | memset(&ks,0,sizeof(ks)); | 170 | OPENSSL_cleanse(&ks,sizeof(ks)); |
171 | DES_set_odd_parity(key1); | 171 | DES_set_odd_parity(key1); |
172 | DES_set_odd_parity(key2); | 172 | DES_set_odd_parity(key2); |
173 | } | 173 | } |
diff --git a/src/lib/libcrypto/dh/dh_key.c b/src/lib/libcrypto/dh/dh_key.c index 1a0efca2c4..77f2f50b51 100644 --- a/src/lib/libcrypto/dh/dh_key.c +++ b/src/lib/libcrypto/dh/dh_key.c | |||
@@ -61,7 +61,6 @@ | |||
61 | #include <openssl/bn.h> | 61 | #include <openssl/bn.h> |
62 | #include <openssl/rand.h> | 62 | #include <openssl/rand.h> |
63 | #include <openssl/dh.h> | 63 | #include <openssl/dh.h> |
64 | #include <openssl/engine.h> | ||
65 | 64 | ||
66 | static int generate_key(DH *dh); | 65 | static int generate_key(DH *dh); |
67 | static int compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh); | 66 | static int compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh); |
diff --git a/src/lib/libcrypto/dh/dh_lib.c b/src/lib/libcrypto/dh/dh_lib.c index ba5fd41057..09965ee2ea 100644 --- a/src/lib/libcrypto/dh/dh_lib.c +++ b/src/lib/libcrypto/dh/dh_lib.c | |||
@@ -60,7 +60,9 @@ | |||
60 | #include "cryptlib.h" | 60 | #include "cryptlib.h" |
61 | #include <openssl/bn.h> | 61 | #include <openssl/bn.h> |
62 | #include <openssl/dh.h> | 62 | #include <openssl/dh.h> |
63 | #ifndef OPENSSL_NO_ENGINE | ||
63 | #include <openssl/engine.h> | 64 | #include <openssl/engine.h> |
65 | #endif | ||
64 | 66 | ||
65 | const char *DH_version="Diffie-Hellman" OPENSSL_VERSION_PTEXT; | 67 | const char *DH_version="Diffie-Hellman" OPENSSL_VERSION_PTEXT; |
66 | 68 | ||
@@ -85,11 +87,13 @@ int DH_set_method(DH *dh, const DH_METHOD *meth) | |||
85 | const DH_METHOD *mtmp; | 87 | const DH_METHOD *mtmp; |
86 | mtmp = dh->meth; | 88 | mtmp = dh->meth; |
87 | if (mtmp->finish) mtmp->finish(dh); | 89 | if (mtmp->finish) mtmp->finish(dh); |
90 | #ifndef OPENSSL_NO_ENGINE | ||
88 | if (dh->engine) | 91 | if (dh->engine) |
89 | { | 92 | { |
90 | ENGINE_finish(dh->engine); | 93 | ENGINE_finish(dh->engine); |
91 | dh->engine = NULL; | 94 | dh->engine = NULL; |
92 | } | 95 | } |
96 | #endif | ||
93 | dh->meth = meth; | 97 | dh->meth = meth; |
94 | if (meth->init) meth->init(dh); | 98 | if (meth->init) meth->init(dh); |
95 | return 1; | 99 | return 1; |
@@ -112,6 +116,7 @@ DH *DH_new_method(ENGINE *engine) | |||
112 | } | 116 | } |
113 | 117 | ||
114 | ret->meth = DH_get_default_method(); | 118 | ret->meth = DH_get_default_method(); |
119 | #ifndef OPENSSL_NO_ENGINE | ||
115 | if (engine) | 120 | if (engine) |
116 | { | 121 | { |
117 | if (!ENGINE_init(engine)) | 122 | if (!ENGINE_init(engine)) |
@@ -135,6 +140,7 @@ DH *DH_new_method(ENGINE *engine) | |||
135 | return NULL; | 140 | return NULL; |
136 | } | 141 | } |
137 | } | 142 | } |
143 | #endif | ||
138 | 144 | ||
139 | ret->pad=0; | 145 | ret->pad=0; |
140 | ret->version=0; | 146 | ret->version=0; |
@@ -154,8 +160,10 @@ DH *DH_new_method(ENGINE *engine) | |||
154 | CRYPTO_new_ex_data(CRYPTO_EX_INDEX_DH, ret, &ret->ex_data); | 160 | CRYPTO_new_ex_data(CRYPTO_EX_INDEX_DH, ret, &ret->ex_data); |
155 | if ((ret->meth->init != NULL) && !ret->meth->init(ret)) | 161 | if ((ret->meth->init != NULL) && !ret->meth->init(ret)) |
156 | { | 162 | { |
163 | #ifndef OPENSSL_NO_ENGINE | ||
157 | if (ret->engine) | 164 | if (ret->engine) |
158 | ENGINE_finish(ret->engine); | 165 | ENGINE_finish(ret->engine); |
166 | #endif | ||
159 | CRYPTO_free_ex_data(CRYPTO_EX_INDEX_DH, ret, &ret->ex_data); | 167 | CRYPTO_free_ex_data(CRYPTO_EX_INDEX_DH, ret, &ret->ex_data); |
160 | OPENSSL_free(ret); | 168 | OPENSSL_free(ret); |
161 | ret=NULL; | 169 | ret=NULL; |
@@ -182,8 +190,10 @@ void DH_free(DH *r) | |||
182 | 190 | ||
183 | if (r->meth->finish) | 191 | if (r->meth->finish) |
184 | r->meth->finish(r); | 192 | r->meth->finish(r); |
193 | #ifndef OPENSSL_NO_ENGINE | ||
185 | if (r->engine) | 194 | if (r->engine) |
186 | ENGINE_finish(r->engine); | 195 | ENGINE_finish(r->engine); |
196 | #endif | ||
187 | 197 | ||
188 | CRYPTO_free_ex_data(CRYPTO_EX_INDEX_DH, r, &r->ex_data); | 198 | CRYPTO_free_ex_data(CRYPTO_EX_INDEX_DH, r, &r->ex_data); |
189 | 199 | ||
diff --git a/src/lib/libcrypto/doc/DH_generate_key.pod b/src/lib/libcrypto/doc/DH_generate_key.pod index 920995b2e5..81f09fdf45 100644 --- a/src/lib/libcrypto/doc/DH_generate_key.pod +++ b/src/lib/libcrypto/doc/DH_generate_key.pod | |||
@@ -40,7 +40,7 @@ The error codes can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>. | |||
40 | 40 | ||
41 | =head1 SEE ALSO | 41 | =head1 SEE ALSO |
42 | 42 | ||
43 | L<dh(3)|dh(3)>, L<err(3)|err(3)>, L<rand(3)|rand(3)>, L<DH_size(3)|DH_size(3)> | 43 | L<dh(3)|dh(3)>, L<ERR_get_error(3)|ERR_get_error(3)>, L<rand(3)|rand(3)>, L<DH_size(3)|DH_size(3)> |
44 | 44 | ||
45 | =head1 HISTORY | 45 | =head1 HISTORY |
46 | 46 | ||
diff --git a/src/lib/libcrypto/doc/DH_generate_parameters.pod b/src/lib/libcrypto/doc/DH_generate_parameters.pod index a7d0c75f0c..9081e9ea7c 100644 --- a/src/lib/libcrypto/doc/DH_generate_parameters.pod +++ b/src/lib/libcrypto/doc/DH_generate_parameters.pod | |||
@@ -59,7 +59,8 @@ a usable generator. | |||
59 | 59 | ||
60 | =head1 SEE ALSO | 60 | =head1 SEE ALSO |
61 | 61 | ||
62 | L<dh(3)|dh(3)>, L<err(3)|err(3)>, L<rand(3)|rand(3)>, L<DH_free(3)|DH_free(3)> | 62 | L<dh(3)|dh(3)>, L<ERR_get_error(3)|ERR_get_error(3)>, L<rand(3)|rand(3)>, |
63 | L<DH_free(3)|DH_free(3)> | ||
63 | 64 | ||
64 | =head1 HISTORY | 65 | =head1 HISTORY |
65 | 66 | ||
diff --git a/src/lib/libcrypto/doc/DH_new.pod b/src/lib/libcrypto/doc/DH_new.pod index 64624b9d15..60c930093e 100644 --- a/src/lib/libcrypto/doc/DH_new.pod +++ b/src/lib/libcrypto/doc/DH_new.pod | |||
@@ -29,7 +29,7 @@ DH_free() returns no value. | |||
29 | 29 | ||
30 | =head1 SEE ALSO | 30 | =head1 SEE ALSO |
31 | 31 | ||
32 | L<dh(3)|dh(3)>, L<err(3)|err(3)>, | 32 | L<dh(3)|dh(3)>, L<ERR_get_error(3)|ERR_get_error(3)>, |
33 | L<DH_generate_parameters(3)|DH_generate_parameters(3)>, | 33 | L<DH_generate_parameters(3)|DH_generate_parameters(3)>, |
34 | L<DH_generate_key(3)|DH_generate_key(3)> | 34 | L<DH_generate_key(3)|DH_generate_key(3)> |
35 | 35 | ||
diff --git a/src/lib/libcrypto/doc/DSA_SIG_new.pod b/src/lib/libcrypto/doc/DSA_SIG_new.pod index 671655554a..3ac6140038 100644 --- a/src/lib/libcrypto/doc/DSA_SIG_new.pod +++ b/src/lib/libcrypto/doc/DSA_SIG_new.pod | |||
@@ -30,7 +30,8 @@ DSA_SIG_free() returns no value. | |||
30 | 30 | ||
31 | =head1 SEE ALSO | 31 | =head1 SEE ALSO |
32 | 32 | ||
33 | L<dsa(3)|dsa(3)>, L<err(3)|err(3)>, L<DSA_do_sign(3)|DSA_do_sign(3)> | 33 | L<dsa(3)|dsa(3)>, L<ERR_get_error(3)|ERR_get_error(3)>, |
34 | L<DSA_do_sign(3)|DSA_do_sign(3)> | ||
34 | 35 | ||
35 | =head1 HISTORY | 36 | =head1 HISTORY |
36 | 37 | ||
diff --git a/src/lib/libcrypto/doc/DSA_do_sign.pod b/src/lib/libcrypto/doc/DSA_do_sign.pod index a24fd5714e..5dfc733b20 100644 --- a/src/lib/libcrypto/doc/DSA_do_sign.pod +++ b/src/lib/libcrypto/doc/DSA_do_sign.pod | |||
@@ -36,7 +36,7 @@ L<ERR_get_error(3)|ERR_get_error(3)>. | |||
36 | 36 | ||
37 | =head1 SEE ALSO | 37 | =head1 SEE ALSO |
38 | 38 | ||
39 | L<dsa(3)|dsa(3)>, L<err(3)|err(3)>, L<rand(3)|rand(3)>, | 39 | L<dsa(3)|dsa(3)>, L<ERR_get_error(3)|ERR_get_error(3)>, L<rand(3)|rand(3)>, |
40 | L<DSA_SIG_new(3)|DSA_SIG_new(3)>, | 40 | L<DSA_SIG_new(3)|DSA_SIG_new(3)>, |
41 | L<DSA_sign(3)|DSA_sign(3)> | 41 | L<DSA_sign(3)|DSA_sign(3)> |
42 | 42 | ||
diff --git a/src/lib/libcrypto/doc/DSA_dup_DH.pod b/src/lib/libcrypto/doc/DSA_dup_DH.pod index fdfe125ab0..7f6f0d1115 100644 --- a/src/lib/libcrypto/doc/DSA_dup_DH.pod +++ b/src/lib/libcrypto/doc/DSA_dup_DH.pod | |||
@@ -27,7 +27,7 @@ Be careful to avoid small subgroup attacks when using this. | |||
27 | 27 | ||
28 | =head1 SEE ALSO | 28 | =head1 SEE ALSO |
29 | 29 | ||
30 | L<dh(3)|dh(3)>, L<dsa(3)|dsa(3)>, L<err(3)|err(3)> | 30 | L<dh(3)|dh(3)>, L<dsa(3)|dsa(3)>, L<ERR_get_error(3)|ERR_get_error(3)> |
31 | 31 | ||
32 | =head1 HISTORY | 32 | =head1 HISTORY |
33 | 33 | ||
diff --git a/src/lib/libcrypto/doc/DSA_generate_key.pod b/src/lib/libcrypto/doc/DSA_generate_key.pod index 52890db5be..af83ccfaa1 100644 --- a/src/lib/libcrypto/doc/DSA_generate_key.pod +++ b/src/lib/libcrypto/doc/DSA_generate_key.pod | |||
@@ -24,7 +24,8 @@ The error codes can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>. | |||
24 | 24 | ||
25 | =head1 SEE ALSO | 25 | =head1 SEE ALSO |
26 | 26 | ||
27 | L<dsa(3)|dsa(3)>, L<err(3)|err(3)>, L<rand(3)|rand(3)>, L<DSA_generate_parameters(3)|DSA_generate_parameters(3)> | 27 | L<dsa(3)|dsa(3)>, L<ERR_get_error(3)|ERR_get_error(3)>, L<rand(3)|rand(3)>, |
28 | L<DSA_generate_parameters(3)|DSA_generate_parameters(3)> | ||
28 | 29 | ||
29 | =head1 HISTORY | 30 | =head1 HISTORY |
30 | 31 | ||
diff --git a/src/lib/libcrypto/doc/DSA_generate_parameters.pod b/src/lib/libcrypto/doc/DSA_generate_parameters.pod index 43f60b0eb9..be7c924ff8 100644 --- a/src/lib/libcrypto/doc/DSA_generate_parameters.pod +++ b/src/lib/libcrypto/doc/DSA_generate_parameters.pod | |||
@@ -90,7 +90,7 @@ Seed lengths E<gt> 20 are not supported. | |||
90 | 90 | ||
91 | =head1 SEE ALSO | 91 | =head1 SEE ALSO |
92 | 92 | ||
93 | L<dsa(3)|dsa(3)>, L<err(3)|err(3)>, L<rand(3)|rand(3)>, | 93 | L<dsa(3)|dsa(3)>, L<ERR_get_error(3)|ERR_get_error(3)>, L<rand(3)|rand(3)>, |
94 | L<DSA_free(3)|DSA_free(3)> | 94 | L<DSA_free(3)|DSA_free(3)> |
95 | 95 | ||
96 | =head1 HISTORY | 96 | =head1 HISTORY |
diff --git a/src/lib/libcrypto/doc/DSA_new.pod b/src/lib/libcrypto/doc/DSA_new.pod index 546146d9de..48e9b82a09 100644 --- a/src/lib/libcrypto/doc/DSA_new.pod +++ b/src/lib/libcrypto/doc/DSA_new.pod | |||
@@ -31,7 +31,7 @@ DSA_free() returns no value. | |||
31 | 31 | ||
32 | =head1 SEE ALSO | 32 | =head1 SEE ALSO |
33 | 33 | ||
34 | L<dsa(3)|dsa(3)>, L<err(3)|err(3)>, | 34 | L<dsa(3)|dsa(3)>, L<ERR_get_error(3)|ERR_get_error(3)>, |
35 | L<DSA_generate_parameters(3)|DSA_generate_parameters(3)>, | 35 | L<DSA_generate_parameters(3)|DSA_generate_parameters(3)>, |
36 | L<DSA_generate_key(3)|DSA_generate_key(3)> | 36 | L<DSA_generate_key(3)|DSA_generate_key(3)> |
37 | 37 | ||
diff --git a/src/lib/libcrypto/doc/DSA_sign.pod b/src/lib/libcrypto/doc/DSA_sign.pod index f6e60a8ca3..97389e8ec8 100644 --- a/src/lib/libcrypto/doc/DSA_sign.pod +++ b/src/lib/libcrypto/doc/DSA_sign.pod | |||
@@ -55,7 +55,7 @@ Standard, DSS), ANSI X9.30 | |||
55 | 55 | ||
56 | =head1 SEE ALSO | 56 | =head1 SEE ALSO |
57 | 57 | ||
58 | L<dsa(3)|dsa(3)>, L<err(3)|err(3)>, L<rand(3)|rand(3)>, | 58 | L<dsa(3)|dsa(3)>, L<ERR_get_error(3)|ERR_get_error(3)>, L<rand(3)|rand(3)>, |
59 | L<DSA_do_sign(3)|DSA_do_sign(3)> | 59 | L<DSA_do_sign(3)|DSA_do_sign(3)> |
60 | 60 | ||
61 | =head1 HISTORY | 61 | =head1 HISTORY |
diff --git a/src/lib/libcrypto/doc/ERR_get_error.pod b/src/lib/libcrypto/doc/ERR_get_error.pod index 9fdedbcb91..34443045fc 100644 --- a/src/lib/libcrypto/doc/ERR_get_error.pod +++ b/src/lib/libcrypto/doc/ERR_get_error.pod | |||
@@ -5,7 +5,7 @@ | |||
5 | ERR_get_error, ERR_peek_error, ERR_peek_last_error, | 5 | ERR_get_error, ERR_peek_error, ERR_peek_last_error, |
6 | ERR_get_error_line, ERR_peek_error_line, ERR_peek_last_error_line, | 6 | ERR_get_error_line, ERR_peek_error_line, ERR_peek_last_error_line, |
7 | ERR_get_error_line_data, ERR_peek_error_line_data, | 7 | ERR_get_error_line_data, ERR_peek_error_line_data, |
8 | ERR_peek_error_line_data - obtain error code and data | 8 | ERR_peek_last_error_line_data - obtain error code and data |
9 | 9 | ||
10 | =head1 SYNOPSIS | 10 | =head1 SYNOPSIS |
11 | 11 | ||
diff --git a/src/lib/libcrypto/doc/EVP_EncryptInit.pod b/src/lib/libcrypto/doc/EVP_EncryptInit.pod index 75cceb1ca2..daf57e5895 100644 --- a/src/lib/libcrypto/doc/EVP_EncryptInit.pod +++ b/src/lib/libcrypto/doc/EVP_EncryptInit.pod | |||
@@ -419,7 +419,7 @@ Encrypt a string using blowfish: | |||
419 | EVP_CIPHER_CTX ctx; | 419 | EVP_CIPHER_CTX ctx; |
420 | FILE *out; | 420 | FILE *out; |
421 | EVP_CIPHER_CTX_init(&ctx); | 421 | EVP_CIPHER_CTX_init(&ctx); |
422 | EVP_EncryptInit_ex(&ctx, NULL, EVP_bf_cbc(), key, iv); | 422 | EVP_EncryptInit_ex(&ctx, EVP_bf_cbc(), NULL, key, iv); |
423 | 423 | ||
424 | if(!EVP_EncryptUpdate(&ctx, outbuf, &outlen, intext, strlen(intext))) | 424 | if(!EVP_EncryptUpdate(&ctx, outbuf, &outlen, intext, strlen(intext))) |
425 | { | 425 | { |
diff --git a/src/lib/libcrypto/doc/EVP_PKEY_new.pod b/src/lib/libcrypto/doc/EVP_PKEY_new.pod new file mode 100644 index 0000000000..10687e458d --- /dev/null +++ b/src/lib/libcrypto/doc/EVP_PKEY_new.pod | |||
@@ -0,0 +1,47 @@ | |||
1 | =pod | ||
2 | |||
3 | =head1 NAME | ||
4 | |||
5 | EVP_PKEY_new, EVP_PKEY_free - private key allocation functions. | ||
6 | |||
7 | =head1 SYNOPSIS | ||
8 | |||
9 | #include <openssl/evp.h> | ||
10 | |||
11 | EVP_PKEY *EVP_PKEY_new(void); | ||
12 | void EVP_PKEY_free(EVP_PKEY *key); | ||
13 | |||
14 | |||
15 | =head1 DESCRIPTION | ||
16 | |||
17 | The EVP_PKEY_new() function allocates an empty B<EVP_PKEY> | ||
18 | structure which is used by OpenSSL to store private keys. | ||
19 | |||
20 | EVP_PKEY_free() frees up the private key B<key>. | ||
21 | |||
22 | =head1 NOTES | ||
23 | |||
24 | The B<EVP_PKEY> structure is used by various OpenSSL functions | ||
25 | which require a general private key without reference to any | ||
26 | particular algorithm. | ||
27 | |||
28 | The structure returned by EVP_PKEY_new() is empty. To add a | ||
29 | private key to this empty structure the functions described in | ||
30 | L<EVP_PKEY_set1_RSA(3)|EVP_PKEY_set1_RSA(3)> should be used. | ||
31 | |||
32 | =head1 RETURN VALUES | ||
33 | |||
34 | EVP_PKEY_new() returns either the newly allocated B<EVP_PKEY> | ||
35 | structure of B<NULL> if an error occurred. | ||
36 | |||
37 | EVP_PKEY_free() does not return a value. | ||
38 | |||
39 | =head1 SEE ALSO | ||
40 | |||
41 | L<EVP_PKEY_set1_RSA(3)|EVP_PKEY_set1_RSA(3)> | ||
42 | |||
43 | =head1 HISTORY | ||
44 | |||
45 | TBA | ||
46 | |||
47 | =cut | ||
diff --git a/src/lib/libcrypto/doc/EVP_PKEY_set1_RSA.pod b/src/lib/libcrypto/doc/EVP_PKEY_set1_RSA.pod new file mode 100644 index 0000000000..2db692e271 --- /dev/null +++ b/src/lib/libcrypto/doc/EVP_PKEY_set1_RSA.pod | |||
@@ -0,0 +1,80 @@ | |||
1 | =pod | ||
2 | |||
3 | =head1 NAME | ||
4 | |||
5 | EVP_PKEY_set1_RSA, EVP_PKEY_set1_DSA, EVP_PKEY_set1_DH, EVP_PKEY_set1_EC_KEY, | ||
6 | EVP_PKEY_get1_RSA, EVP_PKEY_get1_DSA, EVP_PKEY_get1_DH, EVP_PKEY_get1_EC_KEY, | ||
7 | EVP_PKEY_assign_RSA, EVP_PKEY_assign_DSA, EVP_PKEY_assign_DH, EVP_PKEY_assign_EC_KEY, | ||
8 | EVP_PKEY_type - EVP_PKEY assignment functions. | ||
9 | |||
10 | =head1 SYNOPSIS | ||
11 | |||
12 | #include <openssl/evp.h> | ||
13 | |||
14 | int EVP_PKEY_set1_RSA(EVP_PKEY *pkey,RSA *key); | ||
15 | int EVP_PKEY_set1_DSA(EVP_PKEY *pkey,DSA *key); | ||
16 | int EVP_PKEY_set1_DH(EVP_PKEY *pkey,DH *key); | ||
17 | int EVP_PKEY_set1_EC_KEY(EVP_PKEY *pkey,EC_KEY *key); | ||
18 | |||
19 | RSA *EVP_PKEY_get1_RSA(EVP_PKEY *pkey); | ||
20 | DSA *EVP_PKEY_get1_DSA(EVP_PKEY *pkey); | ||
21 | DH *EVP_PKEY_get1_DH(EVP_PKEY *pkey); | ||
22 | EC_KEY *EVP_PKEY_get1_EC_KEY(EVP_PKEY *pkey); | ||
23 | |||
24 | int EVP_PKEY_assign_RSA(EVP_PKEY *pkey,RSA *key); | ||
25 | int EVP_PKEY_assign_DSA(EVP_PKEY *pkey,DSA *key); | ||
26 | int EVP_PKEY_assign_DH(EVP_PKEY *pkey,DH *key); | ||
27 | int EVP_PKEY_assign_EC_KEY(EVP_PKEY *pkey,EC_KEY *key); | ||
28 | |||
29 | int EVP_PKEY_type(int type); | ||
30 | |||
31 | =head1 DESCRIPTION | ||
32 | |||
33 | EVP_PKEY_set1_RSA(), EVP_PKEY_set1_DSA(), EVP_PKEY_set1_DH() and | ||
34 | EVP_PKEY_set1_EC_KEY() set the key referenced by B<pkey> to B<key>. | ||
35 | |||
36 | EVP_PKEY_get1_RSA(), EVP_PKEY_get1_DSA(), EVP_PKEY_get1_DH() and | ||
37 | EVP_PKEY_get1_EC_KEY() return the referenced key in B<pkey> or | ||
38 | B<NULL> if the key is not of the correct type. | ||
39 | |||
40 | EVP_PKEY_assign_RSA() EVP_PKEY_assign_DSA(), EVP_PKEY_assign_DH() | ||
41 | and EVP_PKEY_assign_EC_KEY() also set the referenced key to B<key> | ||
42 | however these use the supplied B<key> internally and so B<key> | ||
43 | will be freed when the parent B<pkey> is freed. | ||
44 | |||
45 | EVP_PKEY_type() returns the type of key corresponding to the value | ||
46 | B<type>. The type of a key can be obtained with | ||
47 | EVP_PKEY_type(pkey->type). The return value will be EVP_PKEY_RSA, | ||
48 | EVP_PKEY_DSA, EVP_PKEY_DH or EVP_PKEY_EC for the corresponding | ||
49 | key types or NID_undef if the key type is unassigned. | ||
50 | |||
51 | =head1 NOTES | ||
52 | |||
53 | In accordance with the OpenSSL naming convention the key obtained | ||
54 | from or assigned to the B<pkey> using the B<1> functions must be | ||
55 | freed as well as B<pkey>. | ||
56 | |||
57 | EVP_PKEY_assign_RSA() EVP_PKEY_assign_DSA(), EVP_PKEY_assign_DH() | ||
58 | EVP_PKEY_assign_EC_KEY() are implemented as macros. | ||
59 | |||
60 | =head1 RETURN VALUES | ||
61 | |||
62 | EVP_PKEY_set1_RSA(), EVP_PKEY_set1_DSA(), EVP_PKEY_set1_DH() and | ||
63 | EVP_PKEY_set1_EC_KEY() return 1 for success or 0 for failure. | ||
64 | |||
65 | EVP_PKEY_get1_RSA(), EVP_PKEY_get1_DSA(), EVP_PKEY_get1_DH() and | ||
66 | EVP_PKEY_get1_EC_KEY() return the referenced key or B<NULL> if | ||
67 | an error occurred. | ||
68 | |||
69 | EVP_PKEY_assign_RSA() EVP_PKEY_assign_DSA(), EVP_PKEY_assign_DH() | ||
70 | and EVP_PKEY_assign_EC_KEY() return 1 for success and 0 for failure. | ||
71 | |||
72 | =head1 SEE ALSO | ||
73 | |||
74 | L<EVP_PKEY_new(3)|EVP_PKEY_new(3)> | ||
75 | |||
76 | =head1 HISTORY | ||
77 | |||
78 | TBA | ||
79 | |||
80 | =cut | ||
diff --git a/src/lib/libcrypto/doc/EVP_SealInit.pod b/src/lib/libcrypto/doc/EVP_SealInit.pod index 25ef07f7c7..b5e477e294 100644 --- a/src/lib/libcrypto/doc/EVP_SealInit.pod +++ b/src/lib/libcrypto/doc/EVP_SealInit.pod | |||
@@ -18,22 +18,28 @@ EVP_SealInit, EVP_SealUpdate, EVP_SealFinal - EVP envelope encryption | |||
18 | =head1 DESCRIPTION | 18 | =head1 DESCRIPTION |
19 | 19 | ||
20 | The EVP envelope routines are a high level interface to envelope | 20 | The EVP envelope routines are a high level interface to envelope |
21 | encryption. They generate a random key and then "envelope" it by | 21 | encryption. They generate a random key and IV (if required) then |
22 | using public key encryption. Data can then be encrypted using this | 22 | "envelope" it by using public key encryption. Data can then be |
23 | key. | 23 | encrypted using this key. |
24 | 24 | ||
25 | EVP_SealInit() initializes a cipher context B<ctx> for encryption | 25 | EVP_SealInit() initializes a cipher context B<ctx> for encryption |
26 | with cipher B<type> using a random secret key and IV supplied in | 26 | with cipher B<type> using a random secret key and IV. B<type> is normally |
27 | the B<iv> parameter. B<type> is normally supplied by a function such | 27 | supplied by a function such as EVP_des_cbc(). The secret key is encrypted |
28 | as EVP_des_cbc(). The secret key is encrypted using one or more public | 28 | using one or more public keys, this allows the same encrypted data to be |
29 | keys, this allows the same encrypted data to be decrypted using any | 29 | decrypted using any of the corresponding private keys. B<ek> is an array of |
30 | of the corresponding private keys. B<ek> is an array of buffers where | 30 | buffers where the public key encrypted secret key will be written, each buffer |
31 | the public key encrypted secret key will be written, each buffer must | 31 | must contain enough room for the corresponding encrypted key: that is |
32 | contain enough room for the corresponding encrypted key: that is | ||
33 | B<ek[i]> must have room for B<EVP_PKEY_size(pubk[i])> bytes. The actual | 32 | B<ek[i]> must have room for B<EVP_PKEY_size(pubk[i])> bytes. The actual |
34 | size of each encrypted secret key is written to the array B<ekl>. B<pubk> is | 33 | size of each encrypted secret key is written to the array B<ekl>. B<pubk> is |
35 | an array of B<npubk> public keys. | 34 | an array of B<npubk> public keys. |
36 | 35 | ||
36 | The B<iv> parameter is a buffer where the generated IV is written to. It must | ||
37 | contain enough room for the corresponding cipher's IV, as determined by (for | ||
38 | example) EVP_CIPHER_iv_length(type). | ||
39 | |||
40 | If the cipher does not require an IV then the B<iv> parameter is ignored | ||
41 | and can be B<NULL>. | ||
42 | |||
37 | EVP_SealUpdate() and EVP_SealFinal() have exactly the same properties | 43 | EVP_SealUpdate() and EVP_SealFinal() have exactly the same properties |
38 | as the EVP_EncryptUpdate() and EVP_EncryptFinal() routines, as | 44 | as the EVP_EncryptUpdate() and EVP_EncryptFinal() routines, as |
39 | documented on the L<EVP_EncryptInit(3)|EVP_EncryptInit(3)> manual | 45 | documented on the L<EVP_EncryptInit(3)|EVP_EncryptInit(3)> manual |
diff --git a/src/lib/libcrypto/doc/OBJ_nid2obj.pod b/src/lib/libcrypto/doc/OBJ_nid2obj.pod new file mode 100644 index 0000000000..7dcc07923f --- /dev/null +++ b/src/lib/libcrypto/doc/OBJ_nid2obj.pod | |||
@@ -0,0 +1,149 @@ | |||
1 | =pod | ||
2 | |||
3 | =head1 NAME | ||
4 | |||
5 | OBJ_nid2obj, OBJ_nid2ln, OBJ_nid2sn, OBJ_obj2nid, OBJ_txt2nid, OBJ_ln2nid, OBJ_sn2nid, | ||
6 | OBJ_cmp, OBJ_dup, OBJ_txt2obj, OBJ_obj2txt, OBJ_create, OBJ_cleanup - ASN1 object utility | ||
7 | functions | ||
8 | |||
9 | =head1 SYNOPSIS | ||
10 | |||
11 | ASN1_OBJECT * OBJ_nid2obj(int n); | ||
12 | const char * OBJ_nid2ln(int n); | ||
13 | const char * OBJ_nid2sn(int n); | ||
14 | |||
15 | int OBJ_obj2nid(const ASN1_OBJECT *o); | ||
16 | int OBJ_ln2nid(const char *ln); | ||
17 | int OBJ_sn2nid(const char *sn); | ||
18 | |||
19 | int OBJ_txt2nid(const char *s); | ||
20 | |||
21 | ASN1_OBJECT * OBJ_txt2obj(const char *s, int no_name); | ||
22 | int OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name); | ||
23 | |||
24 | int OBJ_cmp(const ASN1_OBJECT *a,const ASN1_OBJECT *b); | ||
25 | ASN1_OBJECT * OBJ_dup(const ASN1_OBJECT *o); | ||
26 | |||
27 | int OBJ_create(const char *oid,const char *sn,const char *ln); | ||
28 | void OBJ_cleanup(void); | ||
29 | |||
30 | =head1 DESCRIPTION | ||
31 | |||
32 | The ASN1 object utility functions process ASN1_OBJECT structures which are | ||
33 | a representation of the ASN1 OBJECT IDENTIFIER (OID) type. | ||
34 | |||
35 | OBJ_nid2obj(), OBJ_nid2ln() and OBJ_nid2sn() convert the NID B<n> to | ||
36 | an ASN1_OBJECT structure, its long name and its short name respectively, | ||
37 | or B<NULL> is an error occurred. | ||
38 | |||
39 | OBJ_obj2nid(), OBJ_ln2nid(), OBJ_sn2nid() return the corresponding NID | ||
40 | for the object B<o>, the long name <ln> or the short name <sn> respectively | ||
41 | or NID_undef if an error occurred. | ||
42 | |||
43 | OBJ_txt2nid() returns NID corresponding to text string <s>. B<s> can be | ||
44 | a long name, a short name or the numerical respresentation of an object. | ||
45 | |||
46 | OBJ_txt2obj() converts the text string B<s> into an ASN1_OBJECT structure. | ||
47 | If B<no_name> is 0 then long names and short names will be interpreted | ||
48 | as well as numerical forms. If B<no_name> is 1 only the numerical form | ||
49 | is acceptable. | ||
50 | |||
51 | OBJ_obj2txt() converts the B<ASN1_OBJECT> B<a> into a textual representation. | ||
52 | The representation is written as a null terminated string to B<buf> | ||
53 | at most B<buf_len> bytes are written, truncating the result if necessary. | ||
54 | The total amount of space required is returned. If B<no_name> is 0 then | ||
55 | if the object has a long or short name then that will be used, otherwise | ||
56 | the numerical form will be used. If B<no_name> is 1 then the numerical | ||
57 | form will always be used. | ||
58 | |||
59 | OBJ_cmp() compares B<a> to B<b>. If the two are identical 0 is returned. | ||
60 | |||
61 | OBJ_dup() returns a copy of B<o>. | ||
62 | |||
63 | OBJ_create() adds a new object to the internal table. B<oid> is the | ||
64 | numerical form of the object, B<sn> the short name and B<ln> the | ||
65 | long name. A new NID is returned for the created object. | ||
66 | |||
67 | OBJ_cleanup() cleans up OpenSSLs internal object table: this should | ||
68 | be called before an application exits if any new objects were added | ||
69 | using OBJ_create(). | ||
70 | |||
71 | =head1 NOTES | ||
72 | |||
73 | Objects in OpenSSL can have a short name, a long name and a numerical | ||
74 | identifier (NID) associated with them. A standard set of objects is | ||
75 | represented in an internal table. The appropriate values are defined | ||
76 | in the header file B<objects.h>. | ||
77 | |||
78 | For example the OID for commonName has the following definitions: | ||
79 | |||
80 | #define SN_commonName "CN" | ||
81 | #define LN_commonName "commonName" | ||
82 | #define NID_commonName 13 | ||
83 | |||
84 | New objects can be added by calling OBJ_create(). | ||
85 | |||
86 | Table objects have certain advantages over other objects: for example | ||
87 | their NIDs can be used in a C language switch statement. They are | ||
88 | also static constant structures which are shared: that is there | ||
89 | is only a single constant structure for each table object. | ||
90 | |||
91 | Objects which are not in the table have the NID value NID_undef. | ||
92 | |||
93 | Objects do not need to be in the internal tables to be processed, | ||
94 | the functions OBJ_txt2obj() and OBJ_obj2txt() can process the numerical | ||
95 | form of an OID. | ||
96 | |||
97 | =head1 EXAMPLES | ||
98 | |||
99 | Create an object for B<commonName>: | ||
100 | |||
101 | ASN1_OBJECT *o; | ||
102 | o = OBJ_nid2obj(NID_commonName); | ||
103 | |||
104 | Check if an object is B<commonName> | ||
105 | |||
106 | if (OBJ_obj2nid(obj) == NID_commonName) | ||
107 | /* Do something */ | ||
108 | |||
109 | Create a new NID and initialize an object from it: | ||
110 | |||
111 | int new_nid; | ||
112 | ASN1_OBJECT *obj; | ||
113 | new_nid = OBJ_create("1.2.3.4", "NewOID", "New Object Identifier"); | ||
114 | |||
115 | obj = OBJ_nid2obj(new_nid); | ||
116 | |||
117 | Create a new object directly: | ||
118 | |||
119 | obj = OBJ_txt2obj("1.2.3.4", 1); | ||
120 | |||
121 | =head1 BUGS | ||
122 | |||
123 | OBJ_obj2txt() is awkward and messy to use: it doesn't follow the | ||
124 | convention of other OpenSSL functions where the buffer can be set | ||
125 | to B<NULL> to determine the amount of data that should be written. | ||
126 | Instead B<buf> must point to a valid buffer and B<buf_len> should | ||
127 | be set to a positive value. A buffer length of 80 should be more | ||
128 | than enough to handle any OID encountered in practice. | ||
129 | |||
130 | =head1 RETURN VALUES | ||
131 | |||
132 | OBJ_nid2obj() returns an B<ASN1_OBJECT> structure or B<NULL> is an | ||
133 | error occurred. | ||
134 | |||
135 | OBJ_nid2ln() and OBJ_nid2sn() returns a valid string or B<NULL> | ||
136 | on error. | ||
137 | |||
138 | OBJ_obj2nid(), OBJ_ln2nid(), OBJ_sn2nid() and OBJ_txt2nid() return | ||
139 | a NID or B<NID_undef> on error. | ||
140 | |||
141 | =head1 SEE ALSO | ||
142 | |||
143 | L<ERR_get_error(3)|ERR_get_error(3)> | ||
144 | |||
145 | =head1 HISTORY | ||
146 | |||
147 | TBA | ||
148 | |||
149 | =cut | ||
diff --git a/src/lib/libcrypto/doc/PKCS12_create.pod b/src/lib/libcrypto/doc/PKCS12_create.pod new file mode 100644 index 0000000000..48f3bb8cb8 --- /dev/null +++ b/src/lib/libcrypto/doc/PKCS12_create.pod | |||
@@ -0,0 +1,57 @@ | |||
1 | =pod | ||
2 | |||
3 | =head1 NAME | ||
4 | |||
5 | PKCS12_create - create a PKCS#12 structure | ||
6 | |||
7 | =head1 SYNOPSIS | ||
8 | |||
9 | #include <openssl/pkcs12.h> | ||
10 | |||
11 | PKCS12 *PKCS12_create(char *pass, char *name, EVP_PKEY *pkey, X509 *cert, STACK_OF(X509) *ca, | ||
12 | int nid_key, int nid_cert, int iter, int mac_iter, int keytype); | ||
13 | |||
14 | =head1 DESCRIPTION | ||
15 | |||
16 | PKCS12_create() creates a PKCS#12 structure. | ||
17 | |||
18 | B<pass> is the passphrase to use. B<name> is the B<friendlyName> to use for | ||
19 | the supplied certifictate and key. B<pkey> is the private key to include in | ||
20 | the structure and B<cert> its corresponding certificates. B<ca>, if not B<NULL> | ||
21 | is an optional set of certificates to also include in the structure. | ||
22 | |||
23 | B<nid_key> and B<nid_cert> are the encryption algorithms that should be used | ||
24 | for the key and certificate respectively. B<iter> is the encryption algorithm | ||
25 | iteration count to use and B<mac_iter> is the MAC iteration count to use. | ||
26 | B<keytype> is the type of key. | ||
27 | |||
28 | =head1 NOTES | ||
29 | |||
30 | The parameters B<nid_key>, B<nid_cert>, B<iter>, B<mac_iter> and B<keytype> | ||
31 | can all be set to zero and sensible defaults will be used. | ||
32 | |||
33 | These defaults are: 40 bit RC2 encryption for certificates, triple DES | ||
34 | encryption for private keys, a key iteration count of PKCS12_DEFAULT_ITER | ||
35 | (currently 2048) and a MAC iteration count of 1. | ||
36 | |||
37 | The default MAC iteration count is 1 in order to retain compatibility with | ||
38 | old software which did not interpret MAC iteration counts. If such compatibility | ||
39 | is not required then B<mac_iter> should be set to PKCS12_DEFAULT_ITER. | ||
40 | |||
41 | B<keytype> adds a flag to the store private key. This is a non standard extension | ||
42 | that is only currently interpreted by MSIE. If set to zero the flag is omitted, | ||
43 | if set to B<KEY_SIG> the key can be used for signing only, if set to B<KEY_EX> | ||
44 | it can be used for signing and encryption. This option was useful for old | ||
45 | export grade software which could use signing only keys of arbitrary size but | ||
46 | had restrictions on the permissible sizes of keys which could be used for | ||
47 | encryption. | ||
48 | |||
49 | =head1 SEE ALSO | ||
50 | |||
51 | L<d2i_PKCS12(3)|d2i_PKCS12(3)> | ||
52 | |||
53 | =head1 HISTORY | ||
54 | |||
55 | PKCS12_create was added in OpenSSL 0.9.3 | ||
56 | |||
57 | =cut | ||
diff --git a/src/lib/libcrypto/doc/PKCS12_parse.pod b/src/lib/libcrypto/doc/PKCS12_parse.pod new file mode 100644 index 0000000000..51344f883a --- /dev/null +++ b/src/lib/libcrypto/doc/PKCS12_parse.pod | |||
@@ -0,0 +1,50 @@ | |||
1 | =pod | ||
2 | |||
3 | =head1 NAME | ||
4 | |||
5 | PKCS12_parse - parse a PKCS#12 structure | ||
6 | |||
7 | =head1 SYNOPSIS | ||
8 | |||
9 | #include <openssl/pkcs12.h> | ||
10 | |||
11 | int PKCS12_parse(PKCS12 *p12, const char *pass, EVP_PKEY **pkey, X509 **cert, STACK_OF(X509) **ca); | ||
12 | |||
13 | =head1 DESCRIPTION | ||
14 | |||
15 | PKCS12_parse() parses a PKCS12 structure. | ||
16 | |||
17 | B<p12> is the B<PKCS12> structure to parse. B<pass> is the passphrase to use. | ||
18 | If successful the private key will be written to B<*pkey>, the corresponding | ||
19 | certificate to B<*cert> and any additional certificates to B<*ca>. | ||
20 | |||
21 | =head1 NOTES | ||
22 | |||
23 | The parameters B<pkey> and B<cert> cannot be B<NULL>. B<ca> can be <NULL> | ||
24 | in which case additional certificates will be discarded. B<*ca> can also | ||
25 | be a valid STACK in which case additional certificates are appended to | ||
26 | B<*ca>. If B<*ca> is B<NULL> a new STACK will be allocated. | ||
27 | |||
28 | The B<friendlyName> and B<localKeyID> attributes (if present) on each certificate | ||
29 | will be stored in the B<alias> and B<keyid> attributes of the B<X509> structure. | ||
30 | |||
31 | =head1 BUGS | ||
32 | |||
33 | Only a single private key and corresponding certificate is returned by this function. | ||
34 | More complex PKCS#12 files with multiple private keys will only return the first | ||
35 | match. | ||
36 | |||
37 | Only B<friendlyName> and B<localKeyID> attributes are currently stored in certificates. | ||
38 | Other attributes are discarded. | ||
39 | |||
40 | Attributes currently cannot be store in the private key B<EVP_PKEY> structure. | ||
41 | |||
42 | =head1 SEE ALSO | ||
43 | |||
44 | L<d2i_PKCS12(3)|d2i_PKCS12(3)> | ||
45 | |||
46 | =head1 HISTORY | ||
47 | |||
48 | PKCS12_parse was added in OpenSSL 0.9.3 | ||
49 | |||
50 | =cut | ||
diff --git a/src/lib/libcrypto/doc/PKCS7_decrypt.pod b/src/lib/libcrypto/doc/PKCS7_decrypt.pod new file mode 100644 index 0000000000..b0ca067b89 --- /dev/null +++ b/src/lib/libcrypto/doc/PKCS7_decrypt.pod | |||
@@ -0,0 +1,53 @@ | |||
1 | =pod | ||
2 | |||
3 | =head1 NAME | ||
4 | |||
5 | PKCS7_decrypt - decrypt content from a PKCS#7 envelopedData structure | ||
6 | |||
7 | =head1 SYNOPSIS | ||
8 | |||
9 | int PKCS7_decrypt(PKCS7 *p7, EVP_PKEY *pkey, X509 *cert, BIO *data, int flags); | ||
10 | |||
11 | =head1 DESCRIPTION | ||
12 | |||
13 | PKCS7_decrypt() extracts and decrypts the content from a PKCS#7 envelopedData | ||
14 | structure. B<pkey> is the private key of the recipient, B<cert> is the | ||
15 | recipients certificate, B<data> is a BIO to write the content to and | ||
16 | B<flags> is an optional set of flags. | ||
17 | |||
18 | =head1 NOTES | ||
19 | |||
20 | OpenSSL_add_all_algorithms() (or equivalent) should be called before using this | ||
21 | function or errors about unknown algorithms will occur. | ||
22 | |||
23 | Although the recipients certificate is not needed to decrypt the data it is needed | ||
24 | to locate the appropriate (of possible several) recipients in the PKCS#7 structure. | ||
25 | |||
26 | The following flags can be passed in the B<flags> parameter. | ||
27 | |||
28 | If the B<PKCS7_TEXT> flag is set MIME headers for type B<text/plain> are deleted | ||
29 | from the content. If the content is not of type B<text/plain> then an error is | ||
30 | returned. | ||
31 | |||
32 | =head1 RETURN VALUES | ||
33 | |||
34 | PKCS7_decrypt() returns either 1 for success or 0 for failure. | ||
35 | The error can be obtained from ERR_get_error(3) | ||
36 | |||
37 | =head1 BUGS | ||
38 | |||
39 | PKCS7_decrypt() must be passed the correct recipient key and certificate. It would | ||
40 | be better if it could look up the correct key and certificate from a database. | ||
41 | |||
42 | The lack of single pass processing and need to hold all data in memory as | ||
43 | mentioned in PKCS7_sign() also applies to PKCS7_verify(). | ||
44 | |||
45 | =head1 SEE ALSO | ||
46 | |||
47 | L<ERR_get_error(3)|ERR_get_error(3)>, L<PKCS7_encrypt(3)|PKCS7_encrypt(3)> | ||
48 | |||
49 | =head1 HISTORY | ||
50 | |||
51 | PKCS7_decrypt() was added to OpenSSL 0.9.5 | ||
52 | |||
53 | =cut | ||
diff --git a/src/lib/libcrypto/doc/PKCS7_encrypt.pod b/src/lib/libcrypto/doc/PKCS7_encrypt.pod new file mode 100644 index 0000000000..1a507b22a2 --- /dev/null +++ b/src/lib/libcrypto/doc/PKCS7_encrypt.pod | |||
@@ -0,0 +1,65 @@ | |||
1 | =pod | ||
2 | |||
3 | =head1 NAME | ||
4 | |||
5 | PKCS7_encrypt - create a PKCS#7 envelopedData structure | ||
6 | |||
7 | =head1 SYNOPSIS | ||
8 | |||
9 | PKCS7 *PKCS7_encrypt(STACK_OF(X509) *certs, BIO *in, const EVP_CIPHER *cipher, int flags); | ||
10 | |||
11 | =head1 DESCRIPTION | ||
12 | |||
13 | PKCS7_encrypt() creates and returns a PKCS#7 envelopedData structure. B<certs> | ||
14 | is a list of recipient certificates. B<in> is the content to be encrypted. | ||
15 | B<cipher> is the symmetric cipher to use. B<flags> is an optional set of flags. | ||
16 | |||
17 | =head1 NOTES | ||
18 | |||
19 | Only RSA keys are supported in PKCS#7 and envelopedData so the recipient certificates | ||
20 | supplied to this function must all contain RSA public keys, though they do not have to | ||
21 | be signed using the RSA algorithm. | ||
22 | |||
23 | EVP_des_ede3_cbc() (triple DES) is the algorithm of choice for S/MIME use because | ||
24 | most clients will support it. | ||
25 | |||
26 | Some old "export grade" clients may only support weak encryption using 40 or 64 bit | ||
27 | RC2. These can be used by passing EVP_rc2_40_cbc() and EVP_rc2_64_cbc() respectively. | ||
28 | |||
29 | The algorithm passed in the B<cipher> parameter must support ASN1 encoding of its | ||
30 | parameters. | ||
31 | |||
32 | Many browsers implement a "sign and encrypt" option which is simply an S/MIME | ||
33 | envelopedData containing an S/MIME signed message. This can be readily produced | ||
34 | by storing the S/MIME signed message in a memory BIO and passing it to | ||
35 | PKCS7_encrypt(). | ||
36 | |||
37 | The following flags can be passed in the B<flags> parameter. | ||
38 | |||
39 | If the B<PKCS7_TEXT> flag is set MIME headers for type B<text/plain> are prepended | ||
40 | to the data. | ||
41 | |||
42 | Normally the supplied content is translated into MIME canonical format (as required | ||
43 | by the S/MIME specifications) if B<PKCS7_BINARY> is set no translation occurs. This | ||
44 | option should be used if the supplied data is in binary format otherwise the translation | ||
45 | will corrupt it. If B<PKCS7_BINARY> is set then B<PKCS7_TEXT> is ignored. | ||
46 | |||
47 | =head1 RETURN VALUES | ||
48 | |||
49 | PKCS7_encrypt() returns either a valid PKCS7 structure or NULL if an error occurred. | ||
50 | The error can be obtained from ERR_get_error(3). | ||
51 | |||
52 | =head1 BUGS | ||
53 | |||
54 | The lack of single pass processing and need to hold all data in memory as | ||
55 | mentioned in PKCS7_sign() also applies to PKCS7_verify(). | ||
56 | |||
57 | =head1 SEE ALSO | ||
58 | |||
59 | L<ERR_get_error(3)|ERR_get_error(3)>, L<PKCS7_decrypt(3)|PKCS7_decrypt(3)> | ||
60 | |||
61 | =head1 HISTORY | ||
62 | |||
63 | PKCS7_decrypt() was added to OpenSSL 0.9.5 | ||
64 | |||
65 | =cut | ||
diff --git a/src/lib/libcrypto/doc/PKCS7_sign.pod b/src/lib/libcrypto/doc/PKCS7_sign.pod new file mode 100644 index 0000000000..fc7e649b34 --- /dev/null +++ b/src/lib/libcrypto/doc/PKCS7_sign.pod | |||
@@ -0,0 +1,85 @@ | |||
1 | =pod | ||
2 | |||
3 | =head1 NAME | ||
4 | |||
5 | PKCS7_sign - create a PKCS#7 signedData structure | ||
6 | |||
7 | =head1 SYNOPSIS | ||
8 | |||
9 | PKCS7 *PKCS7_sign(X509 *signcert, EVP_PKEY *pkey, STACK_OF(X509) *certs, BIO *data, int flags); | ||
10 | |||
11 | =head1 DESCRIPTION | ||
12 | |||
13 | PKCS7_sign() creates and returns a PKCS#7 signedData structure. B<signcert> | ||
14 | is the certificate to sign with, B<pkey> is the corresponsding private key. | ||
15 | B<certs> is an optional additional set of certificates to include in the | ||
16 | PKCS#7 structure (for example any intermediate CAs in the chain). | ||
17 | |||
18 | The data to be signed is read from BIO B<data>. | ||
19 | |||
20 | B<flags> is an optional set of flags. | ||
21 | |||
22 | =head1 NOTES | ||
23 | |||
24 | Any of the following flags (ored together) can be passed in the B<flags> parameter. | ||
25 | |||
26 | Many S/MIME clients expect the signed content to include valid MIME headers. If | ||
27 | the B<PKCS7_TEXT> flag is set MIME headers for type B<text/plain> are prepended | ||
28 | to the data. | ||
29 | |||
30 | If B<PKCS7_NOCERTS> is set the signer's certificate will not be included in the | ||
31 | PKCS7 structure, the signer's certificate must still be supplied in the B<signcert> | ||
32 | parameter though. This can reduce the size of the signature if the signers certificate | ||
33 | can be obtained by other means: for example a previously signed message. | ||
34 | |||
35 | The data being signed is included in the PKCS7 structure, unless B<PKCS7_DETACHED> | ||
36 | is set in which case it is omitted. This is used for PKCS7 detached signatures | ||
37 | which are used in S/MIME plaintext signed messages for example. | ||
38 | |||
39 | Normally the supplied content is translated into MIME canonical format (as required | ||
40 | by the S/MIME specifications) if B<PKCS7_BINARY> is set no translation occurs. This | ||
41 | option should be used if the supplied data is in binary format otherwise the translation | ||
42 | will corrupt it. | ||
43 | |||
44 | The signedData structure includes several PKCS#7 autenticatedAttributes including | ||
45 | the signing time, the PKCS#7 content type and the supported list of ciphers in | ||
46 | an SMIMECapabilities attribute. If B<PKCS7_NOATTR> is set then no authenticatedAttributes | ||
47 | will be used. If B<PKCS7_NOSMIMECAP> is set then just the SMIMECapabilities are | ||
48 | omitted. | ||
49 | |||
50 | If present the SMIMECapabilities attribute indicates support for the following | ||
51 | algorithms: triple DES, 128 bit RC2, 64 bit RC2, DES and 40 bit RC2. If any | ||
52 | of these algorithms is disabled then it will not be included. | ||
53 | |||
54 | =head1 BUGS | ||
55 | |||
56 | PKCS7_sign() is somewhat limited. It does not support multiple signers, some | ||
57 | advanced attributes such as counter signatures are not supported. | ||
58 | |||
59 | The SHA1 digest algorithm is currently always used. | ||
60 | |||
61 | When the signed data is not detached it will be stored in memory within the | ||
62 | B<PKCS7> structure. This effectively limits the size of messages which can be | ||
63 | signed due to memory restraints. There should be a way to sign data without | ||
64 | having to hold it all in memory, this would however require fairly major | ||
65 | revisions of the OpenSSL ASN1 code. | ||
66 | |||
67 | Clear text signing does not store the content in memory but the way PKCS7_sign() | ||
68 | operates means that two passes of the data must typically be made: one to compute | ||
69 | the signatures and a second to output the data along with the signature. There | ||
70 | should be a way to process the data with only a single pass. | ||
71 | |||
72 | =head1 RETURN VALUES | ||
73 | |||
74 | PKCS7_sign() returns either a valid PKCS7 structure or NULL if an error occurred. | ||
75 | The error can be obtained from ERR_get_error(3). | ||
76 | |||
77 | =head1 SEE ALSO | ||
78 | |||
79 | L<ERR_get_error(3)|ERR_get_error(3)>, L<PKCS7_verify(3)|PKCS7_verify(3)> | ||
80 | |||
81 | =head1 HISTORY | ||
82 | |||
83 | PKCS7_sign() was added to OpenSSL 0.9.5 | ||
84 | |||
85 | =cut | ||
diff --git a/src/lib/libcrypto/doc/PKCS7_verify.pod b/src/lib/libcrypto/doc/PKCS7_verify.pod new file mode 100644 index 0000000000..07c9fdad40 --- /dev/null +++ b/src/lib/libcrypto/doc/PKCS7_verify.pod | |||
@@ -0,0 +1,116 @@ | |||
1 | =pod | ||
2 | |||
3 | =head1 NAME | ||
4 | |||
5 | PKCS7_verify - verify a PKCS#7 signedData structure | ||
6 | |||
7 | =head1 SYNOPSIS | ||
8 | |||
9 | int PKCS7_verify(PKCS7 *p7, STACK_OF(X509) *certs, X509_STORE *store, BIO *indata, BIO *out, int flags); | ||
10 | |||
11 | int PKCS7_get0_signers(PKCS7 *p7, STACK_OF(X509) *certs, int flags); | ||
12 | |||
13 | =head1 DESCRIPTION | ||
14 | |||
15 | PKCS7_verify() verifies a PKCS#7 signedData structure. B<p7> is the PKCS7 | ||
16 | structure to verify. B<certs> is a set of certificates in which to search for | ||
17 | the signer's certificate. B<store> is a trusted certficate store (used for | ||
18 | chain verification). B<indata> is the signed data if the content is not | ||
19 | present in B<p7> (that is it is detached). The content is written to B<out> | ||
20 | if it is not NULL. | ||
21 | |||
22 | B<flags> is an optional set of flags, which can be used to modify the verify | ||
23 | operation. | ||
24 | |||
25 | PKCS7_get0_signers() retrieves the signer's certificates from B<p7>, it does | ||
26 | B<not> check their validity or whether any signatures are valid. The B<certs> | ||
27 | and B<flags> parameters have the same meanings as in PKCS7_verify(). | ||
28 | |||
29 | =head1 VERIFY PROCESS | ||
30 | |||
31 | Normally the verify process proceeds as follows. | ||
32 | |||
33 | Initially some sanity checks are performed on B<p7>. The type of B<p7> must | ||
34 | be signedData. There must be at least one signature on the data and if | ||
35 | the content is detached B<indata> cannot be B<NULL>. | ||
36 | |||
37 | An attempt is made to locate all the signer's certificates, first looking in | ||
38 | the B<certs> parameter (if it is not B<NULL>) and then looking in any certificates | ||
39 | contained in the B<p7> structure itself. If any signer's certificates cannot be | ||
40 | located the operation fails. | ||
41 | |||
42 | Each signer's certificate is chain verified using the B<smimesign> purpose and | ||
43 | the supplied trusted certificate store. Any internal certificates in the message | ||
44 | are used as untrusted CAs. If any chain verify fails an error code is returned. | ||
45 | |||
46 | Finally the signed content is read (and written to B<out> is it is not NULL) and | ||
47 | the signature's checked. | ||
48 | |||
49 | If all signature's verify correctly then the function is successful. | ||
50 | |||
51 | Any of the following flags (ored together) can be passed in the B<flags> parameter | ||
52 | to change the default verify behaviour. Only the flag B<PKCS7_NOINTERN> is | ||
53 | meaningful to PKCS7_get0_signers(). | ||
54 | |||
55 | If B<PKCS7_NOINTERN> is set the certificates in the message itself are not | ||
56 | searched when locating the signer's certificate. This means that all the signers | ||
57 | certificates must be in the B<certs> parameter. | ||
58 | |||
59 | If the B<PKCS7_TEXT> flag is set MIME headers for type B<text/plain> are deleted | ||
60 | from the content. If the content is not of type B<text/plain> then an error is | ||
61 | returned. | ||
62 | |||
63 | If B<PKCS7_NOVERIFY> is set the signer's certificates are not chain verified. | ||
64 | |||
65 | If B<PKCS7_NOCHAIN> is set then the certificates contained in the message are | ||
66 | not used as untrusted CAs. This means that the whole verify chain (apart from | ||
67 | the signer's certificate) must be contained in the trusted store. | ||
68 | |||
69 | If B<PKCS7_NOSIGS> is set then the signatures on the data are not checked. | ||
70 | |||
71 | =head1 NOTES | ||
72 | |||
73 | One application of B<PKCS7_NOINTERN> is to only accept messages signed by | ||
74 | a small number of certificates. The acceptable certificates would be passed | ||
75 | in the B<certs> parameter. In this case if the signer is not one of the | ||
76 | certificates supplied in B<certs> then the verify will fail because the | ||
77 | signer cannot be found. | ||
78 | |||
79 | Care should be taken when modifying the default verify behaviour, for example | ||
80 | setting B<PKCS7_NOVERIFY|PKCS7_NOSIGS> will totally disable all verification | ||
81 | and any signed message will be considered valid. This combination is however | ||
82 | useful if one merely wishes to write the content to B<out> and its validity | ||
83 | is not considered important. | ||
84 | |||
85 | Chain verification should arguably be performed using the signing time rather | ||
86 | than the current time. However since the signing time is supplied by the | ||
87 | signer it cannot be trusted without additional evidence (such as a trusted | ||
88 | timestamp). | ||
89 | |||
90 | =head1 RETURN VALUES | ||
91 | |||
92 | PKCS7_verify() returns 1 for a successful verification and zero or a negative | ||
93 | value if an error occurs. | ||
94 | |||
95 | PKCS7_get0_signers() returns all signers or B<NULL> if an error occurred. | ||
96 | |||
97 | The error can be obtained from L<ERR_get_error(3)|ERR_get_error(3)> | ||
98 | |||
99 | =head1 BUGS | ||
100 | |||
101 | The trusted certificate store is not searched for the signers certificate, | ||
102 | this is primarily due to the inadequacies of the current B<X509_STORE> | ||
103 | functionality. | ||
104 | |||
105 | The lack of single pass processing and need to hold all data in memory as | ||
106 | mentioned in PKCS7_sign() also applies to PKCS7_verify(). | ||
107 | |||
108 | =head1 SEE ALSO | ||
109 | |||
110 | L<ERR_get_error(3)|ERR_get_error(3)>, L<PKCS7_sign(3)|PKCS7_sign(3)> | ||
111 | |||
112 | =head1 HISTORY | ||
113 | |||
114 | PKCS7_verify() was added to OpenSSL 0.9.5 | ||
115 | |||
116 | =cut | ||
diff --git a/src/lib/libcrypto/doc/RAND_bytes.pod b/src/lib/libcrypto/doc/RAND_bytes.pod index b6ebd50527..ce6329ce54 100644 --- a/src/lib/libcrypto/doc/RAND_bytes.pod +++ b/src/lib/libcrypto/doc/RAND_bytes.pod | |||
@@ -35,7 +35,8 @@ method. | |||
35 | 35 | ||
36 | =head1 SEE ALSO | 36 | =head1 SEE ALSO |
37 | 37 | ||
38 | L<rand(3)|rand(3)>, L<err(3)|err(3)>, L<RAND_add(3)|RAND_add(3)> | 38 | L<rand(3)|rand(3)>, L<ERR_get_error(3)|ERR_get_error(3)>, |
39 | L<RAND_add(3)|RAND_add(3)> | ||
39 | 40 | ||
40 | =head1 HISTORY | 41 | =head1 HISTORY |
41 | 42 | ||
diff --git a/src/lib/libcrypto/doc/RSA_check_key.pod b/src/lib/libcrypto/doc/RSA_check_key.pod index 3d824a07f5..a5198f3db5 100644 --- a/src/lib/libcrypto/doc/RSA_check_key.pod +++ b/src/lib/libcrypto/doc/RSA_check_key.pod | |||
@@ -58,7 +58,7 @@ provide their own verifiers. | |||
58 | 58 | ||
59 | =head1 SEE ALSO | 59 | =head1 SEE ALSO |
60 | 60 | ||
61 | L<rsa(3)|rsa(3)>, L<err(3)|err(3)> | 61 | L<rsa(3)|rsa(3)>, L<ERR_get_error(3)|ERR_get_error(3)> |
62 | 62 | ||
63 | =head1 HISTORY | 63 | =head1 HISTORY |
64 | 64 | ||
diff --git a/src/lib/libcrypto/doc/RSA_generate_key.pod b/src/lib/libcrypto/doc/RSA_generate_key.pod index 8714f7179d..52dbb14a53 100644 --- a/src/lib/libcrypto/doc/RSA_generate_key.pod +++ b/src/lib/libcrypto/doc/RSA_generate_key.pod | |||
@@ -59,7 +59,8 @@ RSA_generate_key() goes into an infinite loop for illegal input values. | |||
59 | 59 | ||
60 | =head1 SEE ALSO | 60 | =head1 SEE ALSO |
61 | 61 | ||
62 | L<err(3)|err(3)>, L<rand(3)|rand(3)>, L<rsa(3)|rsa(3)>, L<RSA_free(3)|RSA_free(3)> | 62 | L<ERR_get_error(3)|ERR_get_error(3)>, L<rand(3)|rand(3)>, L<rsa(3)|rsa(3)>, |
63 | L<RSA_free(3)|RSA_free(3)> | ||
63 | 64 | ||
64 | =head1 HISTORY | 65 | =head1 HISTORY |
65 | 66 | ||
diff --git a/src/lib/libcrypto/doc/RSA_new.pod b/src/lib/libcrypto/doc/RSA_new.pod index f0d996c40f..3d15b92824 100644 --- a/src/lib/libcrypto/doc/RSA_new.pod +++ b/src/lib/libcrypto/doc/RSA_new.pod | |||
@@ -30,7 +30,8 @@ RSA_free() returns no value. | |||
30 | 30 | ||
31 | =head1 SEE ALSO | 31 | =head1 SEE ALSO |
32 | 32 | ||
33 | L<err(3)|err(3)>, L<rsa(3)|rsa(3)>, L<RSA_generate_key(3)|RSA_generate_key(3)>, | 33 | L<ERR_get_error(3)|ERR_get_error(3)>, L<rsa(3)|rsa(3)>, |
34 | L<RSA_generate_key(3)|RSA_generate_key(3)>, | ||
34 | L<RSA_new_method(3)|RSA_new_method(3)> | 35 | L<RSA_new_method(3)|RSA_new_method(3)> |
35 | 36 | ||
36 | =head1 HISTORY | 37 | =head1 HISTORY |
diff --git a/src/lib/libcrypto/doc/RSA_print.pod b/src/lib/libcrypto/doc/RSA_print.pod index 67876facc5..e28d107d1c 100644 --- a/src/lib/libcrypto/doc/RSA_print.pod +++ b/src/lib/libcrypto/doc/RSA_print.pod | |||
@@ -2,9 +2,9 @@ | |||
2 | 2 | ||
3 | =head1 NAME | 3 | =head1 NAME |
4 | 4 | ||
5 | RSA_print, RSA_print_fp, DHparams_print, DHparams_print_fp, DSA_print, | 5 | RSA_print, RSA_print_fp, |
6 | DSA_print_fp, DHparams_print, DHparams_print_fp - print cryptographic | 6 | DSAparams_print, DSAparams_print_fp, DSA_print, DSA_print_fp, |
7 | parameters | 7 | DHparams_print, DHparams_print_fp - print cryptographic parameters |
8 | 8 | ||
9 | =head1 SYNOPSIS | 9 | =head1 SYNOPSIS |
10 | 10 | ||
diff --git a/src/lib/libcrypto/doc/RSA_private_encrypt.pod b/src/lib/libcrypto/doc/RSA_private_encrypt.pod index 6861a98a10..746a80c79e 100644 --- a/src/lib/libcrypto/doc/RSA_private_encrypt.pod +++ b/src/lib/libcrypto/doc/RSA_private_encrypt.pod | |||
@@ -59,7 +59,8 @@ obtained by L<ERR_get_error(3)|ERR_get_error(3)>. | |||
59 | 59 | ||
60 | =head1 SEE ALSO | 60 | =head1 SEE ALSO |
61 | 61 | ||
62 | L<err(3)|err(3)>, L<rsa(3)|rsa(3)>, L<RSA_sign(3)|RSA_sign(3)>, L<RSA_verify(3)|RSA_verify(3)> | 62 | L<ERR_get_error(3)|ERR_get_error(3)>, L<rsa(3)|rsa(3)>, |
63 | L<RSA_sign(3)|RSA_sign(3)>, L<RSA_verify(3)|RSA_verify(3)> | ||
63 | 64 | ||
64 | =head1 HISTORY | 65 | =head1 HISTORY |
65 | 66 | ||
diff --git a/src/lib/libcrypto/doc/RSA_public_encrypt.pod b/src/lib/libcrypto/doc/RSA_public_encrypt.pod index e20dfcb551..d53e19d2b7 100644 --- a/src/lib/libcrypto/doc/RSA_public_encrypt.pod +++ b/src/lib/libcrypto/doc/RSA_public_encrypt.pod | |||
@@ -72,7 +72,8 @@ SSL, PKCS #1 v2.0 | |||
72 | 72 | ||
73 | =head1 SEE ALSO | 73 | =head1 SEE ALSO |
74 | 74 | ||
75 | L<err(3)|err(3)>, L<rand(3)|rand(3)>, L<rsa(3)|rsa(3)>, L<RSA_size(3)|RSA_size(3)> | 75 | L<ERR_get_error(3)|ERR_get_error(3)>, L<rand(3)|rand(3)>, L<rsa(3)|rsa(3)>, |
76 | L<RSA_size(3)|RSA_size(3)> | ||
76 | 77 | ||
77 | =head1 HISTORY | 78 | =head1 HISTORY |
78 | 79 | ||
diff --git a/src/lib/libcrypto/doc/RSA_set_method.pod b/src/lib/libcrypto/doc/RSA_set_method.pod index 0687c2242a..0a305f6b14 100644 --- a/src/lib/libcrypto/doc/RSA_set_method.pod +++ b/src/lib/libcrypto/doc/RSA_set_method.pod | |||
@@ -3,13 +3,12 @@ | |||
3 | =head1 NAME | 3 | =head1 NAME |
4 | 4 | ||
5 | RSA_set_default_method, RSA_get_default_method, RSA_set_method, | 5 | RSA_set_default_method, RSA_get_default_method, RSA_set_method, |
6 | RSA_get_method, RSA_PKCS1_SSLeay, | 6 | RSA_get_method, RSA_PKCS1_SSLeay, RSA_null_method, RSA_flags, |
7 | RSA_null_method, RSA_flags, RSA_new_method - select RSA method | 7 | RSA_new_method - select RSA method |
8 | 8 | ||
9 | =head1 SYNOPSIS | 9 | =head1 SYNOPSIS |
10 | 10 | ||
11 | #include <openssl/rsa.h> | 11 | #include <openssl/rsa.h> |
12 | #include <openssl/engine.h> | ||
13 | 12 | ||
14 | void RSA_set_default_method(const RSA_METHOD *meth); | 13 | void RSA_set_default_method(const RSA_METHOD *meth); |
15 | 14 | ||
@@ -25,7 +24,7 @@ RSA_null_method, RSA_flags, RSA_new_method - select RSA method | |||
25 | 24 | ||
26 | int RSA_flags(const RSA *rsa); | 25 | int RSA_flags(const RSA *rsa); |
27 | 26 | ||
28 | RSA *RSA_new_method(ENGINE *engine); | 27 | RSA *RSA_new_method(RSA_METHOD *method); |
29 | 28 | ||
30 | =head1 DESCRIPTION | 29 | =head1 DESCRIPTION |
31 | 30 | ||
@@ -70,6 +69,12 @@ B<engine> will be used for the RSA operations. If B<engine> is NULL, the | |||
70 | default ENGINE for RSA operations is used, and if no default ENGINE is set, | 69 | default ENGINE for RSA operations is used, and if no default ENGINE is set, |
71 | the RSA_METHOD controlled by RSA_set_default_method() is used. | 70 | the RSA_METHOD controlled by RSA_set_default_method() is used. |
72 | 71 | ||
72 | RSA_flags() returns the B<flags> that are set for B<rsa>'s current method. | ||
73 | |||
74 | RSA_new_method() allocates and initializes an B<RSA> structure so that | ||
75 | B<method> will be used for the RSA operations. If B<method> is B<NULL>, | ||
76 | the default method is used. | ||
77 | |||
73 | =head1 THE RSA_METHOD STRUCTURE | 78 | =head1 THE RSA_METHOD STRUCTURE |
74 | 79 | ||
75 | typedef struct rsa_meth_st | 80 | typedef struct rsa_meth_st |
diff --git a/src/lib/libcrypto/doc/RSA_sign.pod b/src/lib/libcrypto/doc/RSA_sign.pod index f0bf6eea1b..71688a665e 100644 --- a/src/lib/libcrypto/doc/RSA_sign.pod +++ b/src/lib/libcrypto/doc/RSA_sign.pod | |||
@@ -50,8 +50,8 @@ SSL, PKCS #1 v2.0 | |||
50 | 50 | ||
51 | =head1 SEE ALSO | 51 | =head1 SEE ALSO |
52 | 52 | ||
53 | L<err(3)|err(3)>, L<objects(3)|objects(3)>, L<rsa(3)|rsa(3)>, | 53 | L<ERR_get_error(3)|ERR_get_error(3)>, L<objects(3)|objects(3)>, |
54 | L<RSA_private_encrypt(3)|RSA_private_encrypt(3)>, | 54 | L<rsa(3)|rsa(3)>, L<RSA_private_encrypt(3)|RSA_private_encrypt(3)>, |
55 | L<RSA_public_decrypt(3)|RSA_public_decrypt(3)> | 55 | L<RSA_public_decrypt(3)|RSA_public_decrypt(3)> |
56 | 56 | ||
57 | =head1 HISTORY | 57 | =head1 HISTORY |
diff --git a/src/lib/libcrypto/doc/RSA_sign_ASN1_OCTET_STRING.pod b/src/lib/libcrypto/doc/RSA_sign_ASN1_OCTET_STRING.pod index df9ceb339a..e70380bbfc 100644 --- a/src/lib/libcrypto/doc/RSA_sign_ASN1_OCTET_STRING.pod +++ b/src/lib/libcrypto/doc/RSA_sign_ASN1_OCTET_STRING.pod | |||
@@ -47,8 +47,8 @@ These functions serve no recognizable purpose. | |||
47 | 47 | ||
48 | =head1 SEE ALSO | 48 | =head1 SEE ALSO |
49 | 49 | ||
50 | L<err(3)|err(3)>, L<objects(3)|objects(3)>, L<rand(3)|rand(3)>, | 50 | L<ERR_get_error(3)|ERR_get_error(3)>, L<objects(3)|objects(3)>, |
51 | L<rsa(3)|rsa(3)>, L<RSA_sign(3)|RSA_sign(3)>, | 51 | L<rand(3)|rand(3)>, L<rsa(3)|rsa(3)>, L<RSA_sign(3)|RSA_sign(3)>, |
52 | L<RSA_verify(3)|RSA_verify(3)> | 52 | L<RSA_verify(3)|RSA_verify(3)> |
53 | 53 | ||
54 | =head1 HISTORY | 54 | =head1 HISTORY |
diff --git a/src/lib/libcrypto/doc/SMIME_read_PKCS7.pod b/src/lib/libcrypto/doc/SMIME_read_PKCS7.pod new file mode 100644 index 0000000000..ffafa37887 --- /dev/null +++ b/src/lib/libcrypto/doc/SMIME_read_PKCS7.pod | |||
@@ -0,0 +1,71 @@ | |||
1 | =pod | ||
2 | |||
3 | =head1 NAME | ||
4 | |||
5 | SMIME_read_PKCS7 - parse S/MIME message. | ||
6 | |||
7 | =head1 SYNOPSIS | ||
8 | |||
9 | PKCS7 *SMIME_read_PKCS7(BIO *in, BIO **bcont); | ||
10 | |||
11 | =head1 DESCRIPTION | ||
12 | |||
13 | SMIME_read_PKCS7() parses a message in S/MIME format. | ||
14 | |||
15 | B<in> is a BIO to read the message from. | ||
16 | |||
17 | If cleartext signing is used then the content is saved in | ||
18 | a memory bio which is written to B<*bcont>, otherwise | ||
19 | B<*bcont> is set to B<NULL>. | ||
20 | |||
21 | The parsed PKCS#7 structure is returned or B<NULL> if an | ||
22 | error occurred. | ||
23 | |||
24 | =head1 NOTES | ||
25 | |||
26 | If B<*bcont> is not B<NULL> then the message is clear text | ||
27 | signed. B<*bcont> can then be passed to PKCS7_verify() with | ||
28 | the B<PKCS7_DETACHED> flag set. | ||
29 | |||
30 | Otherwise the type of the returned structure can be determined | ||
31 | using PKCS7_type(). | ||
32 | |||
33 | To support future functionality if B<bcont> is not B<NULL> | ||
34 | B<*bcont> should be initialized to B<NULL>. For example: | ||
35 | |||
36 | BIO *cont = NULL; | ||
37 | PKCS7 *p7; | ||
38 | |||
39 | p7 = SMIME_read_PKCS7(in, &cont); | ||
40 | |||
41 | =head1 BUGS | ||
42 | |||
43 | The MIME parser used by SMIME_read_PKCS7() is somewhat primitive. | ||
44 | While it will handle most S/MIME messages more complex compound | ||
45 | formats may not work. | ||
46 | |||
47 | The parser assumes that the PKCS7 structure is always base64 | ||
48 | encoded and will not handle the case where it is in binary format | ||
49 | or uses quoted printable format. | ||
50 | |||
51 | The use of a memory BIO to hold the signed content limits the size | ||
52 | of message which can be processed due to memory restraints: a | ||
53 | streaming single pass option should be available. | ||
54 | |||
55 | =head1 RETURN VALUES | ||
56 | |||
57 | SMIME_read_PKCS7() returns a valid B<PKCS7> structure or B<NULL> | ||
58 | is an error occurred. The error can be obtained from ERR_get_error(3). | ||
59 | |||
60 | =head1 SEE ALSO | ||
61 | |||
62 | L<ERR_get_error(3)|ERR_get_error(3)>, L<PKCS7_type(3)|PKCS7_type(3)> | ||
63 | L<SMIME_read_PKCS7(3)|SMIME_read_PKCS7(3)>, L<PKCS7_sign(3)|PKCS7_sign(3)>, | ||
64 | L<PKCS7_verify(3)|PKCS7_verify(3)>, L<PKCS7_encrypt(3)|PKCS7_encrypt(3)> | ||
65 | L<PKCS7_decrypt(3)|PKCS7_decrypt(3)> | ||
66 | |||
67 | =head1 HISTORY | ||
68 | |||
69 | SMIME_read_PKCS7() was added to OpenSSL 0.9.5 | ||
70 | |||
71 | =cut | ||
diff --git a/src/lib/libcrypto/doc/SMIME_write_PKCS7.pod b/src/lib/libcrypto/doc/SMIME_write_PKCS7.pod new file mode 100644 index 0000000000..2cfad2e049 --- /dev/null +++ b/src/lib/libcrypto/doc/SMIME_write_PKCS7.pod | |||
@@ -0,0 +1,59 @@ | |||
1 | =pod | ||
2 | |||
3 | =head1 NAME | ||
4 | |||
5 | SMIME_write_PKCS7 - convert PKCS#7 structure to S/MIME format. | ||
6 | |||
7 | =head1 SYNOPSIS | ||
8 | |||
9 | int SMIME_write_PKCS7(BIO *out, PKCS7 *p7, BIO *data, int flags); | ||
10 | |||
11 | =head1 DESCRIPTION | ||
12 | |||
13 | SMIME_write_PKCS7() adds the appropriate MIME headers to a PKCS#7 | ||
14 | structure to produce an S/MIME message. | ||
15 | |||
16 | B<out> is the BIO to write the data to. B<p7> is the appropriate | ||
17 | B<PKCS7> structure. If cleartext signing (B<multipart/signed>) is | ||
18 | being used then the signed data must be supplied in the B<data> | ||
19 | argument. B<flags> is an optional set of flags. | ||
20 | |||
21 | =head1 NOTES | ||
22 | |||
23 | The following flags can be passed in the B<flags> parameter. | ||
24 | |||
25 | If B<PKCS7_DETACHED> is set then cleartext signing will be used, | ||
26 | this option only makes sense for signedData where B<PKCS7_DETACHED> | ||
27 | is also set when PKCS7_sign() is also called. | ||
28 | |||
29 | If the B<PKCS7_TEXT> flag is set MIME headers for type B<text/plain> | ||
30 | are added to the content, this only makes sense if B<PKCS7_DETACHED> | ||
31 | is also set. | ||
32 | |||
33 | If cleartext signing is being used then the data must be read twice: | ||
34 | once to compute the signature in PKCS7_sign() and once to output the | ||
35 | S/MIME message. | ||
36 | |||
37 | =head1 BUGS | ||
38 | |||
39 | SMIME_write_PKCS7() always base64 encodes PKCS#7 structures, there | ||
40 | should be an option to disable this. | ||
41 | |||
42 | There should really be a way to produce cleartext signing using only | ||
43 | a single pass of the data. | ||
44 | |||
45 | =head1 RETURN VALUES | ||
46 | |||
47 | SMIME_write_PKCS7() returns 1 for success or 0 for failure. | ||
48 | |||
49 | =head1 SEE ALSO | ||
50 | |||
51 | L<ERR_get_error(3)|ERR_get_error(3)>, L<PKCS7_sign(3)|PKCS7_sign(3)>, | ||
52 | L<PKCS7_verify(3)|PKCS7_verify(3)>, L<PKCS7_encrypt(3)|PKCS7_encrypt(3)> | ||
53 | L<PKCS7_decrypt(3)|PKCS7_decrypt(3)> | ||
54 | |||
55 | =head1 HISTORY | ||
56 | |||
57 | SMIME_write_PKCS7() was added to OpenSSL 0.9.5 | ||
58 | |||
59 | =cut | ||
diff --git a/src/lib/libcrypto/doc/X509_NAME_ENTRY_get_object.pod b/src/lib/libcrypto/doc/X509_NAME_ENTRY_get_object.pod new file mode 100644 index 0000000000..d287c18564 --- /dev/null +++ b/src/lib/libcrypto/doc/X509_NAME_ENTRY_get_object.pod | |||
@@ -0,0 +1,72 @@ | |||
1 | =pod | ||
2 | |||
3 | =head1 NAME | ||
4 | |||
5 | X509_NAME_ENTRY_get_object, X509_NAME_ENTRY_get_data, | ||
6 | X509_NAME_ENTRY_set_object, X509_NAME_ENTRY_set_data, | ||
7 | X509_NAME_ENTRY_create_by_txt, X509_NAME_ENTRY_create_by_NID, | ||
8 | X509_NAME_ENTRY_create_by_OBJ - X509_NAME_ENTRY utility functions | ||
9 | |||
10 | =head1 SYNOPSIS | ||
11 | |||
12 | ASN1_OBJECT * X509_NAME_ENTRY_get_object(X509_NAME_ENTRY *ne); | ||
13 | ASN1_STRING * X509_NAME_ENTRY_get_data(X509_NAME_ENTRY *ne); | ||
14 | |||
15 | int X509_NAME_ENTRY_set_object(X509_NAME_ENTRY *ne, ASN1_OBJECT *obj); | ||
16 | int X509_NAME_ENTRY_set_data(X509_NAME_ENTRY *ne, int type, unsigned char *bytes, int len); | ||
17 | |||
18 | X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_txt(X509_NAME_ENTRY **ne, char *field, int type, unsigned char *bytes, int len); | ||
19 | X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_NID(X509_NAME_ENTRY **ne, int nid, int type,unsigned char *bytes, int len); | ||
20 | X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_OBJ(X509_NAME_ENTRY **ne, ASN1_OBJECT *obj, int type,unsigned char *bytes, int len); | ||
21 | |||
22 | =head1 DESCRIPTION | ||
23 | |||
24 | X509_NAME_ENTRY_get_object() retrieves the field name of B<ne> in | ||
25 | and B<ASN1_OBJECT> structure. | ||
26 | |||
27 | X509_NAME_ENTRY_get_data() retrieves the field value of B<ne> in | ||
28 | and B<ASN1_STRING> structure. | ||
29 | |||
30 | X509_NAME_ENTRY_set_object() sets the field name of B<ne> to B<obj>. | ||
31 | |||
32 | X509_NAME_ENTRY_set_data() sets the field value of B<ne> to string type | ||
33 | B<type> and value determined by B<bytes> and B<len>. | ||
34 | |||
35 | X509_NAME_ENTRY_create_by_txt(), X509_NAME_ENTRY_create_by_NID() | ||
36 | and X509_NAME_ENTRY_create_by_OBJ() create and return an | ||
37 | B<X509_NAME_ENTRY> structure. | ||
38 | |||
39 | =head1 NOTES | ||
40 | |||
41 | X509_NAME_ENTRY_get_object() and X509_NAME_ENTRY_get_data() can be | ||
42 | used to examine an B<X509_NAME_ENTRY> function as returned by | ||
43 | X509_NAME_get_entry() for example. | ||
44 | |||
45 | X509_NAME_ENTRY_create_by_txt(), X509_NAME_ENTRY_create_by_NID(), | ||
46 | and X509_NAME_ENTRY_create_by_OBJ() create and return an | ||
47 | |||
48 | X509_NAME_ENTRY_create_by_txt(), X509_NAME_ENTRY_create_by_OBJ(), | ||
49 | X509_NAME_ENTRY_create_by_NID() and X509_NAME_ENTRY_set_data() | ||
50 | are seldom used in practice because B<X509_NAME_ENTRY> structures | ||
51 | are almost always part of B<X509_NAME> structures and the | ||
52 | corresponding B<X509_NAME> functions are typically used to | ||
53 | create and add new entries in a single operation. | ||
54 | |||
55 | The arguments of these functions support similar options to the similarly | ||
56 | named ones of the corresponding B<X509_NAME> functions such as | ||
57 | X509_NAME_add_entry_by_txt(). So for example B<type> can be set to | ||
58 | B<MBSTRING_ASC> but in the case of X509_set_data() the field name must be | ||
59 | set first so the relevant field information can be looked up internally. | ||
60 | |||
61 | =head1 RETURN VALUES | ||
62 | |||
63 | =head1 SEE ALSO | ||
64 | |||
65 | L<ERR_get_error(3)|ERR_get_error(3)>, L<d2i_X509_NAME(3)|d2i_X509_NAME(3)>, | ||
66 | L<OBJ_nid2obj(3),OBJ_nid2obj(3)> | ||
67 | |||
68 | =head1 HISTORY | ||
69 | |||
70 | TBA | ||
71 | |||
72 | =cut | ||
diff --git a/src/lib/libcrypto/doc/X509_NAME_add_entry_by_txt.pod b/src/lib/libcrypto/doc/X509_NAME_add_entry_by_txt.pod new file mode 100644 index 0000000000..4472a1c5cf --- /dev/null +++ b/src/lib/libcrypto/doc/X509_NAME_add_entry_by_txt.pod | |||
@@ -0,0 +1,110 @@ | |||
1 | =pod | ||
2 | |||
3 | =head1 NAME | ||
4 | |||
5 | X509_NAME_add_entry_by_txt, X509_NAME_add_entry_by_OBJ, X509_NAME_add_entry_by_NID, | ||
6 | X509_NAME_add_entry, X509_NAME_delete_entry - X509_NAME modification functions | ||
7 | |||
8 | =head1 SYNOPSIS | ||
9 | |||
10 | int X509_NAME_add_entry_by_txt(X509_NAME *name, char *field, int type, unsigned char *bytes, int len, int loc, int set); | ||
11 | int X509_NAME_add_entry_by_OBJ(X509_NAME *name, ASN1_OBJECT *obj, int type, unsigned char *bytes, int len, int loc, int set); | ||
12 | int X509_NAME_add_entry_by_NID(X509_NAME *name, int nid, int type, unsigned char *bytes, int len, int loc, int set); | ||
13 | int X509_NAME_add_entry(X509_NAME *name,X509_NAME_ENTRY *ne, int loc, int set); | ||
14 | X509_NAME_ENTRY *X509_NAME_delete_entry(X509_NAME *name, int loc); | ||
15 | |||
16 | =head1 DESCRIPTION | ||
17 | |||
18 | X509_NAME_add_entry_by_txt(), X509_NAME_add_entry_by_OBJ() and | ||
19 | X509_NAME_add_entry_by_NID() add a field whose name is defined | ||
20 | by a string B<field>, an object B<obj> or a NID B<nid> respectively. | ||
21 | The field value to be added is in B<bytes> of length B<len>. If | ||
22 | B<len> is -1 then the field length is calculated internally using | ||
23 | strlen(bytes). | ||
24 | |||
25 | The type of field is determined by B<type> which can either be a | ||
26 | definition of the type of B<bytes> (such as B<MBSTRING_ASC>) or a | ||
27 | standard ASN1 type (such as B<V_ASN1_IA5STRING>). The new entry is | ||
28 | added to a position determined by B<loc> and B<set>. | ||
29 | |||
30 | X509_NAME_add_entry() adds a copy of B<X509_NAME_ENTRY> structure B<ne> | ||
31 | to B<name>. The new entry is added to a position determined by B<loc> | ||
32 | and B<set>. Since a copy of B<ne> is added B<ne> must be freed up after | ||
33 | the call. | ||
34 | |||
35 | X509_NAME_delete_entry() deletes an entry from B<name> at position | ||
36 | B<loc>. The deleted entry is returned and must be freed up. | ||
37 | |||
38 | =head1 NOTES | ||
39 | |||
40 | The use of string types such as B<MBSTRING_ASC> or B<MBSTRING_UTF8> | ||
41 | is strongly recommened for the B<type> parameter. This allows the | ||
42 | internal code to correctly determine the type of the field and to | ||
43 | apply length checks according to the relevant standards. This is | ||
44 | done using ASN1_STRING_set_by_NID(). | ||
45 | |||
46 | If instead an ASN1 type is used no checks are performed and the | ||
47 | supplied data in B<bytes> is used directly. | ||
48 | |||
49 | In X509_NAME_add_entry_by_txt() the B<field> string represents | ||
50 | the field name using OBJ_txt2obj(field, 0). | ||
51 | |||
52 | The B<loc> and B<set> parameters determine where a new entry should | ||
53 | be added. For almost all applications B<loc> can be set to -1 and B<set> | ||
54 | to 0. This adds a new entry to the end of B<name> as a single valued | ||
55 | RelativeDistinguishedName (RDN). | ||
56 | |||
57 | B<loc> actually determines the index where the new entry is inserted: | ||
58 | if it is -1 it is appended. | ||
59 | |||
60 | B<set> determines how the new type is added. If it is zero a | ||
61 | new RDN is created. | ||
62 | |||
63 | If B<set> is -1 or 1 it is added to the previous or next RDN | ||
64 | structure respectively. This will then be a multivalued RDN: | ||
65 | since multivalues RDNs are very seldom used B<set> is almost | ||
66 | always set to zero. | ||
67 | |||
68 | =head1 EXAMPLES | ||
69 | |||
70 | Create an B<X509_NAME> structure: | ||
71 | |||
72 | "C=UK, O=Disorganized Organization, CN=Joe Bloggs" | ||
73 | |||
74 | X509_NAME *nm; | ||
75 | nm = X509_NAME_new(); | ||
76 | if (nm == NULL) | ||
77 | /* Some error */ | ||
78 | if (!X509_NAME_add_entry_by_txt(nm, MBSTRING_ASC, | ||
79 | "C", "UK", -1, -1, 0)) | ||
80 | /* Error */ | ||
81 | if (!X509_NAME_add_entry_by_txt(nm, MBSTRING_ASC, | ||
82 | "O", "Disorganized Organization", -1, -1, 0)) | ||
83 | /* Error */ | ||
84 | if (!X509_NAME_add_entry_by_txt(nm, MBSTRING_ASC, | ||
85 | "CN", "Joe Bloggs", -1, -1, 0)) | ||
86 | /* Error */ | ||
87 | |||
88 | =head1 RETURN VALUES | ||
89 | |||
90 | X509_NAME_add_entry_by_txt(), X509_NAME_add_entry_by_OBJ(), | ||
91 | X509_NAME_add_entry_by_NID() and X509_NAME_add_entry() return 1 for | ||
92 | success of 0 if an error occurred. | ||
93 | |||
94 | X509_NAME_delete_entry() returns either the deleted B<X509_NAME_ENTRY> | ||
95 | structure of B<NULL> if an error occurred. | ||
96 | |||
97 | =head1 BUGS | ||
98 | |||
99 | B<type> can still be set to B<V_ASN1_APP_CHOOSE> to use a | ||
100 | different algorithm to determine field types. Since this form does | ||
101 | not understand multicharacter types, performs no length checks and | ||
102 | can result in invalid field types its use is strongly discouraged. | ||
103 | |||
104 | =head1 SEE ALSO | ||
105 | |||
106 | L<ERR_get_error(3)|ERR_get_error(3)>, L<d2i_X509_NAME(3)|d2i_X509_NAME(3)> | ||
107 | |||
108 | =head1 HISTORY | ||
109 | |||
110 | =cut | ||
diff --git a/src/lib/libcrypto/doc/X509_NAME_get_index_by_NID.pod b/src/lib/libcrypto/doc/X509_NAME_get_index_by_NID.pod new file mode 100644 index 0000000000..333323d734 --- /dev/null +++ b/src/lib/libcrypto/doc/X509_NAME_get_index_by_NID.pod | |||
@@ -0,0 +1,106 @@ | |||
1 | =pod | ||
2 | |||
3 | =head1 NAME | ||
4 | |||
5 | X509_NAME_get_index_by_NID, X509_NAME_get_index_by_OBJ, X509_NAME_get_entry, | ||
6 | X509_NAME_entry_count, X509_NAME_get_text_by_NID, X509_NAME_get_text_by_OBJ - | ||
7 | X509_NAME lookup and enumeration functions | ||
8 | |||
9 | =head1 SYNOPSIS | ||
10 | |||
11 | int X509_NAME_get_index_by_NID(X509_NAME *name,int nid,int lastpos); | ||
12 | int X509_NAME_get_index_by_OBJ(X509_NAME *name,ASN1_OBJECT *obj, int lastpos); | ||
13 | |||
14 | int X509_NAME_entry_count(X509_NAME *name); | ||
15 | X509_NAME_ENTRY *X509_NAME_get_entry(X509_NAME *name, int loc); | ||
16 | |||
17 | int X509_NAME_get_text_by_NID(X509_NAME *name, int nid, char *buf,int len); | ||
18 | int X509_NAME_get_text_by_OBJ(X509_NAME *name, ASN1_OBJECT *obj, char *buf,int len); | ||
19 | |||
20 | =head1 DESCRIPTION | ||
21 | |||
22 | These functions allow an B<X509_NAME> structure to be examined. The | ||
23 | B<X509_NAME> structure is the same as the B<Name> type defined in | ||
24 | RFC2459 (and elsewhere) and used for example in certificate subject | ||
25 | and issuer names. | ||
26 | |||
27 | X509_NAME_get_index_by_NID() and X509_NAME_get_index_by_OBJ() retrieve | ||
28 | the next index matching B<nid> or B<obj> after B<lastpos>. B<lastpos> | ||
29 | should initially be set to -1. If there are no more entries -1 is returned. | ||
30 | |||
31 | X509_NAME_entry_count() returns the total number of entries in B<name>. | ||
32 | |||
33 | X509_NAME_get_entry() retrieves the B<X509_NAME_ENTRY> from B<name> | ||
34 | corresponding to index B<loc>. Acceptable values for B<loc> run from | ||
35 | 0 to (X509_NAME_entry_count(name) - 1). The value returned is an | ||
36 | internal pointer which must not be freed. | ||
37 | |||
38 | X509_NAME_get_text_by_NID(), X509_NAME_get_text_by_OBJ() retrieve | ||
39 | the "text" from the first entry in B<name> which matches B<nid> or | ||
40 | B<obj>, if no such entry exists -1 is returned. At most B<len> bytes | ||
41 | will be written and the text written to B<buf> will be null | ||
42 | terminated. The length of the output string written is returned | ||
43 | excluding the terminating null. If B<buf> is <NULL> then the amount | ||
44 | of space needed in B<buf> (excluding the final null) is returned. | ||
45 | |||
46 | =head1 NOTES | ||
47 | |||
48 | X509_NAME_get_text_by_NID() and X509_NAME_get_text_by_OBJ() are | ||
49 | legacy functions which have various limitations which make them | ||
50 | of minimal use in practice. They can only find the first matching | ||
51 | entry and will copy the contents of the field verbatim: this can | ||
52 | be highly confusing if the target is a muticharacter string type | ||
53 | like a BMPString or a UTF8String. | ||
54 | |||
55 | For a more general solution X509_NAME_get_index_by_NID() or | ||
56 | X509_NAME_get_index_by_OBJ() should be used followed by | ||
57 | X509_NAME_get_entry() on any matching indices and then the | ||
58 | various B<X509_NAME_ENTRY> utility functions on the result. | ||
59 | |||
60 | =head1 EXAMPLES | ||
61 | |||
62 | Process all entries: | ||
63 | |||
64 | int i; | ||
65 | X509_NAME_ENTRY *e; | ||
66 | |||
67 | for (i = 0; i < X509_NAME_entry_count(nm); i++) | ||
68 | { | ||
69 | e = X509_NAME_get_entry(nm, i); | ||
70 | /* Do something with e */ | ||
71 | } | ||
72 | |||
73 | Process all commonName entries: | ||
74 | |||
75 | int loc; | ||
76 | X509_NAME_ENTRY *e; | ||
77 | |||
78 | loc = -1; | ||
79 | for (;;) | ||
80 | { | ||
81 | lastpos = X509_NAME_get_index_by_NID(nm, NID_commonName, lastpos); | ||
82 | if (lastpos == -1) | ||
83 | break; | ||
84 | e = X509_NAME_get_entry(nm, lastpos); | ||
85 | /* Do something with e */ | ||
86 | } | ||
87 | |||
88 | =head1 RETURN VALUES | ||
89 | |||
90 | X509_NAME_get_index_by_NID() and X509_NAME_get_index_by_OBJ() | ||
91 | return the index of the next matching entry or -1 if not found. | ||
92 | |||
93 | X509_NAME_entry_count() returns the total number of entries. | ||
94 | |||
95 | X509_NAME_get_entry() returns an B<X509_NAME> pointer to the | ||
96 | requested entry or B<NULL> if the index is invalid. | ||
97 | |||
98 | =head1 SEE ALSO | ||
99 | |||
100 | L<ERR_get_error(3)|ERR_get_error(3)>, L<d2i_X509_NAME(3)|d2i_X509_NAME(3)> | ||
101 | |||
102 | =head1 HISTORY | ||
103 | |||
104 | TBA | ||
105 | |||
106 | =cut | ||
diff --git a/src/lib/libcrypto/doc/X509_NAME_print_ex.pod b/src/lib/libcrypto/doc/X509_NAME_print_ex.pod new file mode 100644 index 0000000000..907c04f684 --- /dev/null +++ b/src/lib/libcrypto/doc/X509_NAME_print_ex.pod | |||
@@ -0,0 +1,105 @@ | |||
1 | =pod | ||
2 | |||
3 | =head1 NAME | ||
4 | |||
5 | X509_NAME_print_ex, X509_NAME_print_ex_fp, X509_NAME_print, | ||
6 | X509_NAME_oneline - X509_NAME printing routines. | ||
7 | |||
8 | =head1 SYNOPSIS | ||
9 | |||
10 | #include <openssl/x509.h> | ||
11 | |||
12 | int X509_NAME_print_ex(BIO *out, X509_NAME *nm, int indent, unsigned long flags); | ||
13 | int X509_NAME_print_ex_fp(FILE *fp, X509_NAME *nm, int indent, unsigned long flags); | ||
14 | char * X509_NAME_oneline(X509_NAME *a,char *buf,int size); | ||
15 | int X509_NAME_print(BIO *bp, X509_NAME *name, int obase); | ||
16 | |||
17 | =head1 DESCRIPTION | ||
18 | |||
19 | X509_NAME_print_ex() prints a human readable version of B<nm> to BIO B<out>. Each | ||
20 | line (for multiline formats) is indented by B<indent> spaces. The output format | ||
21 | can be extensively customised by use of the B<flags> parameter. | ||
22 | |||
23 | X509_NAME_print_ex_fp() is identical to X509_NAME_print_ex() except the output is | ||
24 | written to FILE pointer B<fp>. | ||
25 | |||
26 | X509_NAME_oneline() prints an ASCII version of B<a> to B<buf>. At most B<size> | ||
27 | bytes will be written. If B<buf> is B<NULL> then a buffer is dynamically allocated | ||
28 | and returned, otherwise B<buf> is returned. | ||
29 | |||
30 | X509_NAME_print() prints out B<name> to B<bp> indenting each line by B<obase> | ||
31 | characters. Multiple lines are used if the output (including indent) exceeds | ||
32 | 80 characters. | ||
33 | |||
34 | =head1 NOTES | ||
35 | |||
36 | The functions X509_NAME_oneline() and X509_NAME_print() are legacy functions which | ||
37 | produce a non standard output form, they don't handle multi character fields and | ||
38 | have various quirks and inconsistencies. Their use is strongly discouraged in new | ||
39 | applications. | ||
40 | |||
41 | Although there are a large number of possible flags for most purposes | ||
42 | B<XN_FLAG_ONELINE>, B<XN_FLAG_MULTILINE> or B<XN_FLAG_RFC2253> will suffice. | ||
43 | As noted on the L<ASN1_STRING_print_ex(3)|ASN1_STRING_print_ex(3)> manual page | ||
44 | for UTF8 terminals the B<ASN1_STRFLAGS_ESC_MSB> should be unset: so for example | ||
45 | B<XN_FLAG_ONELINE & ~ASN1_STRFLAGS_ESC_MSB> would be used. | ||
46 | |||
47 | The complete set of the flags supported by X509_NAME_print_ex() is listed below. | ||
48 | |||
49 | Several options can be ored together. | ||
50 | |||
51 | The options B<XN_FLAG_SEP_COMMA_PLUS>, B<XN_FLAG_SEP_CPLUS_SPC>, | ||
52 | B<XN_FLAG_SEP_SPLUS_SPC> and B<XN_FLAG_SEP_MULTILINE> determine the field separators | ||
53 | to use. Two distinct separators are used between distinct RelativeDistinguishedName | ||
54 | components and separate values in the same RDN for a multi-valued RDN. Multi-valued | ||
55 | RDNs are currently very rare so the second separator will hardly ever be used. | ||
56 | |||
57 | B<XN_FLAG_SEP_COMMA_PLUS> uses comma and plus as separators. B<XN_FLAG_SEP_CPLUS_SPC> | ||
58 | uses comma and plus with spaces: this is more readable that plain comma and plus. | ||
59 | B<XN_FLAG_SEP_SPLUS_SPC> uses spaced semicolon and plus. B<XN_FLAG_SEP_MULTILINE> uses | ||
60 | spaced newline and plus respectively. | ||
61 | |||
62 | If B<XN_FLAG_DN_REV> is set the whole DN is printed in reversed order. | ||
63 | |||
64 | The fields B<XN_FLAG_FN_SN>, B<XN_FLAG_FN_LN>, B<XN_FLAG_FN_OID>, | ||
65 | B<XN_FLAG_FN_NONE> determine how a field name is displayed. It will | ||
66 | use the short name (e.g. CN) the long name (e.g. commonName) always | ||
67 | use OID numerical form (normally OIDs are only used if the field name is not | ||
68 | recognised) and no field name respectively. | ||
69 | |||
70 | If B<XN_FLAG_SPC_EQ> is set then spaces will be placed around the '=' character | ||
71 | separating field names and values. | ||
72 | |||
73 | If B<XN_FLAG_DUMP_UNKNOWN_FIELDS> is set then the encoding of unknown fields is | ||
74 | printed instead of the values. | ||
75 | |||
76 | If B<XN_FLAG_FN_ALIGN> is set then field names are padded to 20 characters: this | ||
77 | is only of use for multiline format. | ||
78 | |||
79 | Additionally all the options supported by ASN1_STRING_print_ex() can be used to | ||
80 | control how each field value is displayed. | ||
81 | |||
82 | In addition a number options can be set for commonly used formats. | ||
83 | |||
84 | B<XN_FLAG_RFC2253> sets options which produce an output compatible with RFC2253 it | ||
85 | is equivalent to: | ||
86 | B<ASN1_STRFLGS_RFC2253 | XN_FLAG_SEP_COMMA_PLUS | XN_FLAG_DN_REV | XN_FLAG_FN_SN | XN_FLAG_DUMP_UNKNOWN_FIELDS> | ||
87 | |||
88 | |||
89 | B<XN_FLAG_ONELINE> is a more readable one line format it is the same as: | ||
90 | B<ASN1_STRFLGS_RFC2253 | ASN1_STRFLGS_ESC_QUOTE | XN_FLAG_SEP_CPLUS_SPC | XN_FLAG_SPC_EQ | XN_FLAG_FN_SN> | ||
91 | |||
92 | B<XN_FLAG_MULTILINE> is a multiline format is is the same as: | ||
93 | B<ASN1_STRFLGS_ESC_CTRL | ASN1_STRFLGS_ESC_MSB | XN_FLAG_SEP_MULTILINE | XN_FLAG_SPC_EQ | XN_FLAG_FN_LN | XN_FLAG_FN_ALIGN> | ||
94 | |||
95 | B<XN_FLAG_COMPAT> uses a format identical to X509_NAME_print(): in fact it calls X509_NAME_print() internally. | ||
96 | |||
97 | =head1 SEE ALSO | ||
98 | |||
99 | L<ASN1_STRING_print_ex(3)|ASN1_STRING_print_ex(3)> | ||
100 | |||
101 | =head1 HISTORY | ||
102 | |||
103 | TBA | ||
104 | |||
105 | =cut | ||
diff --git a/src/lib/libcrypto/doc/X509_new.pod b/src/lib/libcrypto/doc/X509_new.pod new file mode 100644 index 0000000000..fd5fc65ce1 --- /dev/null +++ b/src/lib/libcrypto/doc/X509_new.pod | |||
@@ -0,0 +1,37 @@ | |||
1 | =pod | ||
2 | |||
3 | =head1 NAME | ||
4 | |||
5 | X509_new, X509_free - X509 certificate ASN1 allocation functions | ||
6 | |||
7 | =head1 SYNOPSIS | ||
8 | |||
9 | X509 *X509_new(void); | ||
10 | void X509_free(X509 *a); | ||
11 | |||
12 | =head1 DESCRIPTION | ||
13 | |||
14 | The X509 ASN1 allocation routines, allocate and free an | ||
15 | X509 structure, which represents an X509 certificate. | ||
16 | |||
17 | X509_new() allocates and initializes a X509 structure. | ||
18 | |||
19 | X509_free() frees up the B<X509> structure B<a>. | ||
20 | |||
21 | =head1 RETURN VALUES | ||
22 | |||
23 | If the allocation fails, X509_new() returns B<NULL> and sets an error | ||
24 | code that can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>. | ||
25 | Otherwise it returns a pointer to the newly allocated structure. | ||
26 | |||
27 | X509_free() returns no value. | ||
28 | |||
29 | =head1 SEE ALSO | ||
30 | |||
31 | L<ERR_get_error(3)|ERR_get_error(3)>, L<d2i_X509(3)|d2i_X509(3)> | ||
32 | |||
33 | =head1 HISTORY | ||
34 | |||
35 | X509_new() and X509_free() are available in all versions of SSLeay and OpenSSL. | ||
36 | |||
37 | =cut | ||
diff --git a/src/lib/libcrypto/doc/d2i_ASN1_OBJECT.pod b/src/lib/libcrypto/doc/d2i_ASN1_OBJECT.pod new file mode 100644 index 0000000000..45bb18492c --- /dev/null +++ b/src/lib/libcrypto/doc/d2i_ASN1_OBJECT.pod | |||
@@ -0,0 +1,29 @@ | |||
1 | =pod | ||
2 | |||
3 | =head1 NAME | ||
4 | |||
5 | d2i_ASN1_OBJECT, i2d_ASN1_OBJECT - ASN1 OBJECT IDENTIFIER functions | ||
6 | |||
7 | =head1 SYNOPSIS | ||
8 | |||
9 | #include <openssl/objects.h> | ||
10 | |||
11 | ASN1_OBJECT *d2i_ASN1_OBJECT(ASN1_OBJECT **a, unsigned char **pp, long length); | ||
12 | int i2d_ASN1_OBJECT(ASN1_OBJECT *a, unsigned char **pp); | ||
13 | |||
14 | =head1 DESCRIPTION | ||
15 | |||
16 | These functions decode and encode an ASN1 OBJECT IDENTIFIER. | ||
17 | |||
18 | Othewise these behave in a similar way to d2i_X509() and i2d_X509() | ||
19 | described in the L<d2i_X509(3)|d2i_X509(3)> manual page. | ||
20 | |||
21 | =head1 SEE ALSO | ||
22 | |||
23 | L<d2i_X509(3)|d2i_X509(3)> | ||
24 | |||
25 | =head1 HISTORY | ||
26 | |||
27 | TBA | ||
28 | |||
29 | =cut | ||
diff --git a/src/lib/libcrypto/doc/d2i_DHparams.pod b/src/lib/libcrypto/doc/d2i_DHparams.pod index a6d1743d39..1e98aebeca 100644 --- a/src/lib/libcrypto/doc/d2i_DHparams.pod +++ b/src/lib/libcrypto/doc/d2i_DHparams.pod | |||
@@ -2,7 +2,7 @@ | |||
2 | 2 | ||
3 | =head1 NAME | 3 | =head1 NAME |
4 | 4 | ||
5 | d2i_DHparams, i2d_DHparams - ... | 5 | d2i_DHparams, i2d_DHparams - PKCS#3 DH parameter functions. |
6 | 6 | ||
7 | =head1 SYNOPSIS | 7 | =head1 SYNOPSIS |
8 | 8 | ||
@@ -13,18 +13,18 @@ d2i_DHparams, i2d_DHparams - ... | |||
13 | 13 | ||
14 | =head1 DESCRIPTION | 14 | =head1 DESCRIPTION |
15 | 15 | ||
16 | ... | 16 | These functions decode and encode PKCS#3 DH parameters using the |
17 | DHparameter structure described in PKCS#3. | ||
17 | 18 | ||
18 | =head1 RETURN VALUES | 19 | Othewise these behave in a similar way to d2i_X509() and i2d_X509() |
19 | 20 | described in the L<d2i_X509(3)|d2i_X509(3)> manual page. | |
20 | ... | ||
21 | 21 | ||
22 | =head1 SEE ALSO | 22 | =head1 SEE ALSO |
23 | 23 | ||
24 | ... | 24 | L<d2i_X509(3)|d2i_X509(3)> |
25 | 25 | ||
26 | =head1 HISTORY | 26 | =head1 HISTORY |
27 | 27 | ||
28 | ... | 28 | TBA |
29 | 29 | ||
30 | =cut | 30 | =cut |
diff --git a/src/lib/libcrypto/doc/d2i_DSAPublicKey.pod b/src/lib/libcrypto/doc/d2i_DSAPublicKey.pod new file mode 100644 index 0000000000..6ebd30427b --- /dev/null +++ b/src/lib/libcrypto/doc/d2i_DSAPublicKey.pod | |||
@@ -0,0 +1,82 @@ | |||
1 | =pod | ||
2 | |||
3 | =head1 NAME | ||
4 | |||
5 | d2i_DSAPublicKey, i2d_DSAPublicKey, d2i_DSAPrivateKey, i2d_DSAPrivateKey, | ||
6 | d2i_DSA_PUBKEY, i2d_DSA_PUBKEY, d2i_DSA_SIG, i2d_DSA_SIG - DSA key encoding | ||
7 | and parsing functions. | ||
8 | |||
9 | =head1 SYNOPSIS | ||
10 | |||
11 | #include <openssl/dsa.h> | ||
12 | |||
13 | DSA * d2i_DSAPublicKey(DSA **a, const unsigned char **pp, long length); | ||
14 | |||
15 | int i2d_DSAPublicKey(const DSA *a, unsigned char **pp); | ||
16 | |||
17 | DSA * d2i_DSA_PUBKEY(DSA **a, const unsigned char **pp, long length); | ||
18 | |||
19 | int i2d_DSA_PUBKEY(const DSA *a, unsigned char **pp); | ||
20 | |||
21 | DSA * d2i_DSAPrivateKey(DSA **a, const unsigned char **pp, long length); | ||
22 | |||
23 | int i2d_DSAPrivateKey(const DSA *a, unsigned char **pp); | ||
24 | |||
25 | DSA * d2i_DSAparams(DSA **a, const unsigned char **pp, long length); | ||
26 | |||
27 | int i2d_DSAparams(const DSA *a, unsigned char **pp); | ||
28 | |||
29 | DSA * d2i_DSA_SIG(DSA_SIG **a, const unsigned char **pp, long length); | ||
30 | |||
31 | int i2d_DSA_SIG(const DSA_SIG *a, unsigned char **pp); | ||
32 | |||
33 | =head1 DESCRIPTION | ||
34 | |||
35 | d2i_DSAPublicKey() and i2d_DSAPublicKey() decode and encode the DSA public key | ||
36 | components structure. | ||
37 | |||
38 | d2i_DSA_PUKEY() and i2d_DSA_PUKEY() decode and encode an DSA public key using a | ||
39 | SubjectPublicKeyInfo (certificate public key) structure. | ||
40 | |||
41 | d2i_DSAPrivateKey(), i2d_DSAPrivateKey() decode and encode the DSA private key | ||
42 | components. | ||
43 | |||
44 | d2i_DSAparams(), i2d_DSAparams() decode and encode the DSA parameters using | ||
45 | a B<Dss-Parms> structure as defined in RFC2459. | ||
46 | |||
47 | d2i_DSA_SIG(), i2d_DSA_SIG() decode and encode a DSA signature using a | ||
48 | B<Dss-Sig-Value> structure as defined in RFC2459. | ||
49 | |||
50 | The usage of all of these functions is similar to the d2i_X509() and | ||
51 | i2d_X509() described in the L<d2i_X509(3)|d2i_X509(3)> manual page. | ||
52 | |||
53 | =head1 NOTES | ||
54 | |||
55 | The B<DSA> structure passed to the private key encoding functions should have | ||
56 | all the private key components present. | ||
57 | |||
58 | The data encoded by the private key functions is unencrypted and therefore | ||
59 | offers no private key security. | ||
60 | |||
61 | The B<DSA_PUBKEY> functions should be used in preference to the B<DSAPublicKey> | ||
62 | functions when encoding public keys because they use a standard format. | ||
63 | |||
64 | The B<DSAPublicKey> functions use an non standard format the actual data encoded | ||
65 | depends on the value of the B<write_params> field of the B<a> key parameter. | ||
66 | If B<write_params> is zero then only the B<pub_key> field is encoded as an | ||
67 | B<INTEGER>. If B<write_params> is 1 then a B<SEQUENCE> consisting of the | ||
68 | B<p>, B<q>, B<g> and B<pub_key> respectively fields are encoded. | ||
69 | |||
70 | The B<DSAPrivateKey> functions also use a non standard structure consiting | ||
71 | consisting of a SEQUENCE containing the B<p>, B<q>, B<g> and B<pub_key> and | ||
72 | B<priv_key> fields respectively. | ||
73 | |||
74 | =head1 SEE ALSO | ||
75 | |||
76 | L<d2i_X509(3)|d2i_X509(3)> | ||
77 | |||
78 | =head1 HISTORY | ||
79 | |||
80 | TBA | ||
81 | |||
82 | =cut | ||
diff --git a/src/lib/libcrypto/doc/d2i_RSAPublicKey.pod b/src/lib/libcrypto/doc/d2i_RSAPublicKey.pod index ff4d0d57db..7c71bcbf3d 100644 --- a/src/lib/libcrypto/doc/d2i_RSAPublicKey.pod +++ b/src/lib/libcrypto/doc/d2i_RSAPublicKey.pod | |||
@@ -2,7 +2,9 @@ | |||
2 | 2 | ||
3 | =head1 NAME | 3 | =head1 NAME |
4 | 4 | ||
5 | d2i_RSAPublicKey, i2d_RSAPublicKey, d2i_RSAPrivateKey, i2d_RSAPrivateKey, i2d_Netscape_RSA, d2i_Netscape_RSA - ... | 5 | d2i_RSAPublicKey, i2d_RSAPublicKey, d2i_RSAPrivateKey, i2d_RSAPrivateKey, |
6 | d2i_RSA_PUBKEY, i2d_RSA_PUBKEY, i2d_Netscape_RSA, | ||
7 | d2i_Netscape_RSA - RSA public and private key encoding functions. | ||
6 | 8 | ||
7 | =head1 SYNOPSIS | 9 | =head1 SYNOPSIS |
8 | 10 | ||
@@ -12,6 +14,10 @@ d2i_RSAPublicKey, i2d_RSAPublicKey, d2i_RSAPrivateKey, i2d_RSAPrivateKey, i2d_Ne | |||
12 | 14 | ||
13 | int i2d_RSAPublicKey(RSA *a, unsigned char **pp); | 15 | int i2d_RSAPublicKey(RSA *a, unsigned char **pp); |
14 | 16 | ||
17 | RSA * d2i_RSA_PUBKEY(RSA **a, unsigned char **pp, long length); | ||
18 | |||
19 | int i2d_RSA_PUBKEY(RSA *a, unsigned char **pp); | ||
20 | |||
15 | RSA * d2i_RSAPrivateKey(RSA **a, unsigned char **pp, long length); | 21 | RSA * d2i_RSAPrivateKey(RSA **a, unsigned char **pp, long length); |
16 | 22 | ||
17 | int i2d_RSAPrivateKey(RSA *a, unsigned char **pp); | 23 | int i2d_RSAPrivateKey(RSA *a, unsigned char **pp); |
@@ -22,18 +28,39 @@ d2i_RSAPublicKey, i2d_RSAPublicKey, d2i_RSAPrivateKey, i2d_RSAPrivateKey, i2d_Ne | |||
22 | 28 | ||
23 | =head1 DESCRIPTION | 29 | =head1 DESCRIPTION |
24 | 30 | ||
25 | ... | 31 | d2i_RSAPublicKey() and i2d_RSAPublicKey() decode and encode a PKCS#1 RSAPublicKey |
32 | structure. | ||
33 | |||
34 | d2i_RSA_PUKEY() and i2d_RSA_PUKEY() decode and encode an RSA public key using a | ||
35 | SubjectPublicKeyInfo (certificate public key) structure. | ||
36 | |||
37 | d2i_RSAPrivateKey(), i2d_RSAPrivateKey() decode and encode a PKCS#1 RSAPrivateKey | ||
38 | structure. | ||
39 | |||
40 | d2i_Netscape_RSA(), i2d_Netscape_RSA() decode and encode an RSA private key in | ||
41 | NET format. | ||
42 | |||
43 | The usage of all of these functions is similar to the d2i_X509() and | ||
44 | i2d_X509() described in the L<d2i_X509(3)|d2i_X509(3)> manual page. | ||
45 | |||
46 | =head1 NOTES | ||
47 | |||
48 | The B<RSA> structure passed to the private key encoding functions should have | ||
49 | all the PKCS#1 private key components present. | ||
26 | 50 | ||
27 | =head1 RETURN VALUES | 51 | The data encoded by the private key functions is unencrypted and therefore |
52 | offers no private key security. | ||
28 | 53 | ||
29 | ... | 54 | The NET format functions are present to provide compatibility with certain very |
55 | old software. This format has some severe security weaknesses and should be | ||
56 | avoided if possible. | ||
30 | 57 | ||
31 | =head1 SEE ALSO | 58 | =head1 SEE ALSO |
32 | 59 | ||
33 | ... | 60 | L<d2i_X509(3)|d2i_X509(3)> |
34 | 61 | ||
35 | =head1 HISTORY | 62 | =head1 HISTORY |
36 | 63 | ||
37 | ... | 64 | TBA |
38 | 65 | ||
39 | =cut | 66 | =cut |
diff --git a/src/lib/libcrypto/doc/d2i_X509.pod b/src/lib/libcrypto/doc/d2i_X509.pod new file mode 100644 index 0000000000..5e3c3d0985 --- /dev/null +++ b/src/lib/libcrypto/doc/d2i_X509.pod | |||
@@ -0,0 +1,231 @@ | |||
1 | =pod | ||
2 | |||
3 | =head1 NAME | ||
4 | |||
5 | d2i_X509, i2d_X509, d2i_X509_bio, d2i_X509_fp, i2d_X509_bio, | ||
6 | i2d_X509_fp - X509 encode and decode functions | ||
7 | |||
8 | =head1 SYNOPSIS | ||
9 | |||
10 | #include <openssl/x509.h> | ||
11 | |||
12 | X509 *d2i_X509(X509 **px, unsigned char **in, int len); | ||
13 | int i2d_X509(X509 *x, unsigned char **out); | ||
14 | |||
15 | X509 *d2i_X509_bio(BIO *bp, X509 **x); | ||
16 | X509 *d2i_X509_fp(FILE *fp, X509 **x); | ||
17 | |||
18 | int i2d_X509_bio(X509 *x, BIO *bp); | ||
19 | int i2d_X509_fp(X509 *x, FILE *fp); | ||
20 | |||
21 | =head1 DESCRIPTION | ||
22 | |||
23 | The X509 encode and decode routines encode and parse an | ||
24 | B<X509> structure, which represents an X509 certificate. | ||
25 | |||
26 | d2i_X509() attempts to decode B<len> bytes at B<*out>. If | ||
27 | successful a pointer to the B<X509> structure is returned. If an error | ||
28 | occurred then B<NULL> is returned. If B<px> is not B<NULL> then the | ||
29 | returned structure is written to B<*px>. If B<*px> is not B<NULL> | ||
30 | then it is assumed that B<*px> contains a valid B<X509> | ||
31 | structure and an attempt is made to reuse it. If the call is | ||
32 | successful B<*out> is incremented to the byte following the | ||
33 | parsed data. | ||
34 | |||
35 | i2d_X509() encodes the structure pointed to by B<x> into DER format. | ||
36 | If B<out> is not B<NULL> is writes the DER encoded data to the buffer | ||
37 | at B<*out>, and increments it to point after the data just written. | ||
38 | If the return value is negative an error occurred, otherwise it | ||
39 | returns the length of the encoded data. | ||
40 | |||
41 | For OpenSSL 0.9.7 and later if B<*out> is B<NULL> memory will be | ||
42 | allocated for a buffer and the encoded data written to it. In this | ||
43 | case B<*out> is not incremented and it points to the start of the | ||
44 | data just written. | ||
45 | |||
46 | d2i_X509_bio() is similar to d2i_X509() except it attempts | ||
47 | to parse data from BIO B<bp>. | ||
48 | |||
49 | d2i_X509_fp() is similar to d2i_X509() except it attempts | ||
50 | to parse data from FILE pointer B<fp>. | ||
51 | |||
52 | i2d_X509_bio() is similar to i2d_X509() except it writes | ||
53 | the encoding of the structure B<x> to BIO B<bp> and it | ||
54 | returns 1 for success and 0 for failure. | ||
55 | |||
56 | i2d_X509_fp() is similar to i2d_X509() except it writes | ||
57 | the encoding of the structure B<x> to BIO B<bp> and it | ||
58 | returns 1 for success and 0 for failure. | ||
59 | |||
60 | =head1 NOTES | ||
61 | |||
62 | The letters B<i> and B<d> in for example B<i2d_X509> stand for | ||
63 | "internal" (that is an internal C structure) and "DER". So that | ||
64 | B<i2d_X509> converts from internal to DER. | ||
65 | |||
66 | The functions can also understand B<BER> forms. | ||
67 | |||
68 | The actual X509 structure passed to i2d_X509() must be a valid | ||
69 | populated B<X509> structure it can B<not> simply be fed with an | ||
70 | empty structure such as that returned by X509_new(). | ||
71 | |||
72 | The encoded data is in binary form and may contain embedded zeroes. | ||
73 | Therefore any FILE pointers or BIOs should be opened in binary mode. | ||
74 | Functions such as B<strlen()> will B<not> return the correct length | ||
75 | of the encoded structure. | ||
76 | |||
77 | The ways that B<*in> and B<*out> are incremented after the operation | ||
78 | can trap the unwary. See the B<WARNINGS> section for some common | ||
79 | errors. | ||
80 | |||
81 | The reason for the auto increment behaviour is to reflect a typical | ||
82 | usage of ASN1 functions: after one structure is encoded or decoded | ||
83 | another will processed after it. | ||
84 | |||
85 | =head1 EXAMPLES | ||
86 | |||
87 | Allocate and encode the DER encoding of an X509 structure: | ||
88 | |||
89 | int len; | ||
90 | unsigned char *buf, *p; | ||
91 | |||
92 | len = i2d_X509(x, NULL); | ||
93 | |||
94 | buf = OPENSSL_malloc(len); | ||
95 | |||
96 | if (buf == NULL) | ||
97 | /* error */ | ||
98 | |||
99 | p = buf; | ||
100 | |||
101 | i2d_X509(x, &p); | ||
102 | |||
103 | If you are using OpenSSL 0.9.7 or later then this can be | ||
104 | simplified to: | ||
105 | |||
106 | |||
107 | int len; | ||
108 | unsigned char *buf; | ||
109 | |||
110 | buf = NULL; | ||
111 | |||
112 | len = i2d_X509(x, &buf); | ||
113 | |||
114 | if (len < 0) | ||
115 | /* error */ | ||
116 | |||
117 | Attempt to decode a buffer: | ||
118 | |||
119 | X509 *x; | ||
120 | |||
121 | unsigned char *buf, *p; | ||
122 | |||
123 | int len; | ||
124 | |||
125 | /* Something to setup buf and len */ | ||
126 | |||
127 | p = buf; | ||
128 | |||
129 | x = d2i_X509(NULL, &p, len); | ||
130 | |||
131 | if (x == NULL) | ||
132 | /* Some error */ | ||
133 | |||
134 | Alternative technique: | ||
135 | |||
136 | X509 *x; | ||
137 | |||
138 | unsigned char *buf, *p; | ||
139 | |||
140 | int len; | ||
141 | |||
142 | /* Something to setup buf and len */ | ||
143 | |||
144 | p = buf; | ||
145 | |||
146 | x = NULL; | ||
147 | |||
148 | if(!d2i_X509(&x, &p, len)) | ||
149 | /* Some error */ | ||
150 | |||
151 | |||
152 | =head1 WARNINGS | ||
153 | |||
154 | The use of temporary variable is mandatory. A common | ||
155 | mistake is to attempt to use a buffer directly as follows: | ||
156 | |||
157 | int len; | ||
158 | unsigned char *buf; | ||
159 | |||
160 | len = i2d_X509(x, NULL); | ||
161 | |||
162 | buf = OPENSSL_malloc(len); | ||
163 | |||
164 | if (buf == NULL) | ||
165 | /* error */ | ||
166 | |||
167 | i2d_X509(x, &buf); | ||
168 | |||
169 | /* Other stuff ... */ | ||
170 | |||
171 | OPENSSL_free(buf); | ||
172 | |||
173 | This code will result in B<buf> apparently containing garbage because | ||
174 | it was incremented after the call to point after the data just written. | ||
175 | Also B<buf> will no longer contain the pointer allocated by B<OPENSSL_malloc()> | ||
176 | and the subsequent call to B<OPENSSL_free()> may well crash. | ||
177 | |||
178 | The auto allocation feature (setting buf to NULL) only works on OpenSSL | ||
179 | 0.9.7 and later. Attempts to use it on earlier versions will typically | ||
180 | cause a segmentation violation. | ||
181 | |||
182 | Another trap to avoid is misuse of the B<xp> argument to B<d2i_X509()>: | ||
183 | |||
184 | X509 *x; | ||
185 | |||
186 | if (!d2i_X509(&x, &p, len)) | ||
187 | /* Some error */ | ||
188 | |||
189 | This will probably crash somewhere in B<d2i_X509()>. The reason for this | ||
190 | is that the variable B<x> is uninitialized and an attempt will be made to | ||
191 | interpret its (invalid) value as an B<X509> structure, typically causing | ||
192 | a segmentation violation. If B<x> is set to NULL first then this will not | ||
193 | happen. | ||
194 | |||
195 | =head1 BUGS | ||
196 | |||
197 | In some versions of OpenSSL the "reuse" behaviour of d2i_X509() when | ||
198 | B<*px> is valid is broken and some parts of the reused structure may | ||
199 | persist if they are not present in the new one. As a result the use | ||
200 | of this "reuse" behaviour is strongly discouraged. | ||
201 | |||
202 | i2d_X509() will not return an error in many versions of OpenSSL, | ||
203 | if mandatory fields are not initialized due to a programming error | ||
204 | then the encoded structure may contain invalid data or omit the | ||
205 | fields entirely and will not be parsed by d2i_X509(). This may be | ||
206 | fixed in future so code should not assume that i2d_X509() will | ||
207 | always succeed. | ||
208 | |||
209 | =head1 RETURN VALUES | ||
210 | |||
211 | d2i_X509(), d2i_X509_bio() and d2i_X509_fp() return a valid B<X509> structure | ||
212 | or B<NULL> if an error occurs. The error code that can be obtained by | ||
213 | L<ERR_get_error(3)|ERR_get_error(3)>. | ||
214 | |||
215 | i2d_X509(), i2d_X509_bio() and i2d_X509_fp() return a the number of bytes | ||
216 | successfully encoded or a negative value if an error occurs. The error code | ||
217 | can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>. | ||
218 | |||
219 | i2d_X509_bio() and i2d_X509_fp() returns 1 for success and 0 if an error | ||
220 | occurs The error code can be obtained by L<ERR_get_error(3)|ERR_get_error(3)>. | ||
221 | |||
222 | =head1 SEE ALSO | ||
223 | |||
224 | L<ERR_get_error(3)|ERR_get_error(3)> | ||
225 | |||
226 | =head1 HISTORY | ||
227 | |||
228 | d2i_X509, i2d_X509, d2i_X509_bio, d2i_X509_fp, i2d_X509_bio and i2d_X509_fp | ||
229 | are available in all versions of SSLeay and OpenSSL. | ||
230 | |||
231 | =cut | ||
diff --git a/src/lib/libcrypto/doc/d2i_X509_ALGOR.pod b/src/lib/libcrypto/doc/d2i_X509_ALGOR.pod new file mode 100644 index 0000000000..9e5cd92ca7 --- /dev/null +++ b/src/lib/libcrypto/doc/d2i_X509_ALGOR.pod | |||
@@ -0,0 +1,30 @@ | |||
1 | =pod | ||
2 | |||
3 | =head1 NAME | ||
4 | |||
5 | d2i_X509_ALGOR, i2d_X509_ALGOR - AlgorithmIdentifier functions. | ||
6 | |||
7 | =head1 SYNOPSIS | ||
8 | |||
9 | #include <openssl/x509.h> | ||
10 | |||
11 | X509_ALGOR *d2i_X509_ALGOR(X509_ALGOR **a, unsigned char **pp, long length); | ||
12 | int i2d_X509_ALGOR(X509_ALGOR *a, unsigned char **pp); | ||
13 | |||
14 | =head1 DESCRIPTION | ||
15 | |||
16 | These functions decode and encode an B<X509_ALGOR> structure which is | ||
17 | equivalent to the B<AlgorithmIdentifier> structure. | ||
18 | |||
19 | Othewise these behave in a similar way to d2i_X509() and i2d_X509() | ||
20 | described in the L<d2i_X509(3)|d2i_X509(3)> manual page. | ||
21 | |||
22 | =head1 SEE ALSO | ||
23 | |||
24 | L<d2i_X509(3)|d2i_X509(3)> | ||
25 | |||
26 | =head1 HISTORY | ||
27 | |||
28 | TBA | ||
29 | |||
30 | =cut | ||
diff --git a/src/lib/libcrypto/doc/d2i_X509_CRL.pod b/src/lib/libcrypto/doc/d2i_X509_CRL.pod new file mode 100644 index 0000000000..06c5b23c09 --- /dev/null +++ b/src/lib/libcrypto/doc/d2i_X509_CRL.pod | |||
@@ -0,0 +1,37 @@ | |||
1 | =pod | ||
2 | |||
3 | =head1 NAME | ||
4 | |||
5 | d2i_X509_CRL, i2d_X509_CRL, d2i_X509_CRL_bio, d2i_509_CRL_fp, | ||
6 | i2d_X509_CRL_bio, i2d_X509_CRL_fp - PKCS#10 certificate request functions. | ||
7 | |||
8 | =head1 SYNOPSIS | ||
9 | |||
10 | #include <openssl/x509.h> | ||
11 | |||
12 | X509_CRL *d2i_X509_CRL(X509_CRL **a, unsigned char **pp, long length); | ||
13 | int i2d_X509_CRL(X509_CRL *a, unsigned char **pp); | ||
14 | |||
15 | X509_CRL *d2i_X509_CRL_bio(BIO *bp, X509_CRL **x); | ||
16 | X509_CRL *d2i_X509_CRL_fp(FILE *fp, X509_CRL **x); | ||
17 | |||
18 | int i2d_X509_CRL_bio(X509_CRL *x, BIO *bp); | ||
19 | int i2d_X509_CRL_fp(X509_CRL *x, FILE *fp); | ||
20 | |||
21 | =head1 DESCRIPTION | ||
22 | |||
23 | These functions decode and encode an X509 CRL (certificate revocation | ||
24 | list). | ||
25 | |||
26 | Othewise the functions behave in a similar way to d2i_X509() and i2d_X509() | ||
27 | described in the L<d2i_X509(3)|d2i_X509(3)> manual page. | ||
28 | |||
29 | =head1 SEE ALSO | ||
30 | |||
31 | L<d2i_X509(3)|d2i_X509(3)> | ||
32 | |||
33 | =head1 HISTORY | ||
34 | |||
35 | TBA | ||
36 | |||
37 | =cut | ||
diff --git a/src/lib/libcrypto/doc/d2i_X509_NAME.pod b/src/lib/libcrypto/doc/d2i_X509_NAME.pod new file mode 100644 index 0000000000..343ffe1519 --- /dev/null +++ b/src/lib/libcrypto/doc/d2i_X509_NAME.pod | |||
@@ -0,0 +1,31 @@ | |||
1 | =pod | ||
2 | |||
3 | =head1 NAME | ||
4 | |||
5 | d2i_X509_NAME, i2d_X509_NAME - X509_NAME encoding functions | ||
6 | |||
7 | =head1 SYNOPSIS | ||
8 | |||
9 | #include <openssl/x509.h> | ||
10 | |||
11 | X509_NAME *d2i_X509_NAME(X509_NAME **a, unsigned char **pp, long length); | ||
12 | int i2d_X509_NAME(X509_NAME *a, unsigned char **pp); | ||
13 | |||
14 | =head1 DESCRIPTION | ||
15 | |||
16 | These functions decode and encode an B<X509_NAME> structure which is the | ||
17 | the same as the B<Name> type defined in RFC2459 (and elsewhere) and used | ||
18 | for example in certificate subject and issuer names. | ||
19 | |||
20 | Othewise the functions behave in a similar way to d2i_X509() and i2d_X509() | ||
21 | described in the L<d2i_X509(3)|d2i_X509(3)> manual page. | ||
22 | |||
23 | =head1 SEE ALSO | ||
24 | |||
25 | L<d2i_X509(3)|d2i_X509(3)> | ||
26 | |||
27 | =head1 HISTORY | ||
28 | |||
29 | TBA | ||
30 | |||
31 | =cut | ||
diff --git a/src/lib/libcrypto/doc/d2i_X509_REQ.pod b/src/lib/libcrypto/doc/d2i_X509_REQ.pod new file mode 100644 index 0000000000..be4ad68257 --- /dev/null +++ b/src/lib/libcrypto/doc/d2i_X509_REQ.pod | |||
@@ -0,0 +1,36 @@ | |||
1 | =pod | ||
2 | |||
3 | =head1 NAME | ||
4 | |||
5 | d2i_X509_REQ, i2d_X509_REQ, d2i_X509_REQ_bio, d2i_X509_REQ_fp, | ||
6 | i2d_X509_REQ_bio, i2d_X509_REQ_fp - PKCS#10 certificate request functions. | ||
7 | |||
8 | =head1 SYNOPSIS | ||
9 | |||
10 | #include <openssl/x509.h> | ||
11 | |||
12 | X509_REQ *d2i_X509_REQ(X509_REQ **a, unsigned char **pp, long length); | ||
13 | int i2d_X509_REQ(X509_REQ *a, unsigned char **pp); | ||
14 | |||
15 | X509_REQ *d2i_X509_REQ_bio(BIO *bp, X509_REQ **x); | ||
16 | X509_REQ *d2i_X509_REQ_fp(FILE *fp, X509_REQ **x); | ||
17 | |||
18 | int i2d_X509_REQ_bio(X509_REQ *x, BIO *bp); | ||
19 | int i2d_X509_REQ_fp(X509_REQ *x, FILE *fp); | ||
20 | |||
21 | =head1 DESCRIPTION | ||
22 | |||
23 | These functions decode and encode a PKCS#10 certificate request. | ||
24 | |||
25 | Othewise these behave in a similar way to d2i_X509() and i2d_X509() | ||
26 | described in the L<d2i_X509(3)|d2i_X509(3)> manual page. | ||
27 | |||
28 | =head1 SEE ALSO | ||
29 | |||
30 | L<d2i_X509(3)|d2i_X509(3)> | ||
31 | |||
32 | =head1 HISTORY | ||
33 | |||
34 | TBA | ||
35 | |||
36 | =cut | ||
diff --git a/src/lib/libcrypto/doc/d2i_X509_SIG.pod b/src/lib/libcrypto/doc/d2i_X509_SIG.pod new file mode 100644 index 0000000000..e48fd79a51 --- /dev/null +++ b/src/lib/libcrypto/doc/d2i_X509_SIG.pod | |||
@@ -0,0 +1,30 @@ | |||
1 | =pod | ||
2 | |||
3 | =head1 NAME | ||
4 | |||
5 | d2i_X509_SIG, i2d_X509_SIG - DigestInfo functions. | ||
6 | |||
7 | =head1 SYNOPSIS | ||
8 | |||
9 | #include <openssl/x509.h> | ||
10 | |||
11 | X509_SIG *d2i_X509_SIG(X509_SIG **a, unsigned char **pp, long length); | ||
12 | int i2d_X509_SIG(X509_SIG *a, unsigned char **pp); | ||
13 | |||
14 | =head1 DESCRIPTION | ||
15 | |||
16 | These functions decode and encode an X509_SIG structure which is | ||
17 | equivalent to the B<DigestInfo> structure defined in PKCS#1 and PKCS#7. | ||
18 | |||
19 | Othewise these behave in a similar way to d2i_X509() and i2d_X509() | ||
20 | described in the L<d2i_X509(3)|d2i_X509(3)> manual page. | ||
21 | |||
22 | =head1 SEE ALSO | ||
23 | |||
24 | L<d2i_X509(3)|d2i_X509(3)> | ||
25 | |||
26 | =head1 HISTORY | ||
27 | |||
28 | TBA | ||
29 | |||
30 | =cut | ||
diff --git a/src/lib/libcrypto/doc/engine.pod b/src/lib/libcrypto/doc/engine.pod index 61e0264bb7..c77dad5562 100644 --- a/src/lib/libcrypto/doc/engine.pod +++ b/src/lib/libcrypto/doc/engine.pod | |||
@@ -187,7 +187,7 @@ tell which one you are dealing with at any given point in time (after all | |||
187 | they are both simply (ENGINE *) pointers, the difference is in the way they | 187 | they are both simply (ENGINE *) pointers, the difference is in the way they |
188 | are used). | 188 | are used). |
189 | 189 | ||
190 | =head3 Structural references | 190 | I<Structural references> |
191 | 191 | ||
192 | This basic type of reference is typically used for creating new ENGINEs | 192 | This basic type of reference is typically used for creating new ENGINEs |
193 | dynamically, iterating across OpenSSL's internal linked-list of loaded | 193 | dynamically, iterating across OpenSSL's internal linked-list of loaded |
@@ -224,7 +224,7 @@ To clarify a particular function's handling of references, one should | |||
224 | always consult that function's documentation "man" page, or failing that | 224 | always consult that function's documentation "man" page, or failing that |
225 | the openssl/engine.h header file includes some hints. | 225 | the openssl/engine.h header file includes some hints. |
226 | 226 | ||
227 | =head3 Functional references | 227 | I<Functional references> |
228 | 228 | ||
229 | As mentioned, functional references exist when the cryptographic | 229 | As mentioned, functional references exist when the cryptographic |
230 | functionality of an ENGINE is required to be available. A functional | 230 | functionality of an ENGINE is required to be available. A functional |
@@ -386,7 +386,7 @@ things, so we will simply illustrate the consequences as they apply to a | |||
386 | couple of simple cases and leave developers to consider these and the | 386 | couple of simple cases and leave developers to consider these and the |
387 | source code to openssl's builtin utilities as guides. | 387 | source code to openssl's builtin utilities as guides. |
388 | 388 | ||
389 | =head3 Using a specific ENGINE implementation | 389 | I<Using a specific ENGINE implementation> |
390 | 390 | ||
391 | Here we'll assume an application has been configured by its user or admin | 391 | Here we'll assume an application has been configured by its user or admin |
392 | to want to use the "ACME" ENGINE if it is available in the version of | 392 | to want to use the "ACME" ENGINE if it is available in the version of |
@@ -418,7 +418,7 @@ illustrates how to approach this; | |||
418 | /* Release the structural reference from ENGINE_by_id() */ | 418 | /* Release the structural reference from ENGINE_by_id() */ |
419 | ENGINE_free(e); | 419 | ENGINE_free(e); |
420 | 420 | ||
421 | =head3 Automatically using builtin ENGINE implementations | 421 | I<Automatically using builtin ENGINE implementations> |
422 | 422 | ||
423 | Here we'll assume we want to load and register all ENGINE implementations | 423 | Here we'll assume we want to load and register all ENGINE implementations |
424 | bundled with OpenSSL, such that for any cryptographic algorithm required by | 424 | bundled with OpenSSL, such that for any cryptographic algorithm required by |
@@ -469,7 +469,7 @@ in same cases both. ENGINE implementations should provide indications of | |||
469 | this in the descriptions attached to builtin control commands and/or in | 469 | this in the descriptions attached to builtin control commands and/or in |
470 | external product documentation. | 470 | external product documentation. |
471 | 471 | ||
472 | =head3 Issuing control commands to an ENGINE | 472 | I<Issuing control commands to an ENGINE> |
473 | 473 | ||
474 | Let's illustrate by example; a function for which the caller supplies the | 474 | Let's illustrate by example; a function for which the caller supplies the |
475 | name of the ENGINE it wishes to use, a table of string-pairs for use before | 475 | name of the ENGINE it wishes to use, a table of string-pairs for use before |
@@ -526,7 +526,7 @@ return success without doing anything. In this case we assume the user is | |||
526 | only supplying commands specific to the given ENGINE so we set this to | 526 | only supplying commands specific to the given ENGINE so we set this to |
527 | FALSE. | 527 | FALSE. |
528 | 528 | ||
529 | =head3 Discovering supported control commands | 529 | I<Discovering supported control commands> |
530 | 530 | ||
531 | It is possible to discover at run-time the names, numerical-ids, descriptions | 531 | It is possible to discover at run-time the names, numerical-ids, descriptions |
532 | and input parameters of the control commands supported from a structural | 532 | and input parameters of the control commands supported from a structural |
diff --git a/src/lib/libcrypto/dsa/dsa_lib.c b/src/lib/libcrypto/dsa/dsa_lib.c index da2cdfa3d6..4171af24c6 100644 --- a/src/lib/libcrypto/dsa/dsa_lib.c +++ b/src/lib/libcrypto/dsa/dsa_lib.c | |||
@@ -63,7 +63,9 @@ | |||
63 | #include <openssl/bn.h> | 63 | #include <openssl/bn.h> |
64 | #include <openssl/dsa.h> | 64 | #include <openssl/dsa.h> |
65 | #include <openssl/asn1.h> | 65 | #include <openssl/asn1.h> |
66 | #ifndef OPENSSL_NO_ENGINE | ||
66 | #include <openssl/engine.h> | 67 | #include <openssl/engine.h> |
68 | #endif | ||
67 | 69 | ||
68 | const char *DSA_version="DSA" OPENSSL_VERSION_PTEXT; | 70 | const char *DSA_version="DSA" OPENSSL_VERSION_PTEXT; |
69 | 71 | ||
@@ -93,11 +95,13 @@ int DSA_set_method(DSA *dsa, const DSA_METHOD *meth) | |||
93 | const DSA_METHOD *mtmp; | 95 | const DSA_METHOD *mtmp; |
94 | mtmp = dsa->meth; | 96 | mtmp = dsa->meth; |
95 | if (mtmp->finish) mtmp->finish(dsa); | 97 | if (mtmp->finish) mtmp->finish(dsa); |
98 | #ifndef OPENSSL_NO_ENGINE | ||
96 | if (dsa->engine) | 99 | if (dsa->engine) |
97 | { | 100 | { |
98 | ENGINE_finish(dsa->engine); | 101 | ENGINE_finish(dsa->engine); |
99 | dsa->engine = NULL; | 102 | dsa->engine = NULL; |
100 | } | 103 | } |
104 | #endif | ||
101 | dsa->meth = meth; | 105 | dsa->meth = meth; |
102 | if (meth->init) meth->init(dsa); | 106 | if (meth->init) meth->init(dsa); |
103 | return 1; | 107 | return 1; |
@@ -114,6 +118,7 @@ DSA *DSA_new_method(ENGINE *engine) | |||
114 | return(NULL); | 118 | return(NULL); |
115 | } | 119 | } |
116 | ret->meth = DSA_get_default_method(); | 120 | ret->meth = DSA_get_default_method(); |
121 | #ifndef OPENSSL_NO_ENGINE | ||
117 | if (engine) | 122 | if (engine) |
118 | { | 123 | { |
119 | if (!ENGINE_init(engine)) | 124 | if (!ENGINE_init(engine)) |
@@ -138,6 +143,7 @@ DSA *DSA_new_method(ENGINE *engine) | |||
138 | return NULL; | 143 | return NULL; |
139 | } | 144 | } |
140 | } | 145 | } |
146 | #endif | ||
141 | 147 | ||
142 | ret->pad=0; | 148 | ret->pad=0; |
143 | ret->version=0; | 149 | ret->version=0; |
@@ -158,8 +164,10 @@ DSA *DSA_new_method(ENGINE *engine) | |||
158 | CRYPTO_new_ex_data(CRYPTO_EX_INDEX_DSA, ret, &ret->ex_data); | 164 | CRYPTO_new_ex_data(CRYPTO_EX_INDEX_DSA, ret, &ret->ex_data); |
159 | if ((ret->meth->init != NULL) && !ret->meth->init(ret)) | 165 | if ((ret->meth->init != NULL) && !ret->meth->init(ret)) |
160 | { | 166 | { |
167 | #ifndef OPENSSL_NO_ENGINE | ||
161 | if (ret->engine) | 168 | if (ret->engine) |
162 | ENGINE_finish(ret->engine); | 169 | ENGINE_finish(ret->engine); |
170 | #endif | ||
163 | CRYPTO_free_ex_data(CRYPTO_EX_INDEX_DSA, ret, &ret->ex_data); | 171 | CRYPTO_free_ex_data(CRYPTO_EX_INDEX_DSA, ret, &ret->ex_data); |
164 | OPENSSL_free(ret); | 172 | OPENSSL_free(ret); |
165 | ret=NULL; | 173 | ret=NULL; |
@@ -189,8 +197,10 @@ void DSA_free(DSA *r) | |||
189 | 197 | ||
190 | if(r->meth->finish) | 198 | if(r->meth->finish) |
191 | r->meth->finish(r); | 199 | r->meth->finish(r); |
200 | #ifndef OPENSSL_NO_ENGINE | ||
192 | if(r->engine) | 201 | if(r->engine) |
193 | ENGINE_finish(r->engine); | 202 | ENGINE_finish(r->engine); |
203 | #endif | ||
194 | 204 | ||
195 | CRYPTO_free_ex_data(CRYPTO_EX_INDEX_DSA, r, &r->ex_data); | 205 | CRYPTO_free_ex_data(CRYPTO_EX_INDEX_DSA, r, &r->ex_data); |
196 | 206 | ||
@@ -224,7 +234,10 @@ int DSA_size(const DSA *r) | |||
224 | { | 234 | { |
225 | int ret,i; | 235 | int ret,i; |
226 | ASN1_INTEGER bs; | 236 | ASN1_INTEGER bs; |
227 | unsigned char buf[4]; | 237 | unsigned char buf[4]; /* 4 bytes looks really small. |
238 | However, i2d_ASN1_INTEGER() will not look | ||
239 | beyond the first byte, as long as the second | ||
240 | parameter is NULL. */ | ||
228 | 241 | ||
229 | i=BN_num_bits(r->q); | 242 | i=BN_num_bits(r->q); |
230 | bs.length=(i+7)/8; | 243 | bs.length=(i+7)/8; |
diff --git a/src/lib/libcrypto/dsa/dsa_ossl.c b/src/lib/libcrypto/dsa/dsa_ossl.c index 37dd5fc994..b9e7f3ea5c 100644 --- a/src/lib/libcrypto/dsa/dsa_ossl.c +++ b/src/lib/libcrypto/dsa/dsa_ossl.c | |||
@@ -64,7 +64,6 @@ | |||
64 | #include <openssl/dsa.h> | 64 | #include <openssl/dsa.h> |
65 | #include <openssl/rand.h> | 65 | #include <openssl/rand.h> |
66 | #include <openssl/asn1.h> | 66 | #include <openssl/asn1.h> |
67 | #include <openssl/engine.h> | ||
68 | 67 | ||
69 | static DSA_SIG *dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa); | 68 | static DSA_SIG *dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa); |
70 | static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp); | 69 | static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp); |
@@ -106,13 +105,15 @@ static DSA_SIG *dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa) | |||
106 | int i,reason=ERR_R_BN_LIB; | 105 | int i,reason=ERR_R_BN_LIB; |
107 | DSA_SIG *ret=NULL; | 106 | DSA_SIG *ret=NULL; |
108 | 107 | ||
108 | BN_init(&m); | ||
109 | BN_init(&xr); | ||
110 | |||
109 | if (!dsa->p || !dsa->q || !dsa->g) | 111 | if (!dsa->p || !dsa->q || !dsa->g) |
110 | { | 112 | { |
111 | reason=DSA_R_MISSING_PARAMETERS; | 113 | reason=DSA_R_MISSING_PARAMETERS; |
112 | goto err; | 114 | goto err; |
113 | } | 115 | } |
114 | BN_init(&m); | 116 | |
115 | BN_init(&xr); | ||
116 | s=BN_new(); | 117 | s=BN_new(); |
117 | if (s == NULL) goto err; | 118 | if (s == NULL) goto err; |
118 | 119 | ||
@@ -178,6 +179,9 @@ static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp) | |||
178 | DSAerr(DSA_F_DSA_SIGN_SETUP,DSA_R_MISSING_PARAMETERS); | 179 | DSAerr(DSA_F_DSA_SIGN_SETUP,DSA_R_MISSING_PARAMETERS); |
179 | return 0; | 180 | return 0; |
180 | } | 181 | } |
182 | |||
183 | BN_init(&k); | ||
184 | |||
181 | if (ctx_in == NULL) | 185 | if (ctx_in == NULL) |
182 | { | 186 | { |
183 | if ((ctx=BN_CTX_new()) == NULL) goto err; | 187 | if ((ctx=BN_CTX_new()) == NULL) goto err; |
@@ -185,7 +189,6 @@ static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp) | |||
185 | else | 189 | else |
186 | ctx=ctx_in; | 190 | ctx=ctx_in; |
187 | 191 | ||
188 | BN_init(&k); | ||
189 | if ((r=BN_new()) == NULL) goto err; | 192 | if ((r=BN_new()) == NULL) goto err; |
190 | kinv=NULL; | 193 | kinv=NULL; |
191 | 194 | ||
@@ -241,11 +244,12 @@ static int dsa_do_verify(const unsigned char *dgst, int dgst_len, DSA_SIG *sig, | |||
241 | return -1; | 244 | return -1; |
242 | } | 245 | } |
243 | 246 | ||
244 | if ((ctx=BN_CTX_new()) == NULL) goto err; | ||
245 | BN_init(&u1); | 247 | BN_init(&u1); |
246 | BN_init(&u2); | 248 | BN_init(&u2); |
247 | BN_init(&t1); | 249 | BN_init(&t1); |
248 | 250 | ||
251 | if ((ctx=BN_CTX_new()) == NULL) goto err; | ||
252 | |||
249 | if (BN_is_zero(sig->r) || sig->r->neg || BN_ucmp(sig->r, dsa->q) >= 0) | 253 | if (BN_is_zero(sig->r) || sig->r->neg || BN_ucmp(sig->r, dsa->q) >= 0) |
250 | { | 254 | { |
251 | ret = 0; | 255 | ret = 0; |
diff --git a/src/lib/libcrypto/dsa/dsa_sign.c b/src/lib/libcrypto/dsa/dsa_sign.c index e9469ca62f..89205026f0 100644 --- a/src/lib/libcrypto/dsa/dsa_sign.c +++ b/src/lib/libcrypto/dsa/dsa_sign.c | |||
@@ -64,7 +64,6 @@ | |||
64 | #include <openssl/dsa.h> | 64 | #include <openssl/dsa.h> |
65 | #include <openssl/rand.h> | 65 | #include <openssl/rand.h> |
66 | #include <openssl/asn1.h> | 66 | #include <openssl/asn1.h> |
67 | #include <openssl/engine.h> | ||
68 | 67 | ||
69 | DSA_SIG * DSA_do_sign(const unsigned char *dgst, int dlen, DSA *dsa) | 68 | DSA_SIG * DSA_do_sign(const unsigned char *dgst, int dlen, DSA *dsa) |
70 | { | 69 | { |
diff --git a/src/lib/libcrypto/dsa/dsa_vrf.c b/src/lib/libcrypto/dsa/dsa_vrf.c index 066c6b5b28..c4aeddd056 100644 --- a/src/lib/libcrypto/dsa/dsa_vrf.c +++ b/src/lib/libcrypto/dsa/dsa_vrf.c | |||
@@ -65,7 +65,6 @@ | |||
65 | #include <openssl/rand.h> | 65 | #include <openssl/rand.h> |
66 | #include <openssl/asn1.h> | 66 | #include <openssl/asn1.h> |
67 | #include <openssl/asn1_mac.h> | 67 | #include <openssl/asn1_mac.h> |
68 | #include <openssl/engine.h> | ||
69 | 68 | ||
70 | int DSA_do_verify(const unsigned char *dgst, int dgst_len, DSA_SIG *sig, | 69 | int DSA_do_verify(const unsigned char *dgst, int dgst_len, DSA_SIG *sig, |
71 | DSA *dsa) | 70 | DSA *dsa) |
diff --git a/src/lib/libcrypto/ec/ec.h b/src/lib/libcrypto/ec/ec.h index a52d4edf14..6d6a9b7127 100644 --- a/src/lib/libcrypto/ec/ec.h +++ b/src/lib/libcrypto/ec/ec.h | |||
@@ -195,7 +195,6 @@ void ERR_load_EC_strings(void); | |||
195 | #define EC_F_EC_GROUP_GET0_GENERATOR 139 | 195 | #define EC_F_EC_GROUP_GET0_GENERATOR 139 |
196 | #define EC_F_EC_GROUP_GET_COFACTOR 140 | 196 | #define EC_F_EC_GROUP_GET_COFACTOR 140 |
197 | #define EC_F_EC_GROUP_GET_CURVE_GFP 130 | 197 | #define EC_F_EC_GROUP_GET_CURVE_GFP 130 |
198 | #define EC_F_EC_GROUP_GET_EXTRA_DATA 107 | ||
199 | #define EC_F_EC_GROUP_GET_ORDER 141 | 198 | #define EC_F_EC_GROUP_GET_ORDER 141 |
200 | #define EC_F_EC_GROUP_NEW 108 | 199 | #define EC_F_EC_GROUP_NEW 108 |
201 | #define EC_F_EC_GROUP_PRECOMPUTE_MULT 142 | 200 | #define EC_F_EC_GROUP_PRECOMPUTE_MULT 142 |
@@ -232,7 +231,6 @@ void ERR_load_EC_strings(void); | |||
232 | #define EC_R_INVALID_FIELD 103 | 231 | #define EC_R_INVALID_FIELD 103 |
233 | #define EC_R_INVALID_FORM 104 | 232 | #define EC_R_INVALID_FORM 104 |
234 | #define EC_R_NOT_INITIALIZED 111 | 233 | #define EC_R_NOT_INITIALIZED 111 |
235 | #define EC_R_NO_SUCH_EXTRA_DATA 105 | ||
236 | #define EC_R_POINT_AT_INFINITY 106 | 234 | #define EC_R_POINT_AT_INFINITY 106 |
237 | #define EC_R_POINT_IS_NOT_ON_CURVE 107 | 235 | #define EC_R_POINT_IS_NOT_ON_CURVE 107 |
238 | #define EC_R_SLOT_FULL 108 | 236 | #define EC_R_SLOT_FULL 108 |
diff --git a/src/lib/libcrypto/ec/ec_err.c b/src/lib/libcrypto/ec/ec_err.c index 394cdc021f..d37b6aba87 100644 --- a/src/lib/libcrypto/ec/ec_err.c +++ b/src/lib/libcrypto/ec/ec_err.c | |||
@@ -84,7 +84,6 @@ static ERR_STRING_DATA EC_str_functs[]= | |||
84 | {ERR_PACK(0,EC_F_EC_GROUP_GET0_GENERATOR,0), "EC_GROUP_get0_generator"}, | 84 | {ERR_PACK(0,EC_F_EC_GROUP_GET0_GENERATOR,0), "EC_GROUP_get0_generator"}, |
85 | {ERR_PACK(0,EC_F_EC_GROUP_GET_COFACTOR,0), "EC_GROUP_get_cofactor"}, | 85 | {ERR_PACK(0,EC_F_EC_GROUP_GET_COFACTOR,0), "EC_GROUP_get_cofactor"}, |
86 | {ERR_PACK(0,EC_F_EC_GROUP_GET_CURVE_GFP,0), "EC_GROUP_get_curve_GFp"}, | 86 | {ERR_PACK(0,EC_F_EC_GROUP_GET_CURVE_GFP,0), "EC_GROUP_get_curve_GFp"}, |
87 | {ERR_PACK(0,EC_F_EC_GROUP_GET_EXTRA_DATA,0), "EC_GROUP_get_extra_data"}, | ||
88 | {ERR_PACK(0,EC_F_EC_GROUP_GET_ORDER,0), "EC_GROUP_get_order"}, | 87 | {ERR_PACK(0,EC_F_EC_GROUP_GET_ORDER,0), "EC_GROUP_get_order"}, |
89 | {ERR_PACK(0,EC_F_EC_GROUP_NEW,0), "EC_GROUP_new"}, | 88 | {ERR_PACK(0,EC_F_EC_GROUP_NEW,0), "EC_GROUP_new"}, |
90 | {ERR_PACK(0,EC_F_EC_GROUP_PRECOMPUTE_MULT,0), "EC_GROUP_precompute_mult"}, | 89 | {ERR_PACK(0,EC_F_EC_GROUP_PRECOMPUTE_MULT,0), "EC_GROUP_precompute_mult"}, |
@@ -124,7 +123,6 @@ static ERR_STRING_DATA EC_str_reasons[]= | |||
124 | {EC_R_INVALID_FIELD ,"invalid field"}, | 123 | {EC_R_INVALID_FIELD ,"invalid field"}, |
125 | {EC_R_INVALID_FORM ,"invalid form"}, | 124 | {EC_R_INVALID_FORM ,"invalid form"}, |
126 | {EC_R_NOT_INITIALIZED ,"not initialized"}, | 125 | {EC_R_NOT_INITIALIZED ,"not initialized"}, |
127 | {EC_R_NO_SUCH_EXTRA_DATA ,"no such extra data"}, | ||
128 | {EC_R_POINT_AT_INFINITY ,"point at infinity"}, | 126 | {EC_R_POINT_AT_INFINITY ,"point at infinity"}, |
129 | {EC_R_POINT_IS_NOT_ON_CURVE ,"point is not on curve"}, | 127 | {EC_R_POINT_IS_NOT_ON_CURVE ,"point is not on curve"}, |
130 | {EC_R_SLOT_FULL ,"slot full"}, | 128 | {EC_R_SLOT_FULL ,"slot full"}, |
diff --git a/src/lib/libcrypto/ec/ec_lib.c b/src/lib/libcrypto/ec/ec_lib.c index 0cf485de60..deb522060f 100644 --- a/src/lib/libcrypto/ec/ec_lib.c +++ b/src/lib/libcrypto/ec/ec_lib.c | |||
@@ -128,7 +128,7 @@ void EC_GROUP_clear_free(EC_GROUP *group) | |||
128 | 128 | ||
129 | EC_GROUP_clear_free_extra_data(group); | 129 | EC_GROUP_clear_free_extra_data(group); |
130 | 130 | ||
131 | memset(group, 0, sizeof *group); | 131 | OPENSSL_cleanse(group, sizeof *group); |
132 | OPENSSL_free(group); | 132 | OPENSSL_free(group); |
133 | } | 133 | } |
134 | 134 | ||
@@ -268,7 +268,9 @@ void *EC_GROUP_get_extra_data(const EC_GROUP *group, void *(*extra_data_dup_func | |||
268 | || (group->extra_data_free_func != extra_data_free_func) | 268 | || (group->extra_data_free_func != extra_data_free_func) |
269 | || (group->extra_data_clear_free_func != extra_data_clear_free_func)) | 269 | || (group->extra_data_clear_free_func != extra_data_clear_free_func)) |
270 | { | 270 | { |
271 | ECerr(EC_F_EC_GROUP_GET_EXTRA_DATA, EC_R_NO_SUCH_EXTRA_DATA); | 271 | #if 0 /* this was an error in 0.9.7, but that does not make a lot of sense */ |
272 | ECerr(..._F_EC_GROUP_GET_EXTRA_DATA, ..._R_NO_SUCH_EXTRA_DATA); | ||
273 | #endif | ||
272 | return NULL; | 274 | return NULL; |
273 | } | 275 | } |
274 | 276 | ||
@@ -357,7 +359,7 @@ void EC_POINT_clear_free(EC_POINT *point) | |||
357 | point->meth->point_clear_finish(point); | 359 | point->meth->point_clear_finish(point); |
358 | else if (point->meth != NULL && point->meth->point_finish != 0) | 360 | else if (point->meth != NULL && point->meth->point_finish != 0) |
359 | point->meth->point_finish(point); | 361 | point->meth->point_finish(point); |
360 | memset(point, 0, sizeof *point); | 362 | OPENSSL_cleanse(point, sizeof *point); |
361 | OPENSSL_free(point); | 363 | OPENSSL_free(point); |
362 | } | 364 | } |
363 | 365 | ||
diff --git a/src/lib/libcrypto/ec/ec_mult.c b/src/lib/libcrypto/ec/ec_mult.c index 603ba31b81..4dbc931120 100644 --- a/src/lib/libcrypto/ec/ec_mult.c +++ b/src/lib/libcrypto/ec/ec_mult.c | |||
@@ -209,6 +209,17 @@ int EC_POINTs_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar, | |||
209 | EC_POINT ***val_sub = NULL; /* pointers to sub-arrays of 'val' */ | 209 | EC_POINT ***val_sub = NULL; /* pointers to sub-arrays of 'val' */ |
210 | int ret = 0; | 210 | int ret = 0; |
211 | 211 | ||
212 | if (group->meth != r->meth) | ||
213 | { | ||
214 | ECerr(EC_F_EC_POINTS_MUL, EC_R_INCOMPATIBLE_OBJECTS); | ||
215 | return 0; | ||
216 | } | ||
217 | |||
218 | if ((scalar == NULL) && (num == 0)) | ||
219 | { | ||
220 | return EC_POINT_set_to_infinity(group, r); | ||
221 | } | ||
222 | |||
212 | if (scalar != NULL) | 223 | if (scalar != NULL) |
213 | { | 224 | { |
214 | generator = EC_GROUP_get0_generator(group); | 225 | generator = EC_GROUP_get0_generator(group); |
diff --git a/src/lib/libcrypto/engine/eng_all.c b/src/lib/libcrypto/engine/eng_all.c index b3030fe505..0f6992a40d 100644 --- a/src/lib/libcrypto/engine/eng_all.c +++ b/src/lib/libcrypto/engine/eng_all.c | |||
@@ -95,8 +95,19 @@ void ENGINE_load_builtin_engines(void) | |||
95 | #ifndef OPENSSL_NO_HW_4758_CCA | 95 | #ifndef OPENSSL_NO_HW_4758_CCA |
96 | ENGINE_load_4758cca(); | 96 | ENGINE_load_4758cca(); |
97 | #endif | 97 | #endif |
98 | #ifdef OPENSSL_OPENBSD_DEV_CRYPTO | 98 | #if defined(__OpenBSD__) || defined(__FreeBSD__) |
99 | ENGINE_load_openbsd_dev_crypto(); | 99 | ENGINE_load_cryptodev(); |
100 | #endif | 100 | #endif |
101 | #endif | 101 | #endif |
102 | } | 102 | } |
103 | |||
104 | #if defined(__OpenBSD__) || defined(__FreeBSD__) | ||
105 | void ENGINE_setup_bsd_cryptodev(void) { | ||
106 | static int bsd_cryptodev_default_loaded = 0; | ||
107 | if (!bsd_cryptodev_default_loaded) { | ||
108 | ENGINE_load_cryptodev(); | ||
109 | ENGINE_register_all_complete(); | ||
110 | } | ||
111 | bsd_cryptodev_default_loaded=1; | ||
112 | } | ||
113 | #endif | ||
diff --git a/src/lib/libcrypto/engine/eng_err.c b/src/lib/libcrypto/engine/eng_err.c index f6c5630395..814d95ee32 100644 --- a/src/lib/libcrypto/engine/eng_err.c +++ b/src/lib/libcrypto/engine/eng_err.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* crypto/engine/eng_err.c */ | 1 | /* crypto/engine/eng_err.c */ |
2 | /* ==================================================================== | 2 | /* ==================================================================== |
3 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | 3 | * Copyright (c) 1999-2002 The OpenSSL Project. All rights reserved. |
4 | * | 4 | * |
5 | * Redistribution and use in source and binary forms, with or without | 5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions | 6 | * modification, are permitted provided that the following conditions |
@@ -96,6 +96,7 @@ static ERR_STRING_DATA ENGINE_str_functs[]= | |||
96 | {ERR_PACK(0,ENGINE_F_ENGINE_SET_NAME,0), "ENGINE_set_name"}, | 96 | {ERR_PACK(0,ENGINE_F_ENGINE_SET_NAME,0), "ENGINE_set_name"}, |
97 | {ERR_PACK(0,ENGINE_F_ENGINE_TABLE_REGISTER,0), "ENGINE_TABLE_REGISTER"}, | 97 | {ERR_PACK(0,ENGINE_F_ENGINE_TABLE_REGISTER,0), "ENGINE_TABLE_REGISTER"}, |
98 | {ERR_PACK(0,ENGINE_F_ENGINE_UNLOAD_KEY,0), "ENGINE_UNLOAD_KEY"}, | 98 | {ERR_PACK(0,ENGINE_F_ENGINE_UNLOAD_KEY,0), "ENGINE_UNLOAD_KEY"}, |
99 | {ERR_PACK(0,ENGINE_F_ENGINE_UP_REF,0), "ENGINE_up_ref"}, | ||
99 | {ERR_PACK(0,ENGINE_F_INT_CTRL_HELPER,0), "INT_CTRL_HELPER"}, | 100 | {ERR_PACK(0,ENGINE_F_INT_CTRL_HELPER,0), "INT_CTRL_HELPER"}, |
100 | {ERR_PACK(0,ENGINE_F_INT_ENGINE_CONFIGURE,0), "INT_ENGINE_CONFIGURE"}, | 101 | {ERR_PACK(0,ENGINE_F_INT_ENGINE_CONFIGURE,0), "INT_ENGINE_CONFIGURE"}, |
101 | {ERR_PACK(0,ENGINE_F_LOG_MESSAGE,0), "LOG_MESSAGE"}, | 102 | {ERR_PACK(0,ENGINE_F_LOG_MESSAGE,0), "LOG_MESSAGE"}, |
diff --git a/src/lib/libcrypto/engine/eng_fat.c b/src/lib/libcrypto/engine/eng_fat.c index f7edb5ad32..0d7dae00b2 100644 --- a/src/lib/libcrypto/engine/eng_fat.c +++ b/src/lib/libcrypto/engine/eng_fat.c | |||
@@ -66,18 +66,18 @@ int ENGINE_set_default(ENGINE *e, unsigned int flags) | |||
66 | if((flags & ENGINE_METHOD_DIGESTS) && !ENGINE_set_default_digests(e)) | 66 | if((flags & ENGINE_METHOD_DIGESTS) && !ENGINE_set_default_digests(e)) |
67 | return 0; | 67 | return 0; |
68 | #ifndef OPENSSL_NO_RSA | 68 | #ifndef OPENSSL_NO_RSA |
69 | if((flags & ENGINE_METHOD_RSA) & !ENGINE_set_default_RSA(e)) | 69 | if((flags & ENGINE_METHOD_RSA) && !ENGINE_set_default_RSA(e)) |
70 | return 0; | 70 | return 0; |
71 | #endif | 71 | #endif |
72 | #ifndef OPENSSL_NO_DSA | 72 | #ifndef OPENSSL_NO_DSA |
73 | if((flags & ENGINE_METHOD_DSA) & !ENGINE_set_default_DSA(e)) | 73 | if((flags & ENGINE_METHOD_DSA) && !ENGINE_set_default_DSA(e)) |
74 | return 0; | 74 | return 0; |
75 | #endif | 75 | #endif |
76 | #ifndef OPENSSL_NO_DH | 76 | #ifndef OPENSSL_NO_DH |
77 | if((flags & ENGINE_METHOD_DH) & !ENGINE_set_default_DH(e)) | 77 | if((flags & ENGINE_METHOD_DH) && !ENGINE_set_default_DH(e)) |
78 | return 0; | 78 | return 0; |
79 | #endif | 79 | #endif |
80 | if((flags & ENGINE_METHOD_RAND) & !ENGINE_set_default_RAND(e)) | 80 | if((flags & ENGINE_METHOD_RAND) && !ENGINE_set_default_RAND(e)) |
81 | return 0; | 81 | return 0; |
82 | return 1; | 82 | return 1; |
83 | } | 83 | } |
diff --git a/src/lib/libcrypto/engine/eng_init.c b/src/lib/libcrypto/engine/eng_init.c index 98caa21e32..170c1791b3 100644 --- a/src/lib/libcrypto/engine/eng_init.c +++ b/src/lib/libcrypto/engine/eng_init.c | |||
@@ -93,7 +93,7 @@ int engine_unlocked_finish(ENGINE *e, int unlock_for_handlers) | |||
93 | * there's a chance that both threads will together take the count from | 93 | * there's a chance that both threads will together take the count from |
94 | * 2 to 0 without either calling finish(). */ | 94 | * 2 to 0 without either calling finish(). */ |
95 | e->funct_ref--; | 95 | e->funct_ref--; |
96 | engine_ref_debug(e, 1, -1) | 96 | engine_ref_debug(e, 1, -1); |
97 | if((e->funct_ref == 0) && e->finish) | 97 | if((e->funct_ref == 0) && e->finish) |
98 | { | 98 | { |
99 | if(unlock_for_handlers) | 99 | if(unlock_for_handlers) |
diff --git a/src/lib/libcrypto/engine/eng_list.c b/src/lib/libcrypto/engine/eng_list.c index 0c220558e7..1cc3217f4c 100644 --- a/src/lib/libcrypto/engine/eng_list.c +++ b/src/lib/libcrypto/engine/eng_list.c | |||
@@ -191,14 +191,14 @@ ENGINE *ENGINE_get_first(void) | |||
191 | { | 191 | { |
192 | ENGINE *ret; | 192 | ENGINE *ret; |
193 | 193 | ||
194 | CRYPTO_r_lock(CRYPTO_LOCK_ENGINE); | 194 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); |
195 | ret = engine_list_head; | 195 | ret = engine_list_head; |
196 | if(ret) | 196 | if(ret) |
197 | { | 197 | { |
198 | ret->struct_ref++; | 198 | ret->struct_ref++; |
199 | engine_ref_debug(ret, 0, 1) | 199 | engine_ref_debug(ret, 0, 1) |
200 | } | 200 | } |
201 | CRYPTO_r_unlock(CRYPTO_LOCK_ENGINE); | 201 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); |
202 | return ret; | 202 | return ret; |
203 | } | 203 | } |
204 | 204 | ||
@@ -206,14 +206,14 @@ ENGINE *ENGINE_get_last(void) | |||
206 | { | 206 | { |
207 | ENGINE *ret; | 207 | ENGINE *ret; |
208 | 208 | ||
209 | CRYPTO_r_lock(CRYPTO_LOCK_ENGINE); | 209 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); |
210 | ret = engine_list_tail; | 210 | ret = engine_list_tail; |
211 | if(ret) | 211 | if(ret) |
212 | { | 212 | { |
213 | ret->struct_ref++; | 213 | ret->struct_ref++; |
214 | engine_ref_debug(ret, 0, 1) | 214 | engine_ref_debug(ret, 0, 1) |
215 | } | 215 | } |
216 | CRYPTO_r_unlock(CRYPTO_LOCK_ENGINE); | 216 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); |
217 | return ret; | 217 | return ret; |
218 | } | 218 | } |
219 | 219 | ||
@@ -227,7 +227,7 @@ ENGINE *ENGINE_get_next(ENGINE *e) | |||
227 | ERR_R_PASSED_NULL_PARAMETER); | 227 | ERR_R_PASSED_NULL_PARAMETER); |
228 | return 0; | 228 | return 0; |
229 | } | 229 | } |
230 | CRYPTO_r_lock(CRYPTO_LOCK_ENGINE); | 230 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); |
231 | ret = e->next; | 231 | ret = e->next; |
232 | if(ret) | 232 | if(ret) |
233 | { | 233 | { |
@@ -235,7 +235,7 @@ ENGINE *ENGINE_get_next(ENGINE *e) | |||
235 | ret->struct_ref++; | 235 | ret->struct_ref++; |
236 | engine_ref_debug(ret, 0, 1) | 236 | engine_ref_debug(ret, 0, 1) |
237 | } | 237 | } |
238 | CRYPTO_r_unlock(CRYPTO_LOCK_ENGINE); | 238 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); |
239 | /* Release the structural reference to the previous ENGINE */ | 239 | /* Release the structural reference to the previous ENGINE */ |
240 | ENGINE_free(e); | 240 | ENGINE_free(e); |
241 | return ret; | 241 | return ret; |
@@ -250,7 +250,7 @@ ENGINE *ENGINE_get_prev(ENGINE *e) | |||
250 | ERR_R_PASSED_NULL_PARAMETER); | 250 | ERR_R_PASSED_NULL_PARAMETER); |
251 | return 0; | 251 | return 0; |
252 | } | 252 | } |
253 | CRYPTO_r_lock(CRYPTO_LOCK_ENGINE); | 253 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); |
254 | ret = e->prev; | 254 | ret = e->prev; |
255 | if(ret) | 255 | if(ret) |
256 | { | 256 | { |
@@ -258,7 +258,7 @@ ENGINE *ENGINE_get_prev(ENGINE *e) | |||
258 | ret->struct_ref++; | 258 | ret->struct_ref++; |
259 | engine_ref_debug(ret, 0, 1) | 259 | engine_ref_debug(ret, 0, 1) |
260 | } | 260 | } |
261 | CRYPTO_r_unlock(CRYPTO_LOCK_ENGINE); | 261 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); |
262 | /* Release the structural reference to the previous ENGINE */ | 262 | /* Release the structural reference to the previous ENGINE */ |
263 | ENGINE_free(e); | 263 | ENGINE_free(e); |
264 | return ret; | 264 | return ret; |
@@ -346,7 +346,7 @@ ENGINE *ENGINE_by_id(const char *id) | |||
346 | ERR_R_PASSED_NULL_PARAMETER); | 346 | ERR_R_PASSED_NULL_PARAMETER); |
347 | return NULL; | 347 | return NULL; |
348 | } | 348 | } |
349 | CRYPTO_r_lock(CRYPTO_LOCK_ENGINE); | 349 | CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); |
350 | iterator = engine_list_head; | 350 | iterator = engine_list_head; |
351 | while(iterator && (strcmp(id, iterator->id) != 0)) | 351 | while(iterator && (strcmp(id, iterator->id) != 0)) |
352 | iterator = iterator->next; | 352 | iterator = iterator->next; |
@@ -372,7 +372,7 @@ ENGINE *ENGINE_by_id(const char *id) | |||
372 | engine_ref_debug(iterator, 0, 1) | 372 | engine_ref_debug(iterator, 0, 1) |
373 | } | 373 | } |
374 | } | 374 | } |
375 | CRYPTO_r_unlock(CRYPTO_LOCK_ENGINE); | 375 | CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); |
376 | if(iterator == NULL) | 376 | if(iterator == NULL) |
377 | { | 377 | { |
378 | ENGINEerr(ENGINE_F_ENGINE_BY_ID, | 378 | ENGINEerr(ENGINE_F_ENGINE_BY_ID, |
@@ -381,3 +381,14 @@ ENGINE *ENGINE_by_id(const char *id) | |||
381 | } | 381 | } |
382 | return iterator; | 382 | return iterator; |
383 | } | 383 | } |
384 | |||
385 | int ENGINE_up_ref(ENGINE *e) | ||
386 | { | ||
387 | if (e == NULL) | ||
388 | { | ||
389 | ENGINEerr(ENGINE_F_ENGINE_UP_REF,ERR_R_PASSED_NULL_PARAMETER); | ||
390 | return 0; | ||
391 | } | ||
392 | CRYPTO_add(&e->struct_ref,1,CRYPTO_LOCK_ENGINE); | ||
393 | return 1; | ||
394 | } | ||
diff --git a/src/lib/libcrypto/engine/eng_openssl.c b/src/lib/libcrypto/engine/eng_openssl.c index e9d976f46b..54579eea2e 100644 --- a/src/lib/libcrypto/engine/eng_openssl.c +++ b/src/lib/libcrypto/engine/eng_openssl.c | |||
@@ -63,6 +63,7 @@ | |||
63 | #include <openssl/engine.h> | 63 | #include <openssl/engine.h> |
64 | #include <openssl/dso.h> | 64 | #include <openssl/dso.h> |
65 | #include <openssl/pem.h> | 65 | #include <openssl/pem.h> |
66 | #include <openssl/evp.h> | ||
66 | 67 | ||
67 | /* This testing gunk is implemented (and explained) lower down. It also assumes | 68 | /* This testing gunk is implemented (and explained) lower down. It also assumes |
68 | * the application explicitly calls "ENGINE_load_openssl()" because this is no | 69 | * the application explicitly calls "ENGINE_load_openssl()" because this is no |
@@ -78,6 +79,21 @@ | |||
78 | /* #define TEST_ENG_OPENSSL_SHA_P_UPDATE */ | 79 | /* #define TEST_ENG_OPENSSL_SHA_P_UPDATE */ |
79 | /* #define TEST_ENG_OPENSSL_SHA_P_FINAL */ | 80 | /* #define TEST_ENG_OPENSSL_SHA_P_FINAL */ |
80 | 81 | ||
82 | /* Now check what of those algorithms are actually enabled */ | ||
83 | #ifdef OPENSSL_NO_RC4 | ||
84 | #undef TEST_ENG_OPENSSL_RC4 | ||
85 | #undef TEST_ENG_OPENSSL_RC4_OTHERS | ||
86 | #undef TEST_ENG_OPENSSL_RC4_P_INIT | ||
87 | #undef TEST_ENG_OPENSSL_RC4_P_CIPHER | ||
88 | #endif | ||
89 | #if defined(OPENSSL_NO_SHA) || defined(OPENSSL_NO_SHA0) || defined(OPENSSL_NO_SHA1) | ||
90 | #undef TEST_ENG_OPENSSL_SHA | ||
91 | #undef TEST_ENG_OPENSSL_SHA_OTHERS | ||
92 | #undef TEST_ENG_OPENSSL_SHA_P_INIT | ||
93 | #undef TEST_ENG_OPENSSL_SHA_P_UPDATE | ||
94 | #undef TEST_ENG_OPENSSL_SHA_P_FINAL | ||
95 | #endif | ||
96 | |||
81 | #ifdef TEST_ENG_OPENSSL_RC4 | 97 | #ifdef TEST_ENG_OPENSSL_RC4 |
82 | static int openssl_ciphers(ENGINE *e, const EVP_CIPHER **cipher, | 98 | static int openssl_ciphers(ENGINE *e, const EVP_CIPHER **cipher, |
83 | const int **nids, int nid); | 99 | const int **nids, int nid); |
@@ -180,7 +196,6 @@ IMPLEMENT_DYNAMIC_BIND_FN(bind_fn) | |||
180 | * the "init_key" handler is called. | 196 | * the "init_key" handler is called. |
181 | * TEST_ENG_OPENSSL_RC4_P_CIPHER - ditto for the "cipher" handler. | 197 | * TEST_ENG_OPENSSL_RC4_P_CIPHER - ditto for the "cipher" handler. |
182 | */ | 198 | */ |
183 | #include <openssl/evp.h> | ||
184 | #include <openssl/rc4.h> | 199 | #include <openssl/rc4.h> |
185 | #define TEST_RC4_KEY_SIZE 16 | 200 | #define TEST_RC4_KEY_SIZE 16 |
186 | static int test_cipher_nids[] = {NID_rc4,NID_rc4_40}; | 201 | static int test_cipher_nids[] = {NID_rc4,NID_rc4_40}; |
@@ -265,7 +280,6 @@ static int openssl_ciphers(ENGINE *e, const EVP_CIPHER **cipher, | |||
265 | 280 | ||
266 | #ifdef TEST_ENG_OPENSSL_SHA | 281 | #ifdef TEST_ENG_OPENSSL_SHA |
267 | /* Much the same sort of comment as for TEST_ENG_OPENSSL_RC4 */ | 282 | /* Much the same sort of comment as for TEST_ENG_OPENSSL_RC4 */ |
268 | #include <openssl/evp.h> | ||
269 | #include <openssl/sha.h> | 283 | #include <openssl/sha.h> |
270 | static int test_digest_nids[] = {NID_sha1}; | 284 | static int test_digest_nids[] = {NID_sha1}; |
271 | static int test_digest_nids_number = 1; | 285 | static int test_digest_nids_number = 1; |
diff --git a/src/lib/libcrypto/engine/engine.h b/src/lib/libcrypto/engine/engine.h index cf06618286..8686879e1a 100644 --- a/src/lib/libcrypto/engine/engine.h +++ b/src/lib/libcrypto/engine/engine.h | |||
@@ -59,6 +59,12 @@ | |||
59 | #ifndef HEADER_ENGINE_H | 59 | #ifndef HEADER_ENGINE_H |
60 | #define HEADER_ENGINE_H | 60 | #define HEADER_ENGINE_H |
61 | 61 | ||
62 | #include <openssl/opensslconf.h> | ||
63 | |||
64 | #ifdef OPENSSL_NO_ENGINE | ||
65 | #error ENGINE is disabled. | ||
66 | #endif | ||
67 | |||
62 | #include <openssl/ossl_typ.h> | 68 | #include <openssl/ossl_typ.h> |
63 | #include <openssl/bn.h> | 69 | #include <openssl/bn.h> |
64 | #ifndef OPENSSL_NO_RSA | 70 | #ifndef OPENSSL_NO_RSA |
@@ -307,7 +313,7 @@ void ENGINE_load_ubsec(void); | |||
307 | void ENGINE_load_aep(void); | 313 | void ENGINE_load_aep(void); |
308 | void ENGINE_load_sureware(void); | 314 | void ENGINE_load_sureware(void); |
309 | void ENGINE_load_4758cca(void); | 315 | void ENGINE_load_4758cca(void); |
310 | void ENGINE_load_openbsd_dev_crypto(void); | 316 | void ENGINE_load_cryptodev(void); |
311 | void ENGINE_load_builtin_engines(void); | 317 | void ENGINE_load_builtin_engines(void); |
312 | 318 | ||
313 | /* Get and set global flags (ENGINE_TABLE_FLAG_***) for the implementation | 319 | /* Get and set global flags (ENGINE_TABLE_FLAG_***) for the implementation |
@@ -406,6 +412,7 @@ int ENGINE_ctrl_cmd_string(ENGINE *e, const char *cmd_name, const char *arg, | |||
406 | * compatibility! */ | 412 | * compatibility! */ |
407 | ENGINE *ENGINE_new(void); | 413 | ENGINE *ENGINE_new(void); |
408 | int ENGINE_free(ENGINE *e); | 414 | int ENGINE_free(ENGINE *e); |
415 | int ENGINE_up_ref(ENGINE *e); | ||
409 | int ENGINE_set_id(ENGINE *e, const char *id); | 416 | int ENGINE_set_id(ENGINE *e, const char *id); |
410 | int ENGINE_set_name(ENGINE *e, const char *name); | 417 | int ENGINE_set_name(ENGINE *e, const char *name); |
411 | int ENGINE_set_RSA(ENGINE *e, const RSA_METHOD *rsa_meth); | 418 | int ENGINE_set_RSA(ENGINE *e, const RSA_METHOD *rsa_meth); |
@@ -662,6 +669,7 @@ void ERR_load_ENGINE_strings(void); | |||
662 | #define ENGINE_F_ENGINE_SET_NAME 130 | 669 | #define ENGINE_F_ENGINE_SET_NAME 130 |
663 | #define ENGINE_F_ENGINE_TABLE_REGISTER 184 | 670 | #define ENGINE_F_ENGINE_TABLE_REGISTER 184 |
664 | #define ENGINE_F_ENGINE_UNLOAD_KEY 152 | 671 | #define ENGINE_F_ENGINE_UNLOAD_KEY 152 |
672 | #define ENGINE_F_ENGINE_UP_REF 190 | ||
665 | #define ENGINE_F_INT_CTRL_HELPER 172 | 673 | #define ENGINE_F_INT_CTRL_HELPER 172 |
666 | #define ENGINE_F_INT_ENGINE_CONFIGURE 188 | 674 | #define ENGINE_F_INT_ENGINE_CONFIGURE 188 |
667 | #define ENGINE_F_LOG_MESSAGE 141 | 675 | #define ENGINE_F_LOG_MESSAGE 141 |
diff --git a/src/lib/libcrypto/engine/tb_cipher.c b/src/lib/libcrypto/engine/tb_cipher.c index c5a50fc910..50b3cec1fa 100644 --- a/src/lib/libcrypto/engine/tb_cipher.c +++ b/src/lib/libcrypto/engine/tb_cipher.c | |||
@@ -81,7 +81,7 @@ int ENGINE_register_ciphers(ENGINE *e) | |||
81 | int num_nids = e->ciphers(e, NULL, &nids, 0); | 81 | int num_nids = e->ciphers(e, NULL, &nids, 0); |
82 | if(num_nids > 0) | 82 | if(num_nids > 0) |
83 | return engine_table_register(&cipher_table, | 83 | return engine_table_register(&cipher_table, |
84 | &engine_unregister_all_ciphers, e, nids, | 84 | engine_unregister_all_ciphers, e, nids, |
85 | num_nids, 0); | 85 | num_nids, 0); |
86 | } | 86 | } |
87 | return 1; | 87 | return 1; |
@@ -103,7 +103,7 @@ int ENGINE_set_default_ciphers(ENGINE *e) | |||
103 | int num_nids = e->ciphers(e, NULL, &nids, 0); | 103 | int num_nids = e->ciphers(e, NULL, &nids, 0); |
104 | if(num_nids > 0) | 104 | if(num_nids > 0) |
105 | return engine_table_register(&cipher_table, | 105 | return engine_table_register(&cipher_table, |
106 | &engine_unregister_all_ciphers, e, nids, | 106 | engine_unregister_all_ciphers, e, nids, |
107 | num_nids, 1); | 107 | num_nids, 1); |
108 | } | 108 | } |
109 | return 1; | 109 | return 1; |
diff --git a/src/lib/libcrypto/engine/tb_dh.c b/src/lib/libcrypto/engine/tb_dh.c index c9347235ea..e290e1702b 100644 --- a/src/lib/libcrypto/engine/tb_dh.c +++ b/src/lib/libcrypto/engine/tb_dh.c | |||
@@ -78,7 +78,7 @@ int ENGINE_register_DH(ENGINE *e) | |||
78 | { | 78 | { |
79 | if(e->dh_meth) | 79 | if(e->dh_meth) |
80 | return engine_table_register(&dh_table, | 80 | return engine_table_register(&dh_table, |
81 | &engine_unregister_all_DH, e, &dummy_nid, 1, 0); | 81 | engine_unregister_all_DH, e, &dummy_nid, 1, 0); |
82 | return 1; | 82 | return 1; |
83 | } | 83 | } |
84 | 84 | ||
@@ -94,7 +94,7 @@ int ENGINE_set_default_DH(ENGINE *e) | |||
94 | { | 94 | { |
95 | if(e->dh_meth) | 95 | if(e->dh_meth) |
96 | return engine_table_register(&dh_table, | 96 | return engine_table_register(&dh_table, |
97 | &engine_unregister_all_DH, e, &dummy_nid, 1, 1); | 97 | engine_unregister_all_DH, e, &dummy_nid, 1, 1); |
98 | return 1; | 98 | return 1; |
99 | } | 99 | } |
100 | 100 | ||
diff --git a/src/lib/libcrypto/engine/tb_digest.c b/src/lib/libcrypto/engine/tb_digest.c index 2c4dd6f796..e82d2a17c9 100644 --- a/src/lib/libcrypto/engine/tb_digest.c +++ b/src/lib/libcrypto/engine/tb_digest.c | |||
@@ -81,7 +81,7 @@ int ENGINE_register_digests(ENGINE *e) | |||
81 | int num_nids = e->digests(e, NULL, &nids, 0); | 81 | int num_nids = e->digests(e, NULL, &nids, 0); |
82 | if(num_nids > 0) | 82 | if(num_nids > 0) |
83 | return engine_table_register(&digest_table, | 83 | return engine_table_register(&digest_table, |
84 | &engine_unregister_all_digests, e, nids, | 84 | engine_unregister_all_digests, e, nids, |
85 | num_nids, 0); | 85 | num_nids, 0); |
86 | } | 86 | } |
87 | return 1; | 87 | return 1; |
@@ -103,7 +103,7 @@ int ENGINE_set_default_digests(ENGINE *e) | |||
103 | int num_nids = e->digests(e, NULL, &nids, 0); | 103 | int num_nids = e->digests(e, NULL, &nids, 0); |
104 | if(num_nids > 0) | 104 | if(num_nids > 0) |
105 | return engine_table_register(&digest_table, | 105 | return engine_table_register(&digest_table, |
106 | &engine_unregister_all_digests, e, nids, | 106 | engine_unregister_all_digests, e, nids, |
107 | num_nids, 1); | 107 | num_nids, 1); |
108 | } | 108 | } |
109 | return 1; | 109 | return 1; |
diff --git a/src/lib/libcrypto/engine/tb_dsa.c b/src/lib/libcrypto/engine/tb_dsa.c index e9209476b8..80170591f2 100644 --- a/src/lib/libcrypto/engine/tb_dsa.c +++ b/src/lib/libcrypto/engine/tb_dsa.c | |||
@@ -78,7 +78,7 @@ int ENGINE_register_DSA(ENGINE *e) | |||
78 | { | 78 | { |
79 | if(e->dsa_meth) | 79 | if(e->dsa_meth) |
80 | return engine_table_register(&dsa_table, | 80 | return engine_table_register(&dsa_table, |
81 | &engine_unregister_all_DSA, e, &dummy_nid, 1, 0); | 81 | engine_unregister_all_DSA, e, &dummy_nid, 1, 0); |
82 | return 1; | 82 | return 1; |
83 | } | 83 | } |
84 | 84 | ||
@@ -94,7 +94,7 @@ int ENGINE_set_default_DSA(ENGINE *e) | |||
94 | { | 94 | { |
95 | if(e->dsa_meth) | 95 | if(e->dsa_meth) |
96 | return engine_table_register(&dsa_table, | 96 | return engine_table_register(&dsa_table, |
97 | &engine_unregister_all_DSA, e, &dummy_nid, 1, 0); | 97 | engine_unregister_all_DSA, e, &dummy_nid, 1, 0); |
98 | return 1; | 98 | return 1; |
99 | } | 99 | } |
100 | 100 | ||
diff --git a/src/lib/libcrypto/engine/tb_rand.c b/src/lib/libcrypto/engine/tb_rand.c index 0b1d031f1e..69b67111bc 100644 --- a/src/lib/libcrypto/engine/tb_rand.c +++ b/src/lib/libcrypto/engine/tb_rand.c | |||
@@ -78,7 +78,7 @@ int ENGINE_register_RAND(ENGINE *e) | |||
78 | { | 78 | { |
79 | if(e->rand_meth) | 79 | if(e->rand_meth) |
80 | return engine_table_register(&rand_table, | 80 | return engine_table_register(&rand_table, |
81 | &engine_unregister_all_RAND, e, &dummy_nid, 1, 0); | 81 | engine_unregister_all_RAND, e, &dummy_nid, 1, 0); |
82 | return 1; | 82 | return 1; |
83 | } | 83 | } |
84 | 84 | ||
@@ -94,7 +94,7 @@ int ENGINE_set_default_RAND(ENGINE *e) | |||
94 | { | 94 | { |
95 | if(e->rand_meth) | 95 | if(e->rand_meth) |
96 | return engine_table_register(&rand_table, | 96 | return engine_table_register(&rand_table, |
97 | &engine_unregister_all_RAND, e, &dummy_nid, 1, 1); | 97 | engine_unregister_all_RAND, e, &dummy_nid, 1, 1); |
98 | return 1; | 98 | return 1; |
99 | } | 99 | } |
100 | 100 | ||
diff --git a/src/lib/libcrypto/engine/tb_rsa.c b/src/lib/libcrypto/engine/tb_rsa.c index f84fea3968..fee4867f52 100644 --- a/src/lib/libcrypto/engine/tb_rsa.c +++ b/src/lib/libcrypto/engine/tb_rsa.c | |||
@@ -78,7 +78,7 @@ int ENGINE_register_RSA(ENGINE *e) | |||
78 | { | 78 | { |
79 | if(e->rsa_meth) | 79 | if(e->rsa_meth) |
80 | return engine_table_register(&rsa_table, | 80 | return engine_table_register(&rsa_table, |
81 | &engine_unregister_all_RSA, e, &dummy_nid, 1, 0); | 81 | engine_unregister_all_RSA, e, &dummy_nid, 1, 0); |
82 | return 1; | 82 | return 1; |
83 | } | 83 | } |
84 | 84 | ||
@@ -94,7 +94,7 @@ int ENGINE_set_default_RSA(ENGINE *e) | |||
94 | { | 94 | { |
95 | if(e->rsa_meth) | 95 | if(e->rsa_meth) |
96 | return engine_table_register(&rsa_table, | 96 | return engine_table_register(&rsa_table, |
97 | &engine_unregister_all_RSA, e, &dummy_nid, 1, 1); | 97 | engine_unregister_all_RSA, e, &dummy_nid, 1, 1); |
98 | return 1; | 98 | return 1; |
99 | } | 99 | } |
100 | 100 | ||
diff --git a/src/lib/libcrypto/err/err.c b/src/lib/libcrypto/err/err.c index 5abe44e6d5..b873270c04 100644 --- a/src/lib/libcrypto/err/err.c +++ b/src/lib/libcrypto/err/err.c | |||
@@ -211,6 +211,7 @@ static ERR_STRING_DATA ERR_str_reasons[]= | |||
211 | 211 | ||
212 | {0,NULL}, | 212 | {0,NULL}, |
213 | }; | 213 | }; |
214 | #endif | ||
214 | 215 | ||
215 | 216 | ||
216 | /* Define the predeclared (but externally opaque) "ERR_FNS" type */ | 217 | /* Define the predeclared (but externally opaque) "ERR_FNS" type */ |
@@ -491,6 +492,7 @@ static int int_err_get_next_lib(void) | |||
491 | } | 492 | } |
492 | 493 | ||
493 | 494 | ||
495 | #ifndef OPENSSL_NO_ERR | ||
494 | #define NUM_SYS_STR_REASONS 127 | 496 | #define NUM_SYS_STR_REASONS 127 |
495 | #define LEN_SYS_STR_REASON 32 | 497 | #define LEN_SYS_STR_REASON 32 |
496 | 498 | ||
diff --git a/src/lib/libcrypto/err/err_all.c b/src/lib/libcrypto/err/err_all.c index 90029fd159..dc505d9d9d 100644 --- a/src/lib/libcrypto/err/err_all.c +++ b/src/lib/libcrypto/err/err_all.c | |||
@@ -82,7 +82,9 @@ | |||
82 | #include <openssl/pkcs12.h> | 82 | #include <openssl/pkcs12.h> |
83 | #include <openssl/rand.h> | 83 | #include <openssl/rand.h> |
84 | #include <openssl/dso.h> | 84 | #include <openssl/dso.h> |
85 | #ifndef OPENSSL_NO_ENGINE | ||
85 | #include <openssl/engine.h> | 86 | #include <openssl/engine.h> |
87 | #endif | ||
86 | #include <openssl/ocsp.h> | 88 | #include <openssl/ocsp.h> |
87 | #include <openssl/err.h> | 89 | #include <openssl/err.h> |
88 | 90 | ||
@@ -122,7 +124,9 @@ void ERR_load_crypto_strings(void) | |||
122 | ERR_load_PKCS12_strings(); | 124 | ERR_load_PKCS12_strings(); |
123 | ERR_load_RAND_strings(); | 125 | ERR_load_RAND_strings(); |
124 | ERR_load_DSO_strings(); | 126 | ERR_load_DSO_strings(); |
127 | #ifndef OPENSSL_NO_ENGINE | ||
125 | ERR_load_ENGINE_strings(); | 128 | ERR_load_ENGINE_strings(); |
129 | #endif | ||
126 | ERR_load_OCSP_strings(); | 130 | ERR_load_OCSP_strings(); |
127 | ERR_load_UI_strings(); | 131 | ERR_load_UI_strings(); |
128 | #endif | 132 | #endif |
diff --git a/src/lib/libcrypto/err/err_prn.c b/src/lib/libcrypto/err/err_prn.c index c156663f0e..81e34bd6ce 100644 --- a/src/lib/libcrypto/err/err_prn.c +++ b/src/lib/libcrypto/err/err_prn.c | |||
@@ -62,7 +62,6 @@ | |||
62 | #include "cryptlib.h" | 62 | #include "cryptlib.h" |
63 | #include <openssl/buffer.h> | 63 | #include <openssl/buffer.h> |
64 | #include <openssl/err.h> | 64 | #include <openssl/err.h> |
65 | #include <openssl/crypto.h> | ||
66 | 65 | ||
67 | void ERR_print_errors_cb(int (*cb)(const char *str, size_t len, void *u), | 66 | void ERR_print_errors_cb(int (*cb)(const char *str, size_t len, void *u), |
68 | void *u) | 67 | void *u) |
diff --git a/src/lib/libcrypto/evp/bio_b64.c b/src/lib/libcrypto/evp/bio_b64.c index f12eac1b55..6e550f6a43 100644 --- a/src/lib/libcrypto/evp/bio_b64.c +++ b/src/lib/libcrypto/evp/bio_b64.c | |||
@@ -165,6 +165,7 @@ static int b64_read(BIO *b, char *out, int outl) | |||
165 | { | 165 | { |
166 | i=ctx->buf_len-ctx->buf_off; | 166 | i=ctx->buf_len-ctx->buf_off; |
167 | if (i > outl) i=outl; | 167 | if (i > outl) i=outl; |
168 | OPENSSL_assert(ctx->buf_off+i < sizeof ctx->buf); | ||
168 | memcpy(out,&(ctx->buf[ctx->buf_off]),i); | 169 | memcpy(out,&(ctx->buf[ctx->buf_off]),i); |
169 | ret=i; | 170 | ret=i; |
170 | out+=i; | 171 | out+=i; |
diff --git a/src/lib/libcrypto/evp/bio_enc.c b/src/lib/libcrypto/evp/bio_enc.c index 64fb2353af..ab81851503 100644 --- a/src/lib/libcrypto/evp/bio_enc.c +++ b/src/lib/libcrypto/evp/bio_enc.c | |||
@@ -132,7 +132,7 @@ static int enc_free(BIO *a) | |||
132 | if (a == NULL) return(0); | 132 | if (a == NULL) return(0); |
133 | b=(BIO_ENC_CTX *)a->ptr; | 133 | b=(BIO_ENC_CTX *)a->ptr; |
134 | EVP_CIPHER_CTX_cleanup(&(b->cipher)); | 134 | EVP_CIPHER_CTX_cleanup(&(b->cipher)); |
135 | memset(a->ptr,0,sizeof(BIO_ENC_CTX)); | 135 | OPENSSL_cleanse(a->ptr,sizeof(BIO_ENC_CTX)); |
136 | OPENSSL_free(a->ptr); | 136 | OPENSSL_free(a->ptr); |
137 | a->ptr=NULL; | 137 | a->ptr=NULL; |
138 | a->init=0; | 138 | a->init=0; |
@@ -271,7 +271,7 @@ static int enc_write(BIO *b, const char *in, int inl) | |||
271 | if (i <= 0) | 271 | if (i <= 0) |
272 | { | 272 | { |
273 | BIO_copy_next_retry(b); | 273 | BIO_copy_next_retry(b); |
274 | return(i); | 274 | return (ret == inl) ? i : ret - inl; |
275 | } | 275 | } |
276 | n-=i; | 276 | n-=i; |
277 | ctx->buf_off+=i; | 277 | ctx->buf_off+=i; |
@@ -325,10 +325,7 @@ again: | |||
325 | { | 325 | { |
326 | i=enc_write(b,NULL,0); | 326 | i=enc_write(b,NULL,0); |
327 | if (i < 0) | 327 | if (i < 0) |
328 | { | 328 | return i; |
329 | ret=i; | ||
330 | break; | ||
331 | } | ||
332 | } | 329 | } |
333 | 330 | ||
334 | if (!ctx->finished) | 331 | if (!ctx->finished) |
diff --git a/src/lib/libcrypto/evp/c_all.c b/src/lib/libcrypto/evp/c_all.c index 2d3e57c4fa..1b31a14e37 100644 --- a/src/lib/libcrypto/evp/c_all.c +++ b/src/lib/libcrypto/evp/c_all.c | |||
@@ -73,4 +73,9 @@ void OPENSSL_add_all_algorithms_noconf(void) | |||
73 | { | 73 | { |
74 | OpenSSL_add_all_ciphers(); | 74 | OpenSSL_add_all_ciphers(); |
75 | OpenSSL_add_all_digests(); | 75 | OpenSSL_add_all_digests(); |
76 | #ifndef OPENSSL_NO_ENGINE | ||
77 | # if defined(__OpenBSD__) || defined(__FreeBSD__) | ||
78 | ENGINE_setup_bsd_cryptodev(); | ||
79 | # endif | ||
80 | #endif | ||
76 | } | 81 | } |
diff --git a/src/lib/libcrypto/evp/digest.c b/src/lib/libcrypto/evp/digest.c index a969ac69ed..b22eed4421 100644 --- a/src/lib/libcrypto/evp/digest.c +++ b/src/lib/libcrypto/evp/digest.c | |||
@@ -113,7 +113,9 @@ | |||
113 | #include "cryptlib.h" | 113 | #include "cryptlib.h" |
114 | #include <openssl/objects.h> | 114 | #include <openssl/objects.h> |
115 | #include <openssl/evp.h> | 115 | #include <openssl/evp.h> |
116 | #ifndef OPENSSL_NO_ENGINE | ||
116 | #include <openssl/engine.h> | 117 | #include <openssl/engine.h> |
118 | #endif | ||
117 | 119 | ||
118 | void EVP_MD_CTX_init(EVP_MD_CTX *ctx) | 120 | void EVP_MD_CTX_init(EVP_MD_CTX *ctx) |
119 | { | 121 | { |
@@ -138,6 +140,7 @@ int EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type) | |||
138 | int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl) | 140 | int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl) |
139 | { | 141 | { |
140 | EVP_MD_CTX_clear_flags(ctx,EVP_MD_CTX_FLAG_CLEANED); | 142 | EVP_MD_CTX_clear_flags(ctx,EVP_MD_CTX_FLAG_CLEANED); |
143 | #ifndef OPENSSL_NO_ENGINE | ||
141 | /* Whether it's nice or not, "Inits" can be used on "Final"'d contexts | 144 | /* Whether it's nice or not, "Inits" can be used on "Final"'d contexts |
142 | * so this context may already have an ENGINE! Try to avoid releasing | 145 | * so this context may already have an ENGINE! Try to avoid releasing |
143 | * the previous handle, re-querying for an ENGINE, and having a | 146 | * the previous handle, re-querying for an ENGINE, and having a |
@@ -183,11 +186,13 @@ int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl) | |||
183 | else | 186 | else |
184 | ctx->engine = NULL; | 187 | ctx->engine = NULL; |
185 | } | 188 | } |
186 | else if(!ctx->digest) | 189 | else |
190 | if(!ctx->digest) | ||
187 | { | 191 | { |
188 | EVPerr(EVP_F_EVP_DIGESTINIT, EVP_R_NO_DIGEST_SET); | 192 | EVPerr(EVP_F_EVP_DIGESTINIT, EVP_R_NO_DIGEST_SET); |
189 | return 0; | 193 | return 0; |
190 | } | 194 | } |
195 | #endif | ||
191 | if (ctx->digest != type) | 196 | if (ctx->digest != type) |
192 | { | 197 | { |
193 | if (ctx->digest && ctx->digest->ctx_size) | 198 | if (ctx->digest && ctx->digest->ctx_size) |
@@ -196,7 +201,9 @@ int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl) | |||
196 | if (type->ctx_size) | 201 | if (type->ctx_size) |
197 | ctx->md_data=OPENSSL_malloc(type->ctx_size); | 202 | ctx->md_data=OPENSSL_malloc(type->ctx_size); |
198 | } | 203 | } |
204 | #ifndef OPENSSL_NO_ENGINE | ||
199 | skip_to_init: | 205 | skip_to_init: |
206 | #endif | ||
200 | return ctx->digest->init(ctx); | 207 | return ctx->digest->init(ctx); |
201 | } | 208 | } |
202 | 209 | ||
@@ -219,6 +226,8 @@ int EVP_DigestFinal(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *size) | |||
219 | int EVP_DigestFinal_ex(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *size) | 226 | int EVP_DigestFinal_ex(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *size) |
220 | { | 227 | { |
221 | int ret; | 228 | int ret; |
229 | |||
230 | OPENSSL_assert(ctx->digest->md_size <= EVP_MAX_MD_SIZE); | ||
222 | ret=ctx->digest->final(ctx,md); | 231 | ret=ctx->digest->final(ctx,md); |
223 | if (size != NULL) | 232 | if (size != NULL) |
224 | *size=ctx->digest->md_size; | 233 | *size=ctx->digest->md_size; |
@@ -244,12 +253,14 @@ int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in) | |||
244 | EVPerr(EVP_F_EVP_MD_CTX_COPY,EVP_R_INPUT_NOT_INITIALIZED); | 253 | EVPerr(EVP_F_EVP_MD_CTX_COPY,EVP_R_INPUT_NOT_INITIALIZED); |
245 | return 0; | 254 | return 0; |
246 | } | 255 | } |
256 | #ifndef OPENSSL_NO_ENGINE | ||
247 | /* Make sure it's safe to copy a digest context using an ENGINE */ | 257 | /* Make sure it's safe to copy a digest context using an ENGINE */ |
248 | if (in->engine && !ENGINE_init(in->engine)) | 258 | if (in->engine && !ENGINE_init(in->engine)) |
249 | { | 259 | { |
250 | EVPerr(EVP_F_EVP_MD_CTX_COPY,ERR_R_ENGINE_LIB); | 260 | EVPerr(EVP_F_EVP_MD_CTX_COPY,ERR_R_ENGINE_LIB); |
251 | return 0; | 261 | return 0; |
252 | } | 262 | } |
263 | #endif | ||
253 | 264 | ||
254 | EVP_MD_CTX_cleanup(out); | 265 | EVP_MD_CTX_cleanup(out); |
255 | memcpy(out,in,sizeof *out); | 266 | memcpy(out,in,sizeof *out); |
@@ -299,13 +310,15 @@ int EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx) | |||
299 | ctx->digest->cleanup(ctx); | 310 | ctx->digest->cleanup(ctx); |
300 | if (ctx->digest && ctx->digest->ctx_size && ctx->md_data) | 311 | if (ctx->digest && ctx->digest->ctx_size && ctx->md_data) |
301 | { | 312 | { |
302 | memset(ctx->md_data,0,ctx->digest->ctx_size); | 313 | OPENSSL_cleanse(ctx->md_data,ctx->digest->ctx_size); |
303 | OPENSSL_free(ctx->md_data); | 314 | OPENSSL_free(ctx->md_data); |
304 | } | 315 | } |
316 | #ifndef OPENSSL_NO_ENGINE | ||
305 | if(ctx->engine) | 317 | if(ctx->engine) |
306 | /* The EVP_MD we used belongs to an ENGINE, release the | 318 | /* The EVP_MD we used belongs to an ENGINE, release the |
307 | * functional reference we held for this reason. */ | 319 | * functional reference we held for this reason. */ |
308 | ENGINE_finish(ctx->engine); | 320 | ENGINE_finish(ctx->engine); |
321 | #endif | ||
309 | memset(ctx,'\0',sizeof *ctx); | 322 | memset(ctx,'\0',sizeof *ctx); |
310 | 323 | ||
311 | return 1; | 324 | return 1; |
diff --git a/src/lib/libcrypto/evp/e_aes.c b/src/lib/libcrypto/evp/e_aes.c index c323fa2892..fe8bcda631 100644 --- a/src/lib/libcrypto/evp/e_aes.c +++ b/src/lib/libcrypto/evp/e_aes.c | |||
@@ -52,7 +52,6 @@ | |||
52 | #include <openssl/evp.h> | 52 | #include <openssl/evp.h> |
53 | #include <openssl/err.h> | 53 | #include <openssl/err.h> |
54 | #include <string.h> | 54 | #include <string.h> |
55 | #include <assert.h> | ||
56 | #include <openssl/aes.h> | 55 | #include <openssl/aes.h> |
57 | #include "evp_locl.h" | 56 | #include "evp_locl.h" |
58 | 57 | ||
diff --git a/src/lib/libcrypto/evp/e_idea.c b/src/lib/libcrypto/evp/e_idea.c index ed838d3e62..b9efa75ae7 100644 --- a/src/lib/libcrypto/evp/e_idea.c +++ b/src/lib/libcrypto/evp/e_idea.c | |||
@@ -109,7 +109,7 @@ static int idea_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | |||
109 | 109 | ||
110 | idea_set_encrypt_key(key,&tmp); | 110 | idea_set_encrypt_key(key,&tmp); |
111 | idea_set_decrypt_key(&tmp,ctx->cipher_data); | 111 | idea_set_decrypt_key(&tmp,ctx->cipher_data); |
112 | memset((unsigned char *)&tmp,0, | 112 | OPENSSL_cleanse((unsigned char *)&tmp, |
113 | sizeof(IDEA_KEY_SCHEDULE)); | 113 | sizeof(IDEA_KEY_SCHEDULE)); |
114 | } | 114 | } |
115 | return 1; | 115 | return 1; |
diff --git a/src/lib/libcrypto/evp/e_rc2.c b/src/lib/libcrypto/evp/e_rc2.c index 4685198e2e..d42cbfd17e 100644 --- a/src/lib/libcrypto/evp/e_rc2.c +++ b/src/lib/libcrypto/evp/e_rc2.c | |||
@@ -174,6 +174,7 @@ static int rc2_get_asn1_type_and_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type) | |||
174 | if (type != NULL) | 174 | if (type != NULL) |
175 | { | 175 | { |
176 | l=EVP_CIPHER_CTX_iv_length(c); | 176 | l=EVP_CIPHER_CTX_iv_length(c); |
177 | OPENSSL_assert(l <= sizeof iv); | ||
177 | i=ASN1_TYPE_get_int_octetstring(type,&num,iv,l); | 178 | i=ASN1_TYPE_get_int_octetstring(type,&num,iv,l); |
178 | if (i != l) | 179 | if (i != l) |
179 | return(-1); | 180 | return(-1); |
diff --git a/src/lib/libcrypto/evp/e_rc4.c b/src/lib/libcrypto/evp/e_rc4.c index 4064cc5fa0..d58f507837 100644 --- a/src/lib/libcrypto/evp/e_rc4.c +++ b/src/lib/libcrypto/evp/e_rc4.c | |||
@@ -69,8 +69,6 @@ | |||
69 | 69 | ||
70 | typedef struct | 70 | typedef struct |
71 | { | 71 | { |
72 | /* FIXME: what is the key for? */ | ||
73 | unsigned char key[EVP_RC4_KEY_SIZE]; | ||
74 | RC4_KEY ks; /* working key */ | 72 | RC4_KEY ks; /* working key */ |
75 | } EVP_RC4_KEY; | 73 | } EVP_RC4_KEY; |
76 | 74 | ||
@@ -121,9 +119,8 @@ const EVP_CIPHER *EVP_rc4_40(void) | |||
121 | static int rc4_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | 119 | static int rc4_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, |
122 | const unsigned char *iv, int enc) | 120 | const unsigned char *iv, int enc) |
123 | { | 121 | { |
124 | memcpy(&data(ctx)->key[0],key,EVP_CIPHER_CTX_key_length(ctx)); | ||
125 | RC4_set_key(&data(ctx)->ks,EVP_CIPHER_CTX_key_length(ctx), | 122 | RC4_set_key(&data(ctx)->ks,EVP_CIPHER_CTX_key_length(ctx), |
126 | data(ctx)->key); | 123 | key); |
127 | return 1; | 124 | return 1; |
128 | } | 125 | } |
129 | 126 | ||
diff --git a/src/lib/libcrypto/evp/encode.c b/src/lib/libcrypto/evp/encode.c index 12c6379df1..08209357ce 100644 --- a/src/lib/libcrypto/evp/encode.c +++ b/src/lib/libcrypto/evp/encode.c | |||
@@ -136,6 +136,7 @@ void EVP_EncodeUpdate(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl, | |||
136 | 136 | ||
137 | *outl=0; | 137 | *outl=0; |
138 | if (inl == 0) return; | 138 | if (inl == 0) return; |
139 | OPENSSL_assert(ctx->length <= sizeof ctx->enc_data); | ||
139 | if ((ctx->num+inl) < ctx->length) | 140 | if ((ctx->num+inl) < ctx->length) |
140 | { | 141 | { |
141 | memcpy(&(ctx->enc_data[ctx->num]),in,inl); | 142 | memcpy(&(ctx->enc_data[ctx->num]),in,inl); |
@@ -258,6 +259,7 @@ int EVP_DecodeUpdate(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl, | |||
258 | /* only save the good data :-) */ | 259 | /* only save the good data :-) */ |
259 | if (!B64_NOT_BASE64(v)) | 260 | if (!B64_NOT_BASE64(v)) |
260 | { | 261 | { |
262 | OPENSSL_assert(n < sizeof ctx->enc_data); | ||
261 | d[n++]=tmp; | 263 | d[n++]=tmp; |
262 | ln++; | 264 | ln++; |
263 | } | 265 | } |
diff --git a/src/lib/libcrypto/evp/evp_enc.c b/src/lib/libcrypto/evp/evp_enc.c index 32a1c7a2e9..be0758a879 100644 --- a/src/lib/libcrypto/evp/evp_enc.c +++ b/src/lib/libcrypto/evp/evp_enc.c | |||
@@ -60,11 +60,11 @@ | |||
60 | #include "cryptlib.h" | 60 | #include "cryptlib.h" |
61 | #include <openssl/evp.h> | 61 | #include <openssl/evp.h> |
62 | #include <openssl/err.h> | 62 | #include <openssl/err.h> |
63 | #ifndef OPENSSL_NO_ENGINE | ||
63 | #include <openssl/engine.h> | 64 | #include <openssl/engine.h> |
65 | #endif | ||
64 | #include "evp_locl.h" | 66 | #include "evp_locl.h" |
65 | 67 | ||
66 | #include <assert.h> | ||
67 | |||
68 | const char *EVP_version="EVP" OPENSSL_VERSION_PTEXT; | 68 | const char *EVP_version="EVP" OPENSSL_VERSION_PTEXT; |
69 | 69 | ||
70 | void EVP_CIPHER_CTX_init(EVP_CIPHER_CTX *ctx) | 70 | void EVP_CIPHER_CTX_init(EVP_CIPHER_CTX *ctx) |
@@ -93,6 +93,7 @@ int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *imp | |||
93 | enc = 1; | 93 | enc = 1; |
94 | ctx->encrypt = enc; | 94 | ctx->encrypt = enc; |
95 | } | 95 | } |
96 | #ifndef OPENSSL_NO_ENGINE | ||
96 | /* Whether it's nice or not, "Inits" can be used on "Final"'d contexts | 97 | /* Whether it's nice or not, "Inits" can be used on "Final"'d contexts |
97 | * so this context may already have an ENGINE! Try to avoid releasing | 98 | * so this context may already have an ENGINE! Try to avoid releasing |
98 | * the previous handle, re-querying for an ENGINE, and having a | 99 | * the previous handle, re-querying for an ENGINE, and having a |
@@ -100,6 +101,7 @@ int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *imp | |||
100 | if (ctx->engine && ctx->cipher && (!cipher || | 101 | if (ctx->engine && ctx->cipher && (!cipher || |
101 | (cipher && (cipher->nid == ctx->cipher->nid)))) | 102 | (cipher && (cipher->nid == ctx->cipher->nid)))) |
102 | goto skip_to_init; | 103 | goto skip_to_init; |
104 | #endif | ||
103 | if (cipher) | 105 | if (cipher) |
104 | { | 106 | { |
105 | /* Ensure a context left lying around from last time is cleared | 107 | /* Ensure a context left lying around from last time is cleared |
@@ -109,6 +111,7 @@ int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *imp | |||
109 | 111 | ||
110 | /* Restore encrypt field: it is zeroed by cleanup */ | 112 | /* Restore encrypt field: it is zeroed by cleanup */ |
111 | ctx->encrypt = enc; | 113 | ctx->encrypt = enc; |
114 | #ifndef OPENSSL_NO_ENGINE | ||
112 | if(impl) | 115 | if(impl) |
113 | { | 116 | { |
114 | if (!ENGINE_init(impl)) | 117 | if (!ENGINE_init(impl)) |
@@ -142,6 +145,7 @@ int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *imp | |||
142 | } | 145 | } |
143 | else | 146 | else |
144 | ctx->engine = NULL; | 147 | ctx->engine = NULL; |
148 | #endif | ||
145 | 149 | ||
146 | ctx->cipher=cipher; | 150 | ctx->cipher=cipher; |
147 | ctx->cipher_data=OPENSSL_malloc(ctx->cipher->ctx_size); | 151 | ctx->cipher_data=OPENSSL_malloc(ctx->cipher->ctx_size); |
@@ -161,11 +165,13 @@ int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *imp | |||
161 | EVPerr(EVP_F_EVP_CIPHERINIT, EVP_R_NO_CIPHER_SET); | 165 | EVPerr(EVP_F_EVP_CIPHERINIT, EVP_R_NO_CIPHER_SET); |
162 | return 0; | 166 | return 0; |
163 | } | 167 | } |
168 | #ifndef OPENSSL_NO_ENGINE | ||
164 | skip_to_init: | 169 | skip_to_init: |
170 | #endif | ||
165 | /* we assume block size is a power of 2 in *cryptUpdate */ | 171 | /* we assume block size is a power of 2 in *cryptUpdate */ |
166 | assert(ctx->cipher->block_size == 1 | 172 | OPENSSL_assert(ctx->cipher->block_size == 1 |
167 | || ctx->cipher->block_size == 8 | 173 | || ctx->cipher->block_size == 8 |
168 | || ctx->cipher->block_size == 16); | 174 | || ctx->cipher->block_size == 16); |
169 | 175 | ||
170 | if(!(EVP_CIPHER_CTX_flags(ctx) & EVP_CIPH_CUSTOM_IV)) { | 176 | if(!(EVP_CIPHER_CTX_flags(ctx) & EVP_CIPH_CUSTOM_IV)) { |
171 | switch(EVP_CIPHER_CTX_mode(ctx)) { | 177 | switch(EVP_CIPHER_CTX_mode(ctx)) { |
@@ -181,6 +187,7 @@ skip_to_init: | |||
181 | 187 | ||
182 | case EVP_CIPH_CBC_MODE: | 188 | case EVP_CIPH_CBC_MODE: |
183 | 189 | ||
190 | OPENSSL_assert(EVP_CIPHER_CTX_iv_length(ctx) <= sizeof ctx->iv); | ||
184 | if(iv) memcpy(ctx->oiv, iv, EVP_CIPHER_CTX_iv_length(ctx)); | 191 | if(iv) memcpy(ctx->oiv, iv, EVP_CIPHER_CTX_iv_length(ctx)); |
185 | memcpy(ctx->iv, ctx->oiv, EVP_CIPHER_CTX_iv_length(ctx)); | 192 | memcpy(ctx->iv, ctx->oiv, EVP_CIPHER_CTX_iv_length(ctx)); |
186 | break; | 193 | break; |
@@ -237,7 +244,7 @@ int EVP_EncryptInit_ex(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *cipher, ENGINE *imp | |||
237 | int EVP_DecryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, | 244 | int EVP_DecryptInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, |
238 | const unsigned char *key, const unsigned char *iv) | 245 | const unsigned char *key, const unsigned char *iv) |
239 | { | 246 | { |
240 | return EVP_CipherInit_ex(ctx, cipher, NULL, key, iv, 0); | 247 | return EVP_CipherInit(ctx, cipher, key, iv, 0); |
241 | } | 248 | } |
242 | 249 | ||
243 | int EVP_DecryptInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *impl, | 250 | int EVP_DecryptInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *impl, |
@@ -251,6 +258,7 @@ int EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl, | |||
251 | { | 258 | { |
252 | int i,j,bl; | 259 | int i,j,bl; |
253 | 260 | ||
261 | OPENSSL_assert(inl > 0); | ||
254 | if(ctx->buf_len == 0 && (inl&(ctx->block_mask)) == 0) | 262 | if(ctx->buf_len == 0 && (inl&(ctx->block_mask)) == 0) |
255 | { | 263 | { |
256 | if(ctx->cipher->do_cipher(ctx,out,in,inl)) | 264 | if(ctx->cipher->do_cipher(ctx,out,in,inl)) |
@@ -266,6 +274,7 @@ int EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl, | |||
266 | } | 274 | } |
267 | i=ctx->buf_len; | 275 | i=ctx->buf_len; |
268 | bl=ctx->cipher->block_size; | 276 | bl=ctx->cipher->block_size; |
277 | OPENSSL_assert(bl <= sizeof ctx->buf); | ||
269 | if (i != 0) | 278 | if (i != 0) |
270 | { | 279 | { |
271 | if (i+inl < bl) | 280 | if (i+inl < bl) |
@@ -314,6 +323,7 @@ int EVP_EncryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl) | |||
314 | int i,n,b,bl,ret; | 323 | int i,n,b,bl,ret; |
315 | 324 | ||
316 | b=ctx->cipher->block_size; | 325 | b=ctx->cipher->block_size; |
326 | OPENSSL_assert(b <= sizeof ctx->buf); | ||
317 | if (b == 1) | 327 | if (b == 1) |
318 | { | 328 | { |
319 | *outl=0; | 329 | *outl=0; |
@@ -358,6 +368,7 @@ int EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl, | |||
358 | return EVP_EncryptUpdate(ctx, out, outl, in, inl); | 368 | return EVP_EncryptUpdate(ctx, out, outl, in, inl); |
359 | 369 | ||
360 | b=ctx->cipher->block_size; | 370 | b=ctx->cipher->block_size; |
371 | OPENSSL_assert(b <= sizeof ctx->final); | ||
361 | 372 | ||
362 | if(ctx->final_used) | 373 | if(ctx->final_used) |
363 | { | 374 | { |
@@ -420,6 +431,7 @@ int EVP_DecryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl) | |||
420 | EVPerr(EVP_F_EVP_DECRYPTFINAL,EVP_R_WRONG_FINAL_BLOCK_LENGTH); | 431 | EVPerr(EVP_F_EVP_DECRYPTFINAL,EVP_R_WRONG_FINAL_BLOCK_LENGTH); |
421 | return(0); | 432 | return(0); |
422 | } | 433 | } |
434 | OPENSSL_assert(b <= sizeof ctx->final); | ||
423 | n=ctx->final[b-1]; | 435 | n=ctx->final[b-1]; |
424 | if (n > b) | 436 | if (n > b) |
425 | { | 437 | { |
@@ -450,16 +462,18 @@ int EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *c) | |||
450 | { | 462 | { |
451 | if(c->cipher->cleanup && !c->cipher->cleanup(c)) | 463 | if(c->cipher->cleanup && !c->cipher->cleanup(c)) |
452 | return 0; | 464 | return 0; |
453 | /* Zero cipher context data */ | 465 | /* Cleanse cipher context data */ |
454 | if (c->cipher_data) | 466 | if (c->cipher_data) |
455 | memset(c->cipher_data, 0, c->cipher->ctx_size); | 467 | OPENSSL_cleanse(c->cipher_data, c->cipher->ctx_size); |
456 | } | 468 | } |
457 | if (c->cipher_data) | 469 | if (c->cipher_data) |
458 | OPENSSL_free(c->cipher_data); | 470 | OPENSSL_free(c->cipher_data); |
471 | #ifndef OPENSSL_NO_ENGINE | ||
459 | if (c->engine) | 472 | if (c->engine) |
460 | /* The EVP_CIPHER we used belongs to an ENGINE, release the | 473 | /* The EVP_CIPHER we used belongs to an ENGINE, release the |
461 | * functional reference we held for this reason. */ | 474 | * functional reference we held for this reason. */ |
462 | ENGINE_finish(c->engine); | 475 | ENGINE_finish(c->engine); |
476 | #endif | ||
463 | memset(c,0,sizeof(EVP_CIPHER_CTX)); | 477 | memset(c,0,sizeof(EVP_CIPHER_CTX)); |
464 | return 1; | 478 | return 1; |
465 | } | 479 | } |
diff --git a/src/lib/libcrypto/evp/evp_key.c b/src/lib/libcrypto/evp/evp_key.c index 4271393069..5f387a94d3 100644 --- a/src/lib/libcrypto/evp/evp_key.c +++ b/src/lib/libcrypto/evp/evp_key.c | |||
@@ -103,7 +103,7 @@ int EVP_read_pw_string(char *buf, int len, const char *prompt, int verify) | |||
103 | buff,0,(len>=BUFSIZ)?BUFSIZ-1:len,buf); | 103 | buff,0,(len>=BUFSIZ)?BUFSIZ-1:len,buf); |
104 | ret = UI_process(ui); | 104 | ret = UI_process(ui); |
105 | UI_free(ui); | 105 | UI_free(ui); |
106 | memset(buff,0,BUFSIZ); | 106 | OPENSSL_cleanse(buff,BUFSIZ); |
107 | return ret; | 107 | return ret; |
108 | } | 108 | } |
109 | 109 | ||
@@ -118,6 +118,8 @@ int EVP_BytesToKey(const EVP_CIPHER *type, const EVP_MD *md, | |||
118 | 118 | ||
119 | nkey=type->key_len; | 119 | nkey=type->key_len; |
120 | niv=type->iv_len; | 120 | niv=type->iv_len; |
121 | OPENSSL_assert(nkey <= EVP_MAX_KEY_LENGTH); | ||
122 | OPENSSL_assert(niv <= EVP_MAX_IV_LENGTH); | ||
121 | 123 | ||
122 | if (data == NULL) return(nkey); | 124 | if (data == NULL) return(nkey); |
123 | 125 | ||
@@ -166,7 +168,7 @@ int EVP_BytesToKey(const EVP_CIPHER *type, const EVP_MD *md, | |||
166 | if ((nkey == 0) && (niv == 0)) break; | 168 | if ((nkey == 0) && (niv == 0)) break; |
167 | } | 169 | } |
168 | EVP_MD_CTX_cleanup(&c); | 170 | EVP_MD_CTX_cleanup(&c); |
169 | memset(&(md_buf[0]),0,EVP_MAX_MD_SIZE); | 171 | OPENSSL_cleanse(&(md_buf[0]),EVP_MAX_MD_SIZE); |
170 | return(type->key_len); | 172 | return(type->key_len); |
171 | } | 173 | } |
172 | 174 | ||
diff --git a/src/lib/libcrypto/evp/evp_lib.c b/src/lib/libcrypto/evp/evp_lib.c index a431945ef5..52a3b287be 100644 --- a/src/lib/libcrypto/evp/evp_lib.c +++ b/src/lib/libcrypto/evp/evp_lib.c | |||
@@ -90,6 +90,7 @@ int EVP_CIPHER_get_asn1_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type) | |||
90 | if (type != NULL) | 90 | if (type != NULL) |
91 | { | 91 | { |
92 | l=EVP_CIPHER_CTX_iv_length(c); | 92 | l=EVP_CIPHER_CTX_iv_length(c); |
93 | OPENSSL_assert(l <= sizeof c->iv); | ||
93 | i=ASN1_TYPE_get_octetstring(type,c->oiv,l); | 94 | i=ASN1_TYPE_get_octetstring(type,c->oiv,l); |
94 | if (i != l) | 95 | if (i != l) |
95 | return(-1); | 96 | return(-1); |
@@ -106,6 +107,7 @@ int EVP_CIPHER_set_asn1_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type) | |||
106 | if (type != NULL) | 107 | if (type != NULL) |
107 | { | 108 | { |
108 | j=EVP_CIPHER_CTX_iv_length(c); | 109 | j=EVP_CIPHER_CTX_iv_length(c); |
110 | OPENSSL_assert(j <= sizeof c->iv); | ||
109 | i=ASN1_TYPE_set_octetstring(type,c->oiv,j); | 111 | i=ASN1_TYPE_set_octetstring(type,c->oiv,j); |
110 | } | 112 | } |
111 | return(i); | 113 | return(i); |
diff --git a/src/lib/libcrypto/evp/evp_pbe.c b/src/lib/libcrypto/evp/evp_pbe.c index bcd4d29f85..0da88fdcff 100644 --- a/src/lib/libcrypto/evp/evp_pbe.c +++ b/src/lib/libcrypto/evp/evp_pbe.c | |||
@@ -88,7 +88,7 @@ int EVP_PBE_CipherInit (ASN1_OBJECT *pbe_obj, const char *pass, int passlen, | |||
88 | char obj_tmp[80]; | 88 | char obj_tmp[80]; |
89 | EVPerr(EVP_F_EVP_PBE_CIPHERINIT,EVP_R_UNKNOWN_PBE_ALGORITHM); | 89 | EVPerr(EVP_F_EVP_PBE_CIPHERINIT,EVP_R_UNKNOWN_PBE_ALGORITHM); |
90 | if (!pbe_obj) strcpy (obj_tmp, "NULL"); | 90 | if (!pbe_obj) strcpy (obj_tmp, "NULL"); |
91 | else i2t_ASN1_OBJECT(obj_tmp, 80, pbe_obj); | 91 | else i2t_ASN1_OBJECT(obj_tmp, sizeof obj_tmp, pbe_obj); |
92 | ERR_add_error_data(2, "TYPE=", obj_tmp); | 92 | ERR_add_error_data(2, "TYPE=", obj_tmp); |
93 | return 0; | 93 | return 0; |
94 | } | 94 | } |
diff --git a/src/lib/libcrypto/evp/p5_crpt.c b/src/lib/libcrypto/evp/p5_crpt.c index 27a8286489..a1874e83b2 100644 --- a/src/lib/libcrypto/evp/p5_crpt.c +++ b/src/lib/libcrypto/evp/p5_crpt.c | |||
@@ -140,12 +140,14 @@ int PKCS5_PBE_keyivgen(EVP_CIPHER_CTX *cctx, const char *pass, int passlen, | |||
140 | EVP_DigestFinal_ex (&ctx, md_tmp, NULL); | 140 | EVP_DigestFinal_ex (&ctx, md_tmp, NULL); |
141 | } | 141 | } |
142 | EVP_MD_CTX_cleanup(&ctx); | 142 | EVP_MD_CTX_cleanup(&ctx); |
143 | OPENSSL_assert(EVP_CIPHER_key_length(cipher) <= sizeof md_tmp); | ||
143 | memcpy(key, md_tmp, EVP_CIPHER_key_length(cipher)); | 144 | memcpy(key, md_tmp, EVP_CIPHER_key_length(cipher)); |
145 | OPENSSL_assert(EVP_CIPHER_iv_length(cipher) <= 16); | ||
144 | memcpy(iv, md_tmp + (16 - EVP_CIPHER_iv_length(cipher)), | 146 | memcpy(iv, md_tmp + (16 - EVP_CIPHER_iv_length(cipher)), |
145 | EVP_CIPHER_iv_length(cipher)); | 147 | EVP_CIPHER_iv_length(cipher)); |
146 | EVP_CipherInit_ex(cctx, cipher, NULL, key, iv, en_de); | 148 | EVP_CipherInit_ex(cctx, cipher, NULL, key, iv, en_de); |
147 | memset(md_tmp, 0, EVP_MAX_MD_SIZE); | 149 | OPENSSL_cleanse(md_tmp, EVP_MAX_MD_SIZE); |
148 | memset(key, 0, EVP_MAX_KEY_LENGTH); | 150 | OPENSSL_cleanse(key, EVP_MAX_KEY_LENGTH); |
149 | memset(iv, 0, EVP_MAX_IV_LENGTH); | 151 | OPENSSL_cleanse(iv, EVP_MAX_IV_LENGTH); |
150 | return 1; | 152 | return 1; |
151 | } | 153 | } |
diff --git a/src/lib/libcrypto/evp/p5_crpt2.c b/src/lib/libcrypto/evp/p5_crpt2.c index 7485d6a278..1f94e1ef88 100644 --- a/src/lib/libcrypto/evp/p5_crpt2.c +++ b/src/lib/libcrypto/evp/p5_crpt2.c | |||
@@ -190,6 +190,7 @@ int PKCS5_v2_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen, | |||
190 | goto err; | 190 | goto err; |
191 | } | 191 | } |
192 | keylen = EVP_CIPHER_CTX_key_length(ctx); | 192 | keylen = EVP_CIPHER_CTX_key_length(ctx); |
193 | OPENSSL_assert(keylen <= sizeof key); | ||
193 | 194 | ||
194 | /* Now decode key derivation function */ | 195 | /* Now decode key derivation function */ |
195 | 196 | ||
@@ -230,7 +231,7 @@ int PKCS5_v2_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen, | |||
230 | iter = ASN1_INTEGER_get(kdf->iter); | 231 | iter = ASN1_INTEGER_get(kdf->iter); |
231 | PKCS5_PBKDF2_HMAC_SHA1(pass, passlen, salt, saltlen, iter, keylen, key); | 232 | PKCS5_PBKDF2_HMAC_SHA1(pass, passlen, salt, saltlen, iter, keylen, key); |
232 | EVP_CipherInit_ex(ctx, NULL, NULL, key, NULL, en_de); | 233 | EVP_CipherInit_ex(ctx, NULL, NULL, key, NULL, en_de); |
233 | memset(key, 0, keylen); | 234 | OPENSSL_cleanse(key, keylen); |
234 | PBKDF2PARAM_free(kdf); | 235 | PBKDF2PARAM_free(kdf); |
235 | return 1; | 236 | return 1; |
236 | 237 | ||
diff --git a/src/lib/libcrypto/evp/p_open.c b/src/lib/libcrypto/evp/p_open.c index 6976f2a867..5a933d1cda 100644 --- a/src/lib/libcrypto/evp/p_open.c +++ b/src/lib/libcrypto/evp/p_open.c | |||
@@ -101,7 +101,7 @@ int EVP_OpenInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type, unsigned char *ek, | |||
101 | 101 | ||
102 | ret=1; | 102 | ret=1; |
103 | err: | 103 | err: |
104 | if (key != NULL) memset(key,0,size); | 104 | if (key != NULL) OPENSSL_cleanse(key,size); |
105 | OPENSSL_free(key); | 105 | OPENSSL_free(key); |
106 | return(ret); | 106 | return(ret); |
107 | } | 107 | } |
diff --git a/src/lib/libcrypto/hmac/hmac.c b/src/lib/libcrypto/hmac/hmac.c index da363b7950..4c91f919d5 100644 --- a/src/lib/libcrypto/hmac/hmac.c +++ b/src/lib/libcrypto/hmac/hmac.c | |||
@@ -59,6 +59,7 @@ | |||
59 | #include <stdlib.h> | 59 | #include <stdlib.h> |
60 | #include <string.h> | 60 | #include <string.h> |
61 | #include <openssl/hmac.h> | 61 | #include <openssl/hmac.h> |
62 | #include "cryptlib.h" | ||
62 | 63 | ||
63 | void HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int len, | 64 | void HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int len, |
64 | const EVP_MD *md, ENGINE *impl) | 65 | const EVP_MD *md, ENGINE *impl) |
@@ -78,6 +79,7 @@ void HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int len, | |||
78 | { | 79 | { |
79 | reset=1; | 80 | reset=1; |
80 | j=EVP_MD_block_size(md); | 81 | j=EVP_MD_block_size(md); |
82 | OPENSSL_assert(j <= sizeof ctx->key); | ||
81 | if (j < len) | 83 | if (j < len) |
82 | { | 84 | { |
83 | EVP_DigestInit_ex(&ctx->md_ctx,md, impl); | 85 | EVP_DigestInit_ex(&ctx->md_ctx,md, impl); |
@@ -87,6 +89,7 @@ void HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int len, | |||
87 | } | 89 | } |
88 | else | 90 | else |
89 | { | 91 | { |
92 | OPENSSL_assert(len <= sizeof ctx->key); | ||
90 | memcpy(ctx->key,key,len); | 93 | memcpy(ctx->key,key,len); |
91 | ctx->key_length=len; | 94 | ctx->key_length=len; |
92 | } | 95 | } |
diff --git a/src/lib/libcrypto/lhash/lh_stats.c b/src/lib/libcrypto/lhash/lh_stats.c index 39ea2885f4..5aa7766aa6 100644 --- a/src/lib/libcrypto/lhash/lh_stats.c +++ b/src/lib/libcrypto/lhash/lh_stats.c | |||
@@ -179,49 +179,29 @@ end:; | |||
179 | 179 | ||
180 | void lh_stats_bio(const LHASH *lh, BIO *out) | 180 | void lh_stats_bio(const LHASH *lh, BIO *out) |
181 | { | 181 | { |
182 | char buf[128]; | 182 | BIO_printf(out,"num_items = %lu\n",lh->num_items); |
183 | 183 | BIO_printf(out,"num_nodes = %u\n",lh->num_nodes); | |
184 | sprintf(buf,"num_items = %lu\n",lh->num_items); | 184 | BIO_printf(out,"num_alloc_nodes = %u\n",lh->num_alloc_nodes); |
185 | BIO_puts(out,buf); | 185 | BIO_printf(out,"num_expands = %lu\n",lh->num_expands); |
186 | sprintf(buf,"num_nodes = %u\n",lh->num_nodes); | 186 | BIO_printf(out,"num_expand_reallocs = %lu\n", |
187 | BIO_puts(out,buf); | 187 | lh->num_expand_reallocs); |
188 | sprintf(buf,"num_alloc_nodes = %u\n",lh->num_alloc_nodes); | 188 | BIO_printf(out,"num_contracts = %lu\n",lh->num_contracts); |
189 | BIO_puts(out,buf); | 189 | BIO_printf(out,"num_contract_reallocs = %lu\n", |
190 | sprintf(buf,"num_expands = %lu\n",lh->num_expands); | 190 | lh->num_contract_reallocs); |
191 | BIO_puts(out,buf); | 191 | BIO_printf(out,"num_hash_calls = %lu\n",lh->num_hash_calls); |
192 | sprintf(buf,"num_expand_reallocs = %lu\n",lh->num_expand_reallocs); | 192 | BIO_printf(out,"num_comp_calls = %lu\n",lh->num_comp_calls); |
193 | BIO_puts(out,buf); | 193 | BIO_printf(out,"num_insert = %lu\n",lh->num_insert); |
194 | sprintf(buf,"num_contracts = %lu\n",lh->num_contracts); | 194 | BIO_printf(out,"num_replace = %lu\n",lh->num_replace); |
195 | BIO_puts(out,buf); | 195 | BIO_printf(out,"num_delete = %lu\n",lh->num_delete); |
196 | sprintf(buf,"num_contract_reallocs = %lu\n",lh->num_contract_reallocs); | 196 | BIO_printf(out,"num_no_delete = %lu\n",lh->num_no_delete); |
197 | BIO_puts(out,buf); | 197 | BIO_printf(out,"num_retrieve = %lu\n",lh->num_retrieve); |
198 | sprintf(buf,"num_hash_calls = %lu\n",lh->num_hash_calls); | 198 | BIO_printf(out,"num_retrieve_miss = %lu\n",lh->num_retrieve_miss); |
199 | BIO_puts(out,buf); | 199 | BIO_printf(out,"num_hash_comps = %lu\n",lh->num_hash_comps); |
200 | sprintf(buf,"num_comp_calls = %lu\n",lh->num_comp_calls); | ||
201 | BIO_puts(out,buf); | ||
202 | sprintf(buf,"num_insert = %lu\n",lh->num_insert); | ||
203 | BIO_puts(out,buf); | ||
204 | sprintf(buf,"num_replace = %lu\n",lh->num_replace); | ||
205 | BIO_puts(out,buf); | ||
206 | sprintf(buf,"num_delete = %lu\n",lh->num_delete); | ||
207 | BIO_puts(out,buf); | ||
208 | sprintf(buf,"num_no_delete = %lu\n",lh->num_no_delete); | ||
209 | BIO_puts(out,buf); | ||
210 | sprintf(buf,"num_retrieve = %lu\n",lh->num_retrieve); | ||
211 | BIO_puts(out,buf); | ||
212 | sprintf(buf,"num_retrieve_miss = %lu\n",lh->num_retrieve_miss); | ||
213 | BIO_puts(out,buf); | ||
214 | sprintf(buf,"num_hash_comps = %lu\n",lh->num_hash_comps); | ||
215 | BIO_puts(out,buf); | ||
216 | #if 0 | 200 | #if 0 |
217 | sprintf(buf,"p = %u\n",lh->p); | 201 | BIO_printf(out,"p = %u\n",lh->p); |
218 | BIO_puts(out,buf); | 202 | BIO_printf(out,"pmax = %u\n",lh->pmax); |
219 | sprintf(buf,"pmax = %u\n",lh->pmax); | 203 | BIO_printf(out,"up_load = %lu\n",lh->up_load); |
220 | BIO_puts(out,buf); | 204 | BIO_printf(out,"down_load = %lu\n",lh->down_load); |
221 | sprintf(buf,"up_load = %lu\n",lh->up_load); | ||
222 | BIO_puts(out,buf); | ||
223 | sprintf(buf,"down_load = %lu\n",lh->down_load); | ||
224 | BIO_puts(out,buf); | ||
225 | #endif | 205 | #endif |
226 | } | 206 | } |
227 | 207 | ||
@@ -229,14 +209,12 @@ void lh_node_stats_bio(const LHASH *lh, BIO *out) | |||
229 | { | 209 | { |
230 | LHASH_NODE *n; | 210 | LHASH_NODE *n; |
231 | unsigned int i,num; | 211 | unsigned int i,num; |
232 | char buf[128]; | ||
233 | 212 | ||
234 | for (i=0; i<lh->num_nodes; i++) | 213 | for (i=0; i<lh->num_nodes; i++) |
235 | { | 214 | { |
236 | for (n=lh->b[i],num=0; n != NULL; n=n->next) | 215 | for (n=lh->b[i],num=0; n != NULL; n=n->next) |
237 | num++; | 216 | num++; |
238 | sprintf(buf,"node %6u -> %3u\n",i,num); | 217 | BIO_printf(out,"node %6u -> %3u\n",i,num); |
239 | BIO_puts(out,buf); | ||
240 | } | 218 | } |
241 | } | 219 | } |
242 | 220 | ||
@@ -246,7 +224,6 @@ void lh_node_usage_stats_bio(const LHASH *lh, BIO *out) | |||
246 | unsigned long num; | 224 | unsigned long num; |
247 | unsigned int i; | 225 | unsigned int i; |
248 | unsigned long total=0,n_used=0; | 226 | unsigned long total=0,n_used=0; |
249 | char buf[128]; | ||
250 | 227 | ||
251 | for (i=0; i<lh->num_nodes; i++) | 228 | for (i=0; i<lh->num_nodes; i++) |
252 | { | 229 | { |
@@ -258,17 +235,14 @@ void lh_node_usage_stats_bio(const LHASH *lh, BIO *out) | |||
258 | total+=num; | 235 | total+=num; |
259 | } | 236 | } |
260 | } | 237 | } |
261 | sprintf(buf,"%lu nodes used out of %u\n",n_used,lh->num_nodes); | 238 | BIO_printf(out,"%lu nodes used out of %u\n",n_used,lh->num_nodes); |
262 | BIO_puts(out,buf); | 239 | BIO_printf(out,"%lu items\n",total); |
263 | sprintf(buf,"%lu items\n",total); | ||
264 | BIO_puts(out,buf); | ||
265 | if (n_used == 0) return; | 240 | if (n_used == 0) return; |
266 | sprintf(buf,"load %d.%02d actual load %d.%02d\n", | 241 | BIO_printf(out,"load %d.%02d actual load %d.%02d\n", |
267 | (int)(total/lh->num_nodes), | 242 | (int)(total/lh->num_nodes), |
268 | (int)((total%lh->num_nodes)*100/lh->num_nodes), | 243 | (int)((total%lh->num_nodes)*100/lh->num_nodes), |
269 | (int)(total/n_used), | 244 | (int)(total/n_used), |
270 | (int)((total%n_used)*100/n_used)); | 245 | (int)((total%n_used)*100/n_used)); |
271 | BIO_puts(out,buf); | ||
272 | } | 246 | } |
273 | 247 | ||
274 | #endif | 248 | #endif |
diff --git a/src/lib/libcrypto/md32_common.h b/src/lib/libcrypto/md32_common.h index 353d2b96ad..573850b122 100644 --- a/src/lib/libcrypto/md32_common.h +++ b/src/lib/libcrypto/md32_common.h | |||
@@ -1,6 +1,6 @@ | |||
1 | /* crypto/md32_common.h */ | 1 | /* crypto/md32_common.h */ |
2 | /* ==================================================================== | 2 | /* ==================================================================== |
3 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | 3 | * Copyright (c) 1999-2002 The OpenSSL Project. All rights reserved. |
4 | * | 4 | * |
5 | * Redistribution and use in source and binary forms, with or without | 5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions | 6 | * modification, are permitted provided that the following conditions |
@@ -198,7 +198,7 @@ | |||
198 | * | 198 | * |
199 | * <appro@fy.chalmers.se> | 199 | * <appro@fy.chalmers.se> |
200 | */ | 200 | */ |
201 | # if defined(__i386) || defined(__i386__) | 201 | # if defined(__i386) || defined(__i386__) || defined(__x86_64) || defined(__x86_64__) |
202 | # define ROTATE(a,n) ({ register unsigned int ret; \ | 202 | # define ROTATE(a,n) ({ register unsigned int ret; \ |
203 | asm ( \ | 203 | asm ( \ |
204 | "roll %1,%0" \ | 204 | "roll %1,%0" \ |
@@ -224,7 +224,7 @@ | |||
224 | */ | 224 | */ |
225 | # if defined(__GNUC__) && __GNUC__>=2 && !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_NO_INLINE_ASM) | 225 | # if defined(__GNUC__) && __GNUC__>=2 && !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_NO_INLINE_ASM) |
226 | /* some GNU C inline assembler templates by <appro@fy.chalmers.se> */ | 226 | /* some GNU C inline assembler templates by <appro@fy.chalmers.se> */ |
227 | # if (defined(__i386) || defined(__i386__)) && !defined(I386_ONLY) | 227 | # if (defined(__i386) || defined(__i386__) || defined(__x86_64) || defined(__x86_64__)) && !defined(I386_ONLY) |
228 | # define BE_FETCH32(a) ({ register unsigned int l=(a);\ | 228 | # define BE_FETCH32(a) ({ register unsigned int l=(a);\ |
229 | asm ( \ | 229 | asm ( \ |
230 | "bswapl %0" \ | 230 | "bswapl %0" \ |
@@ -456,7 +456,10 @@ int HASH_UPDATE (HASH_CTX *c, const void *data_, unsigned long len) | |||
456 | { | 456 | { |
457 | ew=(c->num>>2); | 457 | ew=(c->num>>2); |
458 | ec=(c->num&0x03); | 458 | ec=(c->num&0x03); |
459 | l=p[sw]; HOST_p_c2l(data,l,sc); p[sw++]=l; | 459 | if (sc) |
460 | l=p[sw]; | ||
461 | HOST_p_c2l(data,l,sc); | ||
462 | p[sw++]=l; | ||
460 | for (; sw < ew; sw++) | 463 | for (; sw < ew; sw++) |
461 | { | 464 | { |
462 | HOST_c2l(data,l); p[sw]=l; | 465 | HOST_c2l(data,l); p[sw]=l; |
@@ -603,7 +606,32 @@ int HASH_FINAL (unsigned char *md, HASH_CTX *c) | |||
603 | c->num=0; | 606 | c->num=0; |
604 | /* clear stuff, HASH_BLOCK may be leaving some stuff on the stack | 607 | /* clear stuff, HASH_BLOCK may be leaving some stuff on the stack |
605 | * but I'm not worried :-) | 608 | * but I'm not worried :-) |
606 | memset((void *)c,0,sizeof(HASH_CTX)); | 609 | OPENSSL_cleanse((void *)c,sizeof(HASH_CTX)); |
607 | */ | 610 | */ |
608 | return 1; | 611 | return 1; |
609 | } | 612 | } |
613 | |||
614 | #ifndef MD32_REG_T | ||
615 | #define MD32_REG_T long | ||
616 | /* | ||
617 | * This comment was originaly written for MD5, which is why it | ||
618 | * discusses A-D. But it basically applies to all 32-bit digests, | ||
619 | * which is why it was moved to common header file. | ||
620 | * | ||
621 | * In case you wonder why A-D are declared as long and not | ||
622 | * as MD5_LONG. Doing so results in slight performance | ||
623 | * boost on LP64 architectures. The catch is we don't | ||
624 | * really care if 32 MSBs of a 64-bit register get polluted | ||
625 | * with eventual overflows as we *save* only 32 LSBs in | ||
626 | * *either* case. Now declaring 'em long excuses the compiler | ||
627 | * from keeping 32 MSBs zeroed resulting in 13% performance | ||
628 | * improvement under SPARC Solaris7/64 and 5% under AlphaLinux. | ||
629 | * Well, to be honest it should say that this *prevents* | ||
630 | * performance degradation. | ||
631 | * <appro@fy.chalmers.se> | ||
632 | * Apparently there're LP64 compilers that generate better | ||
633 | * code if A-D are declared int. Most notably GCC-x86_64 | ||
634 | * generates better code. | ||
635 | * <appro@fy.chalmers.se> | ||
636 | */ | ||
637 | #endif | ||
diff --git a/src/lib/libcrypto/md4/md4_dgst.c b/src/lib/libcrypto/md4/md4_dgst.c index 6446f5f5e7..7afb7185b6 100644 --- a/src/lib/libcrypto/md4/md4_dgst.c +++ b/src/lib/libcrypto/md4/md4_dgst.c | |||
@@ -86,21 +86,7 @@ int MD4_Init(MD4_CTX *c) | |||
86 | void md4_block_host_order (MD4_CTX *c, const void *data, int num) | 86 | void md4_block_host_order (MD4_CTX *c, const void *data, int num) |
87 | { | 87 | { |
88 | const MD4_LONG *X=data; | 88 | const MD4_LONG *X=data; |
89 | register unsigned long A,B,C,D; | 89 | register unsigned MD32_REG_T A,B,C,D; |
90 | /* | ||
91 | * In case you wonder why A-D are declared as long and not | ||
92 | * as MD4_LONG. Doing so results in slight performance | ||
93 | * boost on LP64 architectures. The catch is we don't | ||
94 | * really care if 32 MSBs of a 64-bit register get polluted | ||
95 | * with eventual overflows as we *save* only 32 LSBs in | ||
96 | * *either* case. Now declaring 'em long excuses the compiler | ||
97 | * from keeping 32 MSBs zeroed resulting in 13% performance | ||
98 | * improvement under SPARC Solaris7/64 and 5% under AlphaLinux. | ||
99 | * Well, to be honest it should say that this *prevents* | ||
100 | * performance degradation. | ||
101 | * | ||
102 | * <appro@fy.chalmers.se> | ||
103 | */ | ||
104 | 90 | ||
105 | A=c->A; | 91 | A=c->A; |
106 | B=c->B; | 92 | B=c->B; |
@@ -176,25 +162,11 @@ void md4_block_host_order (MD4_CTX *c, const void *data, int num) | |||
176 | void md4_block_data_order (MD4_CTX *c, const void *data_, int num) | 162 | void md4_block_data_order (MD4_CTX *c, const void *data_, int num) |
177 | { | 163 | { |
178 | const unsigned char *data=data_; | 164 | const unsigned char *data=data_; |
179 | register unsigned long A,B,C,D,l; | 165 | register unsigned MD32_REG_T A,B,C,D,l; |
180 | /* | ||
181 | * In case you wonder why A-D are declared as long and not | ||
182 | * as MD4_LONG. Doing so results in slight performance | ||
183 | * boost on LP64 architectures. The catch is we don't | ||
184 | * really care if 32 MSBs of a 64-bit register get polluted | ||
185 | * with eventual overflows as we *save* only 32 LSBs in | ||
186 | * *either* case. Now declaring 'em long excuses the compiler | ||
187 | * from keeping 32 MSBs zeroed resulting in 13% performance | ||
188 | * improvement under SPARC Solaris7/64 and 5% under AlphaLinux. | ||
189 | * Well, to be honest it should say that this *prevents* | ||
190 | * performance degradation. | ||
191 | * | ||
192 | * <appro@fy.chalmers.se> | ||
193 | */ | ||
194 | #ifndef MD32_XARRAY | 166 | #ifndef MD32_XARRAY |
195 | /* See comment in crypto/sha/sha_locl.h for details. */ | 167 | /* See comment in crypto/sha/sha_locl.h for details. */ |
196 | unsigned long XX0, XX1, XX2, XX3, XX4, XX5, XX6, XX7, | 168 | unsigned MD32_REG_T XX0, XX1, XX2, XX3, XX4, XX5, XX6, XX7, |
197 | XX8, XX9,XX10,XX11,XX12,XX13,XX14,XX15; | 169 | XX8, XX9,XX10,XX11,XX12,XX13,XX14,XX15; |
198 | # define X(i) XX##i | 170 | # define X(i) XX##i |
199 | #else | 171 | #else |
200 | MD4_LONG XX[MD4_LBLOCK]; | 172 | MD4_LONG XX[MD4_LBLOCK]; |
diff --git a/src/lib/libcrypto/md4/md4_one.c b/src/lib/libcrypto/md4/md4_one.c index 87a995d38d..00565507e4 100644 --- a/src/lib/libcrypto/md4/md4_one.c +++ b/src/lib/libcrypto/md4/md4_one.c | |||
@@ -59,6 +59,7 @@ | |||
59 | #include <stdio.h> | 59 | #include <stdio.h> |
60 | #include <string.h> | 60 | #include <string.h> |
61 | #include <openssl/md4.h> | 61 | #include <openssl/md4.h> |
62 | #include <openssl/crypto.h> | ||
62 | 63 | ||
63 | #ifdef CHARSET_EBCDIC | 64 | #ifdef CHARSET_EBCDIC |
64 | #include <openssl/ebcdic.h> | 65 | #include <openssl/ebcdic.h> |
@@ -89,7 +90,7 @@ unsigned char *MD4(const unsigned char *d, unsigned long n, unsigned char *md) | |||
89 | } | 90 | } |
90 | #endif | 91 | #endif |
91 | MD4_Final(md,&c); | 92 | MD4_Final(md,&c); |
92 | memset(&c,0,sizeof(c)); /* security consideration */ | 93 | OPENSSL_cleanse(&c,sizeof(c)); /* security consideration */ |
93 | return(md); | 94 | return(md); |
94 | } | 95 | } |
95 | 96 | ||
diff --git a/src/lib/libcrypto/md5/md5.h b/src/lib/libcrypto/md5/md5.h index 52cb753e6a..a252e02115 100644 --- a/src/lib/libcrypto/md5/md5.h +++ b/src/lib/libcrypto/md5/md5.h | |||
@@ -59,6 +59,8 @@ | |||
59 | #ifndef HEADER_MD5_H | 59 | #ifndef HEADER_MD5_H |
60 | #define HEADER_MD5_H | 60 | #define HEADER_MD5_H |
61 | 61 | ||
62 | #include <openssl/e_os2.h> | ||
63 | |||
62 | #ifdef __cplusplus | 64 | #ifdef __cplusplus |
63 | extern "C" { | 65 | extern "C" { |
64 | #endif | 66 | #endif |
@@ -76,7 +78,7 @@ extern "C" { | |||
76 | 78 | ||
77 | #if defined(OPENSSL_SYS_WIN16) || defined(__LP32__) | 79 | #if defined(OPENSSL_SYS_WIN16) || defined(__LP32__) |
78 | #define MD5_LONG unsigned long | 80 | #define MD5_LONG unsigned long |
79 | #elif defined(OENSSL_SYS_CRAY) || defined(__ILP64__) | 81 | #elif defined(OPENSSL_SYS_CRAY) || defined(__ILP64__) |
80 | #define MD5_LONG unsigned long | 82 | #define MD5_LONG unsigned long |
81 | #define MD5_LONG_LOG2 3 | 83 | #define MD5_LONG_LOG2 3 |
82 | /* | 84 | /* |
diff --git a/src/lib/libcrypto/md5/md5_dgst.c b/src/lib/libcrypto/md5/md5_dgst.c index c38a3f021e..9c7abc3697 100644 --- a/src/lib/libcrypto/md5/md5_dgst.c +++ b/src/lib/libcrypto/md5/md5_dgst.c | |||
@@ -86,21 +86,7 @@ int MD5_Init(MD5_CTX *c) | |||
86 | void md5_block_host_order (MD5_CTX *c, const void *data, int num) | 86 | void md5_block_host_order (MD5_CTX *c, const void *data, int num) |
87 | { | 87 | { |
88 | const MD5_LONG *X=data; | 88 | const MD5_LONG *X=data; |
89 | register unsigned long A,B,C,D; | 89 | register unsigned MD32_REG_T A,B,C,D; |
90 | /* | ||
91 | * In case you wonder why A-D are declared as long and not | ||
92 | * as MD5_LONG. Doing so results in slight performance | ||
93 | * boost on LP64 architectures. The catch is we don't | ||
94 | * really care if 32 MSBs of a 64-bit register get polluted | ||
95 | * with eventual overflows as we *save* only 32 LSBs in | ||
96 | * *either* case. Now declaring 'em long excuses the compiler | ||
97 | * from keeping 32 MSBs zeroed resulting in 13% performance | ||
98 | * improvement under SPARC Solaris7/64 and 5% under AlphaLinux. | ||
99 | * Well, to be honest it should say that this *prevents* | ||
100 | * performance degradation. | ||
101 | * | ||
102 | * <appro@fy.chalmers.se> | ||
103 | */ | ||
104 | 90 | ||
105 | A=c->A; | 91 | A=c->A; |
106 | B=c->B; | 92 | B=c->B; |
@@ -193,25 +179,11 @@ void md5_block_host_order (MD5_CTX *c, const void *data, int num) | |||
193 | void md5_block_data_order (MD5_CTX *c, const void *data_, int num) | 179 | void md5_block_data_order (MD5_CTX *c, const void *data_, int num) |
194 | { | 180 | { |
195 | const unsigned char *data=data_; | 181 | const unsigned char *data=data_; |
196 | register unsigned long A,B,C,D,l; | 182 | register unsigned MD32_REG_T A,B,C,D,l; |
197 | /* | ||
198 | * In case you wonder why A-D are declared as long and not | ||
199 | * as MD5_LONG. Doing so results in slight performance | ||
200 | * boost on LP64 architectures. The catch is we don't | ||
201 | * really care if 32 MSBs of a 64-bit register get polluted | ||
202 | * with eventual overflows as we *save* only 32 LSBs in | ||
203 | * *either* case. Now declaring 'em long excuses the compiler | ||
204 | * from keeping 32 MSBs zeroed resulting in 13% performance | ||
205 | * improvement under SPARC Solaris7/64 and 5% under AlphaLinux. | ||
206 | * Well, to be honest it should say that this *prevents* | ||
207 | * performance degradation. | ||
208 | * | ||
209 | * <appro@fy.chalmers.se> | ||
210 | */ | ||
211 | #ifndef MD32_XARRAY | 183 | #ifndef MD32_XARRAY |
212 | /* See comment in crypto/sha/sha_locl.h for details. */ | 184 | /* See comment in crypto/sha/sha_locl.h for details. */ |
213 | unsigned long XX0, XX1, XX2, XX3, XX4, XX5, XX6, XX7, | 185 | unsigned MD32_REG_T XX0, XX1, XX2, XX3, XX4, XX5, XX6, XX7, |
214 | XX8, XX9,XX10,XX11,XX12,XX13,XX14,XX15; | 186 | XX8, XX9,XX10,XX11,XX12,XX13,XX14,XX15; |
215 | # define X(i) XX##i | 187 | # define X(i) XX##i |
216 | #else | 188 | #else |
217 | MD5_LONG XX[MD5_LBLOCK]; | 189 | MD5_LONG XX[MD5_LBLOCK]; |
diff --git a/src/lib/libcrypto/md5/md5_locl.h b/src/lib/libcrypto/md5/md5_locl.h index 34c5257306..9e360da732 100644 --- a/src/lib/libcrypto/md5/md5_locl.h +++ b/src/lib/libcrypto/md5/md5_locl.h | |||
@@ -58,7 +58,7 @@ | |||
58 | 58 | ||
59 | #include <stdlib.h> | 59 | #include <stdlib.h> |
60 | #include <string.h> | 60 | #include <string.h> |
61 | #include <openssl/opensslconf.h> | 61 | #include <openssl/e_os2.h> |
62 | #include <openssl/md5.h> | 62 | #include <openssl/md5.h> |
63 | 63 | ||
64 | #ifndef MD5_LONG_LOG2 | 64 | #ifndef MD5_LONG_LOG2 |
diff --git a/src/lib/libcrypto/md5/md5_one.c b/src/lib/libcrypto/md5/md5_one.c index b89dec850d..c5dd2d81db 100644 --- a/src/lib/libcrypto/md5/md5_one.c +++ b/src/lib/libcrypto/md5/md5_one.c | |||
@@ -59,6 +59,7 @@ | |||
59 | #include <stdio.h> | 59 | #include <stdio.h> |
60 | #include <string.h> | 60 | #include <string.h> |
61 | #include <openssl/md5.h> | 61 | #include <openssl/md5.h> |
62 | #include <openssl/crypto.h> | ||
62 | 63 | ||
63 | #ifdef CHARSET_EBCDIC | 64 | #ifdef CHARSET_EBCDIC |
64 | #include <openssl/ebcdic.h> | 65 | #include <openssl/ebcdic.h> |
@@ -89,7 +90,7 @@ unsigned char *MD5(const unsigned char *d, unsigned long n, unsigned char *md) | |||
89 | } | 90 | } |
90 | #endif | 91 | #endif |
91 | MD5_Final(md,&c); | 92 | MD5_Final(md,&c); |
92 | memset(&c,0,sizeof(c)); /* security consideration */ | 93 | OPENSSL_cleanse(&c,sizeof(c)); /* security consideration */ |
93 | return(md); | 94 | return(md); |
94 | } | 95 | } |
95 | 96 | ||
diff --git a/src/lib/libcrypto/mem_clr.c b/src/lib/libcrypto/mem_clr.c new file mode 100644 index 0000000000..e4b7f540b0 --- /dev/null +++ b/src/lib/libcrypto/mem_clr.c | |||
@@ -0,0 +1,75 @@ | |||
1 | /* crypto/mem_clr.c -*- mode:C; c-file-style: "eay" -*- */ | ||
2 | /* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL | ||
3 | * project 2002. | ||
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 | * 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 <string.h> | ||
60 | #include <openssl/crypto.h> | ||
61 | |||
62 | unsigned char cleanse_ctr = 0; | ||
63 | |||
64 | void OPENSSL_cleanse(void *ptr, size_t len) | ||
65 | { | ||
66 | unsigned char *p = ptr; | ||
67 | size_t loop = len; | ||
68 | while(loop--) | ||
69 | { | ||
70 | *(p++) = cleanse_ctr; | ||
71 | cleanse_ctr += (17 + (unsigned char)((int)p & 0xF)); | ||
72 | } | ||
73 | if(memchr(ptr, cleanse_ctr, len)) | ||
74 | cleanse_ctr += 63; | ||
75 | } | ||
diff --git a/src/lib/libcrypto/mem_dbg.c b/src/lib/libcrypto/mem_dbg.c index 1c4e04f51f..57bd08f65d 100644 --- a/src/lib/libcrypto/mem_dbg.c +++ b/src/lib/libcrypto/mem_dbg.c | |||
@@ -102,6 +102,8 @@ typedef struct app_mem_info_st | |||
102 | int references; | 102 | int references; |
103 | } APP_INFO; | 103 | } APP_INFO; |
104 | 104 | ||
105 | static void app_info_free(APP_INFO *); | ||
106 | |||
105 | static LHASH *amih=NULL; /* hash-table with those app_mem_info_st's | 107 | static LHASH *amih=NULL; /* hash-table with those app_mem_info_st's |
106 | * that are at the top of their thread's stack | 108 | * that are at the top of their thread's stack |
107 | * (with `thread' as key); | 109 | * (with `thread' as key); |
@@ -140,6 +142,18 @@ static unsigned long disabling_thread = 0; /* Valid iff num_disable > 0. | |||
140 | * thread named in disabling_thread). | 142 | * thread named in disabling_thread). |
141 | */ | 143 | */ |
142 | 144 | ||
145 | static void app_info_free(APP_INFO *inf) | ||
146 | { | ||
147 | if (--(inf->references) <= 0) | ||
148 | { | ||
149 | if (inf->next != NULL) | ||
150 | { | ||
151 | app_info_free(inf->next); | ||
152 | } | ||
153 | OPENSSL_free(inf); | ||
154 | } | ||
155 | } | ||
156 | |||
143 | int CRYPTO_mem_ctrl(int mode) | 157 | int CRYPTO_mem_ctrl(int mode) |
144 | { | 158 | { |
145 | int ret=mh_mode; | 159 | int ret=mh_mode; |
@@ -502,9 +516,7 @@ void CRYPTO_dbg_free(void *addr, int before_p) | |||
502 | mp->order, mp->addr, mp->num); | 516 | mp->order, mp->addr, mp->num); |
503 | #endif | 517 | #endif |
504 | if (mp->app_info != NULL) | 518 | if (mp->app_info != NULL) |
505 | { | 519 | app_info_free(mp->app_info); |
506 | mp->app_info->references--; | ||
507 | } | ||
508 | OPENSSL_free(mp); | 520 | OPENSSL_free(mp); |
509 | } | 521 | } |
510 | 522 | ||
@@ -666,7 +678,6 @@ static IMPLEMENT_LHASH_DOALL_ARG_FN(print_leak, const MEM *, MEM_LEAK *) | |||
666 | void CRYPTO_mem_leaks(BIO *b) | 678 | void CRYPTO_mem_leaks(BIO *b) |
667 | { | 679 | { |
668 | MEM_LEAK ml; | 680 | MEM_LEAK ml; |
669 | char buf[80]; | ||
670 | 681 | ||
671 | if (mh == NULL && amih == NULL) | 682 | if (mh == NULL && amih == NULL) |
672 | return; | 683 | return; |
@@ -681,9 +692,8 @@ void CRYPTO_mem_leaks(BIO *b) | |||
681 | (char *)&ml); | 692 | (char *)&ml); |
682 | if (ml.chunks != 0) | 693 | if (ml.chunks != 0) |
683 | { | 694 | { |
684 | sprintf(buf,"%ld bytes leaked in %d chunks\n", | 695 | BIO_printf(b,"%ld bytes leaked in %d chunks\n", |
685 | ml.bytes,ml.chunks); | 696 | ml.bytes,ml.chunks); |
686 | BIO_puts(b,buf); | ||
687 | } | 697 | } |
688 | else | 698 | else |
689 | { | 699 | { |
diff --git a/src/lib/libcrypto/o_time.c b/src/lib/libcrypto/o_time.c index 1bc0297b36..723eb1b5af 100644 --- a/src/lib/libcrypto/o_time.c +++ b/src/lib/libcrypto/o_time.c | |||
@@ -80,6 +80,9 @@ struct tm *OPENSSL_gmtime(const time_t *timer, struct tm *result) | |||
80 | ts = result; | 80 | ts = result; |
81 | #elif !defined(OPENSSL_SYS_VMS) | 81 | #elif !defined(OPENSSL_SYS_VMS) |
82 | ts = gmtime(timer); | 82 | ts = gmtime(timer); |
83 | if (ts == NULL) | ||
84 | return NULL; | ||
85 | |||
83 | memcpy(result, ts, sizeof(struct tm)); | 86 | memcpy(result, ts, sizeof(struct tm)); |
84 | ts = result; | 87 | ts = result; |
85 | #endif | 88 | #endif |
diff --git a/src/lib/libcrypto/objects/obj_dat.c b/src/lib/libcrypto/objects/obj_dat.c index ce779dc1b5..5d983e3ed4 100644 --- a/src/lib/libcrypto/objects/obj_dat.c +++ b/src/lib/libcrypto/objects/obj_dat.c | |||
@@ -464,7 +464,7 @@ int OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name) | |||
464 | 464 | ||
465 | sprintf(tbuf,"%d.%lu",i,l); | 465 | sprintf(tbuf,"%d.%lu",i,l); |
466 | i=strlen(tbuf); | 466 | i=strlen(tbuf); |
467 | strncpy(buf,tbuf,buf_len); | 467 | BUF_strlcpy(buf,tbuf,buf_len); |
468 | buf_len-=i; | 468 | buf_len-=i; |
469 | buf+=i; | 469 | buf+=i; |
470 | n+=i; | 470 | n+=i; |
@@ -476,7 +476,7 @@ int OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name) | |||
476 | sprintf(tbuf,".%lu",l); | 476 | sprintf(tbuf,".%lu",l); |
477 | i=strlen(tbuf); | 477 | i=strlen(tbuf); |
478 | if (buf_len > 0) | 478 | if (buf_len > 0) |
479 | strncpy(buf,tbuf,buf_len); | 479 | BUF_strlcpy(buf,tbuf,buf_len); |
480 | buf_len-=i; | 480 | buf_len-=i; |
481 | buf+=i; | 481 | buf+=i; |
482 | n+=i; | 482 | n+=i; |
@@ -488,10 +488,9 @@ int OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name) | |||
488 | s=OBJ_nid2ln(nid); | 488 | s=OBJ_nid2ln(nid); |
489 | if (s == NULL) | 489 | if (s == NULL) |
490 | s=OBJ_nid2sn(nid); | 490 | s=OBJ_nid2sn(nid); |
491 | strncpy(buf,s,buf_len); | 491 | BUF_strlcpy(buf,s,buf_len); |
492 | n=strlen(s); | 492 | n=strlen(s); |
493 | } | 493 | } |
494 | buf[buf_len-1]='\0'; | ||
495 | return(n); | 494 | return(n); |
496 | } | 495 | } |
497 | 496 | ||
diff --git a/src/lib/libcrypto/objects/obj_mac.num b/src/lib/libcrypto/objects/obj_mac.num index 1486199661..9838072b65 100644 --- a/src/lib/libcrypto/objects/obj_mac.num +++ b/src/lib/libcrypto/objects/obj_mac.num | |||
@@ -645,3 +645,5 @@ rsaOAEPEncryptionSET 644 | |||
645 | itu_t 645 | 645 | itu_t 645 |
646 | joint_iso_itu_t 646 | 646 | joint_iso_itu_t 646 |
647 | international_organizations 647 | 647 | international_organizations 647 |
648 | ms_smartcard_login 648 | ||
649 | ms_upn 649 | ||
diff --git a/src/lib/libcrypto/objects/objects.txt b/src/lib/libcrypto/objects/objects.txt index 71a4908485..3ba11f65cc 100644 --- a/src/lib/libcrypto/objects/objects.txt +++ b/src/lib/libcrypto/objects/objects.txt | |||
@@ -276,6 +276,10 @@ rsadsi 3 8 : RC5-CBC : rc5-cbc | |||
276 | 1 3 6 1 4 1 311 10 3 3 : msSGC : Microsoft Server Gated Crypto | 276 | 1 3 6 1 4 1 311 10 3 3 : msSGC : Microsoft Server Gated Crypto |
277 | !Cname ms-efs | 277 | !Cname ms-efs |
278 | 1 3 6 1 4 1 311 10 3 4 : msEFS : Microsoft Encrypted File System | 278 | 1 3 6 1 4 1 311 10 3 4 : msEFS : Microsoft Encrypted File System |
279 | !Cname ms-smartcard-login | ||
280 | 1 3 6 1 4 1 311 20 2 2 : msSmartcardLogin : Microsoft Smartcardlogin | ||
281 | !Cname ms-upn | ||
282 | 1 3 6 1 4 1 311 20 2 3 : msUPN : Microsoft Universal Principal Name | ||
279 | 283 | ||
280 | 1 3 6 1 4 1 188 7 1 1 2 : IDEA-CBC : idea-cbc | 284 | 1 3 6 1 4 1 188 7 1 1 2 : IDEA-CBC : idea-cbc |
281 | : IDEA-ECB : idea-ecb | 285 | : IDEA-ECB : idea-ecb |
@@ -537,7 +541,7 @@ X509 11 : OU : organizationalUnitName | |||
537 | X509 12 : : title | 541 | X509 12 : : title |
538 | X509 13 : : description | 542 | X509 13 : : description |
539 | X509 41 : name : name | 543 | X509 41 : name : name |
540 | X509 42 : gn : givenName | 544 | X509 42 : GN : givenName |
541 | X509 43 : : initials | 545 | X509 43 : : initials |
542 | X509 44 : : generationQualifier | 546 | X509 44 : : generationQualifier |
543 | X509 45 : : x500UniqueIdentifier | 547 | X509 45 : : x500UniqueIdentifier |
diff --git a/src/lib/libcrypto/ocsp/ocsp_asn.c b/src/lib/libcrypto/ocsp/ocsp_asn.c index 8c148cda6a..6a3a360d54 100644 --- a/src/lib/libcrypto/ocsp/ocsp_asn.c +++ b/src/lib/libcrypto/ocsp/ocsp_asn.c | |||
@@ -117,7 +117,7 @@ IMPLEMENT_ASN1_FUNCTIONS(OCSP_RESPONSE) | |||
117 | 117 | ||
118 | ASN1_CHOICE(OCSP_RESPID) = { | 118 | ASN1_CHOICE(OCSP_RESPID) = { |
119 | ASN1_EXP(OCSP_RESPID, value.byName, X509_NAME, 1), | 119 | ASN1_EXP(OCSP_RESPID, value.byName, X509_NAME, 1), |
120 | ASN1_IMP(OCSP_RESPID, value.byKey, ASN1_OCTET_STRING, 2) | 120 | ASN1_EXP(OCSP_RESPID, value.byKey, ASN1_OCTET_STRING, 2) |
121 | } ASN1_CHOICE_END(OCSP_RESPID) | 121 | } ASN1_CHOICE_END(OCSP_RESPID) |
122 | 122 | ||
123 | IMPLEMENT_ASN1_FUNCTIONS(OCSP_RESPID) | 123 | IMPLEMENT_ASN1_FUNCTIONS(OCSP_RESPID) |
diff --git a/src/lib/libcrypto/ocsp/ocsp_ht.c b/src/lib/libcrypto/ocsp/ocsp_ht.c index b78cd37092..9213e58ae4 100644 --- a/src/lib/libcrypto/ocsp/ocsp_ht.c +++ b/src/lib/libcrypto/ocsp/ocsp_ht.c | |||
@@ -64,6 +64,9 @@ | |||
64 | #include <openssl/ocsp.h> | 64 | #include <openssl/ocsp.h> |
65 | #include <openssl/err.h> | 65 | #include <openssl/err.h> |
66 | #include <openssl/buffer.h> | 66 | #include <openssl/buffer.h> |
67 | #ifdef OPENSSL_SYS_SUNOS | ||
68 | #define strtoul (unsigned long)strtol | ||
69 | #endif /* OPENSSL_SYS_SUNOS */ | ||
67 | 70 | ||
68 | /* Quick and dirty HTTP OCSP request handler. | 71 | /* Quick and dirty HTTP OCSP request handler. |
69 | * Could make this a bit cleverer by adding | 72 | * Could make this a bit cleverer by adding |
@@ -94,7 +97,7 @@ Content-Length: %d\r\n\r\n"; | |||
94 | } | 97 | } |
95 | if(!(mem = BIO_new(BIO_s_mem()))) goto err; | 98 | if(!(mem = BIO_new(BIO_s_mem()))) goto err; |
96 | /* Copy response to a memory BIO: socket bios can't do gets! */ | 99 | /* Copy response to a memory BIO: socket bios can't do gets! */ |
97 | while ((len = BIO_read(b, tmpbuf, 1024))) { | 100 | while ((len = BIO_read(b, tmpbuf, sizeof tmpbuf))) { |
98 | if(len < 0) { | 101 | if(len < 0) { |
99 | OCSPerr(OCSP_F_OCSP_SENDREQ_BIO,OCSP_R_SERVER_READ_ERROR); | 102 | OCSPerr(OCSP_F_OCSP_SENDREQ_BIO,OCSP_R_SERVER_READ_ERROR); |
100 | goto err; | 103 | goto err; |
@@ -107,7 +110,7 @@ Content-Length: %d\r\n\r\n"; | |||
107 | } | 110 | } |
108 | /* Parse the HTTP response. This will look like this: | 111 | /* Parse the HTTP response. This will look like this: |
109 | * "HTTP/1.0 200 OK". We need to obtain the numeric code and | 112 | * "HTTP/1.0 200 OK". We need to obtain the numeric code and |
110 | * informational message. | 113 | * (optional) informational message. |
111 | */ | 114 | */ |
112 | 115 | ||
113 | /* Skip to first white space (passed protocol info) */ | 116 | /* Skip to first white space (passed protocol info) */ |
@@ -135,13 +138,19 @@ Content-Length: %d\r\n\r\n"; | |||
135 | if(*r) goto err; | 138 | if(*r) goto err; |
136 | /* Skip over any leading white space in message */ | 139 | /* Skip over any leading white space in message */ |
137 | while(*q && isspace((unsigned char)*q)) q++; | 140 | while(*q && isspace((unsigned char)*q)) q++; |
138 | if(!*q) goto err; | 141 | if(*q) { |
139 | /* Finally zap any trailing white space in message (include CRLF) */ | 142 | /* Finally zap any trailing white space in message (include CRLF) */ |
140 | /* We know q has a non white space character so this is OK */ | 143 | /* We know q has a non white space character so this is OK */ |
141 | for(r = q + strlen(q) - 1; isspace((unsigned char)*r); r--) *r = 0; | 144 | for(r = q + strlen(q) - 1; isspace((unsigned char)*r); r--) *r = 0; |
145 | } | ||
142 | if(retcode != 200) { | 146 | if(retcode != 200) { |
143 | OCSPerr(OCSP_F_OCSP_SENDREQ_BIO,OCSP_R_SERVER_RESPONSE_ERROR); | 147 | OCSPerr(OCSP_F_OCSP_SENDREQ_BIO,OCSP_R_SERVER_RESPONSE_ERROR); |
144 | ERR_add_error_data(4, "Code=", p, ",Reason=", q); | 148 | if(!*q) { |
149 | ERR_add_error_data(2, "Code=", p); | ||
150 | } | ||
151 | else { | ||
152 | ERR_add_error_data(4, "Code=", p, ",Reason=", q); | ||
153 | } | ||
145 | goto err; | 154 | goto err; |
146 | } | 155 | } |
147 | /* Find blank line marking beginning of content */ | 156 | /* Find blank line marking beginning of content */ |
diff --git a/src/lib/libcrypto/opensslv.h b/src/lib/libcrypto/opensslv.h index 9689b49c5b..08cb1d5018 100644 --- a/src/lib/libcrypto/opensslv.h +++ b/src/lib/libcrypto/opensslv.h | |||
@@ -25,8 +25,8 @@ | |||
25 | * (Prior to 0.9.5a beta1, a different scheme was used: MMNNFFRBB for | 25 | * (Prior to 0.9.5a beta1, a different scheme was used: MMNNFFRBB for |
26 | * major minor fix final patch/beta) | 26 | * major minor fix final patch/beta) |
27 | */ | 27 | */ |
28 | #define OPENSSL_VERSION_NUMBER 0x00907003L | 28 | #define OPENSSL_VERSION_NUMBER 0x0090702fL |
29 | #define OPENSSL_VERSION_TEXT "OpenSSL 0.9.7-beta3 30 Jul 2002" | 29 | #define OPENSSL_VERSION_TEXT "OpenSSL 0.9.7b 10 Apr 2003" |
30 | #define OPENSSL_VERSION_PTEXT " part of " OPENSSL_VERSION_TEXT | 30 | #define OPENSSL_VERSION_PTEXT " part of " OPENSSL_VERSION_TEXT |
31 | 31 | ||
32 | 32 | ||
diff --git a/src/lib/libcrypto/ossl_typ.h b/src/lib/libcrypto/ossl_typ.h index 6bd42aee4d..285fd0b1d9 100644 --- a/src/lib/libcrypto/ossl_typ.h +++ b/src/lib/libcrypto/ossl_typ.h | |||
@@ -55,6 +55,8 @@ | |||
55 | #ifndef HEADER_OPENSSL_TYPES_H | 55 | #ifndef HEADER_OPENSSL_TYPES_H |
56 | #define HEADER_OPENSSL_TYPES_H | 56 | #define HEADER_OPENSSL_TYPES_H |
57 | 57 | ||
58 | #include <openssl/e_os2.h> | ||
59 | |||
58 | #ifdef NO_ASN1_TYPEDEFS | 60 | #ifdef NO_ASN1_TYPEDEFS |
59 | #define ASN1_INTEGER ASN1_STRING | 61 | #define ASN1_INTEGER ASN1_STRING |
60 | #define ASN1_ENUMERATED ASN1_STRING | 62 | #define ASN1_ENUMERATED ASN1_STRING |
diff --git a/src/lib/libcrypto/pem/pem.h b/src/lib/libcrypto/pem/pem.h index 3785fca77d..d330cbf9a3 100644 --- a/src/lib/libcrypto/pem/pem.h +++ b/src/lib/libcrypto/pem/pem.h | |||
@@ -149,7 +149,7 @@ typedef struct pem_recip_st | |||
149 | 149 | ||
150 | int cipher; | 150 | int cipher; |
151 | int key_enc; | 151 | int key_enc; |
152 | char iv[8]; | 152 | /* char iv[8]; unused and wrong size */ |
153 | } PEM_USER; | 153 | } PEM_USER; |
154 | 154 | ||
155 | typedef struct pem_ctx_st | 155 | typedef struct pem_ctx_st |
@@ -165,7 +165,8 @@ typedef struct pem_ctx_st | |||
165 | 165 | ||
166 | struct { | 166 | struct { |
167 | int cipher; | 167 | int cipher; |
168 | unsigned char iv[8]; | 168 | /* unused, and wrong size |
169 | unsigned char iv[8]; */ | ||
169 | } DEK_info; | 170 | } DEK_info; |
170 | 171 | ||
171 | PEM_USER *originator; | 172 | PEM_USER *originator; |
@@ -187,7 +188,8 @@ typedef struct pem_ctx_st | |||
187 | EVP_CIPHER *dec; /* date encryption cipher */ | 188 | EVP_CIPHER *dec; /* date encryption cipher */ |
188 | int key_len; /* key length */ | 189 | int key_len; /* key length */ |
189 | unsigned char *key; /* key */ | 190 | unsigned char *key; /* key */ |
190 | unsigned char iv[8]; /* the iv */ | 191 | /* unused, and wrong size |
192 | unsigned char iv[8]; */ | ||
191 | 193 | ||
192 | 194 | ||
193 | int data_enc; /* is the data encrypted */ | 195 | int data_enc; /* is the data encrypted */ |
diff --git a/src/lib/libcrypto/pem/pem_info.c b/src/lib/libcrypto/pem/pem_info.c index 9a6dffb45c..9e4af29c95 100644 --- a/src/lib/libcrypto/pem/pem_info.c +++ b/src/lib/libcrypto/pem/pem_info.c | |||
@@ -324,6 +324,7 @@ int PEM_X509_INFO_write_bio(BIO *bp, X509_INFO *xi, EVP_CIPHER *enc, | |||
324 | } | 324 | } |
325 | 325 | ||
326 | /* create the right magic header stuff */ | 326 | /* create the right magic header stuff */ |
327 | OPENSSL_assert(strlen(objstr)+23+2*enc->iv_len+13 <= sizeof buf); | ||
327 | buf[0]='\0'; | 328 | buf[0]='\0'; |
328 | PEM_proc_type(buf,PEM_TYPE_ENCRYPTED); | 329 | PEM_proc_type(buf,PEM_TYPE_ENCRYPTED); |
329 | PEM_dek_info(buf,objstr,enc->iv_len,(char *)iv); | 330 | PEM_dek_info(buf,objstr,enc->iv_len,(char *)iv); |
@@ -358,7 +359,7 @@ int PEM_X509_INFO_write_bio(BIO *bp, X509_INFO *xi, EVP_CIPHER *enc, | |||
358 | ret=1; | 359 | ret=1; |
359 | 360 | ||
360 | err: | 361 | err: |
361 | memset((char *)&ctx,0,sizeof(ctx)); | 362 | OPENSSL_cleanse((char *)&ctx,sizeof(ctx)); |
362 | memset(buf,0,PEM_BUFSIZE); | 363 | OPENSSL_cleanse(buf,PEM_BUFSIZE); |
363 | return(ret); | 364 | return(ret); |
364 | } | 365 | } |
diff --git a/src/lib/libcrypto/pem/pem_lib.c b/src/lib/libcrypto/pem/pem_lib.c index a8db6ffbf5..70b5446797 100644 --- a/src/lib/libcrypto/pem/pem_lib.c +++ b/src/lib/libcrypto/pem/pem_lib.c | |||
@@ -138,7 +138,7 @@ void PEM_proc_type(char *buf, int type) | |||
138 | 138 | ||
139 | void PEM_dek_info(char *buf, const char *type, int len, char *str) | 139 | void PEM_dek_info(char *buf, const char *type, int len, char *str) |
140 | { | 140 | { |
141 | static unsigned char map[17]="0123456789ABCDEF"; | 141 | static const unsigned char map[17]="0123456789ABCDEF"; |
142 | long i; | 142 | long i; |
143 | int j; | 143 | int j; |
144 | 144 | ||
@@ -249,7 +249,7 @@ int PEM_bytes_read_bio(unsigned char **pdata, long *plen, char **pnm, const char | |||
249 | ret = 1; | 249 | ret = 1; |
250 | 250 | ||
251 | err: | 251 | err: |
252 | if (!pnm) OPENSSL_free(nm); | 252 | if (!ret || !pnm) OPENSSL_free(nm); |
253 | OPENSSL_free(header); | 253 | OPENSSL_free(header); |
254 | if (!ret) OPENSSL_free(data); | 254 | if (!ret) OPENSSL_free(data); |
255 | return ret; | 255 | return ret; |
@@ -304,6 +304,7 @@ int PEM_ASN1_write_bio(int (*i2d)(), const char *name, BIO *bp, char *x, | |||
304 | goto err; | 304 | goto err; |
305 | } | 305 | } |
306 | /* dzise + 8 bytes are needed */ | 306 | /* dzise + 8 bytes are needed */ |
307 | /* actually it needs the cipher block size extra... */ | ||
307 | data=(unsigned char *)OPENSSL_malloc((unsigned int)dsize+20); | 308 | data=(unsigned char *)OPENSSL_malloc((unsigned int)dsize+20); |
308 | if (data == NULL) | 309 | if (data == NULL) |
309 | { | 310 | { |
@@ -333,13 +334,16 @@ int PEM_ASN1_write_bio(int (*i2d)(), const char *name, BIO *bp, char *x, | |||
333 | kstr=(unsigned char *)buf; | 334 | kstr=(unsigned char *)buf; |
334 | } | 335 | } |
335 | RAND_add(data,i,0);/* put in the RSA key. */ | 336 | RAND_add(data,i,0);/* put in the RSA key. */ |
337 | OPENSSL_assert(enc->iv_len <= sizeof iv); | ||
336 | if (RAND_pseudo_bytes(iv,enc->iv_len) < 0) /* Generate a salt */ | 338 | if (RAND_pseudo_bytes(iv,enc->iv_len) < 0) /* Generate a salt */ |
337 | goto err; | 339 | goto err; |
338 | /* The 'iv' is used as the iv and as a salt. It is | 340 | /* The 'iv' is used as the iv and as a salt. It is |
339 | * NOT taken from the BytesToKey function */ | 341 | * NOT taken from the BytesToKey function */ |
340 | EVP_BytesToKey(enc,EVP_md5(),iv,kstr,klen,1,key,NULL); | 342 | EVP_BytesToKey(enc,EVP_md5(),iv,kstr,klen,1,key,NULL); |
341 | 343 | ||
342 | if (kstr == (unsigned char *)buf) memset(buf,0,PEM_BUFSIZE); | 344 | if (kstr == (unsigned char *)buf) OPENSSL_cleanse(buf,PEM_BUFSIZE); |
345 | |||
346 | OPENSSL_assert(strlen(objstr)+23+2*enc->iv_len+13 <= sizeof buf); | ||
343 | 347 | ||
344 | buf[0]='\0'; | 348 | buf[0]='\0'; |
345 | PEM_proc_type(buf,PEM_TYPE_ENCRYPTED); | 349 | PEM_proc_type(buf,PEM_TYPE_ENCRYPTED); |
@@ -362,13 +366,13 @@ int PEM_ASN1_write_bio(int (*i2d)(), const char *name, BIO *bp, char *x, | |||
362 | i=PEM_write_bio(bp,name,buf,data,i); | 366 | i=PEM_write_bio(bp,name,buf,data,i); |
363 | if (i <= 0) ret=0; | 367 | if (i <= 0) ret=0; |
364 | err: | 368 | err: |
365 | memset(key,0,sizeof(key)); | 369 | OPENSSL_cleanse(key,sizeof(key)); |
366 | memset(iv,0,sizeof(iv)); | 370 | OPENSSL_cleanse(iv,sizeof(iv)); |
367 | memset((char *)&ctx,0,sizeof(ctx)); | 371 | OPENSSL_cleanse((char *)&ctx,sizeof(ctx)); |
368 | memset(buf,0,PEM_BUFSIZE); | 372 | OPENSSL_cleanse(buf,PEM_BUFSIZE); |
369 | if (data != NULL) | 373 | if (data != NULL) |
370 | { | 374 | { |
371 | memset(data,0,(unsigned int)dsize); | 375 | OPENSSL_cleanse(data,(unsigned int)dsize); |
372 | OPENSSL_free(data); | 376 | OPENSSL_free(data); |
373 | } | 377 | } |
374 | return(ret); | 378 | return(ret); |
@@ -409,8 +413,8 @@ int PEM_do_header(EVP_CIPHER_INFO *cipher, unsigned char *data, long *plen, | |||
409 | EVP_DecryptUpdate(&ctx,data,&i,data,j); | 413 | EVP_DecryptUpdate(&ctx,data,&i,data,j); |
410 | o=EVP_DecryptFinal_ex(&ctx,&(data[i]),&j); | 414 | o=EVP_DecryptFinal_ex(&ctx,&(data[i]),&j); |
411 | EVP_CIPHER_CTX_cleanup(&ctx); | 415 | EVP_CIPHER_CTX_cleanup(&ctx); |
412 | memset((char *)buf,0,sizeof(buf)); | 416 | OPENSSL_cleanse((char *)buf,sizeof(buf)); |
413 | memset((char *)key,0,sizeof(key)); | 417 | OPENSSL_cleanse((char *)key,sizeof(key)); |
414 | j+=i; | 418 | j+=i; |
415 | if (!o) | 419 | if (!o) |
416 | { | 420 | { |
@@ -691,7 +695,7 @@ int PEM_read_bio(BIO *bp, char **name, char **header, unsigned char **data, | |||
691 | if (strncmp(buf,"-----END ",9) == 0) | 695 | if (strncmp(buf,"-----END ",9) == 0) |
692 | break; | 696 | break; |
693 | if (i > 65) break; | 697 | if (i > 65) break; |
694 | if (!BUF_MEM_grow(dataB,i+bl+9)) | 698 | if (!BUF_MEM_grow_clean(dataB,i+bl+9)) |
695 | { | 699 | { |
696 | PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE); | 700 | PEMerr(PEM_F_PEM_READ_BIO,ERR_R_MALLOC_FAILURE); |
697 | goto err; | 701 | goto err; |
diff --git a/src/lib/libcrypto/pem/pem_pk8.c b/src/lib/libcrypto/pem/pem_pk8.c index f44182ffb5..db38a2a79d 100644 --- a/src/lib/libcrypto/pem/pem_pk8.c +++ b/src/lib/libcrypto/pem/pem_pk8.c | |||
@@ -136,7 +136,7 @@ static int do_pk8pkey(BIO *bp, EVP_PKEY *x, int isder, int nid, const EVP_CIPHER | |||
136 | kstr = buf; | 136 | kstr = buf; |
137 | } | 137 | } |
138 | p8 = PKCS8_encrypt(nid, enc, kstr, klen, NULL, 0, 0, p8inf); | 138 | p8 = PKCS8_encrypt(nid, enc, kstr, klen, NULL, 0, 0, p8inf); |
139 | if(kstr == buf) memset(buf, 0, klen); | 139 | if(kstr == buf) OPENSSL_cleanse(buf, klen); |
140 | PKCS8_PRIV_KEY_INFO_free(p8inf); | 140 | PKCS8_PRIV_KEY_INFO_free(p8inf); |
141 | if(isder) ret = i2d_PKCS8_bio(bp, p8); | 141 | if(isder) ret = i2d_PKCS8_bio(bp, p8); |
142 | else ret = PEM_write_bio_PKCS8(bp, p8); | 142 | else ret = PEM_write_bio_PKCS8(bp, p8); |
diff --git a/src/lib/libcrypto/pem/pem_seal.c b/src/lib/libcrypto/pem/pem_seal.c index ae463a301d..56e08abd70 100644 --- a/src/lib/libcrypto/pem/pem_seal.c +++ b/src/lib/libcrypto/pem/pem_seal.c | |||
@@ -112,7 +112,7 @@ int PEM_SealInit(PEM_ENCODE_SEAL_CTX *ctx, EVP_CIPHER *type, EVP_MD *md_type, | |||
112 | ret=npubk; | 112 | ret=npubk; |
113 | err: | 113 | err: |
114 | if (s != NULL) OPENSSL_free(s); | 114 | if (s != NULL) OPENSSL_free(s); |
115 | memset(key,0,EVP_MAX_KEY_LENGTH); | 115 | OPENSSL_cleanse(key,EVP_MAX_KEY_LENGTH); |
116 | return(ret); | 116 | return(ret); |
117 | } | 117 | } |
118 | 118 | ||
diff --git a/src/lib/libcrypto/perlasm/cbc.pl b/src/lib/libcrypto/perlasm/cbc.pl index 0145c4f0cc..22149c680e 100644 --- a/src/lib/libcrypto/perlasm/cbc.pl +++ b/src/lib/libcrypto/perlasm/cbc.pl | |||
@@ -146,9 +146,15 @@ sub cbc | |||
146 | &mov($count, &wparam(2)); # length | 146 | &mov($count, &wparam(2)); # length |
147 | &and($count, 7); | 147 | &and($count, 7); |
148 | &jz(&label("finish")); | 148 | &jz(&label("finish")); |
149 | &call(&label("PIC_point")); | ||
150 | &set_label("PIC_point"); | ||
151 | &blindpop("edx"); | ||
152 | &lea("ecx",&DWP(&label("cbc_enc_jmp_table")."-".&label("PIC_point"),"edx")); | ||
153 | &mov($count,&DWP(0,"ecx",$count,4)) | ||
154 | &add($count,"edx"); | ||
149 | &xor("ecx","ecx"); | 155 | &xor("ecx","ecx"); |
150 | &xor("edx","edx"); | 156 | &xor("edx","edx"); |
151 | &mov($count,&DWP(&label("cbc_enc_jmp_table"),"",$count,4)); | 157 | #&mov($count,&DWP(&label("cbc_enc_jmp_table"),"",$count,4)); |
152 | &jmp_ptr($count); | 158 | &jmp_ptr($count); |
153 | 159 | ||
154 | &set_label("ej7"); | 160 | &set_label("ej7"); |
@@ -318,22 +324,23 @@ sub cbc | |||
318 | 324 | ||
319 | &set_label("cbc_enc_jmp_table",1); | 325 | &set_label("cbc_enc_jmp_table",1); |
320 | &data_word("0"); | 326 | &data_word("0"); |
321 | &data_word(&label("ej1")); | 327 | &data_word(&label("ej1")."-".&label("PIC_point")); |
322 | &data_word(&label("ej2")); | 328 | &data_word(&label("ej2")."-".&label("PIC_point")); |
323 | &data_word(&label("ej3")); | 329 | &data_word(&label("ej3")."-".&label("PIC_point")); |
324 | &data_word(&label("ej4")); | 330 | &data_word(&label("ej4")."-".&label("PIC_point")); |
325 | &data_word(&label("ej5")); | 331 | &data_word(&label("ej5")."-".&label("PIC_point")); |
326 | &data_word(&label("ej6")); | 332 | &data_word(&label("ej6")."-".&label("PIC_point")); |
327 | &data_word(&label("ej7")); | 333 | &data_word(&label("ej7")."-".&label("PIC_point")); |
328 | &set_label("cbc_dec_jmp_table",1); | 334 | # not used |
329 | &data_word("0"); | 335 | #&set_label("cbc_dec_jmp_table",1); |
330 | &data_word(&label("dj1")); | 336 | #&data_word("0"); |
331 | &data_word(&label("dj2")); | 337 | #&data_word(&label("dj1")."-".&label("PIC_point")); |
332 | &data_word(&label("dj3")); | 338 | #&data_word(&label("dj2")."-".&label("PIC_point")); |
333 | &data_word(&label("dj4")); | 339 | #&data_word(&label("dj3")."-".&label("PIC_point")); |
334 | &data_word(&label("dj5")); | 340 | #&data_word(&label("dj4")."-".&label("PIC_point")); |
335 | &data_word(&label("dj6")); | 341 | #&data_word(&label("dj5")."-".&label("PIC_point")); |
336 | &data_word(&label("dj7")); | 342 | #&data_word(&label("dj6")."-".&label("PIC_point")); |
343 | #&data_word(&label("dj7")."-".&label("PIC_point")); | ||
337 | 344 | ||
338 | &function_end_B($name); | 345 | &function_end_B($name); |
339 | 346 | ||
diff --git a/src/lib/libcrypto/perlasm/x86asm.pl b/src/lib/libcrypto/perlasm/x86asm.pl index 9a3d85b098..1cb96e914a 100644 --- a/src/lib/libcrypto/perlasm/x86asm.pl +++ b/src/lib/libcrypto/perlasm/x86asm.pl | |||
@@ -18,9 +18,9 @@ sub main'asm_init | |||
18 | ($type,$fn,$i386)=@_; | 18 | ($type,$fn,$i386)=@_; |
19 | $filename=$fn; | 19 | $filename=$fn; |
20 | 20 | ||
21 | $cpp=$sol=$aout=$win32=$gaswin=0; | 21 | $elf=$cpp=$sol=$aout=$win32=$gaswin=0; |
22 | if ( ($type eq "elf")) | 22 | if ( ($type eq "elf")) |
23 | { require "x86unix.pl"; } | 23 | { $elf=1; require "x86unix.pl"; } |
24 | elsif ( ($type eq "a.out")) | 24 | elsif ( ($type eq "a.out")) |
25 | { $aout=1; require "x86unix.pl"; } | 25 | { $aout=1; require "x86unix.pl"; } |
26 | elsif ( ($type eq "gaswin")) | 26 | elsif ( ($type eq "gaswin")) |
@@ -47,6 +47,9 @@ EOF | |||
47 | exit(1); | 47 | exit(1); |
48 | } | 48 | } |
49 | 49 | ||
50 | $pic=0; | ||
51 | for (@ARGV) { $pic=1 if (/\-[fK]PIC/i); } | ||
52 | |||
50 | &asm_init_output(); | 53 | &asm_init_output(); |
51 | 54 | ||
52 | &comment("Don't even think of reading this code"); | 55 | &comment("Don't even think of reading this code"); |
@@ -91,7 +94,7 @@ $tmp | |||
91 | #undef SIZE | 94 | #undef SIZE |
92 | #undef TYPE | 95 | #undef TYPE |
93 | #define SIZE(a,b) | 96 | #define SIZE(a,b) |
94 | #define TYPE(a,b) | 97 | #define TYPE(a,b) .def a; .scl 2; .type 32; .endef |
95 | #endif /* __CYGWIN || __DJGPP */ | 98 | #endif /* __CYGWIN || __DJGPP */ |
96 | #endif | 99 | #endif |
97 | 100 | ||
diff --git a/src/lib/libcrypto/pkcs12/p12_crpt.c b/src/lib/libcrypto/pkcs12/p12_crpt.c index 97be6a5fb5..5e8958612b 100644 --- a/src/lib/libcrypto/pkcs12/p12_crpt.c +++ b/src/lib/libcrypto/pkcs12/p12_crpt.c | |||
@@ -118,7 +118,7 @@ int PKCS12_PBE_keyivgen (EVP_CIPHER_CTX *ctx, const char *pass, int passlen, | |||
118 | } | 118 | } |
119 | PBEPARAM_free(pbe); | 119 | PBEPARAM_free(pbe); |
120 | EVP_CipherInit_ex(ctx, cipher, NULL, key, iv, en_de); | 120 | EVP_CipherInit_ex(ctx, cipher, NULL, key, iv, en_de); |
121 | memset(key, 0, EVP_MAX_KEY_LENGTH); | 121 | OPENSSL_cleanse(key, EVP_MAX_KEY_LENGTH); |
122 | memset(iv, 0, EVP_MAX_IV_LENGTH); | 122 | OPENSSL_cleanse(iv, EVP_MAX_IV_LENGTH); |
123 | return 1; | 123 | return 1; |
124 | } | 124 | } |
diff --git a/src/lib/libcrypto/pkcs12/p12_decr.c b/src/lib/libcrypto/pkcs12/p12_decr.c index 394af368f4..b5684a83ba 100644 --- a/src/lib/libcrypto/pkcs12/p12_decr.c +++ b/src/lib/libcrypto/pkcs12/p12_decr.c | |||
@@ -136,7 +136,7 @@ void * PKCS12_item_decrypt_d2i(X509_ALGOR *algor, const ASN1_ITEM *it, | |||
136 | } | 136 | } |
137 | #endif | 137 | #endif |
138 | ret = ASN1_item_d2i(NULL, &p, outlen, it); | 138 | ret = ASN1_item_d2i(NULL, &p, outlen, it); |
139 | if (zbuf) memset(out, 0, outlen); | 139 | if (zbuf) OPENSSL_cleanse(out, outlen); |
140 | if(!ret) PKCS12err(PKCS12_F_PKCS12_DECRYPT_D2I,PKCS12_R_DECODE_ERROR); | 140 | if(!ret) PKCS12err(PKCS12_F_PKCS12_DECRYPT_D2I,PKCS12_R_DECODE_ERROR); |
141 | OPENSSL_free(out); | 141 | OPENSSL_free(out); |
142 | return ret; | 142 | return ret; |
@@ -168,7 +168,7 @@ ASN1_OCTET_STRING *PKCS12_item_i2d_encrypt(X509_ALGOR *algor, const ASN1_ITEM *i | |||
168 | OPENSSL_free(in); | 168 | OPENSSL_free(in); |
169 | return NULL; | 169 | return NULL; |
170 | } | 170 | } |
171 | if (zbuf) memset(in, 0, inlen); | 171 | if (zbuf) OPENSSL_cleanse(in, inlen); |
172 | OPENSSL_free(in); | 172 | OPENSSL_free(in); |
173 | return oct; | 173 | return oct; |
174 | } | 174 | } |
diff --git a/src/lib/libcrypto/pkcs12/p12_key.c b/src/lib/libcrypto/pkcs12/p12_key.c index 0d39ebde8c..9196a34b4a 100644 --- a/src/lib/libcrypto/pkcs12/p12_key.c +++ b/src/lib/libcrypto/pkcs12/p12_key.c | |||
@@ -91,7 +91,7 @@ int PKCS12_key_gen_asc(const char *pass, int passlen, unsigned char *salt, | |||
91 | ret = PKCS12_key_gen_uni(unipass, uniplen, salt, saltlen, | 91 | ret = PKCS12_key_gen_uni(unipass, uniplen, salt, saltlen, |
92 | id, iter, n, out, md_type); | 92 | id, iter, n, out, md_type); |
93 | if(unipass) { | 93 | if(unipass) { |
94 | memset(unipass, 0, uniplen); /* Clear password from memory */ | 94 | OPENSSL_cleanse(unipass, uniplen); /* Clear password from memory */ |
95 | OPENSSL_free(unipass); | 95 | OPENSSL_free(unipass); |
96 | } | 96 | } |
97 | return ret; | 97 | return ret; |
diff --git a/src/lib/libcrypto/pkcs12/p12_npas.c b/src/lib/libcrypto/pkcs12/p12_npas.c index a549433eeb..af708a2743 100644 --- a/src/lib/libcrypto/pkcs12/p12_npas.c +++ b/src/lib/libcrypto/pkcs12/p12_npas.c | |||
@@ -107,7 +107,7 @@ static int newpass_p12(PKCS12 *p12, char *oldpass, char *newpass) | |||
107 | { | 107 | { |
108 | STACK_OF(PKCS7) *asafes, *newsafes; | 108 | STACK_OF(PKCS7) *asafes, *newsafes; |
109 | STACK_OF(PKCS12_SAFEBAG) *bags; | 109 | STACK_OF(PKCS12_SAFEBAG) *bags; |
110 | int i, bagnid, pbe_nid, pbe_iter, pbe_saltlen; | 110 | int i, bagnid, pbe_nid = 0, pbe_iter = 0, pbe_saltlen = 0; |
111 | PKCS7 *p7, *p7new; | 111 | PKCS7 *p7, *p7new; |
112 | ASN1_OCTET_STRING *p12_data_tmp = NULL, *macnew = NULL; | 112 | ASN1_OCTET_STRING *p12_data_tmp = NULL, *macnew = NULL; |
113 | unsigned char mac[EVP_MAX_MD_SIZE]; | 113 | unsigned char mac[EVP_MAX_MD_SIZE]; |
diff --git a/src/lib/libcrypto/pkcs7/pk7_doit.c b/src/lib/libcrypto/pkcs7/pk7_doit.c index 4a4ff340ce..0060a2ea3d 100644 --- a/src/lib/libcrypto/pkcs7/pk7_doit.c +++ b/src/lib/libcrypto/pkcs7/pk7_doit.c | |||
@@ -241,7 +241,7 @@ BIO *PKCS7_dataInit(PKCS7 *p7, BIO *bio) | |||
241 | M_ASN1_OCTET_STRING_set(ri->enc_key,tmp,jj); | 241 | M_ASN1_OCTET_STRING_set(ri->enc_key,tmp,jj); |
242 | } | 242 | } |
243 | OPENSSL_free(tmp); | 243 | OPENSSL_free(tmp); |
244 | memset(key, 0, keylen); | 244 | OPENSSL_cleanse(key, keylen); |
245 | 245 | ||
246 | if (out == NULL) | 246 | if (out == NULL) |
247 | out=btmp; | 247 | out=btmp; |
@@ -448,7 +448,7 @@ BIO *PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert) | |||
448 | } | 448 | } |
449 | EVP_CipherInit_ex(evp_ctx,NULL,NULL,tmp,NULL,0); | 449 | EVP_CipherInit_ex(evp_ctx,NULL,NULL,tmp,NULL,0); |
450 | 450 | ||
451 | memset(tmp,0,jj); | 451 | OPENSSL_cleanse(tmp,jj); |
452 | 452 | ||
453 | if (out == NULL) | 453 | if (out == NULL) |
454 | out=etmp; | 454 | out=etmp; |
@@ -578,7 +578,7 @@ int PKCS7_dataFinal(PKCS7 *p7, BIO *bio) | |||
578 | /* We now have the EVP_MD_CTX, lets do the | 578 | /* We now have the EVP_MD_CTX, lets do the |
579 | * signing. */ | 579 | * signing. */ |
580 | EVP_MD_CTX_copy_ex(&ctx_tmp,mdc); | 580 | EVP_MD_CTX_copy_ex(&ctx_tmp,mdc); |
581 | if (!BUF_MEM_grow(buf,EVP_PKEY_size(si->pkey))) | 581 | if (!BUF_MEM_grow_clean(buf,EVP_PKEY_size(si->pkey))) |
582 | { | 582 | { |
583 | PKCS7err(PKCS7_F_PKCS7_DATASIGN,ERR_R_BIO_LIB); | 583 | PKCS7err(PKCS7_F_PKCS7_DATASIGN,ERR_R_BIO_LIB); |
584 | goto err; | 584 | goto err; |
diff --git a/src/lib/libcrypto/rand/rand.h b/src/lib/libcrypto/rand/rand.h index 66e39991ec..606382dd21 100644 --- a/src/lib/libcrypto/rand/rand.h +++ b/src/lib/libcrypto/rand/rand.h | |||
@@ -87,7 +87,9 @@ extern int rand_predictable; | |||
87 | 87 | ||
88 | int RAND_set_rand_method(const RAND_METHOD *meth); | 88 | int RAND_set_rand_method(const RAND_METHOD *meth); |
89 | const RAND_METHOD *RAND_get_rand_method(void); | 89 | const RAND_METHOD *RAND_get_rand_method(void); |
90 | #ifndef OPENSSL_NO_ENGINE | ||
90 | int RAND_set_rand_engine(ENGINE *engine); | 91 | int RAND_set_rand_engine(ENGINE *engine); |
92 | #endif | ||
91 | RAND_METHOD *RAND_SSLeay(void); | 93 | RAND_METHOD *RAND_SSLeay(void); |
92 | void RAND_cleanup(void ); | 94 | void RAND_cleanup(void ); |
93 | int RAND_bytes(unsigned char *buf,int num); | 95 | int RAND_bytes(unsigned char *buf,int num); |
diff --git a/src/lib/libcrypto/rand/rand_lib.c b/src/lib/libcrypto/rand/rand_lib.c index 5cf5dc1188..513e338985 100644 --- a/src/lib/libcrypto/rand/rand_lib.c +++ b/src/lib/libcrypto/rand/rand_lib.c | |||
@@ -60,19 +60,25 @@ | |||
60 | #include <time.h> | 60 | #include <time.h> |
61 | #include "cryptlib.h" | 61 | #include "cryptlib.h" |
62 | #include <openssl/rand.h> | 62 | #include <openssl/rand.h> |
63 | #ifndef OPENSSL_NO_ENGINE | ||
63 | #include <openssl/engine.h> | 64 | #include <openssl/engine.h> |
65 | #endif | ||
64 | 66 | ||
67 | #ifndef OPENSSL_NO_ENGINE | ||
65 | /* non-NULL if default_RAND_meth is ENGINE-provided */ | 68 | /* non-NULL if default_RAND_meth is ENGINE-provided */ |
66 | static ENGINE *funct_ref =NULL; | 69 | static ENGINE *funct_ref =NULL; |
70 | #endif | ||
67 | static const RAND_METHOD *default_RAND_meth = NULL; | 71 | static const RAND_METHOD *default_RAND_meth = NULL; |
68 | 72 | ||
69 | int RAND_set_rand_method(const RAND_METHOD *meth) | 73 | int RAND_set_rand_method(const RAND_METHOD *meth) |
70 | { | 74 | { |
75 | #ifndef OPENSSL_NO_ENGINE | ||
71 | if(funct_ref) | 76 | if(funct_ref) |
72 | { | 77 | { |
73 | ENGINE_finish(funct_ref); | 78 | ENGINE_finish(funct_ref); |
74 | funct_ref = NULL; | 79 | funct_ref = NULL; |
75 | } | 80 | } |
81 | #endif | ||
76 | default_RAND_meth = meth; | 82 | default_RAND_meth = meth; |
77 | return 1; | 83 | return 1; |
78 | } | 84 | } |
@@ -81,6 +87,7 @@ const RAND_METHOD *RAND_get_rand_method(void) | |||
81 | { | 87 | { |
82 | if (!default_RAND_meth) | 88 | if (!default_RAND_meth) |
83 | { | 89 | { |
90 | #ifndef OPENSSL_NO_ENGINE | ||
84 | ENGINE *e = ENGINE_get_default_RAND(); | 91 | ENGINE *e = ENGINE_get_default_RAND(); |
85 | if(e) | 92 | if(e) |
86 | { | 93 | { |
@@ -94,11 +101,13 @@ const RAND_METHOD *RAND_get_rand_method(void) | |||
94 | if(e) | 101 | if(e) |
95 | funct_ref = e; | 102 | funct_ref = e; |
96 | else | 103 | else |
104 | #endif | ||
97 | default_RAND_meth = RAND_SSLeay(); | 105 | default_RAND_meth = RAND_SSLeay(); |
98 | } | 106 | } |
99 | return default_RAND_meth; | 107 | return default_RAND_meth; |
100 | } | 108 | } |
101 | 109 | ||
110 | #ifndef OPENSSL_NO_ENGINE | ||
102 | int RAND_set_rand_engine(ENGINE *engine) | 111 | int RAND_set_rand_engine(ENGINE *engine) |
103 | { | 112 | { |
104 | const RAND_METHOD *tmp_meth = NULL; | 113 | const RAND_METHOD *tmp_meth = NULL; |
@@ -118,6 +127,7 @@ int RAND_set_rand_engine(ENGINE *engine) | |||
118 | funct_ref = engine; | 127 | funct_ref = engine; |
119 | return 1; | 128 | return 1; |
120 | } | 129 | } |
130 | #endif | ||
121 | 131 | ||
122 | void RAND_cleanup(void) | 132 | void RAND_cleanup(void) |
123 | { | 133 | { |
diff --git a/src/lib/libcrypto/rand/randfile.c b/src/lib/libcrypto/rand/randfile.c index 982074c465..41574768ab 100644 --- a/src/lib/libcrypto/rand/randfile.c +++ b/src/lib/libcrypto/rand/randfile.c | |||
@@ -124,7 +124,7 @@ int RAND_load_file(const char *file, long bytes) | |||
124 | } | 124 | } |
125 | } | 125 | } |
126 | fclose(in); | 126 | fclose(in); |
127 | memset(buf,0,BUFSIZE); | 127 | OPENSSL_cleanse(buf,BUFSIZE); |
128 | err: | 128 | err: |
129 | return(ret); | 129 | return(ret); |
130 | } | 130 | } |
@@ -189,7 +189,7 @@ int RAND_write_file(const char *file) | |||
189 | #endif /* OPENSSL_SYS_VMS */ | 189 | #endif /* OPENSSL_SYS_VMS */ |
190 | 190 | ||
191 | fclose(out); | 191 | fclose(out); |
192 | memset(buf,0,BUFSIZE); | 192 | OPENSSL_cleanse(buf,BUFSIZE); |
193 | err: | 193 | err: |
194 | return (rand_err ? -1 : ret); | 194 | return (rand_err ? -1 : ret); |
195 | } | 195 | } |
@@ -203,8 +203,9 @@ const char *RAND_file_name(char *buf, size_t size) | |||
203 | s=getenv("RANDFILE"); | 203 | s=getenv("RANDFILE"); |
204 | if (s != NULL) | 204 | if (s != NULL) |
205 | { | 205 | { |
206 | strncpy(buf,s,size-1); | 206 | if(strlen(s) >= size) |
207 | buf[size-1]='\0'; | 207 | return NULL; |
208 | strcpy(buf,s); | ||
208 | ret=buf; | 209 | ret=buf; |
209 | } | 210 | } |
210 | else | 211 | else |
diff --git a/src/lib/libcrypto/ripemd/rmd_dgst.c b/src/lib/libcrypto/ripemd/rmd_dgst.c index a3170f7c8a..f351f00eea 100644 --- a/src/lib/libcrypto/ripemd/rmd_dgst.c +++ b/src/lib/libcrypto/ripemd/rmd_dgst.c | |||
@@ -90,8 +90,8 @@ int RIPEMD160_Init(RIPEMD160_CTX *c) | |||
90 | void ripemd160_block_host_order (RIPEMD160_CTX *ctx, const void *p, int num) | 90 | void ripemd160_block_host_order (RIPEMD160_CTX *ctx, const void *p, int num) |
91 | { | 91 | { |
92 | const RIPEMD160_LONG *XX=p; | 92 | const RIPEMD160_LONG *XX=p; |
93 | register unsigned long A,B,C,D,E; | 93 | register unsigned MD32_REG_T A,B,C,D,E; |
94 | register unsigned long a,b,c,d,e; | 94 | register unsigned MD32_REG_T a,b,c,d,e; |
95 | 95 | ||
96 | for (;num--;XX+=HASH_LBLOCK) | 96 | for (;num--;XX+=HASH_LBLOCK) |
97 | { | 97 | { |
@@ -290,12 +290,12 @@ void ripemd160_block_host_order (RIPEMD160_CTX *ctx, const void *p, int num) | |||
290 | void ripemd160_block_data_order (RIPEMD160_CTX *ctx, const void *p, int num) | 290 | void ripemd160_block_data_order (RIPEMD160_CTX *ctx, const void *p, int num) |
291 | { | 291 | { |
292 | const unsigned char *data=p; | 292 | const unsigned char *data=p; |
293 | register unsigned long A,B,C,D,E; | 293 | register unsigned MD32_REG_T A,B,C,D,E; |
294 | unsigned long a,b,c,d,e,l; | 294 | unsigned MD32_REG_T a,b,c,d,e,l; |
295 | #ifndef MD32_XARRAY | 295 | #ifndef MD32_XARRAY |
296 | /* See comment in crypto/sha/sha_locl.h for details. */ | 296 | /* See comment in crypto/sha/sha_locl.h for details. */ |
297 | unsigned long XX0, XX1, XX2, XX3, XX4, XX5, XX6, XX7, | 297 | unsigned MD32_REG_T XX0, XX1, XX2, XX3, XX4, XX5, XX6, XX7, |
298 | XX8, XX9,XX10,XX11,XX12,XX13,XX14,XX15; | 298 | XX8, XX9,XX10,XX11,XX12,XX13,XX14,XX15; |
299 | # define X(i) XX##i | 299 | # define X(i) XX##i |
300 | #else | 300 | #else |
301 | RIPEMD160_LONG XX[16]; | 301 | RIPEMD160_LONG XX[16]; |
diff --git a/src/lib/libcrypto/ripemd/rmd_one.c b/src/lib/libcrypto/ripemd/rmd_one.c index efdf2dd6ef..f8b580c33a 100644 --- a/src/lib/libcrypto/ripemd/rmd_one.c +++ b/src/lib/libcrypto/ripemd/rmd_one.c | |||
@@ -59,6 +59,7 @@ | |||
59 | #include <stdio.h> | 59 | #include <stdio.h> |
60 | #include <string.h> | 60 | #include <string.h> |
61 | #include <openssl/ripemd.h> | 61 | #include <openssl/ripemd.h> |
62 | #include <openssl/crypto.h> | ||
62 | 63 | ||
63 | unsigned char *RIPEMD160(const unsigned char *d, unsigned long n, | 64 | unsigned char *RIPEMD160(const unsigned char *d, unsigned long n, |
64 | unsigned char *md) | 65 | unsigned char *md) |
@@ -70,7 +71,7 @@ unsigned char *RIPEMD160(const unsigned char *d, unsigned long n, | |||
70 | RIPEMD160_Init(&c); | 71 | RIPEMD160_Init(&c); |
71 | RIPEMD160_Update(&c,d,n); | 72 | RIPEMD160_Update(&c,d,n); |
72 | RIPEMD160_Final(md,&c); | 73 | RIPEMD160_Final(md,&c); |
73 | memset(&c,0,sizeof(c)); /* security consideration */ | 74 | OPENSSL_cleanse(&c,sizeof(c)); /* security consideration */ |
74 | return(md); | 75 | return(md); |
75 | } | 76 | } |
76 | 77 | ||
diff --git a/src/lib/libcrypto/rsa/rsa.h b/src/lib/libcrypto/rsa/rsa.h index 98b3bd7cc5..e26a68b482 100644 --- a/src/lib/libcrypto/rsa/rsa.h +++ b/src/lib/libcrypto/rsa/rsa.h | |||
@@ -158,6 +158,11 @@ struct rsa_st | |||
158 | #define RSA_FLAG_CACHE_PUBLIC 0x02 | 158 | #define RSA_FLAG_CACHE_PUBLIC 0x02 |
159 | #define RSA_FLAG_CACHE_PRIVATE 0x04 | 159 | #define RSA_FLAG_CACHE_PRIVATE 0x04 |
160 | #define RSA_FLAG_BLINDING 0x08 | 160 | #define RSA_FLAG_BLINDING 0x08 |
161 | #define RSA_FLAG_NO_BLINDING 0x80 /* new with 0.9.6j and 0.9.7b; the built-in | ||
162 | * RSA implementation now uses blinding by | ||
163 | * default (ignoring RSA_FLAG_BLINDING), | ||
164 | * but other engines might not need it | ||
165 | */ | ||
161 | #define RSA_FLAG_THREAD_SAFE 0x10 | 166 | #define RSA_FLAG_THREAD_SAFE 0x10 |
162 | /* This flag means the private key operations will be handled by rsa_mod_exp | 167 | /* This flag means the private key operations will be handled by rsa_mod_exp |
163 | * and that they do not depend on the private key components being present: | 168 | * and that they do not depend on the private key components being present: |
@@ -170,11 +175,15 @@ struct rsa_st | |||
170 | */ | 175 | */ |
171 | #define RSA_FLAG_SIGN_VER 0x40 | 176 | #define RSA_FLAG_SIGN_VER 0x40 |
172 | 177 | ||
178 | #define RSA_FLAG_NO_BLINDING 0x80 | ||
179 | |||
173 | #define RSA_PKCS1_PADDING 1 | 180 | #define RSA_PKCS1_PADDING 1 |
174 | #define RSA_SSLV23_PADDING 2 | 181 | #define RSA_SSLV23_PADDING 2 |
175 | #define RSA_NO_PADDING 3 | 182 | #define RSA_NO_PADDING 3 |
176 | #define RSA_PKCS1_OAEP_PADDING 4 | 183 | #define RSA_PKCS1_OAEP_PADDING 4 |
177 | 184 | ||
185 | #define RSA_PKCS1_PADDING_SIZE 11 | ||
186 | |||
178 | #define RSA_set_app_data(s,arg) RSA_set_ex_data(s,0,arg) | 187 | #define RSA_set_app_data(s,arg) RSA_set_ex_data(s,0,arg) |
179 | #define RSA_get_app_data(s) RSA_get_ex_data(s,0) | 188 | #define RSA_get_app_data(s) RSA_get_ex_data(s,0) |
180 | 189 | ||
diff --git a/src/lib/libcrypto/rsa/rsa_eay.c b/src/lib/libcrypto/rsa/rsa_eay.c index 0eda816081..027b4dc754 100644 --- a/src/lib/libcrypto/rsa/rsa_eay.c +++ b/src/lib/libcrypto/rsa/rsa_eay.c | |||
@@ -61,7 +61,6 @@ | |||
61 | #include <openssl/bn.h> | 61 | #include <openssl/bn.h> |
62 | #include <openssl/rsa.h> | 62 | #include <openssl/rsa.h> |
63 | #include <openssl/rand.h> | 63 | #include <openssl/rand.h> |
64 | #include <openssl/engine.h> | ||
65 | 64 | ||
66 | #ifndef RSA_NULL | 65 | #ifndef RSA_NULL |
67 | 66 | ||
@@ -187,12 +186,65 @@ err: | |||
187 | BN_clear_free(&ret); | 186 | BN_clear_free(&ret); |
188 | if (buf != NULL) | 187 | if (buf != NULL) |
189 | { | 188 | { |
190 | memset(buf,0,num); | 189 | OPENSSL_cleanse(buf,num); |
191 | OPENSSL_free(buf); | 190 | OPENSSL_free(buf); |
192 | } | 191 | } |
193 | return(r); | 192 | return(r); |
194 | } | 193 | } |
195 | 194 | ||
195 | static int rsa_eay_blinding(RSA *rsa, BN_CTX *ctx) | ||
196 | { | ||
197 | int ret = 1; | ||
198 | CRYPTO_w_lock(CRYPTO_LOCK_RSA); | ||
199 | /* Check again inside the lock - the macro's check is racey */ | ||
200 | if(rsa->blinding == NULL) | ||
201 | ret = RSA_blinding_on(rsa, ctx); | ||
202 | CRYPTO_w_unlock(CRYPTO_LOCK_RSA); | ||
203 | return ret; | ||
204 | } | ||
205 | |||
206 | #define BLINDING_HELPER(rsa, ctx, err_instr) \ | ||
207 | do { \ | ||
208 | if((!((rsa)->flags & RSA_FLAG_NO_BLINDING)) && \ | ||
209 | ((rsa)->blinding == NULL) && \ | ||
210 | !rsa_eay_blinding(rsa, ctx)) \ | ||
211 | err_instr \ | ||
212 | } while(0) | ||
213 | |||
214 | static BN_BLINDING *setup_blinding(RSA *rsa, BN_CTX *ctx) | ||
215 | { | ||
216 | BIGNUM *A, *Ai; | ||
217 | BN_BLINDING *ret = NULL; | ||
218 | |||
219 | /* added in OpenSSL 0.9.6j and 0.9.7b */ | ||
220 | |||
221 | /* NB: similar code appears in RSA_blinding_on (rsa_lib.c); | ||
222 | * this should be placed in a new function of its own, but for reasons | ||
223 | * of binary compatibility can't */ | ||
224 | |||
225 | BN_CTX_start(ctx); | ||
226 | A = BN_CTX_get(ctx); | ||
227 | if ((RAND_status() == 0) && rsa->d != NULL && rsa->d->d != NULL) | ||
228 | { | ||
229 | /* if PRNG is not properly seeded, resort to secret exponent as unpredictable seed */ | ||
230 | RAND_add(rsa->d->d, rsa->d->dmax * sizeof rsa->d->d[0], 0); | ||
231 | if (!BN_pseudo_rand_range(A,rsa->n)) goto err; | ||
232 | } | ||
233 | else | ||
234 | { | ||
235 | if (!BN_rand_range(A,rsa->n)) goto err; | ||
236 | } | ||
237 | if ((Ai=BN_mod_inverse(NULL,A,rsa->n,ctx)) == NULL) goto err; | ||
238 | |||
239 | if (!rsa->meth->bn_mod_exp(A,A,rsa->e,rsa->n,ctx,rsa->_method_mod_n)) | ||
240 | goto err; | ||
241 | ret = BN_BLINDING_new(A,Ai,rsa->n); | ||
242 | BN_free(Ai); | ||
243 | err: | ||
244 | BN_CTX_end(ctx); | ||
245 | return ret; | ||
246 | } | ||
247 | |||
196 | /* signing */ | 248 | /* signing */ |
197 | static int RSA_eay_private_encrypt(int flen, const unsigned char *from, | 249 | static int RSA_eay_private_encrypt(int flen, const unsigned char *from, |
198 | unsigned char *to, RSA *rsa, int padding) | 250 | unsigned char *to, RSA *rsa, int padding) |
@@ -201,6 +253,8 @@ static int RSA_eay_private_encrypt(int flen, const unsigned char *from, | |||
201 | int i,j,k,num=0,r= -1; | 253 | int i,j,k,num=0,r= -1; |
202 | unsigned char *buf=NULL; | 254 | unsigned char *buf=NULL; |
203 | BN_CTX *ctx=NULL; | 255 | BN_CTX *ctx=NULL; |
256 | int local_blinding = 0; | ||
257 | BN_BLINDING *blinding = NULL; | ||
204 | 258 | ||
205 | BN_init(&f); | 259 | BN_init(&f); |
206 | BN_init(&ret); | 260 | BN_init(&ret); |
@@ -237,10 +291,39 @@ static int RSA_eay_private_encrypt(int flen, const unsigned char *from, | |||
237 | goto err; | 291 | goto err; |
238 | } | 292 | } |
239 | 293 | ||
240 | if ((rsa->flags & RSA_FLAG_BLINDING) && (rsa->blinding == NULL)) | 294 | BLINDING_HELPER(rsa, ctx, goto err;); |
241 | RSA_blinding_on(rsa,ctx); | 295 | blinding = rsa->blinding; |
242 | if (rsa->flags & RSA_FLAG_BLINDING) | 296 | |
243 | if (!BN_BLINDING_convert(&f,rsa->blinding,ctx)) goto err; | 297 | /* Now unless blinding is disabled, 'blinding' is non-NULL. |
298 | * But the BN_BLINDING object may be owned by some other thread | ||
299 | * (we don't want to keep it constant and we don't want to use | ||
300 | * lots of locking to avoid race conditions, so only a single | ||
301 | * thread can use it; other threads have to use local blinding | ||
302 | * factors) */ | ||
303 | if (!(rsa->flags & RSA_FLAG_NO_BLINDING)) | ||
304 | { | ||
305 | if (blinding == NULL) | ||
306 | { | ||
307 | RSAerr(RSA_F_RSA_EAY_PRIVATE_ENCRYPT, ERR_R_INTERNAL_ERROR); | ||
308 | goto err; | ||
309 | } | ||
310 | } | ||
311 | |||
312 | if (blinding != NULL) | ||
313 | { | ||
314 | if (blinding->thread_id != CRYPTO_thread_id()) | ||
315 | { | ||
316 | /* we need a local one-time blinding factor */ | ||
317 | |||
318 | blinding = setup_blinding(rsa, ctx); | ||
319 | if (blinding == NULL) | ||
320 | goto err; | ||
321 | local_blinding = 1; | ||
322 | } | ||
323 | } | ||
324 | |||
325 | if (blinding) | ||
326 | if (!BN_BLINDING_convert(&f, blinding, ctx)) goto err; | ||
244 | 327 | ||
245 | if ( (rsa->flags & RSA_FLAG_EXT_PKEY) || | 328 | if ( (rsa->flags & RSA_FLAG_EXT_PKEY) || |
246 | ((rsa->p != NULL) && | 329 | ((rsa->p != NULL) && |
@@ -254,8 +337,8 @@ static int RSA_eay_private_encrypt(int flen, const unsigned char *from, | |||
254 | if (!rsa->meth->bn_mod_exp(&ret,&f,rsa->d,rsa->n,ctx,NULL)) goto err; | 337 | if (!rsa->meth->bn_mod_exp(&ret,&f,rsa->d,rsa->n,ctx,NULL)) goto err; |
255 | } | 338 | } |
256 | 339 | ||
257 | if (rsa->flags & RSA_FLAG_BLINDING) | 340 | if (blinding) |
258 | if (!BN_BLINDING_invert(&ret,rsa->blinding,ctx)) goto err; | 341 | if (!BN_BLINDING_invert(&ret, blinding, ctx)) goto err; |
259 | 342 | ||
260 | /* put in leading 0 bytes if the number is less than the | 343 | /* put in leading 0 bytes if the number is less than the |
261 | * length of the modulus */ | 344 | * length of the modulus */ |
@@ -269,9 +352,11 @@ err: | |||
269 | if (ctx != NULL) BN_CTX_free(ctx); | 352 | if (ctx != NULL) BN_CTX_free(ctx); |
270 | BN_clear_free(&ret); | 353 | BN_clear_free(&ret); |
271 | BN_clear_free(&f); | 354 | BN_clear_free(&f); |
355 | if (local_blinding) | ||
356 | BN_BLINDING_free(blinding); | ||
272 | if (buf != NULL) | 357 | if (buf != NULL) |
273 | { | 358 | { |
274 | memset(buf,0,num); | 359 | OPENSSL_cleanse(buf,num); |
275 | OPENSSL_free(buf); | 360 | OPENSSL_free(buf); |
276 | } | 361 | } |
277 | return(r); | 362 | return(r); |
@@ -285,6 +370,8 @@ static int RSA_eay_private_decrypt(int flen, const unsigned char *from, | |||
285 | unsigned char *p; | 370 | unsigned char *p; |
286 | unsigned char *buf=NULL; | 371 | unsigned char *buf=NULL; |
287 | BN_CTX *ctx=NULL; | 372 | BN_CTX *ctx=NULL; |
373 | int local_blinding = 0; | ||
374 | BN_BLINDING *blinding = NULL; | ||
288 | 375 | ||
289 | BN_init(&f); | 376 | BN_init(&f); |
290 | BN_init(&ret); | 377 | BN_init(&ret); |
@@ -316,10 +403,39 @@ static int RSA_eay_private_decrypt(int flen, const unsigned char *from, | |||
316 | goto err; | 403 | goto err; |
317 | } | 404 | } |
318 | 405 | ||
319 | if ((rsa->flags & RSA_FLAG_BLINDING) && (rsa->blinding == NULL)) | 406 | BLINDING_HELPER(rsa, ctx, goto err;); |
320 | RSA_blinding_on(rsa,ctx); | 407 | blinding = rsa->blinding; |
321 | if (rsa->flags & RSA_FLAG_BLINDING) | 408 | |
322 | if (!BN_BLINDING_convert(&f,rsa->blinding,ctx)) goto err; | 409 | /* Now unless blinding is disabled, 'blinding' is non-NULL. |
410 | * But the BN_BLINDING object may be owned by some other thread | ||
411 | * (we don't want to keep it constant and we don't want to use | ||
412 | * lots of locking to avoid race conditions, so only a single | ||
413 | * thread can use it; other threads have to use local blinding | ||
414 | * factors) */ | ||
415 | if (!(rsa->flags & RSA_FLAG_NO_BLINDING)) | ||
416 | { | ||
417 | if (blinding == NULL) | ||
418 | { | ||
419 | RSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT, ERR_R_INTERNAL_ERROR); | ||
420 | goto err; | ||
421 | } | ||
422 | } | ||
423 | |||
424 | if (blinding != NULL) | ||
425 | { | ||
426 | if (blinding->thread_id != CRYPTO_thread_id()) | ||
427 | { | ||
428 | /* we need a local one-time blinding factor */ | ||
429 | |||
430 | blinding = setup_blinding(rsa, ctx); | ||
431 | if (blinding == NULL) | ||
432 | goto err; | ||
433 | local_blinding = 1; | ||
434 | } | ||
435 | } | ||
436 | |||
437 | if (blinding) | ||
438 | if (!BN_BLINDING_convert(&f, blinding, ctx)) goto err; | ||
323 | 439 | ||
324 | /* do the decrypt */ | 440 | /* do the decrypt */ |
325 | if ( (rsa->flags & RSA_FLAG_EXT_PKEY) || | 441 | if ( (rsa->flags & RSA_FLAG_EXT_PKEY) || |
@@ -335,8 +451,8 @@ static int RSA_eay_private_decrypt(int flen, const unsigned char *from, | |||
335 | goto err; | 451 | goto err; |
336 | } | 452 | } |
337 | 453 | ||
338 | if (rsa->flags & RSA_FLAG_BLINDING) | 454 | if (blinding) |
339 | if (!BN_BLINDING_invert(&ret,rsa->blinding,ctx)) goto err; | 455 | if (!BN_BLINDING_invert(&ret, blinding, ctx)) goto err; |
340 | 456 | ||
341 | p=buf; | 457 | p=buf; |
342 | j=BN_bn2bin(&ret,p); /* j is only used with no-padding mode */ | 458 | j=BN_bn2bin(&ret,p); /* j is only used with no-padding mode */ |
@@ -370,7 +486,7 @@ err: | |||
370 | BN_clear_free(&ret); | 486 | BN_clear_free(&ret); |
371 | if (buf != NULL) | 487 | if (buf != NULL) |
372 | { | 488 | { |
373 | memset(buf,0,num); | 489 | OPENSSL_cleanse(buf,num); |
374 | OPENSSL_free(buf); | 490 | OPENSSL_free(buf); |
375 | } | 491 | } |
376 | return(r); | 492 | return(r); |
@@ -467,7 +583,7 @@ err: | |||
467 | BN_clear_free(&ret); | 583 | BN_clear_free(&ret); |
468 | if (buf != NULL) | 584 | if (buf != NULL) |
469 | { | 585 | { |
470 | memset(buf,0,num); | 586 | OPENSSL_cleanse(buf,num); |
471 | OPENSSL_free(buf); | 587 | OPENSSL_free(buf); |
472 | } | 588 | } |
473 | return(r); | 589 | return(r); |
diff --git a/src/lib/libcrypto/rsa/rsa_lib.c b/src/lib/libcrypto/rsa/rsa_lib.c index 93235744f7..53c5092014 100644 --- a/src/lib/libcrypto/rsa/rsa_lib.c +++ b/src/lib/libcrypto/rsa/rsa_lib.c | |||
@@ -62,7 +62,10 @@ | |||
62 | #include <openssl/lhash.h> | 62 | #include <openssl/lhash.h> |
63 | #include <openssl/bn.h> | 63 | #include <openssl/bn.h> |
64 | #include <openssl/rsa.h> | 64 | #include <openssl/rsa.h> |
65 | #include <openssl/rand.h> | ||
66 | #ifndef OPENSSL_NO_ENGINE | ||
65 | #include <openssl/engine.h> | 67 | #include <openssl/engine.h> |
68 | #endif | ||
66 | 69 | ||
67 | const char *RSA_version="RSA" OPENSSL_VERSION_PTEXT; | 70 | const char *RSA_version="RSA" OPENSSL_VERSION_PTEXT; |
68 | 71 | ||
@@ -70,7 +73,9 @@ static const RSA_METHOD *default_RSA_meth=NULL; | |||
70 | 73 | ||
71 | RSA *RSA_new(void) | 74 | RSA *RSA_new(void) |
72 | { | 75 | { |
73 | return(RSA_new_method(NULL)); | 76 | RSA *r=RSA_new_method(NULL); |
77 | |||
78 | return r; | ||
74 | } | 79 | } |
75 | 80 | ||
76 | void RSA_set_default_method(const RSA_METHOD *meth) | 81 | void RSA_set_default_method(const RSA_METHOD *meth) |
@@ -108,11 +113,13 @@ int RSA_set_method(RSA *rsa, const RSA_METHOD *meth) | |||
108 | const RSA_METHOD *mtmp; | 113 | const RSA_METHOD *mtmp; |
109 | mtmp = rsa->meth; | 114 | mtmp = rsa->meth; |
110 | if (mtmp->finish) mtmp->finish(rsa); | 115 | if (mtmp->finish) mtmp->finish(rsa); |
116 | #ifndef OPENSSL_NO_ENGINE | ||
111 | if (rsa->engine) | 117 | if (rsa->engine) |
112 | { | 118 | { |
113 | ENGINE_finish(rsa->engine); | 119 | ENGINE_finish(rsa->engine); |
114 | rsa->engine = NULL; | 120 | rsa->engine = NULL; |
115 | } | 121 | } |
122 | #endif | ||
116 | rsa->meth = meth; | 123 | rsa->meth = meth; |
117 | if (meth->init) meth->init(rsa); | 124 | if (meth->init) meth->init(rsa); |
118 | return 1; | 125 | return 1; |
@@ -130,6 +137,7 @@ RSA *RSA_new_method(ENGINE *engine) | |||
130 | } | 137 | } |
131 | 138 | ||
132 | ret->meth = RSA_get_default_method(); | 139 | ret->meth = RSA_get_default_method(); |
140 | #ifndef OPENSSL_NO_ENGINE | ||
133 | if (engine) | 141 | if (engine) |
134 | { | 142 | { |
135 | if (!ENGINE_init(engine)) | 143 | if (!ENGINE_init(engine)) |
@@ -154,6 +162,7 @@ RSA *RSA_new_method(ENGINE *engine) | |||
154 | return NULL; | 162 | return NULL; |
155 | } | 163 | } |
156 | } | 164 | } |
165 | #endif | ||
157 | 166 | ||
158 | ret->pad=0; | 167 | ret->pad=0; |
159 | ret->version=0; | 168 | ret->version=0; |
@@ -175,8 +184,10 @@ RSA *RSA_new_method(ENGINE *engine) | |||
175 | CRYPTO_new_ex_data(CRYPTO_EX_INDEX_RSA, ret, &ret->ex_data); | 184 | CRYPTO_new_ex_data(CRYPTO_EX_INDEX_RSA, ret, &ret->ex_data); |
176 | if ((ret->meth->init != NULL) && !ret->meth->init(ret)) | 185 | if ((ret->meth->init != NULL) && !ret->meth->init(ret)) |
177 | { | 186 | { |
187 | #ifndef OPENSSL_NO_ENGINE | ||
178 | if (ret->engine) | 188 | if (ret->engine) |
179 | ENGINE_finish(ret->engine); | 189 | ENGINE_finish(ret->engine); |
190 | #endif | ||
180 | CRYPTO_free_ex_data(CRYPTO_EX_INDEX_RSA, ret, &ret->ex_data); | 191 | CRYPTO_free_ex_data(CRYPTO_EX_INDEX_RSA, ret, &ret->ex_data); |
181 | OPENSSL_free(ret); | 192 | OPENSSL_free(ret); |
182 | ret=NULL; | 193 | ret=NULL; |
@@ -205,8 +216,10 @@ void RSA_free(RSA *r) | |||
205 | 216 | ||
206 | if (r->meth->finish) | 217 | if (r->meth->finish) |
207 | r->meth->finish(r); | 218 | r->meth->finish(r); |
219 | #ifndef OPENSSL_NO_ENGINE | ||
208 | if (r->engine) | 220 | if (r->engine) |
209 | ENGINE_finish(r->engine); | 221 | ENGINE_finish(r->engine); |
222 | #endif | ||
210 | 223 | ||
211 | CRYPTO_free_ex_data(CRYPTO_EX_INDEX_RSA, r, &r->ex_data); | 224 | CRYPTO_free_ex_data(CRYPTO_EX_INDEX_RSA, r, &r->ex_data); |
212 | 225 | ||
@@ -297,7 +310,8 @@ void RSA_blinding_off(RSA *rsa) | |||
297 | BN_BLINDING_free(rsa->blinding); | 310 | BN_BLINDING_free(rsa->blinding); |
298 | rsa->blinding=NULL; | 311 | rsa->blinding=NULL; |
299 | } | 312 | } |
300 | rsa->flags&= ~RSA_FLAG_BLINDING; | 313 | rsa->flags &= ~RSA_FLAG_BLINDING; |
314 | rsa->flags |= RSA_FLAG_NO_BLINDING; | ||
301 | } | 315 | } |
302 | 316 | ||
303 | int RSA_blinding_on(RSA *rsa, BN_CTX *p_ctx) | 317 | int RSA_blinding_on(RSA *rsa, BN_CTX *p_ctx) |
@@ -316,15 +330,32 @@ int RSA_blinding_on(RSA *rsa, BN_CTX *p_ctx) | |||
316 | if (rsa->blinding != NULL) | 330 | if (rsa->blinding != NULL) |
317 | BN_BLINDING_free(rsa->blinding); | 331 | BN_BLINDING_free(rsa->blinding); |
318 | 332 | ||
333 | /* NB: similar code appears in setup_blinding (rsa_eay.c); | ||
334 | * this should be placed in a new function of its own, but for reasons | ||
335 | * of binary compatibility can't */ | ||
336 | |||
319 | BN_CTX_start(ctx); | 337 | BN_CTX_start(ctx); |
320 | A = BN_CTX_get(ctx); | 338 | A = BN_CTX_get(ctx); |
321 | if (!BN_rand_range(A,rsa->n)) goto err; | 339 | if ((RAND_status() == 0) && rsa->d != NULL && rsa->d->d != NULL) |
340 | { | ||
341 | /* if PRNG is not properly seeded, resort to secret exponent as unpredictable seed */ | ||
342 | RAND_add(rsa->d->d, rsa->d->dmax * sizeof rsa->d->d[0], 0); | ||
343 | if (!BN_pseudo_rand_range(A,rsa->n)) goto err; | ||
344 | } | ||
345 | else | ||
346 | { | ||
347 | if (!BN_rand_range(A,rsa->n)) goto err; | ||
348 | } | ||
322 | if ((Ai=BN_mod_inverse(NULL,A,rsa->n,ctx)) == NULL) goto err; | 349 | if ((Ai=BN_mod_inverse(NULL,A,rsa->n,ctx)) == NULL) goto err; |
323 | 350 | ||
324 | if (!rsa->meth->bn_mod_exp(A,A,rsa->e,rsa->n,ctx,rsa->_method_mod_n)) | 351 | if (!rsa->meth->bn_mod_exp(A,A,rsa->e,rsa->n,ctx,rsa->_method_mod_n)) |
325 | goto err; | 352 | goto err; |
326 | rsa->blinding=BN_BLINDING_new(A,Ai,rsa->n); | 353 | if ((rsa->blinding=BN_BLINDING_new(A,Ai,rsa->n)) == NULL) goto err; |
327 | rsa->flags|=RSA_FLAG_BLINDING; | 354 | /* to make things thread-safe without excessive locking, |
355 | * rsa->blinding will be used just by the current thread: */ | ||
356 | rsa->blinding->thread_id = CRYPTO_thread_id(); | ||
357 | rsa->flags |= RSA_FLAG_BLINDING; | ||
358 | rsa->flags &= ~RSA_FLAG_NO_BLINDING; | ||
328 | BN_free(Ai); | 359 | BN_free(Ai); |
329 | ret=1; | 360 | ret=1; |
330 | err: | 361 | err: |
diff --git a/src/lib/libcrypto/rsa/rsa_pk1.c b/src/lib/libcrypto/rsa/rsa_pk1.c index c1edd6764f..8560755f1d 100644 --- a/src/lib/libcrypto/rsa/rsa_pk1.c +++ b/src/lib/libcrypto/rsa/rsa_pk1.c | |||
@@ -68,7 +68,7 @@ int RSA_padding_add_PKCS1_type_1(unsigned char *to, int tlen, | |||
68 | int j; | 68 | int j; |
69 | unsigned char *p; | 69 | unsigned char *p; |
70 | 70 | ||
71 | if (flen > (tlen-11)) | 71 | if (flen > (tlen-RSA_PKCS1_PADDING_SIZE)) |
72 | { | 72 | { |
73 | RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_1,RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE); | 73 | RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_TYPE_1,RSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE); |
74 | return(0); | 74 | return(0); |
diff --git a/src/lib/libcrypto/rsa/rsa_saos.c b/src/lib/libcrypto/rsa/rsa_saos.c index 85adacc08f..f462716a57 100644 --- a/src/lib/libcrypto/rsa/rsa_saos.c +++ b/src/lib/libcrypto/rsa/rsa_saos.c | |||
@@ -77,7 +77,7 @@ int RSA_sign_ASN1_OCTET_STRING(int type, | |||
77 | 77 | ||
78 | i=i2d_ASN1_OCTET_STRING(&sig,NULL); | 78 | i=i2d_ASN1_OCTET_STRING(&sig,NULL); |
79 | j=RSA_size(rsa); | 79 | j=RSA_size(rsa); |
80 | if ((i-RSA_PKCS1_PADDING) > j) | 80 | if (i > (j-RSA_PKCS1_PADDING_SIZE)) |
81 | { | 81 | { |
82 | RSAerr(RSA_F_RSA_SIGN_ASN1_OCTET_STRING,RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY); | 82 | RSAerr(RSA_F_RSA_SIGN_ASN1_OCTET_STRING,RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY); |
83 | return(0); | 83 | return(0); |
@@ -96,7 +96,7 @@ int RSA_sign_ASN1_OCTET_STRING(int type, | |||
96 | else | 96 | else |
97 | *siglen=i; | 97 | *siglen=i; |
98 | 98 | ||
99 | memset(s,0,(unsigned int)j+1); | 99 | OPENSSL_cleanse(s,(unsigned int)j+1); |
100 | OPENSSL_free(s); | 100 | OPENSSL_free(s); |
101 | return(ret); | 101 | return(ret); |
102 | } | 102 | } |
@@ -139,7 +139,7 @@ int RSA_verify_ASN1_OCTET_STRING(int dtype, | |||
139 | ret=1; | 139 | ret=1; |
140 | err: | 140 | err: |
141 | if (sig != NULL) M_ASN1_OCTET_STRING_free(sig); | 141 | if (sig != NULL) M_ASN1_OCTET_STRING_free(sig); |
142 | memset(s,0,(unsigned int)siglen); | 142 | OPENSSL_cleanse(s,(unsigned int)siglen); |
143 | OPENSSL_free(s); | 143 | OPENSSL_free(s); |
144 | return(ret); | 144 | return(ret); |
145 | } | 145 | } |
diff --git a/src/lib/libcrypto/rsa/rsa_sign.c b/src/lib/libcrypto/rsa/rsa_sign.c index 2a440901de..8a1e642183 100644 --- a/src/lib/libcrypto/rsa/rsa_sign.c +++ b/src/lib/libcrypto/rsa/rsa_sign.c | |||
@@ -62,7 +62,6 @@ | |||
62 | #include <openssl/rsa.h> | 62 | #include <openssl/rsa.h> |
63 | #include <openssl/objects.h> | 63 | #include <openssl/objects.h> |
64 | #include <openssl/x509.h> | 64 | #include <openssl/x509.h> |
65 | #include <openssl/engine.h> | ||
66 | 65 | ||
67 | /* Size of an SSL signature: MD5+SHA1 */ | 66 | /* Size of an SSL signature: MD5+SHA1 */ |
68 | #define SSL_SIG_LENGTH 36 | 67 | #define SSL_SIG_LENGTH 36 |
@@ -77,10 +76,11 @@ int RSA_sign(int type, const unsigned char *m, unsigned int m_len, | |||
77 | const unsigned char *s = NULL; | 76 | const unsigned char *s = NULL; |
78 | X509_ALGOR algor; | 77 | X509_ALGOR algor; |
79 | ASN1_OCTET_STRING digest; | 78 | ASN1_OCTET_STRING digest; |
80 | if((rsa->flags & RSA_FLAG_SIGN_VER) | 79 | if((rsa->flags & RSA_FLAG_SIGN_VER) && rsa->meth->rsa_sign) |
81 | && ENGINE_get_RSA(rsa->engine)->rsa_sign) | 80 | { |
82 | return ENGINE_get_RSA(rsa->engine)->rsa_sign(type, | 81 | return rsa->meth->rsa_sign(type, m, m_len, |
83 | m, m_len, sigret, siglen, rsa); | 82 | sigret, siglen, rsa); |
83 | } | ||
84 | /* Special case: SSL signature, just check the length */ | 84 | /* Special case: SSL signature, just check the length */ |
85 | if(type == NID_md5_sha1) { | 85 | if(type == NID_md5_sha1) { |
86 | if(m_len != SSL_SIG_LENGTH) { | 86 | if(m_len != SSL_SIG_LENGTH) { |
@@ -113,7 +113,7 @@ int RSA_sign(int type, const unsigned char *m, unsigned int m_len, | |||
113 | i=i2d_X509_SIG(&sig,NULL); | 113 | i=i2d_X509_SIG(&sig,NULL); |
114 | } | 114 | } |
115 | j=RSA_size(rsa); | 115 | j=RSA_size(rsa); |
116 | if ((i-RSA_PKCS1_PADDING) > j) | 116 | if (i > (j-RSA_PKCS1_PADDING_SIZE)) |
117 | { | 117 | { |
118 | RSAerr(RSA_F_RSA_SIGN,RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY); | 118 | RSAerr(RSA_F_RSA_SIGN,RSA_R_DIGEST_TOO_BIG_FOR_RSA_KEY); |
119 | return(0); | 119 | return(0); |
@@ -136,7 +136,7 @@ int RSA_sign(int type, const unsigned char *m, unsigned int m_len, | |||
136 | *siglen=i; | 136 | *siglen=i; |
137 | 137 | ||
138 | if(type != NID_md5_sha1) { | 138 | if(type != NID_md5_sha1) { |
139 | memset(tmps,0,(unsigned int)j+1); | 139 | OPENSSL_cleanse(tmps,(unsigned int)j+1); |
140 | OPENSSL_free(tmps); | 140 | OPENSSL_free(tmps); |
141 | } | 141 | } |
142 | return(ret); | 142 | return(ret); |
@@ -155,10 +155,11 @@ int RSA_verify(int dtype, const unsigned char *m, unsigned int m_len, | |||
155 | return(0); | 155 | return(0); |
156 | } | 156 | } |
157 | 157 | ||
158 | if((rsa->flags & RSA_FLAG_SIGN_VER) | 158 | if((rsa->flags & RSA_FLAG_SIGN_VER) && rsa->meth->rsa_verify) |
159 | && ENGINE_get_RSA(rsa->engine)->rsa_verify) | 159 | { |
160 | return ENGINE_get_RSA(rsa->engine)->rsa_verify(dtype, | 160 | return rsa->meth->rsa_verify(dtype, m, m_len, |
161 | m, m_len, sigbuf, siglen, rsa); | 161 | sigbuf, siglen, rsa); |
162 | } | ||
162 | 163 | ||
163 | s=(unsigned char *)OPENSSL_malloc((unsigned int)siglen); | 164 | s=(unsigned char *)OPENSSL_malloc((unsigned int)siglen); |
164 | if (s == NULL) | 165 | if (s == NULL) |
@@ -221,7 +222,7 @@ int RSA_verify(int dtype, const unsigned char *m, unsigned int m_len, | |||
221 | } | 222 | } |
222 | err: | 223 | err: |
223 | if (sig != NULL) X509_SIG_free(sig); | 224 | if (sig != NULL) X509_SIG_free(sig); |
224 | memset(s,0,(unsigned int)siglen); | 225 | OPENSSL_cleanse(s,(unsigned int)siglen); |
225 | OPENSSL_free(s); | 226 | OPENSSL_free(s); |
226 | return(ret); | 227 | return(ret); |
227 | } | 228 | } |
diff --git a/src/lib/libcrypto/sha/sha1_one.c b/src/lib/libcrypto/sha/sha1_one.c index e6a24888ed..20e660c71d 100644 --- a/src/lib/libcrypto/sha/sha1_one.c +++ b/src/lib/libcrypto/sha/sha1_one.c | |||
@@ -59,6 +59,7 @@ | |||
59 | #include <stdio.h> | 59 | #include <stdio.h> |
60 | #include <string.h> | 60 | #include <string.h> |
61 | #include <openssl/sha.h> | 61 | #include <openssl/sha.h> |
62 | #include <openssl/crypto.h> | ||
62 | 63 | ||
63 | #ifndef OPENSSL_NO_SHA1 | 64 | #ifndef OPENSSL_NO_SHA1 |
64 | unsigned char *SHA1(const unsigned char *d, unsigned long n, unsigned char *md) | 65 | unsigned char *SHA1(const unsigned char *d, unsigned long n, unsigned char *md) |
@@ -70,7 +71,7 @@ unsigned char *SHA1(const unsigned char *d, unsigned long n, unsigned char *md) | |||
70 | SHA1_Init(&c); | 71 | SHA1_Init(&c); |
71 | SHA1_Update(&c,d,n); | 72 | SHA1_Update(&c,d,n); |
72 | SHA1_Final(md,&c); | 73 | SHA1_Final(md,&c); |
73 | memset(&c,0,sizeof(c)); | 74 | OPENSSL_cleanse(&c,sizeof(c)); |
74 | return(md); | 75 | return(md); |
75 | } | 76 | } |
76 | #endif | 77 | #endif |
diff --git a/src/lib/libcrypto/sha/sha_locl.h b/src/lib/libcrypto/sha/sha_locl.h index 471dfb9f8f..2dd63a62a6 100644 --- a/src/lib/libcrypto/sha/sha_locl.h +++ b/src/lib/libcrypto/sha/sha_locl.h | |||
@@ -224,10 +224,10 @@ int HASH_INIT (SHA_CTX *c) | |||
224 | void HASH_BLOCK_HOST_ORDER (SHA_CTX *c, const void *d, int num) | 224 | void HASH_BLOCK_HOST_ORDER (SHA_CTX *c, const void *d, int num) |
225 | { | 225 | { |
226 | const SHA_LONG *W=d; | 226 | const SHA_LONG *W=d; |
227 | register unsigned long A,B,C,D,E,T; | 227 | register unsigned MD32_REG_T A,B,C,D,E,T; |
228 | #ifndef MD32_XARRAY | 228 | #ifndef MD32_XARRAY |
229 | unsigned long XX0, XX1, XX2, XX3, XX4, XX5, XX6, XX7, | 229 | unsigned MD32_REG_T XX0, XX1, XX2, XX3, XX4, XX5, XX6, XX7, |
230 | XX8, XX9,XX10,XX11,XX12,XX13,XX14,XX15; | 230 | XX8, XX9,XX10,XX11,XX12,XX13,XX14,XX15; |
231 | #else | 231 | #else |
232 | SHA_LONG XX[16]; | 232 | SHA_LONG XX[16]; |
233 | #endif | 233 | #endif |
@@ -349,10 +349,10 @@ void HASH_BLOCK_HOST_ORDER (SHA_CTX *c, const void *d, int num) | |||
349 | void HASH_BLOCK_DATA_ORDER (SHA_CTX *c, const void *p, int num) | 349 | void HASH_BLOCK_DATA_ORDER (SHA_CTX *c, const void *p, int num) |
350 | { | 350 | { |
351 | const unsigned char *data=p; | 351 | const unsigned char *data=p; |
352 | register unsigned long A,B,C,D,E,T,l; | 352 | register unsigned MD32_REG_T A,B,C,D,E,T,l; |
353 | #ifndef MD32_XARRAY | 353 | #ifndef MD32_XARRAY |
354 | unsigned long XX0, XX1, XX2, XX3, XX4, XX5, XX6, XX7, | 354 | unsigned MD32_REG_T XX0, XX1, XX2, XX3, XX4, XX5, XX6, XX7, |
355 | XX8, XX9,XX10,XX11,XX12,XX13,XX14,XX15; | 355 | XX8, XX9,XX10,XX11,XX12,XX13,XX14,XX15; |
356 | #else | 356 | #else |
357 | SHA_LONG XX[16]; | 357 | SHA_LONG XX[16]; |
358 | #endif | 358 | #endif |
diff --git a/src/lib/libcrypto/txt_db/txt_db.c b/src/lib/libcrypto/txt_db/txt_db.c index 9b186f2da5..58b300b00b 100644 --- a/src/lib/libcrypto/txt_db/txt_db.c +++ b/src/lib/libcrypto/txt_db/txt_db.c | |||
@@ -108,7 +108,7 @@ TXT_DB *TXT_DB_read(BIO *in, int num) | |||
108 | if (offset != 0) | 108 | if (offset != 0) |
109 | { | 109 | { |
110 | size+=BUFSIZE; | 110 | size+=BUFSIZE; |
111 | if (!BUF_MEM_grow(buf,size)) goto err; | 111 | if (!BUF_MEM_grow_clean(buf,size)) goto err; |
112 | } | 112 | } |
113 | buf->data[offset]='\0'; | 113 | buf->data[offset]='\0'; |
114 | BIO_gets(in,&(buf->data[offset]),size-offset); | 114 | BIO_gets(in,&(buf->data[offset]),size-offset); |
@@ -268,7 +268,7 @@ long TXT_DB_write(BIO *out, TXT_DB *db) | |||
268 | if (pp[j] != NULL) | 268 | if (pp[j] != NULL) |
269 | l+=strlen(pp[j]); | 269 | l+=strlen(pp[j]); |
270 | } | 270 | } |
271 | if (!BUF_MEM_grow(buf,(int)(l*2+nn))) goto err; | 271 | if (!BUF_MEM_grow_clean(buf,(int)(l*2+nn))) goto err; |
272 | 272 | ||
273 | p=buf->data; | 273 | p=buf->data; |
274 | for (j=0; j<nn; j++) | 274 | for (j=0; j<nn; j++) |
diff --git a/src/lib/libcrypto/ui/ui_lib.c b/src/lib/libcrypto/ui/ui_lib.c index 16946cad95..13e5f20dcb 100644 --- a/src/lib/libcrypto/ui/ui_lib.c +++ b/src/lib/libcrypto/ui/ui_lib.c | |||
@@ -62,6 +62,7 @@ | |||
62 | #include <openssl/ui.h> | 62 | #include <openssl/ui.h> |
63 | #include <openssl/err.h> | 63 | #include <openssl/err.h> |
64 | #include "ui_locl.h" | 64 | #include "ui_locl.h" |
65 | #include "cryptlib.h" | ||
65 | 66 | ||
66 | IMPLEMENT_STACK_OF(UI_STRING_ST) | 67 | IMPLEMENT_STACK_OF(UI_STRING_ST) |
67 | 68 | ||
@@ -144,7 +145,8 @@ static UI_STRING *general_allocate_prompt(UI *ui, const char *prompt, | |||
144 | { | 145 | { |
145 | UIerr(UI_F_GENERAL_ALLOCATE_PROMPT,ERR_R_PASSED_NULL_PARAMETER); | 146 | UIerr(UI_F_GENERAL_ALLOCATE_PROMPT,ERR_R_PASSED_NULL_PARAMETER); |
146 | } | 147 | } |
147 | else if (result_buf == NULL) | 148 | else if ((type == UIT_PROMPT || type == UIT_VERIFY |
149 | || type == UIT_BOOLEAN) && result_buf == NULL) | ||
148 | { | 150 | { |
149 | UIerr(UI_F_GENERAL_ALLOCATE_PROMPT,UI_R_NO_RESULT_BUFFER); | 151 | UIerr(UI_F_GENERAL_ALLOCATE_PROMPT,UI_R_NO_RESULT_BUFFER); |
150 | } | 152 | } |
@@ -235,7 +237,7 @@ static int general_allocate_boolean(UI *ui, | |||
235 | return ret; | 237 | return ret; |
236 | } | 238 | } |
237 | 239 | ||
238 | /* Returns the index to the place in the stack or 0 for error. Uses a | 240 | /* Returns the index to the place in the stack or -1 for error. Uses a |
239 | direct reference to the prompt. */ | 241 | direct reference to the prompt. */ |
240 | int UI_add_input_string(UI *ui, const char *prompt, int flags, | 242 | int UI_add_input_string(UI *ui, const char *prompt, int flags, |
241 | char *result_buf, int minsize, int maxsize) | 243 | char *result_buf, int minsize, int maxsize) |
@@ -831,8 +833,8 @@ int UI_set_result(UI *ui, UI_STRING *uis, const char *result) | |||
831 | case UIT_PROMPT: | 833 | case UIT_PROMPT: |
832 | case UIT_VERIFY: | 834 | case UIT_VERIFY: |
833 | { | 835 | { |
834 | char number1[20]; | 836 | char number1[DECIMAL_SIZE(uis->_.string_data.result_minsize)+1]; |
835 | char number2[20]; | 837 | char number2[DECIMAL_SIZE(uis->_.string_data.result_maxsize)+1]; |
836 | 838 | ||
837 | BIO_snprintf(number1, sizeof(number1), "%d", | 839 | BIO_snprintf(number1, sizeof(number1), "%d", |
838 | uis->_.string_data.result_minsize); | 840 | uis->_.string_data.result_minsize); |
diff --git a/src/lib/libcrypto/ui/ui_openssl.c b/src/lib/libcrypto/ui/ui_openssl.c index 2c2fbc0443..75318d48a1 100644 --- a/src/lib/libcrypto/ui/ui_openssl.c +++ b/src/lib/libcrypto/ui/ui_openssl.c | |||
@@ -159,8 +159,10 @@ | |||
159 | 159 | ||
160 | #ifdef WIN_CONSOLE_BUG | 160 | #ifdef WIN_CONSOLE_BUG |
161 | # include <windows.h> | 161 | # include <windows.h> |
162 | #ifndef OPENSSL_SYS_WINCE | ||
162 | # include <wincon.h> | 163 | # include <wincon.h> |
163 | #endif | 164 | #endif |
165 | #endif | ||
164 | 166 | ||
165 | 167 | ||
166 | /* There are 5 types of terminal interface supported, | 168 | /* There are 5 types of terminal interface supported, |
@@ -191,7 +193,7 @@ | |||
191 | # define SGTTY | 193 | # define SGTTY |
192 | #endif | 194 | #endif |
193 | 195 | ||
194 | #if defined(OPENSSL_SYS_VSWORKS) | 196 | #if defined(OPENSSL_SYS_VXWORKS) |
195 | #undef TERMIOS | 197 | #undef TERMIOS |
196 | #undef TERMIO | 198 | #undef TERMIO |
197 | #undef SGTTY | 199 | #undef SGTTY |
@@ -221,7 +223,7 @@ | |||
221 | # define TTY_set(tty,data) ioctl(tty,TIOCSETP,data) | 223 | # define TTY_set(tty,data) ioctl(tty,TIOCSETP,data) |
222 | #endif | 224 | #endif |
223 | 225 | ||
224 | #if !defined(_LIBC) && !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_VMS) && !defined(OPENSSL_SYS_MACINTOSH_CLASSIC) | 226 | #if !defined(_LIBC) && !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_VMS) && !defined(OPENSSL_SYS_MACINTOSH_CLASSIC) && !defined(OPENSSL_SYS_SUNOS) |
225 | # include <sys/ioctl.h> | 227 | # include <sys/ioctl.h> |
226 | #endif | 228 | #endif |
227 | 229 | ||
@@ -241,6 +243,10 @@ struct IOSB { | |||
241 | }; | 243 | }; |
242 | #endif | 244 | #endif |
243 | 245 | ||
246 | #ifdef OPENSSL_SYS_SUNOS | ||
247 | typedef int sig_atomic_t; | ||
248 | #endif | ||
249 | |||
244 | #if defined(OPENSSL_SYS_MACINTOSH_CLASSIC) || defined(MAC_OS_GUSI_SOURCE) | 250 | #if defined(OPENSSL_SYS_MACINTOSH_CLASSIC) || defined(MAC_OS_GUSI_SOURCE) |
245 | /* | 251 | /* |
246 | * This one needs work. As a matter of fact the code is unoperational | 252 | * This one needs work. As a matter of fact the code is unoperational |
@@ -277,10 +283,12 @@ static FILE *tty_in, *tty_out; | |||
277 | static int is_a_tty; | 283 | static int is_a_tty; |
278 | 284 | ||
279 | /* Declare static functions */ | 285 | /* Declare static functions */ |
286 | #if !defined(OPENSSL_SYS_WIN16) && !defined(OPENSSL_SYS_WINCE) | ||
280 | static void read_till_nl(FILE *); | 287 | static void read_till_nl(FILE *); |
281 | static void recsig(int); | 288 | static void recsig(int); |
282 | static void pushsig(void); | 289 | static void pushsig(void); |
283 | static void popsig(void); | 290 | static void popsig(void); |
291 | #endif | ||
284 | #if defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_WIN16) | 292 | #if defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_WIN16) |
285 | static int noecho_fgets(char *buf, int size, FILE *tty); | 293 | static int noecho_fgets(char *buf, int size, FILE *tty); |
286 | #endif | 294 | #endif |
@@ -367,6 +375,7 @@ static int read_string(UI *ui, UI_STRING *uis) | |||
367 | } | 375 | } |
368 | 376 | ||
369 | 377 | ||
378 | #if !defined(OPENSSL_SYS_WIN16) && !defined(OPENSSL_SYS_WINCE) | ||
370 | /* Internal functions to read a string without echoing */ | 379 | /* Internal functions to read a string without echoing */ |
371 | static void read_till_nl(FILE *in) | 380 | static void read_till_nl(FILE *in) |
372 | { | 381 | { |
@@ -378,7 +387,8 @@ static void read_till_nl(FILE *in) | |||
378 | } while (strchr(buf,'\n') == NULL); | 387 | } while (strchr(buf,'\n') == NULL); |
379 | } | 388 | } |
380 | 389 | ||
381 | static sig_atomic_t intr_signal; | 390 | static volatile sig_atomic_t intr_signal; |
391 | #endif | ||
382 | 392 | ||
383 | static int read_string_inner(UI *ui, UI_STRING *uis, int echo, int strip_nl) | 393 | static int read_string_inner(UI *ui, UI_STRING *uis, int echo, int strip_nl) |
384 | { | 394 | { |
@@ -386,9 +396,9 @@ static int read_string_inner(UI *ui, UI_STRING *uis, int echo, int strip_nl) | |||
386 | int ok; | 396 | int ok; |
387 | char result[BUFSIZ]; | 397 | char result[BUFSIZ]; |
388 | int maxsize = BUFSIZ-1; | 398 | int maxsize = BUFSIZ-1; |
399 | #if !defined(OPENSSL_SYS_WIN16) && !defined(OPENSSL_SYS_WINCE) | ||
389 | char *p; | 400 | char *p; |
390 | 401 | ||
391 | #ifndef OPENSSL_SYS_WIN16 | ||
392 | intr_signal=0; | 402 | intr_signal=0; |
393 | ok=0; | 403 | ok=0; |
394 | ps=0; | 404 | ps=0; |
@@ -439,7 +449,7 @@ error: | |||
439 | ok=1; | 449 | ok=1; |
440 | #endif | 450 | #endif |
441 | 451 | ||
442 | memset(result,0,BUFSIZ); | 452 | OPENSSL_cleanse(result,BUFSIZ); |
443 | return ok; | 453 | return ok; |
444 | } | 454 | } |
445 | 455 | ||
@@ -450,7 +460,7 @@ static int open_console(UI *ui) | |||
450 | CRYPTO_w_lock(CRYPTO_LOCK_UI); | 460 | CRYPTO_w_lock(CRYPTO_LOCK_UI); |
451 | is_a_tty = 1; | 461 | is_a_tty = 1; |
452 | 462 | ||
453 | #if defined(OPENSSL_SYS_MACINTOSH_CLASSIC) || defined(OPENSSL_SYS_VSWORKS) | 463 | #if defined(OPENSSL_SYS_MACINTOSH_CLASSIC) || defined(OPENSSL_SYS_VXWORKS) |
454 | tty_in=stdin; | 464 | tty_in=stdin; |
455 | tty_out=stderr; | 465 | tty_out=stderr; |
456 | #else | 466 | #else |
@@ -540,7 +550,7 @@ static int echo_console(UI *ui) | |||
540 | 550 | ||
541 | static int close_console(UI *ui) | 551 | static int close_console(UI *ui) |
542 | { | 552 | { |
543 | if (tty_in != stderr) fclose(tty_in); | 553 | if (tty_in != stdin) fclose(tty_in); |
544 | if (tty_out != stderr) fclose(tty_out); | 554 | if (tty_out != stderr) fclose(tty_out); |
545 | #ifdef OPENSSL_SYS_VMS | 555 | #ifdef OPENSSL_SYS_VMS |
546 | status = sys$dassgn(channel); | 556 | status = sys$dassgn(channel); |
@@ -551,6 +561,7 @@ static int close_console(UI *ui) | |||
551 | } | 561 | } |
552 | 562 | ||
553 | 563 | ||
564 | #if !defined(OPENSSL_SYS_WIN16) && !defined(OPENSSL_SYS_WINCE) | ||
554 | /* Internal functions to handle signals and act on them */ | 565 | /* Internal functions to handle signals and act on them */ |
555 | static void pushsig(void) | 566 | static void pushsig(void) |
556 | { | 567 | { |
@@ -614,9 +625,10 @@ static void recsig(int i) | |||
614 | { | 625 | { |
615 | intr_signal=i; | 626 | intr_signal=i; |
616 | } | 627 | } |
628 | #endif | ||
617 | 629 | ||
618 | /* Internal functions specific for Windows */ | 630 | /* Internal functions specific for Windows */ |
619 | #if defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_WIN16) | 631 | #if defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_WIN16) && !defined(OPENSSL_SYS_WINCE) |
620 | static int noecho_fgets(char *buf, int size, FILE *tty) | 632 | static int noecho_fgets(char *buf, int size, FILE *tty) |
621 | { | 633 | { |
622 | int i; | 634 | int i; |
diff --git a/src/lib/libcrypto/ui/ui_util.c b/src/lib/libcrypto/ui/ui_util.c index f05573df33..46bc8c1a9a 100644 --- a/src/lib/libcrypto/ui/ui_util.c +++ b/src/lib/libcrypto/ui/ui_util.c | |||
@@ -62,7 +62,7 @@ int UI_UTIL_read_pw_string(char *buf,int length,const char *prompt,int verify) | |||
62 | int ret; | 62 | int ret; |
63 | 63 | ||
64 | ret=UI_UTIL_read_pw(buf,buff,(length>BUFSIZ)?BUFSIZ:length,prompt,verify); | 64 | ret=UI_UTIL_read_pw(buf,buff,(length>BUFSIZ)?BUFSIZ:length,prompt,verify); |
65 | memset(buff,0,BUFSIZ); | 65 | OPENSSL_cleanse(buff,BUFSIZ); |
66 | return(ret); | 66 | return(ret); |
67 | } | 67 | } |
68 | 68 | ||
@@ -78,12 +78,14 @@ int UI_UTIL_read_pw(char *buf,char *buff,int size,const char *prompt,int verify) | |||
78 | if (ui) | 78 | if (ui) |
79 | { | 79 | { |
80 | ok = UI_add_input_string(ui,prompt,0,buf,0,size-1); | 80 | ok = UI_add_input_string(ui,prompt,0,buf,0,size-1); |
81 | if (ok == 0 && verify) | 81 | if (ok >= 0 && verify) |
82 | ok = UI_add_verify_string(ui,prompt,0,buff,0,size-1, | 82 | ok = UI_add_verify_string(ui,prompt,0,buff,0,size-1, |
83 | buf); | 83 | buf); |
84 | if (ok == 0) | 84 | if (ok >= 0) |
85 | ok=UI_process(ui); | 85 | ok=UI_process(ui); |
86 | UI_free(ui); | 86 | UI_free(ui); |
87 | } | 87 | } |
88 | if (ok > 0) | ||
89 | ok = 0; | ||
88 | return(ok); | 90 | return(ok); |
89 | } | 91 | } |
diff --git a/src/lib/libcrypto/util/mkerr.pl b/src/lib/libcrypto/util/mkerr.pl index 4105047b21..1b2915c767 100644 --- a/src/lib/libcrypto/util/mkerr.pl +++ b/src/lib/libcrypto/util/mkerr.pl | |||
@@ -132,16 +132,16 @@ while (($hdr, $lib) = each %libinc) | |||
132 | my $name = $1; | 132 | my $name = $1; |
133 | $name =~ tr/[a-z]/[A-Z]/; | 133 | $name =~ tr/[a-z]/[A-Z]/; |
134 | $ftrans{$name} = $1; | 134 | $ftrans{$name} = $1; |
135 | } elsif (/\w+\W+(\w+)\W*\(\s*\)$/s){ | 135 | } elsif (/\w+\W+(\w+)\W*\(\s*\)(\s*__attribute__\(.*\)\s*)?$/s){ |
136 | # K&R C | 136 | # K&R C |
137 | next ; | 137 | next ; |
138 | } elsif (/\w+\W+\w+\W*\(.*\)$/s) { | 138 | } elsif (/\w+\W+\w+\W*\(.*\)(\s*__attribute__\(.*\)\s*)?$/s) { |
139 | while (not /\(\)$/s) { | 139 | while (not /\(\)(\s*__attribute__\(.*\)\s*)?$/s) { |
140 | s/[^\(\)]*\)$/\)/s; | 140 | s/[^\(\)]*\)(\s*__attribute__\(.*\)\s*)?$/\)/s; |
141 | s/\([^\(\)]*\)\)$/\)/s; | 141 | s/\([^\(\)]*\)\)(\s*__attribute__\(.*\)\s*)?$/\)/s; |
142 | } | 142 | } |
143 | s/\(void\)//; | 143 | s/\(void\)//; |
144 | /(\w+)\W*\(\)/s; | 144 | /(\w+(\{[0-9]+\})?)\W*\(\)/s; |
145 | my $name = $1; | 145 | my $name = $1; |
146 | $name =~ tr/[a-z]/[A-Z]/; | 146 | $name =~ tr/[a-z]/[A-Z]/; |
147 | $ftrans{$name} = $1; | 147 | $ftrans{$name} = $1; |
@@ -262,7 +262,7 @@ foreach $lib (keys %csrc) | |||
262 | } else { | 262 | } else { |
263 | push @out, | 263 | push @out, |
264 | "/* ====================================================================\n", | 264 | "/* ====================================================================\n", |
265 | " * Copyright (c) 2001-2002 The OpenSSL Project. All rights reserved.\n", | 265 | " * Copyright (c) 2001-2003 The OpenSSL Project. All rights reserved.\n", |
266 | " *\n", | 266 | " *\n", |
267 | " * Redistribution and use in source and binary forms, with or without\n", | 267 | " * Redistribution and use in source and binary forms, with or without\n", |
268 | " * modification, are permitted provided that the following conditions\n", | 268 | " * modification, are permitted provided that the following conditions\n", |
@@ -404,7 +404,7 @@ EOF | |||
404 | print OUT <<"EOF"; | 404 | print OUT <<"EOF"; |
405 | /* $cfile */ | 405 | /* $cfile */ |
406 | /* ==================================================================== | 406 | /* ==================================================================== |
407 | * Copyright (c) 1999-2002 The OpenSSL Project. All rights reserved. | 407 | * Copyright (c) 1999-2003 The OpenSSL Project. All rights reserved. |
408 | * | 408 | * |
409 | * Redistribution and use in source and binary forms, with or without | 409 | * Redistribution and use in source and binary forms, with or without |
410 | * modification, are permitted provided that the following conditions | 410 | * modification, are permitted provided that the following conditions |
diff --git a/src/lib/libcrypto/x509/by_file.c b/src/lib/libcrypto/x509/by_file.c index 92e00d2d73..b4b04183d0 100644 --- a/src/lib/libcrypto/x509/by_file.c +++ b/src/lib/libcrypto/x509/by_file.c | |||
@@ -100,18 +100,19 @@ static int by_file_ctrl(X509_LOOKUP *ctx, int cmd, const char *argp, long argl, | |||
100 | case X509_L_FILE_LOAD: | 100 | case X509_L_FILE_LOAD: |
101 | if (argl == X509_FILETYPE_DEFAULT) | 101 | if (argl == X509_FILETYPE_DEFAULT) |
102 | { | 102 | { |
103 | ok = (X509_load_cert_crl_file(ctx,X509_get_default_cert_file(), | 103 | file = (char *)Getenv(X509_get_default_cert_file_env()); |
104 | X509_FILETYPE_PEM) != 0); | 104 | if (file) |
105 | ok = (X509_load_cert_crl_file(ctx,file, | ||
106 | X509_FILETYPE_PEM) != 0); | ||
107 | |||
108 | else | ||
109 | ok = (X509_load_cert_crl_file(ctx,X509_get_default_cert_file(), | ||
110 | X509_FILETYPE_PEM) != 0); | ||
111 | |||
105 | if (!ok) | 112 | if (!ok) |
106 | { | 113 | { |
107 | X509err(X509_F_BY_FILE_CTRL,X509_R_LOADING_DEFAULTS); | 114 | X509err(X509_F_BY_FILE_CTRL,X509_R_LOADING_DEFAULTS); |
108 | } | 115 | } |
109 | else | ||
110 | { | ||
111 | file=(char *)Getenv(X509_get_default_cert_file_env()); | ||
112 | ok = (X509_load_cert_crl_file(ctx,file, | ||
113 | X509_FILETYPE_PEM) != 0); | ||
114 | } | ||
115 | } | 116 | } |
116 | else | 117 | else |
117 | { | 118 | { |
@@ -284,7 +285,8 @@ int X509_load_cert_crl_file(X509_LOOKUP *ctx, const char *file, int type) | |||
284 | if(itmp->x509) { | 285 | if(itmp->x509) { |
285 | X509_STORE_add_cert(ctx->store_ctx, itmp->x509); | 286 | X509_STORE_add_cert(ctx->store_ctx, itmp->x509); |
286 | count++; | 287 | count++; |
287 | } else if(itmp->crl) { | 288 | } |
289 | if(itmp->crl) { | ||
288 | X509_STORE_add_crl(ctx->store_ctx, itmp->crl); | 290 | X509_STORE_add_crl(ctx->store_ctx, itmp->crl); |
289 | count++; | 291 | count++; |
290 | } | 292 | } |
diff --git a/src/lib/libcrypto/x509/x509.h b/src/lib/libcrypto/x509/x509.h index 7095440d36..eaad5685a8 100644 --- a/src/lib/libcrypto/x509/x509.h +++ b/src/lib/libcrypto/x509/x509.h | |||
@@ -87,7 +87,6 @@ | |||
87 | #ifndef OPENSSL_NO_SHA | 87 | #ifndef OPENSSL_NO_SHA |
88 | #include <openssl/sha.h> | 88 | #include <openssl/sha.h> |
89 | #endif | 89 | #endif |
90 | #include <openssl/evp.h> | ||
91 | #include <openssl/e_os2.h> | 90 | #include <openssl/e_os2.h> |
92 | #include <openssl/ossl_typ.h> | 91 | #include <openssl/ossl_typ.h> |
93 | 92 | ||
@@ -487,10 +486,12 @@ typedef struct Netscape_certificate_sequence | |||
487 | STACK_OF(X509) *certs; | 486 | STACK_OF(X509) *certs; |
488 | } NETSCAPE_CERT_SEQUENCE; | 487 | } NETSCAPE_CERT_SEQUENCE; |
489 | 488 | ||
489 | /* Unused (and iv length is wrong) | ||
490 | typedef struct CBCParameter_st | 490 | typedef struct CBCParameter_st |
491 | { | 491 | { |
492 | unsigned char iv[8]; | 492 | unsigned char iv[8]; |
493 | } CBC_PARAM; | 493 | } CBC_PARAM; |
494 | */ | ||
494 | 495 | ||
495 | /* Password based encryption structure */ | 496 | /* Password based encryption structure */ |
496 | 497 | ||
diff --git a/src/lib/libcrypto/x509/x509_cmp.c b/src/lib/libcrypto/x509/x509_cmp.c index cd20b6d66f..f460102f49 100644 --- a/src/lib/libcrypto/x509/x509_cmp.c +++ b/src/lib/libcrypto/x509/x509_cmp.c | |||
@@ -57,6 +57,7 @@ | |||
57 | */ | 57 | */ |
58 | 58 | ||
59 | #include <stdio.h> | 59 | #include <stdio.h> |
60 | #include <ctype.h> | ||
60 | #include "cryptlib.h" | 61 | #include "cryptlib.h" |
61 | #include <openssl/asn1.h> | 62 | #include <openssl/asn1.h> |
62 | #include <openssl/objects.h> | 63 | #include <openssl/objects.h> |
@@ -81,13 +82,14 @@ unsigned long X509_issuer_and_serial_hash(X509 *a) | |||
81 | unsigned long ret=0; | 82 | unsigned long ret=0; |
82 | EVP_MD_CTX ctx; | 83 | EVP_MD_CTX ctx; |
83 | unsigned char md[16]; | 84 | unsigned char md[16]; |
84 | char str[256]; | 85 | char *f; |
85 | 86 | ||
86 | EVP_MD_CTX_init(&ctx); | 87 | EVP_MD_CTX_init(&ctx); |
87 | X509_NAME_oneline(a->cert_info->issuer,str,256); | 88 | f=X509_NAME_oneline(a->cert_info->issuer,NULL,0); |
88 | ret=strlen(str); | 89 | ret=strlen(f); |
89 | EVP_DigestInit_ex(&ctx, EVP_md5(), NULL); | 90 | EVP_DigestInit_ex(&ctx, EVP_md5(), NULL); |
90 | EVP_DigestUpdate(&ctx,(unsigned char *)str,ret); | 91 | EVP_DigestUpdate(&ctx,(unsigned char *)f,ret); |
92 | OPENSSL_free(f); | ||
91 | EVP_DigestUpdate(&ctx,(unsigned char *)a->cert_info->serialNumber->data, | 93 | EVP_DigestUpdate(&ctx,(unsigned char *)a->cert_info->serialNumber->data, |
92 | (unsigned long)a->cert_info->serialNumber->length); | 94 | (unsigned long)a->cert_info->serialNumber->length); |
93 | EVP_DigestFinal_ex(&ctx,&(md[0]),NULL); | 95 | EVP_DigestFinal_ex(&ctx,&(md[0]),NULL); |
@@ -159,6 +161,99 @@ int X509_cmp(const X509 *a, const X509 *b) | |||
159 | } | 161 | } |
160 | #endif | 162 | #endif |
161 | 163 | ||
164 | |||
165 | /* Case insensitive string comparision */ | ||
166 | static int nocase_cmp(const ASN1_STRING *a, const ASN1_STRING *b) | ||
167 | { | ||
168 | int i; | ||
169 | |||
170 | if (a->length != b->length) | ||
171 | return (a->length - b->length); | ||
172 | |||
173 | for (i=0; i<a->length; i++) | ||
174 | { | ||
175 | int ca, cb; | ||
176 | |||
177 | ca = tolower(a->data[i]); | ||
178 | cb = tolower(b->data[i]); | ||
179 | |||
180 | if (ca != cb) | ||
181 | return(ca-cb); | ||
182 | } | ||
183 | return 0; | ||
184 | } | ||
185 | |||
186 | /* Case insensitive string comparision with space normalization | ||
187 | * Space normalization - ignore leading, trailing spaces, | ||
188 | * multiple spaces between characters are replaced by single space | ||
189 | */ | ||
190 | static int nocase_spacenorm_cmp(const ASN1_STRING *a, const ASN1_STRING *b) | ||
191 | { | ||
192 | unsigned char *pa = NULL, *pb = NULL; | ||
193 | int la, lb; | ||
194 | |||
195 | la = a->length; | ||
196 | lb = b->length; | ||
197 | pa = a->data; | ||
198 | pb = b->data; | ||
199 | |||
200 | /* skip leading spaces */ | ||
201 | while (la > 0 && isspace(*pa)) | ||
202 | { | ||
203 | la--; | ||
204 | pa++; | ||
205 | } | ||
206 | while (lb > 0 && isspace(*pb)) | ||
207 | { | ||
208 | lb--; | ||
209 | pb++; | ||
210 | } | ||
211 | |||
212 | /* skip trailing spaces */ | ||
213 | while (la > 0 && isspace(pa[la-1])) | ||
214 | la--; | ||
215 | while (lb > 0 && isspace(pb[lb-1])) | ||
216 | lb--; | ||
217 | |||
218 | /* compare strings with space normalization */ | ||
219 | while (la > 0 && lb > 0) | ||
220 | { | ||
221 | int ca, cb; | ||
222 | |||
223 | /* compare character */ | ||
224 | ca = tolower(*pa); | ||
225 | cb = tolower(*pb); | ||
226 | if (ca != cb) | ||
227 | return (ca - cb); | ||
228 | |||
229 | pa++; pb++; | ||
230 | la--; lb--; | ||
231 | |||
232 | if (la <= 0 || lb <= 0) | ||
233 | break; | ||
234 | |||
235 | /* is white space next character ? */ | ||
236 | if (isspace(*pa) && isspace(*pb)) | ||
237 | { | ||
238 | /* skip remaining white spaces */ | ||
239 | while (la > 0 && isspace(*pa)) | ||
240 | { | ||
241 | la--; | ||
242 | pa++; | ||
243 | } | ||
244 | while (lb > 0 && isspace(*pb)) | ||
245 | { | ||
246 | lb--; | ||
247 | pb++; | ||
248 | } | ||
249 | } | ||
250 | } | ||
251 | if (la > 0 || lb > 0) | ||
252 | return la - lb; | ||
253 | |||
254 | return 0; | ||
255 | } | ||
256 | |||
162 | int X509_NAME_cmp(const X509_NAME *a, const X509_NAME *b) | 257 | int X509_NAME_cmp(const X509_NAME *a, const X509_NAME *b) |
163 | { | 258 | { |
164 | int i,j; | 259 | int i,j; |
@@ -172,10 +267,20 @@ int X509_NAME_cmp(const X509_NAME *a, const X509_NAME *b) | |||
172 | { | 267 | { |
173 | na=sk_X509_NAME_ENTRY_value(a->entries,i); | 268 | na=sk_X509_NAME_ENTRY_value(a->entries,i); |
174 | nb=sk_X509_NAME_ENTRY_value(b->entries,i); | 269 | nb=sk_X509_NAME_ENTRY_value(b->entries,i); |
175 | j=na->value->length-nb->value->length; | 270 | j=na->value->type-nb->value->type; |
176 | if (j) return(j); | 271 | if (j) return(j); |
177 | j=memcmp(na->value->data,nb->value->data, | 272 | if (na->value->type == V_ASN1_PRINTABLESTRING) |
178 | na->value->length); | 273 | j=nocase_spacenorm_cmp(na->value, nb->value); |
274 | else if (na->value->type == V_ASN1_IA5STRING | ||
275 | && OBJ_obj2nid(na->object) == NID_pkcs9_emailAddress) | ||
276 | j=nocase_cmp(na->value, nb->value); | ||
277 | else | ||
278 | { | ||
279 | j=na->value->length-nb->value->length; | ||
280 | if (j) return(j); | ||
281 | j=memcmp(na->value->data,nb->value->data, | ||
282 | na->value->length); | ||
283 | } | ||
179 | if (j) return(j); | 284 | if (j) return(j); |
180 | j=na->set-nb->set; | 285 | j=na->set-nb->set; |
181 | if (j) return(j); | 286 | if (j) return(j); |
diff --git a/src/lib/libcrypto/x509/x509_v3.c b/src/lib/libcrypto/x509/x509_v3.c index b5f7daa2e5..67b1796a92 100644 --- a/src/lib/libcrypto/x509/x509_v3.c +++ b/src/lib/libcrypto/x509/x509_v3.c | |||
@@ -116,7 +116,7 @@ int X509v3_get_ext_by_critical(const STACK_OF(X509_EXTENSION) *sk, int crit, | |||
116 | { | 116 | { |
117 | ex=sk_X509_EXTENSION_value(sk,lastpos); | 117 | ex=sk_X509_EXTENSION_value(sk,lastpos); |
118 | if ( ((ex->critical > 0) && crit) || | 118 | if ( ((ex->critical > 0) && crit) || |
119 | (!(ex->critical <= 0) && !crit)) | 119 | ((ex->critical <= 0) && !crit)) |
120 | return(lastpos); | 120 | return(lastpos); |
121 | } | 121 | } |
122 | return(-1); | 122 | return(-1); |
diff --git a/src/lib/libcrypto/x509/x509_vfy.c b/src/lib/libcrypto/x509/x509_vfy.c index db12f7bd35..552d1e7251 100644 --- a/src/lib/libcrypto/x509/x509_vfy.c +++ b/src/lib/libcrypto/x509/x509_vfy.c | |||
@@ -756,7 +756,7 @@ int X509_cmp_time(ASN1_TIME *ctm, time_t *cmp_time) | |||
756 | { | 756 | { |
757 | char *str; | 757 | char *str; |
758 | ASN1_TIME atm; | 758 | ASN1_TIME atm; |
759 | time_t offset; | 759 | long offset; |
760 | char buff1[24],buff2[24],*p; | 760 | char buff1[24],buff2[24],*p; |
761 | int i,j; | 761 | int i,j; |
762 | 762 | ||
diff --git a/src/lib/libcrypto/x509v3/ext_dat.h b/src/lib/libcrypto/x509v3/ext_dat.h index 2fb97d8925..5442480595 100644 --- a/src/lib/libcrypto/x509v3/ext_dat.h +++ b/src/lib/libcrypto/x509v3/ext_dat.h | |||
@@ -90,17 +90,23 @@ static X509V3_EXT_METHOD *standard_exts[] = { | |||
90 | &v3_crld, | 90 | &v3_crld, |
91 | &v3_ext_ku, | 91 | &v3_ext_ku, |
92 | &v3_crl_reason, | 92 | &v3_crl_reason, |
93 | #ifndef OPENSSL_NO_OCSP | ||
93 | &v3_crl_invdate, | 94 | &v3_crl_invdate, |
95 | #endif | ||
94 | &v3_sxnet, | 96 | &v3_sxnet, |
95 | &v3_info, | 97 | &v3_info, |
98 | #ifndef OPENSSL_NO_OCSP | ||
96 | &v3_ocsp_nonce, | 99 | &v3_ocsp_nonce, |
97 | &v3_ocsp_crlid, | 100 | &v3_ocsp_crlid, |
98 | &v3_ocsp_accresp, | 101 | &v3_ocsp_accresp, |
99 | &v3_ocsp_nocheck, | 102 | &v3_ocsp_nocheck, |
100 | &v3_ocsp_acutoff, | 103 | &v3_ocsp_acutoff, |
101 | &v3_ocsp_serviceloc, | 104 | &v3_ocsp_serviceloc, |
105 | #endif | ||
102 | &v3_sinfo, | 106 | &v3_sinfo, |
107 | #ifndef OPENSSL_NO_OCSP | ||
103 | &v3_crl_hold | 108 | &v3_crl_hold |
109 | #endif | ||
104 | }; | 110 | }; |
105 | 111 | ||
106 | /* Number of standard extensions */ | 112 | /* Number of standard extensions */ |
diff --git a/src/lib/libcrypto/x509v3/v3_info.c b/src/lib/libcrypto/x509v3/v3_info.c index e1cf01a9b4..e269df1373 100644 --- a/src/lib/libcrypto/x509v3/v3_info.c +++ b/src/lib/libcrypto/x509v3/v3_info.c | |||
@@ -113,7 +113,7 @@ static STACK_OF(CONF_VALUE) *i2v_AUTHORITY_INFO_ACCESS(X509V3_EXT_METHOD *method | |||
113 | ret = i2v_GENERAL_NAME(method, desc->location, ret); | 113 | ret = i2v_GENERAL_NAME(method, desc->location, ret); |
114 | if(!ret) break; | 114 | if(!ret) break; |
115 | vtmp = sk_CONF_VALUE_value(ret, i); | 115 | vtmp = sk_CONF_VALUE_value(ret, i); |
116 | i2t_ASN1_OBJECT(objtmp, 80, desc->method); | 116 | i2t_ASN1_OBJECT(objtmp, sizeof objtmp, desc->method); |
117 | ntmp = OPENSSL_malloc(strlen(objtmp) + strlen(vtmp->name) + 5); | 117 | ntmp = OPENSSL_malloc(strlen(objtmp) + strlen(vtmp->name) + 5); |
118 | if(!ntmp) { | 118 | if(!ntmp) { |
119 | X509V3err(X509V3_F_I2V_AUTHORITY_INFO_ACCESS, | 119 | X509V3err(X509V3_F_I2V_AUTHORITY_INFO_ACCESS, |
diff --git a/src/lib/libcrypto/x509v3/v3_ocsp.c b/src/lib/libcrypto/x509v3/v3_ocsp.c index 083112314e..21badc13f9 100644 --- a/src/lib/libcrypto/x509v3/v3_ocsp.c +++ b/src/lib/libcrypto/x509v3/v3_ocsp.c | |||
@@ -56,6 +56,8 @@ | |||
56 | * | 56 | * |
57 | */ | 57 | */ |
58 | 58 | ||
59 | #ifndef OPENSSL_NO_OCSP | ||
60 | |||
59 | #include <stdio.h> | 61 | #include <stdio.h> |
60 | #include "cryptlib.h" | 62 | #include "cryptlib.h" |
61 | #include <openssl/conf.h> | 63 | #include <openssl/conf.h> |
@@ -270,3 +272,4 @@ static int i2r_ocsp_serviceloc(X509V3_EXT_METHOD *method, void *in, BIO *bp, int | |||
270 | err: | 272 | err: |
271 | return 0; | 273 | return 0; |
272 | } | 274 | } |
275 | #endif | ||
diff --git a/src/lib/libcrypto/x509v3/v3_prn.c b/src/lib/libcrypto/x509v3/v3_prn.c index aeaf6170fe..754808b625 100644 --- a/src/lib/libcrypto/x509v3/v3_prn.c +++ b/src/lib/libcrypto/x509v3/v3_prn.c | |||
@@ -178,7 +178,7 @@ int X509V3_extensions_print(BIO *bp, char *title, STACK_OF(X509_EXTENSION) *exts | |||
178 | ASN1_OBJECT *obj; | 178 | ASN1_OBJECT *obj; |
179 | X509_EXTENSION *ex; | 179 | X509_EXTENSION *ex; |
180 | ex=sk_X509_EXTENSION_value(exts, i); | 180 | ex=sk_X509_EXTENSION_value(exts, i); |
181 | if (BIO_printf(bp,"%*s",indent, "") <= 0) return 0; | 181 | if (indent && BIO_printf(bp,"%*s",indent, "") <= 0) return 0; |
182 | obj=X509_EXTENSION_get_object(ex); | 182 | obj=X509_EXTENSION_get_object(ex); |
183 | i2a_ASN1_OBJECT(bp,obj); | 183 | i2a_ASN1_OBJECT(bp,obj); |
184 | j=X509_EXTENSION_get_critical(ex); | 184 | j=X509_EXTENSION_get_critical(ex); |
diff --git a/src/lib/libcrypto/x509v3/v3_purp.c b/src/lib/libcrypto/x509v3/v3_purp.c index b739e4fd83..4d145f71fd 100644 --- a/src/lib/libcrypto/x509v3/v3_purp.c +++ b/src/lib/libcrypto/x509v3/v3_purp.c | |||
@@ -378,6 +378,10 @@ static void x509v3_cache_extensions(X509 *x) | |||
378 | case NID_time_stamp: | 378 | case NID_time_stamp: |
379 | x->ex_xkusage |= XKU_TIMESTAMP; | 379 | x->ex_xkusage |= XKU_TIMESTAMP; |
380 | break; | 380 | break; |
381 | |||
382 | case NID_dvcs: | ||
383 | x->ex_xkusage |= XKU_DVCS; | ||
384 | break; | ||
381 | } | 385 | } |
382 | } | 386 | } |
383 | sk_ASN1_OBJECT_pop_free(extusage, ASN1_OBJECT_free); | 387 | sk_ASN1_OBJECT_pop_free(extusage, ASN1_OBJECT_free); |
diff --git a/src/lib/libcrypto/x509v3/v3_utl.c b/src/lib/libcrypto/x509v3/v3_utl.c index 283e943e46..34ac2998de 100644 --- a/src/lib/libcrypto/x509v3/v3_utl.c +++ b/src/lib/libcrypto/x509v3/v3_utl.c | |||
@@ -491,7 +491,7 @@ static STACK *get_email(X509_NAME *name, GENERAL_NAMES *gens) | |||
491 | i = -1; | 491 | i = -1; |
492 | /* First supplied X509_NAME */ | 492 | /* First supplied X509_NAME */ |
493 | while((i = X509_NAME_get_index_by_NID(name, | 493 | while((i = X509_NAME_get_index_by_NID(name, |
494 | NID_pkcs9_emailAddress, i)) > 0) { | 494 | NID_pkcs9_emailAddress, i)) >= 0) { |
495 | ne = X509_NAME_get_entry(name, i); | 495 | ne = X509_NAME_get_entry(name, i); |
496 | email = X509_NAME_ENTRY_get_data(ne); | 496 | email = X509_NAME_ENTRY_get_data(ne); |
497 | if(!append_ia5(&ret, email)) return NULL; | 497 | if(!append_ia5(&ret, email)) return NULL; |
diff --git a/src/lib/libcrypto/x509v3/x509v3.h b/src/lib/libcrypto/x509v3/x509v3.h index daecc55271..fb07a19016 100644 --- a/src/lib/libcrypto/x509v3/x509v3.h +++ b/src/lib/libcrypto/x509v3/x509v3.h | |||
@@ -352,6 +352,7 @@ DECLARE_ASN1_SET_OF(POLICYINFO) | |||
352 | #define XKU_SGC 0x10 | 352 | #define XKU_SGC 0x10 |
353 | #define XKU_OCSP_SIGN 0x20 | 353 | #define XKU_OCSP_SIGN 0x20 |
354 | #define XKU_TIMESTAMP 0x40 | 354 | #define XKU_TIMESTAMP 0x40 |
355 | #define XKU_DVCS 0x80 | ||
355 | 356 | ||
356 | #define X509_PURPOSE_DYNAMIC 0x1 | 357 | #define X509_PURPOSE_DYNAMIC 0x1 |
357 | #define X509_PURPOSE_DYNAMIC_NAME 0x2 | 358 | #define X509_PURPOSE_DYNAMIC_NAME 0x2 |
diff --git a/src/lib/libssl/LICENSE b/src/lib/libssl/LICENSE index 7b93e0dbce..dddb07842b 100644 --- a/src/lib/libssl/LICENSE +++ b/src/lib/libssl/LICENSE | |||
@@ -12,7 +12,7 @@ | |||
12 | --------------- | 12 | --------------- |
13 | 13 | ||
14 | /* ==================================================================== | 14 | /* ==================================================================== |
15 | * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved. | 15 | * Copyright (c) 1998-2003 The OpenSSL Project. All rights reserved. |
16 | * | 16 | * |
17 | * Redistribution and use in source and binary forms, with or without | 17 | * Redistribution and use in source and binary forms, with or without |
18 | * modification, are permitted provided that the following conditions | 18 | * modification, are permitted provided that the following conditions |
diff --git a/src/lib/libssl/bio_ssl.c b/src/lib/libssl/bio_ssl.c index 467e149947..d683ee43e1 100644 --- a/src/lib/libssl/bio_ssl.c +++ b/src/lib/libssl/bio_ssl.c | |||
@@ -403,6 +403,10 @@ static long ssl_ctrl(BIO *b, int cmd, long num, void *ptr) | |||
403 | { | 403 | { |
404 | BIO_free_all(ssl->wbio); | 404 | BIO_free_all(ssl->wbio); |
405 | } | 405 | } |
406 | if (b->next_bio != NULL) | ||
407 | { | ||
408 | CRYPTO_add(&b->next_bio->references,1,CRYPTO_LOCK_BIO); | ||
409 | } | ||
406 | ssl->wbio=NULL; | 410 | ssl->wbio=NULL; |
407 | ssl->rbio=NULL; | 411 | ssl->rbio=NULL; |
408 | break; | 412 | break; |
@@ -509,6 +513,7 @@ static int ssl_puts(BIO *bp, const char *str) | |||
509 | 513 | ||
510 | BIO *BIO_new_buffer_ssl_connect(SSL_CTX *ctx) | 514 | BIO *BIO_new_buffer_ssl_connect(SSL_CTX *ctx) |
511 | { | 515 | { |
516 | #ifndef OPENSSL_NO_SOCK | ||
512 | BIO *ret=NULL,*buf=NULL,*ssl=NULL; | 517 | BIO *ret=NULL,*buf=NULL,*ssl=NULL; |
513 | 518 | ||
514 | if ((buf=BIO_new(BIO_f_buffer())) == NULL) | 519 | if ((buf=BIO_new(BIO_f_buffer())) == NULL) |
@@ -521,6 +526,7 @@ BIO *BIO_new_buffer_ssl_connect(SSL_CTX *ctx) | |||
521 | err: | 526 | err: |
522 | if (buf != NULL) BIO_free(buf); | 527 | if (buf != NULL) BIO_free(buf); |
523 | if (ssl != NULL) BIO_free(ssl); | 528 | if (ssl != NULL) BIO_free(ssl); |
529 | #endif | ||
524 | return(NULL); | 530 | return(NULL); |
525 | } | 531 | } |
526 | 532 | ||
diff --git a/src/lib/libssl/doc/standards.txt b/src/lib/libssl/doc/standards.txt index 596d9001e6..edbe2f3a57 100644 --- a/src/lib/libssl/doc/standards.txt +++ b/src/lib/libssl/doc/standards.txt | |||
@@ -42,20 +42,9 @@ whole or at least great parts) in OpenSSL. | |||
42 | 2268 A Description of the RC2(r) Encryption Algorithm. R. Rivest. | 42 | 2268 A Description of the RC2(r) Encryption Algorithm. R. Rivest. |
43 | January 1998. (Format: TXT=19048 bytes) (Status: INFORMATIONAL) | 43 | January 1998. (Format: TXT=19048 bytes) (Status: INFORMATIONAL) |
44 | 44 | ||
45 | 2314 PKCS 10: Certification Request Syntax Version 1.5. B. Kaliski. | ||
46 | March 1998. (Format: TXT=15814 bytes) (Status: INFORMATIONAL) | ||
47 | |||
48 | 2315 PKCS 7: Cryptographic Message Syntax Version 1.5. B. Kaliski. | 45 | 2315 PKCS 7: Cryptographic Message Syntax Version 1.5. B. Kaliski. |
49 | March 1998. (Format: TXT=69679 bytes) (Status: INFORMATIONAL) | 46 | March 1998. (Format: TXT=69679 bytes) (Status: INFORMATIONAL) |
50 | 47 | ||
51 | 2437 PKCS #1: RSA Cryptography Specifications Version 2.0. B. Kaliski, | ||
52 | J. Staddon. October 1998. (Format: TXT=73529 bytes) (Obsoletes | ||
53 | RFC2313) (Status: INFORMATIONAL) | ||
54 | |||
55 | 2459 Internet X.509 Public Key Infrastructure Certificate and CRL | ||
56 | Profile. R. Housley, W. Ford, W. Polk, D. Solo. January 1999. | ||
57 | (Format: TXT=278438 bytes) (Status: PROPOSED STANDARD) | ||
58 | |||
59 | PKCS#8: Private-Key Information Syntax Standard | 48 | PKCS#8: Private-Key Information Syntax Standard |
60 | 49 | ||
61 | PKCS#12: Personal Information Exchange Syntax Standard, version 1.0. | 50 | PKCS#12: Personal Information Exchange Syntax Standard, version 1.0. |
@@ -65,6 +54,40 @@ PKCS#12: Personal Information Exchange Syntax Standard, version 1.0. | |||
65 | C. Adams. June 1999. (Format: TXT=43243 bytes) (Status: PROPOSED | 54 | C. Adams. June 1999. (Format: TXT=43243 bytes) (Status: PROPOSED |
66 | STANDARD) | 55 | STANDARD) |
67 | 56 | ||
57 | 2712 Addition of Kerberos Cipher Suites to Transport Layer Security | ||
58 | (TLS). A. Medvinsky, M. Hur. October 1999. (Format: TXT=13763 bytes) | ||
59 | (Status: PROPOSED STANDARD) | ||
60 | |||
61 | 2898 PKCS #5: Password-Based Cryptography Specification Version 2.0. | ||
62 | B. Kaliski. September 2000. (Format: TXT=68692 bytes) (Status: | ||
63 | INFORMATIONAL) | ||
64 | |||
65 | 2986 PKCS #10: Certification Request Syntax Specification Version 1.7. | ||
66 | M. Nystrom, B. Kaliski. November 2000. (Format: TXT=27794 bytes) | ||
67 | (Obsoletes RFC2314) (Status: INFORMATIONAL) | ||
68 | |||
69 | 3174 US Secure Hash Algorithm 1 (SHA1). D. Eastlake 3rd, P. Jones. | ||
70 | September 2001. (Format: TXT=35525 bytes) (Status: INFORMATIONAL) | ||
71 | |||
72 | 3268 Advanced Encryption Standard (AES) Ciphersuites for Transport | ||
73 | Layer Security (TLS). P. Chown. June 2002. (Format: TXT=13530 bytes) | ||
74 | (Status: PROPOSED STANDARD) | ||
75 | |||
76 | 3279 Algorithms and Identifiers for the Internet X.509 Public Key | ||
77 | Infrastructure Certificate and Certificate Revocation List (CRL) | ||
78 | Profile. L. Bassham, W. Polk, R. Housley. April 2002. (Format: | ||
79 | TXT=53833 bytes) (Status: PROPOSED STANDARD) | ||
80 | |||
81 | 3280 Internet X.509 Public Key Infrastructure Certificate and | ||
82 | Certificate Revocation List (CRL) Profile. R. Housley, W. Polk, W. | ||
83 | Ford, D. Solo. April 2002. (Format: TXT=295556 bytes) (Obsoletes | ||
84 | RFC2459) (Status: PROPOSED STANDARD) | ||
85 | |||
86 | 3447 Public-Key Cryptography Standards (PKCS) #1: RSA Cryptography | ||
87 | Specifications Version 2.1. J. Jonsson, B. Kaliski. February 2003. | ||
88 | (Format: TXT=143173 bytes) (Obsoletes RFC2437) (Status: | ||
89 | INFORMATIONAL) | ||
90 | |||
68 | 91 | ||
69 | Related: | 92 | Related: |
70 | -------- | 93 | -------- |
@@ -90,23 +113,60 @@ STARTTLS documents. | |||
90 | Certification and Related Services. B. Kaliski. February 1993. | 113 | Certification and Related Services. B. Kaliski. February 1993. |
91 | (Format: TXT=17537 bytes) (Status: PROPOSED STANDARD) | 114 | (Format: TXT=17537 bytes) (Status: PROPOSED STANDARD) |
92 | 115 | ||
93 | 2256 A Summary of the X.500(96) User Schema for use with LDAPv3. M. | 116 | 2025 The Simple Public-Key GSS-API Mechanism (SPKM). C. Adams. October |
94 | Wahl. December 1997. (Format: TXT=32377 bytes) (Status: PROPOSED | 117 | 1996. (Format: TXT=101692 bytes) (Status: PROPOSED STANDARD) |
95 | STANDARD) | 118 | |
119 | 2510 Internet X.509 Public Key Infrastructure Certificate Management | ||
120 | Protocols. C. Adams, S. Farrell. March 1999. (Format: TXT=158178 | ||
121 | bytes) (Status: PROPOSED STANDARD) | ||
122 | |||
123 | 2511 Internet X.509 Certificate Request Message Format. M. Myers, C. | ||
124 | Adams, D. Solo, D. Kemp. March 1999. (Format: TXT=48278 bytes) | ||
125 | (Status: PROPOSED STANDARD) | ||
126 | |||
127 | 2527 Internet X.509 Public Key Infrastructure Certificate Policy and | ||
128 | Certification Practices Framework. S. Chokhani, W. Ford. March 1999. | ||
129 | (Format: TXT=91860 bytes) (Status: INFORMATIONAL) | ||
96 | 130 | ||
97 | 2487 SMTP Service Extension for Secure SMTP over TLS. P. Hoffman. | 131 | 2538 Storing Certificates in the Domain Name System (DNS). D. Eastlake |
98 | January 1999. (Format: TXT=15120 bytes) (Status: PROPOSED STANDARD) | 132 | 3rd, O. Gudmundsson. March 1999. (Format: TXT=19857 bytes) (Status: |
133 | PROPOSED STANDARD) | ||
134 | |||
135 | 2539 Storage of Diffie-Hellman Keys in the Domain Name System (DNS). | ||
136 | D. Eastlake 3rd. March 1999. (Format: TXT=21049 bytes) (Status: | ||
137 | PROPOSED STANDARD) | ||
138 | |||
139 | 2559 Internet X.509 Public Key Infrastructure Operational Protocols - | ||
140 | LDAPv2. S. Boeyen, T. Howes, P. Richard. April 1999. (Format: | ||
141 | TXT=22889 bytes) (Updates RFC1778) (Status: PROPOSED STANDARD) | ||
99 | 142 | ||
100 | 2585 Internet X.509 Public Key Infrastructure Operational Protocols: | 143 | 2585 Internet X.509 Public Key Infrastructure Operational Protocols: |
101 | FTP and HTTP. R. Housley, P. Hoffman. May 1999. (Format: TXT=14813 | 144 | FTP and HTTP. R. Housley, P. Hoffman. May 1999. (Format: TXT=14813 |
102 | bytes) (Status: PROPOSED STANDARD) | 145 | bytes) (Status: PROPOSED STANDARD) |
103 | 146 | ||
147 | 2587 Internet X.509 Public Key Infrastructure LDAPv2 Schema. S. | ||
148 | Boeyen, T. Howes, P. Richard. June 1999. (Format: TXT=15102 bytes) | ||
149 | (Status: PROPOSED STANDARD) | ||
150 | |||
104 | 2595 Using TLS with IMAP, POP3 and ACAP. C. Newman. June 1999. | 151 | 2595 Using TLS with IMAP, POP3 and ACAP. C. Newman. June 1999. |
105 | (Format: TXT=32440 bytes) (Status: PROPOSED STANDARD) | 152 | (Format: TXT=32440 bytes) (Status: PROPOSED STANDARD) |
106 | 153 | ||
107 | 2712 Addition of Kerberos Cipher Suites to Transport Layer Security | 154 | 2631 Diffie-Hellman Key Agreement Method. E. Rescorla. June 1999. |
108 | (TLS). A. Medvinsky, M. Hur. October 1999. (Format: TXT=13763 bytes) | 155 | (Format: TXT=25932 bytes) (Status: PROPOSED STANDARD) |
109 | (Status: PROPOSED STANDARD) | 156 | |
157 | 2632 S/MIME Version 3 Certificate Handling. B. Ramsdell, Ed.. June | ||
158 | 1999. (Format: TXT=27925 bytes) (Status: PROPOSED STANDARD) | ||
159 | |||
160 | 2716 PPP EAP TLS Authentication Protocol. B. Aboba, D. Simon. October | ||
161 | 1999. (Format: TXT=50108 bytes) (Status: EXPERIMENTAL) | ||
162 | |||
163 | 2773 Encryption using KEA and SKIPJACK. R. Housley, P. Yee, W. Nace. | ||
164 | February 2000. (Format: TXT=20008 bytes) (Updates RFC0959) (Status: | ||
165 | EXPERIMENTAL) | ||
166 | |||
167 | 2797 Certificate Management Messages over CMS. M. Myers, X. Liu, J. | ||
168 | Schaad, J. Weinstein. April 2000. (Format: TXT=103357 bytes) (Status: | ||
169 | PROPOSED STANDARD) | ||
110 | 170 | ||
111 | 2817 Upgrading to TLS Within HTTP/1.1. R. Khare, S. Lawrence. May | 171 | 2817 Upgrading to TLS Within HTTP/1.1. R. Khare, S. Lawrence. May |
112 | 2000. (Format: TXT=27598 bytes) (Updates RFC2616) (Status: PROPOSED | 172 | 2000. (Format: TXT=27598 bytes) (Updates RFC2616) (Status: PROPOSED |
@@ -115,6 +175,77 @@ STARTTLS documents. | |||
115 | 2818 HTTP Over TLS. E. Rescorla. May 2000. (Format: TXT=15170 bytes) | 175 | 2818 HTTP Over TLS. E. Rescorla. May 2000. (Format: TXT=15170 bytes) |
116 | (Status: INFORMATIONAL) | 176 | (Status: INFORMATIONAL) |
117 | 177 | ||
178 | 2876 Use of the KEA and SKIPJACK Algorithms in CMS. J. Pawling. July | ||
179 | 2000. (Format: TXT=29265 bytes) (Status: INFORMATIONAL) | ||
180 | |||
181 | 2984 Use of the CAST-128 Encryption Algorithm in CMS. C. Adams. | ||
182 | October 2000. (Format: TXT=11591 bytes) (Status: PROPOSED STANDARD) | ||
183 | |||
184 | 2985 PKCS #9: Selected Object Classes and Attribute Types Version 2.0. | ||
185 | M. Nystrom, B. Kaliski. November 2000. (Format: TXT=70703 bytes) | ||
186 | (Status: INFORMATIONAL) | ||
187 | |||
188 | 3029 Internet X.509 Public Key Infrastructure Data Validation and | ||
189 | Certification Server Protocols. C. Adams, P. Sylvester, M. Zolotarev, | ||
190 | R. Zuccherato. February 2001. (Format: TXT=107347 bytes) (Status: | ||
191 | EXPERIMENTAL) | ||
192 | |||
193 | 3039 Internet X.509 Public Key Infrastructure Qualified Certificates | ||
194 | Profile. S. Santesson, W. Polk, P. Barzin, M. Nystrom. January 2001. | ||
195 | (Format: TXT=67619 bytes) (Status: PROPOSED STANDARD) | ||
196 | |||
197 | 3058 Use of the IDEA Encryption Algorithm in CMS. S. Teiwes, P. | ||
198 | Hartmann, D. Kuenzi. February 2001. (Format: TXT=17257 bytes) | ||
199 | (Status: INFORMATIONAL) | ||
200 | |||
201 | 3161 Internet X.509 Public Key Infrastructure Time-Stamp Protocol | ||
202 | (TSP). C. Adams, P. Cain, D. Pinkas, R. Zuccherato. August 2001. | ||
203 | (Format: TXT=54585 bytes) (Status: PROPOSED STANDARD) | ||
204 | |||
205 | 3185 Reuse of CMS Content Encryption Keys. S. Farrell, S. Turner. | ||
206 | October 2001. (Format: TXT=20404 bytes) (Status: PROPOSED STANDARD) | ||
207 | |||
208 | 3207 SMTP Service Extension for Secure SMTP over Transport Layer | ||
209 | Security. P. Hoffman. February 2002. (Format: TXT=18679 bytes) | ||
210 | (Obsoletes RFC2487) (Status: PROPOSED STANDARD) | ||
211 | |||
212 | 3217 Triple-DES and RC2 Key Wrapping. R. Housley. December 2001. | ||
213 | (Format: TXT=19855 bytes) (Status: INFORMATIONAL) | ||
214 | |||
215 | 3274 Compressed Data Content Type for Cryptographic Message Syntax | ||
216 | (CMS). P. Gutmann. June 2002. (Format: TXT=11276 bytes) (Status: | ||
217 | PROPOSED STANDARD) | ||
218 | |||
219 | 3278 Use of Elliptic Curve Cryptography (ECC) Algorithms in | ||
220 | Cryptographic Message Syntax (CMS). S. Blake-Wilson, D. Brown, P. | ||
221 | Lambert. April 2002. (Format: TXT=33779 bytes) (Status: | ||
222 | INFORMATIONAL) | ||
223 | |||
224 | 3281 An Internet Attribute Certificate Profile for Authorization. S. | ||
225 | Farrell, R. Housley. April 2002. (Format: TXT=90580 bytes) (Status: | ||
226 | PROPOSED STANDARD) | ||
227 | |||
228 | 3369 Cryptographic Message Syntax (CMS). R. Housley. August 2002. | ||
229 | (Format: TXT=113975 bytes) (Obsoletes RFC2630, RFC3211) (Status: | ||
230 | PROPOSED STANDARD) | ||
231 | |||
232 | 3370 Cryptographic Message Syntax (CMS) Algorithms. R. Housley. August | ||
233 | 2002. (Format: TXT=51001 bytes) (Obsoletes RFC2630, RFC3211) (Status: | ||
234 | PROPOSED STANDARD) | ||
235 | |||
236 | 3377 Lightweight Directory Access Protocol (v3): Technical | ||
237 | Specification. J. Hodges, R. Morgan. September 2002. (Format: | ||
238 | TXT=9981 bytes) (Updates RFC2251, RFC2252, RFC2253, RFC2254, RFC2255, | ||
239 | RFC2256, RFC2829, RFC2830) (Status: PROPOSED STANDARD) | ||
240 | |||
241 | 3394 Advanced Encryption Standard (AES) Key Wrap Algorithm. J. Schaad, | ||
242 | R. Housley. September 2002. (Format: TXT=73072 bytes) (Status: | ||
243 | INFORMATIONAL) | ||
244 | |||
245 | 3436 Transport Layer Security over Stream Control Transmission | ||
246 | Protocol. A. Jungmaier, E. Rescorla, M. Tuexen. December 2002. | ||
247 | (Format: TXT=16333 bytes) (Status: PROPOSED STANDARD) | ||
248 | |||
118 | "Securing FTP with TLS", 01/27/2000, <draft-murray-auth-ftp-ssl-05.txt> | 249 | "Securing FTP with TLS", 01/27/2000, <draft-murray-auth-ftp-ssl-05.txt> |
119 | 250 | ||
120 | 251 | ||
@@ -124,7 +255,3 @@ To be implemented: | |||
124 | These are documents that describe things that are planed to be | 255 | These are documents that describe things that are planed to be |
125 | implemented in the hopefully short future. | 256 | implemented in the hopefully short future. |
126 | 257 | ||
127 | 2712 Addition of Kerberos Cipher Suites to Transport Layer Security | ||
128 | (TLS). A. Medvinsky, M. Hur. October 1999. (Format: TXT=13763 bytes) | ||
129 | (Status: PROPOSED STANDARD) | ||
130 | |||
diff --git a/src/lib/libssl/s23_clnt.c b/src/lib/libssl/s23_clnt.c index 019e9aecee..64ee4269ec 100644 --- a/src/lib/libssl/s23_clnt.c +++ b/src/lib/libssl/s23_clnt.c | |||
@@ -87,18 +87,25 @@ SSL_METHOD *SSLv23_client_method(void) | |||
87 | 87 | ||
88 | if (init) | 88 | if (init) |
89 | { | 89 | { |
90 | memcpy((char *)&SSLv23_client_data, | 90 | CRYPTO_w_lock(CRYPTO_LOCK_SSL_METHOD); |
91 | (char *)sslv23_base_method(),sizeof(SSL_METHOD)); | 91 | |
92 | SSLv23_client_data.ssl_connect=ssl23_connect; | 92 | if (init) |
93 | SSLv23_client_data.get_ssl_method=ssl23_get_client_method; | 93 | { |
94 | init=0; | 94 | memcpy((char *)&SSLv23_client_data, |
95 | (char *)sslv23_base_method(),sizeof(SSL_METHOD)); | ||
96 | SSLv23_client_data.ssl_connect=ssl23_connect; | ||
97 | SSLv23_client_data.get_ssl_method=ssl23_get_client_method; | ||
98 | init=0; | ||
99 | } | ||
100 | |||
101 | CRYPTO_w_unlock(CRYPTO_LOCK_SSL_METHOD); | ||
95 | } | 102 | } |
96 | return(&SSLv23_client_data); | 103 | return(&SSLv23_client_data); |
97 | } | 104 | } |
98 | 105 | ||
99 | int ssl23_connect(SSL *s) | 106 | int ssl23_connect(SSL *s) |
100 | { | 107 | { |
101 | BUF_MEM *buf; | 108 | BUF_MEM *buf=NULL; |
102 | unsigned long Time=time(NULL); | 109 | unsigned long Time=time(NULL); |
103 | void (*cb)(const SSL *ssl,int type,int val)=NULL; | 110 | void (*cb)(const SSL *ssl,int type,int val)=NULL; |
104 | int ret= -1; | 111 | int ret= -1; |
@@ -152,6 +159,7 @@ int ssl23_connect(SSL *s) | |||
152 | goto end; | 159 | goto end; |
153 | } | 160 | } |
154 | s->init_buf=buf; | 161 | s->init_buf=buf; |
162 | buf=NULL; | ||
155 | } | 163 | } |
156 | 164 | ||
157 | if (!ssl3_setup_buffers(s)) { ret= -1; goto end; } | 165 | if (!ssl3_setup_buffers(s)) { ret= -1; goto end; } |
@@ -200,6 +208,8 @@ int ssl23_connect(SSL *s) | |||
200 | } | 208 | } |
201 | end: | 209 | end: |
202 | s->in_handshake--; | 210 | s->in_handshake--; |
211 | if (buf != NULL) | ||
212 | BUF_MEM_free(buf); | ||
203 | if (cb != NULL) | 213 | if (cb != NULL) |
204 | cb(s,SSL_CB_CONNECT_EXIT,ret); | 214 | cb(s,SSL_CB_CONNECT_EXIT,ret); |
205 | return(ret); | 215 | return(ret); |
@@ -363,7 +373,7 @@ static int ssl23_get_server_hello(SSL *s) | |||
363 | 373 | ||
364 | if (s->s3 != NULL) ssl3_free(s); | 374 | if (s->s3 != NULL) ssl3_free(s); |
365 | 375 | ||
366 | if (!BUF_MEM_grow(s->init_buf, | 376 | if (!BUF_MEM_grow_clean(s->init_buf, |
367 | SSL2_MAX_RECORD_LENGTH_3_BYTE_HEADER)) | 377 | SSL2_MAX_RECORD_LENGTH_3_BYTE_HEADER)) |
368 | { | 378 | { |
369 | SSLerr(SSL_F_SSL23_GET_SERVER_HELLO,ERR_R_BUF_LIB); | 379 | SSLerr(SSL_F_SSL23_GET_SERVER_HELLO,ERR_R_BUF_LIB); |
diff --git a/src/lib/libssl/s23_srvr.c b/src/lib/libssl/s23_srvr.c index 8743b61cbb..c5404ca0bc 100644 --- a/src/lib/libssl/s23_srvr.c +++ b/src/lib/libssl/s23_srvr.c | |||
@@ -139,11 +139,18 @@ SSL_METHOD *SSLv23_server_method(void) | |||
139 | 139 | ||
140 | if (init) | 140 | if (init) |
141 | { | 141 | { |
142 | memcpy((char *)&SSLv23_server_data, | 142 | CRYPTO_w_lock(CRYPTO_LOCK_SSL_METHOD); |
143 | (char *)sslv23_base_method(),sizeof(SSL_METHOD)); | 143 | |
144 | SSLv23_server_data.ssl_accept=ssl23_accept; | 144 | if (init) |
145 | SSLv23_server_data.get_ssl_method=ssl23_get_server_method; | 145 | { |
146 | init=0; | 146 | memcpy((char *)&SSLv23_server_data, |
147 | (char *)sslv23_base_method(),sizeof(SSL_METHOD)); | ||
148 | SSLv23_server_data.ssl_accept=ssl23_accept; | ||
149 | SSLv23_server_data.get_ssl_method=ssl23_get_server_method; | ||
150 | init=0; | ||
151 | } | ||
152 | |||
153 | CRYPTO_w_unlock(CRYPTO_LOCK_SSL_METHOD); | ||
147 | } | 154 | } |
148 | return(&SSLv23_server_data); | 155 | return(&SSLv23_server_data); |
149 | } | 156 | } |
@@ -505,7 +512,7 @@ int ssl23_get_client_hello(SSL *s) | |||
505 | 512 | ||
506 | if (s->s3 != NULL) ssl3_free(s); | 513 | if (s->s3 != NULL) ssl3_free(s); |
507 | 514 | ||
508 | if (!BUF_MEM_grow(s->init_buf, | 515 | if (!BUF_MEM_grow_clean(s->init_buf, |
509 | SSL2_MAX_RECORD_LENGTH_3_BYTE_HEADER)) | 516 | SSL2_MAX_RECORD_LENGTH_3_BYTE_HEADER)) |
510 | { | 517 | { |
511 | goto err; | 518 | goto err; |
diff --git a/src/lib/libssl/s3_both.c b/src/lib/libssl/s3_both.c index 8864366f59..64d317b7ac 100644 --- a/src/lib/libssl/s3_both.c +++ b/src/lib/libssl/s3_both.c | |||
@@ -268,16 +268,23 @@ unsigned long ssl3_output_cert_chain(SSL *s, X509 *x) | |||
268 | X509_STORE_CTX xs_ctx; | 268 | X509_STORE_CTX xs_ctx; |
269 | X509_OBJECT obj; | 269 | X509_OBJECT obj; |
270 | 270 | ||
271 | int no_chain; | ||
272 | |||
273 | if ((s->mode & SSL_MODE_NO_AUTO_CHAIN) || s->ctx->extra_certs) | ||
274 | no_chain = 1; | ||
275 | else | ||
276 | no_chain = 0; | ||
277 | |||
271 | /* TLSv1 sends a chain with nothing in it, instead of an alert */ | 278 | /* TLSv1 sends a chain with nothing in it, instead of an alert */ |
272 | buf=s->init_buf; | 279 | buf=s->init_buf; |
273 | if (!BUF_MEM_grow(buf,(int)(10))) | 280 | if (!BUF_MEM_grow_clean(buf,10)) |
274 | { | 281 | { |
275 | SSLerr(SSL_F_SSL3_OUTPUT_CERT_CHAIN,ERR_R_BUF_LIB); | 282 | SSLerr(SSL_F_SSL3_OUTPUT_CERT_CHAIN,ERR_R_BUF_LIB); |
276 | return(0); | 283 | return(0); |
277 | } | 284 | } |
278 | if (x != NULL) | 285 | if (x != NULL) |
279 | { | 286 | { |
280 | if(!X509_STORE_CTX_init(&xs_ctx,s->ctx->cert_store,NULL,NULL)) | 287 | if(!no_chain && !X509_STORE_CTX_init(&xs_ctx,s->ctx->cert_store,NULL,NULL)) |
281 | { | 288 | { |
282 | SSLerr(SSL_F_SSL3_OUTPUT_CERT_CHAIN,ERR_R_X509_LIB); | 289 | SSLerr(SSL_F_SSL3_OUTPUT_CERT_CHAIN,ERR_R_X509_LIB); |
283 | return(0); | 290 | return(0); |
@@ -286,7 +293,7 @@ unsigned long ssl3_output_cert_chain(SSL *s, X509 *x) | |||
286 | for (;;) | 293 | for (;;) |
287 | { | 294 | { |
288 | n=i2d_X509(x,NULL); | 295 | n=i2d_X509(x,NULL); |
289 | if (!BUF_MEM_grow(buf,(int)(n+l+3))) | 296 | if (!BUF_MEM_grow_clean(buf,(int)(n+l+3))) |
290 | { | 297 | { |
291 | SSLerr(SSL_F_SSL3_OUTPUT_CERT_CHAIN,ERR_R_BUF_LIB); | 298 | SSLerr(SSL_F_SSL3_OUTPUT_CERT_CHAIN,ERR_R_BUF_LIB); |
292 | return(0); | 299 | return(0); |
@@ -295,6 +302,10 @@ unsigned long ssl3_output_cert_chain(SSL *s, X509 *x) | |||
295 | l2n3(n,p); | 302 | l2n3(n,p); |
296 | i2d_X509(x,&p); | 303 | i2d_X509(x,&p); |
297 | l+=n+3; | 304 | l+=n+3; |
305 | |||
306 | if (no_chain) | ||
307 | break; | ||
308 | |||
298 | if (X509_NAME_cmp(X509_get_subject_name(x), | 309 | if (X509_NAME_cmp(X509_get_subject_name(x), |
299 | X509_get_issuer_name(x)) == 0) break; | 310 | X509_get_issuer_name(x)) == 0) break; |
300 | 311 | ||
@@ -306,8 +317,8 @@ unsigned long ssl3_output_cert_chain(SSL *s, X509 *x) | |||
306 | * ref count */ | 317 | * ref count */ |
307 | X509_free(x); | 318 | X509_free(x); |
308 | } | 319 | } |
309 | 320 | if (!no_chain) | |
310 | X509_STORE_CTX_cleanup(&xs_ctx); | 321 | X509_STORE_CTX_cleanup(&xs_ctx); |
311 | } | 322 | } |
312 | 323 | ||
313 | /* Thawte special :-) */ | 324 | /* Thawte special :-) */ |
@@ -316,7 +327,7 @@ unsigned long ssl3_output_cert_chain(SSL *s, X509 *x) | |||
316 | { | 327 | { |
317 | x=sk_X509_value(s->ctx->extra_certs,i); | 328 | x=sk_X509_value(s->ctx->extra_certs,i); |
318 | n=i2d_X509(x,NULL); | 329 | n=i2d_X509(x,NULL); |
319 | if (!BUF_MEM_grow(buf,(int)(n+l+3))) | 330 | if (!BUF_MEM_grow_clean(buf,(int)(n+l+3))) |
320 | { | 331 | { |
321 | SSLerr(SSL_F_SSL3_OUTPUT_CERT_CHAIN,ERR_R_BUF_LIB); | 332 | SSLerr(SSL_F_SSL3_OUTPUT_CERT_CHAIN,ERR_R_BUF_LIB); |
322 | return(0); | 333 | return(0); |
@@ -439,7 +450,7 @@ long ssl3_get_message(SSL *s, int st1, int stn, int mt, long max, int *ok) | |||
439 | SSLerr(SSL_F_SSL3_GET_MESSAGE,SSL_R_EXCESSIVE_MESSAGE_SIZE); | 450 | SSLerr(SSL_F_SSL3_GET_MESSAGE,SSL_R_EXCESSIVE_MESSAGE_SIZE); |
440 | goto f_err; | 451 | goto f_err; |
441 | } | 452 | } |
442 | if (l && !BUF_MEM_grow(s->init_buf,(int)l+4)) | 453 | if (l && !BUF_MEM_grow_clean(s->init_buf,(int)l+4)) |
443 | { | 454 | { |
444 | SSLerr(SSL_F_SSL3_GET_MESSAGE,ERR_R_BUF_LIB); | 455 | SSLerr(SSL_F_SSL3_GET_MESSAGE,ERR_R_BUF_LIB); |
445 | goto err; | 456 | goto err; |
diff --git a/src/lib/libssl/s3_clnt.c b/src/lib/libssl/s3_clnt.c index 2b58482484..fae8eadada 100644 --- a/src/lib/libssl/s3_clnt.c +++ b/src/lib/libssl/s3_clnt.c | |||
@@ -146,18 +146,25 @@ SSL_METHOD *SSLv3_client_method(void) | |||
146 | 146 | ||
147 | if (init) | 147 | if (init) |
148 | { | 148 | { |
149 | init=0; | 149 | CRYPTO_w_lock(CRYPTO_LOCK_SSL_METHOD); |
150 | memcpy((char *)&SSLv3_client_data,(char *)sslv3_base_method(), | 150 | |
151 | sizeof(SSL_METHOD)); | 151 | if (init) |
152 | SSLv3_client_data.ssl_connect=ssl3_connect; | 152 | { |
153 | SSLv3_client_data.get_ssl_method=ssl3_get_client_method; | 153 | memcpy((char *)&SSLv3_client_data,(char *)sslv3_base_method(), |
154 | sizeof(SSL_METHOD)); | ||
155 | SSLv3_client_data.ssl_connect=ssl3_connect; | ||
156 | SSLv3_client_data.get_ssl_method=ssl3_get_client_method; | ||
157 | init=0; | ||
158 | } | ||
159 | |||
160 | CRYPTO_w_unlock(CRYPTO_LOCK_SSL_METHOD); | ||
154 | } | 161 | } |
155 | return(&SSLv3_client_data); | 162 | return(&SSLv3_client_data); |
156 | } | 163 | } |
157 | 164 | ||
158 | int ssl3_connect(SSL *s) | 165 | int ssl3_connect(SSL *s) |
159 | { | 166 | { |
160 | BUF_MEM *buf; | 167 | BUF_MEM *buf=NULL; |
161 | unsigned long Time=time(NULL),l; | 168 | unsigned long Time=time(NULL),l; |
162 | long num1; | 169 | long num1; |
163 | void (*cb)(const SSL *ssl,int type,int val)=NULL; | 170 | void (*cb)(const SSL *ssl,int type,int val)=NULL; |
@@ -218,6 +225,7 @@ int ssl3_connect(SSL *s) | |||
218 | goto end; | 225 | goto end; |
219 | } | 226 | } |
220 | s->init_buf=buf; | 227 | s->init_buf=buf; |
228 | buf=NULL; | ||
221 | } | 229 | } |
222 | 230 | ||
223 | if (!ssl3_setup_buffers(s)) { ret= -1; goto end; } | 231 | if (!ssl3_setup_buffers(s)) { ret= -1; goto end; } |
@@ -496,6 +504,8 @@ int ssl3_connect(SSL *s) | |||
496 | } | 504 | } |
497 | end: | 505 | end: |
498 | s->in_handshake--; | 506 | s->in_handshake--; |
507 | if (buf != NULL) | ||
508 | BUF_MEM_free(buf); | ||
499 | if (cb != NULL) | 509 | if (cb != NULL) |
500 | cb(s,SSL_CB_CONNECT_EXIT,ret); | 510 | cb(s,SSL_CB_CONNECT_EXIT,ret); |
501 | return(ret); | 511 | return(ret); |
@@ -632,30 +642,20 @@ static int ssl3_get_server_hello(SSL *s) | |||
632 | /* get the session-id */ | 642 | /* get the session-id */ |
633 | j= *(p++); | 643 | j= *(p++); |
634 | 644 | ||
635 | if(j > sizeof s->session->session_id) | 645 | if ((j > sizeof s->session->session_id) || (j > SSL3_SESSION_ID_SIZE)) |
636 | { | ||
637 | al=SSL_AD_ILLEGAL_PARAMETER; | ||
638 | SSLerr(SSL_F_SSL3_GET_SERVER_HELLO, | ||
639 | SSL_R_SSL3_SESSION_ID_TOO_LONG); | ||
640 | goto f_err; | ||
641 | } | ||
642 | |||
643 | if ((j != 0) && (j != SSL3_SESSION_ID_SIZE)) | ||
644 | { | 646 | { |
645 | /* SSLref returns 16 :-( */ | 647 | al=SSL_AD_ILLEGAL_PARAMETER; |
646 | if (j < SSL2_SSL_SESSION_ID_LENGTH) | 648 | SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_SSL3_SESSION_ID_TOO_LONG); |
647 | { | 649 | goto f_err; |
648 | al=SSL_AD_ILLEGAL_PARAMETER; | ||
649 | SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_SSL3_SESSION_ID_TOO_SHORT); | ||
650 | goto f_err; | ||
651 | } | ||
652 | } | 650 | } |
651 | |||
653 | if (j != 0 && j == s->session->session_id_length | 652 | if (j != 0 && j == s->session->session_id_length |
654 | && memcmp(p,s->session->session_id,j) == 0) | 653 | && memcmp(p,s->session->session_id,j) == 0) |
655 | { | 654 | { |
656 | if(s->sid_ctx_length != s->session->sid_ctx_length | 655 | if(s->sid_ctx_length != s->session->sid_ctx_length |
657 | || memcmp(s->session->sid_ctx,s->sid_ctx,s->sid_ctx_length)) | 656 | || memcmp(s->session->sid_ctx,s->sid_ctx,s->sid_ctx_length)) |
658 | { | 657 | { |
658 | /* actually a client application bug */ | ||
659 | al=SSL_AD_ILLEGAL_PARAMETER; | 659 | al=SSL_AD_ILLEGAL_PARAMETER; |
660 | SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_ATTEMPT_TO_REUSE_SESSION_IN_DIFFERENT_CONTEXT); | 660 | SSLerr(SSL_F_SSL3_GET_SERVER_HELLO,SSL_R_ATTEMPT_TO_REUSE_SESSION_IN_DIFFERENT_CONTEXT); |
661 | goto f_err; | 661 | goto f_err; |
@@ -699,7 +699,12 @@ static int ssl3_get_server_hello(SSL *s) | |||
699 | goto f_err; | 699 | goto f_err; |
700 | } | 700 | } |
701 | 701 | ||
702 | if (s->hit && (s->session->cipher != c)) | 702 | /* Depending on the session caching (internal/external), the cipher |
703 | and/or cipher_id values may not be set. Make sure that | ||
704 | cipher_id is set and use it for comparison. */ | ||
705 | if (s->session->cipher) | ||
706 | s->session->cipher_id = s->session->cipher->id; | ||
707 | if (s->hit && (s->session->cipher_id != c->id)) | ||
703 | { | 708 | { |
704 | if (!(s->options & | 709 | if (!(s->options & |
705 | SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG)) | 710 | SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG)) |
@@ -1457,16 +1462,16 @@ static int ssl3_send_client_key_exchange(SSL *s) | |||
1457 | 1462 | ||
1458 | tmp_buf[0]=s->client_version>>8; | 1463 | tmp_buf[0]=s->client_version>>8; |
1459 | tmp_buf[1]=s->client_version&0xff; | 1464 | tmp_buf[1]=s->client_version&0xff; |
1460 | if (RAND_bytes(&(tmp_buf[2]),SSL_MAX_MASTER_KEY_LENGTH-2) <= 0) | 1465 | if (RAND_bytes(&(tmp_buf[2]),sizeof tmp_buf-2) <= 0) |
1461 | goto err; | 1466 | goto err; |
1462 | 1467 | ||
1463 | s->session->master_key_length=SSL_MAX_MASTER_KEY_LENGTH; | 1468 | s->session->master_key_length=sizeof tmp_buf; |
1464 | 1469 | ||
1465 | q=p; | 1470 | q=p; |
1466 | /* Fix buf for TLS and beyond */ | 1471 | /* Fix buf for TLS and beyond */ |
1467 | if (s->version > SSL3_VERSION) | 1472 | if (s->version > SSL3_VERSION) |
1468 | p+=2; | 1473 | p+=2; |
1469 | n=RSA_public_encrypt(SSL_MAX_MASTER_KEY_LENGTH, | 1474 | n=RSA_public_encrypt(sizeof tmp_buf, |
1470 | tmp_buf,p,rsa,RSA_PKCS1_PADDING); | 1475 | tmp_buf,p,rsa,RSA_PKCS1_PADDING); |
1471 | #ifdef PKCS1_CHECK | 1476 | #ifdef PKCS1_CHECK |
1472 | if (s->options & SSL_OP_PKCS1_CHECK_1) p[1]++; | 1477 | if (s->options & SSL_OP_PKCS1_CHECK_1) p[1]++; |
@@ -1488,8 +1493,8 @@ static int ssl3_send_client_key_exchange(SSL *s) | |||
1488 | s->session->master_key_length= | 1493 | s->session->master_key_length= |
1489 | s->method->ssl3_enc->generate_master_secret(s, | 1494 | s->method->ssl3_enc->generate_master_secret(s, |
1490 | s->session->master_key, | 1495 | s->session->master_key, |
1491 | tmp_buf,SSL_MAX_MASTER_KEY_LENGTH); | 1496 | tmp_buf,sizeof tmp_buf); |
1492 | memset(tmp_buf,0,SSL_MAX_MASTER_KEY_LENGTH); | 1497 | OPENSSL_cleanse(tmp_buf,sizeof tmp_buf); |
1493 | } | 1498 | } |
1494 | #endif | 1499 | #endif |
1495 | #ifndef OPENSSL_NO_KRB5 | 1500 | #ifndef OPENSSL_NO_KRB5 |
@@ -1585,7 +1590,7 @@ static int ssl3_send_client_key_exchange(SSL *s) | |||
1585 | n+=2; | 1590 | n+=2; |
1586 | } | 1591 | } |
1587 | 1592 | ||
1588 | if (RAND_bytes(tmp_buf,SSL_MAX_MASTER_KEY_LENGTH) <= 0) | 1593 | if (RAND_bytes(tmp_buf,sizeof tmp_buf) <= 0) |
1589 | goto err; | 1594 | goto err; |
1590 | 1595 | ||
1591 | /* 20010420 VRS. Tried it this way; failed. | 1596 | /* 20010420 VRS. Tried it this way; failed. |
@@ -1595,11 +1600,11 @@ static int ssl3_send_client_key_exchange(SSL *s) | |||
1595 | ** EVP_EncryptInit_ex(&ciph_ctx,NULL, key,iv); | 1600 | ** EVP_EncryptInit_ex(&ciph_ctx,NULL, key,iv); |
1596 | */ | 1601 | */ |
1597 | 1602 | ||
1598 | memset(iv, 0, EVP_MAX_IV_LENGTH); /* per RFC 1510 */ | 1603 | memset(iv, 0, sizeof iv); /* per RFC 1510 */ |
1599 | EVP_EncryptInit_ex(&ciph_ctx,enc, NULL, | 1604 | EVP_EncryptInit_ex(&ciph_ctx,enc, NULL, |
1600 | kssl_ctx->key,iv); | 1605 | kssl_ctx->key,iv); |
1601 | EVP_EncryptUpdate(&ciph_ctx,epms,&outl,tmp_buf, | 1606 | EVP_EncryptUpdate(&ciph_ctx,epms,&outl,tmp_buf, |
1602 | SSL_MAX_MASTER_KEY_LENGTH); | 1607 | sizeof tmp_buf); |
1603 | EVP_EncryptFinal_ex(&ciph_ctx,&(epms[outl]),&padl); | 1608 | EVP_EncryptFinal_ex(&ciph_ctx,&(epms[outl]),&padl); |
1604 | outl += padl; | 1609 | outl += padl; |
1605 | if (outl > sizeof epms) | 1610 | if (outl > sizeof epms) |
@@ -1618,10 +1623,10 @@ static int ssl3_send_client_key_exchange(SSL *s) | |||
1618 | s->session->master_key_length= | 1623 | s->session->master_key_length= |
1619 | s->method->ssl3_enc->generate_master_secret(s, | 1624 | s->method->ssl3_enc->generate_master_secret(s, |
1620 | s->session->master_key, | 1625 | s->session->master_key, |
1621 | tmp_buf, SSL_MAX_MASTER_KEY_LENGTH); | 1626 | tmp_buf, sizeof tmp_buf); |
1622 | 1627 | ||
1623 | memset(tmp_buf, 0, SSL_MAX_MASTER_KEY_LENGTH); | 1628 | OPENSSL_cleanse(tmp_buf, sizeof tmp_buf); |
1624 | memset(epms, 0, outl); | 1629 | OPENSSL_cleanse(epms, outl); |
1625 | } | 1630 | } |
1626 | #endif | 1631 | #endif |
1627 | #ifndef OPENSSL_NO_DH | 1632 | #ifndef OPENSSL_NO_DH |
diff --git a/src/lib/libssl/s3_lib.c b/src/lib/libssl/s3_lib.c index 14b2f13ae2..896b12fc4f 100644 --- a/src/lib/libssl/s3_lib.c +++ b/src/lib/libssl/s3_lib.c | |||
@@ -512,6 +512,7 @@ OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers[]={ | |||
512 | SSL_ALL_STRENGTHS, | 512 | SSL_ALL_STRENGTHS, |
513 | }, | 513 | }, |
514 | 514 | ||
515 | #if 0 | ||
515 | /* Cipher 1E */ | 516 | /* Cipher 1E */ |
516 | { | 517 | { |
517 | 0, | 518 | 0, |
@@ -525,55 +526,70 @@ OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers[]={ | |||
525 | SSL_ALL_CIPHERS, | 526 | SSL_ALL_CIPHERS, |
526 | SSL_ALL_STRENGTHS, | 527 | SSL_ALL_STRENGTHS, |
527 | }, | 528 | }, |
529 | #endif | ||
528 | 530 | ||
529 | #ifndef OPENSSL_NO_KRB5 | 531 | #ifndef OPENSSL_NO_KRB5 |
530 | /* The Kerberos ciphers | 532 | /* The Kerberos ciphers |
531 | ** 20000107 VRS: And the first shall be last, | 533 | ** 20000107 VRS: And the first shall be last, |
532 | ** in hopes of avoiding the lynx ssl renegotiation problem. | 534 | ** in hopes of avoiding the lynx ssl renegotiation problem. |
533 | */ | 535 | */ |
534 | /* Cipher 21 VRS */ | 536 | /* Cipher 1E VRS */ |
535 | { | 537 | { |
536 | 1, | 538 | 1, |
537 | SSL3_TXT_KRB5_DES_40_CBC_SHA, | 539 | SSL3_TXT_KRB5_DES_64_CBC_SHA, |
538 | SSL3_CK_KRB5_DES_40_CBC_SHA, | 540 | SSL3_CK_KRB5_DES_64_CBC_SHA, |
539 | SSL_kKRB5|SSL_aKRB5| SSL_DES|SSL_SHA1 |SSL_SSLV3, | 541 | SSL_kKRB5|SSL_aKRB5| SSL_DES|SSL_SHA1 |SSL_SSLV3, |
540 | SSL_EXPORT|SSL_EXP40, | 542 | SSL_NOT_EXP|SSL_LOW, |
541 | 0, | 543 | 0, |
542 | 40, | 544 | 56, |
543 | 56, | 545 | 56, |
544 | SSL_ALL_CIPHERS, | 546 | SSL_ALL_CIPHERS, |
545 | SSL_ALL_STRENGTHS, | 547 | SSL_ALL_STRENGTHS, |
546 | }, | 548 | }, |
547 | 549 | ||
548 | /* Cipher 22 VRS */ | 550 | /* Cipher 1F VRS */ |
549 | { | 551 | { |
550 | 1, | 552 | 1, |
551 | SSL3_TXT_KRB5_DES_40_CBC_MD5, | 553 | SSL3_TXT_KRB5_DES_192_CBC3_SHA, |
552 | SSL3_CK_KRB5_DES_40_CBC_MD5, | 554 | SSL3_CK_KRB5_DES_192_CBC3_SHA, |
553 | SSL_kKRB5|SSL_aKRB5| SSL_DES|SSL_MD5 |SSL_SSLV3, | 555 | SSL_kKRB5|SSL_aKRB5| SSL_3DES|SSL_SHA1 |SSL_SSLV3, |
554 | SSL_EXPORT|SSL_EXP40, | 556 | SSL_NOT_EXP|SSL_HIGH, |
555 | 0, | 557 | 0, |
556 | 40, | 558 | 112, |
557 | 56, | 559 | 168, |
558 | SSL_ALL_CIPHERS, | 560 | SSL_ALL_CIPHERS, |
559 | SSL_ALL_STRENGTHS, | 561 | SSL_ALL_STRENGTHS, |
560 | }, | 562 | }, |
561 | 563 | ||
562 | /* Cipher 23 VRS */ | 564 | /* Cipher 20 VRS */ |
563 | { | 565 | { |
564 | 1, | 566 | 1, |
565 | SSL3_TXT_KRB5_DES_64_CBC_SHA, | 567 | SSL3_TXT_KRB5_RC4_128_SHA, |
566 | SSL3_CK_KRB5_DES_64_CBC_SHA, | 568 | SSL3_CK_KRB5_RC4_128_SHA, |
567 | SSL_kKRB5|SSL_aKRB5| SSL_DES|SSL_SHA1 |SSL_SSLV3, | 569 | SSL_kKRB5|SSL_aKRB5| SSL_RC4|SSL_SHA1 |SSL_SSLV3, |
568 | SSL_NOT_EXP|SSL_LOW, | 570 | SSL_NOT_EXP|SSL_MEDIUM, |
569 | 0, | 571 | 0, |
570 | 56, | 572 | 128, |
571 | 56, | 573 | 128, |
572 | SSL_ALL_CIPHERS, | 574 | SSL_ALL_CIPHERS, |
573 | SSL_ALL_STRENGTHS, | 575 | SSL_ALL_STRENGTHS, |
574 | }, | 576 | }, |
575 | 577 | ||
576 | /* Cipher 24 VRS */ | 578 | /* Cipher 21 VRS */ |
579 | { | ||
580 | 1, | ||
581 | SSL3_TXT_KRB5_IDEA_128_CBC_SHA, | ||
582 | SSL3_CK_KRB5_IDEA_128_CBC_SHA, | ||
583 | SSL_kKRB5|SSL_aKRB5| SSL_IDEA|SSL_SHA1 |SSL_SSLV3, | ||
584 | SSL_NOT_EXP|SSL_MEDIUM, | ||
585 | 0, | ||
586 | 128, | ||
587 | 128, | ||
588 | SSL_ALL_CIPHERS, | ||
589 | SSL_ALL_STRENGTHS, | ||
590 | }, | ||
591 | |||
592 | /* Cipher 22 VRS */ | ||
577 | { | 593 | { |
578 | 1, | 594 | 1, |
579 | SSL3_TXT_KRB5_DES_64_CBC_MD5, | 595 | SSL3_TXT_KRB5_DES_64_CBC_MD5, |
@@ -587,12 +603,12 @@ OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers[]={ | |||
587 | SSL_ALL_STRENGTHS, | 603 | SSL_ALL_STRENGTHS, |
588 | }, | 604 | }, |
589 | 605 | ||
590 | /* Cipher 25 VRS */ | 606 | /* Cipher 23 VRS */ |
591 | { | 607 | { |
592 | 1, | 608 | 1, |
593 | SSL3_TXT_KRB5_DES_192_CBC3_SHA, | 609 | SSL3_TXT_KRB5_DES_192_CBC3_MD5, |
594 | SSL3_CK_KRB5_DES_192_CBC3_SHA, | 610 | SSL3_CK_KRB5_DES_192_CBC3_MD5, |
595 | SSL_kKRB5|SSL_aKRB5| SSL_3DES|SSL_SHA1 |SSL_SSLV3, | 611 | SSL_kKRB5|SSL_aKRB5| SSL_3DES|SSL_MD5 |SSL_SSLV3, |
596 | SSL_NOT_EXP|SSL_HIGH, | 612 | SSL_NOT_EXP|SSL_HIGH, |
597 | 0, | 613 | 0, |
598 | 112, | 614 | 112, |
@@ -601,16 +617,114 @@ OPENSSL_GLOBAL SSL_CIPHER ssl3_ciphers[]={ | |||
601 | SSL_ALL_STRENGTHS, | 617 | SSL_ALL_STRENGTHS, |
602 | }, | 618 | }, |
603 | 619 | ||
620 | /* Cipher 24 VRS */ | ||
621 | { | ||
622 | 1, | ||
623 | SSL3_TXT_KRB5_RC4_128_MD5, | ||
624 | SSL3_CK_KRB5_RC4_128_MD5, | ||
625 | SSL_kKRB5|SSL_aKRB5| SSL_RC4|SSL_MD5 |SSL_SSLV3, | ||
626 | SSL_NOT_EXP|SSL_MEDIUM, | ||
627 | 0, | ||
628 | 128, | ||
629 | 128, | ||
630 | SSL_ALL_CIPHERS, | ||
631 | SSL_ALL_STRENGTHS, | ||
632 | }, | ||
633 | |||
634 | /* Cipher 25 VRS */ | ||
635 | { | ||
636 | 1, | ||
637 | SSL3_TXT_KRB5_IDEA_128_CBC_MD5, | ||
638 | SSL3_CK_KRB5_IDEA_128_CBC_MD5, | ||
639 | SSL_kKRB5|SSL_aKRB5| SSL_IDEA|SSL_MD5 |SSL_SSLV3, | ||
640 | SSL_NOT_EXP|SSL_MEDIUM, | ||
641 | 0, | ||
642 | 128, | ||
643 | 128, | ||
644 | SSL_ALL_CIPHERS, | ||
645 | SSL_ALL_STRENGTHS, | ||
646 | }, | ||
647 | |||
604 | /* Cipher 26 VRS */ | 648 | /* Cipher 26 VRS */ |
605 | { | 649 | { |
606 | 1, | 650 | 1, |
607 | SSL3_TXT_KRB5_DES_192_CBC3_MD5, | 651 | SSL3_TXT_KRB5_DES_40_CBC_SHA, |
608 | SSL3_CK_KRB5_DES_192_CBC3_MD5, | 652 | SSL3_CK_KRB5_DES_40_CBC_SHA, |
609 | SSL_kKRB5|SSL_aKRB5| SSL_3DES|SSL_MD5 |SSL_SSLV3, | 653 | SSL_kKRB5|SSL_aKRB5| SSL_DES|SSL_SHA1 |SSL_SSLV3, |
610 | SSL_NOT_EXP|SSL_HIGH, | 654 | SSL_EXPORT|SSL_EXP40, |
611 | 0, | 655 | 0, |
612 | 112, | 656 | 40, |
613 | 168, | 657 | 56, |
658 | SSL_ALL_CIPHERS, | ||
659 | SSL_ALL_STRENGTHS, | ||
660 | }, | ||
661 | |||
662 | /* Cipher 27 VRS */ | ||
663 | { | ||
664 | 1, | ||
665 | SSL3_TXT_KRB5_RC2_40_CBC_SHA, | ||
666 | SSL3_CK_KRB5_RC2_40_CBC_SHA, | ||
667 | SSL_kKRB5|SSL_aKRB5| SSL_RC2|SSL_SHA1 |SSL_SSLV3, | ||
668 | SSL_EXPORT|SSL_EXP40, | ||
669 | 0, | ||
670 | 40, | ||
671 | 128, | ||
672 | SSL_ALL_CIPHERS, | ||
673 | SSL_ALL_STRENGTHS, | ||
674 | }, | ||
675 | |||
676 | /* Cipher 28 VRS */ | ||
677 | { | ||
678 | 1, | ||
679 | SSL3_TXT_KRB5_RC4_40_SHA, | ||
680 | SSL3_CK_KRB5_RC4_40_SHA, | ||
681 | SSL_kKRB5|SSL_aKRB5| SSL_RC4|SSL_SHA1 |SSL_SSLV3, | ||
682 | SSL_EXPORT|SSL_EXP40, | ||
683 | 0, | ||
684 | 128, | ||
685 | 128, | ||
686 | SSL_ALL_CIPHERS, | ||
687 | SSL_ALL_STRENGTHS, | ||
688 | }, | ||
689 | |||
690 | /* Cipher 29 VRS */ | ||
691 | { | ||
692 | 1, | ||
693 | SSL3_TXT_KRB5_DES_40_CBC_MD5, | ||
694 | SSL3_CK_KRB5_DES_40_CBC_MD5, | ||
695 | SSL_kKRB5|SSL_aKRB5| SSL_DES|SSL_MD5 |SSL_SSLV3, | ||
696 | SSL_EXPORT|SSL_EXP40, | ||
697 | 0, | ||
698 | 40, | ||
699 | 56, | ||
700 | SSL_ALL_CIPHERS, | ||
701 | SSL_ALL_STRENGTHS, | ||
702 | }, | ||
703 | |||
704 | /* Cipher 2A VRS */ | ||
705 | { | ||
706 | 1, | ||
707 | SSL3_TXT_KRB5_RC2_40_CBC_MD5, | ||
708 | SSL3_CK_KRB5_RC2_40_CBC_MD5, | ||
709 | SSL_kKRB5|SSL_aKRB5| SSL_RC2|SSL_MD5 |SSL_SSLV3, | ||
710 | SSL_EXPORT|SSL_EXP40, | ||
711 | 0, | ||
712 | 40, | ||
713 | 128, | ||
714 | SSL_ALL_CIPHERS, | ||
715 | SSL_ALL_STRENGTHS, | ||
716 | }, | ||
717 | |||
718 | /* Cipher 2B VRS */ | ||
719 | { | ||
720 | 1, | ||
721 | SSL3_TXT_KRB5_RC4_40_MD5, | ||
722 | SSL3_CK_KRB5_RC4_40_MD5, | ||
723 | SSL_kKRB5|SSL_aKRB5| SSL_RC4|SSL_MD5 |SSL_SSLV3, | ||
724 | SSL_EXPORT|SSL_EXP40, | ||
725 | 0, | ||
726 | 128, | ||
727 | 128, | ||
614 | SSL_ALL_CIPHERS, | 728 | SSL_ALL_CIPHERS, |
615 | SSL_ALL_STRENGTHS, | 729 | SSL_ALL_STRENGTHS, |
616 | }, | 730 | }, |
@@ -986,7 +1100,7 @@ void ssl3_free(SSL *s) | |||
986 | sk_X509_NAME_pop_free(s->s3->tmp.ca_names,X509_NAME_free); | 1100 | sk_X509_NAME_pop_free(s->s3->tmp.ca_names,X509_NAME_free); |
987 | EVP_MD_CTX_cleanup(&s->s3->finish_dgst1); | 1101 | EVP_MD_CTX_cleanup(&s->s3->finish_dgst1); |
988 | EVP_MD_CTX_cleanup(&s->s3->finish_dgst2); | 1102 | EVP_MD_CTX_cleanup(&s->s3->finish_dgst2); |
989 | memset(s->s3,0,sizeof *s->s3); | 1103 | OPENSSL_cleanse(s->s3,sizeof *s->s3); |
990 | OPENSSL_free(s->s3); | 1104 | OPENSSL_free(s->s3); |
991 | s->s3=NULL; | 1105 | s->s3=NULL; |
992 | } | 1106 | } |
@@ -1341,16 +1455,19 @@ SSL_CIPHER *ssl3_get_cipher_by_char(const unsigned char *p) | |||
1341 | { | 1455 | { |
1342 | CRYPTO_w_lock(CRYPTO_LOCK_SSL); | 1456 | CRYPTO_w_lock(CRYPTO_LOCK_SSL); |
1343 | 1457 | ||
1344 | for (i=0; i<SSL3_NUM_CIPHERS; i++) | 1458 | if (init) |
1345 | sorted[i]= &(ssl3_ciphers[i]); | 1459 | { |
1460 | for (i=0; i<SSL3_NUM_CIPHERS; i++) | ||
1461 | sorted[i]= &(ssl3_ciphers[i]); | ||
1346 | 1462 | ||
1347 | qsort( (char *)sorted, | 1463 | qsort(sorted, |
1348 | SSL3_NUM_CIPHERS,sizeof(SSL_CIPHER *), | 1464 | SSL3_NUM_CIPHERS,sizeof(SSL_CIPHER *), |
1349 | FP_ICC ssl_cipher_ptr_id_cmp); | 1465 | FP_ICC ssl_cipher_ptr_id_cmp); |
1350 | 1466 | ||
1467 | init=0; | ||
1468 | } | ||
1469 | |||
1351 | CRYPTO_w_unlock(CRYPTO_LOCK_SSL); | 1470 | CRYPTO_w_unlock(CRYPTO_LOCK_SSL); |
1352 | |||
1353 | init=0; | ||
1354 | } | 1471 | } |
1355 | 1472 | ||
1356 | id=0x03000000L|((unsigned long)p[0]<<8L)|(unsigned long)p[1]; | 1473 | id=0x03000000L|((unsigned long)p[0]<<8L)|(unsigned long)p[1]; |
diff --git a/src/lib/libssl/s3_pkt.c b/src/lib/libssl/s3_pkt.c index 6ccea9aee5..3f88429e79 100644 --- a/src/lib/libssl/s3_pkt.c +++ b/src/lib/libssl/s3_pkt.c | |||
@@ -238,6 +238,8 @@ static int ssl3_get_record(SSL *s) | |||
238 | unsigned int mac_size; | 238 | unsigned int mac_size; |
239 | int clear=0; | 239 | int clear=0; |
240 | size_t extra; | 240 | size_t extra; |
241 | int decryption_failed_or_bad_record_mac = 0; | ||
242 | unsigned char *mac = NULL; | ||
241 | 243 | ||
242 | rr= &(s->s3->rrec); | 244 | rr= &(s->s3->rrec); |
243 | sess=s->session; | 245 | sess=s->session; |
@@ -353,8 +355,11 @@ again: | |||
353 | /* SSLerr() and ssl3_send_alert() have been called */ | 355 | /* SSLerr() and ssl3_send_alert() have been called */ |
354 | goto err; | 356 | goto err; |
355 | 357 | ||
356 | /* otherwise enc_err == -1 */ | 358 | /* Otherwise enc_err == -1, which indicates bad padding |
357 | goto decryption_failed_or_bad_record_mac; | 359 | * (rec->length has not been changed in this case). |
360 | * To minimize information leaked via timing, we will perform | ||
361 | * the MAC computation anyway. */ | ||
362 | decryption_failed_or_bad_record_mac = 1; | ||
358 | } | 363 | } |
359 | 364 | ||
360 | #ifdef TLS_DEBUG | 365 | #ifdef TLS_DEBUG |
@@ -380,28 +385,46 @@ printf("\n"); | |||
380 | SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_PRE_MAC_LENGTH_TOO_LONG); | 385 | SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_PRE_MAC_LENGTH_TOO_LONG); |
381 | goto f_err; | 386 | goto f_err; |
382 | #else | 387 | #else |
383 | goto decryption_failed_or_bad_record_mac; | 388 | decryption_failed_or_bad_record_mac = 1; |
384 | #endif | 389 | #endif |
385 | } | 390 | } |
386 | /* check the MAC for rr->input (it's in mac_size bytes at the tail) */ | 391 | /* check the MAC for rr->input (it's in mac_size bytes at the tail) */ |
387 | if (rr->length < mac_size) | 392 | if (rr->length >= mac_size) |
388 | { | 393 | { |
394 | rr->length -= mac_size; | ||
395 | mac = &rr->data[rr->length]; | ||
396 | } | ||
397 | else | ||
398 | { | ||
399 | /* record (minus padding) is too short to contain a MAC */ | ||
389 | #if 0 /* OK only for stream ciphers */ | 400 | #if 0 /* OK only for stream ciphers */ |
390 | al=SSL_AD_DECODE_ERROR; | 401 | al=SSL_AD_DECODE_ERROR; |
391 | SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_LENGTH_TOO_SHORT); | 402 | SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_LENGTH_TOO_SHORT); |
392 | goto f_err; | 403 | goto f_err; |
393 | #else | 404 | #else |
394 | goto decryption_failed_or_bad_record_mac; | 405 | decryption_failed_or_bad_record_mac = 1; |
406 | rr->length = 0; | ||
395 | #endif | 407 | #endif |
396 | } | 408 | } |
397 | rr->length-=mac_size; | ||
398 | i=s->method->ssl3_enc->mac(s,md,0); | 409 | i=s->method->ssl3_enc->mac(s,md,0); |
399 | if (memcmp(md,&(rr->data[rr->length]),mac_size) != 0) | 410 | if (mac == NULL || memcmp(md, mac, mac_size) != 0) |
400 | { | 411 | { |
401 | goto decryption_failed_or_bad_record_mac; | 412 | decryption_failed_or_bad_record_mac = 1; |
402 | } | 413 | } |
403 | } | 414 | } |
404 | 415 | ||
416 | if (decryption_failed_or_bad_record_mac) | ||
417 | { | ||
418 | /* A separate 'decryption_failed' alert was introduced with TLS 1.0, | ||
419 | * SSL 3.0 only has 'bad_record_mac'. But unless a decryption | ||
420 | * failure is directly visible from the ciphertext anyway, | ||
421 | * we should not reveal which kind of error occured -- this | ||
422 | * might become visible to an attacker (e.g. via a logfile) */ | ||
423 | al=SSL_AD_BAD_RECORD_MAC; | ||
424 | SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_DECRYPTION_FAILED_OR_BAD_RECORD_MAC); | ||
425 | goto f_err; | ||
426 | } | ||
427 | |||
405 | /* r->length is now just compressed */ | 428 | /* r->length is now just compressed */ |
406 | if (s->expand != NULL) | 429 | if (s->expand != NULL) |
407 | { | 430 | { |
@@ -443,14 +466,6 @@ printf("\n"); | |||
443 | 466 | ||
444 | return(1); | 467 | return(1); |
445 | 468 | ||
446 | decryption_failed_or_bad_record_mac: | ||
447 | /* Separate 'decryption_failed' alert was introduced with TLS 1.0, | ||
448 | * SSL 3.0 only has 'bad_record_mac'. But unless a decryption | ||
449 | * failure is directly visible from the ciphertext anyway, | ||
450 | * we should not reveal which kind of error occured -- this | ||
451 | * might become visible to an attacker (e.g. via logfile) */ | ||
452 | al=SSL_AD_BAD_RECORD_MAC; | ||
453 | SSLerr(SSL_F_SSL3_GET_RECORD,SSL_R_DECRYPTION_FAILED_OR_BAD_RECORD_MAC); | ||
454 | f_err: | 469 | f_err: |
455 | ssl3_send_alert(s,SSL3_AL_FATAL,al); | 470 | ssl3_send_alert(s,SSL3_AL_FATAL,al); |
456 | err: | 471 | err: |
diff --git a/src/lib/libssl/s3_srvr.c b/src/lib/libssl/s3_srvr.c index 20d716fb1b..58cf774967 100644 --- a/src/lib/libssl/s3_srvr.c +++ b/src/lib/libssl/s3_srvr.c | |||
@@ -152,11 +152,18 @@ SSL_METHOD *SSLv3_server_method(void) | |||
152 | 152 | ||
153 | if (init) | 153 | if (init) |
154 | { | 154 | { |
155 | memcpy((char *)&SSLv3_server_data,(char *)sslv3_base_method(), | 155 | CRYPTO_w_lock(CRYPTO_LOCK_SSL_METHOD); |
156 | sizeof(SSL_METHOD)); | 156 | |
157 | SSLv3_server_data.ssl_accept=ssl3_accept; | 157 | if (init) |
158 | SSLv3_server_data.get_ssl_method=ssl3_get_server_method; | 158 | { |
159 | init=0; | 159 | memcpy((char *)&SSLv3_server_data,(char *)sslv3_base_method(), |
160 | sizeof(SSL_METHOD)); | ||
161 | SSLv3_server_data.ssl_accept=ssl3_accept; | ||
162 | SSLv3_server_data.get_ssl_method=ssl3_get_server_method; | ||
163 | init=0; | ||
164 | } | ||
165 | |||
166 | CRYPTO_w_unlock(CRYPTO_LOCK_SSL_METHOD); | ||
160 | } | 167 | } |
161 | return(&SSLv3_server_data); | 168 | return(&SSLv3_server_data); |
162 | } | 169 | } |
@@ -1171,7 +1178,7 @@ static int ssl3_send_server_key_exchange(SSL *s) | |||
1171 | kn=0; | 1178 | kn=0; |
1172 | } | 1179 | } |
1173 | 1180 | ||
1174 | if (!BUF_MEM_grow(buf,n+4+kn)) | 1181 | if (!BUF_MEM_grow_clean(buf,n+4+kn)) |
1175 | { | 1182 | { |
1176 | SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,ERR_LIB_BUF); | 1183 | SSLerr(SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE,ERR_LIB_BUF); |
1177 | goto err; | 1184 | goto err; |
@@ -1298,7 +1305,7 @@ static int ssl3_send_certificate_request(SSL *s) | |||
1298 | { | 1305 | { |
1299 | name=sk_X509_NAME_value(sk,i); | 1306 | name=sk_X509_NAME_value(sk,i); |
1300 | j=i2d_X509_NAME(name,NULL); | 1307 | j=i2d_X509_NAME(name,NULL); |
1301 | if (!BUF_MEM_grow(buf,4+n+j+2)) | 1308 | if (!BUF_MEM_grow_clean(buf,4+n+j+2)) |
1302 | { | 1309 | { |
1303 | SSLerr(SSL_F_SSL3_SEND_CERTIFICATE_REQUEST,ERR_R_BUF_LIB); | 1310 | SSLerr(SSL_F_SSL3_SEND_CERTIFICATE_REQUEST,ERR_R_BUF_LIB); |
1304 | goto err; | 1311 | goto err; |
@@ -1440,7 +1447,7 @@ static int ssl3_get_client_key_exchange(SSL *s) | |||
1440 | if (i != SSL_MAX_MASTER_KEY_LENGTH) | 1447 | if (i != SSL_MAX_MASTER_KEY_LENGTH) |
1441 | { | 1448 | { |
1442 | al=SSL_AD_DECODE_ERROR; | 1449 | al=SSL_AD_DECODE_ERROR; |
1443 | SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_BAD_RSA_DECRYPT); | 1450 | /* SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_BAD_RSA_DECRYPT); */ |
1444 | } | 1451 | } |
1445 | 1452 | ||
1446 | if ((al == -1) && !((p[0] == (s->client_version>>8)) && (p[1] == (s->client_version & 0xff)))) | 1453 | if ((al == -1) && !((p[0] == (s->client_version>>8)) && (p[1] == (s->client_version & 0xff)))) |
@@ -1456,37 +1463,35 @@ static int ssl3_get_client_key_exchange(SSL *s) | |||
1456 | (p[0] == (s->version>>8)) && (p[1] == (s->version & 0xff)))) | 1463 | (p[0] == (s->version>>8)) && (p[1] == (s->version & 0xff)))) |
1457 | { | 1464 | { |
1458 | al=SSL_AD_DECODE_ERROR; | 1465 | al=SSL_AD_DECODE_ERROR; |
1459 | SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_BAD_PROTOCOL_VERSION_NUMBER); | 1466 | /* SSLerr(SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE,SSL_R_BAD_PROTOCOL_VERSION_NUMBER); */ |
1460 | goto f_err; | 1467 | |
1468 | /* The Klima-Pokorny-Rosa extension of Bleichenbacher's attack | ||
1469 | * (http://eprint.iacr.org/2003/052/) exploits the version | ||
1470 | * number check as a "bad version oracle" -- an alert would | ||
1471 | * reveal that the plaintext corresponding to some ciphertext | ||
1472 | * made up by the adversary is properly formatted except | ||
1473 | * that the version number is wrong. To avoid such attacks, | ||
1474 | * we should treat this just like any other decryption error. */ | ||
1461 | } | 1475 | } |
1462 | } | 1476 | } |
1463 | 1477 | ||
1464 | if (al != -1) | 1478 | if (al != -1) |
1465 | { | 1479 | { |
1466 | #if 0 | ||
1467 | goto f_err; | ||
1468 | #else | ||
1469 | /* Some decryption failure -- use random value instead as countermeasure | 1480 | /* Some decryption failure -- use random value instead as countermeasure |
1470 | * against Bleichenbacher's attack on PKCS #1 v1.5 RSA padding | 1481 | * against Bleichenbacher's attack on PKCS #1 v1.5 RSA padding |
1471 | * (see RFC 2246, section 7.4.7.1). | 1482 | * (see RFC 2246, section 7.4.7.1). */ |
1472 | * But note that due to length and protocol version checking, the | ||
1473 | * attack is impractical anyway (see section 5 in D. Bleichenbacher: | ||
1474 | * "Chosen Ciphertext Attacks Against Protocols Based on the RSA | ||
1475 | * Encryption Standard PKCS #1", CRYPTO '98, LNCS 1462, pp. 1-12). | ||
1476 | */ | ||
1477 | ERR_clear_error(); | 1483 | ERR_clear_error(); |
1478 | i = SSL_MAX_MASTER_KEY_LENGTH; | 1484 | i = SSL_MAX_MASTER_KEY_LENGTH; |
1479 | p[0] = s->client_version >> 8; | 1485 | p[0] = s->client_version >> 8; |
1480 | p[1] = s->client_version & 0xff; | 1486 | p[1] = s->client_version & 0xff; |
1481 | RAND_pseudo_bytes(p+2, i-2); /* should be RAND_bytes, but we cannot work around a failure */ | 1487 | RAND_pseudo_bytes(p+2, i-2); /* should be RAND_bytes, but we cannot work around a failure */ |
1482 | #endif | ||
1483 | } | 1488 | } |
1484 | 1489 | ||
1485 | s->session->master_key_length= | 1490 | s->session->master_key_length= |
1486 | s->method->ssl3_enc->generate_master_secret(s, | 1491 | s->method->ssl3_enc->generate_master_secret(s, |
1487 | s->session->master_key, | 1492 | s->session->master_key, |
1488 | p,i); | 1493 | p,i); |
1489 | memset(p,0,i); | 1494 | OPENSSL_cleanse(p,i); |
1490 | } | 1495 | } |
1491 | else | 1496 | else |
1492 | #endif | 1497 | #endif |
@@ -1549,7 +1554,7 @@ static int ssl3_get_client_key_exchange(SSL *s) | |||
1549 | s->session->master_key_length= | 1554 | s->session->master_key_length= |
1550 | s->method->ssl3_enc->generate_master_secret(s, | 1555 | s->method->ssl3_enc->generate_master_secret(s, |
1551 | s->session->master_key,p,i); | 1556 | s->session->master_key,p,i); |
1552 | memset(p,0,i); | 1557 | OPENSSL_cleanse(p,i); |
1553 | } | 1558 | } |
1554 | else | 1559 | else |
1555 | #endif | 1560 | #endif |
@@ -1652,7 +1657,7 @@ static int ssl3_get_client_key_exchange(SSL *s) | |||
1652 | if (enc == NULL) | 1657 | if (enc == NULL) |
1653 | goto err; | 1658 | goto err; |
1654 | 1659 | ||
1655 | memset(iv, 0, EVP_MAX_IV_LENGTH); /* per RFC 1510 */ | 1660 | memset(iv, 0, sizeof iv); /* per RFC 1510 */ |
1656 | 1661 | ||
1657 | if (!EVP_DecryptInit_ex(&ciph_ctx,enc,NULL,kssl_ctx->key,iv)) | 1662 | if (!EVP_DecryptInit_ex(&ciph_ctx,enc,NULL,kssl_ctx->key,iv)) |
1658 | { | 1663 | { |
@@ -1740,7 +1745,7 @@ static int ssl3_get_cert_verify(SSL *s) | |||
1740 | SSL3_ST_SR_CERT_VRFY_A, | 1745 | SSL3_ST_SR_CERT_VRFY_A, |
1741 | SSL3_ST_SR_CERT_VRFY_B, | 1746 | SSL3_ST_SR_CERT_VRFY_B, |
1742 | -1, | 1747 | -1, |
1743 | 512, /* 512? */ | 1748 | 514, /* 514? */ |
1744 | &ok); | 1749 | &ok); |
1745 | 1750 | ||
1746 | if (!ok) return((int)n); | 1751 | if (!ok) return((int)n); |
diff --git a/src/lib/libssl/ssl.h b/src/lib/libssl/ssl.h index e9d1e896d7..4ae8458259 100644 --- a/src/lib/libssl/ssl.h +++ b/src/lib/libssl/ssl.h | |||
@@ -204,6 +204,22 @@ extern "C" { | |||
204 | 204 | ||
205 | /* VRS Additional Kerberos5 entries | 205 | /* VRS Additional Kerberos5 entries |
206 | */ | 206 | */ |
207 | #define SSL_TXT_KRB5_DES_64_CBC_SHA SSL3_TXT_KRB5_DES_64_CBC_SHA | ||
208 | #define SSL_TXT_KRB5_DES_192_CBC3_SHA SSL3_TXT_KRB5_DES_192_CBC3_SHA | ||
209 | #define SSL_TXT_KRB5_RC4_128_SHA SSL3_TXT_KRB5_RC4_128_SHA | ||
210 | #define SSL_TXT_KRB5_IDEA_128_CBC_SHA SSL3_TXT_KRB5_IDEA_128_CBC_SHA | ||
211 | #define SSL_TXT_KRB5_DES_64_CBC_MD5 SSL3_TXT_KRB5_DES_64_CBC_MD5 | ||
212 | #define SSL_TXT_KRB5_DES_192_CBC3_MD5 SSL3_TXT_KRB5_DES_192_CBC3_MD5 | ||
213 | #define SSL_TXT_KRB5_RC4_128_MD5 SSL3_TXT_KRB5_RC4_128_MD5 | ||
214 | #define SSL_TXT_KRB5_IDEA_128_CBC_MD5 SSL3_TXT_KRB5_IDEA_128_CBC_MD5 | ||
215 | |||
216 | #define SSL_TXT_KRB5_DES_40_CBC_SHA SSL3_TXT_KRB5_DES_40_CBC_SHA | ||
217 | #define SSL_TXT_KRB5_RC2_40_CBC_SHA SSL3_TXT_KRB5_RC2_40_CBC_SHA | ||
218 | #define SSL_TXT_KRB5_RC4_40_SHA SSL3_TXT_KRB5_RC4_40_SHA | ||
219 | #define SSL_TXT_KRB5_DES_40_CBC_MD5 SSL3_TXT_KRB5_DES_40_CBC_MD5 | ||
220 | #define SSL_TXT_KRB5_RC2_40_CBC_MD5 SSL3_TXT_KRB5_RC2_40_CBC_MD5 | ||
221 | #define SSL_TXT_KRB5_RC4_40_MD5 SSL3_TXT_KRB5_RC4_40_MD5 | ||
222 | |||
207 | #define SSL_TXT_KRB5_DES_40_CBC_SHA SSL3_TXT_KRB5_DES_40_CBC_SHA | 223 | #define SSL_TXT_KRB5_DES_40_CBC_SHA SSL3_TXT_KRB5_DES_40_CBC_SHA |
208 | #define SSL_TXT_KRB5_DES_40_CBC_MD5 SSL3_TXT_KRB5_DES_40_CBC_MD5 | 224 | #define SSL_TXT_KRB5_DES_40_CBC_MD5 SSL3_TXT_KRB5_DES_40_CBC_MD5 |
209 | #define SSL_TXT_KRB5_DES_64_CBC_SHA SSL3_TXT_KRB5_DES_64_CBC_SHA | 225 | #define SSL_TXT_KRB5_DES_64_CBC_SHA SSL3_TXT_KRB5_DES_64_CBC_SHA |
@@ -299,9 +315,7 @@ extern "C" { | |||
299 | #include <openssl/crypto.h> | 315 | #include <openssl/crypto.h> |
300 | #include <openssl/lhash.h> | 316 | #include <openssl/lhash.h> |
301 | #include <openssl/buffer.h> | 317 | #include <openssl/buffer.h> |
302 | #include <openssl/bio.h> | ||
303 | #include <openssl/pem.h> | 318 | #include <openssl/pem.h> |
304 | #include <openssl/x509.h> | ||
305 | 319 | ||
306 | #ifdef __cplusplus | 320 | #ifdef __cplusplus |
307 | extern "C" { | 321 | extern "C" { |
@@ -507,6 +521,8 @@ typedef struct ssl_session_st | |||
507 | /* Never bother the application with retries if the transport | 521 | /* Never bother the application with retries if the transport |
508 | * is blocking: */ | 522 | * is blocking: */ |
509 | #define SSL_MODE_AUTO_RETRY 0x00000004L | 523 | #define SSL_MODE_AUTO_RETRY 0x00000004L |
524 | /* Don't attempt to automatically build certificate chain */ | ||
525 | #define SSL_MODE_NO_AUTO_CHAIN 0x00000008L | ||
510 | 526 | ||
511 | 527 | ||
512 | /* Note: SSL[_CTX]_set_{options,mode} use |= op on the previous value, | 528 | /* Note: SSL[_CTX]_set_{options,mode} use |= op on the previous value, |
@@ -704,10 +720,11 @@ struct ssl_ctx_st | |||
704 | #define SSL_SESS_CACHE_SERVER 0x0002 | 720 | #define SSL_SESS_CACHE_SERVER 0x0002 |
705 | #define SSL_SESS_CACHE_BOTH (SSL_SESS_CACHE_CLIENT|SSL_SESS_CACHE_SERVER) | 721 | #define SSL_SESS_CACHE_BOTH (SSL_SESS_CACHE_CLIENT|SSL_SESS_CACHE_SERVER) |
706 | #define SSL_SESS_CACHE_NO_AUTO_CLEAR 0x0080 | 722 | #define SSL_SESS_CACHE_NO_AUTO_CLEAR 0x0080 |
707 | /* This one, when set, makes the server session-id lookup not look | 723 | /* enough comments already ... see SSL_CTX_set_session_cache_mode(3) */ |
708 | * in the cache. If there is an application get_session callback | ||
709 | * defined, this will still get called. */ | ||
710 | #define SSL_SESS_CACHE_NO_INTERNAL_LOOKUP 0x0100 | 724 | #define SSL_SESS_CACHE_NO_INTERNAL_LOOKUP 0x0100 |
725 | #define SSL_SESS_CACHE_NO_INTERNAL_STORE 0x0200 | ||
726 | #define SSL_SESS_CACHE_NO_INTERNAL \ | ||
727 | (SSL_SESS_CACHE_NO_INTERNAL_LOOKUP|SSL_SESS_CACHE_NO_INTERNAL_STORE) | ||
711 | 728 | ||
712 | struct lhash_st *SSL_CTX_sessions(SSL_CTX *ctx); | 729 | struct lhash_st *SSL_CTX_sessions(SSL_CTX *ctx); |
713 | #define SSL_CTX_sess_number(ctx) \ | 730 | #define SSL_CTX_sess_number(ctx) \ |
@@ -1212,14 +1229,12 @@ int SSL_CTX_use_certificate_chain_file(SSL_CTX *ctx, const char *file); /* PEM t | |||
1212 | STACK_OF(X509_NAME) *SSL_load_client_CA_file(const char *file); | 1229 | STACK_OF(X509_NAME) *SSL_load_client_CA_file(const char *file); |
1213 | int SSL_add_file_cert_subjects_to_stack(STACK_OF(X509_NAME) *stackCAs, | 1230 | int SSL_add_file_cert_subjects_to_stack(STACK_OF(X509_NAME) *stackCAs, |
1214 | const char *file); | 1231 | const char *file); |
1215 | #ifndef OPENSSL_SYS_WIN32 | ||
1216 | #ifndef OPENSSL_SYS_VMS | 1232 | #ifndef OPENSSL_SYS_VMS |
1217 | #ifndef OPENSSL_SYS_MACINTOSH_CLASSIC /* XXXXX: Better scheme needed! [was: #ifndef MAC_OS_pre_X] */ | 1233 | #ifndef OPENSSL_SYS_MACINTOSH_CLASSIC /* XXXXX: Better scheme needed! [was: #ifndef MAC_OS_pre_X] */ |
1218 | int SSL_add_dir_cert_subjects_to_stack(STACK_OF(X509_NAME) *stackCAs, | 1234 | int SSL_add_dir_cert_subjects_to_stack(STACK_OF(X509_NAME) *stackCAs, |
1219 | const char *dir); | 1235 | const char *dir); |
1220 | #endif | 1236 | #endif |
1221 | #endif | 1237 | #endif |
1222 | #endif | ||
1223 | 1238 | ||
1224 | #endif | 1239 | #endif |
1225 | 1240 | ||
@@ -1688,6 +1703,7 @@ void ERR_load_SSL_strings(void); | |||
1688 | #define SSL_R_LENGTH_TOO_SHORT 160 | 1703 | #define SSL_R_LENGTH_TOO_SHORT 160 |
1689 | #define SSL_R_LIBRARY_BUG 274 | 1704 | #define SSL_R_LIBRARY_BUG 274 |
1690 | #define SSL_R_LIBRARY_HAS_NO_CIPHERS 161 | 1705 | #define SSL_R_LIBRARY_HAS_NO_CIPHERS 161 |
1706 | #define SSL_R_MASTER_KEY_TOO_LONG 1112 | ||
1691 | #define SSL_R_MESSAGE_TOO_LONG 1111 | 1707 | #define SSL_R_MESSAGE_TOO_LONG 1111 |
1692 | #define SSL_R_MISSING_DH_DSA_CERT 162 | 1708 | #define SSL_R_MISSING_DH_DSA_CERT 162 |
1693 | #define SSL_R_MISSING_DH_KEY 163 | 1709 | #define SSL_R_MISSING_DH_KEY 163 |
diff --git a/src/lib/libssl/ssl3.h b/src/lib/libssl/ssl3.h index 8fd6951d77..1153aeda74 100644 --- a/src/lib/libssl/ssl3.h +++ b/src/lib/libssl/ssl3.h | |||
@@ -156,23 +156,29 @@ extern "C" { | |||
156 | 156 | ||
157 | #define SSL3_CK_FZA_DMS_NULL_SHA 0x0300001C | 157 | #define SSL3_CK_FZA_DMS_NULL_SHA 0x0300001C |
158 | #define SSL3_CK_FZA_DMS_FZA_SHA 0x0300001D | 158 | #define SSL3_CK_FZA_DMS_FZA_SHA 0x0300001D |
159 | #if 0 /* Because it clashes with KRB5, is never used any more, and is safe | ||
160 | to remove according to David Hopwood <david.hopwood@zetnet.co.uk> | ||
161 | of the ietf-tls list */ | ||
159 | #define SSL3_CK_FZA_DMS_RC4_SHA 0x0300001E | 162 | #define SSL3_CK_FZA_DMS_RC4_SHA 0x0300001E |
163 | #endif | ||
160 | 164 | ||
161 | /* VRS Additional Kerberos5 entries | 165 | /* VRS Additional Kerberos5 entries |
162 | */ | 166 | */ |
163 | #define SSL3_CK_KRB5_DES_40_CBC_SHA 0x03000021 | 167 | #define SSL3_CK_KRB5_DES_64_CBC_SHA 0x0300001E |
164 | #define SSL3_CK_KRB5_DES_40_CBC_MD5 0x03000022 | 168 | #define SSL3_CK_KRB5_DES_192_CBC3_SHA 0x0300001F |
165 | #define SSL3_CK_KRB5_DES_64_CBC_SHA 0x03000023 | 169 | #define SSL3_CK_KRB5_RC4_128_SHA 0x03000020 |
166 | #define SSL3_CK_KRB5_DES_64_CBC_MD5 0x03000024 | 170 | #define SSL3_CK_KRB5_IDEA_128_CBC_SHA 0x03000021 |
167 | #define SSL3_CK_KRB5_DES_192_CBC3_SHA 0x03000025 | 171 | #define SSL3_CK_KRB5_DES_64_CBC_MD5 0x03000022 |
168 | #define SSL3_CK_KRB5_DES_192_CBC3_MD5 0x03000026 | 172 | #define SSL3_CK_KRB5_DES_192_CBC3_MD5 0x03000023 |
169 | 173 | #define SSL3_CK_KRB5_RC4_128_MD5 0x03000024 | |
170 | #define SSL3_TXT_KRB5_DES_40_CBC_SHA "EXP-KRB5-DES-CBC-SHA" | 174 | #define SSL3_CK_KRB5_IDEA_128_CBC_MD5 0x03000025 |
171 | #define SSL3_TXT_KRB5_DES_40_CBC_MD5 "EXP-KRB5-DES-CBC-MD5" | 175 | |
172 | #define SSL3_TXT_KRB5_DES_64_CBC_SHA "KRB5-DES-CBC-SHA" | 176 | #define SSL3_CK_KRB5_DES_40_CBC_SHA 0x03000026 |
173 | #define SSL3_TXT_KRB5_DES_64_CBC_MD5 "KRB5-DES-CBC-MD5" | 177 | #define SSL3_CK_KRB5_RC2_40_CBC_SHA 0x03000027 |
174 | #define SSL3_TXT_KRB5_DES_192_CBC3_SHA "KRB5-DES-CBC3-SHA" | 178 | #define SSL3_CK_KRB5_RC4_40_SHA 0x03000028 |
175 | #define SSL3_TXT_KRB5_DES_192_CBC3_MD5 "KRB5-DES-CBC3-MD5" | 179 | #define SSL3_CK_KRB5_DES_40_CBC_MD5 0x03000029 |
180 | #define SSL3_CK_KRB5_RC2_40_CBC_MD5 0x0300002A | ||
181 | #define SSL3_CK_KRB5_RC4_40_MD5 0x0300002B | ||
176 | 182 | ||
177 | #define SSL3_TXT_RSA_NULL_MD5 "NULL-MD5" | 183 | #define SSL3_TXT_RSA_NULL_MD5 "NULL-MD5" |
178 | #define SSL3_TXT_RSA_NULL_SHA "NULL-SHA" | 184 | #define SSL3_TXT_RSA_NULL_SHA "NULL-SHA" |
@@ -209,6 +215,22 @@ extern "C" { | |||
209 | #define SSL3_TXT_FZA_DMS_FZA_SHA "FZA-FZA-CBC-SHA" | 215 | #define SSL3_TXT_FZA_DMS_FZA_SHA "FZA-FZA-CBC-SHA" |
210 | #define SSL3_TXT_FZA_DMS_RC4_SHA "FZA-RC4-SHA" | 216 | #define SSL3_TXT_FZA_DMS_RC4_SHA "FZA-RC4-SHA" |
211 | 217 | ||
218 | #define SSL3_TXT_KRB5_DES_64_CBC_SHA "KRB5-DES-CBC-SHA" | ||
219 | #define SSL3_TXT_KRB5_DES_192_CBC3_SHA "KRB5-DES-CBC3-SHA" | ||
220 | #define SSL3_TXT_KRB5_RC4_128_SHA "KRB5-RC4-SHA" | ||
221 | #define SSL3_TXT_KRB5_IDEA_128_CBC_SHA "KRB5-IDEA-CBC-SHA" | ||
222 | #define SSL3_TXT_KRB5_DES_64_CBC_MD5 "KRB5-DES-CBC-MD5" | ||
223 | #define SSL3_TXT_KRB5_DES_192_CBC3_MD5 "KRB5-DES-CBC3-MD5" | ||
224 | #define SSL3_TXT_KRB5_RC4_128_MD5 "KRB5-RC4-MD5" | ||
225 | #define SSL3_TXT_KRB5_IDEA_128_CBC_MD5 "KRB5-IDEA-CBC-MD5" | ||
226 | |||
227 | #define SSL3_TXT_KRB5_DES_40_CBC_SHA "EXP-KRB5-DES-CBC-SHA" | ||
228 | #define SSL3_TXT_KRB5_RC2_40_CBC_SHA "EXP-KRB5-RC2-CBC-SHA" | ||
229 | #define SSL3_TXT_KRB5_RC4_40_SHA "EXP-KRB5-RC4-SHA" | ||
230 | #define SSL3_TXT_KRB5_DES_40_CBC_MD5 "EXP-KRB5-DES-CBC-MD5" | ||
231 | #define SSL3_TXT_KRB5_RC2_40_CBC_MD5 "EXP-KRB5-RC2-CBC-MD5" | ||
232 | #define SSL3_TXT_KRB5_RC4_40_MD5 "EXP-KRB5-RC4-MD5" | ||
233 | |||
212 | #define SSL3_SSL_SESSION_ID_LENGTH 32 | 234 | #define SSL3_SSL_SESSION_ID_LENGTH 32 |
213 | #define SSL3_MAX_SSL_SESSION_ID_LENGTH 32 | 235 | #define SSL3_MAX_SSL_SESSION_ID_LENGTH 32 |
214 | 236 | ||
diff --git a/src/lib/libssl/ssl_asn1.c b/src/lib/libssl/ssl_asn1.c index 3723fc2e37..16bc11b559 100644 --- a/src/lib/libssl/ssl_asn1.c +++ b/src/lib/libssl/ssl_asn1.c | |||
@@ -299,6 +299,7 @@ SSL_SESSION *d2i_SSL_SESSION(SSL_SESSION **a, unsigned char **pp, | |||
299 | os.length = sizeof ret->session_id; | 299 | os.length = sizeof ret->session_id; |
300 | 300 | ||
301 | ret->session_id_length=os.length; | 301 | ret->session_id_length=os.length; |
302 | OPENSSL_assert(os.length <= sizeof ret->session_id); | ||
302 | memcpy(ret->session_id,os.data,os.length); | 303 | memcpy(ret->session_id,os.data,os.length); |
303 | 304 | ||
304 | M_ASN1_D2I_get(osp,d2i_ASN1_OCTET_STRING); | 305 | M_ASN1_D2I_get(osp,d2i_ASN1_OCTET_STRING); |
@@ -370,9 +371,15 @@ SSL_SESSION *d2i_SSL_SESSION(SSL_SESSION **a, unsigned char **pp, | |||
370 | if(os.data != NULL) | 371 | if(os.data != NULL) |
371 | { | 372 | { |
372 | if (os.length > SSL_MAX_SID_CTX_LENGTH) | 373 | if (os.length > SSL_MAX_SID_CTX_LENGTH) |
374 | { | ||
375 | ret->sid_ctx_length=os.length; | ||
373 | SSLerr(SSL_F_D2I_SSL_SESSION,SSL_R_BAD_LENGTH); | 376 | SSLerr(SSL_F_D2I_SSL_SESSION,SSL_R_BAD_LENGTH); |
374 | ret->sid_ctx_length=os.length; | 377 | } |
375 | memcpy(ret->sid_ctx,os.data,os.length); | 378 | else |
379 | { | ||
380 | ret->sid_ctx_length=os.length; | ||
381 | memcpy(ret->sid_ctx,os.data,os.length); | ||
382 | } | ||
376 | OPENSSL_free(os.data); os.data=NULL; os.length=0; | 383 | OPENSSL_free(os.data); os.data=NULL; os.length=0; |
377 | } | 384 | } |
378 | else | 385 | else |
diff --git a/src/lib/libssl/ssl_cert.c b/src/lib/libssl/ssl_cert.c index 3d31bbf05f..da90078a37 100644 --- a/src/lib/libssl/ssl_cert.c +++ b/src/lib/libssl/ssl_cert.c | |||
@@ -781,7 +781,7 @@ err: | |||
781 | #endif | 781 | #endif |
782 | #endif | 782 | #endif |
783 | 783 | ||
784 | #else | 784 | #else /* OPENSSL_SYS_WIN32 */ |
785 | 785 | ||
786 | int SSL_add_dir_cert_subjects_to_stack(STACK_OF(X509_NAME) *stack, | 786 | int SSL_add_dir_cert_subjects_to_stack(STACK_OF(X509_NAME) *stack, |
787 | const char *dir) | 787 | const char *dir) |
@@ -789,10 +789,30 @@ int SSL_add_dir_cert_subjects_to_stack(STACK_OF(X509_NAME) *stack, | |||
789 | WIN32_FIND_DATA FindFileData; | 789 | WIN32_FIND_DATA FindFileData; |
790 | HANDLE hFind; | 790 | HANDLE hFind; |
791 | int ret = 0; | 791 | int ret = 0; |
792 | #ifdef OPENSSL_SYS_WINCE | ||
793 | WCHAR* wdir = NULL; | ||
794 | #endif | ||
792 | 795 | ||
793 | CRYPTO_w_lock(CRYPTO_LOCK_READDIR); | 796 | CRYPTO_w_lock(CRYPTO_LOCK_READDIR); |
794 | 797 | ||
798 | #ifdef OPENSSL_SYS_WINCE | ||
799 | /* convert strings to UNICODE */ | ||
800 | { | ||
801 | BOOL result = FALSE; | ||
802 | int i; | ||
803 | wdir = malloc((strlen(dir)+1)*2); | ||
804 | if (wdir == NULL) | ||
805 | goto err_noclose; | ||
806 | for (i=0; i<(int)strlen(dir)+1; i++) | ||
807 | wdir[i] = (short)dir[i]; | ||
808 | } | ||
809 | #endif | ||
810 | |||
811 | #ifdef OPENSSL_SYS_WINCE | ||
812 | hFind = FindFirstFile(wdir, &FindFileData); | ||
813 | #else | ||
795 | hFind = FindFirstFile(dir, &FindFileData); | 814 | hFind = FindFirstFile(dir, &FindFileData); |
815 | #endif | ||
796 | /* Note that a side effect is that the CAs will be sorted by name */ | 816 | /* Note that a side effect is that the CAs will be sorted by name */ |
797 | if(hFind == INVALID_HANDLE_VALUE) | 817 | if(hFind == INVALID_HANDLE_VALUE) |
798 | { | 818 | { |
@@ -807,7 +827,11 @@ int SSL_add_dir_cert_subjects_to_stack(STACK_OF(X509_NAME) *stack, | |||
807 | char buf[1024]; | 827 | char buf[1024]; |
808 | int r; | 828 | int r; |
809 | 829 | ||
830 | #ifdef OPENSSL_SYS_WINCE | ||
831 | if(strlen(dir)+_tcslen(FindFileData.cFileName)+2 > sizeof buf) | ||
832 | #else | ||
810 | if(strlen(dir)+strlen(FindFileData.cFileName)+2 > sizeof buf) | 833 | if(strlen(dir)+strlen(FindFileData.cFileName)+2 > sizeof buf) |
834 | #endif | ||
811 | { | 835 | { |
812 | SSLerr(SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK,SSL_R_PATH_TOO_LONG); | 836 | SSLerr(SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK,SSL_R_PATH_TOO_LONG); |
813 | goto err; | 837 | goto err; |
@@ -825,6 +849,10 @@ int SSL_add_dir_cert_subjects_to_stack(STACK_OF(X509_NAME) *stack, | |||
825 | err: | 849 | err: |
826 | FindClose(hFind); | 850 | FindClose(hFind); |
827 | err_noclose: | 851 | err_noclose: |
852 | #ifdef OPENSSL_SYS_WINCE | ||
853 | if (wdir != NULL) | ||
854 | free(wdir); | ||
855 | #endif | ||
828 | CRYPTO_w_unlock(CRYPTO_LOCK_READDIR); | 856 | CRYPTO_w_unlock(CRYPTO_LOCK_READDIR); |
829 | return ret; | 857 | return ret; |
830 | } | 858 | } |
diff --git a/src/lib/libssl/ssl_ciph.c b/src/lib/libssl/ssl_ciph.c index 37f58886a6..888b667fa1 100644 --- a/src/lib/libssl/ssl_ciph.c +++ b/src/lib/libssl/ssl_ciph.c | |||
@@ -668,13 +668,14 @@ static int ssl_cipher_process_rulestr(const char *rule_str, | |||
668 | * So additionally check whether the cipher name found | 668 | * So additionally check whether the cipher name found |
669 | * has the correct length. We can save a strlen() call: | 669 | * has the correct length. We can save a strlen() call: |
670 | * just checking for the '\0' at the right place is | 670 | * just checking for the '\0' at the right place is |
671 | * sufficient, we have to strncmp() anyway. | 671 | * sufficient, we have to strncmp() anyway. (We cannot |
672 | * use strcmp(), because buf is not '\0' terminated.) | ||
672 | */ | 673 | */ |
673 | j = found = 0; | 674 | j = found = 0; |
674 | while (ca_list[j]) | 675 | while (ca_list[j]) |
675 | { | 676 | { |
676 | if ((ca_list[j]->name[buflen] == '\0') && | 677 | if (!strncmp(buf, ca_list[j]->name, buflen) && |
677 | !strncmp(buf, ca_list[j]->name, buflen)) | 678 | (ca_list[j]->name[buflen] == '\0')) |
678 | { | 679 | { |
679 | found = 1; | 680 | found = 1; |
680 | break; | 681 | break; |
@@ -751,7 +752,12 @@ STACK_OF(SSL_CIPHER) *ssl_create_cipher_list(const SSL_METHOD *ssl_method, | |||
751 | */ | 752 | */ |
752 | if (rule_str == NULL) return(NULL); | 753 | if (rule_str == NULL) return(NULL); |
753 | 754 | ||
754 | if (init_ciphers) load_ciphers(); | 755 | if (init_ciphers) |
756 | { | ||
757 | CRYPTO_w_lock(CRYPTO_LOCK_SSL); | ||
758 | if (init_ciphers) load_ciphers(); | ||
759 | CRYPTO_w_unlock(CRYPTO_LOCK_SSL); | ||
760 | } | ||
755 | 761 | ||
756 | /* | 762 | /* |
757 | * To reduce the work to do we only want to process the compiled | 763 | * To reduce the work to do we only want to process the compiled |
diff --git a/src/lib/libssl/ssl_err.c b/src/lib/libssl/ssl_err.c index 7067a745f3..d2cb181503 100644 --- a/src/lib/libssl/ssl_err.c +++ b/src/lib/libssl/ssl_err.c | |||
@@ -296,6 +296,7 @@ static ERR_STRING_DATA SSL_str_reasons[]= | |||
296 | {SSL_R_LENGTH_TOO_SHORT ,"length too short"}, | 296 | {SSL_R_LENGTH_TOO_SHORT ,"length too short"}, |
297 | {SSL_R_LIBRARY_BUG ,"library bug"}, | 297 | {SSL_R_LIBRARY_BUG ,"library bug"}, |
298 | {SSL_R_LIBRARY_HAS_NO_CIPHERS ,"library has no ciphers"}, | 298 | {SSL_R_LIBRARY_HAS_NO_CIPHERS ,"library has no ciphers"}, |
299 | {SSL_R_MASTER_KEY_TOO_LONG ,"master key too long"}, | ||
299 | {SSL_R_MESSAGE_TOO_LONG ,"message too long"}, | 300 | {SSL_R_MESSAGE_TOO_LONG ,"message too long"}, |
300 | {SSL_R_MISSING_DH_DSA_CERT ,"missing dh dsa cert"}, | 301 | {SSL_R_MISSING_DH_DSA_CERT ,"missing dh dsa cert"}, |
301 | {SSL_R_MISSING_DH_KEY ,"missing dh key"}, | 302 | {SSL_R_MISSING_DH_KEY ,"missing dh key"}, |
diff --git a/src/lib/libssl/ssl_lib.c b/src/lib/libssl/ssl_lib.c index 4bc4ce5b3a..ddd8114587 100644 --- a/src/lib/libssl/ssl_lib.c +++ b/src/lib/libssl/ssl_lib.c | |||
@@ -121,6 +121,7 @@ | |||
121 | #include <openssl/objects.h> | 121 | #include <openssl/objects.h> |
122 | #include <openssl/lhash.h> | 122 | #include <openssl/lhash.h> |
123 | #include <openssl/x509v3.h> | 123 | #include <openssl/x509v3.h> |
124 | #include "cryptlib.h" | ||
124 | 125 | ||
125 | const char *SSL_version_str=OPENSSL_VERSION_TEXT; | 126 | const char *SSL_version_str=OPENSSL_VERSION_TEXT; |
126 | 127 | ||
@@ -273,6 +274,7 @@ SSL *SSL_new(SSL_CTX *ctx) | |||
273 | s->verify_mode=ctx->verify_mode; | 274 | s->verify_mode=ctx->verify_mode; |
274 | s->verify_depth=ctx->verify_depth; | 275 | s->verify_depth=ctx->verify_depth; |
275 | s->sid_ctx_length=ctx->sid_ctx_length; | 276 | s->sid_ctx_length=ctx->sid_ctx_length; |
277 | OPENSSL_assert(s->sid_ctx_length <= sizeof s->sid_ctx); | ||
276 | memcpy(&s->sid_ctx,&ctx->sid_ctx,sizeof(s->sid_ctx)); | 278 | memcpy(&s->sid_ctx,&ctx->sid_ctx,sizeof(s->sid_ctx)); |
277 | s->verify_callback=ctx->default_verify_callback; | 279 | s->verify_callback=ctx->default_verify_callback; |
278 | s->generate_session_id=ctx->generate_session_id; | 280 | s->generate_session_id=ctx->generate_session_id; |
@@ -314,7 +316,7 @@ err: | |||
314 | int SSL_CTX_set_session_id_context(SSL_CTX *ctx,const unsigned char *sid_ctx, | 316 | int SSL_CTX_set_session_id_context(SSL_CTX *ctx,const unsigned char *sid_ctx, |
315 | unsigned int sid_ctx_len) | 317 | unsigned int sid_ctx_len) |
316 | { | 318 | { |
317 | if(sid_ctx_len > SSL_MAX_SID_CTX_LENGTH) | 319 | if(sid_ctx_len > sizeof ctx->sid_ctx) |
318 | { | 320 | { |
319 | SSLerr(SSL_F_SSL_CTX_SET_SESSION_ID_CONTEXT,SSL_R_SSL_SESSION_ID_CONTEXT_TOO_LONG); | 321 | SSLerr(SSL_F_SSL_CTX_SET_SESSION_ID_CONTEXT,SSL_R_SSL_SESSION_ID_CONTEXT_TOO_LONG); |
320 | return 0; | 322 | return 0; |
@@ -364,6 +366,10 @@ int SSL_has_matching_session_id(const SSL *ssl, const unsigned char *id, | |||
364 | * any new session built out of this id/id_len and the ssl_version in | 366 | * any new session built out of this id/id_len and the ssl_version in |
365 | * use by this SSL. */ | 367 | * use by this SSL. */ |
366 | SSL_SESSION r, *p; | 368 | SSL_SESSION r, *p; |
369 | |||
370 | if(id_len > sizeof r.session_id) | ||
371 | return 0; | ||
372 | |||
367 | r.ssl_version = ssl->version; | 373 | r.ssl_version = ssl->version; |
368 | r.session_id_length = id_len; | 374 | r.session_id_length = id_len; |
369 | memcpy(r.session_id, id, id_len); | 375 | memcpy(r.session_id, id, id_len); |
@@ -1063,14 +1069,17 @@ int ssl_cipher_ptr_id_cmp(const SSL_CIPHER * const *ap, | |||
1063 | * preference */ | 1069 | * preference */ |
1064 | STACK_OF(SSL_CIPHER) *SSL_get_ciphers(SSL *s) | 1070 | STACK_OF(SSL_CIPHER) *SSL_get_ciphers(SSL *s) |
1065 | { | 1071 | { |
1066 | if ((s != NULL) && (s->cipher_list != NULL)) | 1072 | if (s != NULL) |
1067 | { | ||
1068 | return(s->cipher_list); | ||
1069 | } | ||
1070 | else if ((s->ctx != NULL) && | ||
1071 | (s->ctx->cipher_list != NULL)) | ||
1072 | { | 1073 | { |
1073 | return(s->ctx->cipher_list); | 1074 | if (s->cipher_list != NULL) |
1075 | { | ||
1076 | return(s->cipher_list); | ||
1077 | } | ||
1078 | else if ((s->ctx != NULL) && | ||
1079 | (s->ctx->cipher_list != NULL)) | ||
1080 | { | ||
1081 | return(s->ctx->cipher_list); | ||
1082 | } | ||
1074 | } | 1083 | } |
1075 | return(NULL); | 1084 | return(NULL); |
1076 | } | 1085 | } |
@@ -1079,14 +1088,17 @@ STACK_OF(SSL_CIPHER) *SSL_get_ciphers(SSL *s) | |||
1079 | * algorithm id */ | 1088 | * algorithm id */ |
1080 | STACK_OF(SSL_CIPHER) *ssl_get_ciphers_by_id(SSL *s) | 1089 | STACK_OF(SSL_CIPHER) *ssl_get_ciphers_by_id(SSL *s) |
1081 | { | 1090 | { |
1082 | if ((s != NULL) && (s->cipher_list_by_id != NULL)) | 1091 | if (s != NULL) |
1083 | { | ||
1084 | return(s->cipher_list_by_id); | ||
1085 | } | ||
1086 | else if ((s != NULL) && (s->ctx != NULL) && | ||
1087 | (s->ctx->cipher_list_by_id != NULL)) | ||
1088 | { | 1092 | { |
1089 | return(s->ctx->cipher_list_by_id); | 1093 | if (s->cipher_list_by_id != NULL) |
1094 | { | ||
1095 | return(s->cipher_list_by_id); | ||
1096 | } | ||
1097 | else if ((s->ctx != NULL) && | ||
1098 | (s->ctx->cipher_list_by_id != NULL)) | ||
1099 | { | ||
1100 | return(s->ctx->cipher_list_by_id); | ||
1101 | } | ||
1090 | } | 1102 | } |
1091 | return(NULL); | 1103 | return(NULL); |
1092 | } | 1104 | } |
@@ -1652,7 +1664,7 @@ void ssl_update_cache(SSL *s,int mode) | |||
1652 | 1664 | ||
1653 | i=s->ctx->session_cache_mode; | 1665 | i=s->ctx->session_cache_mode; |
1654 | if ((i & mode) && (!s->hit) | 1666 | if ((i & mode) && (!s->hit) |
1655 | && ((i & SSL_SESS_CACHE_NO_INTERNAL_LOOKUP) | 1667 | && ((i & SSL_SESS_CACHE_NO_INTERNAL_STORE) |
1656 | || SSL_CTX_add_session(s->ctx,s->session)) | 1668 | || SSL_CTX_add_session(s->ctx,s->session)) |
1657 | && (s->ctx->new_session_cb != NULL)) | 1669 | && (s->ctx->new_session_cb != NULL)) |
1658 | { | 1670 | { |
@@ -1884,6 +1896,7 @@ SSL *SSL_dup(SSL *s) | |||
1884 | * they should not both point to the same object, | 1896 | * they should not both point to the same object, |
1885 | * and thus we can't use SSL_copy_session_id. */ | 1897 | * and thus we can't use SSL_copy_session_id. */ |
1886 | 1898 | ||
1899 | ret->method->ssl_free(ret); | ||
1887 | ret->method = s->method; | 1900 | ret->method = s->method; |
1888 | ret->method->ssl_new(ret); | 1901 | ret->method->ssl_new(ret); |
1889 | 1902 | ||
diff --git a/src/lib/libssl/ssl_sess.c b/src/lib/libssl/ssl_sess.c index ca1a7427be..fbc30b94e6 100644 --- a/src/lib/libssl/ssl_sess.c +++ b/src/lib/libssl/ssl_sess.c | |||
@@ -309,9 +309,12 @@ int ssl_get_prev_session(SSL *s, unsigned char *session_id, int len) | |||
309 | if (copy) | 309 | if (copy) |
310 | CRYPTO_add(&ret->references,1,CRYPTO_LOCK_SSL_SESSION); | 310 | CRYPTO_add(&ret->references,1,CRYPTO_LOCK_SSL_SESSION); |
311 | 311 | ||
312 | /* The following should not return 1, otherwise, | 312 | /* Add the externally cached session to the internal |
313 | * things are very strange */ | 313 | * cache as well if and only if we are supposed to. */ |
314 | SSL_CTX_add_session(s->ctx,ret); | 314 | if(!(s->ctx->session_cache_mode & SSL_SESS_CACHE_NO_INTERNAL_STORE)) |
315 | /* The following should not return 1, otherwise, | ||
316 | * things are very strange */ | ||
317 | SSL_CTX_add_session(s->ctx,ret); | ||
315 | } | 318 | } |
316 | if (ret == NULL) | 319 | if (ret == NULL) |
317 | goto err; | 320 | goto err; |
@@ -525,13 +528,13 @@ void SSL_SESSION_free(SSL_SESSION *ss) | |||
525 | 528 | ||
526 | CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL_SESSION, ss, &ss->ex_data); | 529 | CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL_SESSION, ss, &ss->ex_data); |
527 | 530 | ||
528 | memset(ss->key_arg,0,SSL_MAX_KEY_ARG_LENGTH); | 531 | OPENSSL_cleanse(ss->key_arg,sizeof ss->key_arg); |
529 | memset(ss->master_key,0,SSL_MAX_MASTER_KEY_LENGTH); | 532 | OPENSSL_cleanse(ss->master_key,sizeof ss->master_key); |
530 | memset(ss->session_id,0,SSL_MAX_SSL_SESSION_ID_LENGTH); | 533 | OPENSSL_cleanse(ss->session_id,sizeof ss->session_id); |
531 | if (ss->sess_cert != NULL) ssl_sess_cert_free(ss->sess_cert); | 534 | if (ss->sess_cert != NULL) ssl_sess_cert_free(ss->sess_cert); |
532 | if (ss->peer != NULL) X509_free(ss->peer); | 535 | if (ss->peer != NULL) X509_free(ss->peer); |
533 | if (ss->ciphers != NULL) sk_SSL_CIPHER_free(ss->ciphers); | 536 | if (ss->ciphers != NULL) sk_SSL_CIPHER_free(ss->ciphers); |
534 | memset(ss,0,sizeof(*ss)); | 537 | OPENSSL_cleanse(ss,sizeof(*ss)); |
535 | OPENSSL_free(ss); | 538 | OPENSSL_free(ss); |
536 | } | 539 | } |
537 | 540 | ||
diff --git a/src/lib/libssl/t1_clnt.c b/src/lib/libssl/t1_clnt.c index 9ad518f9f4..57205fb429 100644 --- a/src/lib/libssl/t1_clnt.c +++ b/src/lib/libssl/t1_clnt.c | |||
@@ -79,11 +79,18 @@ SSL_METHOD *TLSv1_client_method(void) | |||
79 | 79 | ||
80 | if (init) | 80 | if (init) |
81 | { | 81 | { |
82 | memcpy((char *)&TLSv1_client_data,(char *)tlsv1_base_method(), | 82 | CRYPTO_w_lock(CRYPTO_LOCK_SSL_METHOD); |
83 | sizeof(SSL_METHOD)); | 83 | |
84 | TLSv1_client_data.ssl_connect=ssl3_connect; | 84 | if (init) |
85 | TLSv1_client_data.get_ssl_method=tls1_get_client_method; | 85 | { |
86 | init=0; | 86 | memcpy((char *)&TLSv1_client_data,(char *)tlsv1_base_method(), |
87 | sizeof(SSL_METHOD)); | ||
88 | TLSv1_client_data.ssl_connect=ssl3_connect; | ||
89 | TLSv1_client_data.get_ssl_method=tls1_get_client_method; | ||
90 | init=0; | ||
91 | } | ||
92 | |||
93 | CRYPTO_w_unlock(CRYPTO_LOCK_SSL_METHOD); | ||
87 | } | 94 | } |
88 | return(&TLSv1_client_data); | 95 | return(&TLSv1_client_data); |
89 | } | 96 | } |
diff --git a/src/lib/libssl/t1_enc.c b/src/lib/libssl/t1_enc.c index 5290bf6665..271e247eea 100644 --- a/src/lib/libssl/t1_enc.c +++ b/src/lib/libssl/t1_enc.c | |||
@@ -124,7 +124,7 @@ static void tls1_P_hash(const EVP_MD *md, const unsigned char *sec, | |||
124 | unsigned int j; | 124 | unsigned int j; |
125 | HMAC_CTX ctx; | 125 | HMAC_CTX ctx; |
126 | HMAC_CTX ctx_tmp; | 126 | HMAC_CTX ctx_tmp; |
127 | unsigned char A1[HMAC_MAX_MD_CBLOCK]; | 127 | unsigned char A1[EVP_MAX_MD_SIZE]; |
128 | unsigned int A1_len; | 128 | unsigned int A1_len; |
129 | 129 | ||
130 | chunk=EVP_MD_size(md); | 130 | chunk=EVP_MD_size(md); |
@@ -161,7 +161,7 @@ static void tls1_P_hash(const EVP_MD *md, const unsigned char *sec, | |||
161 | } | 161 | } |
162 | HMAC_CTX_cleanup(&ctx); | 162 | HMAC_CTX_cleanup(&ctx); |
163 | HMAC_CTX_cleanup(&ctx_tmp); | 163 | HMAC_CTX_cleanup(&ctx_tmp); |
164 | memset(A1,0,sizeof(A1)); | 164 | OPENSSL_cleanse(A1,sizeof(A1)); |
165 | } | 165 | } |
166 | 166 | ||
167 | static void tls1_PRF(const EVP_MD *md5, const EVP_MD *sha1, | 167 | static void tls1_PRF(const EVP_MD *md5, const EVP_MD *sha1, |
@@ -418,10 +418,10 @@ printf("\niv="); | |||
418 | printf("\n"); | 418 | printf("\n"); |
419 | #endif | 419 | #endif |
420 | 420 | ||
421 | memset(tmp1,0,sizeof(tmp1)); | 421 | OPENSSL_cleanse(tmp1,sizeof(tmp1)); |
422 | memset(tmp2,0,sizeof(tmp1)); | 422 | OPENSSL_cleanse(tmp2,sizeof(tmp1)); |
423 | memset(iv1,0,sizeof(iv1)); | 423 | OPENSSL_cleanse(iv1,sizeof(iv1)); |
424 | memset(iv2,0,sizeof(iv2)); | 424 | OPENSSL_cleanse(iv2,sizeof(iv2)); |
425 | return(1); | 425 | return(1); |
426 | err: | 426 | err: |
427 | SSLerr(SSL_F_TLS1_CHANGE_CIPHER_STATE,ERR_R_MALLOC_FAILURE); | 427 | SSLerr(SSL_F_TLS1_CHANGE_CIPHER_STATE,ERR_R_MALLOC_FAILURE); |
@@ -476,7 +476,7 @@ printf("pre-master\n"); | |||
476 | { int z; for (z=0; z<s->session->master_key_length; z++) printf("%02X%c",s->session->master_key[z],((z+1)%16)?' ':'\n'); } | 476 | { int z; for (z=0; z<s->session->master_key_length; z++) printf("%02X%c",s->session->master_key[z],((z+1)%16)?' ':'\n'); } |
477 | #endif | 477 | #endif |
478 | tls1_generate_key_block(s,p1,p2,num); | 478 | tls1_generate_key_block(s,p1,p2,num); |
479 | memset(p2,0,num); | 479 | OPENSSL_cleanse(p2,num); |
480 | OPENSSL_free(p2); | 480 | OPENSSL_free(p2); |
481 | #ifdef TLS_DEBUG | 481 | #ifdef TLS_DEBUG |
482 | printf("\nkey block\n"); | 482 | printf("\nkey block\n"); |
@@ -683,10 +683,10 @@ int tls1_final_finish_mac(SSL *s, EVP_MD_CTX *in1_ctx, EVP_MD_CTX *in2_ctx, | |||
683 | 683 | ||
684 | tls1_PRF(s->ctx->md5,s->ctx->sha1,buf,(int)(q-buf), | 684 | tls1_PRF(s->ctx->md5,s->ctx->sha1,buf,(int)(q-buf), |
685 | s->session->master_key,s->session->master_key_length, | 685 | s->session->master_key,s->session->master_key_length, |
686 | out,buf2,12); | 686 | out,buf2,sizeof buf2); |
687 | EVP_MD_CTX_cleanup(&ctx); | 687 | EVP_MD_CTX_cleanup(&ctx); |
688 | 688 | ||
689 | return((int)12); | 689 | return sizeof buf2; |
690 | } | 690 | } |
691 | 691 | ||
692 | int tls1_mac(SSL *ssl, unsigned char *md, int send) | 692 | int tls1_mac(SSL *ssl, unsigned char *md, int send) |
@@ -773,7 +773,7 @@ int tls1_generate_master_secret(SSL *s, unsigned char *out, unsigned char *p, | |||
773 | s->s3->server_random,SSL3_RANDOM_SIZE); | 773 | s->s3->server_random,SSL3_RANDOM_SIZE); |
774 | tls1_PRF(s->ctx->md5,s->ctx->sha1, | 774 | tls1_PRF(s->ctx->md5,s->ctx->sha1, |
775 | buf,TLS_MD_MASTER_SECRET_CONST_SIZE+SSL3_RANDOM_SIZE*2,p,len, | 775 | buf,TLS_MD_MASTER_SECRET_CONST_SIZE+SSL3_RANDOM_SIZE*2,p,len, |
776 | s->session->master_key,buff,SSL3_MASTER_SECRET_SIZE); | 776 | s->session->master_key,buff,sizeof buff); |
777 | #ifdef KSSL_DEBUG | 777 | #ifdef KSSL_DEBUG |
778 | printf ("tls1_generate_master_secret() complete\n"); | 778 | printf ("tls1_generate_master_secret() complete\n"); |
779 | #endif /* KSSL_DEBUG */ | 779 | #endif /* KSSL_DEBUG */ |
diff --git a/src/lib/libssl/t1_meth.c b/src/lib/libssl/t1_meth.c index 9bb36a7d1c..fcc243f782 100644 --- a/src/lib/libssl/t1_meth.c +++ b/src/lib/libssl/t1_meth.c | |||
@@ -76,13 +76,21 @@ SSL_METHOD *TLSv1_method(void) | |||
76 | 76 | ||
77 | if (init) | 77 | if (init) |
78 | { | 78 | { |
79 | memcpy((char *)&TLSv1_data,(char *)tlsv1_base_method(), | 79 | CRYPTO_w_lock(CRYPTO_LOCK_SSL_METHOD); |
80 | sizeof(SSL_METHOD)); | 80 | |
81 | TLSv1_data.ssl_connect=ssl3_connect; | 81 | if (init) |
82 | TLSv1_data.ssl_accept=ssl3_accept; | 82 | { |
83 | TLSv1_data.get_ssl_method=tls1_get_method; | 83 | memcpy((char *)&TLSv1_data,(char *)tlsv1_base_method(), |
84 | init=0; | 84 | sizeof(SSL_METHOD)); |
85 | TLSv1_data.ssl_connect=ssl3_connect; | ||
86 | TLSv1_data.ssl_accept=ssl3_accept; | ||
87 | TLSv1_data.get_ssl_method=tls1_get_method; | ||
88 | init=0; | ||
89 | } | ||
90 | |||
91 | CRYPTO_w_unlock(CRYPTO_LOCK_SSL_METHOD); | ||
85 | } | 92 | } |
93 | |||
86 | return(&TLSv1_data); | 94 | return(&TLSv1_data); |
87 | } | 95 | } |
88 | 96 | ||
diff --git a/src/lib/libssl/t1_srvr.c b/src/lib/libssl/t1_srvr.c index 6e765e587f..1c1149e49f 100644 --- a/src/lib/libssl/t1_srvr.c +++ b/src/lib/libssl/t1_srvr.c | |||
@@ -80,11 +80,18 @@ SSL_METHOD *TLSv1_server_method(void) | |||
80 | 80 | ||
81 | if (init) | 81 | if (init) |
82 | { | 82 | { |
83 | memcpy((char *)&TLSv1_server_data,(char *)tlsv1_base_method(), | 83 | CRYPTO_w_lock(CRYPTO_LOCK_SSL_METHOD); |
84 | sizeof(SSL_METHOD)); | 84 | |
85 | TLSv1_server_data.ssl_accept=ssl3_accept; | 85 | if (init) |
86 | TLSv1_server_data.get_ssl_method=tls1_get_server_method; | 86 | { |
87 | init=0; | 87 | memcpy((char *)&TLSv1_server_data,(char *)tlsv1_base_method(), |
88 | sizeof(SSL_METHOD)); | ||
89 | TLSv1_server_data.ssl_accept=ssl3_accept; | ||
90 | TLSv1_server_data.get_ssl_method=tls1_get_server_method; | ||
91 | init=0; | ||
92 | } | ||
93 | |||
94 | CRYPTO_w_unlock(CRYPTO_LOCK_SSL_METHOD); | ||
88 | } | 95 | } |
89 | return(&TLSv1_server_data); | 96 | return(&TLSv1_server_data); |
90 | } | 97 | } |
diff --git a/src/lib/libssl/test/methtest.c b/src/lib/libssl/test/methtest.c index 06ccb3b310..005c2f4822 100644 --- a/src/lib/libssl/test/methtest.c +++ b/src/lib/libssl/test/methtest.c | |||
@@ -96,10 +96,10 @@ char *argv[]; | |||
96 | METH_init(top); | 96 | METH_init(top); |
97 | METH_control(tmp1,METH_CONTROL_DUMP,stdout); | 97 | METH_control(tmp1,METH_CONTROL_DUMP,stdout); |
98 | METH_control(tmp2,METH_CONTROL_DUMP,stdout); | 98 | METH_control(tmp2,METH_CONTROL_DUMP,stdout); |
99 | exit(0); | 99 | EXIT(0); |
100 | err: | 100 | err: |
101 | ERR_load_crypto_strings(); | 101 | ERR_load_crypto_strings(); |
102 | ERR_print_errors_fp(stderr); | 102 | ERR_print_errors_fp(stderr); |
103 | exit(1); | 103 | EXIT(1); |
104 | return(0); | 104 | return(0); |
105 | } | 105 | } |
diff --git a/src/lib/libssl/test/testgen b/src/lib/libssl/test/testgen index 55c496f4bc..3798543e04 100644 --- a/src/lib/libssl/test/testgen +++ b/src/lib/libssl/test/testgen | |||
@@ -27,6 +27,8 @@ fi | |||
27 | 27 | ||
28 | echo "This could take some time." | 28 | echo "This could take some time." |
29 | 29 | ||
30 | rm -f testkey.pem testreq.pem | ||
31 | |||
30 | ../apps/openssl req -config test.cnf $req_new -out testreq.pem | 32 | ../apps/openssl req -config test.cnf $req_new -out testreq.pem |
31 | if [ $? != 0 ]; then | 33 | if [ $? != 0 ]; then |
32 | echo problems creating request | 34 | echo problems creating request |
diff --git a/src/lib/libssl/test/testssl b/src/lib/libssl/test/testssl index ba5e41c861..ca8e718022 100644 --- a/src/lib/libssl/test/testssl +++ b/src/lib/libssl/test/testssl | |||
@@ -121,8 +121,12 @@ $ssltest -bio_pair -server_auth -client_auth -app_verify $CA $extra || exit 1 | |||
121 | 121 | ||
122 | ############################################################################# | 122 | ############################################################################# |
123 | 123 | ||
124 | echo test tls1 with 1024bit anonymous DH, multiple handshakes | 124 | if ../apps/openssl no-dh; then |
125 | $ssltest -v -bio_pair -tls1 -cipher ADH -dhe1024dsa -num 10 -f -time $extra || exit 1 | 125 | echo skipping anonymous DH tests |
126 | else | ||
127 | echo test tls1 with 1024bit anonymous DH, multiple handshakes | ||
128 | $ssltest -v -bio_pair -tls1 -cipher ADH -dhe1024dsa -num 10 -f -time $extra || exit 1 | ||
129 | fi | ||
126 | 130 | ||
127 | if ../apps/openssl no-rsa; then | 131 | if ../apps/openssl no-rsa; then |
128 | echo skipping RSA tests | 132 | echo skipping RSA tests |
@@ -130,8 +134,12 @@ else | |||
130 | echo test tls1 with 1024bit RSA, no DHE, multiple handshakes | 134 | echo test tls1 with 1024bit RSA, no DHE, multiple handshakes |
131 | ./ssltest -v -bio_pair -tls1 -cert ../apps/server2.pem -no_dhe -num 10 -f -time $extra || exit 1 | 135 | ./ssltest -v -bio_pair -tls1 -cert ../apps/server2.pem -no_dhe -num 10 -f -time $extra || exit 1 |
132 | 136 | ||
133 | echo test tls1 with 1024bit RSA, 1024bit DHE, multiple handshakes | 137 | if ../apps/openssl no-dh; then |
134 | ./ssltest -v -bio_pair -tls1 -cert ../apps/server2.pem -dhe1024dsa -num 10 -f -time $extra || exit 1 | 138 | echo skipping RSA+DHE tests |
139 | else | ||
140 | echo test tls1 with 1024bit RSA, 1024bit DHE, multiple handshakes | ||
141 | ./ssltest -v -bio_pair -tls1 -cert ../apps/server2.pem -dhe1024dsa -num 10 -f -time $extra || exit 1 | ||
142 | fi | ||
135 | fi | 143 | fi |
136 | 144 | ||
137 | exit 0 | 145 | exit 0 |