📄 aes.cpp
字号:
Td0[GETBYTE(get1, rs24)] ^
Td1[GETBYTE(get0, rs16)] ^
Td2[GETBYTE(get3, rs 8)] ^
Td3[GETBYTE(tet2, )]
*/
AS2( mov esi, ebx )
AS2( shr esi, 24 )
AS2( mov esi, DWORD PTR [ebp + esi*4] )
AS2( mov edi, eax )
AS2( shr edi, 16 )
AS2( and edi, 255 )
AS2( xor esi, DWORD PTR [ebp + 1024 + edi*4] )
AS2( movzx edi, dh )
AS2( xor esi, DWORD PTR [ebp + 2048 + edi*4] )
AS2( movzx edi, cl )
AS2( xor esi, DWORD PTR [ebp + 3072 + edi*4] )
AS2( movd mm1, esi )
/* Put2 (mm2) =
Td0[GETBYTE(get2, rs24)] ^
Td1[GETBYTE(get1, rs16)] ^
Td2[GETBYTE(get0, rs 8)] ^
Td3[GETBYTE(tet3, )]
*/
AS2( mov esi, ecx )
AS2( shr esi, 24 )
AS2( mov esi, DWORD PTR [ebp + esi*4] )
AS2( mov edi, ebx )
AS2( shr edi, 16 )
AS2( and edi, 255 )
AS2( xor esi, DWORD PTR [ebp + 1024 + edi*4] )
AS2( movzx edi, ah )
AS2( xor esi, DWORD PTR [ebp + 2048 + edi*4] )
AS2( movzx edi, dl )
AS2( xor esi, DWORD PTR [ebp + 3072 + edi*4] )
AS2( movd mm2, esi )
/* Put3 (edx) =
Td0[GETBYTE(get3, rs24)] ^
Td1[GETBYTE(get2, rs16)] ^
Td2[GETBYTE(get1, rs 8)] ^
Td3[GETBYTE(tet0, )]
*/
AS2( mov esi, edx )
AS2( shr esi, 24 )
AS2( mov edx, DWORD PTR [ebp + esi*4] )
AS2( mov edi, ecx )
AS2( shr edi, 16 )
AS2( and edi, 255 )
AS2( xor edx, DWORD PTR [ebp + 1024 + edi*4] )
AS2( movzx esi, bh )
AS2( xor edx, DWORD PTR [ebp + 2048 + esi*4] )
AS2( movzx edi, al )
AS2( xor edx, DWORD PTR [ebp + 3072 + edi*4] )
// xOr
AS2( movd esi, mm6 ) // rk
AS2( add esi, 16 )
AS2( movd mm6, esi ) // save back
AS2( movd eax, mm0 )
AS2( movd ebx, mm1 )
AS2( movd ecx, mm2 )
AS2( xor eax, DWORD PTR [esi] )
AS2( xor ebx, DWORD PTR [esi + 4] )
AS2( xor ecx, DWORD PTR [esi + 8] )
AS2( xor edx, DWORD PTR [esi + 12] )
AS2( movd edi, mm5 )
AS1( dec edi )
AS2( movd mm5, edi )
AS1( jnz loop2 )
// last round
/*
Put0 (mm0) =
(Td4[get0, rs24] & 0xff000000) ^ h = 4278190080
(Td4[get3, rs16] & 0x00ff0000) ^ h = 16711680
(Td4[get2, rs 8] & 0x0000ff00) ^ h = 65280
(Td4[get1, rs 0] & 0x000000ff) h = 255
*/
AS2( mov esi, eax )
AS2( shr esi, 24 )
AS2( mov esi, DWORD PTR [ebp + 4096 + esi*4] )
AS2( and esi, 4278190080 )
AS2( mov edi, edx )
AS2( shr edi, 16 )
AS2( and edi, 255 )
AS2( mov edi, DWORD PTR [ebp + 4096 + edi*4] )
AS2( and edi, 16711680 )
AS2( xor esi, edi )
AS2( movzx edi, ch )
AS2( mov edi, DWORD PTR [ebp + 4096 + edi*4] )
AS2( and edi, 65280 )
AS2( xor esi, edi )
AS2( movzx edi, bl )
AS2( mov edi, DWORD PTR [ebp + 4096 + edi*4] )
AS2( and edi, 255 )
AS2( xor esi, edi )
AS2( movd mm0, esi )
/*
Put1 (mm1) =
(Td4[get1, rs24] & 0xff000000) ^ h = 4278190080
(Td4[get0, rs16] & 0x00ff0000) ^ h = 16711680
(Td4[get3, rs 8] & 0x0000ff00) ^ h = 65280
(Td4[get2, rs 0] & 0x000000ff) h = 255
*/
AS2( mov esi, ebx )
AS2( shr esi, 24 )
AS2( mov esi, DWORD PTR [ebp + 4096 + esi*4] )
AS2( and esi, 4278190080 )
AS2( mov edi, eax )
AS2( shr edi, 16 )
AS2( and edi, 255 )
AS2( mov edi, DWORD PTR [ebp + 4096 + edi*4] )
AS2( and edi, 16711680 )
AS2( xor esi, edi )
AS2( movzx edi, dh )
AS2( mov edi, DWORD PTR [ebp + 4096 + edi*4] )
AS2( and edi, 65280 )
AS2( xor esi, edi )
AS2( movzx edi, cl )
AS2( mov edi, DWORD PTR [ebp + 4096 + edi*4] )
AS2( and edi, 255 )
AS2( xor esi, edi )
AS2( movd mm1, esi )
/*
Put2 (mm2) =
(Td4[get2, rs24] & 0xff000000) ^ h = 4278190080
(Td4[get1, rs16] & 0x00ff0000) ^ h = 16711680
(Td4[get0, rs 8] & 0x0000ff00) ^ h = 65280
(Td4[get3, rs 0] & 0x000000ff) h = 255
*/
AS2( mov esi, ecx )
AS2( shr esi, 24 )
AS2( mov esi, DWORD PTR [ebp + 4096 + esi*4] )
AS2( and esi, 4278190080 )
AS2( mov edi, ebx )
AS2( shr edi, 16 )
AS2( and edi, 255 )
AS2( mov edi, DWORD PTR [ebp + 4096 + edi*4] )
AS2( and edi, 16711680 )
AS2( xor esi, edi )
AS2( movzx edi, ah )
AS2( mov edi, DWORD PTR [ebp + 4096 + edi*4] )
AS2( and edi, 65280 )
AS2( xor esi, edi )
AS2( movzx edi, dl )
AS2( mov edi, DWORD PTR [ebp + 4096 + edi*4] )
AS2( and edi, 255 )
AS2( xor esi, edi )
AS2( movd mm2, esi )
/*
Put3 (edx) =
(Td4[get3, rs24] & 0xff000000) ^ h = 4278190080
(Td4[get2, rs16] & 0x00ff0000) ^ h = 16711680
(Td4[get1, rs 8] & 0x0000ff00) ^ h = 65280
(Td4[get0, rs 0] & 0x000000ff) h = 255
*/
AS2( mov esi, edx )
AS2( shr esi, 24 )
AS2( mov edx, DWORD PTR [ebp + 4096 + esi*4] )
AS2( and edx, 4278190080 )
AS2( mov edi, ecx )
AS2( shr edi, 16 )
AS2( and edi, 255 )
AS2( mov esi, DWORD PTR [ebp + 4096 + edi*4] )
AS2( and esi, 16711680 )
AS2( xor edx, esi )
AS2( movzx esi, bh )
AS2( mov edi, DWORD PTR [ebp + 4096 + esi*4] )
AS2( and edi, 65280 )
AS2( xor edx, edi )
AS2( movzx edi, al )
AS2( mov esi, DWORD PTR [ebp + 4096 + edi*4] )
AS2( and esi, 255 )
AS2( xor edx, esi )
// xOr
AS2( movd esi, mm6 ) // rk
AS2( add esi, 16 )
AS2( movd eax, mm0 )
AS2( movd ebx, mm1 )
AS2( movd ecx, mm2 )
AS2( xor eax, DWORD PTR [esi] )
AS2( xor ebx, DWORD PTR [esi + 4] )
AS2( xor ecx, DWORD PTR [esi + 8] )
AS2( xor edx, DWORD PTR [esi + 12] )
// end
AS2( movd ebp, mm7 )
// swap
AS1( bswap eax )
AS1( bswap ebx )
AS1( bswap ecx )
AS1( bswap edx )
// store
#ifdef __GNUC__
AS2( mov esi, DWORD PTR [ebp + 16] ) // outBlock
#else
AS2( mov esi, DWORD PTR [ebp + 12] ) // outBlock
#endif
AS2( mov DWORD PTR [esi], eax )
AS2( mov DWORD PTR [esi + 4], ebx )
AS2( mov DWORD PTR [esi + 8], ecx )
AS2( mov DWORD PTR [esi + 12], edx )
EPILOG()
}
#endif // defined(DO_AES_ASM)
const word32 AES::Te[5][256] = {
{
0xc66363a5U, 0xf87c7c84U, 0xee777799U, 0xf67b7b8dU,
0xfff2f20dU, 0xd66b6bbdU, 0xde6f6fb1U, 0x91c5c554U,
0x60303050U, 0x02010103U, 0xce6767a9U, 0x562b2b7dU,
0xe7fefe19U, 0xb5d7d762U, 0x4dababe6U, 0xec76769aU,
0x8fcaca45U, 0x1f82829dU, 0x89c9c940U, 0xfa7d7d87U,
0xeffafa15U, 0xb25959ebU, 0x8e4747c9U, 0xfbf0f00bU,
0x41adadecU, 0xb3d4d467U, 0x5fa2a2fdU, 0x45afafeaU,
0x239c9cbfU, 0x53a4a4f7U, 0xe4727296U, 0x9bc0c05bU,
0x75b7b7c2U, 0xe1fdfd1cU, 0x3d9393aeU, 0x4c26266aU,
0x6c36365aU, 0x7e3f3f41U, 0xf5f7f702U, 0x83cccc4fU,
0x6834345cU, 0x51a5a5f4U, 0xd1e5e534U, 0xf9f1f108U,
0xe2717193U, 0xabd8d873U, 0x62313153U, 0x2a15153fU,
0x0804040cU, 0x95c7c752U, 0x46232365U, 0x9dc3c35eU,
0x30181828U, 0x379696a1U, 0x0a05050fU, 0x2f9a9ab5U,
0x0e070709U, 0x24121236U, 0x1b80809bU, 0xdfe2e23dU,
0xcdebeb26U, 0x4e272769U, 0x7fb2b2cdU, 0xea75759fU,
0x1209091bU, 0x1d83839eU, 0x582c2c74U, 0x341a1a2eU,
0x361b1b2dU, 0xdc6e6eb2U, 0xb45a5aeeU, 0x5ba0a0fbU,
0xa45252f6U, 0x763b3b4dU, 0xb7d6d661U, 0x7db3b3ceU,
0x5229297bU, 0xdde3e33eU, 0x5e2f2f71U, 0x13848497U,
0xa65353f5U, 0xb9d1d168U, 0x00000000U, 0xc1eded2cU,
0x40202060U, 0xe3fcfc1fU, 0x79b1b1c8U, 0xb65b5bedU,
0xd46a6abeU, 0x8dcbcb46U, 0x67bebed9U, 0x7239394bU,
0x944a4adeU, 0x984c4cd4U, 0xb05858e8U, 0x85cfcf4aU,
0xbbd0d06bU, 0xc5efef2aU, 0x4faaaae5U, 0xedfbfb16U,
0x864343c5U, 0x9a4d4dd7U, 0x66333355U, 0x11858594U,
0x8a4545cfU, 0xe9f9f910U, 0x04020206U, 0xfe7f7f81U,
0xa05050f0U, 0x783c3c44U, 0x259f9fbaU, 0x4ba8a8e3U,
0xa25151f3U, 0x5da3a3feU, 0x804040c0U, 0x058f8f8aU,
0x3f9292adU, 0x219d9dbcU, 0x70383848U, 0xf1f5f504U,
0x63bcbcdfU, 0x77b6b6c1U, 0xafdada75U, 0x42212163U,
0x20101030U, 0xe5ffff1aU, 0xfdf3f30eU, 0xbfd2d26dU,
0x81cdcd4cU, 0x180c0c14U, 0x26131335U, 0xc3ecec2fU,
0xbe5f5fe1U, 0x359797a2U, 0x884444ccU, 0x2e171739U,
0x93c4c457U, 0x55a7a7f2U, 0xfc7e7e82U, 0x7a3d3d47U,
0xc86464acU, 0xba5d5de7U, 0x3219192bU, 0xe6737395U,
0xc06060a0U, 0x19818198U, 0x9e4f4fd1U, 0xa3dcdc7fU,
0x44222266U, 0x542a2a7eU, 0x3b9090abU, 0x0b888883U,
0x8c4646caU, 0xc7eeee29U, 0x6bb8b8d3U, 0x2814143cU,
0xa7dede79U, 0xbc5e5ee2U, 0x160b0b1dU, 0xaddbdb76U,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -