[FFmpeg-cvslog] avutil/aes_ctr: Avoid allocation of AVAES struct

Andreas Rheinhardt git at videolan.org
Wed Dec 8 15:28:57 EET 2021


ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at outlook.com> | Mon Dec  6 01:14:28 2021 +0100| [fbbe7729f0fc7db3daad584b0e5f5a898f2b8acf] | committer: Andreas Rheinhardt

avutil/aes_ctr: Avoid allocation of AVAES struct

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=fbbe7729f0fc7db3daad584b0e5f5a898f2b8acf
---

 libavutil/aes_ctr.c | 17 +++++------------
 1 file 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);
         }



More information about the ffmpeg-cvslog mailing list