[PATCH 2/7] digest: make it multi-instance

Sascha Hauer s.hauer at pengutronix.de
Tue Mar 10 22:32:42 PDT 2015


On Tue, Mar 10, 2015 at 03:28:12PM +0100, Jean-Christophe PLAGNIOL-VILLARD wrote:
> 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 at jcrosoft.com>
> ---

> +struct digest* digest_alloc(char* name)
> +{
> +	struct digest* d;
> +	struct digest_algo* algo;
> +
> +	algo = digest_algo_get_by_name(name);
> +	if (!algo)
> +		return NULL;
> +
> +	d = xzalloc(sizeof(*d));
> +	d->algo = algo;
> +	d->ctx = xzalloc(algo->ctx_length);


I would pretty much prefer to delegate the allocation to the digest_algo
via an algo->alloc() function. The algo specific allocation function
could then embed struct digest into a bigger struct and use
container_of() to get its private data. No need for d->ctx and
algo->ctx_length then.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



More information about the barebox mailing list