Pol  Revision:cb584c9
logincrypt.cpp
Go to the documentation of this file.
1 #include <string.h>
2 
3 #include "logincrypt.h"
4 
5 namespace Pol
6 {
7 namespace Crypt
8 {
9 // Macro Definitions ( to avoid big-/little-endian problems )
10 #define N2L( C, LL ) \
11  LL = ( (unsigned int)( *( ( C )++ ) ) ) << 24, LL |= ( (unsigned int)( *( ( C )++ ) ) ) << 16, \
12  LL |= ( (unsigned int)( *( ( C )++ ) ) ) << 8, LL |= ( (unsigned int)( *( ( C )++ ) ) )
13 
14 // Constructor / Destructor
15 LoginCrypt::LoginCrypt() : m_k1( 0 ), m_k2( 0 )
16 {
17  memset( &lkey, 0, sizeof( lkey ) );
18 }
20 
21 // Member Functions
22 void LoginCrypt::Init( unsigned char* lseed, unsigned int k1, unsigned int k2 )
23 {
24  unsigned int seed;
25  N2L( lseed, seed );
26 
27  lkey[0] = ( ( ( ~seed ) ^ 0x00001357 ) << 16 ) | ( ( seed ^ 0xffffaaaa ) & 0x0000ffff );
28  lkey[1] = ( ( seed ^ 0x43210000 ) >> 16 ) | ( ( ( ~seed ) ^ 0xabcdffff ) & 0xffff0000 );
29 
30  m_k1 = k1;
31  m_k2 = k2;
32 }
33 
34 void LoginCrypt::Decrypt( unsigned char* in, unsigned char* out, int len )
35 {
36  for ( int i = 0; i < len; i++ )
37  {
38  out[i] = in[i] ^ (unsigned char)lkey[0];
39 
40  unsigned int table[2];
41  table[0] = lkey[0];
42  table[1] = lkey[1];
43 
44  lkey[1] =
45  ( ( ( ( ( table[1] >> 1 ) | ( table[0] << 31 ) ) ^ m_k1 ) >> 1 ) | ( table[0] << 31 ) ) ^
46  m_k1;
47  lkey[0] = ( ( table[0] >> 1 ) | ( table[1] << 31 ) ) ^ m_k2;
48  }
49 }
50 
51 void LoginCrypt::Decrypt_Old( unsigned char* in, unsigned char* out, int len )
52 {
53  for ( int i = 0; i < len; i++ )
54  {
55  out[i] = in[i] ^ (unsigned char)lkey[0];
56 
57  unsigned int table[2];
58  table[0] = lkey[0];
59  table[1] = lkey[1];
60 
61  lkey[0] = ( ( table[0] >> 1 ) | ( table[1] << 31 ) ) ^ m_k2;
62  lkey[1] = ( ( table[1] >> 1 ) | ( table[0] << 31 ) ) ^ m_k1;
63  }
64 }
65 
66 void LoginCrypt::Decrypt_1_25_36( unsigned char* in, unsigned char* out, int len )
67 {
68  for ( int i = 0; i < len; i++ )
69  {
70  out[i] = in[i] ^ (unsigned char)lkey[0];
71 
72  unsigned int table[2];
73  table[0] = lkey[0];
74  table[1] = lkey[1];
75 
76  lkey[1] = ( m_k1 >> ( ( 5 * table[1] * table[1] ) & 0xff ) ) + ( table[1] * m_k1 ) +
77  ( table[0] * table[0] * 0x35ce9581 ) + 0x07afcc37;
78  lkey[0] = ( m_k2 >> ( ( 3 * table[0] * table[0] ) & 0xff ) ) + ( table[0] * m_k2 ) -
79  ( lkey[1] * lkey[1] * 0x4c3a1353 ) + 0x16ef783f;
80  }
81 }
82 }
83 }
void Decrypt_Old(unsigned char *in, unsigned char *out, int len)
Definition: logincrypt.cpp:51
unsigned int m_k2
Definition: logincrypt.h:31
unsigned int m_k1
Definition: logincrypt.h:31
#define N2L(C, LL)
Definition: logincrypt.cpp:10
void Init(unsigned char *lseed, unsigned int k1, unsigned int k2)
Definition: logincrypt.cpp:22
unsigned int lkey[2]
Definition: logincrypt.h:28
void Decrypt(unsigned char *in, unsigned char *out, int len)
Definition: logincrypt.cpp:34
void Decrypt_1_25_36(unsigned char *in, unsigned char *out, int len)
Definition: logincrypt.cpp:66
Definition: berror.cpp:12