corrections to aes_reset

This commit is contained in:
fduncanh
2022-01-12 18:52:36 -05:00
parent 2fa1aa9e9e
commit 9dd3ed83c4

View File

@@ -104,19 +104,27 @@ void aes_destroy(aes_ctx_t *ctx) {
}
void aes_reset(aes_ctx_t *ctx, const EVP_CIPHER *type, aes_direction_t direction) {
uint8_t key[AES_128_BLOCK_SIZE], iv[AES_128_BLOCK_SIZE];
memcpy(key, ctx->key, AES_128_BLOCK_SIZE);
memcpy(iv, ctx->iv, AES_128_BLOCK_SIZE);
if (!EVP_CIPHER_CTX_reset(ctx->cipher_ctx)) {
handle_error(__func__);
}
if (direction == AES_ENCRYPT) {
if (!EVP_EncryptInit_ex(ctx->cipher_ctx, type, NULL, ctx->key, ctx->iv)) {
if (!EVP_EncryptInit_ex(ctx->cipher_ctx, type, NULL, key, iv)) {
handle_error(__func__);
}
} else {
if (!EVP_DecryptInit_ex(ctx->cipher_ctx, type, NULL, ctx->key, ctx->iv)) {
if (!EVP_DecryptInit_ex(ctx->cipher_ctx, type, NULL, key, iv)) {
handle_error(__func__);
}
}
memcpy(ctx->key, key, AES_128_BLOCK_SIZE);
memcpy(ctx->iv, iv, AES_128_BLOCK_SIZE);
EVP_CIPHER_CTX_set_padding(ctx->cipher_ctx, 0);
}
// AES CTR