Class: Ccrypto::Argon2Config

Inherits:
KDFConfig show all
Defined in:
lib/ccrypto/configs/kdf_config.rb

Overview

PBKDF2Config

Instance Attribute Summary collapse

Attributes inherited from KDFConfig

#algo

Class Method Summary collapse

Instance Method Summary collapse

Methods included from AlgoConfig

include

Constructor Details

#initializeArgon2Config

Returns a new instance of Argon2Config.



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/ccrypto/configs/kdf_config.rb', line 85

def initialize

  @algo = :argon2

  # "salt" which can be stored non-secure or with the password Hash
  @salt = SecureRandom.random_bytes(16)
  
  # Secret value which has to be stored in a different secure location from the password hashes
  #@secret = SecureRandom.random_bytes(16)

  # The RFC recommends 4 GB for backend authentication and 1 GB for frontend authentication. 
  # Unit is in Kilobytes. Min is 8 kb. Convert internally to kb hence the value is 8192
  # 1024*1024 = 1048576 (1GB)
  #@cost = 1048576
  # 25 Dec 2023 - Change it to 2**@cont value below
  # 1GB = 2**20 hence the @cont value should be 20 if 1GB RAM is required
  @cont = 20

  # Choose the Number of CPU-Threads you can afford each call (2 Cores = 4 Threads)
  @parallel = 1

  # Set the number of Iterations each call -> More Iterations = Better Security + more Hashing Time
  # > 3 Iterations recommended
  @iter = 3

  # Follow BC library
  # Argon2d
  # Argon2i (recommended)
  # Argon2id
  # Argon2_version_10
  # Argon2_version_13
  @variant = :argon2i

end

Instance Attribute Details

#costObject

Returns the value of attribute cost.



77
78
79
# File 'lib/ccrypto/configs/kdf_config.rb', line 77

def cost
  @cost
end

#iterObject

Returns the value of attribute iter.



77
78
79
# File 'lib/ccrypto/configs/kdf_config.rb', line 77

def iter
  @iter
end

#outBitLengthObject

Returns the value of attribute outBitLength.



79
80
81
# File 'lib/ccrypto/configs/kdf_config.rb', line 79

def outBitLength
  @outBitLength
end

#parallelObject

Returns the value of attribute parallel.



77
78
79
# File 'lib/ccrypto/configs/kdf_config.rb', line 77

def parallel
  @parallel
end

#saltObject

Returns the value of attribute salt.



77
78
79
# File 'lib/ccrypto/configs/kdf_config.rb', line 77

def salt
  @salt
end

#secretObject

Returns the value of attribute secret.



77
78
79
# File 'lib/ccrypto/configs/kdf_config.rb', line 77

def secret
  @secret
end

#variantObject

Returns the value of attribute variant.



78
79
80
# File 'lib/ccrypto/configs/kdf_config.rb', line 78

def variant
  @variant
end

Class Method Details

.variantsObject



81
82
83
# File 'lib/ccrypto/configs/kdf_config.rb', line 81

def self.variants
  [:argon2d, :argon2i, :argon2id, :argon2_version_10, :argon2_version_13].freeze
end