summaryrefslogtreecommitdiffstats
path: root/crypto/digest.c
diff options
context:
space:
mode:
authorJean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>2015-03-17 12:53:10 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2015-03-19 07:46:22 +0100
commitec4f9699718054f2b4e49ed441f3420c257f5f26 (patch)
tree43721d010eba21f157bb3b4c053ae31c7a12fc2a /crypto/digest.c
parent92138a77544da7ad7d880082e905c1ca8cd0c527 (diff)
downloadbarebox-ec4f9699718054f2b4e49ed441f3420c257f5f26.tar.gz
barebox-ec4f9699718054f2b4e49ed441f3420c257f5f26.tar.xz
digest: add verify callback
this will allow to compare a md with the original one When calling this do not call final For RSA_SIGN verification final does not exist only verify as final will be for signing Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'crypto/digest.c')
-rw-r--r--crypto/digest.c24
1 files changed, 23 insertions, 1 deletions
diff --git a/crypto/digest.c b/crypto/digest.c
index 208a2041b1..7869c049e9 100644
--- a/crypto/digest.c
+++ b/crypto/digest.c
@@ -26,6 +26,8 @@
#include <module.h>
#include <linux/err.h>
+#include "internal.h"
+
static LIST_HEAD(digests);
static struct digest_algo *digest_algo_get_by_name(const char *name);
@@ -37,9 +39,29 @@ static int dummy_init(struct digest *d)
static void dummy_free(struct digest *d) {}
+int digest_generic_verify(struct digest *d, const unsigned char *md)
+{
+ int ret;
+ int len = digest_length(d);
+ unsigned char *tmp;
+
+ tmp = xmalloc(len);
+
+ ret = digest_final(d, tmp);
+ if (ret)
+ goto end;
+
+ ret = memcmp(md, tmp, len);
+ ret = ret ? -EINVAL : 0;
+end:
+ free(tmp);
+ return ret;
+}
+
int digest_algo_register(struct digest_algo *d)
{
- if (!d || !d->name || !d->update || !d->final || d->length < 1)
+ if (!d || !d->name || !d->update || !d->final || !d->verify ||
+ d->length < 1)
return -EINVAL;
if (!d->init)