2 #define TEST_NAME "kdf"
8 unsigned char *master_key;
11 char hex[crypto_kdf_BYTES_MAX * 2 + 1];
15 context = (char *) sodium_malloc(crypto_kdf_CONTEXTBYTES);
16 master_key = (unsigned char *) sodium_malloc(crypto_kdf_KEYBYTES);
18 memcpy(context, "KDF test", strlen("KDF test"));
19 for (i = 0; i < crypto_kdf_KEYBYTES; i++) {
22 subkey = (unsigned char *) sodium_malloc(crypto_kdf_BYTES_MAX);
23 for (i = 0; i < 10; i++) {
24 ret = crypto_kdf_derive_from_key(subkey, crypto_kdf_BYTES_MAX,
25 i, context, master_key);
27 sodium_bin2hex(hex, sizeof hex, subkey, crypto_kdf_BYTES_MAX);
32 for (i = 0; i < crypto_kdf_BYTES_MAX + 2; i++) {
33 subkey = (unsigned char *) sodium_malloc(crypto_kdf_BYTES_MAX);
34 if (crypto_kdf_derive_from_key(subkey, (size_t) i,
35 i, context, master_key) == 0) {
36 sodium_bin2hex(hex, sizeof hex, subkey, (size_t) i);
39 printf("Failure -- probably expected for output length=%u\n",
45 sodium_free(master_key);
48 assert(strcmp(crypto_kdf_primitive(), crypto_kdf_PRIMITIVE) == 0);
49 assert(crypto_kdf_BYTES_MAX > 0);
50 assert(crypto_kdf_BYTES_MIN <= crypto_kdf_BYTES_MAX);
51 assert(crypto_kdf_bytes_min() == crypto_kdf_BYTES_MIN);
52 assert(crypto_kdf_bytes_max() == crypto_kdf_BYTES_MAX);
53 assert(crypto_kdf_CONTEXTBYTES > 0);
54 assert(crypto_kdf_contextbytes() == crypto_kdf_CONTEXTBYTES);
55 assert(crypto_kdf_KEYBYTES >= 16);
56 assert(crypto_kdf_keybytes() == crypto_kdf_KEYBYTES);
57 assert(crypto_kdf_bytes_min() == crypto_kdf_blake2b_bytes_min());
58 assert(crypto_kdf_bytes_max() == crypto_kdf_blake2b_bytes_max());
59 assert(crypto_kdf_contextbytes() == crypto_kdf_blake2b_contextbytes());
60 assert(crypto_kdf_keybytes() == crypto_kdf_blake2b_keybytes());
62 printf("tv_kdf: ok\n");