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>
This commit is contained in:
parent
ec4f969971
commit
7aeb9650b6
|
@ -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 ||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue