diff mbox series

[FFmpeg-devel,08/10] avutil/aes_ctr: Avoid allocation of AVAES struct

Message ID AM7PR03MB666052567FFC9AF48DEA21788F6D9@AM7PR03MB6660.eurprd03.prod.outlook.com
State Accepted
Commit fbbe7729f0fc7db3daad584b0e5f5a898f2b8acf
Headers show
Series [FFmpeg-devel,01/10] avformat/utils: Make ff_data_to_hex() zero-terminate the string
Related show

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/make_ppc success Make finished
andriy/make_fate_ppc success Make fate finished

Commit Message

Andreas Rheinhardt Dec. 6, 2021, 1:12 a.m. UTC
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavutil/aes_ctr.c | 17 +++++------------
 1 file changed, 5 insertions(+), 12 deletions(-)
diff mbox series

Patch

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);
         }