diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/lib/libssl/src/ssl/s3_enc.c | 50 |
1 files changed, 27 insertions, 23 deletions
diff --git a/src/lib/libssl/src/ssl/s3_enc.c b/src/lib/libssl/src/ssl/s3_enc.c index 84370f6789..d21d9e1216 100644 --- a/src/lib/libssl/src/ssl/s3_enc.c +++ b/src/lib/libssl/src/ssl/s3_enc.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: s3_enc.c,v 1.45 2014/06/13 14:58:05 jsing Exp $ */ | 1 | /* $OpenBSD: s3_enc.c,v 1.46 2014/06/13 15:28:49 jsing Exp $ */ |
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
| 3 | * All rights reserved. | 3 | * All rights reserved. |
| 4 | * | 4 | * |
| @@ -222,7 +222,7 @@ ssl3_change_cipher_state(SSL *s, int which) | |||
| 222 | const EVP_CIPHER *cipher; | 222 | const EVP_CIPHER *cipher; |
| 223 | EVP_MD_CTX mac_ctx; | 223 | EVP_MD_CTX mac_ctx; |
| 224 | const EVP_MD *mac; | 224 | const EVP_MD *mac; |
| 225 | int is_export, n, i, j, k, cl; | 225 | int is_export, n, mac_len, key_len, iv_len; |
| 226 | char is_read; | 226 | char is_read; |
| 227 | 227 | ||
| 228 | #ifndef OPENSSL_NO_COMP | 228 | #ifndef OPENSSL_NO_COMP |
| @@ -306,34 +306,38 @@ ssl3_change_cipher_state(SSL *s, int which) | |||
| 306 | } | 306 | } |
| 307 | 307 | ||
| 308 | p = s->s3->tmp.key_block; | 308 | p = s->s3->tmp.key_block; |
| 309 | i = EVP_MD_size(mac); | 309 | |
| 310 | if (i < 0) | 310 | mac_len = EVP_MD_size(mac); |
| 311 | key_len = EVP_CIPHER_key_length(cipher); | ||
| 312 | iv_len = EVP_CIPHER_iv_length(cipher); | ||
| 313 | |||
| 314 | if (mac_len < 0) | ||
| 311 | goto err2; | 315 | goto err2; |
| 312 | cl = EVP_CIPHER_key_length(cipher); | 316 | |
| 313 | j = is_export ? (cl < SSL_C_EXPORT_KEYLENGTH(s->s3->tmp.new_cipher) ? | 317 | if (is_export && |
| 314 | cl : SSL_C_EXPORT_KEYLENGTH(s->s3->tmp.new_cipher)) : cl; | 318 | key_len > SSL_C_EXPORT_KEYLENGTH(s->s3->tmp.new_cipher)) |
| 315 | /* Was j=(is_exp)?5:EVP_CIPHER_key_length(c); */ | 319 | key_len = SSL_C_EXPORT_KEYLENGTH(s->s3->tmp.new_cipher); |
| 316 | k = EVP_CIPHER_iv_length(cipher); | 320 | |
| 317 | if ((which == SSL3_CHANGE_CIPHER_CLIENT_WRITE) || | 321 | if ((which == SSL3_CHANGE_CIPHER_CLIENT_WRITE) || |
| 318 | (which == SSL3_CHANGE_CIPHER_SERVER_READ)) { | 322 | (which == SSL3_CHANGE_CIPHER_SERVER_READ)) { |
| 319 | ms = &(p[0]); | 323 | ms = &(p[0]); |
| 320 | n = i + i; | 324 | n = mac_len + mac_len; |
| 321 | key = &(p[n]); | 325 | key = &(p[n]); |
| 322 | n += j + j; | 326 | n += key_len + key_len; |
| 323 | iv = &(p[n]); | 327 | iv = &(p[n]); |
| 324 | n += k + k; | 328 | n += iv_len + iv_len; |
| 325 | er1 = &(s->s3->client_random[0]); | 329 | er1 = s->s3->client_random; |
| 326 | er2 = &(s->s3->server_random[0]); | 330 | er2 = s->s3->server_random; |
| 327 | } else { | 331 | } else { |
| 328 | n = i; | 332 | n = mac_len; |
| 329 | ms = &(p[n]); | 333 | ms = &(p[n]); |
| 330 | n += i + j; | 334 | n += mac_len + key_len; |
| 331 | key = &(p[n]); | 335 | key = &(p[n]); |
| 332 | n += j + k; | 336 | n += key_len + iv_len; |
| 333 | iv = &(p[n]); | 337 | iv = &(p[n]); |
| 334 | n += k; | 338 | n += iv_len; |
| 335 | er1 = &(s->s3->server_random[0]); | 339 | er1 = s->s3->server_random; |
| 336 | er2 = &(s->s3->client_random[0]); | 340 | er2 = s->s3->client_random; |
| 337 | } | 341 | } |
| 338 | 342 | ||
| 339 | if (n > s->s3->tmp.key_block_length) { | 343 | if (n > s->s3->tmp.key_block_length) { |
| @@ -342,19 +346,19 @@ ssl3_change_cipher_state(SSL *s, int which) | |||
| 342 | } | 346 | } |
| 343 | 347 | ||
| 344 | EVP_MD_CTX_init(&mac_ctx); | 348 | EVP_MD_CTX_init(&mac_ctx); |
| 345 | memcpy(mac_secret, ms, i); | 349 | memcpy(mac_secret, ms, mac_len); |
| 346 | if (is_export) { | 350 | if (is_export) { |
| 347 | /* In here I set both the read and write key/iv to the | 351 | /* In here I set both the read and write key/iv to the |
| 348 | * same value since only the correct one will be used :-). | 352 | * same value since only the correct one will be used :-). |
| 349 | */ | 353 | */ |
| 350 | EVP_DigestInit_ex(&mac_ctx, EVP_md5(), NULL); | 354 | EVP_DigestInit_ex(&mac_ctx, EVP_md5(), NULL); |
| 351 | EVP_DigestUpdate(&mac_ctx, key, j); | 355 | EVP_DigestUpdate(&mac_ctx, key, key_len); |
| 352 | EVP_DigestUpdate(&mac_ctx, er1, SSL3_RANDOM_SIZE); | 356 | EVP_DigestUpdate(&mac_ctx, er1, SSL3_RANDOM_SIZE); |
| 353 | EVP_DigestUpdate(&mac_ctx, er2, SSL3_RANDOM_SIZE); | 357 | EVP_DigestUpdate(&mac_ctx, er2, SSL3_RANDOM_SIZE); |
| 354 | EVP_DigestFinal_ex(&mac_ctx, export_key, NULL); | 358 | EVP_DigestFinal_ex(&mac_ctx, export_key, NULL); |
| 355 | key = export_key; | 359 | key = export_key; |
| 356 | 360 | ||
| 357 | if (k > 0) { | 361 | if (iv_len > 0) { |
| 358 | EVP_DigestInit_ex(&mac_ctx, EVP_md5(), NULL); | 362 | EVP_DigestInit_ex(&mac_ctx, EVP_md5(), NULL); |
| 359 | EVP_DigestUpdate(&mac_ctx, er1, SSL3_RANDOM_SIZE); | 363 | EVP_DigestUpdate(&mac_ctx, er1, SSL3_RANDOM_SIZE); |
| 360 | EVP_DigestUpdate(&mac_ctx, er2, SSL3_RANDOM_SIZE); | 364 | EVP_DigestUpdate(&mac_ctx, er2, SSL3_RANDOM_SIZE); |
