From 7dcaeb13320c0c4fdcfc9a1fdfd4736c866679e9 Mon Sep 17 00:00:00 2001 From: Didactic Drunk <1479616+didactic-drunk@users.noreply.github.com> Date: Sun, 30 Jun 2019 14:21:31 -0700 Subject: [PATCH] Add examples/constants.cr --- examples/constants.cr | 26 ++++++++++++++++++++++++++ src/sodium/pwhash.cr | 8 ++++---- 2 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 examples/constants.cr diff --git a/examples/constants.cr b/examples/constants.cr new file mode 100644 index 0000000..6fdffdf --- /dev/null +++ b/examples/constants.cr @@ -0,0 +1,26 @@ +require "../src/sodium" + +{% for name in %w(KEY_SIZE KEY_SIZE_MIN KEY_SIZE_MAX SALT_SIZE PERSONAL_SIZE OUT_SIZE OUT_SIZE_MIN OUT_SIZE_MAX) %} + puts "Sodium::Digest::Blake2b::{{ name.id }} #{Sodium::Digest::Blake2b::{{ name.id }}}" +{% end %} +puts "" + +{% for name in %w(OPSLIMIT_MIN OPSLIMIT_INTERACTIVE OPSLIMIT_MODERATE OPSLIMIT_SENSITIVE OPSLIMIT_MAX) %} + puts "Sodium::Digest::Pwhash::{{ name.id }} #{Sodium::Pwhash::{{ name.id }}}" +{% end %} +puts "" + +{% for name in %w(MEMLIMIT_MIN MEMLIMIT_INTERACTIVE MEMLIMIT_MAX) %} + puts "Sodium::Digest::Pwhash::{{ name.id }} #{Sodium::Pwhash::{{ name.id }}}" +{% end %} +puts "" + +{% for name in %w(STR_SIZE) %} + puts "Sodium::Digest::Pwhash::{{ name.id }} #{Sodium::Pwhash::{{ name.id }}}" +{% end %} +puts "" + +{% for name in %w(KEY_SIZE CONTEXT_SIZE) %} + puts "Sodium::Digest::Kdf::{{ name.id }} #{Sodium::Kdf::{{ name.id }}}" +{% end %} +puts "" diff --git a/src/sodium/pwhash.cr b/src/sodium/pwhash.cr index 4cf1e02..48702f6 100644 --- a/src/sodium/pwhash.cr +++ b/src/sodium/pwhash.cr @@ -3,7 +3,7 @@ module Sodium # * #store #verify #needs_rehash? are used together for password verification. # * #key_derive is used on it's own to generate password based keys. # - # See `examples/pwhash_selector.cr` for help on selecting parameters. + # **See `examples/pwhash_selector.cr` for help on selecting parameters.** class Pwhash class PasswordVerifyError < Sodium::Error end @@ -15,10 +15,10 @@ module Sodium OPSLIMIT_MAX = LibSodium.crypto_pwhash_opslimit_max MEMLIMIT_MIN = LibSodium.crypto_pwhash_memlimit_min - MEMLIMIT_MAX = LibSodium.crypto_pwhash_memlimit_max MEMLIMIT_INTERACTIVE = LibSodium.crypto_pwhash_memlimit_interactive + MEMLIMIT_MAX = LibSodium.crypto_pwhash_memlimit_max # Don't use this. Maximum of the library which is more ram than any computer. - PWHASH_STR_SIZE = LibSodium.crypto_pwhash_strbytes + STR_SIZE = LibSodium.crypto_pwhash_strbytes # Use the most recent algorithm Argon2id13 for new applications. enum Algorithm @@ -39,7 +39,7 @@ module Sodium # * the automatically generated salt used for the previous computation # * the other parameters required to verify the password, including the algorithm identifier, its version, opslimit and memlimit. def store(pass) - outstr = Bytes.new PWHASH_STR_SIZE + outstr = Bytes.new STR_SIZE if LibSodium.crypto_pwhash_str(outstr, pass, pass.bytesize, @opslimit, @memlimit) != 0 raise Sodium::Error.new("crypto_pwhash_str") end