Swap Kdf subkey_size and subkey_id arguments.

This commit is contained in:
Didactic Drunk 2019-06-27 16:52:45 -07:00
parent 7292777bdb
commit e0ea31bd2e
3 changed files with 10 additions and 10 deletions

View File

@ -131,11 +131,11 @@ output = d.hexdigest
```crystal ```crystal
kdf = Cox::Kdf.new kdf = Cox::Kdf.new
# kdf.derive(8_byte_context, subkey_size, subkey_id) # kdf.derive(8_byte_context, subkey_id, subkey_size)
subkey1 = kdf.derive "context1", 16, 0 subkey1 = kdf.derive "context1", 0, 16
subkey2 = kdf.derive "context1", 16, 1 subkey2 = kdf.derive "context1", 1, 16
subkey3 = kdf.derive "context2", 32, 0 subkey3 = kdf.derive "context2", 0, 32
subkey4 = kdf.derive "context2", 64, 1 subkey4 = kdf.derive "context2", 1, 64
``` ```
### Password Hashing ### Password Hashing

View File

@ -10,15 +10,15 @@ describe Cox::Kdf do
kdf2 = Cox::Kdf.from_base64 kdf1.to_base64 kdf2 = Cox::Kdf.from_base64 kdf1.to_base64
# verify generated subkey's are the same after loading # verify generated subkey's are the same after loading
key1_s1 = kdf1.derive CONTEXT, 16, 0 key1_s1 = kdf1.derive CONTEXT, 0, 16
key2_s1 = kdf2.derive CONTEXT, 16, 0 key2_s1 = kdf2.derive CONTEXT, 0, 16
key1_s1.should eq key2_s1 key1_s1.should eq key2_s1
end end
it "generates different keys" do it "generates different keys" do
kdf1 = Cox::Kdf.new kdf1 = Cox::Kdf.new
subkey1 = kdf1.derive CONTEXT, 16, 0 subkey1 = kdf1.derive CONTEXT, 0, 16
subkey2 = kdf1.derive CONTEXT, 16, 1 subkey2 = kdf1.derive CONTEXT, 1, 16
subkey1.should_not eq subkey2 subkey1.should_not eq subkey2
end end

View File

@ -16,7 +16,7 @@ module Cox
# context must be 8 bytes # context must be 8 bytes
# subkey_size must be 16..64 bytes as of libsodium 1.0.17 # 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 if context.bytesize != LibSodium::KDF_CONTEXT_SIZE
raise ArgumentError.new("context must be #{LibSodium::KDF_CONTEXT_SIZE}, got #{context.bytesize}") raise ArgumentError.new("context must be #{LibSodium::KDF_CONTEXT_SIZE}, got #{context.bytesize}")
end end