[FFmpeg-cvslog] hmac: add support for SHA-2

James Almer git at videolan.org
Thu Jul 30 01:26:07 CEST 2015


ffmpeg | branch: master | James Almer <jamrial at gmail.com> | Tue Jul 28 15:36:14 2015 -0300| [7e38340b831af8e3271f22bd66b9da14953c02af] | committer: Martin Storsjö

hmac: add support for SHA-2

Signed-off-by: James Almer <jamrial at gmail.com>
Signed-off-by: Martin Storsjö <martin at martin.st>

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

 libavutil/hmac.c |   31 ++++++++++++++++++++++++++-----
 libavutil/hmac.h |    2 ++
 2 files changed, 28 insertions(+), 5 deletions(-)

diff --git a/libavutil/hmac.c b/libavutil/hmac.c
index f87728e..318174e 100644
--- a/libavutil/hmac.c
+++ b/libavutil/hmac.c
@@ -26,7 +26,7 @@
 #include "sha.h"
 #include "mem.h"
 
-#define MAX_HASHLEN 20
+#define MAX_HASHLEN 32
 #define MAX_BLOCKLEN 64
 
 struct AVHMAC {
@@ -39,11 +39,16 @@ struct AVHMAC {
     int keylen;
 };
 
-static av_cold void sha1_init(void *ctx)
-{
-    av_sha_init(ctx, 160);
+#define DEFINE_SHA(bits)                           \
+static av_cold void sha ## bits ##_init(void *ctx) \
+{                                                  \
+    av_sha_init(ctx, bits);                        \
 }
 
+DEFINE_SHA(160)
+DEFINE_SHA(224)
+DEFINE_SHA(256)
+
 AVHMAC *av_hmac_alloc(enum AVHMACType type)
 {
     AVHMAC *c = av_mallocz(sizeof(*c));
@@ -61,7 +66,23 @@ AVHMAC *av_hmac_alloc(enum AVHMACType type)
     case AV_HMAC_SHA1:
         c->blocklen = 64;
         c->hashlen  = 20;
-        c->init     = sha1_init;
+        c->init     = sha160_init;
+        c->update   = av_sha_update;
+        c->final    = av_sha_final;
+        c->hash     = av_sha_alloc();
+        break;
+    case AV_HMAC_SHA224:
+        c->blocklen = 64;
+        c->hashlen  = 28;
+        c->init     = sha224_init;
+        c->update   = av_sha_update;
+        c->final    = av_sha_final;
+        c->hash     = av_sha_alloc();
+        break;
+    case AV_HMAC_SHA256:
+        c->blocklen = 64;
+        c->hashlen  = 32;
+        c->init     = sha256_init;
         c->update   = av_sha_update;
         c->final    = av_sha_final;
         c->hash     = av_sha_alloc();
diff --git a/libavutil/hmac.h b/libavutil/hmac.h
index 28c2062..1ed5626 100644
--- a/libavutil/hmac.h
+++ b/libavutil/hmac.h
@@ -32,6 +32,8 @@
 enum AVHMACType {
     AV_HMAC_MD5,
     AV_HMAC_SHA1,
+    AV_HMAC_SHA224,
+    AV_HMAC_SHA256,
 };
 
 typedef struct AVHMAC AVHMAC;



More information about the ffmpeg-cvslog mailing list