diff options
author | Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> | 2015-03-17 12:53:11 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2015-03-19 07:46:22 +0100 |
commit | 7aeb9650b6c57a81c0cf903a3977e6d6fbb2808c (patch) | |
tree | 21490f2e829ad93f622b09d5c3bb7d322dc43a39 | |
parent | ec4f9699718054f2b4e49ed441f3420c257f5f26 (diff) | |
download | barebox-7aeb9650b6c57a81c0cf903a3977e6d6fbb2808c.tar.gz barebox-7aeb9650b6c57a81c0cf903a3977e6d6fbb2808c.tar.xz |
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 <plagnioj@jcrosoft.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r-- | crypto/digest.c | 18 | ||||
-rw-r--r-- | crypto/hmac.c | 1 | ||||
-rw-r--r-- | crypto/internal.h | 2 | ||||
-rw-r--r-- | crypto/md5.c | 1 | ||||
-rw-r--r-- | crypto/sha1.c | 1 | ||||
-rw-r--r-- | crypto/sha2.c | 1 | ||||
-rw-r--r-- | crypto/sha4.c | 1 | ||||
-rw-r--r-- | include/digest.h | 8 |
8 files changed, 33 insertions, 0 deletions
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), diff --git a/include/digest.h b/include/digest.h index 5d1d80c31d..718793a1a7 100644 --- a/include/digest.h +++ b/include/digest.h @@ -31,6 +31,8 @@ struct digest_algo { int (*init)(struct digest *d); int (*update)(struct digest *d, const void *data, unsigned long len); int (*final)(struct digest *d, unsigned char *md); + int (*digest)(struct digest *d, const void *data, + unsigned int len, u8 *out); int (*set_key)(struct digest *d, const unsigned char *key, unsigned int len); int (*verify)(struct digest *d, const unsigned char *md); @@ -78,6 +80,12 @@ static inline int digest_final(struct digest *d, unsigned char *md) return d->algo->final(d, md); } +static inline int digest_digest(struct digest *d, const void *data, + unsigned int len, u8 *md) +{ + return d->algo->digest(d, data, len, md); +} + static inline int digest_verify(struct digest *d, const unsigned char *md) { return d->algo->verify(d, md); |