mirror of
https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git
synced 2025-07-17 18:59:09 +00:00
Move pnUtBigNum to pnEncryption/plBigNum.
This commit is contained in:
@ -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 (
|
||||
|
Reference in New Issue
Block a user