[PATCH 4/9] crypto: hmac: move register to hmac

Marc Kleine-Budde mkl at pengutronix.de
Mon Jun 15 07:27:34 PDT 2015


Sorry for resurrecting this old thread :)

On 03/25/2015 12:56 PM, Jean-Christophe PLAGNIOL-VILLARD wrote:
> 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

Why do we need this initcall?

[...]

> -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);

We just call digest_algo_register(), which adds us to the list of algos.
Nothing is allocated at this time.

>  }
> +
> +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);

Marc
-- 
Pengutronix e.K.                  | Marc Kleine-Budde           |
Industrial Linux Solutions        | Phone: +49-231-2826-924     |
Vertretung West/Dortmund          | Fax:   +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686  | http://www.pengutronix.de   |

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 455 bytes
Desc: OpenPGP digital signature
URL: <http://lists.infradead.org/pipermail/barebox/attachments/20150615/aa649177/attachment.sig>


More information about the barebox mailing list