pin

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package pin hashes and checks the owner's PIN or passphrase. It is pure: no file, no clock, no randomness of its own - the caller passes the salt.

New hashes are Argon2id at RFC 9106's second recommended setting (t=3, 64 MiB, p=4): memory-hard, so a stolen hash costs a GPU far more to guess than an iterated hash does. Hashes from earlier releases are PBKDF2-HMAC-SHA256 at 600,000 iterations; they still verify, and Verify reports them stale so the caller rehashes on the next correct entry. The encoded form names its algorithm and cost, so this can change again without invalidating a PIN anyone has set.

Index

Constants

View Source
const (
	ArgonTime    = 3
	ArgonMemory  = 64 * 1024 // KiB
	ArgonThreads = 4
)

The Argon2id cost new hashes are made with: RFC 9106 section 4, the second recommended option, for an environment that cannot spare 2 GiB.

View Source
const (
	MinLen = 6
	MaxLen = 128
)

MinLen and MaxLen bound a PIN or passphrase, in characters.

View Source
const Algorithm = "argon2id"

Algorithm is the tag new hashes are encoded under.

View Source
const Iterations = 600_000

Iterations is the PBKDF2 cost earlier releases hashed with.

View Source
const LegacyAlgorithm = "pbkdf2-sha256"

LegacyAlgorithm is the tag of the hashes earlier releases made; they still verify, and are reported stale.

View Source
const SaltLen = 16

SaltLen is the salt length, in bytes, that Hash expects.

Variables

View Source
var ErrMalformed = errors.New("the stored PIN hash is not in a form authama reads")

ErrMalformed is an encoded hash this package cannot read.

Functions

func Hash

func Hash(p string, salt []byte) (string, error)

Hash returns the encoded hash of p with salt, at the current cost: argon2id$v=19$m=65536,t=3,p=4$<salt>$<key>, both base64 (raw, standard alphabet), the parameters as the PHC string format writes them.

func Policy

func Policy(p string) error

Policy reports why a candidate PIN cannot be used, or nil. Six digits is the floor a phone asks for; a passphrase may be anything printable up to 128.

func Verify

func Verify(encoded, p string) (ok, stale bool, err error)

Verify reports whether p matches encoded, comparing in constant time. It also reports whether the hash is weaker than a new one would be (any PBKDF2 hash, or Argon2id below the current cost), so the caller can rehash it while it has the PIN in hand.

Types

This section is empty.

Jump to

Keyboard shortcuts

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