diff options
author | Jack Lloyd <[email protected]> | 2018-08-16 13:36:41 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2018-08-16 13:36:41 -0400 |
commit | 25b13af42e05b0522306cee2a1218a5557d25f42 (patch) | |
tree | 851a286bbd28557000360fa25cc684f475ce496b /src/lib/misc | |
parent | 2a8ef82de490dba1cf4dcd34c6c97022a5d18b1a (diff) |
For HOTP/TOTP allow a key/len pair instead of requiring SymmetricKey
Diffstat (limited to 'src/lib/misc')
-rw-r--r-- | src/lib/misc/hotp/hotp.cpp | 5 | ||||
-rw-r--r-- | src/lib/misc/hotp/hotp.h | 13 | ||||
-rw-r--r-- | src/lib/misc/hotp/info.txt | 4 | ||||
-rw-r--r-- | src/lib/misc/hotp/totp.cpp | 5 | ||||
-rw-r--r-- | src/lib/misc/hotp/totp.h | 18 |
5 files changed, 36 insertions, 9 deletions
diff --git a/src/lib/misc/hotp/hotp.cpp b/src/lib/misc/hotp/hotp.cpp index c4c0c7770..9ca37c101 100644 --- a/src/lib/misc/hotp/hotp.cpp +++ b/src/lib/misc/hotp/hotp.cpp @@ -10,7 +10,8 @@ namespace Botan { -HOTP::HOTP(const SymmetricKey& key, const std::string& hash_algo, size_t digits) +HOTP::HOTP(const uint8_t key[], size_t key_len, + const std::string& hash_algo, size_t digits) { BOTAN_ARG_CHECK(digits == 6 || digits == 7 || digits == 8, "Invalid HOTP digits"); @@ -34,7 +35,7 @@ HOTP::HOTP(const SymmetricKey& key, const std::string& hash_algo, size_t digits) else throw Invalid_Argument("Unsupported HOTP hash function"); - m_mac->set_key(key); + m_mac->set_key(key, key_len); } uint32_t HOTP::generate_hotp(uint64_t counter) diff --git a/src/lib/misc/hotp/hotp.h b/src/lib/misc/hotp/hotp.h index 481e404eb..9282067d5 100644 --- a/src/lib/misc/hotp/hotp.h +++ b/src/lib/misc/hotp/hotp.h @@ -23,7 +23,18 @@ class BOTAN_PUBLIC_API(2,2) HOTP final * @param hash_algo the hash algorithm to use, should be SHA-1 or SHA-256 * @param digits the number of digits in the OTP (must be 6, 7, or 8) */ - HOTP(const SymmetricKey& key, const std::string& hash_algo = "SHA-1", size_t digits = 6); + HOTP(const SymmetricKey& key, const std::string& hash_algo = "SHA-1", size_t digits = 6) : + HOTP(key.begin(), key.size(), hash_algo, digits) {} + + /** + * @param key the secret key shared between client and server + * @param key_len length of key param + * @param hash_algo the hash algorithm to use, should be SHA-1 or SHA-256 + * @param digits the number of digits in the OTP (must be 6, 7, or 8) + */ + HOTP(const uint8_t key[], size_t key_len, + const std::string& hash_algo = "SHA-1", + size_t digits = 6); /** * Generate the HOTP for a particular counter value diff --git a/src/lib/misc/hotp/info.txt b/src/lib/misc/hotp/info.txt index ad74686c3..880940c59 100644 --- a/src/lib/misc/hotp/info.txt +++ b/src/lib/misc/hotp/info.txt @@ -1,6 +1,6 @@ <defines> -HOTP -> 20170513 -TOTP -> 20170519 +HOTP -> 20180816 +TOTP -> 20180816 </defines> <requires> diff --git a/src/lib/misc/hotp/totp.cpp b/src/lib/misc/hotp/totp.cpp index 02bc42aa6..9daef6655 100644 --- a/src/lib/misc/hotp/totp.cpp +++ b/src/lib/misc/hotp/totp.cpp @@ -10,9 +10,10 @@ namespace Botan { -TOTP::TOTP(const SymmetricKey& key, const std::string& hash_algo, +TOTP::TOTP(const uint8_t key[], size_t key_len, + const std::string& hash_algo, size_t digits, size_t time_step) - : m_hotp(key, hash_algo, digits) + : m_hotp(key, key_len, hash_algo, digits) , m_time_step(time_step) , m_unix_epoch(calendar_point(1970, 1, 1, 0, 0, 0).to_std_timepoint()) { diff --git a/src/lib/misc/hotp/totp.h b/src/lib/misc/hotp/totp.h index 4ef74d363..4f41b3e9d 100644 --- a/src/lib/misc/hotp/totp.h +++ b/src/lib/misc/hotp/totp.h @@ -24,8 +24,22 @@ class BOTAN_PUBLIC_API(2,2) TOTP final * @param digits the number of digits in the OTP (must be 6, 7, or 8) * @param time_step granularity of OTP in seconds */ - TOTP(const SymmetricKey& key, const std::string& hash_algo = "SHA-1", - size_t digits = 6, size_t time_step = 30); + TOTP(const SymmetricKey& key, + const std::string& hash_algo = "SHA-1", + size_t digits = 6, size_t time_step = 30) : + TOTP(key.begin(), key.size(), hash_algo, digits, time_step) {} + + /** + * @param key the secret key shared between client and server + * @param key_len length of key + * @param hash_algo the hash algorithm to use, should be SHA-1, SHA-256 or SHA-512 + * @param digits the number of digits in the OTP (must be 6, 7, or 8) + * @param time_step granularity of OTP in seconds + */ + TOTP(const uint8_t key[], size_t key_len, + const std::string& hash_algo = "SHA-1", + size_t digits = 6, + size_t time_step = 30); /** * Convert the provided time_point to a Unix timestamp and call generate_totp |