1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-23 12:43:46 +02:00

hmac: add support for SHA-2

Signed-off-by: James Almer <jamrial@gmail.com>
Signed-off-by: Martin Storsjö <martin@martin.st>
This commit is contained in:
James Almer 2015-07-28 15:36:14 -03:00 committed by Martin Storsjö
parent c6e0829e36
commit 7e38340b83
2 changed files with 28 additions and 5 deletions

View File

@ -26,7 +26,7 @@
#include "sha.h" #include "sha.h"
#include "mem.h" #include "mem.h"
#define MAX_HASHLEN 20 #define MAX_HASHLEN 32
#define MAX_BLOCKLEN 64 #define MAX_BLOCKLEN 64
struct AVHMAC { struct AVHMAC {
@ -39,11 +39,16 @@ struct AVHMAC {
int keylen; int keylen;
}; };
static av_cold void sha1_init(void *ctx) #define DEFINE_SHA(bits) \
{ static av_cold void sha ## bits ##_init(void *ctx) \
av_sha_init(ctx, 160); { \
av_sha_init(ctx, bits); \
} }
DEFINE_SHA(160)
DEFINE_SHA(224)
DEFINE_SHA(256)
AVHMAC *av_hmac_alloc(enum AVHMACType type) AVHMAC *av_hmac_alloc(enum AVHMACType type)
{ {
AVHMAC *c = av_mallocz(sizeof(*c)); AVHMAC *c = av_mallocz(sizeof(*c));
@ -61,7 +66,23 @@ AVHMAC *av_hmac_alloc(enum AVHMACType type)
case AV_HMAC_SHA1: case AV_HMAC_SHA1:
c->blocklen = 64; c->blocklen = 64;
c->hashlen = 20; 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->update = av_sha_update;
c->final = av_sha_final; c->final = av_sha_final;
c->hash = av_sha_alloc(); c->hash = av_sha_alloc();

View File

@ -32,6 +32,8 @@
enum AVHMACType { enum AVHMACType {
AV_HMAC_MD5, AV_HMAC_MD5,
AV_HMAC_SHA1, AV_HMAC_SHA1,
AV_HMAC_SHA224,
AV_HMAC_SHA256,
}; };
typedef struct AVHMAC AVHMAC; typedef struct AVHMAC AVHMAC;