From c9ba75a48fe76e7bf7d56793449ac37c9bd84afe Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Fri, 23 Jan 2015 10:56:01 +0100 Subject: [PATCH] Add crypto_generichash_statebytes() sizeof() is not always an option when accessing the library from other languages. --- src/libsodium/crypto_generichash/crypto_generichash.c | 9 ++++++++- src/libsodium/include/sodium/crypto_generichash.h | 2 ++ test/default/generichash2.c | 1 + 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/libsodium/crypto_generichash/crypto_generichash.c b/src/libsodium/crypto_generichash/crypto_generichash.c index e7cc0ae6..e4547088 100644 --- a/src/libsodium/crypto_generichash/crypto_generichash.c +++ b/src/libsodium/crypto_generichash/crypto_generichash.c @@ -37,11 +37,18 @@ crypto_generichash_keybytes(void) return crypto_generichash_KEYBYTES; } -const char *crypto_generichash_primitive(void) +const char * +crypto_generichash_primitive(void) { return crypto_generichash_PRIMITIVE; } +size_t +crypto_generichash_statebytes(void) +{ + return sizeof(crypto_generichash_state); +} + int crypto_generichash(unsigned char *out, size_t outlen, const unsigned char *in, unsigned long long inlen, const unsigned char *key, diff --git a/src/libsodium/include/sodium/crypto_generichash.h b/src/libsodium/include/sodium/crypto_generichash.h index 851ada42..60d46524 100644 --- a/src/libsodium/include/sodium/crypto_generichash.h +++ b/src/libsodium/include/sodium/crypto_generichash.h @@ -42,6 +42,8 @@ SODIUM_EXPORT const char *crypto_generichash_primitive(void); typedef crypto_generichash_blake2b_state crypto_generichash_state; +SODIUM_EXPORT +size_t crypto_generichash_statebytes(void); SODIUM_EXPORT int crypto_generichash(unsigned char *out, size_t outlen, diff --git a/test/default/generichash2.c b/test/default/generichash2.c index cd9c889c..1458d484 100644 --- a/test/default/generichash2.c +++ b/test/default/generichash2.c @@ -10,6 +10,7 @@ int main(void) k[crypto_generichash_KEYBYTES_MAX]; size_t h, i, j; + assert(crypto_generichash_statebytes() == sizeof st); for (h = 0; h < crypto_generichash_KEYBYTES_MAX; ++h) k[h] = h;