FreeCalypso > hg > freecalypso-tools
annotate rvinterf/etmsync/cl_des.c @ 26:b301b75de0e0
install misc files into /usr/local/share/freecalypso as non-executable
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 23 Oct 2016 01:20:55 +0000 |
parents | 3d148edb87c2 |
children |
rev | line source |
---|---|
14
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This DES implementation is used for the purpose of decrypting |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * Pirelli's factory IMEI record; it has been lifted out of TI's |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 * reference GSM firmware source. |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 */ |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include "cl_des.h" |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 typedef unsigned char UBYTE; |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 /* 64+64+17*56+16*48+64+17*32+17*32 = 3000 bytes */ |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 static UBYTE binmsg[64] , binkey[64], cd[17][56] , deskey[16][48] , ip[64]; |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 static UBYTE l[17][32] , r[17][32]; |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 /* 64+64+32+32+64+64+17*3+2 = 373 bytes */ |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 static UBYTE rnew[64] , xorres[64] , scale[32] , perm[32] , rl[64] , encpt[64]; |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 /* 64+16+48+64+48+32+64+8*66 = 864 bytes */ |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 static |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 const UBYTE shtamt[16] = {1,1,2,2,2,2,2,2,1,2,2,2,2,2,2,1}; |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 static |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 const UBYTE iporder[64] = {58,50,42,34,26,18,10,2,60,52,44,36,28,20,12,4,62,54, |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 46,38,30,22,14,6,64,56,48,40,32,24,16,8,57,49,41,33, |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 25,17,9,1,59,51,43,35,27,19,11,3,61,53,45,37,29,21, |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 13,5,63,55,47,39,31,23,15,7}; |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 static |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 const UBYTE pc1[64] = {57,49,41,33,25,17,9,1,58,50,42,34,26,18,10,2,59,51,43, |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 35,27,19,11,3,60,52,44,36,63,55,47,39,31,23,15,7,62,54, |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 46,38,30,22,14,6,61,53,45,37,29,21,13,5,28,20,12,4}; |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 static |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 const UBYTE pc2[48] = {14,17,11,24,1,5,3,28,15,6,21,10,23,19,12,4,26,8, |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 16,7,27,20,13,2,41,52,31,37,47,55,30,40,51,45,33, |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 48,44,49,39,56,34,53,46,42,50,36,29,32}; |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 static |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 const UBYTE e[48] = {32,1,2,3,4,5,4,5,6,7,8,9,8,9,10,11,12,13,12,13,14,15, |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 16,17,16,17,18,19,20,21,20,21,22,23,24,25,24,25,26,27, |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 28,29,28, 29,30,31,32,1}; |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 static |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 const UBYTE sp[32] = {16,7,20,21,29,12,28,17,1,15,23,26,5,18,31,10, |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 2,8,24,14,32,27,3,9,19,13,30,6,22,11,4,25}; |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 static |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 const UBYTE ipinv[64] = {40,8,48,16,56,24,64,32,39,7,47,15,55,23,63,31,38,6,46, |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 14,54,22,62,30,37,5,45,13,53,21,61,29,36,4,44,12,52, |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 20,60,28,35,3,43,11,51,19,59,27,34,2,42,10,50,18,58, |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 26,33,1,41,9,49,17,57,25}; |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 static |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 const UBYTE s[8][66] = {{14,4,13,1,2,15,11,8,3,10,6,12,5,9,0,7,0,15,7,4,14,2,13, |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 1,10,6,12,11,9,5,3,8,4,1,14,8,13,6,2,11,15,12,9,7,3,10, |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 5,0,15,12,8,2,4,9,1,7,5,11,3,14,10,0,6,13}, |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 {15,1,8,14,6,11,3,4,9,7,2,13,12,0,5,10,3,13,4,7,15,2,8, |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 14,12,0,1,10,6,9,11,5,0,14,7,11,10,4,13,1,5,8,12,6,9,3, |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 2,15,13,8,10,1,3,15,4,2,11,6,7,12,0,5,14,9}, |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 {10,0,9,14,6,3,15,5,1,13,12,7,11,4,2,8,13,7,0,9,3,4,6, |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 10,2,8,5,14,12,11,15,1,13,6,4,9,8,15,3,0,11,1,2,12,5, |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 10,14,7,1,10,13,0,6,9,8,7,4,15,14,3,11,5,2,12 }, |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 {7,13,14,3,0,6,9,10,1,2,8,5,11,12,4,15,13,8,11,5,6,15, |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 0,3,4,7,2,12,1,10,14,9,10,6,9,0,12,11,7,13,15,1,3,14, |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 5,2,8,4,3,15,0,6,10,1,13,8,9,4,5,11,12,7,2,14 }, |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 {2,12,4,1,7,10,11,6,8,5,3,15,13,0,14,9,14,11,2,12,4,7, |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 13,1,5,0,15,10,3,9,8,6,4,2,1,11,10,13,7,8,15,9,12,5,6, |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 3,0,14,11,8,12,7,1,14,2,13,6,15,0,9,10,4,5,3 }, |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 {12,1,10,15,9,2,6,8,0,13,3,4,14,7,5,11,10,15,4,2,7,12, |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 9,5,6,1,13,14,0,11,3,8,9,14,15,5,2,8,12,3,7,0,4,10,1, |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 13,11,6,4,3,2,12,9,5,15,10,11,14,1,7,6,0,8,13 }, |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 {4,11,2,14,15,0,8,13,3,12,9,7,5,10,6,1,13,0,11,7,4,9,1, |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 10,14,3,5,12,2,15,8,6,1,4,11,13,12,3,7,14,10,15,6,8,0, |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 5,9,2,6,11,13,8,1,4,10,7,9,5,0,15,14,2,3,12 }, |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 {13,2,8,4,6,15,11,1,10,9,3,14,5,0,12,7,1,15,13,8,10,3,7, |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 4,12,5,6,11,0,14,9,2,7,11,4,1,9,12,14,2,0,6,10,13,15,3, |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 5,8,2,1,14,7,4,10,8,13,15,12,9,0,3,5,6,11 }}; |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 /*==== FUNCTIONS ==================================================*/ |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 #define LOCAL static |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 /* |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 +------------------------------------------------------------------------------ |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 | Function : des_hex2bin4 |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 +------------------------------------------------------------------------------ |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 | Description : The function converts a 4 bit hex value to 4 binary values |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 | |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 | Parameters : hex : value in hex |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 | m : pointer to buffer of 4 elements to store binary values |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 +------------------------------------------------------------------------------ |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 */ |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 LOCAL void des_hex2bin4(UBYTE hex, UBYTE *m) |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 { |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 m[0] = (hex & 0x08) >> 3; |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 m[1] = (hex & 0x04) >> 2; |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 m[2] = (hex & 0x02) >> 1; |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 m[3] = hex & 0x01; |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 } |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 /* |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 +------------------------------------------------------------------------------ |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 | Function : des_hex2bin8 |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 +------------------------------------------------------------------------------ |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 | Description : The function converts a 8 bit hex value to 8 binary values |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 | |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 | Parameters : hex : value in hex |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 | m : pointer to buffer of 8 elements to store binary values |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 +------------------------------------------------------------------------------ |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 */ |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 LOCAL void des_hex2bin8(UBYTE hex, UBYTE *m) |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
105 { |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 m[0] = (hex & 0x80) >> 7; |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 m[1] = (hex & 0x40) >> 6; |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 m[2] = (hex & 0x20) >> 5; |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 m[3] = (hex & 0x10) >> 4; |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 m[4] = (hex & 0x08) >> 3; |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
111 m[5] = (hex & 0x04) >> 2; |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
112 m[6] = (hex & 0x02) >> 1; |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
113 m[7] = hex & 0x01; |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
114 } |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
115 |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
116 /* |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
117 +------------------------------------------------------------------------------ |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
118 | Function : des_bin2hex |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
119 +------------------------------------------------------------------------------ |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
120 | Description : The function converts 8 bin values to an 8 bit hex value |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
121 | |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
122 | Parameters : m[8] : input bin values |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
123 | Return : converted hex value |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
124 +------------------------------------------------------------------------------ |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
125 */ |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
126 |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
127 LOCAL UBYTE des_bin2hex(UBYTE *m) |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
128 { |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
129 UBYTE hex; |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
130 return hex = (m[0]<<7) | (m[1]<<6) | (m[2]<<5) | (m[3]<<4) | |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
131 (m[4]<<3) | (m[5]<<2) | (m[6]<<1) | m[7]; |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
132 } |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
133 |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
134 |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
135 |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
136 /* |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
137 +------------------------------------------------------------------------------ |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
138 | Function : des_shift |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
139 +------------------------------------------------------------------------------ |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
140 | Description : The function performs shifting |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
141 | |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
142 | Parameters : dst : pointer to destination buffer |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
143 | src : pointer to source buffer |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
144 | sht : shift value |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
145 +------------------------------------------------------------------------------ |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
146 */ |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
147 |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
148 LOCAL void des_shift(UBYTE *dst, UBYTE *src, UBYTE sht) |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
149 { |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
150 UBYTE c1 , c2 , d1 , d2; |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
151 int i; |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
152 |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
153 c1 = src[0]; |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
154 c2 = src[1]; |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
155 d1 = src[28]; |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
156 d2 = src[29]; |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
157 |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
158 for ( i = 0 ; i < 28 - sht ; i++) { |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
159 dst[i] = src[i + sht]; /* copying c[i] */ |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
160 dst[28 + i] = src[28 + i + sht]; /* copying d[i] */ |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
161 } |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
162 |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
163 if (sht == 1){ |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
164 dst[27] = c1; |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
165 dst[55] = d1; |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
166 } else { |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
167 dst[26] = c1; |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
168 dst[27] = c2; |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
169 dst[54] = d1; |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
170 dst[55] = d2; |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
171 } |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
172 } |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
173 |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
174 /* |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
175 +------------------------------------------------------------------------------ |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
176 | Function : des_indx |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
177 +------------------------------------------------------------------------------ |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
178 | Description : The function generates index for S table |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
179 | |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
180 | Parameters : m[6] : |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
181 | Return : index value |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
182 +------------------------------------------------------------------------------ |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
183 */ |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
184 LOCAL UBYTE des_indx(UBYTE *m) |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
185 { |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
186 return( (((m[0]<<1) + m[5])<<4) + ((m[1]<<3) + (m[2]<<2) + (m[3]<<1) + m[4])); |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
187 } |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
188 |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
189 /* |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
190 +------------------------------------------------------------------------------ |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
191 | Function : cl_des |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
192 +------------------------------------------------------------------------------ |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
193 | Description : The function performs DES encrypting or decrypting |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
194 | |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
195 | Parameters : inMsgPtr : pointer to input message M. The length of message |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
196 | has to be min. 8 bytes e.g. M = 0123456789abcdef |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
197 | desKeyPtr : pointer to DES key. Length has to be 8 bytes |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
198 | outMsgPtr : output encrypted/decrypted message. The length is 8 b. |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
199 | code : CL_DES_ENCRYPTION, CL_DES_DECRYPTION |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
200 +------------------------------------------------------------------------------ |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
201 */ |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
202 void cl_des(UBYTE *inMsgPtr, UBYTE *desKeyPtr, UBYTE *outMsgPtr, UBYTE code) |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
203 { |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
204 |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
205 int y , z , g; |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
206 UBYTE temp, more; |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
207 |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
208 /* |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
209 * convert message from hex to bin format |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
210 */ |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
211 for(y = 0; y < 8; y++){ |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
212 des_hex2bin8(inMsgPtr[y], &binmsg[8 * y]); |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
213 } |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
214 |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
215 /* |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
216 * Convert DES key value from hex to bin format |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
217 */ |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
218 for( y = 0; y < 8; y++){ |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
219 des_hex2bin8(desKeyPtr[y], &binkey[8 * y]); |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
220 } |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
221 |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
222 /* |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
223 * Step 1: Create 16 subkeys, each of which is 48-bits long. |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
224 * |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
225 * The 64-bit key is permuted according to the table pc1, |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
226 * to get the 56 bit subkey K+. The subkey K+ consists of left |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
227 * and right halves C0 and D0, where each half has 28 bits. |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
228 */ |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
229 for(y = 0 ; y < 56 ; y++) |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
230 cd[0][y] = binkey[pc1[y] - 1]; |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
231 /* |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
232 * Create futher 15 subkeys C1-C16 and D1-D16 by left shifts of |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
233 * each previous key, i.e. C2 and D2 are obtained from C1 and D1 and so on. |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
234 */ |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
235 for(y = 0 ; y < 16 ; y++) |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
236 des_shift(cd[y + 1] , cd[y] , shtamt[y]); |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
237 |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
238 /* |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
239 * Form the keys K1-K16 by applying the pc2 permutation |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
240 * table to each of the concatenated pairs CnDn. |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
241 */ |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
242 for(y = 0; y < 16; y++){ |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
243 for(z = 0 ; z < 48 ; z++){ |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
244 deskey[y][z] = cd[y + 1][pc2[z] - 1]; |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
245 } |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
246 } |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
247 |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
248 /* |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
249 * Step 2: Encode each 64-bit block of data |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
250 * |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
251 * Perform initial permutation IP of th e64 bits the message data M. |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
252 * This rearranges the bits according to the iporder table. |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
253 */ |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
254 for(y = 0; y < 64; y++) |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
255 ip[y] = binmsg[iporder[y] - 1]; |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
256 |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
257 /* |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
258 * Divide the permuted block IP into left half L0 |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
259 * and a right half R0 each of 32 bits. |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
260 */ |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
261 for(y = 0; y < 32; y++){ |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
262 l[0][y] = ip[y]; |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
263 r[0][y] = ip[y + 32]; |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
264 } |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
265 |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
266 /* |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
267 * Proceed through 16 iterations, operation on two blocks: |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
268 * a data block of 32 bits and a key Kn of 48 bits to produce a block of 32 |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
269 * bits. This results in a final block L16R16. In each iteration, we take |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
270 * the right 32 bits of the previous result and make them the left 32 bits |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
271 * of the current step. For the right 32 bits in the current step, we XOR |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
272 * the left 32 bits of the previous step. |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
273 */ |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
274 for (y = 0; y < 16; y++){ |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
275 if (code == CL_DES_ENCRYPTION)/* encryption */ |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
276 g = y; |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
277 else /* decryption */ |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
278 g = 15 - y; |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
279 |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
280 /* |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
281 * Copie the right bits Rn of the current step |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
282 * to the left bits Ln+1 of the next step |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
283 */ |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
284 for(z = 0; z < 32; z++) |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
285 l[y + 1][z] = r[y][z]; |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
286 |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
287 /* |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
288 * Expand the block Rn from 32 to 48 bits by using the selection table E. |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
289 * Then XOR the result with the key Kn+1. |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
290 */ |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
291 for(z = 0; z < 48; z++){ |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
292 rnew[z] = r[y][e[z] - 1]; |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
293 xorres[z] = (rnew[z] ^ deskey[g][z]); |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
294 } |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
295 |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
296 /* |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
297 * We now have 48 bits, or eight groups of six bits. We use them as |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
298 * addresses in tables calle "S boxes". Each group of six bits will |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
299 * give us an address in a different S box. |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
300 */ |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
301 for(z = 0; z < 8; z++){ |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
302 temp = s[z][des_indx(&xorres[z * 6])]; |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
303 des_hex2bin4(temp, &scale[z * 4]); |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
304 } |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
305 |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
306 /* |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
307 * Perform a permutation P of the S box output. |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
308 */ |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
309 for(z = 0; z < 32; z++) |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
310 perm[z] = scale[sp[z] - 1]; |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
311 |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
312 /* |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
313 * XOR the result with the left half of current step |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
314 * and copie it to the right half of the next step |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
315 */ |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
316 for(z = 0; z < 32; z++) |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
317 r[y+1][z] = (l[y][z] ^ perm[z]); |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
318 } |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
319 |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
320 /* |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
321 * Reserve the order of the final block L16R16 to R16L16 |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
322 */ |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
323 for( z = 0; z < 32; z++){ |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
324 rl[z] = r[16][z]; |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
325 rl[z + 32] = l[16][z]; |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
326 } |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
327 |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
328 /* |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
329 * Apply the final inverse permutation IP |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
330 */ |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
331 for( z = 0; z < 64; z++){ |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
332 encpt[z] = rl[ipinv[z] - 1]; |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
333 } |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
334 |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
335 /* |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
336 * Convert from bin to hex format |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
337 */ |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
338 for(z = 0; z < 8; z++){ |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
339 outMsgPtr[z] = des_bin2hex(&encpt[8 * z]); |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
340 } |
3d148edb87c2
eliminated the dependency on OpenSSL for Pirelli IMEI DES decryption
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
341 } |