diff options
-rw-r--r-- | src/usr.bin/openssl/enc.c | 34 |
1 files changed, 14 insertions, 20 deletions
diff --git a/src/usr.bin/openssl/enc.c b/src/usr.bin/openssl/enc.c index e9830af5f2..00ae0e1b7d 100644 --- a/src/usr.bin/openssl/enc.c +++ b/src/usr.bin/openssl/enc.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: enc.c,v 1.29 2023/06/11 11:54:44 tb Exp $ */ | 1 | /* $OpenBSD: enc.c,v 1.30 2023/06/11 12:06:08 tb 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 | * |
@@ -391,9 +391,9 @@ enc_main(int argc, char **argv) | |||
391 | } | 391 | } |
392 | fclose(infile); | 392 | fclose(infile); |
393 | i = strlen(buf); | 393 | i = strlen(buf); |
394 | if ((i > 0) && ((buf[i - 1] == '\n') || (buf[i - 1] == '\r'))) | 394 | if (i > 0 && (buf[i - 1] == '\n' || buf[i - 1] == '\r')) |
395 | buf[--i] = '\0'; | 395 | buf[--i] = '\0'; |
396 | if ((i > 0) && ((buf[i - 1] == '\n') || (buf[i - 1] == '\r'))) | 396 | if (i > 0 && (buf[i - 1] == '\n' || buf[i - 1] == '\r')) |
397 | buf[--i] = '\0'; | 397 | buf[--i] = '\0'; |
398 | if (i < 1) { | 398 | if (i < 1) { |
399 | BIO_printf(bio_err, "zero length password\n"); | 399 | BIO_printf(bio_err, "zero length password\n"); |
@@ -421,9 +421,8 @@ enc_main(int argc, char **argv) | |||
421 | cfg.md); | 421 | cfg.md); |
422 | goto end; | 422 | goto end; |
423 | } | 423 | } |
424 | if (dgst == NULL) { | 424 | if (dgst == NULL) |
425 | dgst = EVP_sha256(); | 425 | dgst = EVP_sha256(); |
426 | } | ||
427 | 426 | ||
428 | if (cfg.bufsize != NULL) { | 427 | if (cfg.bufsize != NULL) { |
429 | char *p = cfg.bufsize; | 428 | char *p = cfg.bufsize; |
@@ -454,13 +453,13 @@ enc_main(int argc, char **argv) | |||
454 | } | 453 | } |
455 | strbuf = malloc(SIZE); | 454 | strbuf = malloc(SIZE); |
456 | buff = malloc(EVP_ENCODE_LENGTH(bsize)); | 455 | buff = malloc(EVP_ENCODE_LENGTH(bsize)); |
457 | if ((buff == NULL) || (strbuf == NULL)) { | 456 | if (buff == NULL || strbuf == NULL) { |
458 | BIO_printf(bio_err, "malloc failure %ld\n", (long) EVP_ENCODE_LENGTH(bsize)); | 457 | BIO_printf(bio_err, "malloc failure %ld\n", (long) EVP_ENCODE_LENGTH(bsize)); |
459 | goto end; | 458 | goto end; |
460 | } | 459 | } |
461 | in = BIO_new(BIO_s_file()); | 460 | in = BIO_new(BIO_s_file()); |
462 | out = BIO_new(BIO_s_file()); | 461 | out = BIO_new(BIO_s_file()); |
463 | if ((in == NULL) || (out == NULL)) { | 462 | if (in == NULL || out == NULL) { |
464 | ERR_print_errors(bio_err); | 463 | ERR_print_errors(bio_err); |
465 | goto end; | 464 | goto end; |
466 | } | 465 | } |
@@ -482,15 +481,13 @@ enc_main(int argc, char **argv) | |||
482 | } | 481 | } |
483 | 482 | ||
484 | if (!cfg.keystr && cfg.passarg) { | 483 | if (!cfg.keystr && cfg.passarg) { |
485 | if (!app_passwd(bio_err, cfg.passarg, NULL, | 484 | if (!app_passwd(bio_err, cfg.passarg, NULL, &pass, NULL)) { |
486 | &pass, NULL)) { | ||
487 | BIO_printf(bio_err, "Error getting password\n"); | 485 | BIO_printf(bio_err, "Error getting password\n"); |
488 | goto end; | 486 | goto end; |
489 | } | 487 | } |
490 | cfg.keystr = pass; | 488 | cfg.keystr = pass; |
491 | } | 489 | } |
492 | if (cfg.keystr == NULL && cfg.cipher != NULL && | 490 | if (cfg.keystr == NULL && cfg.cipher != NULL && cfg.hkey == NULL) { |
493 | cfg.hkey == NULL) { | ||
494 | for (;;) { | 491 | for (;;) { |
495 | char buf[200]; | 492 | char buf[200]; |
496 | int retval; | 493 | int retval; |
@@ -640,8 +637,7 @@ enc_main(int argc, char **argv) | |||
640 | explicit_bzero(cfg.keystr, | 637 | explicit_bzero(cfg.keystr, |
641 | strlen(cfg.keystr)); | 638 | strlen(cfg.keystr)); |
642 | } | 639 | } |
643 | if (cfg.hiv != NULL && | 640 | if (cfg.hiv != NULL && !set_hex(cfg.hiv, iv, sizeof iv)) { |
644 | !set_hex(cfg.hiv, iv, sizeof iv)) { | ||
645 | BIO_printf(bio_err, "invalid hex iv value\n"); | 641 | BIO_printf(bio_err, "invalid hex iv value\n"); |
646 | goto end; | 642 | goto end; |
647 | } | 643 | } |
@@ -655,8 +651,7 @@ enc_main(int argc, char **argv) | |||
655 | BIO_printf(bio_err, "iv undefined\n"); | 651 | BIO_printf(bio_err, "iv undefined\n"); |
656 | goto end; | 652 | goto end; |
657 | } | 653 | } |
658 | if (cfg.hkey != NULL && | 654 | if (cfg.hkey != NULL && !set_hex(cfg.hkey, key, sizeof key)) { |
659 | !set_hex(cfg.hkey, key, sizeof key)) { | ||
660 | BIO_printf(bio_err, "invalid hex key value\n"); | 655 | BIO_printf(bio_err, "invalid hex key value\n"); |
661 | goto end; | 656 | goto end; |
662 | } | 657 | } |
@@ -680,8 +675,7 @@ enc_main(int argc, char **argv) | |||
680 | if (cfg.nopad) | 675 | if (cfg.nopad) |
681 | EVP_CIPHER_CTX_set_padding(ctx, 0); | 676 | EVP_CIPHER_CTX_set_padding(ctx, 0); |
682 | 677 | ||
683 | if (!EVP_CipherInit_ex(ctx, NULL, NULL, key, iv, | 678 | if (!EVP_CipherInit_ex(ctx, NULL, NULL, key, iv, cfg.enc)) { |
684 | cfg.enc)) { | ||
685 | BIO_printf(bio_err, "Error setting cipher %s\n", | 679 | BIO_printf(bio_err, "Error setting cipher %s\n", |
686 | EVP_CIPHER_name(cfg.cipher)); | 680 | EVP_CIPHER_name(cfg.cipher)); |
687 | ERR_print_errors(bio_err); | 681 | ERR_print_errors(bio_err); |
@@ -772,11 +766,11 @@ set_hex(char *in, unsigned char *out, int size) | |||
772 | *(in++) = '\0'; | 766 | *(in++) = '\0'; |
773 | if (j == 0) | 767 | if (j == 0) |
774 | break; | 768 | break; |
775 | if ((j >= '0') && (j <= '9')) | 769 | if (j >= '0' && j <= '9') |
776 | j -= '0'; | 770 | j -= '0'; |
777 | else if ((j >= 'A') && (j <= 'F')) | 771 | else if (j >= 'A' && j <= 'F') |
778 | j = j - 'A' + 10; | 772 | j = j - 'A' + 10; |
779 | else if ((j >= 'a') && (j <= 'f')) | 773 | else if (j >= 'a' && j <= 'f') |
780 | j = j - 'a' + 10; | 774 | j = j - 'a' + 10; |
781 | else { | 775 | else { |
782 | BIO_printf(bio_err, "non-hex digit\n"); | 776 | BIO_printf(bio_err, "non-hex digit\n"); |