Botan  1.11.15
src/lib/misc/srp6/srp6.h
Go to the documentation of this file.
00001 /*
00002 * SRP-6a (RFC 5054 compatatible)
00003 * (C) 2011,2012 Jack Lloyd
00004 *
00005 * Botan is released under the Simplified BSD License (see license.txt)
00006 */
00007 
00008 #ifndef BOTAN_RFC5054_SRP6_H__
00009 #define BOTAN_RFC5054_SRP6_H__
00010 
00011 #include <botan/bigint.h>
00012 #include <botan/hash.h>
00013 #include <botan/rng.h>
00014 #include <botan/symkey.h>
00015 #include <string>
00016 
00017 namespace Botan {
00018 
00019 /**
00020 * SRP6a Client side
00021 * @param username the username we are attempting login for
00022 * @param password the password we are attempting to use
00023 * @param group_id specifies the shared SRP group
00024 * @param hash_id specifies a secure hash function
00025 * @param salt is the salt value sent by the server
00026 * @param B is the server's public value
00027 * @param rng is a random number generator
00028 *
00029 * @return (A,K) the client public key and the shared secret key
00030 */
00031 std::pair<BigInt,SymmetricKey>
00032 BOTAN_DLL srp6_client_agree(const std::string& username,
00033                             const std::string& password,
00034                             const std::string& group_id,
00035                             const std::string& hash_id,
00036                             const std::vector<byte>& salt,
00037                             const BigInt& B,
00038                             RandomNumberGenerator& rng);
00039 
00040 /**
00041 * Generate a new SRP-6 verifier
00042 * @param identifier a username or other client identifier
00043 * @param password the secret used to authenticate user
00044 * @param salt a randomly chosen value, at least 128 bits long
00045 * @param group_id specifies the shared SRP group
00046 * @param hash_id specifies a secure hash function
00047 */
00048 BigInt BOTAN_DLL generate_srp6_verifier(const std::string& identifier,
00049                                         const std::string& password,
00050                                         const std::vector<byte>& salt,
00051                                         const std::string& group_id,
00052                                         const std::string& hash_id);
00053 
00054 /**
00055 * Return the group id for this SRP param set, or else thrown an
00056 * exception
00057 * @param N the group modulus
00058 * @param g the group generator
00059 * @return group identifier
00060 */
00061 std::string BOTAN_DLL srp6_group_identifier(const BigInt& N, const BigInt& g);
00062 
00063 /**
00064 * Represents a SRP-6a server session
00065 */
00066 class BOTAN_DLL SRP6_Server_Session
00067    {
00068    public:
00069       /**
00070       * Server side step 1
00071       * @param v the verification value saved from client registration
00072       * @param group_id the SRP group id
00073       * @param hash_id the SRP hash in use
00074       * @param rng a random number generator
00075       * @return SRP-6 B value
00076       */
00077       BigInt step1(const BigInt& v,
00078                    const std::string& group_id,
00079                    const std::string& hash_id,
00080                    RandomNumberGenerator& rng);
00081 
00082       /**
00083       * Server side step 2
00084       * @param A the client's value
00085       * @return shared symmetric key
00086       */
00087       SymmetricKey step2(const BigInt& A);
00088 
00089    private:
00090       std::string m_hash_id;
00091       BigInt m_B, m_b, m_v, m_S, m_p;
00092       size_t m_p_bytes;
00093    };
00094 
00095 }
00096 
00097 #endif