Documentation
¶
Overview ¶
Package crypto holds the small set of primitives the vault is built from: AES-256-GCM sealing, HKDF key derivation, Argon2id password hashing and random identifiers. It deliberately contains no novel constructions.
Importers usually alias it: skcrypto "github.com/matusso/sslknife/internal/crypto".
Index ¶
- Constants
- Variables
- func Derive(root []byte, info string) ([]byte, error)
- func NewID() string
- func Open(key, nonce, ciphertext, aad []byte) ([]byte, error)
- func PasswordKey(password, salt []byte, p Argon2Params) ([]byte, error)
- func RandomBytes(n int) []byte
- func Seal(key, plaintext, aad []byte) (nonce, ciphertext []byte, err error)
- func Zero(b []byte)
- type Argon2Params
Constants ¶
const KeySize = 32
KeySize is the size of all symmetric keys (AES-256).
Variables ¶
var DefaultArgon2 = Argon2Params{Time: 3, MemoryKiB: 64 * 1024, Threads: 4}
DefaultArgon2 follows the RFC 9106 second recommended option (t=3, m=64 MiB, p=4).
var ErrDecrypt = errors.New("decryption failed: wrong key or corrupted data")
ErrDecrypt is returned when authenticated decryption fails: wrong key or tampered data.
Functions ¶
func Derive ¶
Derive derives a KeySize subkey from a root key using HKDF-SHA256 with the given info label for domain separation.
func NewID ¶
func NewID() string
NewID returns a random 12-hex-digit identifier used for inventory objects.
func PasswordKey ¶
func PasswordKey(password, salt []byte, p Argon2Params) ([]byte, error)
PasswordKey derives a key-encryption key from a password.
func RandomBytes ¶
RandomBytes returns n bytes from the operating system CSPRNG.
Types ¶
type Argon2Params ¶
type Argon2Params struct {
Time uint32 `json:"t"`
MemoryKiB uint32 `json:"m"`
Threads uint8 `json:"p"`
}
Argon2Params are Argon2id cost parameters. They are stored alongside each password keyslot so they can be raised later without breaking old slots.
func (Argon2Params) Validate ¶
func (p Argon2Params) Validate() error
Validate rejects parameters that are too weak or absurdly expensive, so a tampered keyslot file cannot downgrade or DoS the KDF.