API change. Cox::Blake2b renamed to Cox::Digest::Blake2b
This commit is contained in:
parent
b50e068b43
commit
8e939b9518
24
README.md
24
README.md
@ -65,16 +65,16 @@ dependencies:
|
|||||||
| Class | |
|
| Class | |
|
||||||
| --- | --- |
|
| --- | --- |
|
||||||
| `CryptoBox` `Sign` `SecretBox` | I don't know much about crypto. |
|
| `CryptoBox` `Sign` `SecretBox` | I don't know much about crypto. |
|
||||||
| `Cox::CryptoBox::PrivateKey` | I want to encrypt + authenticate data using public key encryption. |
|
| [`Cox::CryptoBox::SecretKey`](https://didactic-drunk.github.io/cox/Cox/CryptoBox/SecretKey.html) | I want to encrypt + authenticate data using public key encryption. |
|
||||||
| `Cox::Sign::PrivateKey` | I want to sign or verify messages without encryption. |
|
| [`Cox::Sign::SecretKey`](https://didactic-drunk.github.io/cox/Cox/Sign/SecretKey.html) | I want to sign or verify messages without encryption. |
|
||||||
| `Cox::SecretBox` | I have a shared key and want to encrypt + authenticate data. |
|
| [`Cox::SecretBox`](https://didactic-drunk.github.io/cox/Cox/SecretBox.html) | I have a shared key and want to encrypt + authenticate data. |
|
||||||
| AEAD | I have a shared key and want encrypt + authenticate streamed data. (not implemented yet) |
|
| AEAD | I have a shared key and want encrypt + authenticate streamed data. (Not implemented yet) |
|
||||||
| `Cox::Blake2b` | I want to hash data fast and securely. |
|
| [`Cox::Digest::Blake2b`](https://didactic-drunk.github.io/cox/Cox/Digest::Blake2b.html) | I want to hash data fast and securely. |
|
||||||
| `Cox::SipHash` | I want to hash data really fast and less securely. (not implemented yet) |
|
| `Cox::Digest::SipHash` | I want to hash data really fast and less securely. (Not implemented yet) |
|
||||||
| `Cox::Pwhash` | I want to hash a password and store it. |
|
| `Cox::Pwhash` | I want to hash a password and store it. |
|
||||||
| `Cox::Pwhash` | I want to derive a key from a password. |
|
| `Cox::Pwhash` | I want to derive a key from a password. |
|
||||||
| `Cox::Kdf` | I have a high quality master key and want to make subkeys. |
|
| `Cox::Kdf` | I have a high quality master key and want to make subkeys. |
|
||||||
| `Cox::Cipher::Chalsa` | What goes with guacamole? |
|
| [`Cox::Cipher::Chalsa`](https://didactic-drunk.github.io/cox/Cox/Cipher/Chalsa.html) | What goes with guacamole? |
|
||||||
| Everything else | I want to design my own crypto protocol and probably do it wrong. |
|
| Everything else | I want to design my own crypto protocol and probably do it wrong. |
|
||||||
|
|
||||||
|
|
||||||
@ -142,14 +142,14 @@ message = key.decrypt_easy encrypted, nonce
|
|||||||
|
|
||||||
### Blake2b
|
### Blake2b
|
||||||
```crystal
|
```crystal
|
||||||
key = Bytes.new Cox::Blake2B::KEY_SIZE
|
key = Bytes.new Cox::Digest::Blake2B::KEY_SIZE
|
||||||
salt = Bytes.new Cox::Blake2B::SALT_SIZE
|
salt = Bytes.new Cox::Digest::Blake2B::SALT_SIZE
|
||||||
personal = Bytes.new Cox::Blake2B::PERSONAL_SIZE
|
personal = Bytes.new Cox::Digest::Blake2B::PERSONAL_SIZE
|
||||||
out_size = 64 # bytes between Cox::Blake2B::OUT_SIZE_MIN and Cox::Blake2B::OUT_SIZE_MAX
|
out_size = 64 # bytes between Cox::Digest::Blake2B::OUT_SIZE_MIN and Cox::Digest::Blake2B::OUT_SIZE_MAX
|
||||||
data = "data".to_slice
|
data = "data".to_slice
|
||||||
|
|
||||||
# output_size, key, salt, and personal are optional.
|
# output_size, key, salt, and personal are optional.
|
||||||
digest = Cox::Blake2b.new out_size, key: key, salt: salt, personal: personal
|
digest = Cox::Digest::Blake2b.new out_size, key: key, salt: salt, personal: personal
|
||||||
digest.update data
|
digest.update data
|
||||||
output = d.hexdigest
|
output = d.hexdigest
|
||||||
|
|
||||||
|
@ -13,19 +13,19 @@ puts "'crystal run --release benchmarks/blake2b.cr sha1 sha256'"
|
|||||||
Benchmark.ips(warmup: 0.5) do |bm|
|
Benchmark.ips(warmup: 0.5) do |bm|
|
||||||
sizes.each_with_index do |size, i|
|
sizes.each_with_index do |size, i|
|
||||||
bm.report "blake2b new obj per iter #{size}" do
|
bm.report "blake2b new obj per iter #{size}" do
|
||||||
d = Cox::Blake2b.new 64
|
d = Cox::Digest::Blake2b.new 64
|
||||||
d.update bufs[i]
|
d.update bufs[i]
|
||||||
d.digest
|
d.digest
|
||||||
end
|
end
|
||||||
|
|
||||||
d = Cox::Blake2b.new output_size
|
d = Cox::Digest::Blake2b.new output_size
|
||||||
bm.report "blake2b reset per iter #{size}" do
|
bm.report "blake2b reset per iter #{size}" do
|
||||||
d.reset
|
d.reset
|
||||||
d.update bufs[i]
|
d.update bufs[i]
|
||||||
d.digest
|
d.digest
|
||||||
end
|
end
|
||||||
|
|
||||||
d = Cox::Blake2b.new output_size
|
d = Cox::Digest::Blake2b.new output_size
|
||||||
dst = Bytes.new d.digest_size
|
dst = Bytes.new d.digest_size
|
||||||
bm.report "blake2b reset reusing buffer per iter #{size}" do
|
bm.report "blake2b reset reusing buffer per iter #{size}" do
|
||||||
d.reset
|
d.reset
|
||||||
|
@ -23,10 +23,10 @@ test_vectors = [
|
|||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
describe Cox::Blake2b do
|
describe Cox::Digest::Blake2b do
|
||||||
it "libsodium comparisons" do
|
it "libsodium comparisons" do
|
||||||
libsodium_comparisons.each do |vec|
|
libsodium_comparisons.each do |vec|
|
||||||
d = Cox::Blake2b.new vec[:out_size], key: vec[:key].try(&.hexbytes)
|
d = Cox::Digest::Blake2b.new vec[:out_size], key: vec[:key].try(&.hexbytes)
|
||||||
d.update vec[:input].hexbytes
|
d.update vec[:input].hexbytes
|
||||||
d.hexdigest.should eq vec[:output]
|
d.hexdigest.should eq vec[:output]
|
||||||
end
|
end
|
||||||
@ -34,31 +34,31 @@ describe Cox::Blake2b do
|
|||||||
|
|
||||||
it "test vectors" do
|
it "test vectors" do
|
||||||
test_vectors.each do |vec|
|
test_vectors.each do |vec|
|
||||||
d = Cox::Blake2b.new 64, key: vec[:key].hexbytes
|
d = Cox::Digest::Blake2b.new 64, key: vec[:key].hexbytes
|
||||||
d.update vec[:input].hexbytes
|
d.update vec[:input].hexbytes
|
||||||
d.hexdigest.should eq vec[:output]
|
d.hexdigest.should eq vec[:output]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it "produces different output with different salt or personal params" do
|
it "produces different output with different salt or personal params" do
|
||||||
key = Bytes.new Cox::Blake2b::KEY_SIZE
|
key = Bytes.new Cox::Digest::Blake2b::KEY_SIZE
|
||||||
salt = Bytes.new Cox::Blake2b::SALT_SIZE
|
salt = Bytes.new Cox::Digest::Blake2b::SALT_SIZE
|
||||||
salt2 = Bytes.new Cox::Blake2b::SALT_SIZE
|
salt2 = Bytes.new Cox::Digest::Blake2b::SALT_SIZE
|
||||||
salt2 = salt.dup
|
salt2 = salt.dup
|
||||||
salt2[0] = 1
|
salt2[0] = 1
|
||||||
personal = Bytes.new Cox::Blake2b::PERSONAL_SIZE
|
personal = Bytes.new Cox::Digest::Blake2b::PERSONAL_SIZE
|
||||||
personal2 = personal.dup
|
personal2 = personal.dup
|
||||||
personal2[0] = 1
|
personal2[0] = 1
|
||||||
|
|
||||||
d = Cox::Blake2b.new key: key, salt: salt, personal: personal
|
d = Cox::Digest::Blake2b.new key: key, salt: salt, personal: personal
|
||||||
d.update "foo".to_slice
|
d.update "foo".to_slice
|
||||||
output = d.hexdigest
|
output = d.hexdigest
|
||||||
|
|
||||||
d = Cox::Blake2b.new key: key, salt: salt2, personal: personal
|
d = Cox::Digest::Blake2b.new key: key, salt: salt2, personal: personal
|
||||||
d.update "foo".to_slice
|
d.update "foo".to_slice
|
||||||
saltout = d.hexdigest
|
saltout = d.hexdigest
|
||||||
|
|
||||||
d = Cox::Blake2b.new key: key, salt: salt, personal: personal2
|
d = Cox::Digest::Blake2b.new key: key, salt: salt, personal: personal2
|
||||||
d.update "foo".to_slice
|
d.update "foo".to_slice
|
||||||
personalout = d.hexdigest
|
personalout = d.hexdigest
|
||||||
|
|
||||||
@ -69,19 +69,19 @@ describe Cox::Blake2b do
|
|||||||
|
|
||||||
it "raises on invalid " do
|
it "raises on invalid " do
|
||||||
expect_raises ArgumentError do
|
expect_raises ArgumentError do
|
||||||
Cox::Blake2b.new key: Bytes.new(128)
|
Cox::Digest::Blake2b.new key: Bytes.new(128)
|
||||||
end
|
end
|
||||||
|
|
||||||
expect_raises ArgumentError do
|
expect_raises ArgumentError do
|
||||||
Cox::Blake2b.new salt: Bytes.new(1)
|
Cox::Digest::Blake2b.new salt: Bytes.new(1)
|
||||||
end
|
end
|
||||||
|
|
||||||
expect_raises ArgumentError do
|
expect_raises ArgumentError do
|
||||||
Cox::Blake2b.new salt: Bytes.new(128)
|
Cox::Digest::Blake2b.new salt: Bytes.new(128)
|
||||||
end
|
end
|
||||||
|
|
||||||
expect_raises ArgumentError do
|
expect_raises ArgumentError do
|
||||||
Cox::Blake2b.new personal: Bytes.new(128)
|
Cox::Digest::Blake2b.new personal: Bytes.new(128)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
require "openssl/digest/digest_base"
|
require "openssl/digest/digest_base"
|
||||||
|
|
||||||
module Cox
|
module Cox::Digest
|
||||||
class Blake2b
|
class Blake2b
|
||||||
# provides copying digest/hexdigest methods
|
# provides copying digest/hexdigest methods
|
||||||
include OpenSSL::DigestBase
|
include OpenSSL::DigestBase
|
Loading…
Reference in New Issue
Block a user