summaryrefslogtreecommitdiff
path: root/libs/libsodium/src/crypto_kdf/blake2b/kdf_blake2b.c
diff options
context:
space:
mode:
authoraunsane <aunsane@gmail.com>2017-12-15 01:05:56 +0300
committeraunsane <aunsane@gmail.com>2017-12-15 01:05:56 +0300
commite124aa3611f38573898aa79c6eabe77bc874e58f (patch)
tree819464260f758bbc002b23c0c8a77f93751dcb42 /libs/libsodium/src/crypto_kdf/blake2b/kdf_blake2b.c
parentbbd9647d47f20d10b39570def918a0ac68c305c9 (diff)
preparing to build tox from sources
Diffstat (limited to 'libs/libsodium/src/crypto_kdf/blake2b/kdf_blake2b.c')
-rw-r--r--libs/libsodium/src/crypto_kdf/blake2b/kdf_blake2b.c52
1 files changed, 52 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);
+}