From 92138a77544da7ad7d880082e905c1ca8cd0c527 Mon Sep 17 00:00:00 2001 From: Jean-Christophe PLAGNIOL-VILLARD Date: Tue, 17 Mar 2015 12:53:09 +0100 Subject: crypto: digest: digest_file_window/digest_file/digest_file_by_name drop key params expect the key to be set before calling Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD Signed-off-by: Sascha Hauer --- commands/digest.c | 10 ++++++++-- crypto/digest.c | 10 ++-------- include/digest.h | 3 --- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/commands/digest.c b/commands/digest.c index 701e6a16fa..59c94ea2bf 100644 --- a/commands/digest.c +++ b/commands/digest.c @@ -52,11 +52,17 @@ static int do_digest(char *algorithm, int argc, char *argv[]) if (key) { char *tmp = asprintf("hmac(%s)", algorithm); d = digest_alloc(tmp); + BUG_ON(!d); + ret = digest_set_key(d, key, keylen); free(tmp); + if (ret) { + perror("set_key"); + goto err; + } } else { d = digest_alloc(algorithm); + BUG_ON(!d); } - BUG_ON(!d); if (argc < 1) return COMMAND_ERROR_USAGE; @@ -79,7 +85,6 @@ static int do_digest(char *algorithm, int argc, char *argv[]) } ret = digest_file_window(d, filename, - key, keylen, hash, start, size); if (ret < 0) { ret = 1; @@ -94,6 +99,7 @@ static int do_digest(char *algorithm, int argc, char *argv[]) argv++; } +err: free(hash); digest_free(d); diff --git a/crypto/digest.c b/crypto/digest.c index 2228ec7eb5..208a2041b1 100644 --- a/crypto/digest.c +++ b/crypto/digest.c @@ -116,7 +116,6 @@ void digest_free(struct digest *d) EXPORT_SYMBOL_GPL(digest_free); int digest_file_window(struct digest *d, const char *filename, - const unsigned char *key, size_t keylen, unsigned char *hash, ulong start, ulong size) { @@ -125,9 +124,6 @@ int digest_file_window(struct digest *d, const char *filename, unsigned char *buf; int flags = 0; - if (key) - digest_set_key(d, key, keylen); - ret = digest_init(d); if (ret) return ret; @@ -194,7 +190,6 @@ out: EXPORT_SYMBOL_GPL(digest_file_window); int digest_file(struct digest *d, const char *filename, - const unsigned char *key, size_t keylen, unsigned char *hash) { struct stat st; @@ -205,12 +200,11 @@ int digest_file(struct digest *d, const char *filename, if (ret < 0) return ret; - return digest_file_window(d, filename, key, keylen, hash, 0, st.st_size); + return digest_file_window(d, filename, hash, 0, st.st_size); } EXPORT_SYMBOL_GPL(digest_file); int digest_file_by_name(const char *algo, const char *filename, - const unsigned char *key, size_t keylen, unsigned char *hash) { struct digest *d; @@ -220,7 +214,7 @@ int digest_file_by_name(const char *algo, const char *filename, if (!d) return -EIO; - ret = digest_file(d, filename, key, keylen, hash); + ret = digest_file(d, filename, hash); digest_free(d); return ret; } diff --git a/include/digest.h b/include/digest.h index b890a7a10b..1c742f615e 100644 --- a/include/digest.h +++ b/include/digest.h @@ -54,14 +54,11 @@ struct digest *digest_alloc(const char *name); void digest_free(struct digest *d); int digest_file_window(struct digest *d, const char *filename, - const unsigned char *key, size_t keylen, unsigned char *hash, ulong start, ulong size); int digest_file(struct digest *d, const char *filename, - const unsigned char *key, size_t keylen, unsigned char *hash); int digest_file_by_name(const char *algo, const char *filename, - const unsigned char *key, size_t keylen, unsigned char *hash); static inline int digest_init(struct digest *d) -- cgit v1.2.3