mirror of
https://github.com/morgan9e/UxPlay
synced 2026-04-14 00:04:13 +09:00
corrections to aes_reset
This commit is contained in:
12
lib/crypto.c
12
lib/crypto.c
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user