diff options
author | Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> | 2015-03-11 17:53:08 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2015-03-13 08:32:28 +0100 |
commit | 2f3c3f512b2ff5023a4177e167eb6b55055fe883 (patch) | |
tree | 3df19abcf2a21b3909037825bed82f723901a37e /crypto/sha4.c | |
parent | 3a436924121456c1347acedac31c9e19b2893565 (diff) | |
download | barebox-2f3c3f512b2ff5023a4177e167eb6b55055fe883.tar.gz barebox-2f3c3f512b2ff5023a4177e167eb6b55055fe883.tar.xz |
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 <plagnioj@jcrosoft.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'crypto/sha4.c')
-rw-r--r-- | crypto/sha4.c | 35 |
1 files changed, 28 insertions, 7 deletions
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 <linux/string.h> #include <asm/byteorder.h> +#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); |