只做了一个,之后再复现其它的

x64extenshion

用指令集自写了一个aes

先动态调试出加密的轮密钥,然后算出解密密钥直接出

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
#include <wmmintrin.h>
#include<stdio.h>
#include <stdint.h>

void aes_encrypt_array(__m128i* data, int num_elements, __m128i* rkeys) {
unsigned char key1[] = { 0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8, 0xF7, 0xF6, 0xF5, 0xF4, 0xF3, 0xF2, 0xF1, 0xF0 };
unsigned char key2[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F };

__m128i key1_m128i = _mm_loadu_si128((__m128i*)key1);
__m128i key2_m128i = _mm_loadu_si128((__m128i*)key2);

for (int index = 0; index < num_elements; ++index) {
__m128i state = _mm_loadu_si128(&data[index]);

if (index == 0) {
state = _mm_xor_si128(state, _mm_xor_si128(key1_m128i, key2_m128i));
}
else {
__m128i previous_encrypted = _mm_loadu_si128(&data[index - 1]);
state = _mm_xor_si128(state, _mm_xor_si128(previous_encrypted, key2_m128i));
}

for (int i = 0; i < 13; ++i) {
state = _mm_aesenc_si128(state, rkeys[i]);
}

state = _mm_aesenclast_si128(state, rkeys[13]);

_mm_storeu_si128(&data[index], state);
}
}
void aes_decrypt_array(__m128i* data, int num_elements, __m128i* rkeys) {
unsigned char key1[] = { 0xFF, 0xFE, 0xFD, 0xFC, 0xFB, 0xFA, 0xF9, 0xF8, 0xF7, 0xF6, 0xF5, 0xF4, 0xF3, 0xF2, 0xF1, 0xF0 };
unsigned char key2[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F };

__m128i key1_m128i = _mm_loadu_si128((__m128i*)key1);
__m128i key2_m128i = _mm_loadu_si128((__m128i*)key2);
__m128i initial_key = _mm_xor_si128(key1_m128i, key2_m128i);

for (int index = num_elements - 1; index >= 0; --index) {
__m128i state = _mm_loadu_si128(&data[index]);
state = _mm_xor_si128(state, rkeys[13]);

for (int i = 12; i >= 0; --i) {
state = _mm_aesdec_si128(state, rkeys[i]);
}

if (index == 0) {
state = _mm_aesdeclast_si128(state, initial_key);
}
else {
__m128i previous_encrypted = _mm_loadu_si128(&data[index - 1]);
__m128i temp_key = _mm_xor_si128(previous_encrypted, key2_m128i);
state = _mm_aesdeclast_si128(state, temp_key);
}

_mm_storeu_si128(&data[index], state);
}
}




void generateDecryptionKeys(const __m128i* encryptionKeys, __m128i* decryptionKeys, int nr) {
decryptionKeys[nr - 1] = encryptionKeys[nr - 1];

for (int i = 0; i < nr - 1; ++i) {
decryptionKeys[i] = _mm_aesimc_si128(encryptionKeys[i]);
}
}
int main(void) {
unsigned char ciphers[] = { 0x15,0x2a,0x38,0x82,0xcd,0x8a,0x36,0x33,0x54,0x4d,0x22,0x66,0x5c,0xe5,0x8a,0xea,0x1c,0xb2,0x5d,0xb2,0x59,0x64,0x7a,0x7e,0x6d,0x70,0x21,0x2a,0xdd,0x24,0x6b,0x8e,0x38,0x11,0x45,0xa3,0x60,0x3d,0xca,0x8f,0x12,0xb6,0xec,0x9c,0x0f,0x60,0xd9,0x26,0xe9,0x2c,0x83,0x9f,0x61,0x70,0x0f,0xdc,0x78,0x92,0x59,0x39,0x48,0xc1,0xe7,0xc2,0x6b,0x5c,0xba,0x1c,0x43,0xc2,0x86,0x80,0x18,0x62,0x15,0xd2,0x1e,0x0b,0x6b,0x9e,0x17,0x2c,0x14,0xc7,0x41,0x10,0xc4,0x35,0xfe,0x78,0x6f,0xb4,0xfc,0xd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x73, 0x89, 0x96, 0x10,
0xDA, 0x45, 0x2A, 0x58, 0xB8, 0x02, 0xDF, 0x64, 0x58, 0xBD, 0xC1, 0x37, 0x93, 0xBA, 0x8E, 0xD5,
0x87, 0xCB, 0x8C, 0x7E, 0xC6, 0xBE, 0x0F, 0xB5, 0xEA, 0xE2, 0x55, 0x50, 0x99, 0x6B, 0xC3, 0x40,
0x34, 0x3A, 0x04, 0x51, 0x8C, 0x38, 0xDB, 0x35, 0xD4, 0x85, 0x1A, 0x02, 0x47, 0x3F, 0x94, 0xD7,
0xA7, 0xE9, 0x82, 0xDE, 0x61, 0x57, 0x8D, 0x6B, 0x8B, 0xB5, 0xD8, 0x3B, 0x12, 0xDE, 0x1B, 0x7B,
0xFD, 0x27, 0xAB, 0x70, 0x71, 0x1F, 0x70, 0x45, 0xA5, 0x9A, 0x6A, 0x47, 0xE2, 0xA5, 0xFE, 0x90,
0xC7, 0x52, 0xE2, 0x46, 0xA6, 0x05, 0x6F, 0x2D, 0x2D, 0xB0, 0xB7, 0x16, 0x3F, 0x6E, 0xAC, 0x6D };
uint8_t decryption_keys[224];
generateDecryptionKeys((__m128i*)rkeys, (__m128i*)decryption_keys, 14);
aes_decrypt_array((__m128i*)ciphers, 10, (__m128i*)decryption_keys);
ciphers[159] = '\0';
printf("%s", ciphers);
}