From 2dda619026a6bd67bc8a8122df0d6a02080549f2 Mon Sep 17 00:00:00 2001 From: Didactic Drunk <1479616+didactic-drunk@users.noreply.github.com> Date: Sat, 24 Aug 2019 14:15:37 -0700 Subject: [PATCH] Add default Sodium::Pwhash algorithm. --- src/sodium/lib_sodium.cr | 1 + src/sodium/pwhash.cr | 5 +++++ src/sodium/secure_buffer.cr | 2 ++ 3 files changed, 8 insertions(+) diff --git a/src/sodium/lib_sodium.cr b/src/sodium/lib_sodium.cr index d782f36..ad27abb 100644 --- a/src/sodium/lib_sodium.cr +++ b/src/sodium/lib_sodium.cr @@ -36,6 +36,7 @@ module Sodium fun crypto_pwhash_saltbytes : LibC::SizeT fun crypto_pwhash_bytes_min : LibC::SizeT fun crypto_pwhash_bytes_max : LibC::SizeT + fun crypto_pwhash_alg_default : LibC::Int fun crypto_generichash_blake2b_statebytes : LibC::SizeT fun crypto_generichash_blake2b_bytes : LibC::SizeT fun crypto_generichash_blake2b_bytes_min : LibC::SizeT diff --git a/src/sodium/pwhash.cr b/src/sodium/pwhash.cr index ff011e1..27b2e6d 100644 --- a/src/sodium/pwhash.cr +++ b/src/sodium/pwhash.cr @@ -29,6 +29,11 @@ module Sodium enum Mode Argon2i13 = 1 Argon2id13 = 2 + + # The current libsodium default algorithm that may change between versions. + def default + Mode.new LibSodium.crypto_pwhash_alg_default + end end property opslimit = OPSLIMIT_INTERACTIVE diff --git a/src/sodium/secure_buffer.cr b/src/sodium/secure_buffer.cr index ded73a8..859342b 100644 --- a/src/sodium/secure_buffer.cr +++ b/src/sodium/secure_buffer.cr @@ -82,10 +82,12 @@ module Sodium self end + # Timing safe memory compare. def ==(other : self) Sodium.memcmp self.to_slice, other.to_slice end + # Timing safe memory compare. def ==(other : Bytes) Sodium.memcmp self.to_slice, other end