crypto

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 2, 2026 License: MIT Imports: 9 Imported by: 0

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

View Source
const KeySize = 32

KeySize is the size of all symmetric keys (AES-256).

Variables

View Source
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).

View Source
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

func Derive(root []byte, info string) ([]byte, error)

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 Open

func Open(key, nonce, ciphertext, aad []byte) ([]byte, error)

Open decrypts and authenticates data produced by Seal.

func PasswordKey

func PasswordKey(password, salt []byte, p Argon2Params) ([]byte, error)

PasswordKey derives a key-encryption key from a password.

func RandomBytes

func RandomBytes(n int) []byte

RandomBytes returns n bytes from the operating system CSPRNG.

func Seal

func Seal(key, plaintext, aad []byte) (nonce, ciphertext []byte, err error)

Seal encrypts plaintext with AES-256-GCM under key, binding aad. It returns a fresh random 96-bit nonce and the ciphertext with tag.

func Zero

func Zero(b []byte)

Zero overwrites b. Go gives no guarantee that copies were not made, so this is best-effort hygiene rather than a security boundary.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL