| 1 | /* |
| 2 | * Class that implements the SRP-3 based authentication schema |
| 3 | * used by Blizzards WarCraft 3. Implementations is based upon |
| 4 | * public information available under |
| 5 | * http://www.javaop.com/@ron/documents/SRP.html |
| 6 | * |
| 7 | * Copyright (C) 2008 - Olaf Freyer |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or |
| 10 | * modify it under the terms of the GNU Affero General Public License |
| 11 | * as published by the Free Software Foundation; either version 3 |
| 12 | * of the License, or (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU Affero General Public License for more details. |
| 18 | */ |
| 19 | |
| 20 | #ifndef __BNET_SRP3_INCLUDED__ |
| 21 | #define __BNET_SRP3_INCLUDED__ |
| 22 | |
| 23 | #include <string> |
| 24 | #include "common/bigint.h" |
| 25 | |
| 26 | namespace pvpgn |
| 27 | { |
| 28 | |
| 29 | class BnetSRP3 |
| 30 | { |
| 31 | public: |
| 32 | BnetSRP3(const char* username, BigInt& salt); |
| 33 | BnetSRP3(const std::string& username, BigInt& salt); |
| 34 | BnetSRP3(const char* username, const char* password); |
| 35 | BnetSRP3(const std::string& username, const std::string& password); |
| 36 | ~BnetSRP3(); |
| 37 | BigInt getVerifier() const; |
| 38 | BigInt getSalt() const; |
| 39 | void setSalt(BigInt salt); |
| 40 | BigInt getClientSessionPublicKey() const; |
| 41 | BigInt getServerSessionPublicKey(BigInt& v); |
| 42 | BigInt getHashedClientSecret(BigInt& B) const; |
| 43 | BigInt getHashedServerSecret(BigInt& A, BigInt& v); |
| 44 | BigInt getClientPasswordProof(BigInt& A, BigInt& B, BigInt& K) const; |
| 45 | BigInt getServerPasswordProof(BigInt& A, BigInt& M, BigInt& K) const; |
| 46 | |
| 47 | private: |
| 48 | int init(const char* username, const char* password, BigInt* salt); |
| 49 | BigInt getClientPrivateKey() const; |
| 50 | BigInt getScrambler(BigInt& B) const; |
| 51 | BigInt getClientSecret(BigInt& B) const; |
| 52 | BigInt getServerSecret(BigInt& A, BigInt& v); |
| 53 | BigInt hashSecret(BigInt& secret) const; |
| 54 | static BigInt N; // modulus |
| 55 | static BigInt g; // generator |
| 56 | static BigInt I; // H(g) xor H(N) where H() is standard SHA1 |
| 57 | BigInt a; // client session private key |
| 58 | BigInt b; // server session private key |
| 59 | BigInt s; // salt |
| 60 | BigInt *B; // server public key cache |
| 61 | char* username; |
| 62 | size_t username_length; |
| 63 | char* password; |
| 64 | size_t password_length; |
| 65 | unsigned char raw_salt[32]; |
| 66 | }; |
| 67 | |
| 68 | } |
| 69 | |
| 70 | #endif /* __BNET_SRP3_INCLUDED__ */ |