Documentation
¶
Overview ¶
Package totp computes and checks time-based one-time passwords on the standard library: RFC 6238 over RFC 4226's HOTP, fixed at HMAC-SHA-1, six digits and a 30-second step, since Google Authenticator ignores any other algorithm, length or period. It emits the Key Uri Format and never parses one. Replay protection is the caller's: Match returns the step it accepted, and the caller stores it and passes it back as after.
Index ¶
Constants ¶
const ( SecretBytes = 20 // 160 bits: RFC 4226 §4 R6; NIST SP 800-63B-4 §3.1.4 asks for 112 Digits = 6 // RFC 4226 §5.3; the Key Uri Format's default Period = 30 * time.Second // RFC 6238 §5.2's recommended X Skew = 1 // steps accepted either side of now: RFC 6238 §5.2 and §6 )
The fixed parameters of every secret and code.
Variables ¶
This section is empty.
Functions ¶
func Code ¶
Code is the HOTP value of RFC 4226 §5.3 for secret at counter step: HMAC-SHA-1, dynamic truncation, then mod 10^Digits, zero-padded.
func Text ¶
Text is secret in RFC 4648 §6 base32 without padding, the key a person types when they cannot scan the URI.
Types ¶
type Result ¶
type Result int
Result is what Match found.
const ( NoMatch Result = iota Matched Reused // the code is a step at or below after, and no fresher step matched Malformed // not six ASCII digits after removing spaces; the caller refuses it before any count )
The answers of Match.
func Match ¶
Match removes ASCII spaces from raw, so "123 456" is the same code as "123456" for replay and for the count, then compares it with each step from Step(now)+Skew down to Step(now)-Skew by subtle.ConstantTimeCompare, stopping at the first match above after. It returns Matched with that step; else Reused when a step at or below after matches; else NoMatch. The step is meaningful only with Matched, and the caller stores it as the next after. Scanning from the newest step keeps a replay refused when two steps in the window share a code.