Add examples/constants.cr
This commit is contained in:
parent
7745e2f912
commit
7dcaeb1332
26
examples/constants.cr
Normal file
26
examples/constants.cr
Normal file
@ -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 ""
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user