diff options
Diffstat (limited to '')
-rw-r--r-- | src/lib/libcrypto/hmac/hmac.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/lib/libcrypto/hmac/hmac.c b/src/lib/libcrypto/hmac/hmac.c index f2e5f149e0..155e32a540 100644 --- a/src/lib/libcrypto/hmac/hmac.c +++ b/src/lib/libcrypto/hmac/hmac.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: hmac.c,v 1.21 2014/07/11 08:44:48 jsing Exp $ */ | 1 | /* $OpenBSD: hmac.c,v 1.22 2015/02/10 09:52:35 miod 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 | * |
@@ -60,6 +60,7 @@ | |||
60 | #include <stdlib.h> | 60 | #include <stdlib.h> |
61 | #include <string.h> | 61 | #include <string.h> |
62 | 62 | ||
63 | #include <openssl/err.h> | ||
63 | #include <openssl/hmac.h> | 64 | #include <openssl/hmac.h> |
64 | 65 | ||
65 | int | 66 | int |
@@ -78,7 +79,10 @@ HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int len, const EVP_MD *md, | |||
78 | if (key != NULL) { | 79 | if (key != NULL) { |
79 | reset = 1; | 80 | reset = 1; |
80 | j = EVP_MD_block_size(md); | 81 | j = EVP_MD_block_size(md); |
81 | OPENSSL_assert(j <= (int)sizeof(ctx->key)); | 82 | if ((size_t)j > sizeof(ctx->key)) { |
83 | EVPerr(EVP_F_HMAC_INIT_EX, EVP_R_BAD_BLOCK_LENGTH); | ||
84 | goto err; | ||
85 | } | ||
82 | if (j < len) { | 86 | if (j < len) { |
83 | if (!EVP_DigestInit_ex(&ctx->md_ctx, md, impl)) | 87 | if (!EVP_DigestInit_ex(&ctx->md_ctx, md, impl)) |
84 | goto err; | 88 | goto err; |
@@ -88,8 +92,11 @@ HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int len, const EVP_MD *md, | |||
88 | &ctx->key_length)) | 92 | &ctx->key_length)) |
89 | goto err; | 93 | goto err; |
90 | } else { | 94 | } else { |
91 | OPENSSL_assert(len >= 0 && | 95 | if ((size_t)len > sizeof(ctx->key)) { |
92 | len <= (int)sizeof(ctx->key)); | 96 | EVPerr(EVP_F_HMAC_INIT_EX, |
97 | EVP_R_BAD_KEY_LENGTH); | ||
98 | goto err; | ||
99 | } | ||
93 | memcpy(ctx->key, key, len); | 100 | memcpy(ctx->key, key, len); |
94 | ctx->key_length = len; | 101 | ctx->key_length = len; |
95 | } | 102 | } |