Skip to content

Commit 6e3447b

Browse files
authored
Fix AES decryption on ARM (#175)
* fix #174
1 parent 09abfe6 commit 6e3447b

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

emp-tool/utils/block.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ inline __m128i _mm_aesimc_si128(__m128i a) {
1010
}
1111
inline __m128i _mm_aesdec_si128 (__m128i a, __m128i RoundKey)
1212
{
13-
return vreinterpretq_m128i_u8(vaesimcq_u8(vaesdq_u8(vreinterpretq_u8_m128i(a), vdupq_n_u8(0)) ^ vreinterpretq_u8_m128i(RoundKey)));
13+
return vreinterpretq_m128i_u8(vaesimcq_u8(vaesdq_u8(vreinterpretq_u8_m128i(a), vdupq_n_u8(0))) ^ vreinterpretq_u8_m128i(RoundKey));
1414
}
1515

1616
inline __m128i _mm_aesdeclast_si128 (__m128i a, __m128i RoundKey)
@@ -70,7 +70,7 @@ inline std::ostream& operator<<(std::ostream& out, const block& blk) {
7070
out << std::hex;
7171
uint64_t* data = (uint64_t*)&blk;
7272

73-
out << std::setw(16) << std::setfill('0') << data[1]
73+
out << std::setw(16) << std::setfill('0') << data[1] <<" "
7474
<< std::setw(16) << std::setfill('0') << data[0];
7575

7676
out << std::dec << std::setw(0);

test/aes_opt.cpp

+11-3
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,25 @@ int main() {
1515
error("AES test fail!");
1616
}
1717
}
18-
cout <<"all tests pass!\n";
1918

2019
block key = makeBlock(0x0f0e0d0c0b0a0908, 0x0706050403020100);
2120
block msg = makeBlock(0xffeeddccbbaa9988, 0x7766554433221100);
21+
cout << "message:"<<msg<<endl;
2222
block res = makeBlock(0x5ac5b47080b7cdd8, 0x30047b6ad8e0c469);//https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.197.pdf page 36
2323
AES_KEY KEY[2];
2424
AES_set_encrypt_key(key, KEY);
2525
AES_ecb_encrypt_blks(&msg, 1, KEY);
2626
if(!cmpBlock(&msg, &res, 1)) {
27-
error("AES test vector fail!");
27+
error("AES Enc test vector fail!");
28+
}
29+
cout << "ciphertext:"<<msg<<endl;
30+
AES_set_decrypt_key(key, KEY);
31+
AES_ecb_decrypt_blks(&msg, 1, KEY);
32+
block original_msg = makeBlock(0xffeeddccbbaa9988, 0x7766554433221100);
33+
if(!cmpBlock(&msg, &original_msg, 1)) {
34+
error("AES Dec test vector fail!");
2835
}
36+
cout << "decrypted:"<<msg<<endl;
2937

3038
block msg2[2];
3139
msg2[0] = msg2[1] = makeBlock(0xffeeddccbbaa9988, 0x7766554433221100);
@@ -42,7 +50,7 @@ int main() {
4250
error("AES test vector fail!");
4351
}
4452

45-
53+
cout <<"all tests pass!\n";
4654

4755
return 0;
4856
}

0 commit comments

Comments
 (0)