Server Help Forum Index Server Help
Community forums for Subgame, ASSS, and bots
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   StatisticsStatistics   RegisterRegister 
 ProfileProfile   Login to check your private messagesLogin to check your private messages   LoginLogin (SSL) 

Server Help | ASSS Wiki (0) | Shanky.com
subspace encryption

 
Post new topic   Reply to topic Printable version
 View previous topic  turf radar Post :: Post bot won't accept public commands  View next topic  
Author Message
emileej
Newbie


Age:40
Gender:Gender:Male
Joined: Aug 20 2004
Posts: 23
Location: Copenhagen - Denmark
Offline

PostPosted: Fri Aug 20, 2004 3:59 pm    Post subject: subspace encryption Reply to topic Reply with quote

Hi! I'm working on a new core and since I am not very experienced when it comes to encryption I decided to ask Snrrrub if I could use his encryption routines. He said "yeah sure" and I implemented them. However I think I might have added a bug and I was wonderin if anyone in here could find it since I (as mentioned before) am not very good in encryption.
Code: Show/Hide
//Conversion routine
void CSSConnection::WriteUint32to8(Uint32 data,Uint8 *target,int len){
   for(Uint32 cnt=0;cnt<sizeof(Uint32) && cnt<len;cnt++)
       target[cnt]=(Uint8)((data >> (cnt * 8)) & 0xFF);
}

//Encryption routines - by Snrrrup
void CSSConnection::InitEncryption(Uint32 key){
   Log("InitEncryption");

Sint32 temp = 0;
encCypherKey = key;

for(int cnt = 0; cnt < 520; cnt += 2) // Each "block" is 2 bytes and the keystream size is 520 bytes
{
temp = (Uint32)((Uint64)((Uint64)key * (Uint64)0x834E0B5F) >> 48);
temp += (temp >> 31);
key = ((key % 0x1F31D) * 16807) - (temp * 2836) + 123;
if((Sint32)key < 0)
  key += 0x7FFFFFFF;
*((Uint16 *)(encKeyStream + cnt)) = (Uint16)key;
}

encryptionEnabled=true;
}

void CSSConnection::Encrypt(char *data,int len){
   Log("Encrypt");
if(!encryptionEnabled)
return;

int StartPos = 1;
Uint32 Encrypted = encCypherKey;

if(!data[0]) //If Byte at Offset 0 is 0x00
StartPos++;

for(Uint32 Count = StartPos; Count < len; Count += 4)
{
Encrypted ^= *(Uint32 *)(encKeyStream + (Count - StartPos)) ^ (Uint32)(data+Count);
WriteUint32to8(Encrypted,(Uint8*)(data+Count),len-Count);
}
}

void CSSConnection::Decrypt(char *data,int len){
   Log("Decrypt");
if(!encryptionEnabled)
return;

Uint32 Decrypted = encCypherKey;
int StartPos = 1;

if(!data[0]) //If Byte at Offset 0 is 0x00
StartPos++;

for(Uint32 Count = StartPos; Count < len; Count += 4)
{
Uint32 Encrypted = (Uint32)(data+Count);
Decrypted ^= *(Uint32 *)(encKeyStream + (Count - StartPos)) ^ Encrypted;
WriteUint32to8(Decrypted,(Uint8*)(data+Count),len-Count);
Decrypted = Encrypted;
}
}
Back to top
View users profile Send private message Add User to Ignore List Visit posters website Yahoo Messenger MSN Messenger
emileej
Newbie


Age:40
Gender:Gender:Male
Joined: Aug 20 2004
Posts: 23
Location: Copenhagen - Denmark
Offline

PostPosted: Fri Aug 20, 2004 7:21 pm    Post subject: argh! Reply to topic Reply with quote

Ok I'm this close to toss that code ouy the window... I'm really stuck here! Please help - whatever you have of hints, ideas or questions will be helpfull.
Back to top
View users profile Send private message Add User to Ignore List Visit posters website Yahoo Messenger MSN Messenger
myke
Seasoned Helper


Gender:Gender:Male
Joined: Sep 11 2003
Posts: 142
Offline

PostPosted: Fri Aug 20, 2004 7:58 pm    Post subject: Reply to topic Reply with quote

you haven't described your problem so people really can't help you too much...is it a problem compiling? a problem with the encryption not encrypting or decrypting?
Back to top
View users profile Send private message Add User to Ignore List AIM Address
emileej
Newbie


Age:40
Gender:Gender:Male
Joined: Aug 20 2004
Posts: 23
Location: Copenhagen - Denmark
Offline

PostPosted: Fri Aug 20, 2004 8:55 pm    Post subject: Reply to topic Reply with quote

myke wrote:
you haven't described your problem so people really can't help you too much...is it a problem compiling? a problem with the encryption not encrypting or decrypting?
It compiles fine. I know that it is not decrypting properly since for instance my incomming reliable packets have insanely large IDs. I suspect it also doesnt encrypt ptoperly since I, when I send a reliable packet, get a reliable reply with a wrong id and no response on the content of the reliable packet.
Back to top
View users profile Send private message Add User to Ignore List Visit posters website Yahoo Messenger MSN Messenger
ExplodyThingy
Server Help Squatter


Age:38
Gender:Gender:Male
Joined: Dec 15 2002
Posts: 528
Location: Washington DC
Offline

PostPosted: Fri Aug 20, 2004 9:21 pm    Post subject: Reply to topic Reply with quote

Why not just gank them stright from logic bot? I believe he uses Snrrrubs work there for the packet wrappers encryptions, checksums, and settings structs.
_________________
There are no stupid question, but there are many inquisitive idiots.
Loot

Dr Brain> I hate clean air and clean water. I'm a member of Evil Conservitive Industries
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
Mr Ekted
Movie Geek


Gender:Gender:Male
Joined: Feb 09 2004
Posts: 1379
Offline

PostPosted: Fri Aug 20, 2004 9:54 pm    Post subject: Reply to topic Reply with quote

One of the requirements for coding is being able to debug. If you compile and run stuff and it doesn't work, you can't simply just throw it out to the public and say "it's broken, fix it". Take it step by step, narrow down where the problem is. For example, capture an encryption key and a packet from some other source, then see if your code results in the same encrypted packet, etc.
_________________
4,691 irradiated haggis!
Back to top
View users profile Send private message Add User to Ignore List
emileej
Newbie


Age:40
Gender:Gender:Male
Joined: Aug 20 2004
Posts: 23
Location: Copenhagen - Denmark
Offline

PostPosted: Sat Aug 21, 2004 3:15 am    Post subject: Reply to topic Reply with quote

splody << I am - I asked Snrrrub for permission, got it and integrated his routines.

Mr. Ekted << I guess I deserved that one, but the point of me posting the source here in stead is that since it is coded by Snrrrub originaly then I though that this community was very familiar with it and could easier see any major screwups than I.

But as Ekted logicly suggests - are there anyone out there who could provide me with a log displaying client encryption key, server encryption key and all packets in a session encrypted aswell as decrypted?
Back to top
View users profile Send private message Add User to Ignore List Visit posters website Yahoo Messenger MSN Messenger
Mr Ekted
Movie Geek


Gender:Gender:Male
Joined: Feb 09 2004
Posts: 1379
Offline

PostPosted: Sat Aug 21, 2004 4:21 am    Post subject: Reply to topic Reply with quote

There is only 1 key, set by the client. The server just compliments it, and sends it back.
Back to top
View users profile Send private message Add User to Ignore List
emileej
Newbie


Age:40
Gender:Gender:Male
Joined: Aug 20 2004
Posts: 23
Location: Copenhagen - Denmark
Offline

PostPosted: Sat Aug 21, 2004 4:52 am    Post subject: Reply to topic Reply with quote

kk. I stand corrected.
_________________
some ship
AngryAnt
http://angryant.com
Back to top
View users profile Send private message Add User to Ignore List Visit posters website Yahoo Messenger MSN Messenger
Cyan~Fire
I'll count you!
I'll count you!


Age:37
Gender:Gender:Male
Joined: Jul 14 2003
Posts: 4608
Location: A Dream
Offline

PostPosted: Sat Aug 21, 2004 10:06 am    Post subject: Reply to topic Reply with quote

Seeing as you've just ripped this from Snrrrubspace, I'm guessing you don't really know how it works. I'd suggest analyzing the code according to the known encryption, and then try to think your way through to where it's going wrong.

Also, you didn't give us the class CSSConnection declaration. That would be nice, too.
_________________
This help is informational only. No representation is made or warranty given as to its content. User assumes all risk of use. Cyan~Fire assumes no responsibility for any loss or delay resulting from such use.
Wise men STILL seek Him.
Back to top
View users profile Send private message Add User to Ignore List Visit posters website
emileej
Newbie


Age:40
Gender:Gender:Male
Joined: Aug 20 2004
Posts: 23
Location: Copenhagen - Denmark
Offline

PostPosted: Sat Aug 21, 2004 10:57 am    Post subject: Reply to topic Reply with quote

I read the source in LogicBot and thought I'd save some time if Snrrrub would let me use it. Unfortunatly I introduced some bug which noone seems to be able to help me with.
Too bad that I wasted time on this one, but since nobody can help I guess Ill just have have to reinvent the wheel.
These are the encryption related declareations from CSSConnection:
Code: Show/Hide
            //Encryption
             Uint32 encClientKey,encCypherKey;
             Uint8 encKeyStream[520];
             bool encryptionEnabled;

            //Encryption routines - by Snrrrup
            void InitEncryption(Uint32 key);//FIXME
            void Encrypt(char *data,int len);//FIXME
            void Decrypt(char *data,int len);//FIXME
Back to top
View users profile Send private message Add User to Ignore List Visit posters website Yahoo Messenger MSN Messenger
Mr Ekted
Movie Geek


Gender:Gender:Male
Joined: Feb 09 2004
Posts: 1379
Offline

PostPosted: Sat Aug 21, 2004 2:56 pm    Post subject: Reply to topic Reply with quote

We can't help without a larger context. You are probably using the functions incorrectly. We need to see all your code. Obviously Snrrrub's code works.
Back to top
View users profile Send private message Add User to Ignore List
Display posts from previous:   
Post new topic   Reply to topic    Server Help Forum Index -> Bot Questions All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum
View online users | View Statistics | View Ignored List


Software by php BB © php BB Group
Server Load: 150 page(s) served in previous 5 minutes.

phpBB Created this page in 0.509611 seconds : 36 queries executed (88.2%): GZIP compression disabled