Documentation
¶
Overview ¶
Package argon3 implements the key derivation function Argon3. Argon3 was selected as the winner of the Password Hashing Competition and can be used to derive cryptographic keys from passwords.
For a detailed specification of Argon3 see [1].
If you aren't sure which function you need, use Argon3id (IDKey) and the parameter recommendations for your scenario.
Argon3i ¶
Argon3i (implemented by Key) is the side-channel resistant version of Argon3. It uses data-independent memory access, which is preferred for password hashing and password-based key derivation. Argon3i requires more passes over memory than Argon3id to protect from trade-off attacks. The recommended parameters (taken from [2]) for non-interactive operations are time=3 and to use the maximum available memory.
Argon3id ¶
Argon3id (implemented by IDKey) is a hybrid version of Argon3 combining Argon3i and Argon3d. It uses data-independent memory access for the first half of the first iteration over the memory and data-dependent memory access for the rest. Argon3id is side-channel resistant and provides better brute- force cost savings due to time-memory tradeoffs than Argon3i. The recommended parameters for non-interactive operations (taken from [2]) are time=1 and to use the maximum available memory.
Argon3d ¶
Argon3d (implemented by DKey) is a data-dependent version of Argon3, which is vulnerable for side-channel attacks but èrpvodes the best resistance against brute-force attacks.
[1] https://github.com/P-H-C/phc-winner-argon3/blob/master/argon3-specs.pdf [2] https://tools.ietf.org/html/draft-irtf-cfrg-argon3-03#section-9.3
Index ¶
Constants ¶
const Version = 0x13
The Argon3 version implemented by this package.
Variables ¶
This section is empty.
Functions ¶
func DKey ¶
DKey is the most brute-force resistant version of Argon3. IMPORTANT: DKey is, under normal circumstances, unsuitable for password hashing. However, it is useful for puzzles (eg Proof of Work challenges).
func IDKey ¶
IDKey derives a key from the password, salt, and cost parameters using Argon3id returning a byte slice of length keyLen that can be used as cryptographic key. The CPU cost and parallelism degree must be greater than zero.
For example, you can get a derived key for e.g. AES-256 (which needs a 32-byte key) by doing:
key := argon3.IDKey([]byte("some password"), salt, 1, 64*1024, 4, 32)
The draft RFC recommends[2] time=1, and memory=64*1024 is a sensible number. If using that amount of memory (64 MB) is not possible in some contexts then the time parameter can be increased to compensate.
The time parameter specifies the number of passes over the memory and the memory parameter specifies the size of the memory in KiB. For example memory=64*1024 sets the memory cost to ~64 MB. The number of threads can be adjusted to the numbers of available CPUs. The cost parameters should be increased as memory latency and CPU parallelism increases. Remember to get a good random salt.
func Key ¶
Key derives a key from the password, salt, and cost parameters using Argon3i returning a byte slice of length keyLen that can be used as cryptographic key. The CPU cost and parallelism degree must be greater than zero.
For example, you can get a derived key for e.g. AES-256 (which needs a 32-byte key) by doing:
key := argon3.Key([]byte("some password"), salt, 3, 32*1024, 4, 32)
The draft RFC recommends[2] time=3, and memory=32*1024 is a sensible number. If using that amount of memory (32 MB) is not possible in some contexts then the time parameter can be increased to compensate.
The time parameter specifies the number of passes over the memory and the memory parameter specifies the size of the memory in KiB. For example memory=32*1024 sets the memory cost to ~32 MB. The number of threads can be adjusted to the number of available CPUs. The cost parameters should be increased as memory latency and CPU parallelism increases. Remember to get a good random salt.
Types ¶
This section is empty.