HMAC-based one-time password
HMAC-based one-time password (HOTP) is a one-time password (OTP) algorithm based on the hash-based message authentication code (HMAC) cryptographic algorithm and is a basis for the commonly used Time-based one-time password (TOTP) algorithm which extends upon it. The HOTP algorithm is a freely available open standard and often forms part of multi-factor authentication protocols such as the Open Authentication initiative (OATH) challenge-response algorithm. . At setup time a client and server share a secret and other initialization settings. In future exchanges when a client attempts to access a server a challenge is sent from the server to the client and the client then uses the previously... Source: e01 Encyclopedia. Licence: CC BY-SA 4.0.
HMAC-based one-time password (HOTP) is a one-time password (OTP) algorithm based on the hash-based message authentication code (HMAC) cryptographic algorithm and is a basis for the commonly used Time-based one-time password (TOTP) algorithm which extends upon it. The HOTP algorithm is a freely available open standard and often forms part of multi-factor authentication protocols such as the Open Authentication initiative (OATH) challenge-response algorithm. . At setup time a client and server share a secret and other initialization settings. In future exchanges when a client attempts to access a server a challenge is sent from the server to the client and the client then uses the previously exchanged secret and computes a value (a one time password) to be used as the server's challenge response. HOTP was published as an informational IETF in December 2005, documenting the algorithm along with a Java implementation. Since then, the algorithm has been adopted by many companies worldwide (see below). 6-digit codes are commonly provided by proprietary hardware tokens from a number of vendors informing the default value of d. Truncation extracts 31 bits or \log_{10}(2^{31}) \approx 9.3 decimal digits, meaning that d can be at most 10, with the 10th digit adding less variation, taking values of 0, 1, and 2 (i.e., 0.3 digits). After verification, the authenticator can authenticate itself simply by generating the next HOTP value, returning it, and then the authenticated can generate their own HOTP value to verify it. Note that counters are guaranteed to be synchronised at this point in the process. The HOTP value is the human-readable design output, a d-digit decimal number (without omission of leading 0s): HOTP value = HOTP(K, C) mod 10 d . That is, the value is the d least significant base-10 digits of HOTP. HOTP is a truncation of the HMAC of the counter C (under the key K and hash function H): HOTP(K, C) = truncate(HMAC (K, C)), where the counter C must be used big-endian. Truncation first takes the 4 least significant bits of the MAC and uses them as a byte offset i: truncate(MAC) = extract31(MAC, MAC[(19 × 8 + 4):(19 × 8 + 7)]), where ":" is used to extract bits from a starting bit number up to and including an ending bit number, where these bit numbers are 0-origin. The use of "19" in the above formula relates to the size of the output from the hash function. With the default of SHA-1, the output is , and so the last byte is byte 19 (0-origin). That index i is used to select 31 bits from MAC, starting at bit i × 8 + 1: extract31(MAC, i) = MAC[(i × 8 + 1):(i × 8 + 4 × 8 − 1)]. 31 bits are a single bit short of a 4-byte word. Thus the value can be placed inside such a word without using the sign bit (the most significant bit). This is done to definitely avoid doing modular arithmetic on negative numbers, as this has many differing definitions and implementations. import hashlib def hmac_sha1(key: bytes, msg: bytes) -> bytes: if len(key) > 64: key = hashlib.sha1(key).digest() if len(key) str: mac = hmac_sha1(key=key, msg=ctr.to_bytes(8, 'big')) offset = mac[-1] & 0xf truncated = bytearray(mac[offset:offset+4]) truncated[0] &= 0x7f value = int.from_bytes(truncated, 'big') % (10**length) return str(value).rjust(length, '0') The secret is encoded as RFC 4648 Base32, with padding omitted. For example, the URI otpauth://hotp/Wikipedian?secret=JBSWY3DPFQQHO33SNRSCC&counter=42 represents a HOTP token labeled "Wikipedian", with the secret Hello, world! encoded as ASCII, and the initial counter 42. When added to an authenticator, it should produce the code 439256 .
Cite this
"HMAC-based one-time password". 1791323456. e01 Encyclopedia. CC BY-SA 4.0. https://en.wikipedia.org/w/index.php?oldid=1378928807 JSON record · API collection · BibTeX · RIS · CSL-JSON · citation policy