diff options
| author | aunsane <aunsane@gmail.com> | 2017-12-15 01:05:56 +0300 |
|---|---|---|
| committer | aunsane <aunsane@gmail.com> | 2017-12-15 01:05:56 +0300 |
| commit | e124aa3611f38573898aa79c6eabe77bc874e58f (patch) | |
| tree | 819464260f758bbc002b23c0c8a77f93751dcb42 /libs/libsodium/src/crypto_kdf | |
| parent | bbd9647d47f20d10b39570def918a0ac68c305c9 (diff) | |
preparing to build tox from sources
Diffstat (limited to 'libs/libsodium/src/crypto_kdf')
| -rw-r--r-- | libs/libsodium/src/crypto_kdf/blake2b/kdf_blake2b.c | 52 | ||||
| -rw-r--r-- | libs/libsodium/src/crypto_kdf/crypto_kdf.c | 49 |
2 files changed, 101 insertions, 0 deletions
diff --git a/libs/libsodium/src/crypto_kdf/blake2b/kdf_blake2b.c b/libs/libsodium/src/crypto_kdf/blake2b/kdf_blake2b.c new file mode 100644 index 0000000000..2a690c9ac8 --- /dev/null +++ b/libs/libsodium/src/crypto_kdf/blake2b/kdf_blake2b.c @@ -0,0 +1,52 @@ +#include <errno.h> + +#include "crypto_kdf_blake2b.h" +#include "crypto_generichash_blake2b.h" +#include "private/common.h" + +size_t +crypto_kdf_blake2b_bytes_min(void) +{ + return crypto_kdf_blake2b_BYTES_MIN; +} + +size_t +crypto_kdf_blake2b_bytes_max(void) +{ + return crypto_kdf_blake2b_BYTES_MAX; +} + +size_t +crypto_kdf_blake2b_contextbytes(void) +{ + return crypto_kdf_blake2b_CONTEXTBYTES; +} + +size_t +crypto_kdf_blake2b_keybytes(void) +{ + return crypto_kdf_blake2b_KEYBYTES; +} + +int crypto_kdf_blake2b_derive_from_key(unsigned char *subkey, size_t subkey_len, + uint64_t subkey_id, + const char ctx[crypto_kdf_blake2b_CONTEXTBYTES], + const unsigned char key[crypto_kdf_blake2b_KEYBYTES]) +{ + unsigned char ctx_padded[crypto_generichash_blake2b_PERSONALBYTES]; + unsigned char salt[crypto_generichash_blake2b_SALTBYTES]; + + memcpy(ctx_padded, ctx, crypto_kdf_blake2b_CONTEXTBYTES); + memset(ctx_padded + crypto_kdf_blake2b_CONTEXTBYTES, 0, sizeof ctx_padded - crypto_kdf_blake2b_CONTEXTBYTES); + STORE64_LE(salt, subkey_id); + memset(salt + 8, 0, (sizeof salt) - 8); + if (subkey_len < crypto_kdf_blake2b_BYTES_MIN || + subkey_len > crypto_kdf_blake2b_BYTES_MAX) { + errno = EINVAL; + return -1; + } + return crypto_generichash_blake2b_salt_personal(subkey, subkey_len, + NULL, 0, + key, crypto_kdf_blake2b_KEYBYTES, + salt, ctx_padded); +} diff --git a/libs/libsodium/src/crypto_kdf/crypto_kdf.c b/libs/libsodium/src/crypto_kdf/crypto_kdf.c new file mode 100644 index 0000000000..b215d99ae6 --- /dev/null +++ b/libs/libsodium/src/crypto_kdf/crypto_kdf.c @@ -0,0 +1,49 @@ + +#include "crypto_kdf.h" +#include "randombytes.h" + +const char * +crypto_kdf_primitive(void) +{ + return crypto_kdf_PRIMITIVE; +} + +size_t +crypto_kdf_bytes_min(void) +{ + return crypto_kdf_BYTES_MIN; +} + +size_t +crypto_kdf_bytes_max(void) +{ + return crypto_kdf_BYTES_MAX; +} + +size_t +crypto_kdf_contextbytes(void) +{ + return crypto_kdf_CONTEXTBYTES; +} + +size_t +crypto_kdf_keybytes(void) +{ + return crypto_kdf_KEYBYTES; +} + +int +crypto_kdf_derive_from_key(unsigned char *subkey, size_t subkey_len, + uint64_t subkey_id, + const char ctx[crypto_kdf_CONTEXTBYTES], + const unsigned char key[crypto_kdf_KEYBYTES]) +{ + return crypto_kdf_blake2b_derive_from_key(subkey, subkey_len, + subkey_id, ctx, key); +} + +void +crypto_kdf_keygen(unsigned char k[crypto_kdf_KEYBYTES]) +{ + randombytes_buf(k, crypto_kdf_KEYBYTES); +} |
