Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Toggle main menu visibility
Loading...
Searching...
No Matches
SRP6.h
Go to the documentation of this file.
1
#ifndef _SRP6_H
2
#define _SRP6_H
3
4
#include "
AuthDefines.h
"
5
#include "
BigNumber.h
"
6
#include "
Define.h
"
7
#include "
Common.h
"
8
#include "
CryptoHash.h
"
9
#include <array>
10
#include <optional>
11
12
namespace
SkyFire::Crypto
13
{
14
class
SRP6
15
{
16
public
:
17
static
constexpr
size_t
SALT_LENGTH
= 32;
18
using
Salt
= std::array<uint8, SALT_LENGTH>;
19
static
constexpr
size_t
VERIFIER_LENGTH
= 32;
20
using
Verifier
= std::array<uint8, VERIFIER_LENGTH>;
21
static
constexpr
size_t
EPHEMERAL_KEY_LENGTH
= 32;
22
using
EphemeralKey
= std::array<uint8, EPHEMERAL_KEY_LENGTH>;
23
24
static
std::array<uint8, 1>
const
g
;
25
static
std::array<uint8, 32>
const
N
;
26
27
// username + password must be passed through Utf8ToUpperOnlyLatin FIRST!
28
static
std::pair<Salt, Verifier>
MakeRegistrationData
(std::string
const
& username, std::string
const
& password);
29
// username + password must be passed through Utf8ToUpperOnlyLatin FIRST!
30
static
bool
CheckLogin
(std::string
const
& username, std::string
const
& password,
Salt
const
& salt,
Verifier
const
& verifier)
31
{
32
return
(verifier ==
CalculateVerifier
(username, password, salt));
33
}
34
35
static
SHA1::Digest
GetSessionVerifier
(
EphemeralKey
const
& A,
SHA1::Digest
const
& clientM,
SessionKey
const
& K)
36
{
37
return
SHA1::GetDigestOf
(A, clientM, K);
38
}
39
40
SRP6
(std::string
const
& username,
Salt
const
& salt,
Verifier
const
& verifier);
41
std::optional<SessionKey>
VerifyChallengeResponse
(
EphemeralKey
const
& A,
SHA1::Digest
const
& clientM);
42
43
private
:
44
bool
_used
=
false
;
// a single instance can only be used to verify once
45
46
static
Verifier
CalculateVerifier
(std::string
const
& username, std::string
const
& password,
Salt
const
& salt);
47
static
SessionKey
SHA1Interleave
(
EphemeralKey
const
& S);
48
49
/* global algorithm parameters */
50
static
BigNumber
const
_g
;
// a [g]enerator for the ring of integers mod N, algorithm parameter
51
static
BigNumber
const
_N
;
// the modulus, an algorithm parameter; all operations are mod this
52
53
static
EphemeralKey
_B
(
BigNumber
const
& b,
BigNumber
const
& v) {
return
((
_g
.ModExp(b,
_N
) + (v * 3)) %
N
).ToByteArray<
EPHEMERAL_KEY_LENGTH
>(); }
54
55
/* per-instantiation parameters, set on construction */
56
SHA1::Digest
const
_I
;
// H(I) - the username, all uppercase
57
BigNumber
const
_b
;
// b - randomly chosen by the server, 19 bytes, never given out
58
BigNumber
const
_v
;
// v - the user's password verifier, derived from s + H(USERNAME || ":" || PASSWORD)
59
60
public
:
61
Salt
const
s
;
// s - the user's password salt, random, used to calculate v on registration
62
EphemeralKey
const
B
;
// B = 3v + g^b
63
};
64
}
65
66
#endif
AuthDefines.h
SessionKey
std::array< uint8, SESSION_KEY_LENGTH > SessionKey
Definition
AuthDefines.h:8
BigNumber.h
Common.h
CryptoHash.h
Define.h
SRP6
SkyFire::Crypto::SRP6 SRP6
Definition
SRP6.cpp:8
BigNumber
Definition
BigNumber.h:19
SkyFire::Crypto::SRP6::_b
BigNumber const _b
Definition
SRP6.h:57
SkyFire::Crypto::SRP6::Salt
std::array< uint8, SALT_LENGTH > Salt
Definition
SRP6.h:18
SkyFire::Crypto::SRP6::_used
bool _used
Definition
SRP6.h:44
SkyFire::Crypto::SRP6::CalculateVerifier
static Verifier CalculateVerifier(std::string const &username, std::string const &password, Salt const &salt)
Definition
SRP6.cpp:23
SkyFire::Crypto::SRP6::VerifyChallengeResponse
std::optional< SessionKey > VerifyChallengeResponse(EphemeralKey const &A, SHA1::Digest const &clientM)
Definition
SRP6.cpp:67
SkyFire::Crypto::SRP6::CheckLogin
static bool CheckLogin(std::string const &username, std::string const &password, Salt const &salt, Verifier const &verifier)
Definition
SRP6.h:30
SkyFire::Crypto::SRP6::_I
SHA1::Digest const _I
Definition
SRP6.h:56
SkyFire::Crypto::SRP6::SHA1Interleave
static SessionKey SHA1Interleave(EphemeralKey const &S)
Definition
SRP6.cpp:34
SkyFire::Crypto::SRP6::N
static std::array< uint8, 32 > const N
Definition
SRP6.h:25
SkyFire::Crypto::SRP6::_N
static BigNumber const _N
Definition
SRP6.h:51
SkyFire::Crypto::SRP6::EphemeralKey
std::array< uint8, EPHEMERAL_KEY_LENGTH > EphemeralKey
Definition
SRP6.h:22
SkyFire::Crypto::SRP6::SRP6
SRP6(std::string const &username, Salt const &salt, Verifier const &verifier)
Definition
SRP6.cpp:64
SkyFire::Crypto::SRP6::MakeRegistrationData
static std::pair< Salt, Verifier > MakeRegistrationData(std::string const &username, std::string const &password)
Definition
SRP6.cpp:15
SkyFire::Crypto::SRP6::Verifier
std::array< uint8, VERIFIER_LENGTH > Verifier
Definition
SRP6.h:20
SkyFire::Crypto::SRP6::_v
BigNumber const _v
Definition
SRP6.h:58
SkyFire::Crypto::SRP6::g
static std::array< uint8, 1 > const g
Definition
SRP6.h:24
SkyFire::Crypto::SRP6::VERIFIER_LENGTH
static constexpr size_t VERIFIER_LENGTH
Definition
SRP6.h:19
SkyFire::Crypto::SRP6::_B
static EphemeralKey _B(BigNumber const &b, BigNumber const &v)
Definition
SRP6.h:53
SkyFire::Crypto::SRP6::_g
static BigNumber const _g
Definition
SRP6.h:50
SkyFire::Crypto::SRP6::s
Salt const s
Definition
SRP6.h:61
SkyFire::Crypto::SRP6::GetSessionVerifier
static SHA1::Digest GetSessionVerifier(EphemeralKey const &A, SHA1::Digest const &clientM, SessionKey const &K)
Definition
SRP6.h:35
SkyFire::Crypto::SRP6::B
EphemeralKey const B
Definition
SRP6.h:62
SkyFire::Crypto::SRP6::EPHEMERAL_KEY_LENGTH
static constexpr size_t EPHEMERAL_KEY_LENGTH
Definition
SRP6.h:21
SkyFire::Crypto::SRP6::SALT_LENGTH
static constexpr size_t SALT_LENGTH
Definition
SRP6.h:17
SkyFire::Impl::GenericHash< EVP_sha1, Constants::SHA1_DIGEST_LENGTH_BYTES >::Digest
std::array< uint8, DIGEST_LENGTH > Digest
Definition
CryptoHash.h:39
SkyFire::Impl::GenericHash< EVP_sha1, Constants::SHA1_DIGEST_LENGTH_BYTES >::GetDigestOf
static Digest GetDigestOf(uint8 const *data, size_t len)
Definition
CryptoHash.h:41
SkyFire::Crypto
Definition
ARC4.h:15
src
server
shared
Cryptography
Authentication
SRP6.h
Generated on
for Project SkyFire Core by
1.17.0