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

Jean-Christophe PLAGNIOL-VILLARD plagnioj at jcrosoft.com
Wed Mar 11 03:44:48 PDT 2015


On 06:32 Wed 11 Mar     , Sascha Hauer wrote:
> 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.
> 

even in linux we did allocate the ctx at framework level

this will reduce the binary size at the end just few bytes maybe but
few bytes everywhere make kiB as did Mazda on then new mx-5

to save 100Kg on their last roadster

Best Regards,
J.



More information about the barebox mailing list