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

Sascha Hauer s.hauer at pengutronix.de
Wed Mar 11 04:45:18 PDT 2015


On Wed, Mar 11, 2015 at 11:44:48AM +0100, Jean-Christophe PLAGNIOL-VILLARD wrote:
> 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

Ok, then let's hope this is really smaller in binary size.

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