Formatting
parent
e0ea31bd2e
commit
be5b250a22
|
@ -173,10 +173,11 @@ Ops limit →
|
||||||
## Contributing
|
## Contributing
|
||||||
|
|
||||||
1. Fork it ( https://github.com/didactic-drunk/cox/fork )
|
1. Fork it ( https://github.com/didactic-drunk/cox/fork )
|
||||||
2. Create your feature branch (git checkout -b my-new-feature)
|
2. **Install a formatting check git hook (ln -sf ../../scripts/git/pre-commit .git/hooks)**
|
||||||
3. Commit your changes (git commit -am 'Add some feature')
|
3. Create your feature branch (git checkout -b my-new-feature)
|
||||||
4. Push to the branch (git push origin my-new-feature)
|
4. Commit your changes (git commit -am 'Add some feature')
|
||||||
5. Create a new Pull Request
|
5. Push to the branch (git push origin my-new-feature)
|
||||||
|
6. Create a new Pull Request
|
||||||
|
|
||||||
## Contributors
|
## Contributors
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,6 @@ test_vectors = [
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
describe Cox::Blake2b do
|
describe Cox::Blake2b do
|
||||||
it "libsodium comparisons" do
|
it "libsodium comparisons" do
|
||||||
libsodium_comparisons.each do |vec|
|
libsodium_comparisons.each do |vec|
|
||||||
|
@ -51,7 +50,6 @@ describe Cox::Blake2b do
|
||||||
personal2 = personal.dup
|
personal2 = personal.dup
|
||||||
personal2[0] = 1
|
personal2[0] = 1
|
||||||
|
|
||||||
|
|
||||||
d = Cox::Blake2b.new key: key, salt: salt, personal: personal
|
d = Cox::Blake2b.new key: key, salt: salt, personal: personal
|
||||||
d.update "foo".to_slice
|
d.update "foo".to_slice
|
||||||
output = d.hexdigest
|
output = d.hexdigest
|
||||||
|
|
|
@ -20,4 +20,3 @@ require "../../../src/cox/cipher/chalsa"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
{% end %}
|
{% end %}
|
||||||
|
|
||||||
|
|
|
@ -3,13 +3,14 @@ require "random/secure"
|
||||||
module Cox
|
module Cox
|
||||||
class Error < ::Exception
|
class Error < ::Exception
|
||||||
end
|
end
|
||||||
|
|
||||||
class VerificationFailed < Error
|
class VerificationFailed < Error
|
||||||
end
|
end
|
||||||
|
|
||||||
class DecryptionFailed < Error
|
class DecryptionFailed < Error
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
require "./cox/*"
|
require "./cox/*"
|
||||||
|
|
||||||
module Cox
|
module Cox
|
||||||
|
@ -59,7 +60,7 @@ module Cox
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if Cox::LibSodium.sodium_init() == -1
|
if Cox::LibSodium.sodium_init == -1
|
||||||
STDERR.puts("Failed to init libsodium")
|
STDERR.puts("Failed to init libsodium")
|
||||||
exit(1)
|
exit(1)
|
||||||
end
|
end
|
||||||
|
|
|
@ -24,7 +24,6 @@ module Cox
|
||||||
@have_salt = false
|
@have_salt = false
|
||||||
@have_personal = false
|
@have_personal = false
|
||||||
|
|
||||||
|
|
||||||
# implemented as static array's so clone works without jumping through hoops.
|
# implemented as static array's so clone works without jumping through hoops.
|
||||||
@key = StaticArray(UInt8, 64).new 0
|
@key = StaticArray(UInt8, 64).new 0
|
||||||
@salt = StaticArray(UInt8, 16).new 0
|
@salt = StaticArray(UInt8, 16).new 0
|
||||||
|
@ -104,5 +103,3 @@ module Cox
|
||||||
|
|
||||||
Blake2b.new.__validate_sizes__
|
Blake2b.new.__validate_sizes__
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,6 @@ module Cox::Cipher
|
||||||
update src, Bytes.new(src.bytesize)
|
update src, Bytes.new(src.bytesize)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
# Provided for compatibility with block ciphers.
|
# Provided for compatibility with block ciphers.
|
||||||
# Stream ciphers don't have additional data.
|
# Stream ciphers don't have additional data.
|
||||||
def final
|
def final
|
||||||
|
@ -57,11 +56,11 @@ module Cox::Cipher
|
||||||
end
|
end
|
||||||
|
|
||||||
abstract def update(src : Bytes, dst : Bytes)
|
abstract def update(src : Bytes, dst : Bytes)
|
||||||
abstract def key_size()
|
abstract def key_size
|
||||||
abstract def nonce_size()
|
abstract def nonce_size
|
||||||
end
|
end
|
||||||
|
|
||||||
{% for key, val in { "XSalsa20" => "xsalsa20", "Salsa20" => "salsa20", "XChaCha20" => "xchacha20", "ChaCha20Ietf" => "chacha20_ietf", "ChaCha20" => "chacha20",} %}
|
{% for key, val in {"XSalsa20" => "xsalsa20", "Salsa20" => "salsa20", "XChaCha20" => "xchacha20", "ChaCha20Ietf" => "chacha20_ietf", "ChaCha20" => "chacha20"} %}
|
||||||
# These classes can be used to generate pseudo-random data from a key,
|
# These classes can be used to generate pseudo-random data from a key,
|
||||||
# or as building blocks for implementing custom constructions, but they
|
# or as building blocks for implementing custom constructions, but they
|
||||||
# are not alternatives to secretbox.
|
# are not alternatives to secretbox.
|
||||||
|
|
|
@ -1,31 +1,31 @@
|
||||||
module Cox
|
module Cox
|
||||||
@[Link(ldflags: "`#{__DIR__}/../../build/pkg-libs.sh #{__DIR__}/../..`")]
|
@[Link(ldflags: "`#{__DIR__}/../../build/pkg-libs.sh #{__DIR__}/../..`")]
|
||||||
lib LibSodium
|
lib LibSodium
|
||||||
fun sodium_init() : LibC::Int
|
fun sodium_init : LibC::Int
|
||||||
|
|
||||||
fun crypto_box_publickeybytes() : LibC::SizeT
|
fun crypto_box_publickeybytes : LibC::SizeT
|
||||||
fun crypto_box_secretkeybytes() : LibC::SizeT
|
fun crypto_box_secretkeybytes : LibC::SizeT
|
||||||
fun crypto_box_noncebytes() : LibC::SizeT
|
fun crypto_box_noncebytes : LibC::SizeT
|
||||||
fun crypto_box_macbytes() : LibC::SizeT
|
fun crypto_box_macbytes : LibC::SizeT
|
||||||
fun crypto_sign_publickeybytes() : LibC::SizeT
|
fun crypto_sign_publickeybytes : LibC::SizeT
|
||||||
fun crypto_sign_secretkeybytes() : LibC::SizeT
|
fun crypto_sign_secretkeybytes : LibC::SizeT
|
||||||
fun crypto_sign_bytes() : LibC::SizeT
|
fun crypto_sign_bytes : LibC::SizeT
|
||||||
fun crypto_kdf_keybytes() : LibC::SizeT
|
fun crypto_kdf_keybytes : LibC::SizeT
|
||||||
fun crypto_kdf_contextbytes() : LibC::SizeT
|
fun crypto_kdf_contextbytes : LibC::SizeT
|
||||||
fun crypto_pwhash_memlimit_min() : LibC::SizeT
|
fun crypto_pwhash_memlimit_min : LibC::SizeT
|
||||||
fun crypto_pwhash_memlimit_interactive() : LibC::SizeT
|
fun crypto_pwhash_memlimit_interactive : LibC::SizeT
|
||||||
fun crypto_pwhash_memlimit_max() : LibC::SizeT
|
fun crypto_pwhash_memlimit_max : LibC::SizeT
|
||||||
fun crypto_pwhash_opslimit_min() : LibC::SizeT
|
fun crypto_pwhash_opslimit_min : LibC::SizeT
|
||||||
fun crypto_pwhash_opslimit_interactive() : LibC::SizeT
|
fun crypto_pwhash_opslimit_interactive : LibC::SizeT
|
||||||
fun crypto_pwhash_opslimit_moderate() : LibC::SizeT
|
fun crypto_pwhash_opslimit_moderate : LibC::SizeT
|
||||||
fun crypto_pwhash_opslimit_sensitive() : LibC::SizeT
|
fun crypto_pwhash_opslimit_sensitive : LibC::SizeT
|
||||||
fun crypto_pwhash_opslimit_max() : LibC::SizeT
|
fun crypto_pwhash_opslimit_max : LibC::SizeT
|
||||||
fun crypto_pwhash_strbytes() : LibC::SizeT
|
fun crypto_pwhash_strbytes : LibC::SizeT
|
||||||
fun crypto_pwhash_alg_argon2i13() : LibC::Int
|
fun crypto_pwhash_alg_argon2i13 : LibC::Int
|
||||||
fun crypto_pwhash_alg_argon2id13() : LibC::Int
|
fun crypto_pwhash_alg_argon2id13 : LibC::Int
|
||||||
fun crypto_pwhash_saltbytes : LibC::SizeT
|
fun crypto_pwhash_saltbytes : LibC::SizeT
|
||||||
fun crypto_pwhash_bytes_min() : LibC::SizeT
|
fun crypto_pwhash_bytes_min : LibC::SizeT
|
||||||
fun crypto_pwhash_bytes_max() : LibC::SizeT
|
fun crypto_pwhash_bytes_max : LibC::SizeT
|
||||||
fun crypto_generichash_blake2b_statebytes : LibC::SizeT
|
fun crypto_generichash_blake2b_statebytes : LibC::SizeT
|
||||||
fun crypto_generichash_blake2b_bytes : LibC::SizeT
|
fun crypto_generichash_blake2b_bytes : LibC::SizeT
|
||||||
fun crypto_generichash_blake2b_bytes_min : LibC::SizeT
|
fun crypto_generichash_blake2b_bytes_min : LibC::SizeT
|
||||||
|
@ -52,7 +52,7 @@ module Cox
|
||||||
data : Pointer(LibC::UChar),
|
data : Pointer(LibC::UChar),
|
||||||
data_size : LibC::ULongLong,
|
data_size : LibC::ULongLong,
|
||||||
nonce : Pointer(LibC::UChar),
|
nonce : Pointer(LibC::UChar),
|
||||||
key : Pointer(LibC::UChar),
|
key : Pointer(LibC::UChar)
|
||||||
) : LibC::Int
|
) : LibC::Int
|
||||||
|
|
||||||
fun crypto_secretbox_open_easy(
|
fun crypto_secretbox_open_easy(
|
||||||
|
@ -60,7 +60,7 @@ module Cox
|
||||||
data : Pointer(LibC::UChar),
|
data : Pointer(LibC::UChar),
|
||||||
data_size : LibC::ULongLong,
|
data_size : LibC::ULongLong,
|
||||||
nonce : Pointer(LibC::UChar),
|
nonce : Pointer(LibC::UChar),
|
||||||
key : Pointer(LibC::UChar),
|
key : Pointer(LibC::UChar)
|
||||||
) : LibC::Int
|
) : LibC::Int
|
||||||
|
|
||||||
# TODO: Add reduced round variants.
|
# TODO: Add reduced round variants.
|
||||||
|
@ -137,7 +137,7 @@ module Cox
|
||||||
salt : Pointer(LibC::UChar),
|
salt : Pointer(LibC::UChar),
|
||||||
optslimit : LibC::ULongLong,
|
optslimit : LibC::ULongLong,
|
||||||
memlimit : LibC::SizeT,
|
memlimit : LibC::SizeT,
|
||||||
alg : LibC::Int,
|
alg : LibC::Int
|
||||||
) : LibC::Int
|
) : LibC::Int
|
||||||
|
|
||||||
fun crypto_pwhash_str(
|
fun crypto_pwhash_str(
|
||||||
|
@ -145,19 +145,19 @@ module Cox
|
||||||
pass : Pointer(LibC::UChar),
|
pass : Pointer(LibC::UChar),
|
||||||
pass_size : LibC::ULongLong,
|
pass_size : LibC::ULongLong,
|
||||||
optslimit : LibC::ULongLong,
|
optslimit : LibC::ULongLong,
|
||||||
memlimit : LibC::SizeT,
|
memlimit : LibC::SizeT
|
||||||
) : LibC::Int
|
) : LibC::Int
|
||||||
|
|
||||||
fun crypto_pwhash_str_verify(
|
fun crypto_pwhash_str_verify(
|
||||||
str : Pointer(LibC::UChar),
|
str : Pointer(LibC::UChar),
|
||||||
pass : Pointer(LibC::UChar),
|
pass : Pointer(LibC::UChar),
|
||||||
pass_size : LibC::ULongLong,
|
pass_size : LibC::ULongLong
|
||||||
) : LibC::Int
|
) : LibC::Int
|
||||||
|
|
||||||
fun crypto_pwhash_str_needs_rehash(
|
fun crypto_pwhash_str_needs_rehash(
|
||||||
str : Pointer(LibC::UChar),
|
str : Pointer(LibC::UChar),
|
||||||
optslimit : LibC::ULongLong,
|
optslimit : LibC::ULongLong,
|
||||||
memlimit : LibC::SizeT,
|
memlimit : LibC::SizeT
|
||||||
) : LibC::Int
|
) : LibC::Int
|
||||||
|
|
||||||
fun crypto_generichash_blake2b_init_salt_personal(
|
fun crypto_generichash_blake2b_init_salt_personal(
|
||||||
|
@ -166,19 +166,19 @@ module Cox
|
||||||
key_len : UInt8,
|
key_len : UInt8,
|
||||||
out_len : UInt8,
|
out_len : UInt8,
|
||||||
salt : Pointer(LibC::UChar),
|
salt : Pointer(LibC::UChar),
|
||||||
personal : Pointer(LibC::UChar),
|
personal : Pointer(LibC::UChar)
|
||||||
) : LibC::Int
|
) : LibC::Int
|
||||||
|
|
||||||
fun crypto_generichash_blake2b_update(
|
fun crypto_generichash_blake2b_update(
|
||||||
state : Pointer(LibC::UChar),
|
state : Pointer(LibC::UChar),
|
||||||
in : Pointer(LibC::UChar),
|
in : Pointer(LibC::UChar),
|
||||||
in_len : UInt64,
|
in_len : UInt64
|
||||||
) : LibC::Int
|
) : LibC::Int
|
||||||
|
|
||||||
fun crypto_generichash_blake2b_final(
|
fun crypto_generichash_blake2b_final(
|
||||||
state : Pointer(LibC::UChar),
|
state : Pointer(LibC::UChar),
|
||||||
output : Pointer(LibC::UChar),
|
output : Pointer(LibC::UChar),
|
||||||
output_len : UInt64,
|
output_len : UInt64
|
||||||
) : LibC::Int
|
) : LibC::Int
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue