1 ; ---------------------------------------------------------------------------
2 ; Copyright (c) 2002, Dr Brian Gladman, Worcester, UK. All rights reserved.
6 ; The free distribution and use of this software in both source and binary
7 ; form is allowed (with or without changes) provided that:
9 ; 1. distributions of this source code include the above copyright
10 ; notice, this list of conditions and the following disclaimer;
12 ; 2. distributions in binary form include the above copyright
13 ; notice, this list of conditions and the following disclaimer
14 ; in the documentation and/or other associated materials;
16 ; 3. the copyright holder's name is not used to endorse products
17 ; built using this software without specific written permission.
19 ; ALTERNATIVELY, provided that this notice is retained in full, this product
20 ; may be distributed under the terms of the GNU General Public License (GPL),
21 ; in which case the provisions of the GPL apply INSTEAD OF those given above.
25 ; This software is provided 'as is' with no explicit or implied warranties
26 ; in respect of its properties, including, but not limited to, correctness
27 ; and/or fitness for purpose.
28 ; ---------------------------------------------------------------------------
31 ; I am grateful to Dag Arne Osvik for many discussions of the techniques that
32 ; can be used to optimise AES assembler code on AMD64/EM64T architectures.
33 ; Some of the techniques used in this implementation are the result of
34 ; suggestions made by him for which I am most grateful.
36 ; An AES implementation for AMD64 processors using the YASM assembler. This
37 ; implemetation provides only encryption, decryption and hence requires key
38 ; scheduling support in C. It uses 8k bytes of tables but its encryption and
39 ; decryption performance is very close to that obtained using large tables.
40 ; It can use either Windows or Gnu/Linux calling conventions, which are as
48 ; preserved rsi - + rbx, rbp, rsp, r12, r13, r14 & r15
49 ; registers rdi - on both
51 ; destroyed - rsi + rax, rcx, rdx, r8, r9, r10 & r11
52 ; registers - rdi on both
54 ; The default convention is that for windows, the gnu/linux convention being
55 ; used if __GNUC__ is defined.
57 ; This code provides the standard AES block size (128 bits, 16 bytes) and the
58 ; three standard AES key sizes (128, 192 and 256 bits). It has the same call
59 ; interface as my C implementation. It uses the Microsoft C AMD64 calling
60 ; conventions in which the three parameters are placed in rcx, rdx and r8
61 ; respectively. The rbx, rsi, rdi, rbp and r12..r15 registers are preserved.
63 ; AES_RETURN aes_encrypt(const unsigned char in_blk[],
64 ; unsigned char out_blk[], const aes_encrypt_ctx cx[1]);
66 ; AES_RETURN aes_decrypt(const unsigned char in_blk[],
67 ; unsigned char out_blk[], const aes_decrypt_ctx cx[1]);
69 ; AES_RETURN aes_encrypt_key<NNN>(const unsigned char key[],
70 ; const aes_encrypt_ctx cx[1]);
72 ; AES_RETURN aes_decrypt_key<NNN>(const unsigned char key[],
73 ; const aes_decrypt_ctx cx[1]);
75 ; AES_RETURN aes_encrypt_key(const unsigned char key[],
76 ; unsigned int len, const aes_decrypt_ctx cx[1]);
78 ; AES_RETURN aes_decrypt_key(const unsigned char key[],
79 ; unsigned int len, const aes_decrypt_ctx cx[1]);
81 ; where <NNN> is 128, 102 or 256. In the last two calls the length can be in
82 ; either bits or bytes.
84 ; Comment in/out the following lines to obtain the desired subroutines. These
85 ; selections MUST match those in the C header file aes.h
87 %define AES_128 ; define if AES with 128 bit keys is needed
88 %define AES_192 ; define if AES with 192 bit keys is needed
89 %define AES_256 ; define if AES with 256 bit keys is needed
90 %define AES_VAR ; define if a variable key size is needed
91 %define ENCRYPTION ; define if encryption is needed
92 %define DECRYPTION ; define if decryption is needed
93 %define AES_REV_DKS ; define if key decryption schedule is reversed
94 %define LAST_ROUND_TABLES ; define for the faster version using extra tables
96 ; The encryption key schedule has the following in memory layout where N is the
97 ; number of rounds (10, 12 or 14):
99 ; lo: | input key (round 0) | ; each round is four 32-bit words
100 ; | encryption round 1 |
101 ; | encryption round 2 |
103 ; | encryption round N-1 |
104 ; hi: | encryption round N |
106 ; The decryption key schedule is normally set up so that it has the same
107 ; layout as above by actually reversing the order of the encryption key
108 ; schedule in memory (this happens when AES_REV_DKS is set):
110 ; lo: | decryption round 0 | = | encryption round N |
111 ; | decryption round 1 | = INV_MIX_COL[ | encryption round N-1 | ]
112 ; | decryption round 2 | = INV_MIX_COL[ | encryption round N-2 | ]
114 ; | decryption round N-1 | = INV_MIX_COL[ | encryption round 1 | ]
115 ; hi: | decryption round N | = | input key (round 0) |
117 ; with rounds except the first and last modified using inv_mix_column()
118 ; But if AES_REV_DKS is NOT set the order of keys is left as it is for
119 ; encryption so that it has to be accessed in reverse when used for
120 ; decryption (although the inverse mix column modifications are done)
122 ; lo: | decryption round 0 | = | input key (round 0) |
123 ; | decryption round 1 | = INV_MIX_COL[ | encryption round 1 | ]
124 ; | decryption round 2 | = INV_MIX_COL[ | encryption round 2 | ]
126 ; | decryption round N-1 | = INV_MIX_COL[ | encryption round N-1 | ]
127 ; hi: | decryption round N | = | encryption round N |
129 ; This layout is faster when the assembler key scheduling provided here
132 ; The DLL interface must use the _stdcall convention in which the number
133 ; of bytes of parameter space is added after an @ to the sutine's name.
134 ; We must also remove our parameters from the stack before return (see
135 ; the do_exit macro). Define DLL_EXPORT for the Dynamic Link Library version.
139 ; End of user defines
200 ; finite field multiplies by {02}, {04} and {08}
202 %define f2(x) ((x<<1)^(((x>>7)&1)*0x11b))
203 %define f4(x) ((x<<2)^(((x>>6)&1)*0x11b)^(((x>>6)&2)*0x11b))
204 %define f8(x) ((x<<3)^(((x>>5)&1)*0x11b)^(((x>>5)&2)*0x11b)^(((x>>5)&4)*0x11b))
206 ; finite field multiplies required in table generation
208 %define f3(x) (f2(x) ^ x)
209 %define f9(x) (f8(x) ^ x)
210 %define fb(x) (f8(x) ^ f2(x) ^ x)
211 %define fd(x) (f8(x) ^ f4(x) ^ x)
212 %define fe(x) (f8(x) ^ f4(x) ^ f2(x))
214 ; macro for expanding S-box data
217 db %1(0x63),%1(0x7c),%1(0x77),%1(0x7b),%1(0xf2),%1(0x6b),%1(0x6f),%1(0xc5)
218 db %1(0x30),%1(0x01),%1(0x67),%1(0x2b),%1(0xfe),%1(0xd7),%1(0xab),%1(0x76)
219 db %1(0xca),%1(0x82),%1(0xc9),%1(0x7d),%1(0xfa),%1(0x59),%1(0x47),%1(0xf0)
220 db %1(0xad),%1(0xd4),%1(0xa2),%1(0xaf),%1(0x9c),%1(0xa4),%1(0x72),%1(0xc0)
221 db %1(0xb7),%1(0xfd),%1(0x93),%1(0x26),%1(0x36),%1(0x3f),%1(0xf7),%1(0xcc)
222 db %1(0x34),%1(0xa5),%1(0xe5),%1(0xf1),%1(0x71),%1(0xd8),%1(0x31),%1(0x15)
223 db %1(0x04),%1(0xc7),%1(0x23),%1(0xc3),%1(0x18),%1(0x96),%1(0x05),%1(0x9a)
224 db %1(0x07),%1(0x12),%1(0x80),%1(0xe2),%1(0xeb),%1(0x27),%1(0xb2),%1(0x75)
225 db %1(0x09),%1(0x83),%1(0x2c),%1(0x1a),%1(0x1b),%1(0x6e),%1(0x5a),%1(0xa0)
226 db %1(0x52),%1(0x3b),%1(0xd6),%1(0xb3),%1(0x29),%1(0xe3),%1(0x2f),%1(0x84)
227 db %1(0x53),%1(0xd1),%1(0x00),%1(0xed),%1(0x20),%1(0xfc),%1(0xb1),%1(0x5b)
228 db %1(0x6a),%1(0xcb),%1(0xbe),%1(0x39),%1(0x4a),%1(0x4c),%1(0x58),%1(0xcf)
229 db %1(0xd0),%1(0xef),%1(0xaa),%1(0xfb),%1(0x43),%1(0x4d),%1(0x33),%1(0x85)
230 db %1(0x45),%1(0xf9),%1(0x02),%1(0x7f),%1(0x50),%1(0x3c),%1(0x9f),%1(0xa8)
231 db %1(0x51),%1(0xa3),%1(0x40),%1(0x8f),%1(0x92),%1(0x9d),%1(0x38),%1(0xf5)
232 db %1(0xbc),%1(0xb6),%1(0xda),%1(0x21),%1(0x10),%1(0xff),%1(0xf3),%1(0xd2)
233 db %1(0xcd),%1(0x0c),%1(0x13),%1(0xec),%1(0x5f),%1(0x97),%1(0x44),%1(0x17)
234 db %1(0xc4),%1(0xa7),%1(0x7e),%1(0x3d),%1(0x64),%1(0x5d),%1(0x19),%1(0x73)
235 db %1(0x60),%1(0x81),%1(0x4f),%1(0xdc),%1(0x22),%1(0x2a),%1(0x90),%1(0x88)
236 db %1(0x46),%1(0xee),%1(0xb8),%1(0x14),%1(0xde),%1(0x5e),%1(0x0b),%1(0xdb)
237 db %1(0xe0),%1(0x32),%1(0x3a),%1(0x0a),%1(0x49),%1(0x06),%1(0x24),%1(0x5c)
238 db %1(0xc2),%1(0xd3),%1(0xac),%1(0x62),%1(0x91),%1(0x95),%1(0xe4),%1(0x79)
239 db %1(0xe7),%1(0xc8),%1(0x37),%1(0x6d),%1(0x8d),%1(0xd5),%1(0x4e),%1(0xa9)
240 db %1(0x6c),%1(0x56),%1(0xf4),%1(0xea),%1(0x65),%1(0x7a),%1(0xae),%1(0x08)
241 db %1(0xba),%1(0x78),%1(0x25),%1(0x2e),%1(0x1c),%1(0xa6),%1(0xb4),%1(0xc6)
242 db %1(0xe8),%1(0xdd),%1(0x74),%1(0x1f),%1(0x4b),%1(0xbd),%1(0x8b),%1(0x8a)
243 db %1(0x70),%1(0x3e),%1(0xb5),%1(0x66),%1(0x48),%1(0x03),%1(0xf6),%1(0x0e)
244 db %1(0x61),%1(0x35),%1(0x57),%1(0xb9),%1(0x86),%1(0xc1),%1(0x1d),%1(0x9e)
245 db %1(0xe1),%1(0xf8),%1(0x98),%1(0x11),%1(0x69),%1(0xd9),%1(0x8e),%1(0x94)
246 db %1(0x9b),%1(0x1e),%1(0x87),%1(0xe9),%1(0xce),%1(0x55),%1(0x28),%1(0xdf)
247 db %1(0x8c),%1(0xa1),%1(0x89),%1(0x0d),%1(0xbf),%1(0xe6),%1(0x42),%1(0x68)
248 db %1(0x41),%1(0x99),%1(0x2d),%1(0x0f),%1(0xb0),%1(0x54),%1(0xbb),%1(0x16)
252 db %1(0x52),%1(0x09),%1(0x6a),%1(0xd5),%1(0x30),%1(0x36),%1(0xa5),%1(0x38)
253 db %1(0xbf),%1(0x40),%1(0xa3),%1(0x9e),%1(0x81),%1(0xf3),%1(0xd7),%1(0xfb)
254 db %1(0x7c),%1(0xe3),%1(0x39),%1(0x82),%1(0x9b),%1(0x2f),%1(0xff),%1(0x87)
255 db %1(0x34),%1(0x8e),%1(0x43),%1(0x44),%1(0xc4),%1(0xde),%1(0xe9),%1(0xcb)
256 db %1(0x54),%1(0x7b),%1(0x94),%1(0x32),%1(0xa6),%1(0xc2),%1(0x23),%1(0x3d)
257 db %1(0xee),%1(0x4c),%1(0x95),%1(0x0b),%1(0x42),%1(0xfa),%1(0xc3),%1(0x4e)
258 db %1(0x08),%1(0x2e),%1(0xa1),%1(0x66),%1(0x28),%1(0xd9),%1(0x24),%1(0xb2)
259 db %1(0x76),%1(0x5b),%1(0xa2),%1(0x49),%1(0x6d),%1(0x8b),%1(0xd1),%1(0x25)
260 db %1(0x72),%1(0xf8),%1(0xf6),%1(0x64),%1(0x86),%1(0x68),%1(0x98),%1(0x16)
261 db %1(0xd4),%1(0xa4),%1(0x5c),%1(0xcc),%1(0x5d),%1(0x65),%1(0xb6),%1(0x92)
262 db %1(0x6c),%1(0x70),%1(0x48),%1(0x50),%1(0xfd),%1(0xed),%1(0xb9),%1(0xda)
263 db %1(0x5e),%1(0x15),%1(0x46),%1(0x57),%1(0xa7),%1(0x8d),%1(0x9d),%1(0x84)
264 db %1(0x90),%1(0xd8),%1(0xab),%1(0x00),%1(0x8c),%1(0xbc),%1(0xd3),%1(0x0a)
265 db %1(0xf7),%1(0xe4),%1(0x58),%1(0x05),%1(0xb8),%1(0xb3),%1(0x45),%1(0x06)
266 db %1(0xd0),%1(0x2c),%1(0x1e),%1(0x8f),%1(0xca),%1(0x3f),%1(0x0f),%1(0x02)
267 db %1(0xc1),%1(0xaf),%1(0xbd),%1(0x03),%1(0x01),%1(0x13),%1(0x8a),%1(0x6b)
268 db %1(0x3a),%1(0x91),%1(0x11),%1(0x41),%1(0x4f),%1(0x67),%1(0xdc),%1(0xea)
269 db %1(0x97),%1(0xf2),%1(0xcf),%1(0xce),%1(0xf0),%1(0xb4),%1(0xe6),%1(0x73)
270 db %1(0x96),%1(0xac),%1(0x74),%1(0x22),%1(0xe7),%1(0xad),%1(0x35),%1(0x85)
271 db %1(0xe2),%1(0xf9),%1(0x37),%1(0xe8),%1(0x1c),%1(0x75),%1(0xdf),%1(0x6e)
272 db %1(0x47),%1(0xf1),%1(0x1a),%1(0x71),%1(0x1d),%1(0x29),%1(0xc5),%1(0x89)
273 db %1(0x6f),%1(0xb7),%1(0x62),%1(0x0e),%1(0xaa),%1(0x18),%1(0xbe),%1(0x1b)
274 db %1(0xfc),%1(0x56),%1(0x3e),%1(0x4b),%1(0xc6),%1(0xd2),%1(0x79),%1(0x20)
275 db %1(0x9a),%1(0xdb),%1(0xc0),%1(0xfe),%1(0x78),%1(0xcd),%1(0x5a),%1(0xf4)
276 db %1(0x1f),%1(0xdd),%1(0xa8),%1(0x33),%1(0x88),%1(0x07),%1(0xc7),%1(0x31)
277 db %1(0xb1),%1(0x12),%1(0x10),%1(0x59),%1(0x27),%1(0x80),%1(0xec),%1(0x5f)
278 db %1(0x60),%1(0x51),%1(0x7f),%1(0xa9),%1(0x19),%1(0xb5),%1(0x4a),%1(0x0d)
279 db %1(0x2d),%1(0xe5),%1(0x7a),%1(0x9f),%1(0x93),%1(0xc9),%1(0x9c),%1(0xef)
280 db %1(0xa0),%1(0xe0),%1(0x3b),%1(0x4d),%1(0xae),%1(0x2a),%1(0xf5),%1(0xb0)
281 db %1(0xc8),%1(0xeb),%1(0xbb),%1(0x3c),%1(0x83),%1(0x53),%1(0x99),%1(0x61)
282 db %1(0x17),%1(0x2b),%1(0x04),%1(0x7e),%1(0xba),%1(0x77),%1(0xd6),%1(0x26)
283 db %1(0xe1),%1(0x69),%1(0x14),%1(0x63),%1(0x55),%1(0x21),%1(0x0c),%1(0x7d)
286 %define u8(x) f2(x), x, x, f3(x), f2(x), x, x, f3(x)
287 %define v8(x) fe(x), f9(x), fd(x), fb(x), fe(x), f9(x), fd(x), x
288 %define w8(x) x, 0, 0, 0, x, 0, 0, 0
290 %define tptr rbp ; table pointer
291 %define kptr r8 ; key schedule pointer
292 %define fofs 128 ; adjust offset in key schedule to keep |disp| < 128
293 %define fk_ref(x,y) [kptr-16*x+fofs+4*y]
296 %define ik_ref(x,y) [kptr-16*x+rofs+4*y]
299 %define ik_ref(x,y) [kptr+16*x+rofs+4*y]
302 %define tab_0(x) [tptr+8*x]
303 %define tab_1(x) [tptr+8*x+3]
304 %define tab_2(x) [tptr+8*x+2]
305 %define tab_3(x) [tptr+8*x+1]
306 %define tab_f(x) byte [tptr+8*x+1]
307 %define tab_i(x) byte [tptr+8*x+7]
308 %define t_ref(x,r) tab_ %+ x(r)
310 %macro ff_rnd 5 ; normal forward round
311 mov %1d, fk_ref(%5,0)
312 mov %2d, fk_ref(%5,1)
313 mov %3d, fk_ref(%5,2)
314 mov %4d, fk_ref(%5,3)
319 xor %1d, t_ref(0,rsi)
320 xor %4d, t_ref(1,rdi)
323 xor %3d, t_ref(2,rsi)
324 xor %2d, t_ref(3,rdi)
329 xor %2d, t_ref(0,rsi)
330 xor %1d, t_ref(1,rdi)
333 xor %4d, t_ref(2,rsi)
334 xor %3d, t_ref(3,rdi)
339 xor %3d, t_ref(0,rsi)
340 xor %2d, t_ref(1,rdi)
343 xor %1d, t_ref(2,rsi)
344 xor %4d, t_ref(3,rdi)
349 xor %4d, t_ref(0,rsi)
350 xor %3d, t_ref(1,rdi)
353 xor %2d, t_ref(2,rsi)
354 xor %1d, t_ref(3,rdi)
362 %ifdef LAST_ROUND_TABLES
364 %macro fl_rnd 5 ; last forward round
366 mov %1d, fk_ref(%5,0)
367 mov %2d, fk_ref(%5,1)
368 mov %3d, fk_ref(%5,2)
369 mov %4d, fk_ref(%5,3)
374 xor %1d, t_ref(0,rsi)
375 xor %4d, t_ref(1,rdi)
378 xor %3d, t_ref(2,rsi)
379 xor %2d, t_ref(3,rdi)
384 xor %2d, t_ref(0,rsi)
385 xor %1d, t_ref(1,rdi)
388 xor %4d, t_ref(2,rsi)
389 xor %3d, t_ref(3,rdi)
394 xor %3d, t_ref(0,rsi)
395 xor %2d, t_ref(1,rdi)
398 xor %1d, t_ref(2,rsi)
399 xor %4d, t_ref(3,rdi)
404 xor %4d, t_ref(0,rsi)
405 xor %3d, t_ref(1,rdi)
408 xor %2d, t_ref(2,rsi)
409 xor %1d, t_ref(3,rdi)
414 %macro fl_rnd 5 ; last forward round
415 mov %1d, fk_ref(%5,0)
416 mov %2d, fk_ref(%5,1)
417 mov %3d, fk_ref(%5,2)
418 mov %4d, fk_ref(%5,3)
423 movzx esi, t_ref(f,rsi)
424 movzx edi, t_ref(f,rdi)
430 movzx esi, t_ref(f,rsi)
431 movzx edi, t_ref(f,rdi)
440 movzx esi, t_ref(f,rsi)
441 movzx edi, t_ref(f,rdi)
447 movzx esi, t_ref(f,rsi)
448 movzx edi, t_ref(f,rdi)
456 movzx esi, t_ref(f,rsi)
457 movzx edi, t_ref(f,rdi)
464 movzx esi, t_ref(f,rsi)
465 movzx edi, t_ref(f,rdi)
473 movzx esi, t_ref(f,rsi)
474 movzx edi, t_ref(f,rdi)
481 movzx esi, t_ref(f,rsi)
482 movzx edi, t_ref(f,rdi)
491 %macro ii_rnd 5 ; normal inverse round
492 mov %1d, ik_ref(%5,0)
493 mov %2d, ik_ref(%5,1)
494 mov %3d, ik_ref(%5,2)
495 mov %4d, ik_ref(%5,3)
500 xor %1d, t_ref(0,rsi)
501 xor %2d, t_ref(1,rdi)
504 xor %3d, t_ref(2,rsi)
505 xor %4d, t_ref(3,rdi)
510 xor %2d, t_ref(0,rsi)
511 xor %3d, t_ref(1,rdi)
514 xor %4d, t_ref(2,rsi)
515 xor %1d, t_ref(3,rdi)
520 xor %3d, t_ref(0,rsi)
521 xor %4d, t_ref(1,rdi)
524 xor %1d, t_ref(2,rsi)
525 xor %2d, t_ref(3,rdi)
530 xor %4d, t_ref(0,rsi)
531 xor %1d, t_ref(1,rdi)
534 xor %2d, t_ref(2,rsi)
535 xor %3d, t_ref(3,rdi)
543 %ifdef LAST_ROUND_TABLES
545 %macro il_rnd 5 ; last inverse round
547 mov %1d, ik_ref(%5,0)
548 mov %2d, ik_ref(%5,1)
549 mov %3d, ik_ref(%5,2)
550 mov %4d, ik_ref(%5,3)
555 xor %1d, t_ref(0,rsi)
556 xor %2d, t_ref(1,rdi)
559 xor %3d, t_ref(2,rsi)
560 xor %4d, t_ref(3,rdi)
565 xor %2d, t_ref(0,rsi)
566 xor %3d, t_ref(1,rdi)
569 xor %4d, t_ref(2,rsi)
570 xor %1d, t_ref(3,rdi)
575 xor %3d, t_ref(0,rsi)
576 xor %4d, t_ref(1,rdi)
579 xor %1d, t_ref(2,rsi)
580 xor %2d, t_ref(3,rdi)
585 xor %4d, t_ref(0,rsi)
586 xor %1d, t_ref(1,rdi)
589 xor %2d, t_ref(2,rsi)
590 xor %3d, t_ref(3,rdi)
595 %macro il_rnd 5 ; last inverse round
596 mov %1d, ik_ref(%5,0)
597 mov %2d, ik_ref(%5,1)
598 mov %3d, ik_ref(%5,2)
599 mov %4d, ik_ref(%5,3)
603 movzx esi, t_ref(i,rsi)
604 movzx edi, t_ref(i,rdi)
611 movzx esi, t_ref(i,rsi)
612 movzx edi, t_ref(i,rdi)
620 movzx esi, t_ref(i,rsi)
621 movzx edi, t_ref(i,rdi)
628 movzx esi, t_ref(i,rsi)
629 movzx edi, t_ref(i,rdi)
637 movzx esi, t_ref(i,rsi)
638 movzx edi, t_ref(i,rdi)
645 movzx esi, t_ref(i,rsi)
646 movzx edi, t_ref(i,rdi)
654 movzx esi, t_ref(i,rsi)
655 movzx edi, t_ref(i,rdi)
662 movzx esi, t_ref(i,rsi)
663 movzx edi, t_ref(i,rdi)
679 section .data align=64
683 %ifdef LAST_ROUND_TABLES
687 section .text align=16
692 sub rsp, 4*8 ; gnu/linux binary interface
693 mov [rsp+0*8], rsi ; output pointer
694 mov r8, rdx ; context
696 sub rsp, 6*8 ; windows binary interface
699 mov [rsp+0*8], rdx ; output pointer
700 mov rdi, rcx ; input pointer
702 mov [rsp+1*8], rbx ; input pointer in rdi
703 mov [rsp+2*8], rbp ; output pointer in [rsp]
704 mov [rsp+3*8], r12 ; context in r8
706 movzx esi, byte [kptr+4*KS_LENGTH]
707 lea tptr,[enc_tab wrt rip]
716 xor ebx, [kptr+fofs+4]
717 xor ecx, [kptr+fofs+8]
718 xor edx, [kptr+fofs+12]
730 .1: ff_rnd r9, r10, r11, r12, 13
731 ff_rnd r9, r10, r11, r12, 12
732 .2: ff_rnd r9, r10, r11, r12, 11
733 ff_rnd r9, r10, r11, r12, 10
734 .3: ff_rnd r9, r10, r11, r12, 9
735 ff_rnd r9, r10, r11, r12, 8
736 ff_rnd r9, r10, r11, r12, 7
737 ff_rnd r9, r10, r11, r12, 6
738 ff_rnd r9, r10, r11, r12, 5
739 ff_rnd r9, r10, r11, r12, 4
740 ff_rnd r9, r10, r11, r12, 3
741 ff_rnd r9, r10, r11, r12, 2
742 ff_rnd r9, r10, r11, r12, 1
743 fl_rnd r9, r10, r11, r12, 0
773 section .data align=64
777 %ifdef LAST_ROUND_TABLES
781 section .text align=16
786 sub rsp, 4*8 ; gnu/linux binary interface
787 mov [rsp+0*8], rsi ; output pointer
788 mov r8, rdx ; context
790 sub rsp, 6*8 ; windows binary interface
793 mov [rsp+0*8], rdx ; output pointer
794 mov rdi, rcx ; input pointer
796 mov [rsp+1*8], rbx ; input pointer in rdi
797 mov [rsp+2*8], rbp ; output pointer in [rsp]
798 mov [rsp+3*8], r12 ; context in r8
800 movzx esi,byte[kptr+4*KS_LENGTH]
801 lea tptr,[dec_tab wrt rip]
817 xor ebx, [rdi+rofs+4]
818 xor ecx, [rdi+rofs+8]
819 xor edx, [rdi+rofs+12]
830 .1: ii_rnd r9, r10, r11, r12, 13
831 ii_rnd r9, r10, r11, r12, 12
832 .2: ii_rnd r9, r10, r11, r12, 11
833 ii_rnd r9, r10, r11, r12, 10
834 .3: ii_rnd r9, r10, r11, r12, 9
835 ii_rnd r9, r10, r11, r12, 8
836 ii_rnd r9, r10, r11, r12, 7
837 ii_rnd r9, r10, r11, r12, 6
838 ii_rnd r9, r10, r11, r12, 5
839 ii_rnd r9, r10, r11, r12, 4
840 ii_rnd r9, r10, r11, r12, 3
841 ii_rnd r9, r10, r11, r12, 2
842 ii_rnd r9, r10, r11, r12, 1
843 il_rnd r9, r10, r11, r12, 0
851 .4: mov rbx, [rsp+1*8]