[2/7] rc4: add av_rc4_alloc()

Message ID 1438032992-4680-3-git-send-email-jamrial@gmail.com
State New
Headers show

Commit Message

James Almer July 27, 2015, 9:36 p.m.
Signed-off-by: James Almer <jamrial@gmail.com>
---
 doc/APIchanges  |  1 +
 libavutil/rc4.c | 13 +++++++++++++
 libavutil/rc4.h | 21 +++++++++++++++++++++
 3 files changed, 35 insertions(+)

Patch

diff --git a/doc/APIchanges b/doc/APIchanges
index 4db1a3c..3d40ec7 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -15,6 +15,7 @@  API changes, most recent first:
 
 2015-xx-xx - lavu 54.16.0
   xxxxxxx -  Add av_blowfish_alloc().
+  xxxxxxx -  Add av_rc4_alloc().
 
 2015-xx-xx - lavc 56.35.0 - avcodec.h
   xxxxxxxxx - Rename CODEC_FLAG* defines to AV_CODEC_FLAG*.
diff --git a/libavutil/rc4.c b/libavutil/rc4.c
index 3bf710f..129c8f1 100644
--- a/libavutil/rc4.c
+++ b/libavutil/rc4.c
@@ -22,9 +22,22 @@ 
  */
 #include "avutil.h"
 #include "common.h"
+#include "mem.h"
 #include "rc4.h"
 
+#if FF_API_CRYPTO_CONTEXT
 typedef struct AVRC4 AVRC4;
+#else
+typedef struct AVRC4 {
+    uint8_t state[256];
+    int x, y;
+} AVRC4;
+#endif
+
+struct AVRC4 *av_rc4_alloc(void)
+{
+    return av_mallocz(sizeof(struct AVRC4));
+}
 
 int av_rc4_init(AVRC4 *r, const uint8_t *key, int key_bits, int decrypt) {
     int i, j;
diff --git a/libavutil/rc4.h b/libavutil/rc4.h
index ec3b47c..c6168a6 100644
--- a/libavutil/rc4.h
+++ b/libavutil/rc4.h
@@ -22,17 +22,34 @@ 
 #define AVUTIL_RC4_H
 
 #include <stdint.h>
+#include "version.h"
 
+/**
+ * @defgroup lavu_rc4 RC4
+ * @ingroup lavu_crypto
+ * @{
+ */
+
+#if FF_API_CRYPTO_CONTEXT
 struct AVRC4 {
     uint8_t state[256];
     int x, y;
 };
+#else
+struct AVRC4;
+#endif
+
+/**
+ * Allocate an AVRC4 context.
+ */
+struct AVRC4 *av_rc4_alloc(void);
 
 /**
  * @brief Initializes an AVRC4 context.
  *
  * @param key_bits must be a multiple of 8
  * @param decrypt 0 for encryption, 1 for decryption, currently has no effect
+ * @return zero on success, negative value otherwise
  */
 int av_rc4_init(struct AVRC4 *d, const uint8_t *key, int key_bits, int decrypt);
 
@@ -47,4 +64,8 @@  int av_rc4_init(struct AVRC4 *d, const uint8_t *key, int key_bits, int decrypt);
  */
 void av_rc4_crypt(struct AVRC4 *d, uint8_t *dst, const uint8_t *src, int count, uint8_t *iv, int decrypt);
 
+/**
+ * @}
+ */
+
 #endif /* AVUTIL_RC4_H */