feat(Core/Crypto): add support OpenSSL 3.0 (#13354)

This commit is contained in:
Winfidonarleyan
2022-11-23 21:12:20 +03:00
committed by GitHub
parent 4a2964e10a
commit a1a1528cb4
37 changed files with 1099 additions and 507 deletions
+11 -13
View File
@@ -50,8 +50,8 @@ using SRP6 = Acore::Crypto::SRP6;
/*static*/ SessionKey SRP6::SHA1Interleave(SRP6::EphemeralKey const& S)
{
// split S into two buffers
std::array<uint8, EPHEMERAL_KEY_LENGTH/2> buf0, buf1;
for (size_t i = 0; i < EPHEMERAL_KEY_LENGTH/2; ++i)
std::array<uint8, EPHEMERAL_KEY_LENGTH / 2> buf0{}, buf1{};
for (size_t i = 0; i < EPHEMERAL_KEY_LENGTH / 2; ++i)
{
buf0[i] = S[2 * i + 0];
buf1[i] = S[2 * i + 1];
@@ -59,8 +59,12 @@ using SRP6 = Acore::Crypto::SRP6;
// find position of first nonzero byte
size_t p = 0;
while (p < EPHEMERAL_KEY_LENGTH && !S[p]) { ++p; }
if (p & 1) { ++p; } // skip one extra byte if p is odd
while (p < EPHEMERAL_KEY_LENGTH && !S[p])
++p;
if (p & 1)
++p; // skip one extra byte if p is odd
p /= 2; // offset into buffers
// hash each of the halves, starting at the first nonzero byte
@@ -82,14 +86,12 @@ SRP6::SRP6(std::string const& username, Salt const& salt, Verifier const& verifi
std::optional<SessionKey> SRP6::VerifyChallengeResponse(EphemeralKey const& A, SHA1::Digest const& clientM)
{
ASSERT(!_used);
ASSERT(!_used, "A single SRP6 object must only ever be used to verify ONCE!");
_used = true;
BigNumber const _A(A);
if ((_A % _N).IsZero())
{
return std::nullopt;
}
BigNumber const u(SHA1::GetDigestOf(A, B));
EphemeralKey const S = (_A * (_v.ModExp(u, _N))).ModExp(_b, N).ToByteArray<32>();
@@ -104,11 +106,7 @@ std::optional<SessionKey> SRP6::VerifyChallengeResponse(EphemeralKey const& A, S
SHA1::Digest const ourM = SHA1::GetDigestOf(NgHash, _I, s, A, B, K);
if (ourM == clientM)
{
return K;
}
else
{
return std::nullopt;
}
return std::nullopt;
}