You last visited: Today at 13:28
Advertisement
[Release][C++]COEncryption.dll
Discussion on [Release][C++]COEncryption.dll within the CO2 PServer Guides & Releases forum part of the CO2 Private Server category.
03/02/2010, 16:35
#1
elite*gold: 0
Join Date: Nov 2009
Posts: 390
Received Thanks: 321
[Release][C++]COEncryption.dll
This is a dynamic library that contains the encryption for 5017(if someone is up for a Cpp project), Diffie Hellman's KE and Blowfish(thanks to
for those
) might as well upgrade it later to include all the encryption algorithms existing so far, headers and static library also included
USAGE
1- Add the dll in the debug/release folder(both is preferred)
2- Add the header to your include path
3- Add the library to your libraries
4- to use the classes in the header:
PHP Code:
#include <blowfish.h> // obviously for blowfish :}
#include <dhke.h> // For the Diffie Hellman KE's class
#include <coencd.h> // For the 5017 encryption
using namespace ConquerEncryptionClasses ;
5- if you are using MSVC++ 2008 or higher use this statement to link the library
PHP Code:
#pragma comment(lib, "COEncryption.lib")
else, you're on your own, you should know how to do it anyway..
6- Create instances..
7- ???
8- PROFIT
#Added Rev 3, proved working 100% after fixing some bugs in code.
PS. Make sure you already have OpenSSL's libraries and headers before using Blowfish or DH KE's classes.
Attached Files
COEncryption Rev3.zip
(9.0 KB, 52 views)
03/02/2010, 16:37
#2
elite*gold: 0
Join Date: Feb 2010
Posts: 480
Received Thanks: 207
nice
03/02/2010, 16:49
#3
elite*gold: 20
Join Date: Aug 2005
Posts: 1,734
Received Thanks: 1,001
Nice release hopefully it'll spark some interest in developing programs in programming language that isn't C#
. I'm sure there'll be a lot of more interest in this when/if the new cryptography is added, I haven't seen C++ implementation of it yet.
03/02/2010, 16:54
#4
elite*gold: 0
Join Date: Sep 2009
Posts: 321
Received Thanks: 60
i have XD but just a converted version
03/02/2010, 16:57
#5
elite*gold: 0
Join Date: Nov 2009
Posts: 390
Received Thanks: 321
Quote:
Originally Posted by
tanelipe
Nice release hopefully it'll spark some interest in developing programs in programming language that isn't C#
. I'm sure there'll be a lot of more interest in this when/if the new cryptography is added, I haven't seen C++ implementation of it yet.
Thanks, might take some time to include the latest encryption because I'm currently working with some fellows on a project, also school takes most of my time, hopefully i will finish it by this weekend or the next weekend
03/02/2010, 18:21
#6
elite*gold: 20
Join Date: Aug 2005
Posts: 1,734
Received Thanks: 1,001
I've basically written the Blowfish.h/cpp now, all I need to do now is to wrap the DH exchange part in C++ and it should be good to go. I haven't tested this code so far, I have no idea if it really works, lmao.
Blowfish.h
PHP Code:
#pragma once
#include <openssl/blowfish.h>
#pragma comment(lib, "libeay32.lib")
class CBlowfish
{
private:
unsigned char * DecryptIV ;
unsigned char * EncryptIV ;
int DecryptCounter ;
int EncryptCounter ;
BF_KEY * Key ;
public:
CBlowfish ( unsigned char * Data , int Length );
~ CBlowfish ( void );
unsigned char * Encrypt ( unsigned char * Data , int Length );
unsigned char * Decrypt ( unsigned char * Data , int Length );
void SetKey ( unsigned char * Data , int Length );
void SetIVs ( unsigned char * DecryptIV , unsigned char * EncryptIV );
};
Blowfish.cpp
PHP Code:
#include "StdAfx.h"
#include "Blowfish.h"
CBlowfish :: CBlowfish ( unsigned char * Data , int Length )
{
DecryptIV = new unsigned char [ 8 ];
EncryptIV = new unsigned char [ 8 ];
DecryptCounter = 0 ;
EncryptCounter = 0 ;
Key = new BF_KEY ();
BF_set_key ( Key , Length , Data );
}
CBlowfish ::~ CBlowfish ( void )
{
delete [] DecryptIV ;
delete [] EncryptIV ;
delete [] Key ;
}
unsigned char * CBlowfish :: Encrypt ( unsigned char * Data , int Length )
{
unsigned char * Out = new unsigned char [ Length ];
BF_cfb64_encrypt ( Data , Out , Length , Key , EncryptIV , & EncryptCounter , 1 );
return Out ;
}
unsigned char * CBlowfish :: Decrypt ( unsigned char * Data , int Length )
{
unsigned char * Out = new unsigned char [ Length ];
BF_cfb64_encrypt ( Data , Out , Length , Key , DecryptIV , & DecryptCounter , 0 );
return Out ;
}
void CBlowfish :: SetKey ( unsigned char * Data , int Length )
{
BF_set_key ( Key , Length , Data );
DecryptCounter = 0 ;
EncryptCounter = 0 ;
}
void CBlowfish :: SetIVs ( unsigned char * DecryptIV , unsigned char * EncryptIV )
{
memcpy ( this -> DecryptIV , DecryptIV , 8 );
memcpy ( this -> EncryptIV , EncryptIV , 8 );
}
03/02/2010, 18:31
#7
elite*gold: 0
Join Date: Nov 2009
Posts: 390
Received Thanks: 321
Quote:
Originally Posted by
tanelipe
I've basically written the Blowfish.h/cpp now, all I need to do now is to wrap the DH exchange part in C++ and it should be good to go. I haven't tested this code so far, I have no idea if it really works, lmao....
Nice
it should work nonetheless.
03/02/2010, 19:01
#8
elite*gold: 0
Join Date: Feb 2010
Posts: 129
Received Thanks: 30
Sick release
03/02/2010, 20:42
#9
elite*gold: 20
Join Date: Aug 2005
Posts: 1,734
Received Thanks: 1,001
If anyone is kind enough to convert the ClientKeyPacket (Handshake reply) and ServerKeyPacket (Handshake) to C++ (structures atleast), it would be greatly appreciated. I'm not really into doing it, it's pain in the arse in C# already.
EDIT:
DH.h
PHP Code:
#pragma once #include <openssl/dh.h> #include <openssl/bn.h> class CDH { private: DH * dh ; public: CDH ( BIGNUM * P , BIGNUM * G ); ~ CDH ( void ); unsigned char * ComputeKey ( BIGNUM * PublicKey ); void GenerateKeys (); void SetG ( BIGNUM * G ); void SetP ( BIGNUM * P ); void SetPrivate ( BIGNUM * PrivateKey ); void SetPublic ( BIGNUM * PublicKey ); BIGNUM * GetG (); BIGNUM * GetP (); BIGNUM * GetPrivate (); BIGNUM * GetPublic (); __declspec ( property ( get = GetG , put = SetG )) BIGNUM * G ; __declspec ( property ( get = GetP , put = SetP )) BIGNUM * P ; __declspec ( property ( get = GetPrivate , put = SetPrivate )) BIGNUM * PrivateKey ; __declspec ( property ( get = GetPublic , put = SetPublic )) BIGNUM * PublicKey ; };
DH.cpp
PHP Code:
#include "StdAfx.h" #include "DH.h" CDH :: CDH ( BIGNUM * P , BIGNUM * G ) { dh = new DH (); dh -> p = P ; dh -> g = G ; } unsigned char * CDH :: ComputeKey ( BIGNUM * PublicKey ) { unsigned char * Key = new unsigned char [ DH_size ( dh )]; DH_compute_key ( Key , PublicKey , dh ); return Key ; } void CDH :: GenerateKeys () { DH_generate_key ( dh ); } void CDH :: SetG ( BIGNUM * G ) { dh -> g = BN_dup ( G ); } void CDH :: SetP ( BIGNUM * P ) { dh -> p = BN_dup ( P ); } void CDH :: SetPrivate ( BIGNUM * PrivateKey ) { dh -> priv_key = BN_dup ( PrivateKey ); } void CDH :: SetPublic ( BIGNUM * PublicKey ) { dh -> pub_key = BN_dup ( PublicKey ); } BIGNUM * CDH :: GetP () { return dh -> p ; } BIGNUM * CDH :: GetG () { return dh -> g ; } BIGNUM * CDH :: GetPrivate () { return dh -> priv_key ; } BIGNUM * CDH :: GetPublic () { return dh -> pub_key ; } CDH ::~ CDH ( void ) { delete [] dh ; }
03/02/2010, 23:12
#10
elite*gold: 0
Join Date: Oct 2009
Posts: 8,783
Received Thanks: 5,304
Haha tempts me to try cpp lol.
03/02/2010, 23:41
#11
elite*gold: 20
Join Date: Aug 2005
Posts: 1,734
Received Thanks: 1,001
Noticed sligth error in the code, if anyone is using it replace
PHP Code:
CDH :: CDH ( BIGNUM * P , BIGNUM * G )
{
dh = new DH ();
dh -> p = P ;
dh -> g = G ;
}
with
PHP Code:
dh = DH_new ();
dh -> p = BN_dup ( P );
dh -> g = BN_dup ( G );
03/03/2010, 16:07
#12
elite*gold: 0
Join Date: Nov 2009
Posts: 390
Received Thanks: 321
UPDATE
Diffie Hellman and Blowfish included, thanks to tanelipe for those.
03/03/2010, 18:06
#13
elite*gold: 0
Join Date: Jan 2008
Posts: 1,443
Received Thanks: 1,175
I have made the class for the ServerKeyPacket. I don't code a lot in C++ and I make it on Xcode. I'm not sure of the exact structure of the packet. I don't really know the new encryption. I prefer the old Co2
PHP Code:
////////////////////////////////////////////////////////////////////// // ServerKeyPacket.h ////////////////////////////////////////////////////////////////////// #pragma once // include head file(s) here... // define constant(s) here... const int _PAD_LENGTH = 11 ; const int _JUNK_LENGTH = 10 ; const int _IV_LENGTH = 8 ; const int _KEY_LENGTH = 128 ; const char P [ 128 ] = "A320A85EDD79171C341459E94807D71D39BB3B3F3B5161CA84894F3AC3FC7FEC317A2DDEC83B66D30C29261C6492643061AECFCF4A051816D7C359A6A7B7D8FB" ; const char G [ 2 ] = "05" ; class CServerKeyPacket { public: CServerKeyPacket (); virtual ~ CServerKeyPacket (); bool Create ( char Key [ _KEY_LENGTH ], unsigned char ServerIV [ _IV_LENGTH ], unsigned char ClientIV [ _IV_LENGTH ]); private: typedef struct { unsigned char dwPad [ _PAD_LENGTH ]; int MsgSize ; unsigned char dwJunk [ _JUNK_LENGTH ]; unsigned char dwServerIV [ _IV_LENGTH ]; unsigned char dwClientIV [ _IV_LENGTH ]; char dwP [ 128 ]; char dwG [ 2 ]; char dwKey [ _KEY_LENGTH ]; }; } MSG_Info ; MSG_Info * m_pInfo ; };
PHP Code:
////////////////////////////////////////////////////////////////////// // ServerKeyPacket.cpp ////////////////////////////////////////////////////////////////////// // include head file(s) here... #include "ServerKeyPacket.h" #include <stdio.h> #include <stdlib.h> #include <time.h> ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// CServerKeyPacket :: CServerKeyPacket () { } CServerKeyPacket ::~ CServerKeyPacket () { } ////////////////////////////////////////////////////////////////////// bool CServerKeyPacket :: Create ( char Key [ _KEY_LENGTH ], unsigned char ServerIV [ _IV_LENGTH ], unsigned char ClientIV [ _IV_LENGTH ]) { unsigned char Pad [ _PAD_LENGTH ]; unsigned char Junk [ _JUNK_LENGTH ]; for ( int i = 0 ; i < _PAD_LENGTH ; i ++) Pad [ i ] = ( rand () / ( RAND_MAX + 1 ) * 255 ); for ( int i = 0 ; i < _JUNK_LENGTH ; i ++) Junk [ i ] = ( rand () / ( RAND_MAX + 1 ) * 255 ); // fill info now SafeCopy ( m_pInfo -> dwPad , Pad , _PAD_LENGTH ); SafeCopy ( m_pInfo -> dwJunk , Junk , _JUNK_LENGTH ); SafeCopy ( m_pInfo -> dwServerIV , ServerIV , _IV_LENGTH ); SafeCopy ( m_pInfo -> dwClientIV , ClientIV , _IV_LENGTH ); SafeCopy ( m_pInfo -> dwP , P , 128 ); SafeCopy ( m_pInfo -> dwG , G , 2 ); SafeCopy ( m_pInfo -> dwKey , Key , _KEY_LENGTH ); MsgSize = sizeof ( MSG_Info ); return true ; }
03/03/2010, 18:24
#14
elite*gold: 20
Join Date: Aug 2005
Posts: 1,734
Received Thanks: 1,001
I've already got the parsing done for handshake/-reply
PHP Code:
#pragma once
#include "PacketReader.h"
class Handshake
{
public:
Handshake ( void ) { }
~ Handshake ( void ) { }
unsigned char * ServerIV , * ClientIV ;
char * P , * G , * PublicKey ;
void Process ( unsigned char * Packet )
{
PacketReader * Reader = new PacketReader ( Packet , sizeof ( Packet ), 15 );
Reader -> Advance ( Reader -> ReadDWord ());
ServerIV = Reader -> ReadBytes ( Reader -> ReadDWord ());
ClientIV = Reader -> ReadBytes ( Reader -> ReadDWord ());
P = Reader -> ReadString ( Reader -> ReadDWord ());
G = Reader -> ReadString ( Reader -> ReadDWord ());
PublicKey = Reader -> ReadString ( Reader -> ReadDWord ());
}
};
PHP Code:
#pragma once
#include "PacketReader.h"
class HandshakeReply
{
public:
HandshakeReply ( void ) { }
~ HandshakeReply ( void ) { }
char * PublicKey ;
void Process ( unsigned char * Packet )
{
PacketReader * Reader = new PacketReader ( Packet , sizeof ( Packet ), 11 );
Reader -> Advance ( Reader -> ReadDWord ());
PublicKey = Reader -> ReadString ( Reader -> ReadDWord ());
}
};
PacketReader is just a simple class which reads/advances the current position of index, looks neater.
03/03/2010, 21:36
#15
elite*gold: 0
Join Date: Nov 2009
Posts: 390
Received Thanks: 321
You guys are making me lazy.. lol you did almost all the work, where was that when i was searching for it? :P
Anyhow, I'll be writing the reply in a while
All times are GMT +1. The time now is 13:30 .