diff options
author | miod <> | 2014-04-13 15:16:40 +0000 |
---|---|---|
committer | miod <> | 2014-04-13 15:16:40 +0000 |
commit | 52628ee3f51f011b463aaedb1a28aa0524b43cb3 (patch) | |
tree | 4bd2adeac981051908ec5756401424bbb4e57d6a /src/lib/libcrypto/evp | |
parent | 40c22d3625a3818690c889ed6216fedf2be522c9 (diff) | |
download | openbsd-52628ee3f51f011b463aaedb1a28aa0524b43cb3.tar.gz openbsd-52628ee3f51f011b463aaedb1a28aa0524b43cb3.tar.bz2 openbsd-52628ee3f51f011b463aaedb1a28aa0524b43cb3.zip |
Import OpenSSL 1.0.1g
Diffstat (limited to 'src/lib/libcrypto/evp')
-rw-r--r-- | src/lib/libcrypto/evp/bio_b64.c | 2 | ||||
-rw-r--r-- | src/lib/libcrypto/evp/digest.c | 8 | ||||
-rw-r--r-- | src/lib/libcrypto/evp/e_aes.c | 21 | ||||
-rw-r--r-- | src/lib/libcrypto/evp/e_aes_cbc_hmac_sha1.c | 217 | ||||
-rw-r--r-- | src/lib/libcrypto/evp/e_des3.c | 6 | ||||
-rw-r--r-- | src/lib/libcrypto/evp/evp.h | 15 | ||||
-rw-r--r-- | src/lib/libcrypto/evp/evp_err.c | 6 | ||||
-rw-r--r-- | src/lib/libcrypto/evp/m_dss.c | 2 | ||||
-rw-r--r-- | src/lib/libcrypto/evp/m_dss1.c | 2 | ||||
-rw-r--r-- | src/lib/libcrypto/evp/m_sha1.c | 2 | ||||
-rw-r--r-- | src/lib/libcrypto/evp/p5_crpt2.c | 40 | ||||
-rw-r--r-- | src/lib/libcrypto/evp/p_sign.c | 2 | ||||
-rw-r--r-- | src/lib/libcrypto/evp/p_verify.c | 2 |
13 files changed, 273 insertions, 52 deletions
diff --git a/src/lib/libcrypto/evp/bio_b64.c b/src/lib/libcrypto/evp/bio_b64.c index 72a2a67277..ac6d441aad 100644 --- a/src/lib/libcrypto/evp/bio_b64.c +++ b/src/lib/libcrypto/evp/bio_b64.c | |||
@@ -264,7 +264,7 @@ static int b64_read(BIO *b, char *out, int outl) | |||
264 | } | 264 | } |
265 | 265 | ||
266 | /* we fell off the end without starting */ | 266 | /* we fell off the end without starting */ |
267 | if (j == i) | 267 | if ((j == i) && (num == 0)) |
268 | { | 268 | { |
269 | /* Is this is one long chunk?, if so, keep on | 269 | /* Is this is one long chunk?, if so, keep on |
270 | * reading until a new line. */ | 270 | * reading until a new line. */ |
diff --git a/src/lib/libcrypto/evp/digest.c b/src/lib/libcrypto/evp/digest.c index 467e6b5ae9..d14e8e48d5 100644 --- a/src/lib/libcrypto/evp/digest.c +++ b/src/lib/libcrypto/evp/digest.c | |||
@@ -267,6 +267,7 @@ int EVP_DigestFinal_ex(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *size) | |||
267 | return FIPS_digestfinal(ctx, md, size); | 267 | return FIPS_digestfinal(ctx, md, size); |
268 | #else | 268 | #else |
269 | int ret; | 269 | int ret; |
270 | |||
270 | OPENSSL_assert(ctx->digest->md_size <= EVP_MAX_MD_SIZE); | 271 | OPENSSL_assert(ctx->digest->md_size <= EVP_MAX_MD_SIZE); |
271 | ret=ctx->digest->final(ctx,md); | 272 | ret=ctx->digest->final(ctx,md); |
272 | if (size != NULL) | 273 | if (size != NULL) |
@@ -365,8 +366,11 @@ int EVP_Digest(const void *data, size_t count, | |||
365 | 366 | ||
366 | void EVP_MD_CTX_destroy(EVP_MD_CTX *ctx) | 367 | void EVP_MD_CTX_destroy(EVP_MD_CTX *ctx) |
367 | { | 368 | { |
368 | EVP_MD_CTX_cleanup(ctx); | 369 | if (ctx) |
369 | OPENSSL_free(ctx); | 370 | { |
371 | EVP_MD_CTX_cleanup(ctx); | ||
372 | OPENSSL_free(ctx); | ||
373 | } | ||
370 | } | 374 | } |
371 | 375 | ||
372 | /* This call frees resources associated with the context */ | 376 | /* This call frees resources associated with the context */ |
diff --git a/src/lib/libcrypto/evp/e_aes.c b/src/lib/libcrypto/evp/e_aes.c index 1e4af0cb75..c7869b69ef 100644 --- a/src/lib/libcrypto/evp/e_aes.c +++ b/src/lib/libcrypto/evp/e_aes.c | |||
@@ -842,7 +842,10 @@ static int aes_gcm_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | |||
842 | gctx->ctr = NULL; | 842 | gctx->ctr = NULL; |
843 | break; | 843 | break; |
844 | } | 844 | } |
845 | else | ||
845 | #endif | 846 | #endif |
847 | (void)0; /* terminate potentially open 'else' */ | ||
848 | |||
846 | AES_set_encrypt_key(key, ctx->key_len * 8, &gctx->ks); | 849 | AES_set_encrypt_key(key, ctx->key_len * 8, &gctx->ks); |
847 | CRYPTO_gcm128_init(&gctx->gcm, &gctx->ks, (block128_f)AES_encrypt); | 850 | CRYPTO_gcm128_init(&gctx->gcm, &gctx->ks, (block128_f)AES_encrypt); |
848 | #ifdef AES_CTR_ASM | 851 | #ifdef AES_CTR_ASM |
@@ -969,8 +972,6 @@ static int aes_gcm_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | |||
969 | 972 | ||
970 | if (!gctx->iv_set) | 973 | if (!gctx->iv_set) |
971 | return -1; | 974 | return -1; |
972 | if (!ctx->encrypt && gctx->taglen < 0) | ||
973 | return -1; | ||
974 | if (in) | 975 | if (in) |
975 | { | 976 | { |
976 | if (out == NULL) | 977 | if (out == NULL) |
@@ -1012,6 +1013,8 @@ static int aes_gcm_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | |||
1012 | { | 1013 | { |
1013 | if (!ctx->encrypt) | 1014 | if (!ctx->encrypt) |
1014 | { | 1015 | { |
1016 | if (gctx->taglen < 0) | ||
1017 | return -1; | ||
1015 | if (CRYPTO_gcm128_finish(&gctx->gcm, | 1018 | if (CRYPTO_gcm128_finish(&gctx->gcm, |
1016 | ctx->buf, gctx->taglen) != 0) | 1019 | ctx->buf, gctx->taglen) != 0) |
1017 | return -1; | 1020 | return -1; |
@@ -1083,14 +1086,17 @@ static int aes_xts_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | |||
1083 | xctx->xts.block1 = (block128_f)vpaes_decrypt; | 1086 | xctx->xts.block1 = (block128_f)vpaes_decrypt; |
1084 | } | 1087 | } |
1085 | 1088 | ||
1086 | vpaes_set_encrypt_key(key + ctx->key_len/2, | 1089 | vpaes_set_encrypt_key(key + ctx->key_len/2, |
1087 | ctx->key_len * 4, &xctx->ks2); | 1090 | ctx->key_len * 4, &xctx->ks2); |
1088 | xctx->xts.block2 = (block128_f)vpaes_encrypt; | 1091 | xctx->xts.block2 = (block128_f)vpaes_encrypt; |
1089 | 1092 | ||
1090 | xctx->xts.key1 = &xctx->ks1; | 1093 | xctx->xts.key1 = &xctx->ks1; |
1091 | break; | 1094 | break; |
1092 | } | 1095 | } |
1096 | else | ||
1093 | #endif | 1097 | #endif |
1098 | (void)0; /* terminate potentially open 'else' */ | ||
1099 | |||
1094 | if (enc) | 1100 | if (enc) |
1095 | { | 1101 | { |
1096 | AES_set_encrypt_key(key, ctx->key_len * 4, &xctx->ks1); | 1102 | AES_set_encrypt_key(key, ctx->key_len * 4, &xctx->ks1); |
@@ -1217,6 +1223,7 @@ static int aes_ccm_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, | |||
1217 | vpaes_set_encrypt_key(key, ctx->key_len*8, &cctx->ks); | 1223 | vpaes_set_encrypt_key(key, ctx->key_len*8, &cctx->ks); |
1218 | CRYPTO_ccm128_init(&cctx->ccm, cctx->M, cctx->L, | 1224 | CRYPTO_ccm128_init(&cctx->ccm, cctx->M, cctx->L, |
1219 | &cctx->ks, (block128_f)vpaes_encrypt); | 1225 | &cctx->ks, (block128_f)vpaes_encrypt); |
1226 | cctx->str = NULL; | ||
1220 | cctx->key_set = 1; | 1227 | cctx->key_set = 1; |
1221 | break; | 1228 | break; |
1222 | } | 1229 | } |
diff --git a/src/lib/libcrypto/evp/e_aes_cbc_hmac_sha1.c b/src/lib/libcrypto/evp/e_aes_cbc_hmac_sha1.c index 710fb79baf..fb2c884a78 100644 --- a/src/lib/libcrypto/evp/e_aes_cbc_hmac_sha1.c +++ b/src/lib/libcrypto/evp/e_aes_cbc_hmac_sha1.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* ==================================================================== | 1 | /* ==================================================================== |
2 | * Copyright (c) 2011 The OpenSSL Project. All rights reserved. | 2 | * Copyright (c) 2011-2013 The OpenSSL Project. All rights reserved. |
3 | * | 3 | * |
4 | * Redistribution and use in source and binary forms, with or without | 4 | * Redistribution and use in source and binary forms, with or without |
5 | * modification, are permitted provided that the following conditions | 5 | * modification, are permitted provided that the following conditions |
@@ -90,6 +90,10 @@ typedef struct | |||
90 | defined(_M_AMD64) || defined(_M_X64) || \ | 90 | defined(_M_AMD64) || defined(_M_X64) || \ |
91 | defined(__INTEL__) ) | 91 | defined(__INTEL__) ) |
92 | 92 | ||
93 | #if defined(__GNUC__) && __GNUC__>=2 && !defined(PEDANTIC) | ||
94 | # define BSWAP(x) ({ unsigned int r=(x); asm ("bswapl %0":"=r"(r):"0"(r)); r; }) | ||
95 | #endif | ||
96 | |||
93 | extern unsigned int OPENSSL_ia32cap_P[2]; | 97 | extern unsigned int OPENSSL_ia32cap_P[2]; |
94 | #define AESNI_CAPABLE (1<<(57-32)) | 98 | #define AESNI_CAPABLE (1<<(57-32)) |
95 | 99 | ||
@@ -167,6 +171,9 @@ static void sha1_update(SHA_CTX *c,const void *data,size_t len) | |||
167 | SHA1_Update(c,ptr,res); | 171 | SHA1_Update(c,ptr,res); |
168 | } | 172 | } |
169 | 173 | ||
174 | #ifdef SHA1_Update | ||
175 | #undef SHA1_Update | ||
176 | #endif | ||
170 | #define SHA1_Update sha1_update | 177 | #define SHA1_Update sha1_update |
171 | 178 | ||
172 | static int aesni_cbc_hmac_sha1_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | 179 | static int aesni_cbc_hmac_sha1_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, |
@@ -184,6 +191,8 @@ static int aesni_cbc_hmac_sha1_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | |||
184 | sha_off = SHA_CBLOCK-key->md.num; | 191 | sha_off = SHA_CBLOCK-key->md.num; |
185 | #endif | 192 | #endif |
186 | 193 | ||
194 | key->payload_length = NO_PAYLOAD_LENGTH; | ||
195 | |||
187 | if (len%AES_BLOCK_SIZE) return 0; | 196 | if (len%AES_BLOCK_SIZE) return 0; |
188 | 197 | ||
189 | if (ctx->encrypt) { | 198 | if (ctx->encrypt) { |
@@ -234,47 +243,211 @@ static int aesni_cbc_hmac_sha1_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | |||
234 | &key->ks,ctx->iv,1); | 243 | &key->ks,ctx->iv,1); |
235 | } | 244 | } |
236 | } else { | 245 | } else { |
237 | unsigned char mac[SHA_DIGEST_LENGTH]; | 246 | union { unsigned int u[SHA_DIGEST_LENGTH/sizeof(unsigned int)]; |
247 | unsigned char c[32+SHA_DIGEST_LENGTH]; } mac, *pmac; | ||
248 | |||
249 | /* arrange cache line alignment */ | ||
250 | pmac = (void *)(((size_t)mac.c+31)&((size_t)0-32)); | ||
238 | 251 | ||
239 | /* decrypt HMAC|padding at once */ | 252 | /* decrypt HMAC|padding at once */ |
240 | aesni_cbc_encrypt(in,out,len, | 253 | aesni_cbc_encrypt(in,out,len, |
241 | &key->ks,ctx->iv,0); | 254 | &key->ks,ctx->iv,0); |
242 | 255 | ||
243 | if (plen) { /* "TLS" mode of operation */ | 256 | if (plen) { /* "TLS" mode of operation */ |
244 | /* figure out payload length */ | 257 | size_t inp_len, mask, j, i; |
245 | if (len<(size_t)(out[len-1]+1+SHA_DIGEST_LENGTH)) | 258 | unsigned int res, maxpad, pad, bitlen; |
246 | return 0; | 259 | int ret = 1; |
247 | 260 | union { unsigned int u[SHA_LBLOCK]; | |
248 | len -= (out[len-1]+1+SHA_DIGEST_LENGTH); | 261 | unsigned char c[SHA_CBLOCK]; } |
262 | *data = (void *)key->md.data; | ||
249 | 263 | ||
250 | if ((key->aux.tls_aad[plen-4]<<8|key->aux.tls_aad[plen-3]) | 264 | if ((key->aux.tls_aad[plen-4]<<8|key->aux.tls_aad[plen-3]) |
251 | >= TLS1_1_VERSION) { | 265 | >= TLS1_1_VERSION) |
252 | len -= AES_BLOCK_SIZE; | ||
253 | iv = AES_BLOCK_SIZE; | 266 | iv = AES_BLOCK_SIZE; |
254 | } | ||
255 | 267 | ||
256 | key->aux.tls_aad[plen-2] = len>>8; | 268 | if (len<(iv+SHA_DIGEST_LENGTH+1)) |
257 | key->aux.tls_aad[plen-1] = len; | 269 | return 0; |
270 | |||
271 | /* omit explicit iv */ | ||
272 | out += iv; | ||
273 | len -= iv; | ||
274 | |||
275 | /* figure out payload length */ | ||
276 | pad = out[len-1]; | ||
277 | maxpad = len-(SHA_DIGEST_LENGTH+1); | ||
278 | maxpad |= (255-maxpad)>>(sizeof(maxpad)*8-8); | ||
279 | maxpad &= 255; | ||
280 | |||
281 | inp_len = len - (SHA_DIGEST_LENGTH+pad+1); | ||
282 | mask = (0-((inp_len-len)>>(sizeof(inp_len)*8-1))); | ||
283 | inp_len &= mask; | ||
284 | ret &= (int)mask; | ||
285 | |||
286 | key->aux.tls_aad[plen-2] = inp_len>>8; | ||
287 | key->aux.tls_aad[plen-1] = inp_len; | ||
258 | 288 | ||
259 | /* calculate HMAC and verify it */ | 289 | /* calculate HMAC */ |
260 | key->md = key->head; | 290 | key->md = key->head; |
261 | SHA1_Update(&key->md,key->aux.tls_aad,plen); | 291 | SHA1_Update(&key->md,key->aux.tls_aad,plen); |
262 | SHA1_Update(&key->md,out+iv,len); | ||
263 | SHA1_Final(mac,&key->md); | ||
264 | 292 | ||
293 | #if 1 | ||
294 | len -= SHA_DIGEST_LENGTH; /* amend mac */ | ||
295 | if (len>=(256+SHA_CBLOCK)) { | ||
296 | j = (len-(256+SHA_CBLOCK))&(0-SHA_CBLOCK); | ||
297 | j += SHA_CBLOCK-key->md.num; | ||
298 | SHA1_Update(&key->md,out,j); | ||
299 | out += j; | ||
300 | len -= j; | ||
301 | inp_len -= j; | ||
302 | } | ||
303 | |||
304 | /* but pretend as if we hashed padded payload */ | ||
305 | bitlen = key->md.Nl+(inp_len<<3); /* at most 18 bits */ | ||
306 | #ifdef BSWAP | ||
307 | bitlen = BSWAP(bitlen); | ||
308 | #else | ||
309 | mac.c[0] = 0; | ||
310 | mac.c[1] = (unsigned char)(bitlen>>16); | ||
311 | mac.c[2] = (unsigned char)(bitlen>>8); | ||
312 | mac.c[3] = (unsigned char)bitlen; | ||
313 | bitlen = mac.u[0]; | ||
314 | #endif | ||
315 | |||
316 | pmac->u[0]=0; | ||
317 | pmac->u[1]=0; | ||
318 | pmac->u[2]=0; | ||
319 | pmac->u[3]=0; | ||
320 | pmac->u[4]=0; | ||
321 | |||
322 | for (res=key->md.num, j=0;j<len;j++) { | ||
323 | size_t c = out[j]; | ||
324 | mask = (j-inp_len)>>(sizeof(j)*8-8); | ||
325 | c &= mask; | ||
326 | c |= 0x80&~mask&~((inp_len-j)>>(sizeof(j)*8-8)); | ||
327 | data->c[res++]=(unsigned char)c; | ||
328 | |||
329 | if (res!=SHA_CBLOCK) continue; | ||
330 | |||
331 | /* j is not incremented yet */ | ||
332 | mask = 0-((inp_len+7-j)>>(sizeof(j)*8-1)); | ||
333 | data->u[SHA_LBLOCK-1] |= bitlen&mask; | ||
334 | sha1_block_data_order(&key->md,data,1); | ||
335 | mask &= 0-((j-inp_len-72)>>(sizeof(j)*8-1)); | ||
336 | pmac->u[0] |= key->md.h0 & mask; | ||
337 | pmac->u[1] |= key->md.h1 & mask; | ||
338 | pmac->u[2] |= key->md.h2 & mask; | ||
339 | pmac->u[3] |= key->md.h3 & mask; | ||
340 | pmac->u[4] |= key->md.h4 & mask; | ||
341 | res=0; | ||
342 | } | ||
343 | |||
344 | for(i=res;i<SHA_CBLOCK;i++,j++) data->c[i]=0; | ||
345 | |||
346 | if (res>SHA_CBLOCK-8) { | ||
347 | mask = 0-((inp_len+8-j)>>(sizeof(j)*8-1)); | ||
348 | data->u[SHA_LBLOCK-1] |= bitlen&mask; | ||
349 | sha1_block_data_order(&key->md,data,1); | ||
350 | mask &= 0-((j-inp_len-73)>>(sizeof(j)*8-1)); | ||
351 | pmac->u[0] |= key->md.h0 & mask; | ||
352 | pmac->u[1] |= key->md.h1 & mask; | ||
353 | pmac->u[2] |= key->md.h2 & mask; | ||
354 | pmac->u[3] |= key->md.h3 & mask; | ||
355 | pmac->u[4] |= key->md.h4 & mask; | ||
356 | |||
357 | memset(data,0,SHA_CBLOCK); | ||
358 | j+=64; | ||
359 | } | ||
360 | data->u[SHA_LBLOCK-1] = bitlen; | ||
361 | sha1_block_data_order(&key->md,data,1); | ||
362 | mask = 0-((j-inp_len-73)>>(sizeof(j)*8-1)); | ||
363 | pmac->u[0] |= key->md.h0 & mask; | ||
364 | pmac->u[1] |= key->md.h1 & mask; | ||
365 | pmac->u[2] |= key->md.h2 & mask; | ||
366 | pmac->u[3] |= key->md.h3 & mask; | ||
367 | pmac->u[4] |= key->md.h4 & mask; | ||
368 | |||
369 | #ifdef BSWAP | ||
370 | pmac->u[0] = BSWAP(pmac->u[0]); | ||
371 | pmac->u[1] = BSWAP(pmac->u[1]); | ||
372 | pmac->u[2] = BSWAP(pmac->u[2]); | ||
373 | pmac->u[3] = BSWAP(pmac->u[3]); | ||
374 | pmac->u[4] = BSWAP(pmac->u[4]); | ||
375 | #else | ||
376 | for (i=0;i<5;i++) { | ||
377 | res = pmac->u[i]; | ||
378 | pmac->c[4*i+0]=(unsigned char)(res>>24); | ||
379 | pmac->c[4*i+1]=(unsigned char)(res>>16); | ||
380 | pmac->c[4*i+2]=(unsigned char)(res>>8); | ||
381 | pmac->c[4*i+3]=(unsigned char)res; | ||
382 | } | ||
383 | #endif | ||
384 | len += SHA_DIGEST_LENGTH; | ||
385 | #else | ||
386 | SHA1_Update(&key->md,out,inp_len); | ||
387 | res = key->md.num; | ||
388 | SHA1_Final(pmac->c,&key->md); | ||
389 | |||
390 | { | ||
391 | unsigned int inp_blocks, pad_blocks; | ||
392 | |||
393 | /* but pretend as if we hashed padded payload */ | ||
394 | inp_blocks = 1+((SHA_CBLOCK-9-res)>>(sizeof(res)*8-1)); | ||
395 | res += (unsigned int)(len-inp_len); | ||
396 | pad_blocks = res / SHA_CBLOCK; | ||
397 | res %= SHA_CBLOCK; | ||
398 | pad_blocks += 1+((SHA_CBLOCK-9-res)>>(sizeof(res)*8-1)); | ||
399 | for (;inp_blocks<pad_blocks;inp_blocks++) | ||
400 | sha1_block_data_order(&key->md,data,1); | ||
401 | } | ||
402 | #endif | ||
265 | key->md = key->tail; | 403 | key->md = key->tail; |
266 | SHA1_Update(&key->md,mac,SHA_DIGEST_LENGTH); | 404 | SHA1_Update(&key->md,pmac->c,SHA_DIGEST_LENGTH); |
267 | SHA1_Final(mac,&key->md); | 405 | SHA1_Final(pmac->c,&key->md); |
268 | 406 | ||
269 | if (memcmp(out+iv+len,mac,SHA_DIGEST_LENGTH)) | 407 | /* verify HMAC */ |
270 | return 0; | 408 | out += inp_len; |
409 | len -= inp_len; | ||
410 | #if 1 | ||
411 | { | ||
412 | unsigned char *p = out+len-1-maxpad-SHA_DIGEST_LENGTH; | ||
413 | size_t off = out-p; | ||
414 | unsigned int c, cmask; | ||
415 | |||
416 | maxpad += SHA_DIGEST_LENGTH; | ||
417 | for (res=0,i=0,j=0;j<maxpad;j++) { | ||
418 | c = p[j]; | ||
419 | cmask = ((int)(j-off-SHA_DIGEST_LENGTH))>>(sizeof(int)*8-1); | ||
420 | res |= (c^pad)&~cmask; /* ... and padding */ | ||
421 | cmask &= ((int)(off-1-j))>>(sizeof(int)*8-1); | ||
422 | res |= (c^pmac->c[i])&cmask; | ||
423 | i += 1&cmask; | ||
424 | } | ||
425 | maxpad -= SHA_DIGEST_LENGTH; | ||
426 | |||
427 | res = 0-((0-res)>>(sizeof(res)*8-1)); | ||
428 | ret &= (int)~res; | ||
429 | } | ||
430 | #else | ||
431 | for (res=0,i=0;i<SHA_DIGEST_LENGTH;i++) | ||
432 | res |= out[i]^pmac->c[i]; | ||
433 | res = 0-((0-res)>>(sizeof(res)*8-1)); | ||
434 | ret &= (int)~res; | ||
435 | |||
436 | /* verify padding */ | ||
437 | pad = (pad&~res) | (maxpad&res); | ||
438 | out = out+len-1-pad; | ||
439 | for (res=0,i=0;i<pad;i++) | ||
440 | res |= out[i]^pad; | ||
441 | |||
442 | res = (0-res)>>(sizeof(res)*8-1); | ||
443 | ret &= (int)~res; | ||
444 | #endif | ||
445 | return ret; | ||
271 | } else { | 446 | } else { |
272 | SHA1_Update(&key->md,out,len); | 447 | SHA1_Update(&key->md,out,len); |
273 | } | 448 | } |
274 | } | 449 | } |
275 | 450 | ||
276 | key->payload_length = NO_PAYLOAD_LENGTH; | ||
277 | |||
278 | return 1; | 451 | return 1; |
279 | } | 452 | } |
280 | 453 | ||
@@ -309,6 +482,8 @@ static int aesni_cbc_hmac_sha1_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void | |||
309 | SHA1_Init(&key->tail); | 482 | SHA1_Init(&key->tail); |
310 | SHA1_Update(&key->tail,hmac_key,sizeof(hmac_key)); | 483 | SHA1_Update(&key->tail,hmac_key,sizeof(hmac_key)); |
311 | 484 | ||
485 | OPENSSL_cleanse(hmac_key,sizeof(hmac_key)); | ||
486 | |||
312 | return 1; | 487 | return 1; |
313 | } | 488 | } |
314 | case EVP_CTRL_AEAD_TLS1_AAD: | 489 | case EVP_CTRL_AEAD_TLS1_AAD: |
diff --git a/src/lib/libcrypto/evp/e_des3.c b/src/lib/libcrypto/evp/e_des3.c index 1e69972662..8d7b7de292 100644 --- a/src/lib/libcrypto/evp/e_des3.c +++ b/src/lib/libcrypto/evp/e_des3.c | |||
@@ -101,7 +101,7 @@ static int des_ede_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | |||
101 | static int des_ede_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | 101 | static int des_ede_ofb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, |
102 | const unsigned char *in, size_t inl) | 102 | const unsigned char *in, size_t inl) |
103 | { | 103 | { |
104 | if (inl>=EVP_MAXCHUNK) | 104 | while (inl>=EVP_MAXCHUNK) |
105 | { | 105 | { |
106 | DES_ede3_ofb64_encrypt(in, out, (long)EVP_MAXCHUNK, | 106 | DES_ede3_ofb64_encrypt(in, out, (long)EVP_MAXCHUNK, |
107 | &data(ctx)->ks1, &data(ctx)->ks2, &data(ctx)->ks3, | 107 | &data(ctx)->ks1, &data(ctx)->ks2, &data(ctx)->ks3, |
@@ -132,7 +132,7 @@ static int des_ede_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | |||
132 | printf("\n"); | 132 | printf("\n"); |
133 | } | 133 | } |
134 | #endif /* KSSL_DEBUG */ | 134 | #endif /* KSSL_DEBUG */ |
135 | if (inl>=EVP_MAXCHUNK) | 135 | while (inl>=EVP_MAXCHUNK) |
136 | { | 136 | { |
137 | DES_ede3_cbc_encrypt(in, out, (long)EVP_MAXCHUNK, | 137 | DES_ede3_cbc_encrypt(in, out, (long)EVP_MAXCHUNK, |
138 | &data(ctx)->ks1, &data(ctx)->ks2, &data(ctx)->ks3, | 138 | &data(ctx)->ks1, &data(ctx)->ks2, &data(ctx)->ks3, |
@@ -151,7 +151,7 @@ static int des_ede_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | |||
151 | static int des_ede_cfb64_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, | 151 | static int des_ede_cfb64_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, |
152 | const unsigned char *in, size_t inl) | 152 | const unsigned char *in, size_t inl) |
153 | { | 153 | { |
154 | if (inl>=EVP_MAXCHUNK) | 154 | while (inl>=EVP_MAXCHUNK) |
155 | { | 155 | { |
156 | DES_ede3_cfb64_encrypt(in, out, (long)EVP_MAXCHUNK, | 156 | DES_ede3_cfb64_encrypt(in, out, (long)EVP_MAXCHUNK, |
157 | &data(ctx)->ks1, &data(ctx)->ks2, &data(ctx)->ks3, | 157 | &data(ctx)->ks1, &data(ctx)->ks2, &data(ctx)->ks3, |
diff --git a/src/lib/libcrypto/evp/evp.h b/src/lib/libcrypto/evp/evp.h index 0d1b20a7d3..faeb3c24e6 100644 --- a/src/lib/libcrypto/evp/evp.h +++ b/src/lib/libcrypto/evp/evp.h | |||
@@ -402,7 +402,6 @@ struct evp_cipher_st | |||
402 | /* Length of tag for TLS */ | 402 | /* Length of tag for TLS */ |
403 | #define EVP_GCM_TLS_TAG_LEN 16 | 403 | #define EVP_GCM_TLS_TAG_LEN 16 |
404 | 404 | ||
405 | |||
406 | typedef struct evp_cipher_info_st | 405 | typedef struct evp_cipher_info_st |
407 | { | 406 | { |
408 | const EVP_CIPHER *cipher; | 407 | const EVP_CIPHER *cipher; |
@@ -789,8 +788,8 @@ const EVP_CIPHER *EVP_aes_128_cfb128(void); | |||
789 | # define EVP_aes_128_cfb EVP_aes_128_cfb128 | 788 | # define EVP_aes_128_cfb EVP_aes_128_cfb128 |
790 | const EVP_CIPHER *EVP_aes_128_ofb(void); | 789 | const EVP_CIPHER *EVP_aes_128_ofb(void); |
791 | const EVP_CIPHER *EVP_aes_128_ctr(void); | 790 | const EVP_CIPHER *EVP_aes_128_ctr(void); |
792 | const EVP_CIPHER *EVP_aes_128_gcm(void); | ||
793 | const EVP_CIPHER *EVP_aes_128_ccm(void); | 791 | const EVP_CIPHER *EVP_aes_128_ccm(void); |
792 | const EVP_CIPHER *EVP_aes_128_gcm(void); | ||
794 | const EVP_CIPHER *EVP_aes_128_xts(void); | 793 | const EVP_CIPHER *EVP_aes_128_xts(void); |
795 | const EVP_CIPHER *EVP_aes_192_ecb(void); | 794 | const EVP_CIPHER *EVP_aes_192_ecb(void); |
796 | const EVP_CIPHER *EVP_aes_192_cbc(void); | 795 | const EVP_CIPHER *EVP_aes_192_cbc(void); |
@@ -800,8 +799,8 @@ const EVP_CIPHER *EVP_aes_192_cfb128(void); | |||
800 | # define EVP_aes_192_cfb EVP_aes_192_cfb128 | 799 | # define EVP_aes_192_cfb EVP_aes_192_cfb128 |
801 | const EVP_CIPHER *EVP_aes_192_ofb(void); | 800 | const EVP_CIPHER *EVP_aes_192_ofb(void); |
802 | const EVP_CIPHER *EVP_aes_192_ctr(void); | 801 | const EVP_CIPHER *EVP_aes_192_ctr(void); |
803 | const EVP_CIPHER *EVP_aes_192_gcm(void); | ||
804 | const EVP_CIPHER *EVP_aes_192_ccm(void); | 802 | const EVP_CIPHER *EVP_aes_192_ccm(void); |
803 | const EVP_CIPHER *EVP_aes_192_gcm(void); | ||
805 | const EVP_CIPHER *EVP_aes_256_ecb(void); | 804 | const EVP_CIPHER *EVP_aes_256_ecb(void); |
806 | const EVP_CIPHER *EVP_aes_256_cbc(void); | 805 | const EVP_CIPHER *EVP_aes_256_cbc(void); |
807 | const EVP_CIPHER *EVP_aes_256_cfb1(void); | 806 | const EVP_CIPHER *EVP_aes_256_cfb1(void); |
@@ -810,8 +809,8 @@ const EVP_CIPHER *EVP_aes_256_cfb128(void); | |||
810 | # define EVP_aes_256_cfb EVP_aes_256_cfb128 | 809 | # define EVP_aes_256_cfb EVP_aes_256_cfb128 |
811 | const EVP_CIPHER *EVP_aes_256_ofb(void); | 810 | const EVP_CIPHER *EVP_aes_256_ofb(void); |
812 | const EVP_CIPHER *EVP_aes_256_ctr(void); | 811 | const EVP_CIPHER *EVP_aes_256_ctr(void); |
813 | const EVP_CIPHER *EVP_aes_256_gcm(void); | ||
814 | const EVP_CIPHER *EVP_aes_256_ccm(void); | 812 | const EVP_CIPHER *EVP_aes_256_ccm(void); |
813 | const EVP_CIPHER *EVP_aes_256_gcm(void); | ||
815 | const EVP_CIPHER *EVP_aes_256_xts(void); | 814 | const EVP_CIPHER *EVP_aes_256_xts(void); |
816 | #if !defined(OPENSSL_NO_SHA) && !defined(OPENSSL_NO_SHA1) | 815 | #if !defined(OPENSSL_NO_SHA) && !defined(OPENSSL_NO_SHA1) |
817 | const EVP_CIPHER *EVP_aes_128_cbc_hmac_sha1(void); | 816 | const EVP_CIPHER *EVP_aes_128_cbc_hmac_sha1(void); |
@@ -1243,6 +1242,8 @@ void EVP_PKEY_meth_set_ctrl(EVP_PKEY_METHOD *pmeth, | |||
1243 | int (*ctrl_str)(EVP_PKEY_CTX *ctx, | 1242 | int (*ctrl_str)(EVP_PKEY_CTX *ctx, |
1244 | const char *type, const char *value)); | 1243 | const char *type, const char *value)); |
1245 | 1244 | ||
1245 | void EVP_add_alg_module(void); | ||
1246 | |||
1246 | /* BEGIN ERROR CODES */ | 1247 | /* BEGIN ERROR CODES */ |
1247 | /* The following lines are auto generated by the script mkerr.pl. Any changes | 1248 | /* The following lines are auto generated by the script mkerr.pl. Any changes |
1248 | * made after this point may be overwritten when the script is next run. | 1249 | * made after this point may be overwritten when the script is next run. |
@@ -1257,6 +1258,7 @@ void ERR_load_EVP_strings(void); | |||
1257 | #define EVP_F_AES_INIT_KEY 133 | 1258 | #define EVP_F_AES_INIT_KEY 133 |
1258 | #define EVP_F_AES_XTS 172 | 1259 | #define EVP_F_AES_XTS 172 |
1259 | #define EVP_F_AES_XTS_CIPHER 175 | 1260 | #define EVP_F_AES_XTS_CIPHER 175 |
1261 | #define EVP_F_ALG_MODULE_INIT 177 | ||
1260 | #define EVP_F_CAMELLIA_INIT_KEY 159 | 1262 | #define EVP_F_CAMELLIA_INIT_KEY 159 |
1261 | #define EVP_F_CMAC_INIT 173 | 1263 | #define EVP_F_CMAC_INIT 173 |
1262 | #define EVP_F_D2I_PKEY 100 | 1264 | #define EVP_F_D2I_PKEY 100 |
@@ -1350,15 +1352,19 @@ void ERR_load_EVP_strings(void); | |||
1350 | #define EVP_R_DIFFERENT_PARAMETERS 153 | 1352 | #define EVP_R_DIFFERENT_PARAMETERS 153 |
1351 | #define EVP_R_DISABLED_FOR_FIPS 163 | 1353 | #define EVP_R_DISABLED_FOR_FIPS 163 |
1352 | #define EVP_R_ENCODE_ERROR 115 | 1354 | #define EVP_R_ENCODE_ERROR 115 |
1355 | #define EVP_R_ERROR_LOADING_SECTION 165 | ||
1356 | #define EVP_R_ERROR_SETTING_FIPS_MODE 166 | ||
1353 | #define EVP_R_EVP_PBE_CIPHERINIT_ERROR 119 | 1357 | #define EVP_R_EVP_PBE_CIPHERINIT_ERROR 119 |
1354 | #define EVP_R_EXPECTING_AN_RSA_KEY 127 | 1358 | #define EVP_R_EXPECTING_AN_RSA_KEY 127 |
1355 | #define EVP_R_EXPECTING_A_DH_KEY 128 | 1359 | #define EVP_R_EXPECTING_A_DH_KEY 128 |
1356 | #define EVP_R_EXPECTING_A_DSA_KEY 129 | 1360 | #define EVP_R_EXPECTING_A_DSA_KEY 129 |
1357 | #define EVP_R_EXPECTING_A_ECDSA_KEY 141 | 1361 | #define EVP_R_EXPECTING_A_ECDSA_KEY 141 |
1358 | #define EVP_R_EXPECTING_A_EC_KEY 142 | 1362 | #define EVP_R_EXPECTING_A_EC_KEY 142 |
1363 | #define EVP_R_FIPS_MODE_NOT_SUPPORTED 167 | ||
1359 | #define EVP_R_INITIALIZATION_ERROR 134 | 1364 | #define EVP_R_INITIALIZATION_ERROR 134 |
1360 | #define EVP_R_INPUT_NOT_INITIALIZED 111 | 1365 | #define EVP_R_INPUT_NOT_INITIALIZED 111 |
1361 | #define EVP_R_INVALID_DIGEST 152 | 1366 | #define EVP_R_INVALID_DIGEST 152 |
1367 | #define EVP_R_INVALID_FIPS_MODE 168 | ||
1362 | #define EVP_R_INVALID_KEY_LENGTH 130 | 1368 | #define EVP_R_INVALID_KEY_LENGTH 130 |
1363 | #define EVP_R_INVALID_OPERATION 148 | 1369 | #define EVP_R_INVALID_OPERATION 148 |
1364 | #define EVP_R_IV_TOO_LARGE 102 | 1370 | #define EVP_R_IV_TOO_LARGE 102 |
@@ -1383,6 +1389,7 @@ void ERR_load_EVP_strings(void); | |||
1383 | #define EVP_R_TOO_LARGE 164 | 1389 | #define EVP_R_TOO_LARGE 164 |
1384 | #define EVP_R_UNKNOWN_CIPHER 160 | 1390 | #define EVP_R_UNKNOWN_CIPHER 160 |
1385 | #define EVP_R_UNKNOWN_DIGEST 161 | 1391 | #define EVP_R_UNKNOWN_DIGEST 161 |
1392 | #define EVP_R_UNKNOWN_OPTION 169 | ||
1386 | #define EVP_R_UNKNOWN_PBE_ALGORITHM 121 | 1393 | #define EVP_R_UNKNOWN_PBE_ALGORITHM 121 |
1387 | #define EVP_R_UNSUPORTED_NUMBER_OF_ROUNDS 135 | 1394 | #define EVP_R_UNSUPORTED_NUMBER_OF_ROUNDS 135 |
1388 | #define EVP_R_UNSUPPORTED_ALGORITHM 156 | 1395 | #define EVP_R_UNSUPPORTED_ALGORITHM 156 |
diff --git a/src/lib/libcrypto/evp/evp_err.c b/src/lib/libcrypto/evp/evp_err.c index db0f76d59b..08eab9882f 100644 --- a/src/lib/libcrypto/evp/evp_err.c +++ b/src/lib/libcrypto/evp/evp_err.c | |||
@@ -75,6 +75,7 @@ static ERR_STRING_DATA EVP_str_functs[]= | |||
75 | {ERR_FUNC(EVP_F_AES_INIT_KEY), "AES_INIT_KEY"}, | 75 | {ERR_FUNC(EVP_F_AES_INIT_KEY), "AES_INIT_KEY"}, |
76 | {ERR_FUNC(EVP_F_AES_XTS), "AES_XTS"}, | 76 | {ERR_FUNC(EVP_F_AES_XTS), "AES_XTS"}, |
77 | {ERR_FUNC(EVP_F_AES_XTS_CIPHER), "AES_XTS_CIPHER"}, | 77 | {ERR_FUNC(EVP_F_AES_XTS_CIPHER), "AES_XTS_CIPHER"}, |
78 | {ERR_FUNC(EVP_F_ALG_MODULE_INIT), "ALG_MODULE_INIT"}, | ||
78 | {ERR_FUNC(EVP_F_CAMELLIA_INIT_KEY), "CAMELLIA_INIT_KEY"}, | 79 | {ERR_FUNC(EVP_F_CAMELLIA_INIT_KEY), "CAMELLIA_INIT_KEY"}, |
79 | {ERR_FUNC(EVP_F_CMAC_INIT), "CMAC_INIT"}, | 80 | {ERR_FUNC(EVP_F_CMAC_INIT), "CMAC_INIT"}, |
80 | {ERR_FUNC(EVP_F_D2I_PKEY), "D2I_PKEY"}, | 81 | {ERR_FUNC(EVP_F_D2I_PKEY), "D2I_PKEY"}, |
@@ -171,15 +172,19 @@ static ERR_STRING_DATA EVP_str_reasons[]= | |||
171 | {ERR_REASON(EVP_R_DIFFERENT_PARAMETERS) ,"different parameters"}, | 172 | {ERR_REASON(EVP_R_DIFFERENT_PARAMETERS) ,"different parameters"}, |
172 | {ERR_REASON(EVP_R_DISABLED_FOR_FIPS) ,"disabled for fips"}, | 173 | {ERR_REASON(EVP_R_DISABLED_FOR_FIPS) ,"disabled for fips"}, |
173 | {ERR_REASON(EVP_R_ENCODE_ERROR) ,"encode error"}, | 174 | {ERR_REASON(EVP_R_ENCODE_ERROR) ,"encode error"}, |
175 | {ERR_REASON(EVP_R_ERROR_LOADING_SECTION) ,"error loading section"}, | ||
176 | {ERR_REASON(EVP_R_ERROR_SETTING_FIPS_MODE),"error setting fips mode"}, | ||
174 | {ERR_REASON(EVP_R_EVP_PBE_CIPHERINIT_ERROR),"evp pbe cipherinit error"}, | 177 | {ERR_REASON(EVP_R_EVP_PBE_CIPHERINIT_ERROR),"evp pbe cipherinit error"}, |
175 | {ERR_REASON(EVP_R_EXPECTING_AN_RSA_KEY) ,"expecting an rsa key"}, | 178 | {ERR_REASON(EVP_R_EXPECTING_AN_RSA_KEY) ,"expecting an rsa key"}, |
176 | {ERR_REASON(EVP_R_EXPECTING_A_DH_KEY) ,"expecting a dh key"}, | 179 | {ERR_REASON(EVP_R_EXPECTING_A_DH_KEY) ,"expecting a dh key"}, |
177 | {ERR_REASON(EVP_R_EXPECTING_A_DSA_KEY) ,"expecting a dsa key"}, | 180 | {ERR_REASON(EVP_R_EXPECTING_A_DSA_KEY) ,"expecting a dsa key"}, |
178 | {ERR_REASON(EVP_R_EXPECTING_A_ECDSA_KEY) ,"expecting a ecdsa key"}, | 181 | {ERR_REASON(EVP_R_EXPECTING_A_ECDSA_KEY) ,"expecting a ecdsa key"}, |
179 | {ERR_REASON(EVP_R_EXPECTING_A_EC_KEY) ,"expecting a ec key"}, | 182 | {ERR_REASON(EVP_R_EXPECTING_A_EC_KEY) ,"expecting a ec key"}, |
183 | {ERR_REASON(EVP_R_FIPS_MODE_NOT_SUPPORTED),"fips mode not supported"}, | ||
180 | {ERR_REASON(EVP_R_INITIALIZATION_ERROR) ,"initialization error"}, | 184 | {ERR_REASON(EVP_R_INITIALIZATION_ERROR) ,"initialization error"}, |
181 | {ERR_REASON(EVP_R_INPUT_NOT_INITIALIZED) ,"input not initialized"}, | 185 | {ERR_REASON(EVP_R_INPUT_NOT_INITIALIZED) ,"input not initialized"}, |
182 | {ERR_REASON(EVP_R_INVALID_DIGEST) ,"invalid digest"}, | 186 | {ERR_REASON(EVP_R_INVALID_DIGEST) ,"invalid digest"}, |
187 | {ERR_REASON(EVP_R_INVALID_FIPS_MODE) ,"invalid fips mode"}, | ||
183 | {ERR_REASON(EVP_R_INVALID_KEY_LENGTH) ,"invalid key length"}, | 188 | {ERR_REASON(EVP_R_INVALID_KEY_LENGTH) ,"invalid key length"}, |
184 | {ERR_REASON(EVP_R_INVALID_OPERATION) ,"invalid operation"}, | 189 | {ERR_REASON(EVP_R_INVALID_OPERATION) ,"invalid operation"}, |
185 | {ERR_REASON(EVP_R_IV_TOO_LARGE) ,"iv too large"}, | 190 | {ERR_REASON(EVP_R_IV_TOO_LARGE) ,"iv too large"}, |
@@ -204,6 +209,7 @@ static ERR_STRING_DATA EVP_str_reasons[]= | |||
204 | {ERR_REASON(EVP_R_TOO_LARGE) ,"too large"}, | 209 | {ERR_REASON(EVP_R_TOO_LARGE) ,"too large"}, |
205 | {ERR_REASON(EVP_R_UNKNOWN_CIPHER) ,"unknown cipher"}, | 210 | {ERR_REASON(EVP_R_UNKNOWN_CIPHER) ,"unknown cipher"}, |
206 | {ERR_REASON(EVP_R_UNKNOWN_DIGEST) ,"unknown digest"}, | 211 | {ERR_REASON(EVP_R_UNKNOWN_DIGEST) ,"unknown digest"}, |
212 | {ERR_REASON(EVP_R_UNKNOWN_OPTION) ,"unknown option"}, | ||
207 | {ERR_REASON(EVP_R_UNKNOWN_PBE_ALGORITHM) ,"unknown pbe algorithm"}, | 213 | {ERR_REASON(EVP_R_UNKNOWN_PBE_ALGORITHM) ,"unknown pbe algorithm"}, |
208 | {ERR_REASON(EVP_R_UNSUPORTED_NUMBER_OF_ROUNDS),"unsuported number of rounds"}, | 214 | {ERR_REASON(EVP_R_UNSUPORTED_NUMBER_OF_ROUNDS),"unsuported number of rounds"}, |
209 | {ERR_REASON(EVP_R_UNSUPPORTED_ALGORITHM) ,"unsupported algorithm"}, | 215 | {ERR_REASON(EVP_R_UNSUPPORTED_ALGORITHM) ,"unsupported algorithm"}, |
diff --git a/src/lib/libcrypto/evp/m_dss.c b/src/lib/libcrypto/evp/m_dss.c index 4ad63ada6f..6fb7e9a861 100644 --- a/src/lib/libcrypto/evp/m_dss.c +++ b/src/lib/libcrypto/evp/m_dss.c | |||
@@ -60,7 +60,7 @@ | |||
60 | #include "cryptlib.h" | 60 | #include "cryptlib.h" |
61 | #include <openssl/evp.h> | 61 | #include <openssl/evp.h> |
62 | #include <openssl/objects.h> | 62 | #include <openssl/objects.h> |
63 | #include <openssl/x509.h> | 63 | #include <openssl/sha.h> |
64 | #ifndef OPENSSL_NO_DSA | 64 | #ifndef OPENSSL_NO_DSA |
65 | #include <openssl/dsa.h> | 65 | #include <openssl/dsa.h> |
66 | #endif | 66 | #endif |
diff --git a/src/lib/libcrypto/evp/m_dss1.c b/src/lib/libcrypto/evp/m_dss1.c index f80170efeb..2df362a670 100644 --- a/src/lib/libcrypto/evp/m_dss1.c +++ b/src/lib/libcrypto/evp/m_dss1.c | |||
@@ -63,7 +63,7 @@ | |||
63 | 63 | ||
64 | #include <openssl/evp.h> | 64 | #include <openssl/evp.h> |
65 | #include <openssl/objects.h> | 65 | #include <openssl/objects.h> |
66 | #include <openssl/x509.h> | 66 | #include <openssl/sha.h> |
67 | #ifndef OPENSSL_NO_DSA | 67 | #ifndef OPENSSL_NO_DSA |
68 | #include <openssl/dsa.h> | 68 | #include <openssl/dsa.h> |
69 | #endif | 69 | #endif |
diff --git a/src/lib/libcrypto/evp/m_sha1.c b/src/lib/libcrypto/evp/m_sha1.c index 3cb11f1ebb..bd0c01ad3c 100644 --- a/src/lib/libcrypto/evp/m_sha1.c +++ b/src/lib/libcrypto/evp/m_sha1.c | |||
@@ -65,7 +65,7 @@ | |||
65 | 65 | ||
66 | #include <openssl/evp.h> | 66 | #include <openssl/evp.h> |
67 | #include <openssl/objects.h> | 67 | #include <openssl/objects.h> |
68 | #include <openssl/x509.h> | 68 | #include <openssl/sha.h> |
69 | #ifndef OPENSSL_NO_RSA | 69 | #ifndef OPENSSL_NO_RSA |
70 | #include <openssl/rsa.h> | 70 | #include <openssl/rsa.h> |
71 | #endif | 71 | #endif |
diff --git a/src/lib/libcrypto/evp/p5_crpt2.c b/src/lib/libcrypto/evp/p5_crpt2.c index 975d004df4..fe3c6c8813 100644 --- a/src/lib/libcrypto/evp/p5_crpt2.c +++ b/src/lib/libcrypto/evp/p5_crpt2.c | |||
@@ -85,19 +85,24 @@ int PKCS5_PBKDF2_HMAC(const char *pass, int passlen, | |||
85 | unsigned char digtmp[EVP_MAX_MD_SIZE], *p, itmp[4]; | 85 | unsigned char digtmp[EVP_MAX_MD_SIZE], *p, itmp[4]; |
86 | int cplen, j, k, tkeylen, mdlen; | 86 | int cplen, j, k, tkeylen, mdlen; |
87 | unsigned long i = 1; | 87 | unsigned long i = 1; |
88 | HMAC_CTX hctx; | 88 | HMAC_CTX hctx_tpl, hctx; |
89 | 89 | ||
90 | mdlen = EVP_MD_size(digest); | 90 | mdlen = EVP_MD_size(digest); |
91 | if (mdlen < 0) | 91 | if (mdlen < 0) |
92 | return 0; | 92 | return 0; |
93 | 93 | ||
94 | HMAC_CTX_init(&hctx); | 94 | HMAC_CTX_init(&hctx_tpl); |
95 | p = out; | 95 | p = out; |
96 | tkeylen = keylen; | 96 | tkeylen = keylen; |
97 | if(!pass) | 97 | if(!pass) |
98 | passlen = 0; | 98 | passlen = 0; |
99 | else if(passlen == -1) | 99 | else if(passlen == -1) |
100 | passlen = strlen(pass); | 100 | passlen = strlen(pass); |
101 | if (!HMAC_Init_ex(&hctx_tpl, pass, passlen, digest, NULL)) | ||
102 | { | ||
103 | HMAC_CTX_cleanup(&hctx_tpl); | ||
104 | return 0; | ||
105 | } | ||
101 | while(tkeylen) | 106 | while(tkeylen) |
102 | { | 107 | { |
103 | if(tkeylen > mdlen) | 108 | if(tkeylen > mdlen) |
@@ -111,19 +116,36 @@ int PKCS5_PBKDF2_HMAC(const char *pass, int passlen, | |||
111 | itmp[1] = (unsigned char)((i >> 16) & 0xff); | 116 | itmp[1] = (unsigned char)((i >> 16) & 0xff); |
112 | itmp[2] = (unsigned char)((i >> 8) & 0xff); | 117 | itmp[2] = (unsigned char)((i >> 8) & 0xff); |
113 | itmp[3] = (unsigned char)(i & 0xff); | 118 | itmp[3] = (unsigned char)(i & 0xff); |
114 | if (!HMAC_Init_ex(&hctx, pass, passlen, digest, NULL) | 119 | if (!HMAC_CTX_copy(&hctx, &hctx_tpl)) |
115 | || !HMAC_Update(&hctx, salt, saltlen) | ||
116 | || !HMAC_Update(&hctx, itmp, 4) | ||
117 | || !HMAC_Final(&hctx, digtmp, NULL)) | ||
118 | { | 120 | { |
121 | HMAC_CTX_cleanup(&hctx_tpl); | ||
122 | return 0; | ||
123 | } | ||
124 | if (!HMAC_Update(&hctx, salt, saltlen) | ||
125 | || !HMAC_Update(&hctx, itmp, 4) | ||
126 | || !HMAC_Final(&hctx, digtmp, NULL)) | ||
127 | { | ||
128 | HMAC_CTX_cleanup(&hctx_tpl); | ||
119 | HMAC_CTX_cleanup(&hctx); | 129 | HMAC_CTX_cleanup(&hctx); |
120 | return 0; | 130 | return 0; |
121 | } | 131 | } |
132 | HMAC_CTX_cleanup(&hctx); | ||
122 | memcpy(p, digtmp, cplen); | 133 | memcpy(p, digtmp, cplen); |
123 | for(j = 1; j < iter; j++) | 134 | for(j = 1; j < iter; j++) |
124 | { | 135 | { |
125 | HMAC(digest, pass, passlen, | 136 | if (!HMAC_CTX_copy(&hctx, &hctx_tpl)) |
126 | digtmp, mdlen, digtmp, NULL); | 137 | { |
138 | HMAC_CTX_cleanup(&hctx_tpl); | ||
139 | return 0; | ||
140 | } | ||
141 | if (!HMAC_Update(&hctx, digtmp, mdlen) | ||
142 | || !HMAC_Final(&hctx, digtmp, NULL)) | ||
143 | { | ||
144 | HMAC_CTX_cleanup(&hctx_tpl); | ||
145 | HMAC_CTX_cleanup(&hctx); | ||
146 | return 0; | ||
147 | } | ||
148 | HMAC_CTX_cleanup(&hctx); | ||
127 | for(k = 0; k < cplen; k++) | 149 | for(k = 0; k < cplen; k++) |
128 | p[k] ^= digtmp[k]; | 150 | p[k] ^= digtmp[k]; |
129 | } | 151 | } |
@@ -131,7 +153,7 @@ int PKCS5_PBKDF2_HMAC(const char *pass, int passlen, | |||
131 | i++; | 153 | i++; |
132 | p+= cplen; | 154 | p+= cplen; |
133 | } | 155 | } |
134 | HMAC_CTX_cleanup(&hctx); | 156 | HMAC_CTX_cleanup(&hctx_tpl); |
135 | #ifdef DEBUG_PKCS5V2 | 157 | #ifdef DEBUG_PKCS5V2 |
136 | fprintf(stderr, "Password:\n"); | 158 | fprintf(stderr, "Password:\n"); |
137 | h__dump (pass, passlen); | 159 | h__dump (pass, passlen); |
diff --git a/src/lib/libcrypto/evp/p_sign.c b/src/lib/libcrypto/evp/p_sign.c index dfa48c157c..8afb664306 100644 --- a/src/lib/libcrypto/evp/p_sign.c +++ b/src/lib/libcrypto/evp/p_sign.c | |||
@@ -80,7 +80,7 @@ int EVP_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret, unsigned int *siglen, | |||
80 | { | 80 | { |
81 | unsigned char m[EVP_MAX_MD_SIZE]; | 81 | unsigned char m[EVP_MAX_MD_SIZE]; |
82 | unsigned int m_len; | 82 | unsigned int m_len; |
83 | int i=0,ok=0,v; | 83 | int i = 0,ok = 0,v; |
84 | EVP_MD_CTX tmp_ctx; | 84 | EVP_MD_CTX tmp_ctx; |
85 | EVP_PKEY_CTX *pkctx = NULL; | 85 | EVP_PKEY_CTX *pkctx = NULL; |
86 | 86 | ||
diff --git a/src/lib/libcrypto/evp/p_verify.c b/src/lib/libcrypto/evp/p_verify.c index 5f5c409f45..c66d63ccf8 100644 --- a/src/lib/libcrypto/evp/p_verify.c +++ b/src/lib/libcrypto/evp/p_verify.c | |||
@@ -67,7 +67,7 @@ int EVP_VerifyFinal(EVP_MD_CTX *ctx, const unsigned char *sigbuf, | |||
67 | { | 67 | { |
68 | unsigned char m[EVP_MAX_MD_SIZE]; | 68 | unsigned char m[EVP_MAX_MD_SIZE]; |
69 | unsigned int m_len; | 69 | unsigned int m_len; |
70 | int i=-1,ok=0,v; | 70 | int i = 0,ok = 0,v; |
71 | EVP_MD_CTX tmp_ctx; | 71 | EVP_MD_CTX tmp_ctx; |
72 | EVP_PKEY_CTX *pkctx = NULL; | 72 | EVP_PKEY_CTX *pkctx = NULL; |
73 | 73 | ||