2 ; ---------------------------------------------------------------------------
3 ; Copyright (c) 1998-2007, Brian Gladman, Worcester, UK. All rights reserved.
7 ; The free distribution and use of this software is allowed (with or without
8 ; changes) provided that:
10 ; 1. source code distributions include the above copyright notice, this
11 ; list of conditions and the following disclaimer;
13 ; 2. binary distributions include the above copyright notice, this list
14 ; of conditions and the following disclaimer in their documentation;
16 ; 3. the name of the copyright holder is not used to endorse products
17 ; built using this software without specific written permission.
21 ; This software is provided 'as is' with no explicit or implied warranties
22 ; in respect of its properties, including, but not limited to, correctness
23 ; and/or fitness for purpose.
24 ; ---------------------------------------------------------------------------
27 ; I am grateful to Dag Arne Osvik for many discussions of the techniques that
28 ; can be used to optimise AES assembler code on AMD64/EM64T architectures.
29 ; Some of the techniques used in this implementation are the result of
30 ; suggestions made by him for which I am most grateful.
32 ; An AES implementation for AMD64 processors using the YASM assembler. This
33 ; implemetation provides only encryption, decryption and hence requires key
34 ; scheduling support in C. It uses 8k bytes of tables but its encryption and
35 ; decryption performance is very close to that obtained using large tables.
36 ; It can use either Windows or Gnu/Linux calling conventions, which are as
44 ; preserved rsi - + rbx, rbp, rsp, r12, r13, r14 & r15
45 ; registers rdi - on both
47 ; destroyed - rsi + rax, rcx, rdx, r8, r9, r10 & r11
48 ; registers - rdi on both
50 ; The default convention is that for windows, the gnu/linux convention being
51 ; used if __GNUC__ is defined.
53 ; Define _SEH_ to include support for Win64 structured exception handling
54 ; (this requires YASM version 0.6 or later).
56 ; This code provides the standard AES block size (128 bits, 16 bytes) and the
57 ; three standard AES key sizes (128, 192 and 256 bits). It has the same call
58 ; interface as my C implementation. It uses the Microsoft C AMD64 calling
59 ; conventions in which the three parameters are placed in rcx, rdx and r8
60 ; respectively. The rbx, rsi, rdi, rbp and r12..r15 registers are preserved.
62 ; AES_RETURN aes_encrypt(const unsigned char in_blk[],
63 ; unsigned char out_blk[], const aes_encrypt_ctx cx[1]);
65 ; AES_RETURN aes_decrypt(const unsigned char in_blk[],
66 ; unsigned char out_blk[], const aes_decrypt_ctx cx[1]);
68 ; AES_RETURN aes_encrypt_key<NNN>(const unsigned char key[],
69 ; const aes_encrypt_ctx cx[1]);
71 ; AES_RETURN aes_decrypt_key<NNN>(const unsigned char key[],
72 ; const aes_decrypt_ctx cx[1]);
74 ; AES_RETURN aes_encrypt_key(const unsigned char key[],
75 ; unsigned int len, const aes_decrypt_ctx cx[1]);
77 ; AES_RETURN aes_decrypt_key(const unsigned char key[],
78 ; unsigned int len, const aes_decrypt_ctx cx[1]);
80 ; where <NNN> is 128, 102 or 256. In the last two calls the length can be in
81 ; either bits or bytes.
83 ; Comment in/out the following lines to obtain the desired subroutines. These
84 ; selections MUST match those in the C header file aes.h
86 ; %define AES_128 ; define if AES with 128 bit keys is needed
87 ; %define AES_192 ; define if AES with 192 bit keys is needed
88 %define AES_256
; define if AES with 256 bit keys is needed
89 ; %define AES_VAR ; define if a variable key size is needed
90 %define ENCRYPTION
; define if encryption is needed
91 %define DECRYPTION
; define if decryption is needed
92 %define AES_REV_DKS
; define if key decryption schedule is reversed
93 %define LAST_ROUND_TABLES
; define for the faster version using extra tables
95 ; The encryption key schedule has the following in memory layout where N is the
96 ; number of rounds (10, 12 or 14):
98 ; lo: | input key (round 0) | ; each round is four 32-bit words
99 ; | encryption round 1 |
100 ; | encryption round 2 |
102 ; | encryption round N-1 |
103 ; hi: | encryption round N |
105 ; The decryption key schedule is normally set up so that it has the same
106 ; layout as above by actually reversing the order of the encryption key
107 ; schedule in memory (this happens when AES_REV_DKS is set):
109 ; lo: | decryption round 0 | = | encryption round N |
110 ; | decryption round 1 | = INV_MIX_COL[ | encryption round N-1 | ]
111 ; | decryption round 2 | = INV_MIX_COL[ | encryption round N-2 | ]
113 ; | decryption round N-1 | = INV_MIX_COL[ | encryption round 1 | ]
114 ; hi: | decryption round N | = | input key (round 0) |
116 ; with rounds except the first and last modified using inv_mix_column()
117 ; But if AES_REV_DKS is NOT set the order of keys is left as it is for
118 ; encryption so that it has to be accessed in reverse when used for
119 ; decryption (although the inverse mix column modifications are done)
121 ; lo: | decryption round 0 | = | input key (round 0) |
122 ; | decryption round 1 | = INV_MIX_COL[ | encryption round 1 | ]
123 ; | decryption round 2 | = INV_MIX_COL[ | encryption round 2 | ]
125 ; | decryption round N-1 | = INV_MIX_COL[ | encryption round N-1 | ]
126 ; hi: | decryption round N | = | encryption round N |
128 ; This layout is faster when the assembler key scheduling provided here
131 ; The DLL interface must use the _stdcall convention in which the number
132 ; of bytes of parameter space is added after an @ to the sutine's name.
133 ; We must also remove our parameters from the stack before return (see
134 ; the do_exit macro). Define DLL_EXPORT for the Dynamic Link Library version.
138 ; End of user defines
199 ; finite field multiplies by {02}, {04} and {08}
201 %define f2
(x
) ((x
<<1)^
(((x
>>7)&1)*0x11b))
202 %define f4
(x
) ((x
<<2)^
(((x
>>6)&1)*0x11b)^
(((x
>>6)&2)*0x11b))
203 %define f8
(x
) ((x
<<3)^
(((x
>>5)&1)*0x11b)^
(((x
>>5)&2)*0x11b)^
(((x
>>5)&4)*0x11b))
205 ; finite field multiplies required in table generation
207 %define f3
(x
) (f2
(x
) ^ x
)
208 %define f9
(x
) (f8
(x
) ^ x
)
209 %define fb
(x
) (f8
(x
) ^ f2
(x
) ^ x
)
210 %define fd
(x
) (f8
(x
) ^ f4
(x
) ^ x
)
211 %define fe
(x
) (f8
(x
) ^ f4
(x
) ^ f2
(x
))
213 ; macro for expanding S-box data
216 db %1(0x63),%1(0x7c),%1(0x77),%1(0x7b),%1(0xf2),%1(0x6b),%1(0x6f),%1(0xc5)
217 db %1(0x30),%1(0x01),%1(0x67),%1(0x2b),%1(0xfe),%1(0xd7),%1(0xab),%1(0x76)
218 db %1(0xca),%1(0x82),%1(0xc9),%1(0x7d),%1(0xfa),%1(0x59),%1(0x47),%1(0xf0)
219 db %1(0xad),%1(0xd4),%1(0xa2),%1(0xaf),%1(0x9c),%1(0xa4),%1(0x72),%1(0xc0)
220 db %1(0xb7),%1(0xfd),%1(0x93),%1(0x26),%1(0x36),%1(0x3f),%1(0xf7),%1(0xcc)
221 db %1(0x34),%1(0xa5),%1(0xe5),%1(0xf1),%1(0x71),%1(0xd8),%1(0x31),%1(0x15)
222 db %1(0x04),%1(0xc7),%1(0x23),%1(0xc3),%1(0x18),%1(0x96),%1(0x05),%1(0x9a)
223 db %1(0x07),%1(0x12),%1(0x80),%1(0xe2),%1(0xeb),%1(0x27),%1(0xb2),%1(0x75)
224 db %1(0x09),%1(0x83),%1(0x2c),%1(0x1a),%1(0x1b),%1(0x6e),%1(0x5a),%1(0xa0)
225 db %1(0x52),%1(0x3b),%1(0xd6),%1(0xb3),%1(0x29),%1(0xe3),%1(0x2f),%1(0x84)
226 db %1(0x53),%1(0xd1),%1(0x00),%1(0xed),%1(0x20),%1(0xfc),%1(0xb1),%1(0x5b)
227 db %1(0x6a),%1(0xcb),%1(0xbe),%1(0x39),%1(0x4a),%1(0x4c),%1(0x58),%1(0xcf)
228 db %1(0xd0),%1(0xef),%1(0xaa),%1(0xfb),%1(0x43),%1(0x4d),%1(0x33),%1(0x85)
229 db %1(0x45),%1(0xf9),%1(0x02),%1(0x7f),%1(0x50),%1(0x3c),%1(0x9f),%1(0xa8)
230 db %1(0x51),%1(0xa3),%1(0x40),%1(0x8f),%1(0x92),%1(0x9d),%1(0x38),%1(0xf5)
231 db %1(0xbc),%1(0xb6),%1(0xda),%1(0x21),%1(0x10),%1(0xff),%1(0xf3),%1(0xd2)
232 db %1(0xcd),%1(0x0c),%1(0x13),%1(0xec),%1(0x5f),%1(0x97),%1(0x44),%1(0x17)
233 db %1(0xc4),%1(0xa7),%1(0x7e),%1(0x3d),%1(0x64),%1(0x5d),%1(0x19),%1(0x73)
234 db %1(0x60),%1(0x81),%1(0x4f),%1(0xdc),%1(0x22),%1(0x2a),%1(0x90),%1(0x88)
235 db %1(0x46),%1(0xee),%1(0xb8),%1(0x14),%1(0xde),%1(0x5e),%1(0x0b),%1(0xdb)
236 db %1(0xe0),%1(0x32),%1(0x3a),%1(0x0a),%1(0x49),%1(0x06),%1(0x24),%1(0x5c)
237 db %1(0xc2),%1(0xd3),%1(0xac),%1(0x62),%1(0x91),%1(0x95),%1(0xe4),%1(0x79)
238 db %1(0xe7),%1(0xc8),%1(0x37),%1(0x6d),%1(0x8d),%1(0xd5),%1(0x4e),%1(0xa9)
239 db %1(0x6c),%1(0x56),%1(0xf4),%1(0xea),%1(0x65),%1(0x7a),%1(0xae),%1(0x08)
240 db %1(0xba),%1(0x78),%1(0x25),%1(0x2e),%1(0x1c),%1(0xa6),%1(0xb4),%1(0xc6)
241 db %1(0xe8),%1(0xdd),%1(0x74),%1(0x1f),%1(0x4b),%1(0xbd),%1(0x8b),%1(0x8a)
242 db %1(0x70),%1(0x3e),%1(0xb5),%1(0x66),%1(0x48),%1(0x03),%1(0xf6),%1(0x0e)
243 db %1(0x61),%1(0x35),%1(0x57),%1(0xb9),%1(0x86),%1(0xc1),%1(0x1d),%1(0x9e)
244 db %1(0xe1),%1(0xf8),%1(0x98),%1(0x11),%1(0x69),%1(0xd9),%1(0x8e),%1(0x94)
245 db %1(0x9b),%1(0x1e),%1(0x87),%1(0xe9),%1(0xce),%1(0x55),%1(0x28),%1(0xdf)
246 db %1(0x8c),%1(0xa1),%1(0x89),%1(0x0d),%1(0xbf),%1(0xe6),%1(0x42),%1(0x68)
247 db %1(0x41),%1(0x99),%1(0x2d),%1(0x0f),%1(0xb0),%1(0x54),%1(0xbb),%1(0x16)
251 db %1(0x52),%1(0x09),%1(0x6a),%1(0xd5),%1(0x30),%1(0x36),%1(0xa5),%1(0x38)
252 db %1(0xbf),%1(0x40),%1(0xa3),%1(0x9e),%1(0x81),%1(0xf3),%1(0xd7),%1(0xfb)
253 db %1(0x7c),%1(0xe3),%1(0x39),%1(0x82),%1(0x9b),%1(0x2f),%1(0xff),%1(0x87)
254 db %1(0x34),%1(0x8e),%1(0x43),%1(0x44),%1(0xc4),%1(0xde),%1(0xe9),%1(0xcb)
255 db %1(0x54),%1(0x7b),%1(0x94),%1(0x32),%1(0xa6),%1(0xc2),%1(0x23),%1(0x3d)
256 db %1(0xee),%1(0x4c),%1(0x95),%1(0x0b),%1(0x42),%1(0xfa),%1(0xc3),%1(0x4e)
257 db %1(0x08),%1(0x2e),%1(0xa1),%1(0x66),%1(0x28),%1(0xd9),%1(0x24),%1(0xb2)
258 db %1(0x76),%1(0x5b),%1(0xa2),%1(0x49),%1(0x6d),%1(0x8b),%1(0xd1),%1(0x25)
259 db %1(0x72),%1(0xf8),%1(0xf6),%1(0x64),%1(0x86),%1(0x68),%1(0x98),%1(0x16)
260 db %1(0xd4),%1(0xa4),%1(0x5c),%1(0xcc),%1(0x5d),%1(0x65),%1(0xb6),%1(0x92)
261 db %1(0x6c),%1(0x70),%1(0x48),%1(0x50),%1(0xfd),%1(0xed),%1(0xb9),%1(0xda)
262 db %1(0x5e),%1(0x15),%1(0x46),%1(0x57),%1(0xa7),%1(0x8d),%1(0x9d),%1(0x84)
263 db %1(0x90),%1(0xd8),%1(0xab),%1(0x00),%1(0x8c),%1(0xbc),%1(0xd3),%1(0x0a)
264 db %1(0xf7),%1(0xe4),%1(0x58),%1(0x05),%1(0xb8),%1(0xb3),%1(0x45),%1(0x06)
265 db %1(0xd0),%1(0x2c),%1(0x1e),%1(0x8f),%1(0xca),%1(0x3f),%1(0x0f),%1(0x02)
266 db %1(0xc1),%1(0xaf),%1(0xbd),%1(0x03),%1(0x01),%1(0x13),%1(0x8a),%1(0x6b)
267 db %1(0x3a),%1(0x91),%1(0x11),%1(0x41),%1(0x4f),%1(0x67),%1(0xdc),%1(0xea)
268 db %1(0x97),%1(0xf2),%1(0xcf),%1(0xce),%1(0xf0),%1(0xb4),%1(0xe6),%1(0x73)
269 db %1(0x96),%1(0xac),%1(0x74),%1(0x22),%1(0xe7),%1(0xad),%1(0x35),%1(0x85)
270 db %1(0xe2),%1(0xf9),%1(0x37),%1(0xe8),%1(0x1c),%1(0x75),%1(0xdf),%1(0x6e)
271 db %1(0x47),%1(0xf1),%1(0x1a),%1(0x71),%1(0x1d),%1(0x29),%1(0xc5),%1(0x89)
272 db %1(0x6f),%1(0xb7),%1(0x62),%1(0x0e),%1(0xaa),%1(0x18),%1(0xbe),%1(0x1b)
273 db %1(0xfc),%1(0x56),%1(0x3e),%1(0x4b),%1(0xc6),%1(0xd2),%1(0x79),%1(0x20)
274 db %1(0x9a),%1(0xdb),%1(0xc0),%1(0xfe),%1(0x78),%1(0xcd),%1(0x5a),%1(0xf4)
275 db %1(0x1f),%1(0xdd),%1(0xa8),%1(0x33),%1(0x88),%1(0x07),%1(0xc7),%1(0x31)
276 db %1(0xb1),%1(0x12),%1(0x10),%1(0x59),%1(0x27),%1(0x80),%1(0xec),%1(0x5f)
277 db %1(0x60),%1(0x51),%1(0x7f),%1(0xa9),%1(0x19),%1(0xb5),%1(0x4a),%1(0x0d)
278 db %1(0x2d),%1(0xe5),%1(0x7a),%1(0x9f),%1(0x93),%1(0xc9),%1(0x9c),%1(0xef)
279 db %1(0xa0),%1(0xe0),%1(0x3b),%1(0x4d),%1(0xae),%1(0x2a),%1(0xf5),%1(0xb0)
280 db %1(0xc8),%1(0xeb),%1(0xbb),%1(0x3c),%1(0x83),%1(0x53),%1(0x99),%1(0x61)
281 db %1(0x17),%1(0x2b),%1(0x04),%1(0x7e),%1(0xba),%1(0x77),%1(0xd6),%1(0x26)
282 db %1(0xe1),%1(0x69),%1(0x14),%1(0x63),%1(0x55),%1(0x21),%1(0x0c),%1(0x7d)
285 %define u8
(x
) f2
(x
), x
, x
, f3
(x
), f2
(x
), x
, x
, f3
(x
)
286 %define v8
(x
) fe
(x
), f9
(x
), fd
(x
), fb
(x
), fe
(x
), f9
(x
), fd
(x
), x
287 %define w8
(x
) x
, 0, 0, 0, x
, 0, 0, 0
289 %define tptr rbp
; table pointer
290 %define kptr r8
; key schedule pointer
291 %define fofs
128 ; adjust offset in key schedule to keep |disp| < 128
292 %define fk_ref
(x
,y
) [kptr
-16*x
+fofs
+4*y
]
295 %define ik_ref
(x
,y
) [kptr
-16*x
+rofs
+4*y
]
298 %define ik_ref
(x
,y
) [kptr
+16*x
+rofs
+4*y
]
301 %define tab_0
(x
) [tptr
+8*x
]
302 %define tab_1
(x
) [tptr
+8*x
+3]
303 %define tab_2
(x
) [tptr
+8*x
+2]
304 %define tab_3
(x
) [tptr
+8*x
+1]
305 %define tab_f
(x
) byte [tptr
+8*x
+1]
306 %define tab_i
(x
) byte [tptr
+8*x
+7]
307 %define t_ref
(x
,r
) tab_
%+ x
(r
)
309 %macro ff_rnd
5 ; normal forward round
310 mov %1d
, fk_ref
(%5,0)
311 mov %2d
, fk_ref
(%5,1)
312 mov %3d
, fk_ref
(%5,2)
313 mov %4d
, fk_ref
(%5,3)
318 xor %1d
, t_ref
(0,rsi
)
319 xor %4d
, t_ref
(1,rdi
)
322 xor %3d
, t_ref
(2,rsi
)
323 xor %2d
, t_ref
(3,rdi
)
328 xor %2d
, t_ref
(0,rsi
)
329 xor %1d
, t_ref
(1,rdi
)
332 xor %4d
, t_ref
(2,rsi
)
333 xor %3d
, t_ref
(3,rdi
)
338 xor %3d
, t_ref
(0,rsi
)
339 xor %2d
, t_ref
(1,rdi
)
342 xor %1d
, t_ref
(2,rsi
)
343 xor %4d
, t_ref
(3,rdi
)
348 xor %4d
, t_ref
(0,rsi
)
349 xor %3d
, t_ref
(1,rdi
)
352 xor %2d
, t_ref
(2,rsi
)
353 xor %1d
, t_ref
(3,rdi
)
361 %ifdef LAST_ROUND_TABLES
363 %macro fl_rnd
5 ; last forward round
365 mov %1d
, fk_ref
(%5,0)
366 mov %2d
, fk_ref
(%5,1)
367 mov %3d
, fk_ref
(%5,2)
368 mov %4d
, fk_ref
(%5,3)
373 xor %1d
, t_ref
(0,rsi
)
374 xor %4d
, t_ref
(1,rdi
)
377 xor %3d
, t_ref
(2,rsi
)
378 xor %2d
, t_ref
(3,rdi
)
383 xor %2d
, t_ref
(0,rsi
)
384 xor %1d
, t_ref
(1,rdi
)
387 xor %4d
, t_ref
(2,rsi
)
388 xor %3d
, t_ref
(3,rdi
)
393 xor %3d
, t_ref
(0,rsi
)
394 xor %2d
, t_ref
(1,rdi
)
397 xor %1d
, t_ref
(2,rsi
)
398 xor %4d
, t_ref
(3,rdi
)
403 xor %4d
, t_ref
(0,rsi
)
404 xor %3d
, t_ref
(1,rdi
)
407 xor %2d
, t_ref
(2,rsi
)
408 xor %1d
, t_ref
(3,rdi
)
413 %macro fl_rnd
5 ; last forward round
414 mov %1d
, fk_ref
(%5,0)
415 mov %2d
, fk_ref
(%5,1)
416 mov %3d
, fk_ref
(%5,2)
417 mov %4d
, fk_ref
(%5,3)
422 movzx esi, t_ref
(f
,rsi
)
423 movzx edi, t_ref
(f
,rdi
)
429 movzx esi, t_ref
(f
,rsi
)
430 movzx edi, t_ref
(f
,rdi
)
439 movzx esi, t_ref
(f
,rsi
)
440 movzx edi, t_ref
(f
,rdi
)
446 movzx esi, t_ref
(f
,rsi
)
447 movzx edi, t_ref
(f
,rdi
)
455 movzx esi, t_ref
(f
,rsi
)
456 movzx edi, t_ref
(f
,rdi
)
463 movzx esi, t_ref
(f
,rsi
)
464 movzx edi, t_ref
(f
,rdi
)
472 movzx esi, t_ref
(f
,rsi
)
473 movzx edi, t_ref
(f
,rdi
)
480 movzx esi, t_ref
(f
,rsi
)
481 movzx edi, t_ref
(f
,rdi
)
490 %macro ii_rnd
5 ; normal inverse round
491 mov %1d
, ik_ref
(%5,0)
492 mov %2d
, ik_ref
(%5,1)
493 mov %3d
, ik_ref
(%5,2)
494 mov %4d
, ik_ref
(%5,3)
499 xor %1d
, t_ref
(0,rsi
)
500 xor %2d
, t_ref
(1,rdi
)
503 xor %3d
, t_ref
(2,rsi
)
504 xor %4d
, t_ref
(3,rdi
)
509 xor %2d
, t_ref
(0,rsi
)
510 xor %3d
, t_ref
(1,rdi
)
513 xor %4d
, t_ref
(2,rsi
)
514 xor %1d
, t_ref
(3,rdi
)
519 xor %3d
, t_ref
(0,rsi
)
520 xor %4d
, t_ref
(1,rdi
)
523 xor %1d
, t_ref
(2,rsi
)
524 xor %2d
, t_ref
(3,rdi
)
529 xor %4d
, t_ref
(0,rsi
)
530 xor %1d
, t_ref
(1,rdi
)
533 xor %2d
, t_ref
(2,rsi
)
534 xor %3d
, t_ref
(3,rdi
)
542 %ifdef LAST_ROUND_TABLES
544 %macro il_rnd
5 ; last inverse round
546 mov %1d
, ik_ref
(%5,0)
547 mov %2d
, ik_ref
(%5,1)
548 mov %3d
, ik_ref
(%5,2)
549 mov %4d
, ik_ref
(%5,3)
554 xor %1d
, t_ref
(0,rsi
)
555 xor %2d
, t_ref
(1,rdi
)
558 xor %3d
, t_ref
(2,rsi
)
559 xor %4d
, t_ref
(3,rdi
)
564 xor %2d
, t_ref
(0,rsi
)
565 xor %3d
, t_ref
(1,rdi
)
568 xor %4d
, t_ref
(2,rsi
)
569 xor %1d
, t_ref
(3,rdi
)
574 xor %3d
, t_ref
(0,rsi
)
575 xor %4d
, t_ref
(1,rdi
)
578 xor %1d
, t_ref
(2,rsi
)
579 xor %2d
, t_ref
(3,rdi
)
584 xor %4d
, t_ref
(0,rsi
)
585 xor %1d
, t_ref
(1,rdi
)
588 xor %2d
, t_ref
(2,rsi
)
589 xor %3d
, t_ref
(3,rdi
)
594 %macro il_rnd
5 ; last inverse round
595 mov %1d
, ik_ref
(%5,0)
596 mov %2d
, ik_ref
(%5,1)
597 mov %3d
, ik_ref
(%5,2)
598 mov %4d
, ik_ref
(%5,3)
602 movzx esi, t_ref
(i
,rsi
)
603 movzx edi, t_ref
(i
,rdi
)
610 movzx esi, t_ref
(i
,rsi
)
611 movzx edi, t_ref
(i
,rdi
)
619 movzx esi, t_ref
(i
,rsi
)
620 movzx edi, t_ref
(i
,rdi
)
627 movzx esi, t_ref
(i
,rsi
)
628 movzx edi, t_ref
(i
,rdi
)
636 movzx esi, t_ref
(i
,rsi
)
637 movzx edi, t_ref
(i
,rdi
)
644 movzx esi, t_ref
(i
,rsi
)
645 movzx edi, t_ref
(i
,rdi
)
653 movzx esi, t_ref
(i
,rsi
)
654 movzx edi, t_ref
(i
,rdi
)
661 movzx esi, t_ref
(i
,rsi
)
662 movzx edi, t_ref
(i
,rdi
)
678 section .data
align=64
682 %ifdef LAST_ROUND_TABLES
686 section .text
align=16
690 proc_frame aes_encrypt
691 alloc_stack
7*8 ; 7 to align stack to 16 bytes
698 mov rdi
, rcx
; input pointer
699 mov [rsp
+0*8], rdx
; output pointer
703 sub rsp
, 4*8 ; gnu/linux binary interface
704 mov [rsp
+0*8], rsi
; output pointer
705 mov r8
, rdx
; context
707 sub rsp
, 6*8 ; windows binary interface
710 mov rdi
, rcx
; input pointer
711 mov [rsp
+0*8], rdx
; output pointer
713 mov [rsp
+1*8], rbx
; input pointer in rdi
714 mov [rsp
+2*8], rbp
; output pointer in [rsp]
715 mov [rsp
+3*8], r12
; context in r8
718 movzx esi, byte [kptr
+4*KS_LENGTH
]
719 lea tptr
,[enc_tab wrt rip
]
728 xor ebx, [kptr
+fofs
+4]
729 xor ecx, [kptr
+fofs
+8]
730 xor edx, [kptr
+fofs
+12]
742 .1: ff_rnd r9
, r10
, r11
, r12
, 13
743 ff_rnd r9
, r10
, r11
, r12
, 12
744 .2: ff_rnd r9
, r10
, r11
, r12
, 11
745 ff_rnd r9
, r10
, r11
, r12
, 10
746 .3: ff_rnd r9
, r10
, r11
, r12
, 9
747 ff_rnd r9
, r10
, r11
, r12
, 8
748 ff_rnd r9
, r10
, r11
, r12
, 7
749 ff_rnd r9
, r10
, r11
, r12
, 6
750 ff_rnd r9
, r10
, r11
, r12
, 5
751 ff_rnd r9
, r10
, r11
, r12
, 4
752 ff_rnd r9
, r10
, r11
, r12
, 3
753 ff_rnd r9
, r10
, r11
, r12
, 2
754 ff_rnd r9
, r10
, r11
, r12
, 1
755 fl_rnd r9
, r10
, r11
, r12
, 0
796 %ifdef LAST_ROUND_TABLES
804 proc_frame aes_decrypt
805 alloc_stack
7*8 ; 7 to align stack to 16 bytes
812 mov rdi
, rcx
; input pointer
813 mov [rsp
+0*8], rdx
; output pointer
817 sub rsp
, 4*8 ; gnu/linux binary interface
818 mov [rsp
+0*8], rsi
; output pointer
819 mov r8
, rdx
; context
821 sub rsp
, 6*8 ; windows binary interface
824 mov rdi
, rcx
; input pointer
825 mov [rsp
+0*8], rdx
; output pointer
827 mov [rsp
+1*8], rbx
; input pointer in rdi
828 mov [rsp
+2*8], rbp
; output pointer in [rsp]
829 mov [rsp
+3*8], r12
; context in r8
832 movzx esi,byte[kptr
+4*KS_LENGTH
]
833 lea tptr
,[dec_tab wrt rip
]
849 xor ebx, [rdi
+rofs
+4]
850 xor ecx, [rdi
+rofs
+8]
851 xor edx, [rdi
+rofs
+12]
862 .1: ii_rnd r9
, r10
, r11
, r12
, 13
863 ii_rnd r9
, r10
, r11
, r12
, 12
864 .2: ii_rnd r9
, r10
, r11
, r12
, 11
865 ii_rnd r9
, r10
, r11
, r12
, 10
866 .3: ii_rnd r9
, r10
, r11
, r12
, 9
867 ii_rnd r9
, r10
, r11
, r12
, 8
868 ii_rnd r9
, r10
, r11
, r12
, 7
869 ii_rnd r9
, r10
, r11
, r12
, 6
870 ii_rnd r9
, r10
, r11
, r12
, 5
871 ii_rnd r9
, r10
, r11
, r12
, 4
872 ii_rnd r9
, r10
, r11
, r12
, 3
873 ii_rnd r9
, r10
, r11
, r12
, 2
874 ii_rnd r9
, r10
, r11
, r12
, 1
875 il_rnd r9
, r10
, r11
, r12
, 0
883 .4: mov rbx
, [rsp
+1*8]