crypto: hmac: move register to hmac
As we will use the best sha algo at runtime Add a new init level crypto_initcall to ensure that all the sha present before hmac Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
parent
ab5b2c35e1
commit
c3fe3d7059
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -33,7 +33,8 @@
|
|||
KEEP(*(.initcall.8)) \
|
||||
KEEP(*(.initcall.9)) \
|
||||
KEEP(*(.initcall.10)) \
|
||||
KEEP(*(.initcall.11))
|
||||
KEEP(*(.initcall.11)) \
|
||||
KEEP(*(.initcall.12))
|
||||
|
||||
#define BAREBOX_CMDS KEEP(*(SORT_BY_NAME(.barebox_cmd*)))
|
||||
|
||||
|
|
|
@ -4,16 +4,6 @@
|
|||
* GPL v2 only
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_DIGEST_HMAC
|
||||
int digest_hmac_register(struct digest_algo *algo, unsigned int pad_length);
|
||||
#else
|
||||
static inline int digest_hmac_register(struct digest_algo *algo,
|
||||
unsigned int pad_length)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
int digest_generic_verify(struct digest *d, const unsigned char *md);
|
||||
int digest_generic_digest(struct digest *d, const void *data,
|
||||
unsigned int len, u8 *out);
|
||||
|
|
|
@ -37,7 +37,8 @@ typedef int (*initcall_t)(void);
|
|||
#define coredevice_initcall(fn) __define_initcall("8",fn,8)
|
||||
#define fs_initcall(fn) __define_initcall("9",fn,9)
|
||||
#define device_initcall(fn) __define_initcall("10",fn,10)
|
||||
#define late_initcall(fn) __define_initcall("11",fn,11)
|
||||
#define crypto_initcall(fn) __define_initcall("11",fn,11)
|
||||
#define late_initcall(fn) __define_initcall("12",fn,12)
|
||||
|
||||
/* section for code used very early when
|
||||
* - we're not running from where we linked at
|
||||
|
|
Loading…
Reference in New Issue