Formatting

This commit is contained in:
Didactic Drunk 2019-06-27 17:20:02 -07:00
parent e0ea31bd2e
commit be5b250a22
11 changed files with 121 additions and 126 deletions

View File

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

View File

@ -19,7 +19,7 @@ mem_limit = (ARGV.shift?.try &.to_i || (Cox::Pwhash::MEMLIMIT_MAX)).to_u64
pwhash = Cox::Pwhash.new pwhash = Cox::Pwhash.new
pass = "1234" pass = "1234"
#data = Array(Array({UInt64, UInt64, Float64})).new # data = Array(Array({UInt64, UInt64, Float64})).new
header = [" "] header = [" "]
data = [header] data = [header]
@ -49,7 +49,7 @@ loop do
header << ostr if data.size == 2 header << ostr if data.size == 2
if t >= time_min if t >= time_min
mstr = bytes_str pwhash.memlimit mstr = bytes_str pwhash.memlimit
# mstr = "%5dK" % (pwhash.memlimit / 1024) # mstr = "%5dK" % (pwhash.memlimit / 1024)
tstr = "%6.3fs" % t tstr = "%6.3fs" % t
row << tstr row << tstr
s = String.build do |sb| s = String.build do |sb|
@ -75,7 +75,7 @@ loop do
break if pwhash.opslimit == Cox::Pwhash::OPSLIMIT_MIN # Couldn't get past 1 iteration before going over time. break if pwhash.opslimit == Cox::Pwhash::OPSLIMIT_MIN # Couldn't get past 1 iteration before going over time.
pwhash.memlimit *= 4 pwhash.memlimit *= 4
end end
#header << "Ops limit" # header << "Ops limit"
data << ["Memory"] data << ["Memory"]
# Quick n dirty sparse table. # Quick n dirty sparse table.

View File

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

View File

@ -20,4 +20,3 @@ require "../../../src/cox/cipher/chalsa"
end end
end end
{% end %} {% end %}

View File

@ -22,5 +22,5 @@ describe Cox::Kdf do
subkey1.should_not eq subkey2 subkey1.should_not eq subkey2
end end
# TODO: test exceptions # TODO: test exceptions
end end

View File

@ -45,6 +45,6 @@ describe Cox::Pwhash do
key1.should eq key2 key1.should eq key2
key1.should_not eq key3 key1.should_not eq key3
key1.should_not eq key4 key1.should_not eq key4
# BUG: validate against known passwords # BUG: validate against known passwords
end end
end end

View File

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

View File

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

View File

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

View File

@ -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,13 +60,13 @@ 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.
{% for name in ["_chacha20", "_chacha20_ietf", "_xchacha20", "_salsa20", "_xsalsa20"] %} {% for name in ["_chacha20", "_chacha20_ietf", "_xchacha20", "_salsa20", "_xsalsa20"] %}
fun crypto_stream{{ name.id}}_keybytes() : LibC::SizeT fun crypto_stream{{ name.id }}_keybytes() : LibC::SizeT
fun crypto_stream{{ name.id}}_noncebytes() : LibC::SizeT fun crypto_stream{{ name.id }}_noncebytes() : LibC::SizeT
fun crypto_stream{{ name.id }}_xor_ic( fun crypto_stream{{ name.id }}_xor_ic(
c : Pointer(LibC::UChar), c : Pointer(LibC::UChar),
@ -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