mirror of
https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git
synced 2025-07-14 02:27:40 -04:00
Move pnUtBigNum to pnEncryption/plBigNum.
This commit is contained in:
@ -3,11 +3,13 @@ include_directories("../../NucleusLib")
|
||||
include_directories(${OPENSSL_INCLUDE_DIR})
|
||||
|
||||
set(pnEncryption_SOURCES
|
||||
plBigNum.cpp
|
||||
plChallengeHash.cpp
|
||||
plChecksum.cpp
|
||||
)
|
||||
|
||||
set(pnEncryption_HEADERS
|
||||
plBigNum.h
|
||||
plChallengeHash.h
|
||||
plChecksum.h
|
||||
plRandom.h
|
||||
|
@ -39,18 +39,12 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
|
||||
Mead, WA 99021
|
||||
|
||||
*==LICENSE==*/
|
||||
/*****************************************************************************
|
||||
*
|
||||
* $/Plasma20/Sources/Plasma/NucleusLib/pnUtils/Private/pnUtBigNum.cpp
|
||||
*
|
||||
***/
|
||||
|
||||
#include "pnUtBigNum.h"
|
||||
|
||||
#include "plBigNum.h"
|
||||
#include <openssl/rand.h>
|
||||
#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)
|
||||
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
|
||||
*
|
||||
***/
|
||||
|
||||
//===========================================================================
|
||||
BigNum::BigNum () : m_context(nil)
|
||||
plBigNum::plBigNum () : m_context(nil)
|
||||
{
|
||||
BN_init(&m_number);
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
BigNum::BigNum (const BigNum & a) : m_context(nil)
|
||||
plBigNum::plBigNum(const plBigNum& a) : m_context(nil)
|
||||
{
|
||||
BN_init(&m_number);
|
||||
BN_copy(&m_number, &a.m_number);
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
BigNum::BigNum (unsigned a) : m_context(nil)
|
||||
plBigNum::plBigNum(unsigned a) : m_context(nil)
|
||||
{
|
||||
BN_init(&m_number);
|
||||
BN_set_word(&m_number, a);
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
BigNum::BigNum (unsigned bytes, const void * data, bool le) : m_context(nil)
|
||||
plBigNum::plBigNum(unsigned bytes, const void* data, bool le) : m_context(nil)
|
||||
{
|
||||
BN_init(&m_number);
|
||||
if (le)
|
||||
@ -92,16 +82,15 @@ BigNum::BigNum (unsigned bytes, const void * data, bool le) : m_context(nil)
|
||||
FromData_BE(bytes, data);
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
BigNum::~BigNum ()
|
||||
plBigNum::~plBigNum ()
|
||||
{
|
||||
if (m_context)
|
||||
BN_CTX_free(m_context);
|
||||
BN_free(&m_number);
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
int BigNum::Compare (uint32_t a) const {
|
||||
int plBigNum::Compare(uint32_t a) const
|
||||
{
|
||||
// -1 if (this < a)
|
||||
// 0 if (this == a)
|
||||
// 1 if (this > a)
|
||||
@ -118,43 +107,39 @@ int BigNum::Compare (uint32_t a) const {
|
||||
return 1;
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
void BigNum::FromData_LE (unsigned bytes, const void * data)
|
||||
void plBigNum::FromData_LE(uint32_t bytes, const void* data)
|
||||
{
|
||||
unsigned char * buffer = new unsigned char[bytes];
|
||||
uint8_t* buffer = new uint8_t[bytes];
|
||||
memcpy(buffer, data, bytes);
|
||||
byteswap(bytes, buffer);
|
||||
BN_bin2bn(buffer, bytes, &m_number);
|
||||
delete [] buffer;
|
||||
delete[] buffer;
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
unsigned char * BigNum::GetData_BE (unsigned * bytes) const
|
||||
uint8_t* plBigNum::GetData_BE(uint32_t* bytes) const
|
||||
{
|
||||
*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);
|
||||
return data;
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
unsigned char * BigNum::GetData_LE (unsigned * bytes) const
|
||||
uint8_t* plBigNum::GetData_LE(uint32_t* bytes) const
|
||||
{
|
||||
*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);
|
||||
byteswap(*bytes, data);
|
||||
return data;
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
void BigNum::Rand (unsigned bits, BigNum * seed)
|
||||
void plBigNum::Rand(uint32_t bits, plBigNum* seed)
|
||||
{
|
||||
// this = random number with bits or fewer bits
|
||||
|
||||
unsigned seedbytes;
|
||||
unsigned char * seedData = seed->GetData_BE(&seedbytes);
|
||||
uint32_t seedbytes;
|
||||
uint8_t* seedData = seed->GetData_BE(&seedbytes);
|
||||
RAND_seed(seedData, seedbytes);
|
||||
BN_rand(&m_number, bits, 0, 0);
|
||||
delete [] seedData;
|
||||
delete[] seedData;
|
||||
}
|
@ -39,31 +39,26 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
|
||||
Mead, WA 99021
|
||||
|
||||
*==LICENSE==*/
|
||||
/*****************************************************************************
|
||||
*
|
||||
* $/Plasma20/Sources/Plasma/NucleusLib/pnUtils/Private/pnUtBigNum.h
|
||||
*
|
||||
***/
|
||||
|
||||
#ifndef PLASMA20_SOURCES_PLASMA_NUCLEUSLIB_PNUTILS_PRIVATE_PNUTBIGNUM_H
|
||||
#define PLASMA20_SOURCES_PLASMA_NUCLEUSLIB_PNUTILS_PRIVATE_PNUTBIGNUM_H
|
||||
|
||||
#include "Pch.h"
|
||||
#ifndef plBigNum_inc
|
||||
#define plBigNum_inc
|
||||
|
||||
/*****************************************************************************
|
||||
*
|
||||
* BigNum class
|
||||
* plBigNum class
|
||||
*
|
||||
***/
|
||||
|
||||
#include "HeadSpin.h"
|
||||
#include <openssl/bn.h>
|
||||
|
||||
class BigNum {
|
||||
class plBigNum
|
||||
{
|
||||
private:
|
||||
BIGNUM m_number;
|
||||
mutable BN_CTX * m_context;
|
||||
mutable BN_CTX* m_context;
|
||||
|
||||
BN_CTX * GetContext () const
|
||||
BN_CTX* GetContext() const
|
||||
{
|
||||
if (!m_context)
|
||||
m_context = BN_CTX_new();
|
||||
@ -71,13 +66,13 @@ private:
|
||||
}
|
||||
|
||||
public:
|
||||
BigNum ();
|
||||
BigNum (const BigNum & a);
|
||||
BigNum (unsigned a);
|
||||
BigNum (unsigned bytess, const void * data, bool le=false);
|
||||
~BigNum ();
|
||||
plBigNum();
|
||||
plBigNum(const plBigNum& a);
|
||||
plBigNum(uint32_t a);
|
||||
plBigNum(uint32_t bytess, const void* data, bool le=false);
|
||||
~plBigNum();
|
||||
|
||||
BigNum & operator= (const BigNum & a)
|
||||
plBigNum& operator=(const plBigNum& a)
|
||||
{
|
||||
BN_copy(&m_number, &a.m_number);
|
||||
return *this;
|
||||
@ -86,37 +81,39 @@ public:
|
||||
// Constant parameters need not be distinct from the destination or from
|
||||
// each other
|
||||
|
||||
void Add (const BigNum & a, uint32_t b)
|
||||
void Add(const plBigNum& a, uint32_t b)
|
||||
{
|
||||
// this = a + b
|
||||
BN_copy(&m_number, &a.m_number);
|
||||
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
|
||||
BN_add(&m_number, &a.m_number, &b.m_number);
|
||||
}
|
||||
|
||||
int Compare (uint32_t a) const;
|
||||
int Compare (const BigNum & a) const
|
||||
int Compare(uint32_t a) const;
|
||||
|
||||
int Compare(const plBigNum& a) const
|
||||
{
|
||||
return BN_cmp(&m_number, &a.m_number);
|
||||
}
|
||||
|
||||
bool isZero() const
|
||||
{
|
||||
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
|
||||
BN_copy(&m_number, &a.m_number);
|
||||
*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
|
||||
// either this or remainder may be nil
|
||||
@ -124,55 +121,55 @@ public:
|
||||
&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;
|
||||
unsigned char * GetData_LE (unsigned * bytess) const;
|
||||
uint8_t* GetData_BE(uint32_t* 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.
|
||||
// This provides an accurate answer to p < 0.015625
|
||||
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
|
||||
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
|
||||
BN_copy(&m_number, &a.m_number);
|
||||
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
|
||||
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
|
||||
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
|
||||
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
|
||||
int bits = BN_num_bits(&a.m_number);
|
||||
@ -181,49 +178,49 @@ public:
|
||||
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);
|
||||
}
|
||||
|
||||
void Set (const BigNum & a)
|
||||
void Set(const plBigNum& a)
|
||||
{
|
||||
BN_copy(&m_number, &a.m_number);
|
||||
}
|
||||
|
||||
void Set (unsigned a)
|
||||
void Set(uint32_t a)
|
||||
{
|
||||
BN_set_word(&m_number, a);
|
||||
}
|
||||
|
||||
void SetOne () { Set(1); }
|
||||
void SetZero () { Set(0); }
|
||||
void SetOne() { Set(1); }
|
||||
void SetZero() { Set(0); }
|
||||
|
||||
void Shl (const BigNum & a, unsigned b)
|
||||
void Shl(const plBigNum& a, uint32_t b)
|
||||
{
|
||||
// this = a << 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
|
||||
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
|
||||
BN_copy(&m_number, &a.m_number);
|
||||
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
|
||||
BN_sub(&m_number, &a.m_number, &b.m_number);
|
||||
}
|
||||
};
|
||||
#endif
|
||||
#endif // plBigNum_inc
|
@ -41,7 +41,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
|
||||
*==LICENSE==*/
|
||||
|
||||
#include "plChallengeHash.h"
|
||||
#include "pnUtils/pnUtils.h"
|
||||
|
||||
ShaDigest fSeed;
|
||||
|
||||
|
@ -80,8 +80,8 @@ const NetMsgInitSend * NetMsgChannelFindSendMessage (
|
||||
void NetMsgChannelGetDhConstants (
|
||||
const NetMsgChannel * channel,
|
||||
unsigned * dh_g,
|
||||
const BigNum ** dh_xa, // client: dh_x server: dh_a
|
||||
const BigNum ** dh_n
|
||||
const plBigNum** dh_xa, // client: dh_x server: dh_a
|
||||
const plBigNum** dh_n
|
||||
);
|
||||
|
||||
|
||||
@ -92,18 +92,18 @@ void NetMsgChannelGetDhConstants (
|
||||
***/
|
||||
|
||||
void NetMsgCryptClientStart (
|
||||
NetMsgChannel * channel,
|
||||
NetMsgChannel* channel,
|
||||
unsigned seedBytes,
|
||||
const uint8_t seedData[],
|
||||
BigNum * clientSeed,
|
||||
BigNum * serverSeed
|
||||
const uint8_t seedData[],
|
||||
plBigNum* clientSeed,
|
||||
plBigNum* serverSeed
|
||||
);
|
||||
|
||||
void NetMsgCryptServerConnect (
|
||||
NetMsgChannel * channel,
|
||||
NetMsgChannel* channel,
|
||||
unsigned seedBytes,
|
||||
const uint8_t seedData[],
|
||||
BigNum * clientSeed
|
||||
const uint8_t seedData[],
|
||||
plBigNum* clientSeed
|
||||
);
|
||||
|
||||
|
||||
|
@ -54,6 +54,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
|
||||
#include "pnUtils/pnUtils.h"
|
||||
#include "pnNetBase/pnNetBase.h"
|
||||
#include "pnAsyncCore/pnAsyncCore.h"
|
||||
#include "pnEncryption/plBigNum.h"
|
||||
|
||||
#include "pnNetCli.h"
|
||||
#include "Intern.h"
|
||||
|
@ -83,8 +83,8 @@ struct NetMsgChannel : AtomicRef {
|
||||
|
||||
// Diffie-Hellman constants
|
||||
uint32_t m_dh_g;
|
||||
BigNum m_dh_xa; // client: dh_x server: dh_a
|
||||
BigNum m_dh_n;
|
||||
plBigNum m_dh_xa; // client: dh_x server: dh_a
|
||||
plBigNum m_dh_n;
|
||||
};
|
||||
|
||||
static ChannelCrit s_channelCrit;
|
||||
@ -355,8 +355,8 @@ const NetMsgInitSend * NetMsgChannelFindSendMessage (
|
||||
void NetMsgChannelGetDhConstants (
|
||||
const NetMsgChannel * channel,
|
||||
uint32_t * dh_g,
|
||||
const BigNum ** dh_xa,
|
||||
const BigNum ** dh_n
|
||||
const plBigNum** dh_xa,
|
||||
const plBigNum** dh_n
|
||||
) {
|
||||
if (dh_g) *dh_g = channel->m_dh_g;
|
||||
if (dh_xa) *dh_xa = &channel->m_dh_xa;
|
||||
@ -382,8 +382,8 @@ void NetMsgProtocolRegister (
|
||||
const NetMsgInitRecv recvMsgs[],
|
||||
uint32_t recvMsgCount,
|
||||
uint32_t dh_g,
|
||||
const BigNum & dh_xa, // client: dh_x server: dh_a
|
||||
const BigNum & dh_n
|
||||
const plBigNum& dh_xa, // client: dh_x server: dh_a
|
||||
const plBigNum& dh_n
|
||||
) {
|
||||
s_channelCrit.EnterSafe();
|
||||
{
|
||||
|
@ -652,8 +652,8 @@ static void CreateSymmetricKey (
|
||||
static void ClientConnect (NetCli * cli) {
|
||||
|
||||
// Initiate diffie-hellman for client
|
||||
BigNum clientSeed;
|
||||
BigNum serverSeed;
|
||||
plBigNum clientSeed;
|
||||
plBigNum serverSeed;
|
||||
NetMsgCryptClientStart(
|
||||
cli->channel,
|
||||
sizeof(cli->seed),
|
||||
@ -717,7 +717,7 @@ static bool ServerRecvConnect (
|
||||
else {
|
||||
// Compute client seed
|
||||
uint8_t clientSeed[kNetMaxSymmetricSeedBytes];
|
||||
BigNum clientSeedValue;
|
||||
plBigNum clientSeedValue;
|
||||
{
|
||||
NetMsgCryptServerConnect(
|
||||
cli->channel,
|
||||
@ -761,7 +761,7 @@ static bool ClientRecvEncrypt (
|
||||
return false;
|
||||
|
||||
// find out if we want encryption
|
||||
const BigNum * DH_N;
|
||||
const plBigNum* DH_N;
|
||||
NetMsgChannelGetDhConstants(cli->channel, nil, nil, &DH_N);
|
||||
bool encrypt = !DH_N->isZero();
|
||||
|
||||
|
@ -58,23 +58,23 @@ namespace pnNetCli {
|
||||
|
||||
// g and n are pregenerated and published
|
||||
// (built into both client and server software)
|
||||
BigNum g(4);
|
||||
BigNum n; n.RandPrime(kKeyBits, &seed);
|
||||
plBigNum g(4);
|
||||
plBigNum n; n.RandPrime(kKeyBits, &seed);
|
||||
|
||||
// a and x are pregenerated; a is built into server software, and x is
|
||||
// built into client software
|
||||
BigNum a; a.Rand(kKeyBits, &seed);
|
||||
BigNum x; x.PowMod(g, a, n);
|
||||
plBigNum a; a.Rand(kKeyBits, &seed);
|
||||
plBigNum x; x.PowMod(g, a, n);
|
||||
|
||||
// client chooses b and y on connect, and sends y to the server
|
||||
BigNum b; b.Rand(kKeyBits, &seed);
|
||||
BigNum y; y.PowMod(g, b, n);
|
||||
plBigNum b; b.Rand(kKeyBits, &seed);
|
||||
plBigNum y; y.PowMod(g, b, 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
|
||||
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
|
||||
static void GetCachedServerKey (
|
||||
NetMsgChannel * channel,
|
||||
BigNum * ka,
|
||||
const BigNum & dh_y
|
||||
NetMsgChannel* channel,
|
||||
plBigNum* ka,
|
||||
const plBigNum& dh_y
|
||||
) {
|
||||
// Get diffie-hellman constants
|
||||
unsigned DH_G;
|
||||
const BigNum * DH_A;
|
||||
const BigNum * DH_N;
|
||||
unsigned DH_G;
|
||||
const plBigNum* DH_A;
|
||||
const plBigNum* DH_N;
|
||||
NetMsgChannelGetDhConstants(channel, &DH_G, &DH_A, &DH_N);
|
||||
hsAssert(!DH_N->isZero(), "DH_N must not be zero in encrypted mode");
|
||||
|
||||
@ -114,15 +114,15 @@ static void GetCachedServerKey (
|
||||
|
||||
//============================================================================
|
||||
void NetMsgCryptClientStart (
|
||||
NetMsgChannel * channel,
|
||||
NetMsgChannel* channel,
|
||||
unsigned seedBytes,
|
||||
const uint8_t seedData[],
|
||||
BigNum * clientSeed,
|
||||
BigNum * serverSeed
|
||||
const uint8_t seedData[],
|
||||
plBigNum* clientSeed,
|
||||
plBigNum* serverSeed
|
||||
) {
|
||||
unsigned DH_G;
|
||||
const BigNum * DH_X;
|
||||
const BigNum * DH_N;
|
||||
const plBigNum* DH_X;
|
||||
const plBigNum* DH_N;
|
||||
NetMsgChannelGetDhConstants(channel, &DH_G, &DH_X, &DH_N);
|
||||
if (DH_N->isZero()) { // no actual encryption, but the caller expects a seed
|
||||
clientSeed->SetZero();
|
||||
@ -130,9 +130,9 @@ void NetMsgCryptClientStart (
|
||||
}
|
||||
else {
|
||||
// Client chooses b and y on connect
|
||||
BigNum g(DH_G);
|
||||
BigNum seed(seedBytes, seedData);
|
||||
BigNum b; b.Rand(kNetDiffieHellmanKeyBits, &seed);
|
||||
plBigNum g(DH_G);
|
||||
plBigNum seed(seedBytes, seedData);
|
||||
plBigNum b; b.Rand(kNetDiffieHellmanKeyBits, &seed);
|
||||
|
||||
// Client computes key: kb = x^b mod n
|
||||
clientSeed->PowMod(*DH_X, b, *DH_N);
|
||||
@ -144,13 +144,13 @@ void NetMsgCryptClientStart (
|
||||
|
||||
//============================================================================
|
||||
void NetMsgCryptServerConnect (
|
||||
NetMsgChannel * channel,
|
||||
NetMsgChannel* channel,
|
||||
unsigned seedBytes,
|
||||
const uint8_t seedData[],
|
||||
BigNum * clientSeed
|
||||
const uint8_t seedData[],
|
||||
plBigNum* clientSeed
|
||||
) {
|
||||
// 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);
|
||||
}
|
||||
|
||||
|
@ -326,8 +326,8 @@ void NetMsgProtocolRegister (
|
||||
uint32_t recvMsgCount,
|
||||
// Diffie-Hellman keys
|
||||
uint32_t dh_g,
|
||||
const BigNum & dh_xa, // client: dh_x server: dh_a
|
||||
const BigNum & dh_n
|
||||
const plBigNum& dh_xa, // client: dh_x server: dh_a
|
||||
const plBigNum& dh_n
|
||||
);
|
||||
|
||||
void NetMsgProtocolDestroy (
|
||||
|
@ -616,8 +616,8 @@ static void StartAuthTcpTest (
|
||||
s_send, arrsize(s_send),
|
||||
s_recv, arrsize(s_recv),
|
||||
kAuthDhGValue,
|
||||
BigNum(sizeof(kAuthDhXData), kAuthDhXData),
|
||||
BigNum(sizeof(kAuthDhNData), kAuthDhNData)
|
||||
plBigNum(sizeof(kAuthDhXData), kAuthDhXData),
|
||||
plBigNum(sizeof(kAuthDhNData), kAuthDhNData)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,6 @@ set(pnUtils_HEADERS
|
||||
pnUtAddr.h
|
||||
pnUtAllIncludes.h
|
||||
pnUtArray.h
|
||||
pnUtBigNum.h
|
||||
pnUtCmd.h
|
||||
pnUtCrypt.h
|
||||
pnUtHash.h
|
||||
@ -27,7 +26,6 @@ set(pnUtils_HEADERS
|
||||
|
||||
set(pnUtils_SOURCES
|
||||
pnUtArray.cpp
|
||||
pnUtBigNum.cpp
|
||||
pnUtCmd.cpp
|
||||
pnUtCrypt.cpp
|
||||
pnUtHash.cpp
|
||||
|
@ -63,7 +63,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
|
||||
#include "pnUtStr.h"
|
||||
#include "pnUtRef.h"
|
||||
#include "pnUtPath.h"
|
||||
#include "pnUtBigNum.h"
|
||||
#include "pnUtCmd.h"
|
||||
#include "pnUtMisc.h"
|
||||
#include "pnUtCrypt.h"
|
||||
|
@ -51,6 +51,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
|
||||
#define PLASMA20_SOURCES_PLASMA_PUBUTILLIB_PLNETGAMELIB_PCH_H
|
||||
|
||||
#include "pnUtils/pnUtils.h"
|
||||
#include "pnEncryption/plBigNum.h"
|
||||
#include "pnNetBase/pnNetBase.h"
|
||||
#include "pnAsyncCore/pnAsyncCore.h"
|
||||
#include "pnNetCli/pnNetCli.h"
|
||||
|
@ -5032,8 +5032,8 @@ void AuthInitialize () {
|
||||
s_send, arrsize(s_send),
|
||||
s_recv, arrsize(s_recv),
|
||||
kAuthDhGValue,
|
||||
BigNum(sizeof(kAuthDhXData), kAuthDhXData),
|
||||
BigNum(sizeof(kAuthDhNData), kAuthDhNData)
|
||||
plBigNum(sizeof(kAuthDhXData), kAuthDhXData),
|
||||
plBigNum(sizeof(kAuthDhNData), kAuthDhNData)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -758,8 +758,8 @@ void CsrInitialize () {
|
||||
s_send, arrsize(s_send),
|
||||
s_recv, arrsize(s_recv),
|
||||
kCsrDhGValue,
|
||||
BigNum(sizeof(kCsrDhXData), kCsrDhXData),
|
||||
BigNum(sizeof(kCsrDhNData), kCsrDhNData)
|
||||
plBigNum(sizeof(kCsrDhXData), kCsrDhXData),
|
||||
plBigNum(sizeof(kCsrDhNData), kCsrDhNData)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -711,8 +711,8 @@ void GameInitialize () {
|
||||
s_send, arrsize(s_send),
|
||||
s_recv, arrsize(s_recv),
|
||||
kGameDhGValue,
|
||||
BigNum(sizeof(kGameDhXData), kGameDhXData),
|
||||
BigNum(sizeof(kGameDhNData), kGameDhNData)
|
||||
plBigNum(sizeof(kGameDhXData), kGameDhXData),
|
||||
plBigNum(sizeof(kGameDhNData), kGameDhNData)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -984,8 +984,8 @@ void GateKeeperInitialize () {
|
||||
s_send, arrsize(s_send),
|
||||
s_recv, arrsize(s_recv),
|
||||
kGateKeeperDhGValue,
|
||||
BigNum(sizeof(kGateKeeperDhXData), kGateKeeperDhXData),
|
||||
BigNum(sizeof(kGateKeeperDhNData), kGateKeeperDhNData)
|
||||
plBigNum(sizeof(kGateKeeperDhXData), kGateKeeperDhXData),
|
||||
plBigNum(sizeof(kGateKeeperDhNData), kGateKeeperDhNData)
|
||||
);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user