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
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

View File

@ -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

View File

@ -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