-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCHOWAES-JIT.c
executable file
·167 lines (122 loc) · 4.83 KB
/
CHOWAES-JIT.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#include <stdio.h>
#include "common/tboxes.h"
#include "common/ty.h"
#include "common/txor.h"
#include "common/tyboxes.h"
#include "../tigress/3.1/tigress.h"
#include "../tigress/3.1/jitter-amd64.c"
void init_tigress() {}
void ShiftRows(unsigned char out[16])
{
unsigned char tmp1, tmp2;
// 8-bits left rotation of the second line
tmp1 = out[1];
out[1] = out[5];
out[5] = out[9];
out[9] = out[13];
out[13] = tmp1;
// 16-bits left rotation of the third line
tmp1 = out[2];
tmp2 = out[6];
out[2] = out[10];
out[6] = out[14];
out[10] = tmp1;
out[14] = tmp2;
// 24-bits left rotation of the last line
tmp1 = out[3];
out[3] = out[15];
out[15] = out[11];
out[11] = out[7];
out[7] = tmp1;
}
void aes128_enc_wb_final(unsigned char in[16], unsigned char out[16])
{
unsigned char out2[16] = { 0 };
int k;
memcpy(out, in, 16);
int i, j;
/// Let's start the encryption process now
for (i = 0; i < 9; ++i)
{
ShiftRows(out);
for (j = 0; j < 4; ++j)
{
unsigned int aa = Tyboxes[i][j * 4 + 0][out[j * 4 + 0]];
unsigned int bb = Tyboxes[i][j * 4 + 1][out[j * 4 + 1]];
unsigned int cc = Tyboxes[i][j * 4 + 2][out[j * 4 + 2]];
unsigned int dd = Tyboxes[i][j * 4 + 3][out[j * 4 + 3]];
unsigned int intabs0 = Txor[(aa >> 0) & 0xf][(bb >> 0) & 0xf];
unsigned int intcds0 = Txor[(cc >> 0) & 0xf][(dd >> 0) & 0xf];
unsigned int intabs4 = Txor[(aa >> 4) & 0xf][(bb >> 4) & 0xf];
unsigned int intcds4 = Txor[(cc >> 4) & 0xf][(dd >> 4) & 0xf];
unsigned int intabs8 = Txor[(aa >> 8) & 0xf][(bb >> 8) & 0xf];
unsigned int intcds8 = Txor[(cc >> 8) & 0xf][(dd >> 8) & 0xf];
unsigned int intabs12 = Txor[(aa >> 12) & 0xf][(bb >> 12) & 0xf];
unsigned int intcds12 = Txor[(cc >> 12) & 0xf][(dd >> 12) & 0xf];
unsigned int intabs16 = Txor[(aa >> 16) & 0xf][(bb >> 16) & 0xf];
unsigned int intcds16 = Txor[(cc >> 16) & 0xf][(dd >> 16) & 0xf];
unsigned int intabs20 = Txor[(aa >> 20) & 0xf][(bb >> 20) & 0xf];
unsigned int intcds20 = Txor[(cc >> 20) & 0xf][(dd >> 20) & 0xf];
unsigned int intabs24 = Txor[(aa >> 24) & 0xf][(bb >> 24) & 0xf];
unsigned int intcds24 = Txor[(cc >> 24) & 0xf][(dd >> 24) & 0xf];
unsigned int intabs28 = Txor[(aa >> 28) & 0xf][(bb >> 28) & 0xf];
unsigned int intcds28 = Txor[(cc >> 28) & 0xf][(dd >> 28) & 0xf];
out[j * 4 + 0] = (Txor[intabs0][intcds0]) | ((Txor[intabs4][intcds4]) << 4);
out[j * 4 + 1] = (Txor[intabs8][intcds8]) | ((Txor[intabs12][intcds12]) << 4);
out[j * 4 + 2] = (Txor[intabs16][intcds16]) | ((Txor[intabs20][intcds20]) << 4);
out[j * 4 + 3] = (Txor[intabs24][intcds24]) | ((Txor[intabs28][intcds28]) << 4);
}
}
/// Last round which is a bit different
ShiftRows(out);
for ( j = 0; j < 16; ++j)
{
unsigned char x = Tboxes_[j][out[j]];
out[j] = x;
}
memcpy(out2, out, 16);
}
int main(int argc, char *argv[])
{
int i;
unsigned char out[16] = { 0 };
unsigned char out2[16] = { 0 };
unsigned char plain[16];
//= {0x77, 0x68, 0x61, 0x74, 0x64, 0x75, 0x70, 0x20, 0x66, 0x6F, 0x6C, 0x6B, 0x73, 0x3F, 0x3F, 0x3F};
//= {0x74, 0x65, 0x74, 0x65, 0x74, 0x65, 0x74, 0x65, 0x74, 0x65, 0x74, 0x65, 0x74, 0x65, 0x74, 0x65};
char *m ="7768617464757020666F6C6B733F3F3F";// "whatdup folks???";//"testtesttesttest";
char *m2 ="4576A387563BDC8E47FA96B9E84D6F54";// "whatdup folks???";//"testtesttesttest";
char *m3 ="74657465746574657465746574657465";// "tetetetetetetete"
int count;
if( argc == 2 ) {
//assuming the input is always 32 characters representing 16 bytes
m = argv[1];
}
unsigned char val[16]; //assuming the input is 16 bytes
char * pos= m; //copy the message to the buffer for processing (using sscanf because we were testing emulation of some methods) also because the input was provided as need to be transformed to a byte array.
for(count = 0; count < 16; count++) {
sscanf(pos, "%2hhx", &plain[count]);
pos += 2;
}
/*char *pos = m3;
for (count = 0; count < 16; count++) {
if (count % 2 == 0){
plain[count] = 0x74;
}else{
plain[count] = 0x65;
}
}*/
//char *key = "30766572636C306B40646F6172652D65";//"0vercl0k@doare-e";//"The Key";
aes128_enc_wb_final(plain, out);
//char* output_str = "OUTPUT: ";
//printf("%s", output_str);
for (i = 0; i < 16; i++)
//printf("%16X", out);
printf("%02X", out[i]);
//printf("\n");
//int aux;
/*for ( aux = 0; aux < 16; ++aux) {
out2[aux] = out[aux];
}*/
return out;
}