Zoltan Fridrich <[email protected]> writes:

> I would like to contribute an implementation of the balloon hashing
> algorithm to Nettle.

Please provide some information about use cases and which specification
it is based on. (I only had a quick look at wikipedia and the
https://eprint.iacr.org/2016/027 paper, to get some context).

> I am aware that the code does not have proper Nettle formatting, I will
> change that after the patch will be in an acceptable state. Could you
> please provide feedback on the patch? Thank you.

A few initial comments:

1. The balloon_set_hash_alg implies global state, which isn't good in a
   library. It's better to pass the const struct nettle_hash *hash_alg
   as an argument to the balloon function.

2. For allocating smallish items like the hashing context, use stack
   allocation. Using the TMP_DECL, TMP_ALLOC macros (when size is
   bounded but determined at runtime), of if constant, a plain

      uint8_t data[3*sizeof(i)];
 
   instead of 

      uint8_t *data = xalloc(3 * sizeof(i));

   For the hashing context, if only one is needed, it would be better to
   allocate in the top-level baloon function, instead of allocating and
   freeing in the hash utility function. 

   Or in this particular case, one could also consider using

     uint64_t data[3];

   plus endian-dependent byteswapping when writing the values. As I
   understand it, if this part isn't performance critical, style should
   be chosen based on what makes the code clearest.

3. For allocating the working storage, which as I understand it can be
   intentionally pretty large, using xalloc isn't so nice. It would be
   more inline with nettle design to leave to the application to
   allocate the storage and pass in. You can then provide a function or
   macro the application can use to determine needed size.

Regards,
/Niels

-- 
Niels Möller. PGP key CB4962D070D77D7FCB8BA36271D8F1FF368C6677.
Internet email is subject to wholesale government surveillance.
_______________________________________________
nettle-bugs mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to