crypto: digest: speficied when a digest need a key to be used
such as for hmac(xxx) you must provide a key This will allow to enforce the correct parameter at digest command <digest>sum is not impacted 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
b0be99fc10
commit
ca95c2531f
|
@ -34,6 +34,9 @@ int __do_digest(struct digest *d, unsigned char *key, int keylen,
|
|||
perror("set_key");
|
||||
goto err;
|
||||
}
|
||||
} else if (digest_is_flags(d, DIGEST_ALGO_NEED_KEY)) {
|
||||
eprintf("%s need a key to be used\n", digest_name(d));
|
||||
goto err;
|
||||
}
|
||||
|
||||
hash = calloc(digest_length(d), sizeof(unsigned char));
|
||||
|
|
|
@ -145,6 +145,7 @@ err:
|
|||
}
|
||||
|
||||
struct digest_algo hmac_algo = {
|
||||
.flags = DIGEST_ALGO_NEED_KEY,
|
||||
.alloc = digest_hmac_alloc,
|
||||
.init = digest_hmac_init,
|
||||
.update = digest_hmac_update,
|
||||
|
|
|
@ -25,6 +25,8 @@ struct digest;
|
|||
|
||||
struct digest_algo {
|
||||
char *name;
|
||||
#define DIGEST_ALGO_NEED_KEY (1 << 0)
|
||||
unsigned int flags;
|
||||
|
||||
int (*alloc)(struct digest *d);
|
||||
void (*free)(struct digest *d);
|
||||
|
@ -108,4 +110,14 @@ static inline int digest_set_key(struct digest *d, const unsigned char *key,
|
|||
return d->algo->set_key(d, key, len);
|
||||
}
|
||||
|
||||
static inline int digest_is_flags(struct digest *d, unsigned int flags)
|
||||
{
|
||||
return d->algo->flags & flags;
|
||||
}
|
||||
|
||||
static inline const char *digest_name(struct digest *d)
|
||||
{
|
||||
return d->algo->name;
|
||||
}
|
||||
|
||||
#endif /* __SH_ST_DEVICES_H__ */
|
||||
|
|
Loading…
Reference in New Issue