diff options
author | miod <> | 2015-02-10 09:52:35 +0000 |
---|---|---|
committer | miod <> | 2015-02-10 09:52:35 +0000 |
commit | d2f68f95d95ff1ca4370b66eb67e8add10d9d079 (patch) | |
tree | 58f7f299c05557099d7278079e061aed0f4a9f23 /src/lib/libcrypto/evp/evp_enc.c | |
parent | 9c8f4b278d0fe6c5ae67ecea60905c57ccf4c4e1 (diff) | |
download | openbsd-d2f68f95d95ff1ca4370b66eb67e8add10d9d079.tar.gz openbsd-d2f68f95d95ff1ca4370b66eb67e8add10d9d079.tar.bz2 openbsd-d2f68f95d95ff1ca4370b66eb67e8add10d9d079.zip |
Replace assert() and OPENSSL_assert() calls with proper error return paths.
Careful review, feedback & ok doug@ jsing@
Diffstat (limited to 'src/lib/libcrypto/evp/evp_enc.c')
-rw-r--r-- | src/lib/libcrypto/evp/evp_enc.c | 45 |
1 files changed, 31 insertions, 14 deletions
diff --git a/src/lib/libcrypto/evp/evp_enc.c b/src/lib/libcrypto/evp/evp_enc.c index 49ceacefad..42ccfceec9 100644 --- a/src/lib/libcrypto/evp/evp_enc.c +++ b/src/lib/libcrypto/evp/evp_enc.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: evp_enc.c,v 1.25 2014/10/22 13:02:04 jsing Exp $ */ | 1 | /* $OpenBSD: evp_enc.c,v 1.26 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 | * |
@@ -140,10 +140,6 @@ EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *impl, | |||
140 | const EVP_CIPHER *c = | 140 | const EVP_CIPHER *c = |
141 | ENGINE_get_cipher(impl, cipher->nid); | 141 | ENGINE_get_cipher(impl, cipher->nid); |
142 | if (!c) { | 142 | if (!c) { |
143 | /* One positive side-effect of US's export | ||
144 | * control history, is that we should at least | ||
145 | * be able to avoid using US mispellings of | ||
146 | * "initialisation"? */ | ||
147 | EVPerr(EVP_F_EVP_CIPHERINIT_EX, | 143 | EVPerr(EVP_F_EVP_CIPHERINIT_EX, |
148 | EVP_R_INITIALIZATION_ERROR); | 144 | EVP_R_INITIALIZATION_ERROR); |
149 | return 0; | 145 | return 0; |
@@ -186,9 +182,12 @@ EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *impl, | |||
186 | skip_to_init: | 182 | skip_to_init: |
187 | #endif | 183 | #endif |
188 | /* we assume block size is a power of 2 in *cryptUpdate */ | 184 | /* we assume block size is a power of 2 in *cryptUpdate */ |
189 | OPENSSL_assert(ctx->cipher->block_size == 1 || | 185 | if (ctx->cipher->block_size != 1 && |
190 | ctx->cipher->block_size == 8 || | 186 | ctx->cipher->block_size != 8 && |
191 | ctx->cipher->block_size == 16); | 187 | ctx->cipher->block_size != 16) { |
188 | EVPerr(EVP_F_EVP_CIPHERINIT_EX, EVP_R_BAD_BLOCK_LENGTH); | ||
189 | return 0; | ||
190 | } | ||
192 | 191 | ||
193 | if (!(EVP_CIPHER_CTX_flags(ctx) & EVP_CIPH_CUSTOM_IV)) { | 192 | if (!(EVP_CIPHER_CTX_flags(ctx) & EVP_CIPH_CUSTOM_IV)) { |
194 | switch (EVP_CIPHER_CTX_mode(ctx)) { | 193 | switch (EVP_CIPHER_CTX_mode(ctx)) { |
@@ -205,8 +204,12 @@ skip_to_init: | |||
205 | 204 | ||
206 | case EVP_CIPH_CBC_MODE: | 205 | case EVP_CIPH_CBC_MODE: |
207 | 206 | ||
208 | OPENSSL_assert(EVP_CIPHER_CTX_iv_length(ctx) <= | 207 | if ((size_t)EVP_CIPHER_CTX_iv_length(ctx) > |
209 | (int)sizeof(ctx->iv)); | 208 | sizeof(ctx->iv)) { |
209 | EVPerr(EVP_F_EVP_CIPHERINIT_EX, | ||
210 | EVP_R_IV_TOO_LARGE); | ||
211 | return 0; | ||
212 | } | ||
210 | if (iv) | 213 | if (iv) |
211 | memcpy(ctx->oiv, iv, | 214 | memcpy(ctx->oiv, iv, |
212 | EVP_CIPHER_CTX_iv_length(ctx)); | 215 | EVP_CIPHER_CTX_iv_length(ctx)); |
@@ -325,7 +328,11 @@ EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl, | |||
325 | } | 328 | } |
326 | i = ctx->buf_len; | 329 | i = ctx->buf_len; |
327 | bl = ctx->cipher->block_size; | 330 | bl = ctx->cipher->block_size; |
328 | OPENSSL_assert(bl <= (int)sizeof(ctx->buf)); | 331 | if ((size_t)bl > sizeof(ctx->buf)) { |
332 | EVPerr(EVP_F_EVP_ENCRYPTUPDATE, EVP_R_BAD_BLOCK_LENGTH); | ||
333 | *outl = 0; | ||
334 | return 0; | ||
335 | } | ||
329 | if (i != 0) { | 336 | if (i != 0) { |
330 | if (i + inl < bl) { | 337 | if (i + inl < bl) { |
331 | memcpy(&(ctx->buf[i]), in, inl); | 338 | memcpy(&(ctx->buf[i]), in, inl); |
@@ -383,7 +390,10 @@ EVP_EncryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl) | |||
383 | } | 390 | } |
384 | 391 | ||
385 | b = ctx->cipher->block_size; | 392 | b = ctx->cipher->block_size; |
386 | OPENSSL_assert(b <= sizeof ctx->buf); | 393 | if (b > sizeof ctx->buf) { |
394 | EVPerr(EVP_F_EVP_ENCRYPTFINAL_EX, EVP_R_BAD_BLOCK_LENGTH); | ||
395 | return 0; | ||
396 | } | ||
387 | if (b == 1) { | 397 | if (b == 1) { |
388 | *outl = 0; | 398 | *outl = 0; |
389 | return 1; | 399 | return 1; |
@@ -437,7 +447,10 @@ EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl, | |||
437 | return EVP_EncryptUpdate(ctx, out, outl, in, inl); | 447 | return EVP_EncryptUpdate(ctx, out, outl, in, inl); |
438 | 448 | ||
439 | b = ctx->cipher->block_size; | 449 | b = ctx->cipher->block_size; |
440 | OPENSSL_assert(b <= sizeof ctx->final); | 450 | if (b > sizeof ctx->final) { |
451 | EVPerr(EVP_F_EVP_DECRYPTUPDATE, EVP_R_BAD_BLOCK_LENGTH); | ||
452 | return 0; | ||
453 | } | ||
441 | 454 | ||
442 | if (ctx->final_used) { | 455 | if (ctx->final_used) { |
443 | memcpy(out, ctx->final, b); | 456 | memcpy(out, ctx->final, b); |
@@ -506,7 +519,11 @@ EVP_DecryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl) | |||
506 | EVP_R_WRONG_FINAL_BLOCK_LENGTH); | 519 | EVP_R_WRONG_FINAL_BLOCK_LENGTH); |
507 | return (0); | 520 | return (0); |
508 | } | 521 | } |
509 | OPENSSL_assert(b <= sizeof ctx->final); | 522 | if (b > sizeof ctx->final) { |
523 | EVPerr(EVP_F_EVP_DECRYPTFINAL_EX, | ||
524 | EVP_R_BAD_BLOCK_LENGTH); | ||
525 | return 0; | ||
526 | } | ||
510 | n = ctx->final[b - 1]; | 527 | n = ctx->final[b - 1]; |
511 | if (n == 0 || n > (int)b) { | 528 | if (n == 0 || n > (int)b) { |
512 | EVPerr(EVP_F_EVP_DECRYPTFINAL_EX, EVP_R_BAD_DECRYPT); | 529 | EVPerr(EVP_F_EVP_DECRYPTFINAL_EX, EVP_R_BAD_DECRYPT); |