Documentation
¶
Overview ¶
Package argon2 provides fast and easy to use bindings for Argon2: A very secure, modern password hashing algorithm - Winner of the Password Hashing Competition (PHC).
Index ¶
Constants ¶
const ( ErrOutputPtrNull = Error(C.ARGON2_OUTPUT_PTR_NULL) ErrOutputTooShort = Error(C.ARGON2_OUTPUT_TOO_SHORT) ErrOutputTooLong = Error(C.ARGON2_OUTPUT_TOO_LONG) ErrPwdTooShort = Error(C.ARGON2_PWD_TOO_SHORT) ErrPwdTooLong = Error(C.ARGON2_PWD_TOO_LONG) ErrSaltTooShort = Error(C.ARGON2_SALT_TOO_SHORT) ErrSaltTooLong = Error(C.ARGON2_SALT_TOO_LONG) ErrAdTooShort = Error(C.ARGON2_AD_TOO_SHORT) ErrAdTooLong = Error(C.ARGON2_AD_TOO_LONG) ErrSecretTooShort = Error(C.ARGON2_SECRET_TOO_SHORT) ErrSecretTooLong = Error(C.ARGON2_SECRET_TOO_LONG) ErrTimeTooSmall = Error(C.ARGON2_TIME_TOO_SMALL) ErrTimeTooLarge = Error(C.ARGON2_TIME_TOO_LARGE) ErrMemoryTooLittle = Error(C.ARGON2_MEMORY_TOO_LITTLE) ErrMemoryTooMuch = Error(C.ARGON2_MEMORY_TOO_MUCH) ErrLanesTooFew = Error(C.ARGON2_LANES_TOO_FEW) ErrLanesTooMany = Error(C.ARGON2_LANES_TOO_MANY) ErrPwdPtrMismatch = Error(C.ARGON2_PWD_PTR_MISMATCH) ErrSaltPtrMismatch = Error(C.ARGON2_SALT_PTR_MISMATCH) ErrSecretPtrMismatch = Error(C.ARGON2_SECRET_PTR_MISMATCH) ErrAdPtrMismatch = Error(C.ARGON2_AD_PTR_MISMATCH) ErrMemoryAllocationError = Error(C.ARGON2_MEMORY_ALLOCATION_ERROR) ErrFreeMemoryCbkNull = Error(C.ARGON2_FREE_MEMORY_CBK_NULL) ErrAllocateMemoryCbkNull = Error(C.ARGON2_ALLOCATE_MEMORY_CBK_NULL) ErrIncorrectParameter = Error(C.ARGON2_INCORRECT_PARAMETER) ErrIncorrectType = Error(C.ARGON2_INCORRECT_TYPE) ErrOutPtrMismatch = Error(C.ARGON2_OUT_PTR_MISMATCH) ErrThreadsTooFew = Error(C.ARGON2_THREADS_TOO_FEW) ErrThreadsTooMany = Error(C.ARGON2_THREADS_TOO_MANY) ErrMissingArgs = Error(C.ARGON2_MISSING_ARGS) ErrEncodingFail = Error(C.ARGON2_ENCODING_FAIL) ErrDecodingFail = Error(C.ARGON2_DECODING_FAIL) ErrThreadFail = Error(C.ARGON2_THREAD_FAIL) ErrDecodingLengthFail = Error(C.ARGON2_DECODING_LENGTH_FAIL) ErrVerifyMismatch = Error(C.ARGON2_VERIFY_MISMATCH) )
Variables ¶
This section is empty.
Functions ¶
func SecureZeroMemory ¶
func SecureZeroMemory(b []byte)
SecureZeroMemory is a helper method which sets all bytes in `b` (up to it's capacity) to `0x00`, erasing it's contents.
Types ¶
type Config ¶
type Config struct { // HashLength specifies the length of the resulting hash in Bytes. // // Must be > 0. HashLength uint32 // SaltLength specifies the length of the resulting salt in Bytes, // if one of the helper methods is used. // // Must be > 0. SaltLength uint32 // TimeCost specifies the number of iterations of argon2. // // Must be > 0. // If you use ModeArgon2i this should *always* be >= 3 due to TMTO attacks. // Additionally if you can afford it you might set it to >= 10. TimeCost uint32 // MemoryCost specifies the amount of memory to use in Kibibytes. // // Must be > 0. MemoryCost uint32 // Parallelism specifies the amount of threads to use. // // Must be > 0. Parallelism uint32 // Mode specifies the hashing method used by argon2. // // If you're writing a server and unsure what to choose, // use ModeArgon2i with a TimeCost >= 3. Mode Mode // Version specifies the argon2 version to be used. Version Version }
Config contains all configuration parameters for the Argon2 hash function.
You MUST ensure that a Config instance is not changed after creation, otherwise you risk race conditions. If you do need to change it during runtime use a Mutex and simply create a by-value copy of your shared Config instance in the critical section and store it on your local stack. That way your critical section is very short, while allowing you to safely call all the member methods on your local "immutable" copy.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns a Config struct suitable for most servers.
These default settings follow the recommendation from
https://tools.ietf.org/html/draft-irtf-cfrg-argon2-03#section-9.4
using ModeArgon2id, TimeCost of 1 and 32 MiB of memory, which result in around 10-15ms of computation time. (Tested on an i7 8700k and DDR4 @ 3200 MHz).
func (*Config) Hash ¶
Hash takes a password and optionally a salt and returns an Argon2 hash.
If salt is nil a appropriate salt of Config.SaltLength bytes is generated for you.
func (*Config) HashEncoded ¶
HashEncoded is a helper function around Hash() which automatically generates a salt and encodes the result for you.
type Mode ¶
type Mode uint32
Mode exists for type check purposes. See Config.
const ( // ModeArgon2d is faster and uses data-depending memory access, // which makes it highly resistant against GPU cracking attacks and // suitable for applications with no (!) threats from // side-channel timing attacks (eg. cryptocurrencies). ModeArgon2d Mode = C.Argon2_d // ModeArgon2i uses data-independent memory access, which is // preferred for password hashing and password-based key derivation // (e.g. hard drive encryption), but it's slower as it makes // more passes over the memory to protect from TMTO attacks. ModeArgon2i Mode = C.Argon2_i // ModeArgon2id is a hybrid of Argon2i and Argon2d, using a // combination of data-depending and data-independent memory accesses, // which gives some of Argon2i's resistance to side-channel cache timing // attacks and much of Argon2d's resistance to GPU cracking attacks. ModeArgon2id Mode = C.Argon2_id )
type Raw ¶
Raw wraps a salt and hash pair including the Config with which it was generated.
A Raw struct is generated using Decode() or the Hash*() methods above. This struct MUST NOT be mutated while any of its member functions are currently being executed.
func Decode ¶
Decode takes a stringified/encoded argon2 hash and turns it back into a Raw struct.
This decoder ignores "data" attributes as they are likely to be deprecated.
type Version ¶
type Version uint32
Version contains the Argon2 version being used.
See Config.
const ( // Version10 of the Argon2 algorithm. Deprecated: Use Version13 instead. Version10 Version = C.ARGON2_VERSION_10 // Version13 of the Argon2 algorithm. Recommended. Version13 Version = C.ARGON2_VERSION_13 )