Botan  2.7.0
Crypto and TLS for C++11
hotp.h
Go to the documentation of this file.
1 /*
2 * HOTP
3 * (C) 2017 Jack Lloyd
4 *
5 * Botan is released under the Simplified BSD License (see license.txt)
6 */
7 
8 #ifndef BOTAN_HOTP_H_
9 #define BOTAN_HOTP_H_
10 
11 #include <botan/mac.h>
12 
13 namespace Botan {
14 
15 /**
16 * HOTP one time passwords (RFC 4226)
17 */
18 class BOTAN_PUBLIC_API(2,2) HOTP final
19  {
20  public:
21  /**
22  * @param key the secret key shared between client and server
23  * @param hash_algo the hash algorithm to use, should be SHA-1 or SHA-256
24  * @param digits the number of digits in the OTP (must be 6, 7, or 8)
25  */
26  HOTP(const SymmetricKey& key, const std::string& hash_algo = "SHA-1", size_t digits = 6);
27 
28  /**
29  * Generate the HOTP for a particular counter value
30  * @warning if the counter value is repeated the OTP ceases to be one-time
31  */
32  uint32_t generate_hotp(uint64_t counter);
33 
34  /**
35  * Check an OTP value using a starting counter and a resync range
36  * @param otp the client provided OTP
37  * @param starting_counter the server's guess as to the current counter state
38  * @param resync_range if 0 then only HOTP(starting_counter) is accepted
39  * If larger than 0, up to resync_range values after HOTP are also checked.
40  * @return (valid,next_counter). If the OTP does not validate, always
41  * returns (false,starting_counter). Otherwise returns (true,next_counter)
42  * where next_counter is at most starting_counter + resync_range + 1
43  */
44  std::pair<bool,uint64_t> verify_hotp(uint32_t otp, uint64_t starting_counter, size_t resync_range = 0);
45  private:
46  std::unique_ptr<MessageAuthenticationCode> m_mac;
47  uint32_t m_digit_mod;
48  };
49 
50 }
51 
52 #endif
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:27
Definition: alg_id.cpp:13
AlgorithmIdentifier hash_algo
Definition: x509_obj.cpp:23