summaryrefslogtreecommitdiff
path: root/libavutil
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2021-12-06 01:14:28 +0100
committerAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2021-12-08 14:14:00 +0100
commitfbbe7729f0fc7db3daad584b0e5f5a898f2b8acf (patch)
tree432aa374966b8d8370583272857f94ab8acfc632 /libavutil
parent72745beb44b4ddf60b77833b2edddf80e8f79ef2 (diff)
avutil/aes_ctr: Avoid allocation of AVAES struct
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Diffstat (limited to 'libavutil')
-rw-r--r--libavutil/aes_ctr.c17
1 files changed, 5 insertions, 12 deletions
diff --git a/libavutil/aes_ctr.c b/libavutil/aes_ctr.c
index 0c2e86785f..517d09cf96 100644
--- a/libavutil/aes_ctr.c
+++ b/libavutil/aes_ctr.c
@@ -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);
}