chore(net): add defines for SRP6_Client status codes

This commit is contained in:
fallenoak 2025-09-25 14:37:11 -07:00
parent 3bd58205bb
commit d39789d624
No known key found for this signature in database
GPG Key ID: 7628F8E61AEA070D
2 changed files with 16 additions and 11 deletions

View File

@ -5,7 +5,7 @@
int32_t SRP6_Client::BeginAuthentication(const char* accountName, const char* password) { int32_t SRP6_Client::BeginAuthentication(const char* accountName, const char* password) {
if (!accountName || !password) { if (!accountName || !password) {
return -1; return SRP6_INVALID;
} }
SHA1_Init(&this->ctx); SHA1_Init(&this->ctx);
@ -22,7 +22,7 @@ int32_t SRP6_Client::BeginAuthentication(const char* accountName, const char* pa
SHA1_Update(&ctx, reinterpret_cast<const uint8_t*>(password), strlen(password)); SHA1_Update(&ctx, reinterpret_cast<const uint8_t*>(password), strlen(password));
SHA1_Final(this->interimDigest, &ctx); SHA1_Final(this->interimDigest, &ctx);
return 0; return SRP6_OK;
} }
int32_t SRP6_Client::CalculateProof(const uint8_t* largeSafePrime, uint32_t largeSafePrimeLen, const uint8_t* generator, uint32_t generatorLen, const uint8_t* salt, uint32_t saltLen, const uint8_t* publicKey, uint32_t publicKeyLen, SRP6_Random& random) { int32_t SRP6_Client::CalculateProof(const uint8_t* largeSafePrime, uint32_t largeSafePrimeLen, const uint8_t* generator, uint32_t generatorLen, const uint8_t* salt, uint32_t saltLen, const uint8_t* publicKey, uint32_t publicKeyLen, SRP6_Random& random) {
@ -39,25 +39,25 @@ int32_t SRP6_Client::CalculateProof(const uint8_t* largeSafePrime, uint32_t larg
auto k = BigIntegerFromInt(0); auto k = BigIntegerFromInt(0);
auto S = BigIntegerFromInt(0); auto S = BigIntegerFromInt(0);
int32_t result = 0; int32_t result = SRP6_OK;
if (!largeSafePrime || largeSafePrimeLen - 1 > 31) { if (!largeSafePrime || largeSafePrimeLen - 1 > 31) {
result = -1; result = SRP6_INVALID;
goto cleanup; goto cleanup;
} }
if (!generator || generatorLen - 1 > 31) { if (!generator || generatorLen - 1 > 31) {
result = -1; result = SRP6_INVALID;
goto cleanup; goto cleanup;
} }
if (!salt || saltLen - 1 > 31) { if (!salt || saltLen - 1 > 31) {
result = -1; result = SRP6_INVALID;
goto cleanup; goto cleanup;
} }
if (!publicKey || publicKeyLen < 31) { if (!publicKey || publicKeyLen < 31) {
result = -1; result = SRP6_INVALID;
goto cleanup; goto cleanup;
} }
@ -150,12 +150,12 @@ int32_t SRP6_Client::CalculateProof(const uint8_t* largeSafePrime, uint32_t larg
SHA1_Update(&this->ctx, this->clientProof, sizeof(this->clientProof)); SHA1_Update(&this->ctx, this->clientProof, sizeof(this->clientProof));
SHA1_Update(&this->ctx, this->sessionKey, sizeof(this->sessionKey)); SHA1_Update(&this->ctx, this->sessionKey, sizeof(this->sessionKey));
result = 0; result = SRP6_OK;
} else { } else {
result = -2; result = SRP6_FAILURE;
} }
} else { } else {
result = -1; result = SRP6_INVALID;
} }
cleanup: cleanup:
@ -177,7 +177,7 @@ cleanup:
int32_t SRP6_Client::VerifyServerProof(const uint8_t* serverProof, uint32_t serverProofLen) { int32_t SRP6_Client::VerifyServerProof(const uint8_t* serverProof, uint32_t serverProofLen) {
if (serverProofLen != 20) { if (serverProofLen != 20) {
return -2; return SRP6_FAILURE;
} }
// Calculate expected server proof // Calculate expected server proof

View File

@ -3,6 +3,11 @@
#include <common/SHA1.hpp> #include <common/SHA1.hpp>
// Invented names
#define SRP6_OK (0)
#define SRP6_INVALID (-1)
#define SRP6_FAILURE (-2)
class SRP6_Random; class SRP6_Random;
class SRP6_Client { class SRP6_Client {