Documentation
¶
Overview ¶
Package totp implements the time-based one-time password of RFC 6238 over the HMAC one-time password of RFC 4226.
The package supports the single configuration that every authenticator application accepts: HMAC-SHA-1, six digits, and a thirty-second step.
SHA-1 is correct here. The HMAC construction does not inherit the collision weakness of the bare hash, and an authenticator application that reads a different algorithm from the enrolment URI can refuse it.
Index ¶
- Constants
- Variables
- func DecodeSecret(s string) ([]byte, error)
- func EncodeSecret(secret []byte) string
- func Generate(secret []byte, t time.Time, p Params) string
- func NewSecret() ([]byte, error)
- func Step(t time.Time, p Params) int64
- func URI(secret []byte, issuer, account string, p Params) string
- func Validate(secret []byte, input string, t time.Time, p Params) (int64, bool)
- type Params
Constants ¶
const SecretBytes = 20
SecretBytes is the length of a new shared secret. RFC 4226 requires at least 128 bits and recommends 160 bits, which is the output length of SHA-1.
Variables ¶
var ErrInvalidSecret = errors.New("authall/totp: the secret is not valid base32")
ErrInvalidSecret reports a secret that is not valid base32.
Functions ¶
func DecodeSecret ¶
DecodeSecret returns the raw bytes of a base32 secret. It accepts a secret with padding and a secret in lower case, because a user can retype one.
func EncodeSecret ¶
EncodeSecret returns the base32 form of a secret. The database keeps this form, and the enrolment response shows it to the user.
func URI ¶
URI returns the otpauth URI of an enrolment. An authenticator application reads it from a QR code.
The label names the issuer and the account, so a person who holds two accounts of one application sees them apart.
Types ¶
type Params ¶
type Params struct {
// Digits is the length of a code.
Digits int
// Period is the length of one time step.
Period time.Duration
// Skew is the number of steps that Validate accepts on each side of the
// current step. A skew of one covers a clock difference of one period in
// each direction.
Skew int
}
Params are the parameters of one TOTP configuration.