diff options
Diffstat (limited to 'src/lib/libssl/t1_enc.c')
| -rw-r--r-- | src/lib/libssl/t1_enc.c | 69 |
1 files changed, 41 insertions, 28 deletions
diff --git a/src/lib/libssl/t1_enc.c b/src/lib/libssl/t1_enc.c index 53570b2d4f..6305a6ffb9 100644 --- a/src/lib/libssl/t1_enc.c +++ b/src/lib/libssl/t1_enc.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: t1_enc.c,v 1.85 2016/04/28 16:39:45 jsing Exp $ */ | 1 | /* $OpenBSD: t1_enc.c,v 1.86 2016/11/03 08:15:22 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 | * |
| @@ -177,9 +177,9 @@ tls1_free_digest_list(SSL *s) | |||
| 177 | 177 | ||
| 178 | if (s == NULL) | 178 | if (s == NULL) |
| 179 | return; | 179 | return; |
| 180 | |||
| 181 | if (s->s3->handshake_dgst == NULL) | 180 | if (s->s3->handshake_dgst == NULL) |
| 182 | return; | 181 | return; |
| 182 | |||
| 183 | for (i = 0; i < SSL_MAX_DIGEST; i++) { | 183 | for (i = 0; i < SSL_MAX_DIGEST; i++) { |
| 184 | if (s->s3->handshake_dgst[i]) | 184 | if (s->s3->handshake_dgst[i]) |
| 185 | EVP_MD_CTX_destroy(s->s3->handshake_dgst[i]); | 185 | EVP_MD_CTX_destroy(s->s3->handshake_dgst[i]); |
| @@ -188,61 +188,70 @@ tls1_free_digest_list(SSL *s) | |||
| 188 | s->s3->handshake_dgst = NULL; | 188 | s->s3->handshake_dgst = NULL; |
| 189 | } | 189 | } |
| 190 | 190 | ||
| 191 | void | 191 | int |
| 192 | tls1_finish_mac(SSL *s, const unsigned char *buf, int len) | 192 | tls1_finish_mac(SSL *s, const unsigned char *buf, int len) |
| 193 | { | 193 | { |
| 194 | int i; | ||
| 195 | |||
| 194 | if (s->s3->handshake_buffer && | 196 | if (s->s3->handshake_buffer && |
| 195 | !(s->s3->flags & TLS1_FLAGS_KEEP_HANDSHAKE)) { | 197 | !(s->s3->flags & TLS1_FLAGS_KEEP_HANDSHAKE)) { |
| 196 | BIO_write(s->s3->handshake_buffer, (void *)buf, len); | 198 | BIO_write(s->s3->handshake_buffer, (void *)buf, len); |
| 197 | } else { | 199 | return 1; |
| 198 | int i; | 200 | } |
| 199 | for (i = 0; i < SSL_MAX_DIGEST; i++) { | 201 | |
| 200 | if (s->s3->handshake_dgst[i]!= NULL) | 202 | for (i = 0; i < SSL_MAX_DIGEST; i++) { |
| 201 | EVP_DigestUpdate(s->s3->handshake_dgst[i], buf, len); | 203 | if (s->s3->handshake_dgst[i] == NULL) |
| 204 | continue; | ||
| 205 | if (!EVP_DigestUpdate(s->s3->handshake_dgst[i], buf, len)) { | ||
| 206 | SSLerr(SSL_F_SSL3_DIGEST_CACHED_RECORDS, ERR_R_EVP_LIB); | ||
| 207 | return 0; | ||
| 202 | } | 208 | } |
| 203 | } | 209 | } |
| 210 | |||
| 211 | return 1; | ||
| 204 | } | 212 | } |
| 205 | 213 | ||
| 206 | int | 214 | int |
| 207 | tls1_digest_cached_records(SSL *s) | 215 | tls1_digest_cached_records(SSL *s) |
| 208 | { | 216 | { |
| 209 | int i; | ||
| 210 | long mask; | ||
| 211 | const EVP_MD *md; | 217 | const EVP_MD *md; |
| 212 | long hdatalen; | 218 | long hdatalen, mask; |
| 213 | void *hdata; | 219 | void *hdata; |
| 220 | int i; | ||
| 214 | 221 | ||
| 215 | tls1_free_digest_list(s); | 222 | tls1_free_digest_list(s); |
| 216 | 223 | ||
| 217 | s->s3->handshake_dgst = calloc(SSL_MAX_DIGEST, sizeof(EVP_MD_CTX *)); | 224 | s->s3->handshake_dgst = calloc(SSL_MAX_DIGEST, sizeof(EVP_MD_CTX *)); |
| 218 | if (s->s3->handshake_dgst == NULL) { | 225 | if (s->s3->handshake_dgst == NULL) { |
| 219 | SSLerr(SSL_F_SSL3_DIGEST_CACHED_RECORDS, ERR_R_MALLOC_FAILURE); | 226 | SSLerr(SSL_F_SSL3_DIGEST_CACHED_RECORDS, ERR_R_MALLOC_FAILURE); |
| 220 | return 0; | 227 | goto err; |
| 221 | } | 228 | } |
| 222 | hdatalen = BIO_get_mem_data(s->s3->handshake_buffer, &hdata); | 229 | hdatalen = BIO_get_mem_data(s->s3->handshake_buffer, &hdata); |
| 223 | if (hdatalen <= 0) { | 230 | if (hdatalen <= 0) { |
| 224 | SSLerr(SSL_F_SSL3_DIGEST_CACHED_RECORDS, | 231 | SSLerr(SSL_F_SSL3_DIGEST_CACHED_RECORDS, |
| 225 | SSL_R_BAD_HANDSHAKE_LENGTH); | 232 | SSL_R_BAD_HANDSHAKE_LENGTH); |
| 226 | return 0; | 233 | goto err; |
| 227 | } | 234 | } |
| 228 | 235 | ||
| 229 | /* Loop through bits of the algorithm2 field and create MD contexts. */ | 236 | /* Loop through bits of the algorithm2 field and create MD contexts. */ |
| 230 | for (i = 0; ssl_get_handshake_digest(i, &mask, &md); i++) { | 237 | for (i = 0; ssl_get_handshake_digest(i, &mask, &md); i++) { |
| 231 | if ((mask & ssl_get_algorithm2(s)) && md) { | 238 | if ((mask & ssl_get_algorithm2(s)) == 0 || md == NULL) |
| 232 | s->s3->handshake_dgst[i] = EVP_MD_CTX_create(); | 239 | continue; |
| 233 | if (s->s3->handshake_dgst[i] == NULL) { | 240 | |
| 234 | SSLerr(SSL_F_SSL3_DIGEST_CACHED_RECORDS, | 241 | s->s3->handshake_dgst[i] = EVP_MD_CTX_create(); |
| 235 | ERR_R_MALLOC_FAILURE); | 242 | if (s->s3->handshake_dgst[i] == NULL) { |
| 236 | return 0; | 243 | SSLerr(SSL_F_SSL3_DIGEST_CACHED_RECORDS, |
| 237 | } | 244 | ERR_R_MALLOC_FAILURE); |
| 238 | if (!EVP_DigestInit_ex(s->s3->handshake_dgst[i], | 245 | goto err; |
| 239 | md, NULL)) { | 246 | } |
| 240 | EVP_MD_CTX_destroy(s->s3->handshake_dgst[i]); | 247 | if (!EVP_DigestInit_ex(s->s3->handshake_dgst[i], md, NULL)) { |
| 241 | return 0; | 248 | SSLerr(SSL_F_SSL3_DIGEST_CACHED_RECORDS, ERR_R_EVP_LIB); |
| 242 | } | 249 | goto err; |
| 243 | if (!EVP_DigestUpdate(s->s3->handshake_dgst[i], hdata, | 250 | } |
| 244 | hdatalen)) | 251 | if (!EVP_DigestUpdate(s->s3->handshake_dgst[i], hdata, |
| 245 | return 0; | 252 | hdatalen)) { |
| 253 | SSLerr(SSL_F_SSL3_DIGEST_CACHED_RECORDS, ERR_R_EVP_LIB); | ||
| 254 | goto err; | ||
| 246 | } | 255 | } |
| 247 | } | 256 | } |
| 248 | 257 | ||
| @@ -252,6 +261,10 @@ tls1_digest_cached_records(SSL *s) | |||
| 252 | } | 261 | } |
| 253 | 262 | ||
| 254 | return 1; | 263 | return 1; |
| 264 | |||
| 265 | err: | ||
| 266 | tls1_free_digest_list(s); | ||
| 267 | return 0; | ||
| 255 | } | 268 | } |
| 256 | 269 | ||
| 257 | void | 270 | void |
