summaryrefslogtreecommitdiffstats
path: root/crypto
diff options
context:
space:
mode:
Diffstat (limited to 'crypto')
-rw-r--r--crypto/hmac.c48
-rw-r--r--crypto/md5.c8
-rw-r--r--crypto/sha1.c8
-rw-r--r--crypto/sha2.c16
-rw-r--r--crypto/sha4.c16
5 files changed, 39 insertions, 57 deletions
diff --git a/crypto/hmac.c b/crypto/hmac.c
index 77814a1643..20af2a56de 100644
--- a/crypto/hmac.c
+++ b/crypto/hmac.c
@@ -7,6 +7,7 @@
#include <common.h>
#include <digest.h>
#include <malloc.h>
+#include <init.h>
#include <crypto/internal.h>
struct digest_hmac {
@@ -39,6 +40,8 @@ static int digest_hmac_alloc(struct digest *d)
if (!dh->d)
return -EINVAL;
+ d->length = dh->d->algo->length;
+
dh->ipad = xmalloc(hmac->pad_length);
dh->opad = xmalloc(hmac->pad_length);
@@ -148,34 +151,49 @@ struct digest_algo hmac_algo = {
.priority = 0,
.flags = DIGEST_ALGO_NEED_KEY,
},
- .alloc = digest_hmac_alloc,
- .init = digest_hmac_init,
- .update = digest_hmac_update,
- .final = digest_hmac_final,
- .digest = digest_generic_digest,
- .verify = digest_generic_verify,
- .set_key = digest_hmac_set_key,
- .free = digest_hmac_free,
- .ctx_length = sizeof(struct digest_hmac),
+ .alloc = digest_hmac_alloc,
+ .init = digest_hmac_init,
+ .update = digest_hmac_update,
+ .final = digest_hmac_final,
+ .digest = digest_generic_digest,
+ .verify = digest_generic_verify,
+ .set_key = digest_hmac_set_key,
+ .free = digest_hmac_free,
+ .ctx_length = sizeof(struct digest_hmac),
};
-int digest_hmac_register(struct digest_algo *algo, unsigned int pad_length)
+static int digest_hmac_register(char *name, unsigned int pad_length)
{
struct digest_hmac *dh;
- char *name;
- if (!algo || !pad_length)
+ if (!name || !pad_length)
return -EINVAL;
- name = algo->base.name;
dh = xzalloc(sizeof(*dh));
dh->name = xstrdup(name);
dh->pad_length = pad_length;
dh->algo = hmac_algo;
- dh->algo.length = algo->length;
dh->algo.base.name = asprintf("hmac(%s)", name);
dh->algo.base.driver_name = asprintf("hmac(%s)-generic", name);
- dh->algo.base.priority = algo->base.priority;
return digest_algo_register(&dh->algo);
}
+
+static int digest_hmac_initcall(void)
+{
+ if (IS_ENABLED(CONFIG_MD5))
+ digest_hmac_register("md5", 64);
+ if (IS_ENABLED(CONFIG_SHA1))
+ digest_hmac_register("sha1", 64);
+ if (IS_ENABLED(CONFIG_SHA224))
+ digest_hmac_register("sha224", 64);
+ if (IS_ENABLED(CONFIG_SHA256))
+ digest_hmac_register("sha256", 64);
+ if (IS_ENABLED(CONFIG_SHA384))
+ digest_hmac_register("sha384", 128);
+ if (IS_ENABLED(CONFIG_SHA512))
+ digest_hmac_register("sha512", 128);
+
+ return 0;
+}
+crypto_initcall(digest_hmac_initcall);
diff --git a/crypto/md5.c b/crypto/md5.c
index 74c9b706f0..23892babce 100644
--- a/crypto/md5.c
+++ b/crypto/md5.c
@@ -305,12 +305,6 @@ static struct digest_algo md5 = {
static int md5_digest_register(void)
{
- int ret;
-
- ret = digest_algo_register(&md5);
- if (ret)
- return ret;
-
- return digest_hmac_register(&md5, 64);
+ return digest_algo_register(&md5);
}
device_initcall(md5_digest_register);
diff --git a/crypto/sha1.c b/crypto/sha1.c
index a2ca191899..94d56c3e46 100644
--- a/crypto/sha1.c
+++ b/crypto/sha1.c
@@ -328,12 +328,6 @@ static struct digest_algo m = {
static int sha1_digest_register(void)
{
- int ret;
-
- ret = digest_algo_register(&m);
- if (ret)
- return ret;
-
- return digest_hmac_register(&m, 64);
+ return digest_algo_register(&m);
}
device_initcall(sha1_digest_register);
diff --git a/crypto/sha2.c b/crypto/sha2.c
index 42c40da757..f7b8bebde2 100644
--- a/crypto/sha2.c
+++ b/crypto/sha2.c
@@ -315,16 +315,10 @@ static struct digest_algo m224 = {
static int sha224_digest_register(void)
{
- int ret;
-
if (!IS_ENABLED(CONFIG_SHA224))
return 0;
- ret = digest_algo_register(&m224);
- if (ret)
- return ret;
-
- return digest_hmac_register(&m224, 64);
+ return digest_algo_register(&m224);
}
device_initcall(sha224_digest_register);
@@ -353,15 +347,9 @@ static struct digest_algo m256 = {
static int sha256_digest_register(void)
{
- int ret;
-
if (!IS_ENABLED(CONFIG_SHA256))
return 0;
- ret = digest_algo_register(&m256);
- if (ret)
- return ret;
-
- return digest_hmac_register(&m256, 64);
+ return digest_algo_register(&m256);
}
device_initcall(sha256_digest_register);
diff --git a/crypto/sha4.c b/crypto/sha4.c
index cb62d1d2f2..3f8fa0d293 100644
--- a/crypto/sha4.c
+++ b/crypto/sha4.c
@@ -321,16 +321,10 @@ static struct digest_algo m384 = {
static int sha384_digest_register(void)
{
- int ret;
-
if (!IS_ENABLED(CONFIG_SHA384))
return 0;
- ret = digest_algo_register(&m384);
- if (ret)
- return ret;
-
- return digest_hmac_register(&m384, 128);
+ return digest_algo_register(&m384);
}
device_initcall(sha384_digest_register);
@@ -359,15 +353,9 @@ static struct digest_algo m512 = {
static int sha512_digest_register(void)
{
- int ret;
-
if (!IS_ENABLED(CONFIG_SHA512))
return 0;
- ret = digest_algo_register(&m512);
- if (ret)
- return ret;
-
- return digest_hmac_register(&m512, 128);
+ return digest_algo_register(&m512);
}
device_initcall(sha512_digest_register);