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
1. Fork it ( https://github.com/didactic-drunk/cox/fork )
2. Create your feature branch (git checkout -b my-new-feature)
3. Commit your changes (git commit -am 'Add some feature')
4. Push to the branch (git push origin my-new-feature)
5. Create a new Pull Request
2. **Install a formatting check git hook (ln -sf ../../scripts/git/pre-commit .git/hooks)**
3. Create your feature branch (git checkout -b my-new-feature)
4. Commit your changes (git commit -am 'Add some feature')
5. Push to the branch (git push origin my-new-feature)
6. Create a new Pull Request
## Contributors

View File

@ -19,7 +19,7 @@ mem_limit = (ARGV.shift?.try &.to_i || (Cox::Pwhash::MEMLIMIT_MAX)).to_u64
pwhash = Cox::Pwhash.new
pass = "1234"
#data = Array(Array({UInt64, UInt64, Float64})).new
# data = Array(Array({UInt64, UInt64, Float64})).new
header = [" "]
data = [header]
@ -49,7 +49,7 @@ loop do
header << ostr if data.size == 2
if t >= time_min
mstr = bytes_str pwhash.memlimit
# mstr = "%5dK" % (pwhash.memlimit / 1024)
# mstr = "%5dK" % (pwhash.memlimit / 1024)
tstr = "%6.3fs" % t
row << tstr
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.
pwhash.memlimit *= 4
end
#header << "Ops limit"
# header << "Ops limit"
data << ["Memory"]
# Quick n dirty sparse table.

View File

@ -23,7 +23,6 @@ test_vectors = [
},
]
describe Cox::Blake2b do
it "libsodium comparisons" do
libsodium_comparisons.each do |vec|
@ -51,7 +50,6 @@ describe Cox::Blake2b do
personal2 = personal.dup
personal2[0] = 1
d = Cox::Blake2b.new key: key, salt: salt, personal: personal
d.update "foo".to_slice
output = d.hexdigest

View File

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

View File

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

View File

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

View File

@ -3,13 +3,14 @@ require "random/secure"
module Cox
class Error < ::Exception
end
class VerificationFailed < Error
end
class DecryptionFailed < Error
end
end
require "./cox/*"
module Cox
@ -59,7 +60,7 @@ module Cox
end
end
if Cox::LibSodium.sodium_init() == -1
if Cox::LibSodium.sodium_init == -1
STDERR.puts("Failed to init libsodium")
exit(1)
end

View File

@ -24,7 +24,6 @@ module Cox
@have_salt = false
@have_personal = false
# implemented as static array's so clone works without jumping through hoops.
@key = StaticArray(UInt8, 64).new 0
@salt = StaticArray(UInt8, 16).new 0
@ -104,5 +103,3 @@ module Cox
Blake2b.new.__validate_sizes__
end

View File

@ -44,7 +44,6 @@ module Cox::Cipher
update src, Bytes.new(src.bytesize)
end
# Provided for compatibility with block ciphers.
# Stream ciphers don't have additional data.
def final
@ -57,11 +56,11 @@ module Cox::Cipher
end
abstract def update(src : Bytes, dst : Bytes)
abstract def key_size()
abstract def nonce_size()
abstract def key_size
abstract def nonce_size
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,
# or as building blocks for implementing custom constructions, but they
# are not alternatives to secretbox.

View File

@ -1,31 +1,31 @@
module Cox
@[Link(ldflags: "`#{__DIR__}/../../build/pkg-libs.sh #{__DIR__}/../..`")]
lib LibSodium
fun sodium_init() : LibC::Int
fun sodium_init : LibC::Int
fun crypto_box_publickeybytes() : LibC::SizeT
fun crypto_box_secretkeybytes() : LibC::SizeT
fun crypto_box_noncebytes() : LibC::SizeT
fun crypto_box_macbytes() : LibC::SizeT
fun crypto_sign_publickeybytes() : LibC::SizeT
fun crypto_sign_secretkeybytes() : LibC::SizeT
fun crypto_sign_bytes() : LibC::SizeT
fun crypto_kdf_keybytes() : LibC::SizeT
fun crypto_kdf_contextbytes() : LibC::SizeT
fun crypto_pwhash_memlimit_min() : LibC::SizeT
fun crypto_pwhash_memlimit_interactive() : LibC::SizeT
fun crypto_pwhash_memlimit_max() : LibC::SizeT
fun crypto_pwhash_opslimit_min() : LibC::SizeT
fun crypto_pwhash_opslimit_interactive() : LibC::SizeT
fun crypto_pwhash_opslimit_moderate() : LibC::SizeT
fun crypto_pwhash_opslimit_sensitive() : LibC::SizeT
fun crypto_pwhash_opslimit_max() : LibC::SizeT
fun crypto_pwhash_strbytes() : LibC::SizeT
fun crypto_pwhash_alg_argon2i13() : LibC::Int
fun crypto_pwhash_alg_argon2id13() : LibC::Int
fun crypto_box_publickeybytes : LibC::SizeT
fun crypto_box_secretkeybytes : LibC::SizeT
fun crypto_box_noncebytes : LibC::SizeT
fun crypto_box_macbytes : LibC::SizeT
fun crypto_sign_publickeybytes : LibC::SizeT
fun crypto_sign_secretkeybytes : LibC::SizeT
fun crypto_sign_bytes : LibC::SizeT
fun crypto_kdf_keybytes : LibC::SizeT
fun crypto_kdf_contextbytes : LibC::SizeT
fun crypto_pwhash_memlimit_min : LibC::SizeT
fun crypto_pwhash_memlimit_interactive : LibC::SizeT
fun crypto_pwhash_memlimit_max : LibC::SizeT
fun crypto_pwhash_opslimit_min : LibC::SizeT
fun crypto_pwhash_opslimit_interactive : LibC::SizeT
fun crypto_pwhash_opslimit_moderate : LibC::SizeT
fun crypto_pwhash_opslimit_sensitive : LibC::SizeT
fun crypto_pwhash_opslimit_max : LibC::SizeT
fun crypto_pwhash_strbytes : LibC::SizeT
fun crypto_pwhash_alg_argon2i13 : LibC::Int
fun crypto_pwhash_alg_argon2id13 : LibC::Int
fun crypto_pwhash_saltbytes : LibC::SizeT
fun crypto_pwhash_bytes_min() : LibC::SizeT
fun crypto_pwhash_bytes_max() : LibC::SizeT
fun crypto_pwhash_bytes_min : LibC::SizeT
fun crypto_pwhash_bytes_max : LibC::SizeT
fun crypto_generichash_blake2b_statebytes : LibC::SizeT
fun crypto_generichash_blake2b_bytes : LibC::SizeT
fun crypto_generichash_blake2b_bytes_min : LibC::SizeT
@ -52,7 +52,7 @@ module Cox
data : Pointer(LibC::UChar),
data_size : LibC::ULongLong,
nonce : Pointer(LibC::UChar),
key : Pointer(LibC::UChar),
key : Pointer(LibC::UChar)
) : LibC::Int
fun crypto_secretbox_open_easy(
@ -60,13 +60,13 @@ module Cox
data : Pointer(LibC::UChar),
data_size : LibC::ULongLong,
nonce : Pointer(LibC::UChar),
key : Pointer(LibC::UChar),
key : Pointer(LibC::UChar)
) : LibC::Int
# TODO: Add reduced round variants.
# TODO: Add reduced round variants.
{% for name in ["_chacha20", "_chacha20_ietf", "_xchacha20", "_salsa20", "_xsalsa20"] %}
fun crypto_stream{{ name.id}}_keybytes() : LibC::SizeT
fun crypto_stream{{ name.id}}_noncebytes() : LibC::SizeT
fun crypto_stream{{ name.id }}_keybytes() : LibC::SizeT
fun crypto_stream{{ name.id }}_noncebytes() : LibC::SizeT
fun crypto_stream{{ name.id }}_xor_ic(
c : Pointer(LibC::UChar),
@ -137,7 +137,7 @@ module Cox
salt : Pointer(LibC::UChar),
optslimit : LibC::ULongLong,
memlimit : LibC::SizeT,
alg : LibC::Int,
alg : LibC::Int
) : LibC::Int
fun crypto_pwhash_str(
@ -145,19 +145,19 @@ module Cox
pass : Pointer(LibC::UChar),
pass_size : LibC::ULongLong,
optslimit : LibC::ULongLong,
memlimit : LibC::SizeT,
memlimit : LibC::SizeT
) : LibC::Int
fun crypto_pwhash_str_verify(
str : Pointer(LibC::UChar),
pass : Pointer(LibC::UChar),
pass_size : LibC::ULongLong,
pass_size : LibC::ULongLong
) : LibC::Int
fun crypto_pwhash_str_needs_rehash(
str : Pointer(LibC::UChar),
optslimit : LibC::ULongLong,
memlimit : LibC::SizeT,
memlimit : LibC::SizeT
) : LibC::Int
fun crypto_generichash_blake2b_init_salt_personal(
@ -166,19 +166,19 @@ module Cox
key_len : UInt8,
out_len : UInt8,
salt : Pointer(LibC::UChar),
personal : Pointer(LibC::UChar),
personal : Pointer(LibC::UChar)
) : LibC::Int
fun crypto_generichash_blake2b_update(
state : Pointer(LibC::UChar),
in : Pointer(LibC::UChar),
in_len : UInt64,
in_len : UInt64
) : LibC::Int
fun crypto_generichash_blake2b_final(
state : Pointer(LibC::UChar),
output : Pointer(LibC::UChar),
output_len : UInt64,
output_len : UInt64
) : LibC::Int
end
end