From c0c645da45abe8fcb17999ea133f22aff991453d Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Sun, 26 Feb 2017 21:30:40 +0100 Subject: [PATCH] Test crypto_kdf constants, add _PRIMITIVE --- src/libsodium/crypto_kdf/crypto_kdf.c | 6 ++++++ src/libsodium/include/sodium/crypto_kdf.h | 4 ++++ test/default/kdf.c | 11 +++++++++++ 3 files changed, 21 insertions(+) diff --git a/src/libsodium/crypto_kdf/crypto_kdf.c b/src/libsodium/crypto_kdf/crypto_kdf.c index b80cd053..b215d99a 100644 --- a/src/libsodium/crypto_kdf/crypto_kdf.c +++ b/src/libsodium/crypto_kdf/crypto_kdf.c @@ -2,6 +2,12 @@ #include "crypto_kdf.h" #include "randombytes.h" +const char * +crypto_kdf_primitive(void) +{ + return crypto_kdf_PRIMITIVE; +} + size_t crypto_kdf_bytes_min(void) { diff --git a/src/libsodium/include/sodium/crypto_kdf.h b/src/libsodium/include/sodium/crypto_kdf.h index 9b0ac5b5..82a3aab9 100644 --- a/src/libsodium/include/sodium/crypto_kdf.h +++ b/src/libsodium/include/sodium/crypto_kdf.h @@ -30,6 +30,10 @@ size_t crypto_kdf_contextbytes(void); SODIUM_EXPORT size_t crypto_kdf_keybytes(void); +#define crypto_kdf_PRIMITIVE "blake2b" +SODIUM_EXPORT +const char *crypto_kdf_primitive(void); + SODIUM_EXPORT int crypto_kdf_derive_from_key(unsigned char *subkey, size_t subkey_len, uint64_t subkey_id, diff --git a/test/default/kdf.c b/test/default/kdf.c index 664d1c32..211cc4af 100644 --- a/test/default/kdf.c +++ b/test/default/kdf.c @@ -38,6 +38,17 @@ tv_kdf(void) } sodium_free(subkey); } + + assert(strcmp(crypto_kdf_primitive(), crypto_kdf_PRIMITIVE) == 0); + assert(crypto_kdf_BYTES_MAX > 0); + assert(crypto_kdf_BYTES_MIN <= crypto_kdf_BYTES_MAX); + assert(crypto_kdf_bytes_min() == crypto_kdf_BYTES_MIN); + assert(crypto_kdf_bytes_max() == crypto_kdf_BYTES_MAX); + assert(crypto_kdf_CONTEXTBYTES > 0); + assert(crypto_kdf_contextbytes() == crypto_kdf_CONTEXTBYTES); + assert(crypto_kdf_KEYBYTES >= 16); + assert(crypto_kdf_keybytes() == crypto_kdf_KEYBYTES); + printf("tv_kdf: ok\n"); }