

argon2 - GoDoc
source link: https://godoc.org/golang.org/x/crypto/argon2
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Overview ¶
Package argon2 implements the key derivation function Argon2. Argon2 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 Argon2 see [1].
If you aren't sure which function you need, use Argon2id (IDKey) and the parameter recommendations for your scenario.
Argon2i ¶
Argon2i (implemented by Key) is the side-channel resistant version of Argon2. It uses data-independent memory access, which is preferred for password hashing and password-based key derivation. Argon2i requires more passes over memory than Argon2id 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.
Argon2id ¶
Argon2id (implemented by IDKey) is a hybrid version of Argon2 combining Argon2i and Argon2d. 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. Argon2id is side-channel resistant and provides better brute- force cost savings due to time-memory tradeoffs than Argon2i. The recommended parameters for non-interactive operations (taken from [2]) are time=1 and to use the maximum available memory.
[1] https://github.com/P-H-C/phc-winner-argon2/blob/master/argon2-specs.pdf [2] https://tools.ietf.org/html/draft-irtf-cfrg-argon2-03#section-9.3
Constants ¶
const Version = 0x13
The Argon2 version implemented by this package.
Variables ¶
This section is empty.
Functions ¶
func IDKey ¶
IDKey derives a key from the password, salt, and cost parameters using Argon2id 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 := argon2.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 Argon2i 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 := argon2.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.
Recommend
-
38
README ¶
-
27
Overview ¶ Package cosmo implements basic cosmology calculations in Go. FLRW is the basic interface type that d...
-
106
-
67
GitHub is where people build software. More than 28 million people use GitHub to discover, fork, and contribute to over 79 million projects.
-
233
README.md XMRig ⚠️Monero will change PoW algorithm to RandomX on November 30.
-
20
A key derivation function , or KDF, derives one or many secret keys from a s...
-
12
How to Hash and Verify Passwords With Argon2 in Go Posted on: 10th December 2018 Filed under:
-
21
Argon2, Memory-hard Hash Function柴昊天一个程序员Argon2 是一种慢哈希函数,在...
-
6
Using WebAssembly to add Argon2 to Snowflake Posted on December 14, 2020
-
8
Argon2 code audits - part one - InferFebruary 12, 2016Introduction This article is the first part in a series in which we use popular tools to audit the Argon2 library. Let’s start with a quick background on what...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK