Browse Source

Move pnUtBigNum to pnEncryption/plBigNum.

Darryl Pogue 12 years ago
parent
commit
9479aadb3a
  1. 2
      Sources/Plasma/NucleusLib/pnEncryption/CMakeLists.txt
  2. 57
      Sources/Plasma/NucleusLib/pnEncryption/plBigNum.cpp
  3. 95
      Sources/Plasma/NucleusLib/pnEncryption/plBigNum.h
  4. 1
      Sources/Plasma/NucleusLib/pnEncryption/plChallengeHash.cpp
  5. 18
      Sources/Plasma/NucleusLib/pnNetCli/Intern.h
  6. 1
      Sources/Plasma/NucleusLib/pnNetCli/Pch.h
  7. 12
      Sources/Plasma/NucleusLib/pnNetCli/pnNcChannel.cpp
  8. 8
      Sources/Plasma/NucleusLib/pnNetCli/pnNcCli.cpp
  9. 54
      Sources/Plasma/NucleusLib/pnNetCli/pnNcEncrypt.cpp
  10. 4
      Sources/Plasma/NucleusLib/pnNetCli/pnNetCli.h
  11. 4
      Sources/Plasma/NucleusLib/pnNetDiag/pnNdTcp.cpp
  12. 2
      Sources/Plasma/NucleusLib/pnUtils/CMakeLists.txt
  13. 1
      Sources/Plasma/NucleusLib/pnUtils/pnUtAllIncludes.h
  14. 1
      Sources/Plasma/PubUtilLib/plNetGameLib/Pch.h
  15. 4
      Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp
  16. 4
      Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglCsr.cpp
  17. 4
      Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglGame.cpp
  18. 4
      Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglGateKeeper.cpp

2
Sources/Plasma/NucleusLib/pnEncryption/CMakeLists.txt

@ -3,11 +3,13 @@ include_directories("../../NucleusLib")
include_directories(${OPENSSL_INCLUDE_DIR}) include_directories(${OPENSSL_INCLUDE_DIR})
set(pnEncryption_SOURCES set(pnEncryption_SOURCES
plBigNum.cpp
plChallengeHash.cpp plChallengeHash.cpp
plChecksum.cpp plChecksum.cpp
) )
set(pnEncryption_HEADERS set(pnEncryption_HEADERS
plBigNum.h
plChallengeHash.h plChallengeHash.h
plChecksum.h plChecksum.h
plRandom.h plRandom.h

57
Sources/Plasma/NucleusLib/pnUtils/pnUtBigNum.cpp → Sources/Plasma/NucleusLib/pnEncryption/plBigNum.cpp

@ -39,18 +39,12 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
Mead, WA 99021 Mead, WA 99021
*==LICENSE==*/ *==LICENSE==*/
/*****************************************************************************
*
* $/Plasma20/Sources/Plasma/NucleusLib/pnUtils/Private/pnUtBigNum.cpp
*
***/
#include "pnUtBigNum.h"
#include "plBigNum.h"
#include <openssl/rand.h> #include <openssl/rand.h>
#include <algorithm> #include <algorithm>
static inline void byteswap(size_t size, unsigned char * data) static inline void byteswap(size_t size, uint8_t* data)
{ {
for (size_t i = 0; i < (size / 2); ++i) for (size_t i = 0; i < (size / 2); ++i)
std::swap(data[i], data[size - i - 1]); std::swap(data[i], data[size - i - 1]);
@ -58,32 +52,28 @@ static inline void byteswap(size_t size, unsigned char * data)
/**************************************************************************** /****************************************************************************
* *
* BigNum public methods * plBigNum public methods
* *
***/ ***/
//=========================================================================== plBigNum::plBigNum () : m_context(nil)
BigNum::BigNum () : m_context(nil)
{ {
BN_init(&m_number); BN_init(&m_number);
} }
//=========================================================================== plBigNum::plBigNum(const plBigNum& a) : m_context(nil)
BigNum::BigNum (const BigNum & a) : m_context(nil)
{ {
BN_init(&m_number); BN_init(&m_number);
BN_copy(&m_number, &a.m_number); BN_copy(&m_number, &a.m_number);
} }
//=========================================================================== plBigNum::plBigNum(unsigned a) : m_context(nil)
BigNum::BigNum (unsigned a) : m_context(nil)
{ {
BN_init(&m_number); BN_init(&m_number);
BN_set_word(&m_number, a); BN_set_word(&m_number, a);
} }
//=========================================================================== plBigNum::plBigNum(unsigned bytes, const void* data, bool le) : m_context(nil)
BigNum::BigNum (unsigned bytes, const void * data, bool le) : m_context(nil)
{ {
BN_init(&m_number); BN_init(&m_number);
if (le) if (le)
@ -92,16 +82,15 @@ BigNum::BigNum (unsigned bytes, const void * data, bool le) : m_context(nil)
FromData_BE(bytes, data); FromData_BE(bytes, data);
} }
//=========================================================================== plBigNum::~plBigNum ()
BigNum::~BigNum ()
{ {
if (m_context) if (m_context)
BN_CTX_free(m_context); BN_CTX_free(m_context);
BN_free(&m_number); BN_free(&m_number);
} }
//=========================================================================== int plBigNum::Compare(uint32_t a) const
int BigNum::Compare (uint32_t a) const { {
// -1 if (this < a) // -1 if (this < a)
// 0 if (this == a) // 0 if (this == a)
// 1 if (this > a) // 1 if (this > a)
@ -118,43 +107,39 @@ int BigNum::Compare (uint32_t a) const {
return 1; return 1;
} }
//=========================================================================== void plBigNum::FromData_LE(uint32_t bytes, const void* data)
void BigNum::FromData_LE (unsigned bytes, const void * data)
{ {
unsigned char * buffer = new unsigned char[bytes]; uint8_t* buffer = new uint8_t[bytes];
memcpy(buffer, data, bytes); memcpy(buffer, data, bytes);
byteswap(bytes, buffer); byteswap(bytes, buffer);
BN_bin2bn(buffer, bytes, &m_number); BN_bin2bn(buffer, bytes, &m_number);
delete [] buffer; delete[] buffer;
} }
//=========================================================================== uint8_t* plBigNum::GetData_BE(uint32_t* bytes) const
unsigned char * BigNum::GetData_BE (unsigned * bytes) const
{ {
*bytes = BN_num_bytes(&m_number); *bytes = BN_num_bytes(&m_number);
unsigned char * data = new unsigned char[*bytes]; uint8_t* data = new uint8_t[*bytes];
BN_bn2bin(&m_number, data); BN_bn2bin(&m_number, data);
return data; return data;
} }
//=========================================================================== uint8_t* plBigNum::GetData_LE(uint32_t* bytes) const
unsigned char * BigNum::GetData_LE (unsigned * bytes) const
{ {
*bytes = BN_num_bytes(&m_number); *bytes = BN_num_bytes(&m_number);
unsigned char * data = new unsigned char[*bytes]; uint8_t* data = new uint8_t[*bytes];
BN_bn2bin(&m_number, data); BN_bn2bin(&m_number, data);
byteswap(*bytes, data); byteswap(*bytes, data);
return data; return data;
} }
//=========================================================================== void plBigNum::Rand(uint32_t bits, plBigNum* seed)
void BigNum::Rand (unsigned bits, BigNum * seed)
{ {
// this = random number with bits or fewer bits // this = random number with bits or fewer bits
unsigned seedbytes; uint32_t seedbytes;
unsigned char * seedData = seed->GetData_BE(&seedbytes); uint8_t* seedData = seed->GetData_BE(&seedbytes);
RAND_seed(seedData, seedbytes); RAND_seed(seedData, seedbytes);
BN_rand(&m_number, bits, 0, 0); BN_rand(&m_number, bits, 0, 0);
delete [] seedData; delete[] seedData;
} }

95
Sources/Plasma/NucleusLib/pnUtils/pnUtBigNum.h → Sources/Plasma/NucleusLib/pnEncryption/plBigNum.h

@ -39,31 +39,26 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
Mead, WA 99021 Mead, WA 99021
*==LICENSE==*/ *==LICENSE==*/
/*****************************************************************************
*
* $/Plasma20/Sources/Plasma/NucleusLib/pnUtils/Private/pnUtBigNum.h
*
***/
#ifndef PLASMA20_SOURCES_PLASMA_NUCLEUSLIB_PNUTILS_PRIVATE_PNUTBIGNUM_H #ifndef plBigNum_inc
#define PLASMA20_SOURCES_PLASMA_NUCLEUSLIB_PNUTILS_PRIVATE_PNUTBIGNUM_H #define plBigNum_inc
#include "Pch.h"
/***************************************************************************** /*****************************************************************************
* *
* BigNum class * plBigNum class
* *
***/ ***/
#include "HeadSpin.h"
#include <openssl/bn.h> #include <openssl/bn.h>
class BigNum { class plBigNum
{
private: private:
BIGNUM m_number; BIGNUM m_number;
mutable BN_CTX * m_context; mutable BN_CTX* m_context;
BN_CTX * GetContext () const BN_CTX* GetContext() const
{ {
if (!m_context) if (!m_context)
m_context = BN_CTX_new(); m_context = BN_CTX_new();
@ -71,13 +66,13 @@ private:
} }
public: public:
BigNum (); plBigNum();
BigNum (const BigNum & a); plBigNum(const plBigNum& a);
BigNum (unsigned a); plBigNum(uint32_t a);
BigNum (unsigned bytess, const void * data, bool le=false); plBigNum(uint32_t bytess, const void* data, bool le=false);
~BigNum (); ~plBigNum();
BigNum & operator= (const BigNum & a) plBigNum& operator=(const plBigNum& a)
{ {
BN_copy(&m_number, &a.m_number); BN_copy(&m_number, &a.m_number);
return *this; return *this;
@ -86,37 +81,39 @@ public:
// Constant parameters need not be distinct from the destination or from // Constant parameters need not be distinct from the destination or from
// each other // each other
void Add (const BigNum & a, uint32_t b) void Add(const plBigNum& a, uint32_t b)
{ {
// this = a + b // this = a + b
BN_copy(&m_number, &a.m_number); BN_copy(&m_number, &a.m_number);
BN_add_word(&m_number, b); BN_add_word(&m_number, b);
} }
void Add (const BigNum & a, const BigNum & b) void Add(const plBigNum& a, const plBigNum& b)
{ {
// this = a + b // this = a + b
BN_add(&m_number, &a.m_number, &b.m_number); BN_add(&m_number, &a.m_number, &b.m_number);
} }
int Compare (uint32_t a) const; int Compare(uint32_t a) const;
int Compare (const BigNum & a) const
int Compare(const plBigNum& a) const
{ {
return BN_cmp(&m_number, &a.m_number); return BN_cmp(&m_number, &a.m_number);
} }
bool isZero() const bool isZero() const
{ {
return BN_is_zero(&m_number); return BN_is_zero(&m_number);
} }
void Div (const BigNum & a, uint32_t b, uint32_t * remainder) void Div(const plBigNum& a, uint32_t b, uint32_t* remainder)
{ {
// this = a / b, remainder = a % b // this = a / b, remainder = a % b
BN_copy(&m_number, &a.m_number); BN_copy(&m_number, &a.m_number);
*remainder = (uint32_t)BN_div_word(&m_number, b); *remainder = (uint32_t)BN_div_word(&m_number, b);
} }
void Div (const BigNum & a, const BigNum & b, BigNum * remainder) void Div(const plBigNum& a, const plBigNum& b, plBigNum* remainder)
{ {
// this = a / b, remainder = a % b // this = a / b, remainder = a % b
// either this or remainder may be nil // either this or remainder may be nil
@ -124,55 +121,55 @@ public:
&a.m_number, &b.m_number, GetContext()); &a.m_number, &b.m_number, GetContext());
} }
void FromData_BE (unsigned bytess, const void * data) void FromData_BE(uint32_t bytess, const void* data)
{ {
BN_bin2bn((const unsigned char *)data, bytess, &m_number); BN_bin2bn((const uint8_t*)data, bytess, &m_number);
} }
void FromData_LE (unsigned bytess, const void * data); void FromData_LE(uint32_t bytess, const void* data);
unsigned char * GetData_BE (unsigned * bytess) const; uint8_t* GetData_BE(uint32_t* bytess) const;
unsigned char * GetData_LE (unsigned * bytess) const; uint8_t* GetData_LE(uint32_t* bytess) const;
bool IsPrime () const bool IsPrime() const
{ {
// Cyan's code uses 3 checks, so we'll follow suit. // Cyan's code uses 3 checks, so we'll follow suit.
// This provides an accurate answer to p < 0.015625 // This provides an accurate answer to p < 0.015625
return BN_is_prime_fasttest(&m_number, 3, nil, GetContext(), nil, 1) > 0; return BN_is_prime_fasttest(&m_number, 3, nil, GetContext(), nil, 1) > 0;
} }
void Mod (const BigNum & a, const BigNum & b) void Mod(const plBigNum& a, const plBigNum& b)
{ {
// this = a % b // this = a % b
BN_div(nil, &m_number, &a.m_number, &b.m_number, GetContext()); BN_div(nil, &m_number, &a.m_number, &b.m_number, GetContext());
} }
void Mul (const BigNum & a, uint32_t b) void Mul(const plBigNum& a, uint32_t b)
{ {
// this = a * b // this = a * b
BN_copy(&m_number, &a.m_number); BN_copy(&m_number, &a.m_number);
BN_mul_word(&m_number, b); BN_mul_word(&m_number, b);
} }
void Mul (const BigNum & a, const BigNum & b) void Mul(const plBigNum& a, const plBigNum& b)
{ {
// this = a * b // this = a * b
BN_mul(&m_number, &a.m_number, &b.m_number, GetContext()); BN_mul(&m_number, &a.m_number, &b.m_number, GetContext());
} }
void PowMod (uint32_t a, const BigNum & b, const BigNum & c) void PowMod(uint32_t a, const plBigNum& b, const plBigNum& c)
{ {
// this = a ^ b % c // this = a ^ b % c
PowMod(BigNum(a), b, c); PowMod(plBigNum(a), b, c);
} }
void PowMod (const BigNum & a, const BigNum & b, const BigNum & c) void PowMod(const plBigNum& a, const plBigNum& b, const plBigNum& c)
{ {
// this = a ^ b % c // this = a ^ b % c
BN_mod_exp(&m_number, &a.m_number, &b.m_number, &c.m_number, GetContext()); BN_mod_exp(&m_number, &a.m_number, &b.m_number, &c.m_number, GetContext());
} }
void Rand (const BigNum & a, BigNum * seed) void Rand(const plBigNum& a, plBigNum* seed)
{ {
// this = random number less than a // this = random number less than a
int bits = BN_num_bits(&a.m_number); int bits = BN_num_bits(&a.m_number);
@ -181,49 +178,49 @@ public:
while (Compare(a) >= 0); while (Compare(a) >= 0);
} }
void Rand (unsigned bits, BigNum * seed); void Rand(uint32_t bits, plBigNum* seed);
void RandPrime (unsigned bits, BigNum * seed) void RandPrime(uint32_t bits, plBigNum* seed)
{ {
BN_generate_prime(&m_number, bits, 1, nil, nil, nil, nil); BN_generate_prime(&m_number, bits, 1, nil, nil, nil, nil);
} }
void Set (const BigNum & a) void Set(const plBigNum& a)
{ {
BN_copy(&m_number, &a.m_number); BN_copy(&m_number, &a.m_number);
} }
void Set (unsigned a) void Set(uint32_t a)
{ {
BN_set_word(&m_number, a); BN_set_word(&m_number, a);
} }
void SetOne () { Set(1); } void SetOne() { Set(1); }
void SetZero () { Set(0); } void SetZero() { Set(0); }
void Shl (const BigNum & a, unsigned b) void Shl(const plBigNum& a, uint32_t b)
{ {
// this = a << b // this = a << b
BN_lshift(&m_number, &a.m_number, b); BN_lshift(&m_number, &a.m_number, b);
} }
void Shr (const BigNum & a, unsigned b) void Shr(const plBigNum& a, uint32_t b)
{ {
// this = a >> b // this = a >> b
BN_rshift(&m_number, &a.m_number, b); BN_rshift(&m_number, &a.m_number, b);
} }
void Sub (const BigNum & a, uint32_t b) void Sub(const plBigNum& a, uint32_t b)
{ {
// this = a - b // this = a - b
BN_copy(&m_number, &a.m_number); BN_copy(&m_number, &a.m_number);
BN_sub_word(&m_number, b); BN_sub_word(&m_number, b);
} }
void Sub (const BigNum & a, const BigNum & b) void Sub(const plBigNum& a, const plBigNum& b)
{ {
// this = a - b // this = a - b
BN_sub(&m_number, &a.m_number, &b.m_number); BN_sub(&m_number, &a.m_number, &b.m_number);
} }
}; };
#endif #endif // plBigNum_inc

1
Sources/Plasma/NucleusLib/pnEncryption/plChallengeHash.cpp

@ -41,7 +41,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
*==LICENSE==*/ *==LICENSE==*/
#include "plChallengeHash.h" #include "plChallengeHash.h"
#include "pnUtils/pnUtils.h"
ShaDigest fSeed; ShaDigest fSeed;

18
Sources/Plasma/NucleusLib/pnNetCli/Intern.h

@ -80,8 +80,8 @@ const NetMsgInitSend * NetMsgChannelFindSendMessage (
void NetMsgChannelGetDhConstants ( void NetMsgChannelGetDhConstants (
const NetMsgChannel * channel, const NetMsgChannel * channel,
unsigned * dh_g, unsigned * dh_g,
const BigNum ** dh_xa, // client: dh_x server: dh_a const plBigNum** dh_xa, // client: dh_x server: dh_a
const BigNum ** dh_n const plBigNum** dh_n
); );
@ -92,18 +92,18 @@ void NetMsgChannelGetDhConstants (
***/ ***/
void NetMsgCryptClientStart ( void NetMsgCryptClientStart (
NetMsgChannel * channel, NetMsgChannel* channel,
unsigned seedBytes, unsigned seedBytes,
const uint8_t seedData[], const uint8_t seedData[],
BigNum * clientSeed, plBigNum* clientSeed,
BigNum * serverSeed plBigNum* serverSeed
); );
void NetMsgCryptServerConnect ( void NetMsgCryptServerConnect (
NetMsgChannel * channel, NetMsgChannel* channel,
unsigned seedBytes, unsigned seedBytes,
const uint8_t seedData[], const uint8_t seedData[],
BigNum * clientSeed plBigNum* clientSeed
); );

1
Sources/Plasma/NucleusLib/pnNetCli/Pch.h

@ -54,6 +54,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "pnUtils/pnUtils.h" #include "pnUtils/pnUtils.h"
#include "pnNetBase/pnNetBase.h" #include "pnNetBase/pnNetBase.h"
#include "pnAsyncCore/pnAsyncCore.h" #include "pnAsyncCore/pnAsyncCore.h"
#include "pnEncryption/plBigNum.h"
#include "pnNetCli.h" #include "pnNetCli.h"
#include "Intern.h" #include "Intern.h"

12
Sources/Plasma/NucleusLib/pnNetCli/pnNcChannel.cpp

@ -83,8 +83,8 @@ struct NetMsgChannel : AtomicRef {
// Diffie-Hellman constants // Diffie-Hellman constants
uint32_t m_dh_g; uint32_t m_dh_g;
BigNum m_dh_xa; // client: dh_x server: dh_a plBigNum m_dh_xa; // client: dh_x server: dh_a
BigNum m_dh_n; plBigNum m_dh_n;
}; };
static ChannelCrit s_channelCrit; static ChannelCrit s_channelCrit;
@ -355,8 +355,8 @@ const NetMsgInitSend * NetMsgChannelFindSendMessage (
void NetMsgChannelGetDhConstants ( void NetMsgChannelGetDhConstants (
const NetMsgChannel * channel, const NetMsgChannel * channel,
uint32_t * dh_g, uint32_t * dh_g,
const BigNum ** dh_xa, const plBigNum** dh_xa,
const BigNum ** dh_n const plBigNum** dh_n
) { ) {
if (dh_g) *dh_g = channel->m_dh_g; if (dh_g) *dh_g = channel->m_dh_g;
if (dh_xa) *dh_xa = &channel->m_dh_xa; if (dh_xa) *dh_xa = &channel->m_dh_xa;
@ -382,8 +382,8 @@ void NetMsgProtocolRegister (
const NetMsgInitRecv recvMsgs[], const NetMsgInitRecv recvMsgs[],
uint32_t recvMsgCount, uint32_t recvMsgCount,
uint32_t dh_g, uint32_t dh_g,
const BigNum & dh_xa, // client: dh_x server: dh_a const plBigNum& dh_xa, // client: dh_x server: dh_a
const BigNum & dh_n const plBigNum& dh_n
) { ) {
s_channelCrit.EnterSafe(); s_channelCrit.EnterSafe();
{ {

8
Sources/Plasma/NucleusLib/pnNetCli/pnNcCli.cpp

@ -652,8 +652,8 @@ static void CreateSymmetricKey (
static void ClientConnect (NetCli * cli) { static void ClientConnect (NetCli * cli) {
// Initiate diffie-hellman for client // Initiate diffie-hellman for client
BigNum clientSeed; plBigNum clientSeed;
BigNum serverSeed; plBigNum serverSeed;
NetMsgCryptClientStart( NetMsgCryptClientStart(
cli->channel, cli->channel,
sizeof(cli->seed), sizeof(cli->seed),
@ -717,7 +717,7 @@ static bool ServerRecvConnect (
else { else {
// Compute client seed // Compute client seed
uint8_t clientSeed[kNetMaxSymmetricSeedBytes]; uint8_t clientSeed[kNetMaxSymmetricSeedBytes];
BigNum clientSeedValue; plBigNum clientSeedValue;
{ {
NetMsgCryptServerConnect( NetMsgCryptServerConnect(
cli->channel, cli->channel,
@ -761,7 +761,7 @@ static bool ClientRecvEncrypt (
return false; return false;
// find out if we want encryption // find out if we want encryption
const BigNum * DH_N; const plBigNum* DH_N;
NetMsgChannelGetDhConstants(cli->channel, nil, nil, &DH_N); NetMsgChannelGetDhConstants(cli->channel, nil, nil, &DH_N);
bool encrypt = !DH_N->isZero(); bool encrypt = !DH_N->isZero();

54
Sources/Plasma/NucleusLib/pnNetCli/pnNcEncrypt.cpp

@ -58,23 +58,23 @@ namespace pnNetCli {
// g and n are pregenerated and published // g and n are pregenerated and published
// (built into both client and server software) // (built into both client and server software)
BigNum g(4); plBigNum g(4);
BigNum n; n.RandPrime(kKeyBits, &seed); plBigNum n; n.RandPrime(kKeyBits, &seed);
// a and x are pregenerated; a is built into server software, and x is // a and x are pregenerated; a is built into server software, and x is
// built into client software // built into client software
BigNum a; a.Rand(kKeyBits, &seed); plBigNum a; a.Rand(kKeyBits, &seed);
BigNum x; x.PowMod(g, a, n); plBigNum x; x.PowMod(g, a, n);
// client chooses b and y on connect, and sends y to the server // client chooses b and y on connect, and sends y to the server
BigNum b; b.Rand(kKeyBits, &seed); plBigNum b; b.Rand(kKeyBits, &seed);
BigNum y; y.PowMod(g, b, n); plBigNum y; y.PowMod(g, b, n);
// server computes key: k = y^a mod n // server computes key: k = y^a mod n
BigNum ka; ka.PowMod(y, a, n); plBigNum ka; ka.PowMod(y, a, n);
// client computes key: k = x^b mod n // client computes key: k = x^b mod n
BigNum kb; kb.PowMod(x, b, n); plBigNum kb; kb.PowMod(x, b, n);
***/ ***/
@ -90,14 +90,14 @@ COMPILER_ASSERT(IS_POW2(kNetDiffieHellmanKeyBits));
//============================================================================ //============================================================================
// TODO: Cache computed keys // TODO: Cache computed keys
static void GetCachedServerKey ( static void GetCachedServerKey (
NetMsgChannel * channel, NetMsgChannel* channel,
BigNum * ka, plBigNum* ka,
const BigNum & dh_y const plBigNum& dh_y
) { ) {
// Get diffie-hellman constants // Get diffie-hellman constants
unsigned DH_G; unsigned DH_G;
const BigNum * DH_A; const plBigNum* DH_A;
const BigNum * DH_N; const plBigNum* DH_N;
NetMsgChannelGetDhConstants(channel, &DH_G, &DH_A, &DH_N); NetMsgChannelGetDhConstants(channel, &DH_G, &DH_A, &DH_N);
hsAssert(!DH_N->isZero(), "DH_N must not be zero in encrypted mode"); hsAssert(!DH_N->isZero(), "DH_N must not be zero in encrypted mode");
@ -114,15 +114,15 @@ static void GetCachedServerKey (
//============================================================================ //============================================================================
void NetMsgCryptClientStart ( void NetMsgCryptClientStart (
NetMsgChannel * channel, NetMsgChannel* channel,
unsigned seedBytes, unsigned seedBytes,
const uint8_t seedData[], const uint8_t seedData[],
BigNum * clientSeed, plBigNum* clientSeed,
BigNum * serverSeed plBigNum* serverSeed
) { ) {
unsigned DH_G; unsigned DH_G;
const BigNum * DH_X; const plBigNum* DH_X;
const BigNum * DH_N; const plBigNum* DH_N;
NetMsgChannelGetDhConstants(channel, &DH_G, &DH_X, &DH_N); NetMsgChannelGetDhConstants(channel, &DH_G, &DH_X, &DH_N);
if (DH_N->isZero()) { // no actual encryption, but the caller expects a seed if (DH_N->isZero()) { // no actual encryption, but the caller expects a seed
clientSeed->SetZero(); clientSeed->SetZero();
@ -130,9 +130,9 @@ void NetMsgCryptClientStart (
} }
else { else {
// Client chooses b and y on connect // Client chooses b and y on connect
BigNum g(DH_G); plBigNum g(DH_G);
BigNum seed(seedBytes, seedData); plBigNum seed(seedBytes, seedData);
BigNum b; b.Rand(kNetDiffieHellmanKeyBits, &seed); plBigNum b; b.Rand(kNetDiffieHellmanKeyBits, &seed);
// Client computes key: kb = x^b mod n // Client computes key: kb = x^b mod n
clientSeed->PowMod(*DH_X, b, *DH_N); clientSeed->PowMod(*DH_X, b, *DH_N);
@ -144,13 +144,13 @@ void NetMsgCryptClientStart (
//============================================================================ //============================================================================
void NetMsgCryptServerConnect ( void NetMsgCryptServerConnect (
NetMsgChannel * channel, NetMsgChannel* channel,
unsigned seedBytes, unsigned seedBytes,
const uint8_t seedData[], const uint8_t seedData[],
BigNum * clientSeed plBigNum* clientSeed
) { ) {
// Server computes client key: ka = y^a mod n // Server computes client key: ka = y^a mod n
const BigNum dh_y(seedBytes, seedData); const plBigNum dh_y(seedBytes, seedData);
GetCachedServerKey(channel, clientSeed, dh_y); GetCachedServerKey(channel, clientSeed, dh_y);
} }

4
Sources/Plasma/NucleusLib/pnNetCli/pnNetCli.h

@ -326,8 +326,8 @@ void NetMsgProtocolRegister (
uint32_t recvMsgCount, uint32_t recvMsgCount,
// Diffie-Hellman keys // Diffie-Hellman keys
uint32_t dh_g, uint32_t dh_g,
const BigNum & dh_xa, // client: dh_x server: dh_a const plBigNum& dh_xa, // client: dh_x server: dh_a
const BigNum & dh_n const plBigNum& dh_n
); );
void NetMsgProtocolDestroy ( void NetMsgProtocolDestroy (

4
Sources/Plasma/NucleusLib/pnNetDiag/pnNdTcp.cpp

@ -616,8 +616,8 @@ static void StartAuthTcpTest (
s_send, arrsize(s_send), s_send, arrsize(s_send),
s_recv, arrsize(s_recv), s_recv, arrsize(s_recv),
kAuthDhGValue, kAuthDhGValue,
BigNum(sizeof(kAuthDhXData), kAuthDhXData), plBigNum(sizeof(kAuthDhXData), kAuthDhXData),
BigNum(sizeof(kAuthDhNData), kAuthDhNData) plBigNum(sizeof(kAuthDhNData), kAuthDhNData)
); );
} }

2
Sources/Plasma/NucleusLib/pnUtils/CMakeLists.txt

@ -8,7 +8,6 @@ set(pnUtils_HEADERS
pnUtAddr.h pnUtAddr.h
pnUtAllIncludes.h pnUtAllIncludes.h
pnUtArray.h pnUtArray.h
pnUtBigNum.h
pnUtCmd.h pnUtCmd.h
pnUtCrypt.h pnUtCrypt.h
pnUtHash.h pnUtHash.h
@ -27,7 +26,6 @@ set(pnUtils_HEADERS
set(pnUtils_SOURCES set(pnUtils_SOURCES
pnUtArray.cpp pnUtArray.cpp
pnUtBigNum.cpp
pnUtCmd.cpp pnUtCmd.cpp
pnUtCrypt.cpp pnUtCrypt.cpp
pnUtHash.cpp pnUtHash.cpp

1
Sources/Plasma/NucleusLib/pnUtils/pnUtAllIncludes.h

@ -63,7 +63,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "pnUtStr.h" #include "pnUtStr.h"
#include "pnUtRef.h" #include "pnUtRef.h"
#include "pnUtPath.h" #include "pnUtPath.h"
#include "pnUtBigNum.h"
#include "pnUtCmd.h" #include "pnUtCmd.h"
#include "pnUtMisc.h" #include "pnUtMisc.h"
#include "pnUtCrypt.h" #include "pnUtCrypt.h"

1
Sources/Plasma/PubUtilLib/plNetGameLib/Pch.h

@ -51,6 +51,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#define PLASMA20_SOURCES_PLASMA_PUBUTILLIB_PLNETGAMELIB_PCH_H #define PLASMA20_SOURCES_PLASMA_PUBUTILLIB_PLNETGAMELIB_PCH_H
#include "pnUtils/pnUtils.h" #include "pnUtils/pnUtils.h"
#include "pnEncryption/plBigNum.h"
#include "pnNetBase/pnNetBase.h" #include "pnNetBase/pnNetBase.h"
#include "pnAsyncCore/pnAsyncCore.h" #include "pnAsyncCore/pnAsyncCore.h"
#include "pnNetCli/pnNetCli.h" #include "pnNetCli/pnNetCli.h"

4
Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp

@ -5032,8 +5032,8 @@ void AuthInitialize () {
s_send, arrsize(s_send), s_send, arrsize(s_send),
s_recv, arrsize(s_recv), s_recv, arrsize(s_recv),
kAuthDhGValue, kAuthDhGValue,
BigNum(sizeof(kAuthDhXData), kAuthDhXData), plBigNum(sizeof(kAuthDhXData), kAuthDhXData),
BigNum(sizeof(kAuthDhNData), kAuthDhNData) plBigNum(sizeof(kAuthDhNData), kAuthDhNData)
); );
} }

4
Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglCsr.cpp

@ -758,8 +758,8 @@ void CsrInitialize () {
s_send, arrsize(s_send), s_send, arrsize(s_send),
s_recv, arrsize(s_recv), s_recv, arrsize(s_recv),
kCsrDhGValue, kCsrDhGValue,
BigNum(sizeof(kCsrDhXData), kCsrDhXData), plBigNum(sizeof(kCsrDhXData), kCsrDhXData),
BigNum(sizeof(kCsrDhNData), kCsrDhNData) plBigNum(sizeof(kCsrDhNData), kCsrDhNData)
); );
} }

4
Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglGame.cpp

@ -711,8 +711,8 @@ void GameInitialize () {
s_send, arrsize(s_send), s_send, arrsize(s_send),
s_recv, arrsize(s_recv), s_recv, arrsize(s_recv),
kGameDhGValue, kGameDhGValue,
BigNum(sizeof(kGameDhXData), kGameDhXData), plBigNum(sizeof(kGameDhXData), kGameDhXData),
BigNum(sizeof(kGameDhNData), kGameDhNData) plBigNum(sizeof(kGameDhNData), kGameDhNData)
); );
} }

4
Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglGateKeeper.cpp

@ -984,8 +984,8 @@ void GateKeeperInitialize () {
s_send, arrsize(s_send), s_send, arrsize(s_send),
s_recv, arrsize(s_recv), s_recv, arrsize(s_recv),
kGateKeeperDhGValue, kGateKeeperDhGValue,
BigNum(sizeof(kGateKeeperDhXData), kGateKeeperDhXData), plBigNum(sizeof(kGateKeeperDhXData), kGateKeeperDhXData),
BigNum(sizeof(kGateKeeperDhNData), kGateKeeperDhNData) plBigNum(sizeof(kGateKeeperDhNData), kGateKeeperDhNData)
); );
} }

Loading…
Cancel
Save