2019-06-27 22:52:09 +02:00
|
|
|
require "../../spec_helper"
|
2019-06-29 01:17:09 +02:00
|
|
|
require "../../../src/sodium/cipher/chalsa"
|
2019-06-27 22:52:09 +02:00
|
|
|
|
|
|
|
{% for name in %w(XSalsa20 Salsa20 XChaCha20 ChaCha20Ietf ChaCha20) %}
|
|
|
|
# TODO: verify against test vectors.
|
2019-06-29 01:17:09 +02:00
|
|
|
describe Sodium::Cipher::{{ name.id }} do
|
2019-06-27 22:52:09 +02:00
|
|
|
it "xors" do
|
|
|
|
data = Bytes.new(100)
|
2019-07-09 01:08:39 +02:00
|
|
|
|
2019-06-29 01:17:09 +02:00
|
|
|
cipher1 = Sodium::Cipher::{{ name.id }}.new
|
|
|
|
cipher2 = Sodium::Cipher::{{ name.id }}.new
|
2019-07-09 01:08:39 +02:00
|
|
|
|
2019-06-27 22:52:09 +02:00
|
|
|
key = cipher1.random_key
|
2019-07-09 01:08:39 +02:00
|
|
|
cipher2.key = key
|
|
|
|
|
2019-06-27 22:52:09 +02:00
|
|
|
nonce = cipher1.random_nonce
|
2019-07-09 01:08:39 +02:00
|
|
|
cipher2.nonce = nonce
|
|
|
|
|
|
|
|
|
2019-06-27 22:52:09 +02:00
|
|
|
output = cipher1.update data
|
2019-07-09 01:08:39 +02:00
|
|
|
output.should_not eq data # Verify encryption did something.
|
2019-06-27 22:52:09 +02:00
|
|
|
cipher1.update(data).should_not eq output # Verify offset is incremented.
|
|
|
|
cipher1.final.should eq Bytes.new(0)
|
|
|
|
|
|
|
|
cipher2.update(output).should eq data
|
2019-07-09 01:08:39 +02:00
|
|
|
cipher2.final.should eq Bytes.new(0)
|
2019-06-27 22:52:09 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
{% end %}
|