avutil/aes_ctr: Avoid allocation of AVAES struct

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
Andreas Rheinhardt 2021-12-06 01:14:28 +01:00
parent 72745beb44
commit fbbe7729f0
1 changed files with 5 additions and 12 deletions

View File

@ -22,15 +22,16 @@
#include "common.h"
#include "aes_ctr.h"
#include "aes.h"
#include "aes_internal.h"
#include "random_seed.h"
#define AES_BLOCK_SIZE (16)
typedef struct AVAESCTR {
struct AVAES* aes;
uint8_t counter[AES_BLOCK_SIZE];
uint8_t encrypted_counter[AES_BLOCK_SIZE];
int block_offset;
AVAES aes;
} AVAESCTR;
struct AVAESCTR *av_aes_ctr_alloc(void)
@ -68,12 +69,7 @@ void av_aes_ctr_set_random_iv(struct AVAESCTR *a)
int av_aes_ctr_init(struct AVAESCTR *a, const uint8_t *key)
{
a->aes = av_aes_alloc();
if (!a->aes) {
return AVERROR(ENOMEM);
}
av_aes_init(a->aes, key, 128, 0);
av_aes_init(&a->aes, key, 128, 0);
memset(a->counter, 0, sizeof(a->counter));
a->block_offset = 0;
@ -83,10 +79,7 @@ int av_aes_ctr_init(struct AVAESCTR *a, const uint8_t *key)
void av_aes_ctr_free(struct AVAESCTR *a)
{
if (a) {
av_freep(&a->aes);
av_free(a);
}
av_free(a);
}
static void av_aes_ctr_increment_be64(uint8_t* counter)
@ -116,7 +109,7 @@ void av_aes_ctr_crypt(struct AVAESCTR *a, uint8_t *dst, const uint8_t *src, int
while (src < src_end) {
if (a->block_offset == 0) {
av_aes_crypt(a->aes, a->encrypted_counter, a->counter, 1, NULL, 0);
av_aes_crypt(&a->aes, a->encrypted_counter, a->counter, 1, NULL, 0);
av_aes_ctr_increment_be64(a->counter + 8);
}