From 7aeb9650b6c57a81c0cf903a3977e6d6fbb2808c Mon Sep 17 00:00:00 2001 From: Jean-Christophe PLAGNIOL-VILLARD Date: Tue, 17 Mar 2015 12:53:11 +0100 Subject: digest: add digest callback Combination of @init and @update and @final. This function effectively behaves as the entire chain of operations, @init, @update and @final issued in sequence. This is added for hardware which cannot do even the @finup, but can only do the whole transformation in one run. Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD Signed-off-by: Sascha Hauer --- crypto/digest.c | 18 ++++++++++++++++++ crypto/hmac.c | 1 + crypto/internal.h | 2 ++ crypto/md5.c | 1 + crypto/sha1.c | 1 + crypto/sha2.c | 1 + crypto/sha4.c | 1 + 7 files changed, 25 insertions(+) (limited to 'crypto') diff --git a/crypto/digest.c b/crypto/digest.c index 7869c049e9..7670ed06b7 100644 --- a/crypto/digest.c +++ b/crypto/digest.c @@ -58,6 +58,24 @@ end: return ret; } +int digest_generic_digest(struct digest *d, const void *data, + unsigned int len, u8 *md) + +{ + int ret; + + if (!data || len == 0 || !md) + return -EINVAL; + + ret = digest_init(d); + if (ret) + return ret; + ret = digest_update(d, data, len); + if (ret) + return ret; + return digest_final(d, md); +} + int digest_algo_register(struct digest_algo *d) { if (!d || !d->name || !d->update || !d->final || !d->verify || diff --git a/crypto/hmac.c b/crypto/hmac.c index f39e4c8e8c..b1c17afdf6 100644 --- a/crypto/hmac.c +++ b/crypto/hmac.c @@ -136,6 +136,7 @@ struct digest_algo hmac_algo = { .init = digest_hmac_init, .update = digest_hmac_update, .final = digest_hmac_final, + .digest = digest_generic_digest, .verify = digest_generic_verify, .set_key = digest_hmac_set_key, .free = digest_hmac_free, diff --git a/crypto/internal.h b/crypto/internal.h index f482654f63..c6f5908ea0 100644 --- a/crypto/internal.h +++ b/crypto/internal.h @@ -15,3 +15,5 @@ static inline int digest_hmac_register(struct digest_algo *algo, #endif int digest_generic_verify(struct digest *d, const unsigned char *md); +int digest_generic_digest(struct digest *d, const void *data, + unsigned int len, u8 *out); diff --git a/crypto/md5.c b/crypto/md5.c index 4847b38631..b7ad6f27e9 100644 --- a/crypto/md5.c +++ b/crypto/md5.c @@ -294,6 +294,7 @@ static struct digest_algo md5 = { .init = digest_md5_init, .update = digest_md5_update, .final = digest_md5_final, + .digest = digest_generic_digest, .verify = digest_generic_verify, .length = 16, .ctx_length = sizeof(struct MD5Context), diff --git a/crypto/sha1.c b/crypto/sha1.c index 09dee87321..b108f8ae31 100644 --- a/crypto/sha1.c +++ b/crypto/sha1.c @@ -315,6 +315,7 @@ static struct digest_algo m = { .init = digest_sha1_init, .update = digest_sha1_update, .final = digest_sha1_final, + .digest = digest_generic_digest, .verify = digest_generic_verify, .length = SHA1_SUM_LEN, .ctx_length = sizeof(sha1_context), diff --git a/crypto/sha2.c b/crypto/sha2.c index 9bf6541498..375a40e1f6 100644 --- a/crypto/sha2.c +++ b/crypto/sha2.c @@ -336,6 +336,7 @@ static struct digest_algo m256 = { .init = digest_sha256_init, .update = digest_sha2_update, .final = digest_sha2_final, + .digest = digest_generic_digest, .verify = digest_generic_verify, .length = SHA256_SUM_LEN, .ctx_length = sizeof(sha2_context), diff --git a/crypto/sha4.c b/crypto/sha4.c index 5c3097db4a..1b91e7fcc3 100644 --- a/crypto/sha4.c +++ b/crypto/sha4.c @@ -342,6 +342,7 @@ static struct digest_algo m512 = { .init = digest_sha512_init, .update = digest_sha4_update, .final = digest_sha4_final, + .digest = digest_generic_digest, .verify = digest_generic_verify, .length = SHA512_SUM_LEN, .ctx_length = sizeof(sha4_context), -- cgit v1.2.3