[1/4,v2] blowfish: add av_blowfish_alloc()

Message ID 1438113469-3260-1-git-send-email-jamrial@gmail.com
State New
Headers show

Commit Message

James Almer July 28, 2015, 7:57 p.m.
Signed-off-by: James Almer <jamrial@gmail.com>
---
 doc/APIchanges       |  3 +++
 libavutil/blowfish.c | 15 +++++++++++++++
 libavutil/blowfish.h | 10 ++++++++++
 libavutil/version.h  |  5 ++++-
 4 files changed, 32 insertions(+), 1 deletion(-)

Comments

Anton Khirnov July 31, 2015, 7:18 a.m. | #1
Quoting James Almer (2015-07-28 21:57:46)
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
>  doc/APIchanges       |  3 +++
>  libavutil/blowfish.c | 15 +++++++++++++++
>  libavutil/blowfish.h | 10 ++++++++++
>  libavutil/version.h  |  5 ++++-
>  4 files changed, 32 insertions(+), 1 deletion(-)
> 

Thanks for the patches, all 4 pushed.

I wonder if this wouldn't also be a good time to add destructors for
those structs, in case we want them to have a more complex internal
structure later.

Patch

diff --git a/doc/APIchanges b/doc/APIchanges
index 4ee7f41..4db1a3c 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -13,6 +13,9 @@  libavutil:     2014-08-09
 
 API changes, most recent first:
 
+2015-xx-xx - lavu 54.16.0
+  xxxxxxx -  Add av_blowfish_alloc().
+
 2015-xx-xx - lavc 56.35.0 - avcodec.h
   xxxxxxxxx - Rename CODEC_FLAG* defines to AV_CODEC_FLAG*.
   xxxxxxxxx - Rename CODEC_CAP_* defines to AV_CODEC_CAP_*.
diff --git a/libavutil/blowfish.c b/libavutil/blowfish.c
index 8437dd6..a392459 100644
--- a/libavutil/blowfish.c
+++ b/libavutil/blowfish.c
@@ -24,8 +24,18 @@ 
 #include "avutil.h"
 #include "common.h"
 #include "intreadwrite.h"
+#include "mem.h"
 #include "blowfish.h"
 
+#if !FF_API_CRYPTO_CONTEXT
+#define AV_BF_ROUNDS 16
+
+struct AVBlowfish {
+    uint32_t p[AV_BF_ROUNDS + 2];
+    uint32_t s[4][256];
+};
+#endif
+
 static const uint32_t orig_p[AV_BF_ROUNDS + 2] = {
     0x243F6A88, 0x85A308D3, 0x13198A2E, 0x03707344,
     0xA4093822, 0x299F31D0, 0x082EFA98, 0xEC4E6C89,
@@ -312,6 +322,11 @@  static void F(AVBlowfish *ctx, uint32_t *xl, uint32_t *xr, int i)
     *xr = Xl;
 }
 
+AVBlowfish *av_blowfish_alloc(void)
+{
+    return av_mallocz(sizeof(struct AVBlowfish));
+}
+
 av_cold void av_blowfish_init(AVBlowfish *ctx, const uint8_t *key, int key_len)
 {
     uint32_t data, data_l, data_r;
diff --git a/libavutil/blowfish.h b/libavutil/blowfish.h
index 8c29536..4f86bf7 100644
--- a/libavutil/blowfish.h
+++ b/libavutil/blowfish.h
@@ -22,6 +22,7 @@ 
 #define AVUTIL_BLOWFISH_H
 
 #include <stdint.h>
+#include "version.h"
 
 /**
  * @defgroup lavu_blowfish Blowfish
@@ -29,12 +30,21 @@ 
  * @{
  */
 
+#if FF_API_CRYPTO_CONTEXT
 #define AV_BF_ROUNDS 16
 
 typedef struct AVBlowfish {
     uint32_t p[AV_BF_ROUNDS + 2];
     uint32_t s[4][256];
 } AVBlowfish;
+#else
+typedef struct AVBlowfish AVBlowfish;
+#endif
+
+/**
+ * Allocate an AVBlowfish context.
+ */
+AVBlowfish *av_blowfish_alloc(void);
 
 /**
  * Initialize an AVBlowfish context.
diff --git a/libavutil/version.h b/libavutil/version.h
index 4c3b7f4..c6227ef 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -54,7 +54,7 @@ 
  */
 
 #define LIBAVUTIL_VERSION_MAJOR 54
-#define LIBAVUTIL_VERSION_MINOR 15
+#define LIBAVUTIL_VERSION_MINOR 16
 #define LIBAVUTIL_VERSION_MICRO  0
 
 #define LIBAVUTIL_VERSION_INT   AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
@@ -114,6 +114,9 @@ 
 #ifndef FF_API_DLOG
 #define FF_API_DLOG                     (LIBAVUTIL_VERSION_MAJOR < 55)
 #endif
+#ifndef FF_API_CRYPTO_CONTEXT
+#define FF_API_CRYPTO_CONTEXT           (LIBAVUTIL_VERSION_MAJOR < 56)
+#endif
 
 
 /**