From 2f3c3f512b2ff5023a4177e167eb6b55055fe883 Mon Sep 17 00:00:00 2001 From: Jean-Christophe PLAGNIOL-VILLARD Date: Wed, 11 Mar 2015 17:53:08 +0100 Subject: digest: add HMAC support for md5, sha1, sha224, sha256, sha384, sha512 the hmac algo will be registered as hmac(%s) such as hmac(sha256) Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD Signed-off-by: Sascha Hauer --- crypto/sha4.c | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) (limited to 'crypto/sha4.c') diff --git a/crypto/sha4.c b/crypto/sha4.c index c3dcf17dd2..8a56081c33 100644 --- a/crypto/sha4.c +++ b/crypto/sha4.c @@ -29,6 +29,8 @@ #include #include +#include "internal.h" + #define SHA384_SUM_LEN 48 #define SHA512_SUM_LEN 64 @@ -311,6 +313,22 @@ static struct digest_algo m384 = { .ctx_length = sizeof(sha4_context), }; + +static int sha384_digest_register(void) +{ + int ret; + + if (!IS_ENABLED(CONFIG_SHA384)) + return 0; + + ret = digest_algo_register(&m384); + if (ret) + return ret; + + return digest_hmac_register(&m384, 128); +} +device_initcall(sha384_digest_register); + static int digest_sha512_init(struct digest *d) { sha4_starts(d->ctx, 0); @@ -327,14 +345,17 @@ static struct digest_algo m512 = { .ctx_length = sizeof(sha4_context), }; -static int sha4_digest_register(void) +static int sha512_digest_register(void) { - if IS_ENABLED(CONFIG_SHA384) - digest_algo_register(&m384); + int ret; - if IS_ENABLED(CONFIG_SHA512) - digest_algo_register(&m512); + if (!IS_ENABLED(CONFIG_SHA512)) + return 0; - return 0; + ret = digest_algo_register(&m512); + if (ret) + return ret; + + return digest_hmac_register(&m512, 128); } -device_initcall(sha4_digest_register); +device_initcall(sha512_digest_register); -- cgit v1.2.3