summaryrefslogtreecommitdiffstats
path: root/crypto/sha1.c
diff options
context:
space:
mode:
authorJean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>2015-03-11 17:53:04 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2015-03-12 07:58:24 +0100
commit27b2336029335ea3f02243ff170986cdab1f98ef (patch)
tree722083808d1ce9b3bb69d3cca3520ce61a09064d /crypto/sha1.c
parent804fae5d16c8c48c6fca8d54f2878a2e382a0bc2 (diff)
downloadbarebox-27b2336029335ea3f02243ff170986cdab1f98ef.tar.gz
barebox-27b2336029335ea3f02243ff170986cdab1f98ef.tar.xz
digest: make it multi-instance
Now you need to call digest_alloc and when you finish to use it digest_free. We need this for upcomming aes encryption support and secure boot as we will need multiple instance of the same digest. Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'crypto/sha1.c')
-rw-r--r--crypto/sha1.c34
1 files changed, 11 insertions, 23 deletions
diff --git a/crypto/sha1.c b/crypto/sha1.c
index 58d14a8b3f..b6f4cbbc5a 100644
--- a/crypto/sha1.c
+++ b/crypto/sha1.c
@@ -286,16 +286,9 @@ static void sha1_finish (sha1_context * ctx, uint8_t output[20])
PUT_UINT32_BE (ctx->state[4], output, 16);
}
-struct sha1 {
- sha1_context context;
- struct digest d;
-};
-
static int digest_sha1_init(struct digest *d)
{
- struct sha1 *m = container_of(d, struct sha1, d);
-
- sha1_starts(&m->context);
+ sha1_starts(d->ctx);
return 0;
}
@@ -303,35 +296,30 @@ static int digest_sha1_init(struct digest *d)
static int digest_sha1_update(struct digest *d, const void *data,
unsigned long len)
{
- struct sha1 *m = container_of(d, struct sha1, d);
-
- sha1_update(&m->context, (uint8_t*)data, len);
+ sha1_update(d->ctx, (uint8_t*)data, len);
return 0;
}
static int digest_sha1_final(struct digest *d, unsigned char *md)
{
- struct sha1 *m = container_of(d, struct sha1, d);
-
- sha1_finish(&m->context, md);
+ sha1_finish(d->ctx, md);
return 0;
}
-static struct sha1 m = {
- .d = {
- .name = "sha1",
- .init = digest_sha1_init,
- .update = digest_sha1_update,
- .final = digest_sha1_final,
- .length = SHA1_SUM_LEN,
- }
+static struct digest_algo m = {
+ .name = "sha1",
+ .init = digest_sha1_init,
+ .update = digest_sha1_update,
+ .final = digest_sha1_final,
+ .length = SHA1_SUM_LEN,
+ .ctx_length = sizeof(sha1_context),
};
static int sha1_digest_register(void)
{
- digest_register(&m.d);
+ digest_algo_register(&m);
return 0;
}