[FFmpeg-devel] avutil/aes_ctr: Add method to set 16-byte IV.

Submitted by Jacob Trimble on Jan. 8, 2018, 10:12 p.m.

Details

Message ID 20180108221243.80244-1-modmaker@google.com
State New
Headers show

Commit Message

Jacob Trimble Jan. 8, 2018, 10:12 p.m.
Signed-off-by: Jacob Trimble <modmaker@google.com>
---
 doc/APIchanges            | 3 +++
 libavutil/aes_ctr.c       | 6 ++++++
 libavutil/aes_ctr.h       | 7 ++++++-
 libavutil/tests/aes_ctr.c | 2 +-
 libavutil/version.h       | 2 +-
 5 files changed, 17 insertions(+), 3 deletions(-)

Comments

Michael Niedermayer Jan. 23, 2018, 8:48 p.m.
On Mon, Jan 08, 2018 at 02:12:43PM -0800, Jacob Trimble wrote:
> Signed-off-by: Jacob Trimble <modmaker@google.com>
> ---
>  doc/APIchanges            | 3 +++
>  libavutil/aes_ctr.c       | 6 ++++++
>  libavutil/aes_ctr.h       | 7 ++++++-
>  libavutil/tests/aes_ctr.c | 2 +-
>  libavutil/version.h       | 2 +-
>  5 files changed, 17 insertions(+), 3 deletions(-)

will apply

thanks

[...]

Patch hide | download patch | download mbox

diff --git a/doc/APIchanges b/doc/APIchanges
index b771031740..4e07a806eb 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -15,6 +15,9 @@  libavutil:     2017-10-21
 
 API changes, most recent first:
 
+2018-xx-xx - xxxxxxx - lavu 56.9.100 - aes_ctr.h
+  Add method to set the 16-byte IV.
+
 2018-xx-xx - xxxxxxx - lavu 56.8.100 - encryption_info.h
   Add AVEncryptionInitInfo and AVEncryptionInfo structures to hold new side-data
   for encryption info.
diff --git a/libavutil/aes_ctr.c b/libavutil/aes_ctr.c
index e9c568fe0d..0c2e86785f 100644
--- a/libavutil/aes_ctr.c
+++ b/libavutil/aes_ctr.c
@@ -45,6 +45,12 @@  void av_aes_ctr_set_iv(struct AVAESCTR *a, const uint8_t* iv)
     a->block_offset = 0;
 }
 
+void av_aes_ctr_set_full_iv(struct AVAESCTR *a, const uint8_t* iv)
+{
+    memcpy(a->counter, iv, sizeof(a->counter));
+    a->block_offset = 0;
+}
+
 const uint8_t* av_aes_ctr_get_iv(struct AVAESCTR *a)
 {
     return a->counter;
diff --git a/libavutil/aes_ctr.h b/libavutil/aes_ctr.h
index f596fa6a46..e4aae126a7 100644
--- a/libavutil/aes_ctr.h
+++ b/libavutil/aes_ctr.h
@@ -67,10 +67,15 @@  const uint8_t* av_aes_ctr_get_iv(struct AVAESCTR *a);
 void av_aes_ctr_set_random_iv(struct AVAESCTR *a);
 
 /**
- * Forcefully change the iv
+ * Forcefully change the 8-byte iv
  */
 void av_aes_ctr_set_iv(struct AVAESCTR *a, const uint8_t* iv);
 
+/**
+ * Forcefully change the "full" 16-byte iv, including the counter
+ */
+void av_aes_ctr_set_full_iv(struct AVAESCTR *a, const uint8_t* iv);
+
 /**
  * Increment the top 64 bit of the iv (performed after each frame)
  */
diff --git a/libavutil/tests/aes_ctr.c b/libavutil/tests/aes_ctr.c
index c5ebeda7ac..00fdb05d13 100644
--- a/libavutil/tests/aes_ctr.c
+++ b/libavutil/tests/aes_ctr.c
@@ -45,7 +45,7 @@  int main (void)
 
     av_aes_ctr_set_random_iv(ae);
     iv =   av_aes_ctr_get_iv(ae);
-    av_aes_ctr_set_iv(ad, iv);
+    av_aes_ctr_set_full_iv(ad, iv);
 
     av_aes_ctr_crypt(ae, tmp, plain, sizeof(tmp));
     av_aes_ctr_crypt(ad, tmp, tmp,   sizeof(tmp));
diff --git a/libavutil/version.h b/libavutil/version.h
index d7398c41c5..0c032c8553 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -79,7 +79,7 @@ 
  */
 
 #define LIBAVUTIL_VERSION_MAJOR  56
-#define LIBAVUTIL_VERSION_MINOR   8
+#define LIBAVUTIL_VERSION_MINOR   9
 #define LIBAVUTIL_VERSION_MICRO 100
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \