SodiumPasswordHash
struct SodiumPasswordHash
A wrapper for password hashing.
-
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
password
A pointer to the password.
passwordSizeInBytes
The size of the password.
opslimit
Complexity limit for hashing.
memlimit
Memory limit for hashing.
Return Value
An ASCII-encoded string that can be stored,
nil
on failure. - 0 ≤
-
Check if a password is verifying a storable string.
Precondition
precondition:
storableString
is ASCII-encoded- 0 ≤
passwordSizeInBytes
Declaration
Swift
func isVerifying(storableString: String, password: UnsafePointer<Int8>, passwordSizeInBytes: UInt64) -> Bool
Parameters
storableString
The storable string.
password
A pointer to the password.
passwordSizeInBytes
The size of the password in bytes.
Return Value
true
ifpassword
verifiesstorableString
. -
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
key
A pointer to the memory, where the derived key should be written.
sizeInBytes
The size of the memory area reserved for the
key
.passwordSizeInBytes
The size of the
password
in bytes.salt
The salt that will be used in order to prevent rainbow table attacks.
opslimit
Complexity limit for hashing.
memlimit
Memory limit for hashing.