Documentation
¶
Index ¶
- Constants
- func CompareArgon2idKey(passphrase string, salt []byte, params Argon2idParams, expectedKey []byte) (bool, error)
- func CopyBytes(src []byte) []byte
- func DecryptAES(cipherText, rawKey []byte) ([]byte, error)
- func DecryptAESWithAAD(cipherText, rawKey, aad []byte) ([]byte, error)
- func DeriveArgon2idKey(passphrase string, salt []byte, params Argon2idParams) ([]byte, error)
- func EncryptAES(plainText, rawKey []byte) ([]byte, error)
- func EncryptAESWithAAD(plainText, rawKey, aad []byte) ([]byte, error)
- func GenerateSelfSignedCert() (tls.Certificate, error)
- func HKDF(seed []byte, salt []byte, info []byte) ([]byte, error)
- func HexDecode(s string) ([]byte, error)
- func HexEncode(b []byte) string
- func NewAESKey() ([]byte, error)
- func NewTwoSecretKey(passphrase string, saltPass []byte, argonParams Argon2idParams, ...) ([]byte, error)
- func Normalize(s string) string
- func RandomBytes(n int) ([]byte, error)
- func RandomChars(n int) (string, error)
- func RandomInt() (int, error)
- func RandomIntn(max int) (int, error)
- func SharedSecret(priv [32]byte, pub [32]byte) ([32]byte, error)
- func ValidateArgon2idParams(p Argon2idParams) error
- func WipeArray32(a *[32]byte)
- func WipeBytes(b []byte)
- func Xor(a, b []byte) ([]byte, error)
- type Argon2idParams
- type KeyPair
Constants ¶
const ( MinArgon2Time uint32 = 1 MinArgon2MemoryKiB uint32 = 19 * 1024 // 19 MiB — OWASP minimum recommendation MinArgon2Parallel uint8 = 1 )
Minimum acceptable Argon2id parameters. Any profile or custom configuration must meet or exceed these to prevent dangerously weak KDF settings. Values are based on OWASP Password Storage Cheat Sheet recommendations for Argon2id.
const ( // KDFProfileInteractive targets sub-second derivation on modest hardware. // Suitable for development, testing, and high-throughput API servers. // OWASP: meets minimum recommendation (Argon2id t=2, m=19MiB). KDFProfileInteractive = "interactive" // KDFProfileModerate is the production default. Balances security and // latency for typical web-application deployments. // OWASP: exceeds minimum recommendation (Argon2id t=3, m=64MiB). KDFProfileModerate = "moderate" // KDFProfileSensitive targets higher-value secrets where multi-second // derivation is acceptable. Suitable for CA root keys, backup encryption, // and credential export. // OWASP: well above minimum recommendation (Argon2id t=4, m=128MiB). KDFProfileSensitive = "sensitive" )
Named KDF profiles for different deployment scenarios. Profiles are ordered from lowest to highest cost.
const (
AESKeySize = 32
)
const HKDFKeyLength = 32
Variables ¶
This section is empty.
Functions ¶
func CompareArgon2idKey ¶
func CompareArgon2idKey(passphrase string, salt []byte, params Argon2idParams, expectedKey []byte) (bool, error)
CompareArgon2idKey derives a key and compares it in constant time to the expected key.
func DecryptAES ¶
func DecryptAESWithAAD ¶
func DeriveArgon2idKey ¶
func DeriveArgon2idKey(passphrase string, salt []byte, params Argon2idParams) ([]byte, error)
DeriveArgon2idKey derives a 32-byte key from a passphrase using Argon2id.
func EncryptAES ¶
func EncryptAESWithAAD ¶
func GenerateSelfSignedCert ¶
func GenerateSelfSignedCert() (tls.Certificate, error)
GenerateSelfSignedCert generates a self-signed certificate in memory.
func NewTwoSecretKey ¶
func RandomBytes ¶
func RandomChars ¶
func RandomIntn ¶
func ValidateArgon2idParams ¶
func ValidateArgon2idParams(p Argon2idParams) error
ValidateArgon2idParams checks that the given parameters meet the minimum acceptable thresholds. Returns an error describing which parameter is too low. This prevents operators from accidentally configuring dangerously weak KDF settings.
func WipeArray32 ¶
func WipeArray32(a *[32]byte)
WipeArray32 best-effort zeroes the provided 32-byte array in place.
Types ¶
type Argon2idParams ¶
type Argon2idParams struct {
Time uint32 `json:"time"`
MemoryKiB uint32 `json:"memory"`
Parallelism uint8 `json:"parallelism"`
KeyLen uint32 `json:"key_len"`
}
Argon2idParams configures the Argon2id key derivation function. Parameters are stored alongside vault state so that existing vaults keep working when defaults are raised.
func Argon2idProfile ¶
func Argon2idProfile(name string) (Argon2idParams, error)
Argon2idProfile returns the Argon2idParams for a named profile. Returns an error for unknown profile names.
func DefaultArgon2idParams ¶
func DefaultArgon2idParams() Argon2idParams
DefaultArgon2idParams returns the default Argon2id parameters for vault operations. This uses the "moderate" profile: Time=3, Memory=64 MiB, Parallelism=4 — aligned with OWASP Password Storage Cheat Sheet guidance for Argon2id.
Existing vaults are NOT affected by changes to this default because KDF parameters are persisted in vault state at creation time. Only newly created vaults use the current default.