totp

package
v1.0.310 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: MIT Imports: 7 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 totp implements TOTP (RFC 6238) validation using only the standard library: HMAC-SHA1 with a 30-second step, 6-digit output, and ±1 step clock skew. It has no dependencies on the rest of Culvert (first internal/ leaf extracted under ADR-0002).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SameKey added in v1.0.248

func SameKey(a, b string) bool

SameKey reports whether two stored secret strings denote the SAME authenticator key.

It compares the DECODED keys, never the stored strings: the verifier canonicalises case and surrounding whitespace before decoding, so "jbswy3dpehpk3pxp", " JBSWY3DPEHPK3PXP " and "JBSWY3DPEHPK3PXP" are one key and generate identical codes. A caller deciding whether a key CHANGED must ask this question, not whether the stored string changed.

An unusable secret is never the same key as anything, so a caller must treat !Usable separately rather than reading false as "the key changed" — see Config.SetTOTPSecret in package main.

func Usable added in v1.0.248

func Usable(secret string) bool

Usable reports whether a stored secret decodes to a key that could validate a code. A secret that is not usable authenticates nothing.

func VerifyTOTPReturnCounter

func VerifyTOTPReturnCounter(secret, code string, nowUnix, lastCounter int64) (ok bool, counter int64)

VerifyTOTPReturnCounter validates a TOTP code and returns (ok, counter) where counter is the matched time-step. Callers MUST track the last-matched counter per user and reject codes whose matched counter is <= lastCounter to close the replay window (RFC 6238 §5.2). Passing lastCounter = 0 disables replay protection (legacy call sites).

A nowUnix parameter is taken instead of calling time.Now() so tests can exercise the function deterministically without clock monkey-patching.

Types

This section is empty.

Jump to

Keyboard shortcuts

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