diff options
author | Jack Lloyd <[email protected]> | 2019-04-30 08:53:55 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2019-04-30 08:56:28 -0400 |
commit | c060827c1e6e662fd51fbb34d0300ff09067e586 (patch) | |
tree | ee6a91c93f44aa6e93f5a714d6e08ecf5f090cf3 /src/lib/misc | |
parent | a3655a15e84f9496fec587e72d923be4c1901137 (diff) |
Add proper SRP6 tests
Fixes GH #1917
Diffstat (limited to 'src/lib/misc')
-rw-r--r-- | src/lib/misc/srp6/srp6.cpp | 46 | ||||
-rw-r--r-- | src/lib/misc/srp6/srp6.h | 70 |
2 files changed, 102 insertions, 14 deletions
diff --git a/src/lib/misc/srp6/srp6.cpp b/src/lib/misc/srp6/srp6.cpp index 825c38589..0bd9b192a 100644 --- a/src/lib/misc/srp6/srp6.cpp +++ b/src/lib/misc/srp6/srp6.cpp @@ -1,6 +1,6 @@ /* * SRP-6a (RFC 5054 compatatible) -* (C) 2011,2012 Jack Lloyd +* (C) 2011,2012,2019 Jack Lloyd * * Botan is released under the Simplified BSD License (see license.txt) */ @@ -82,9 +82,22 @@ srp6_client_agree(const std::string& identifier, const BigInt& B, RandomNumberGenerator& rng) { - const size_t a_bits = 256; - DL_Group group(group_id); + const size_t a_bits = group.exponent_bits(); + + return srp6_client_agree(identifier, password, group, hash_id, salt, B, a_bits, rng); + } + +std::pair<BigInt, SymmetricKey> +srp6_client_agree(const std::string& identifier, + const std::string& password, + const DL_Group& group, + const std::string& hash_id, + const std::vector<uint8_t>& salt, + const BigInt& B, + const size_t a_bits, + RandomNumberGenerator& rng) + { const BigInt& g = group.get_g(); const BigInt& p = group.get_p(); @@ -117,10 +130,18 @@ BigInt generate_srp6_verifier(const std::string& identifier, const std::string& group_id, const std::string& hash_id) { - const BigInt x = compute_x(hash_id, identifier, password, salt); - DL_Group group(group_id); - // FIXME: x should be size of hash fn + return generate_srp6_verifier(identifier, password, salt, group, hash_id); + } + +BigInt generate_srp6_verifier(const std::string& identifier, + const std::string& password, + const std::vector<uint8_t>& salt, + const DL_Group& group, + const std::string& hash_id) + { + const BigInt x = compute_x(hash_id, identifier, password, salt); + // FIXME: x should be size of hash fn so avoid computing x.bits() here return group.power_g_p(x, x.bits()); } @@ -129,9 +150,18 @@ BigInt SRP6_Server_Session::step1(const BigInt& v, const std::string& hash_id, RandomNumberGenerator& rng) { - const size_t b_bits = 256; - DL_Group group(group_id); + const size_t b_bits = group.exponent_bits(); + + return this->step1(v, group, hash_id, b_bits, rng); + } + +BigInt SRP6_Server_Session::step1(const BigInt& v, + const DL_Group& group, + const std::string& hash_id, + size_t b_bits, + RandomNumberGenerator& rng) + { const BigInt& g = group.get_g(); const BigInt& p = group.get_p(); diff --git a/src/lib/misc/srp6/srp6.h b/src/lib/misc/srp6/srp6.h index ad880946a..cf41b1ef2 100644 --- a/src/lib/misc/srp6/srp6.h +++ b/src/lib/misc/srp6/srp6.h @@ -1,6 +1,6 @@ /* * SRP-6a (RFC 5054 compatatible) -* (C) 2011,2012 Jack Lloyd +* (C) 2011,2012,2019 Jack Lloyd * * Botan is released under the Simplified BSD License (see license.txt) */ @@ -14,6 +14,7 @@ namespace Botan { +class DL_Group; class RandomNumberGenerator; /** @@ -37,6 +38,30 @@ BOTAN_PUBLIC_API(2,0) srp6_client_agree(const std::string& username, const BigInt& B, RandomNumberGenerator& rng); + +/** +* SRP6a Client side +* @param username the username we are attempting login for +* @param password the password we are attempting to use +* @param group specifies the shared SRP group +* @param hash_id specifies a secure hash function +* @param salt is the salt value sent by the server +* @param B is the server's public value +* @param a_bits size of secret exponent in bits +* @param rng is a random number generator +* +* @return (A,K) the client public key and the shared secret key +*/ +std::pair<BigInt,SymmetricKey> BOTAN_PUBLIC_API(2,11) + srp6_client_agree(const std::string& username, + const std::string& password, + const DL_Group& group, + const std::string& hash_id, + const std::vector<uint8_t>& salt, + const BigInt& B, + size_t a_bits, + RandomNumberGenerator& rng); + /** * Generate a new SRP-6 verifier * @param identifier a username or other client identifier @@ -45,11 +70,27 @@ BOTAN_PUBLIC_API(2,0) srp6_client_agree(const std::string& username, * @param group_id specifies the shared SRP group * @param hash_id specifies a secure hash function */ -BigInt BOTAN_PUBLIC_API(2,0) generate_srp6_verifier(const std::string& identifier, - const std::string& password, - const std::vector<uint8_t>& salt, - const std::string& group_id, - const std::string& hash_id); +BigInt BOTAN_PUBLIC_API(2,0) + generate_srp6_verifier(const std::string& identifier, + const std::string& password, + const std::vector<uint8_t>& salt, + const std::string& group_id, + const std::string& hash_id); + +/** +* Generate a new SRP-6 verifier +* @param identifier a username or other client identifier +* @param password the secret used to authenticate user +* @param salt a randomly chosen value, at least 128 bits long +* @param group_id specifies the shared SRP group +* @param hash_id specifies a secure hash function +*/ +BigInt BOTAN_PUBLIC_API(2,11) + generate_srp6_verifier(const std::string& identifier, + const std::string& password, + const std::vector<uint8_t>& salt, + const DL_Group& group, + const std::string& hash_id); /** * Return the group id for this SRP param set, or else thrown an @@ -80,6 +121,23 @@ class BOTAN_PUBLIC_API(2,0) SRP6_Server_Session final RandomNumberGenerator& rng); /** + * Server side step 1 + * This version of step1 added in 2.11 + * + * @param v the verification value saved from client registration + * @param group the SRP group + * @param hash_id the SRP hash in use + * @param rng a random number generator + * @param b_bits size of secret exponent in bits + * @return SRP-6 B value + */ + BigInt step1(const BigInt& v, + const DL_Group& group, + const std::string& hash_id, + const size_t b_bits, + RandomNumberGenerator& rng); + + /** * Server side step 2 * @param A the client's value * @return shared symmetric key |