From e0ea31bd2e73ca2fae56a3b89a50d91e6e74c962 Mon Sep 17 00:00:00 2001 From: Didactic Drunk <1479616+didactic-drunk@users.noreply.github.com> Date: Thu, 27 Jun 2019 16:52:45 -0700 Subject: [PATCH] Swap Kdf subkey_size and subkey_id arguments. --- README.md | 10 +++++----- spec/cox/kdf_spec.cr | 8 ++++---- src/cox/kdf.cr | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 2019030..12ffd21 100644 --- a/README.md +++ b/README.md @@ -131,11 +131,11 @@ output = d.hexdigest ```crystal kdf = Cox::Kdf.new -# kdf.derive(8_byte_context, subkey_size, subkey_id) -subkey1 = kdf.derive "context1", 16, 0 -subkey2 = kdf.derive "context1", 16, 1 -subkey3 = kdf.derive "context2", 32, 0 -subkey4 = kdf.derive "context2", 64, 1 +# kdf.derive(8_byte_context, subkey_id, subkey_size) +subkey1 = kdf.derive "context1", 0, 16 +subkey2 = kdf.derive "context1", 1, 16 +subkey3 = kdf.derive "context2", 0, 32 +subkey4 = kdf.derive "context2", 1, 64 ``` ### Password Hashing diff --git a/spec/cox/kdf_spec.cr b/spec/cox/kdf_spec.cr index 35bbdfe..a8675a1 100644 --- a/spec/cox/kdf_spec.cr +++ b/spec/cox/kdf_spec.cr @@ -10,15 +10,15 @@ describe Cox::Kdf do kdf2 = Cox::Kdf.from_base64 kdf1.to_base64 # verify generated subkey's are the same after loading - key1_s1 = kdf1.derive CONTEXT, 16, 0 - key2_s1 = kdf2.derive CONTEXT, 16, 0 + key1_s1 = kdf1.derive CONTEXT, 0, 16 + key2_s1 = kdf2.derive CONTEXT, 0, 16 key1_s1.should eq key2_s1 end it "generates different keys" do kdf1 = Cox::Kdf.new - subkey1 = kdf1.derive CONTEXT, 16, 0 - subkey2 = kdf1.derive CONTEXT, 16, 1 + subkey1 = kdf1.derive CONTEXT, 0, 16 + subkey2 = kdf1.derive CONTEXT, 1, 16 subkey1.should_not eq subkey2 end diff --git a/src/cox/kdf.cr b/src/cox/kdf.cr index 5d333b7..37ee384 100644 --- a/src/cox/kdf.cr +++ b/src/cox/kdf.cr @@ -16,7 +16,7 @@ module Cox # context must be 8 bytes # subkey_size must be 16..64 bytes as of libsodium 1.0.17 - def derive(context, subkey_size, subkey_id = 0) + def derive(context, subkey_id, subkey_size) if context.bytesize != LibSodium::KDF_CONTEXT_SIZE raise ArgumentError.new("context must be #{LibSodium::KDF_CONTEXT_SIZE}, got #{context.bytesize}") end