@hackage OTP0.1.0.0
HMAC-Based and Time-Based One-Time Passwords (HOTP & TOTP)
Categories
License
MIT
Maintainer
hvr@gnu.org
Links
Versions
Installation
Tested Compilers
Dependencies (7)
- SHA >=1.6.4.4 && <1.7
- base >=4.5.0.0 && <4.20
- bytestring >=0.10.0.0 && <0.12
- cryptohash-sha1 >=0.11.100.1 && <0.12
- cryptohash-sha256 >=0.11.100.1 && <0.12
- cryptohash-sha512 >=0.11.100.1 && <0.12 Show all…
Dependents (1)
@hackage/acme-everything
Package Flags
pure-sha
(off by default)
Use pure Haskell SHA implementation instead of cryptohash-sha1/256/512
OTP: HMAC-Based and Time-Based One-Time Passwords (HOTP & TOTP)

Please refer to the package description for an overview of OTP.
Usage examples
Generating one-time passwords
If you need to generate HOTP password described in RFC4226, then use
>>> hotp SHA1 "1234" 100 6
317569
>>> hotp SHA512 "1234" 100 6
134131
Or
>>> totp SHA1 "1234" (read "2010-10-10 00:01:00 UTC") 30 8
43388892
to generate TOTP password described in RFC6238.
Checking one-time passwords
hotpCheck :: HashAlgorithm -- ^ Hashing algorithm
-> Secret -- ^ Shared secret
-> (Word8, Word8) -- ^ how much counters to take lower and higher than ideal
-> Word64 -- ^ ideal (expected) counter value
-> Word8 -- ^ Number of digits in password
-> Word32 -- ^ Password entered by user
-> Bool -- ^ True if password acceptable
>>> hotpCheck SHA1 "1234" (0,0) 10 6 50897
True
>>> hotpCheck SHA1 "1234" (0,0) 9 6 50897
False
>>> hotpCheck SHA1 "1234" (0,1) 9 6 50897
True
Here almost the same aguments as for hotp function, but there is
also (0, 0) tuple. This tuple describes range of counters to check
in case of desynchronisation of counters between client and
server. I.e. if you specify (1, 1) and ideal counter will be 10
then function will check passwords for [9, 10, 11] list of
counters.
Here is the same for TOTP:
>>> totpCheck SHA1 "1234" (0, 0) (read "2010-10-10 00:00:00 UTC") 30 6 778374
True
>>> totpCheck SHA1 "1234" (0, 0) (read "2010-10-10 00:00:30 UTC") 30 6 778374
False
>>> totpCheck SHA1 "1234" (1, 0) (read "2010-10-10 00:00:30 UTC") 30 6 778374
True