2019-05-28 23:31:31 +02:00
|
|
|
require "../spec_helper"
|
2019-07-01 15:24:26 +02:00
|
|
|
require "../../src/sodium/kdf"
|
2019-05-28 23:31:31 +02:00
|
|
|
|
|
|
|
CONTEXT = "8_bytess"
|
|
|
|
|
2019-06-29 01:17:09 +02:00
|
|
|
describe Sodium::Kdf do
|
2019-05-28 23:31:31 +02:00
|
|
|
it "generates master key" do
|
2019-06-29 01:17:09 +02:00
|
|
|
kdf1 = Sodium::Kdf.new
|
2019-05-28 23:31:31 +02:00
|
|
|
|
|
|
|
# verify loading saved key
|
2021-06-22 02:54:23 +02:00
|
|
|
kdf2 = kdf1.key.readonly do |kslice|
|
|
|
|
Sodium::Kdf.new kslice.dup
|
|
|
|
end
|
|
|
|
|
|
|
|
kdf1.key.should eq kdf2.key
|
2019-05-28 23:31:31 +02:00
|
|
|
|
|
|
|
# verify generated subkey's are the same after loading
|
2019-06-28 01:52:45 +02:00
|
|
|
key1_s1 = kdf1.derive CONTEXT, 0, 16
|
|
|
|
key2_s1 = kdf2.derive CONTEXT, 0, 16
|
2019-05-28 23:31:31 +02:00
|
|
|
key1_s1.should eq key2_s1
|
|
|
|
end
|
|
|
|
|
|
|
|
it "generates different keys" do
|
2019-06-29 01:17:09 +02:00
|
|
|
kdf1 = Sodium::Kdf.new
|
2019-06-28 01:52:45 +02:00
|
|
|
subkey1 = kdf1.derive CONTEXT, 0, 16
|
|
|
|
subkey2 = kdf1.derive CONTEXT, 1, 16
|
2019-05-28 23:31:31 +02:00
|
|
|
subkey1.should_not eq subkey2
|
|
|
|
end
|
|
|
|
|
2019-06-28 02:20:02 +02:00
|
|
|
# TODO: test exceptions
|
2019-06-30 04:20:30 +02:00
|
|
|
# TODO: test wipe
|
2019-05-28 23:31:31 +02:00
|
|
|
end
|