BLAKE2 / libb2

C library providing BLAKE2b, BLAKE2s, BLAKE2bp, BLAKE2sp
Creative Commons Zero v1.0 Universal
132 stars 47 forks source link

why does blake2*_final need outlen? #6

Open capr opened 8 years ago

capr commented 8 years ago

blake2*_final() asks for outlen only to check if it's the same as the internal one:

int blake2b_final( blake2b_state *S, uint8_t *out, size_t outlen )
{
  if(S->outlen != outlen) return -1;

why is that?

sneves commented 8 years ago

Mostly to prevent accidents. For example, you decide to use the full 512-bit BLAKE2b instead of the shorter 256-bit one, but forget to update buffer sizes somewhere.

On second thought, it would make more sense to treat this outlen parameter as a buffer size, and verify that S->outlen <= outlen.

capr commented 8 years ago

I would personally prefer to have this parameter optional i.e. if (!outlen) outlen = S->outlen because I don't have safety issues like that in Lua and forcing this on the API makes little sense in that context.

Otherwise I have to wrap S just to keep the outlen passed to init() so I can pass it to back to final(), or treat S as non-opaque and get it from there.

capr commented 8 years ago

Actually it doesn't matter, the state is not opaque anyway I can get outlen from there.

Sorry for the noise :)