secretbox

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 10, 2026 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package secretbox is a thin AEAD wrapper used to protect at-rest secrets — currently TOTP secrets, future sprints will reuse it for per-user key material (PATs, deploy keys, etc.).

Construction: chacha20poly1305 (XChaCha20 not used — we mint nonces per-row and store them, so the smaller 12-byte nonce is fine).

Key sourcing: 32-byte key, base64-encoded in config (auth.totp_key_b64 or env SHITHUB_TOTP_KEY). Operators rotate by re-encrypting all rows — a key change without a rotation breaks every existing 2FA login. That procedure is documented in docs/internal/2fa.md.

Index

Constants

View Source
const KeySize = chacha20poly1305.KeySize // 32

KeySize is the required key length in bytes.

View Source
const NonceSize = chacha20poly1305.NonceSize // 12

NonceSize is the AEAD nonce length, stored alongside the ciphertext.

Variables

This section is empty.

Functions

func EncodeKey

func EncodeKey(key []byte) string

EncodeKey returns the standard-base64 encoding suitable for placing in auth.totp_key_b64.

func GenerateKey

func GenerateKey() ([]byte, error)

GenerateKey returns a fresh 32-byte key suitable for FromBytes / FromBase64. Used by the test harness and an operator helper.

Types

type Box

type Box struct {
	// contains filtered or unexported fields
}

Box wraps a ready-to-use AEAD. Construct with FromBase64 or FromBytes.

func FromBase64

func FromBase64(b64 string) (*Box, error)

FromBase64 decodes the supplied base64 key (standard or url alphabet) and returns a Box. Returns an error if the key isn't 32 bytes.

func FromBytes

func FromBytes(key []byte) (*Box, error)

FromBytes wraps raw key bytes. Returns an error if not exactly KeySize.

func (*Box) Open

func (b *Box) Open(ciphertext, nonce []byte) ([]byte, error)

Open decrypts ciphertext with the stored nonce. Authenticated decryption failures (tamper, wrong key) return a non-nil error.

func (*Box) Seal

func (b *Box) Seal(plaintext []byte) (ciphertext, nonce []byte, err error)

Seal encrypts plaintext under a freshly minted random nonce. Returns (ciphertext, nonce). Nonces are 12 bytes — at our scale the birthday bound is well above the operational lifetime of any single key.

Jump to

Keyboard shortcuts

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