github.com/decred/politeia@v1.4.0/util/argon2.go (about)

     1  // Copyright (c) 2020-2021 The Decred developers
     2  // Use of this source code is governed by an ISC
     3  // license that can be found in the LICENSE file.
     4  
     5  package util
     6  
     7  // Argon2Params represent the argon2 key derivation parameters that are used
     8  // to derive various keys in politeia.
     9  type Argon2Params struct {
    10  	Time    uint32 `json:"time"`
    11  	Memory  uint32 `json:"memory"`
    12  	Threads uint8  `json:"threads"`
    13  	KeyLen  uint32 `json:"keylen"`
    14  	Salt    []byte `json:"salt"`
    15  }
    16  
    17  // NewArgon2Params returns a new Argon2Params with default values.
    18  func NewArgon2Params() Argon2Params {
    19  	salt, err := Random(16)
    20  	if err != nil {
    21  		panic(err)
    22  	}
    23  	return Argon2Params{
    24  		Time:    1,
    25  		Memory:  64 * 1024, // In KiB
    26  		Threads: 4,
    27  		KeyLen:  32,
    28  		Salt:    salt,
    29  	}
    30  }