[PATCH 2/9] digest: allow algo to specify their length at runtime

Jean-Christophe PLAGNIOL-VILLARD plagnioj at jcrosoft.com
Wed Mar 25 04:56:13 PDT 2015


such as RSA as we load a DER key we will detect the key size
at runtime and so the algo length.

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj at jcrosoft.com>
---
 crypto/digest.c  | 3 +--
 include/digest.h | 3 ++-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/crypto/digest.c b/crypto/digest.c
index 047131b..f902dc1 100644
--- a/crypto/digest.c
+++ b/crypto/digest.c
@@ -78,8 +78,7 @@ int digest_generic_digest(struct digest *d, const void *data,
 
 int digest_algo_register(struct digest_algo *d)
 {
-	if (!d || !d->name || !d->update || !d->final || !d->verify ||
-	    d->length < 1)
+	if (!d || !d->name || !d->update || !d->final || !d->verify)
 		return -EINVAL;
 
 	if (!d->init)
diff --git a/include/digest.h b/include/digest.h
index 85c4da3..c574b4d 100644
--- a/include/digest.h
+++ b/include/digest.h
@@ -47,6 +47,7 @@ struct digest_algo {
 struct digest {
 	struct digest_algo *algo;
 	void *ctx;
+	unsigned int length;
 };
 
 /*
@@ -99,7 +100,7 @@ static inline int digest_verify(struct digest *d, const unsigned char *md)
 
 static inline int digest_length(struct digest *d)
 {
-	return d->algo->length;
+	return d->length ? d->length : d->algo->length;
 }
 
 static inline int digest_set_key(struct digest *d, const unsigned char *key,
-- 
2.1.4




More information about the barebox mailing list