SodiumPasswordHash
struct SodiumPasswordHash
A wrapper for password hashing.
-
The initializer is disabled.
Declaration
Swift
fileprivate init() -
This is the fastest option and should be avoided if possible.
Declaration
Swift
let opslimit_interactive: Int -
This takes about 0.7 seconds on a 2.8 Ghz Core i7 CPU.
Declaration
Swift
let opslimit_moderate: Int -
This takes about 3.5 seconds on a 2.8 Ghz Core i7 CPU.
Declaration
Swift
let opslimit_sensitive: Int -
This requires about 64 MiB memory.
Declaration
Swift
let memlimit_interactive: Int -
This requires about 256 MiB memory.
Declaration
Swift
let memlimit_moderate: Int -
This requires about 1 GiB memory.
Declaration
Swift
let memlimit_sensitive: Int -
Size of a storable string in bytes.
Declaration
Swift
let sizeOfStorableStringInBytes: Int -
Size of a salt used for password hashing in bytes.
Declaration
Swift
let sizeOfSaltInBytes: Int -
Minimum size for passwords.
Declaration
Swift
let minimumPasswordLength: Int -
Maximum size for passwords.
Declaration
Swift
let maximumPasswordLength: Int -
Minimum size of derived keys in bytes.
Declaration
Swift
let minimumKeySizeInBytes: Int -
Maximum size of derived keys in bytes.
Declaration
Swift
let maximumKeySizeInBytes: Int -
Creates a string that can be used for storing user passwords for the purpose of authentication.
Precondition
precondition:
- 0 ≤
passwordSizeInBytes opslimit∈ {opslimit_interactive,opslimit_moderate,opslimit_sensitive}memlimit∈ {memlimit_interactive,memlimit_moderate,memlimit_sensitive}
Declaration
Swift
func storableString(password: UnsafePointer<Int8>, passwordSizeInBytes: UInt64, opslimit: Int, memlimit: Int) -> String?Parameters
passwordA pointer to the password.
passwordSizeInBytesThe size of the password.
opslimitComplexity limit for hashing.
memlimitMemory limit for hashing.
Return Value
An ASCII-encoded string that can be stored,
nilon failure. - 0 ≤
-
Check if a password is verifying a storable string.
Precondition
precondition:
storableStringis ASCII-encoded- 0 ≤
passwordSizeInBytes
Declaration
Swift
func isVerifying(storableString: String, password: UnsafePointer<Int8>, passwordSizeInBytes: UInt64) -> BoolParameters
storableStringThe storable string.
passwordA pointer to the password.
passwordSizeInBytesThe size of the password in bytes.
Return Value
trueifpasswordverifiesstorableString. -
Derive a key from a given password with a given salt.
Declaration
Swift
func derive(key: UnsafeMutablePointer<UInt8>, sizeInBytes: UInt64, from password: UnsafePointer<Int8>, passwordSizeInBytes: UInt64, salt: Bytes, opslimit: UInt64, memlimit: Int, algorithm: Int32 = libsodium.crypto_pwhash_alg_default())Parameters
keyA pointer to the memory, where the derived key should be written.
sizeInBytesThe size of the memory area reserved for the
key.passwordSizeInBytesThe size of the
passwordin bytes.saltThe salt that will be used in order to prevent rainbow table attacks.
opslimitComplexity limit for hashing.
memlimitMemory limit for hashing.
View on GitHub
SodiumPasswordHash Structure Reference