1
mirror of https://github.com/jedisct1/libsodium.git synced 2024-12-28 22:21:15 -07:00

Add crypt_generichash_blake2b_statebytes function

The function crypto_generichash_statebytes exists to dynamically determine the
size of a crypto_generichash_state struct. This is useful when using libsodium
from a language which can't use sizeof on C types. However, no equivalent
existed for the crypto_generichash_blake2b_state struct for users who want to
explicitly use the blake2b algorithm.

The function crypt_generichash_blake2b_statebytes is added to fill this gap.
This commit is contained in:
Paul Barker 2016-01-16 17:25:14 +00:00
parent 1cce9b1e00
commit e20291d78e
3 changed files with 11 additions and 0 deletions

View File

@ -39,3 +39,10 @@ size_t
crypto_generichash_blake2b_personalbytes(void) { crypto_generichash_blake2b_personalbytes(void) {
return crypto_generichash_blake2b_PERSONALBYTES; return crypto_generichash_blake2b_PERSONALBYTES;
} }
size_t
crypto_generichash_blake2b_statebytes(void)
{
return (sizeof(crypto_generichash_blake2b_state) + (size_t) 63U)
& ~(size_t) 63U;
}

View File

@ -67,6 +67,9 @@ size_t crypto_generichash_blake2b_saltbytes(void);
SODIUM_EXPORT SODIUM_EXPORT
size_t crypto_generichash_blake2b_personalbytes(void); size_t crypto_generichash_blake2b_personalbytes(void);
SODIUM_EXPORT
size_t crypto_generichash_blake2b_statebytes(void);
SODIUM_EXPORT SODIUM_EXPORT
int crypto_generichash_blake2b(unsigned char *out, size_t outlen, int crypto_generichash_blake2b(unsigned char *out, size_t outlen,
const unsigned char *in, const unsigned char *in,

View File

@ -20,6 +20,7 @@ main(void)
size_t i; size_t i;
size_t j; size_t j;
assert(crypto_generichash_blake2b_statebytes() >= sizeof st);
for (h = 0; h < crypto_generichash_blake2b_KEYBYTES_MAX; ++h) { for (h = 0; h < crypto_generichash_blake2b_KEYBYTES_MAX; ++h) {
k[h] = (unsigned char) h; k[h] = (unsigned char) h;
} }