Skip to content

Commit

Permalink
enc - init once
Browse files Browse the repository at this point in the history
  • Loading branch information
beldmit committed Jan 20, 2025
1 parent e9b2eee commit b8742c2
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions apps/enc.c
Original file line number Diff line number Diff line change
Expand Up @@ -668,18 +668,8 @@ int enc_main(int argc, char **argv)
if (wrap == 1)
EVP_CIPHER_CTX_set_flags(ctx, EVP_CIPHER_CTX_FLAG_WRAP_ALLOW);

if (!EVP_CipherInit_ex(ctx, cipher, e, NULL, NULL, enc)) {
BIO_printf(bio_err, "Error setting cipher %s\n",
EVP_CIPHER_get0_name(cipher));
ERR_print_errors(bio_err);
goto end;
}

if (nopad)
EVP_CIPHER_CTX_set_padding(ctx, 0);

if (rawkey_set) {
if (!EVP_CipherInit_ex(ctx, NULL, NULL, key,
if (!EVP_CipherInit_ex(ctx, cipher, e, key,
(hiv == NULL && wrap == 1 ? NULL : iv), enc)) {
BIO_printf(bio_err, "Error setting cipher %s\n",
EVP_CIPHER_get0_name(cipher));
Expand All @@ -700,7 +690,7 @@ int enc_main(int argc, char **argv)
goto end;
}

if (!EVP_CipherInit_skey(ctx, NULL, skey,
if (!EVP_CipherInit_skey(ctx, cipher, skey,
(hiv == NULL && wrap == 1 ? NULL : iv),
EVP_CIPHER_get_iv_length(cipher), enc, NULL)) {
BIO_printf(bio_err, "Error setting an opaque key for cipher %s\n",
Expand All @@ -710,6 +700,9 @@ int enc_main(int argc, char **argv)
}
}

if (nopad)
EVP_CIPHER_CTX_set_padding(ctx, 0);

if (debug) {
BIO_set_callback_ex(benc, BIO_debug_callback_ex);
BIO_set_callback_arg(benc, (char *)bio_err);
Expand Down

0 comments on commit b8742c2

Please sign in to comment.