From 2d0ed351eafc6d9db0165f3f7b81df7fe7eaaa0c Mon Sep 17 00:00:00 2001 From: Didactic Drunk <1479616+didactic-drunk@users.noreply.github.com> Date: Tue, 6 Aug 2019 22:56:49 -0700 Subject: [PATCH] Allow reusable nonces. --- examples/pwhash_selector.cr | 2 +- src/sodium/nonce.cr | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/examples/pwhash_selector.cr b/examples/pwhash_selector.cr index 6fe30d1..649cbf1 100644 --- a/examples/pwhash_selector.cr +++ b/examples/pwhash_selector.cr @@ -43,7 +43,7 @@ loop do loop do # p pwhash - t = Time.measure { pwhash.store pass }.to_f + t = Time.measure { pwhash.create pass }.to_f ostr = "%7d" % pwhash.opslimit header << ostr if data.size == 2 if t >= time_min diff --git a/src/sodium/nonce.cr b/src/sodium/nonce.cr index c94abdd..33deab9 100644 --- a/src/sodium/nonce.cr +++ b/src/sodium/nonce.cr @@ -10,8 +10,10 @@ module Sodium NONCE_SIZE = LibSodium::NONCE_SIZE.to_i - getter? used - @used = false + getter? used = false + + # Only use with single use keys. + property? reusable = false # Returns bytes delegate to_slice, to: @bytes @@ -37,7 +39,7 @@ module Sodium def used! raise Error::Reused.new("attempted nonce reuse") if @used - @used = true + @used = true unless @reusable end end end