aesni.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  1. /*
  2. * AES-NI support functions
  3. *
  4. * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
  5. * SPDX-License-Identifier: GPL-2.0
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along
  18. * with this program; if not, write to the Free Software Foundation, Inc.,
  19. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  20. *
  21. * This file is part of mbed TLS (https://tls.mbed.org)
  22. */
  23. /*
  24. * [AES-WP] http://software.intel.com/en-us/articles/intel-advanced-encryption-standard-aes-instructions-set
  25. * [CLMUL-WP] http://software.intel.com/en-us/articles/intel-carry-less-multiplication-instruction-and-its-usage-for-computing-the-gcm-mode/
  26. */
  27. #if !defined(MBEDTLS_CONFIG_FILE)
  28. #include "mbedtls/config.h"
  29. #else
  30. #include MBEDTLS_CONFIG_FILE
  31. #endif
  32. #if defined(MBEDTLS_AESNI_C)
  33. #include "mbedtls/aesni.h"
  34. #include <string.h>
  35. #ifndef asm
  36. #define asm __asm
  37. #endif
  38. #if defined(MBEDTLS_HAVE_X86_64)
  39. /*
  40. * AES-NI support detection routine
  41. */
  42. int mbedtls_aesni_has_support( unsigned int what )
  43. {
  44. static int done = 0;
  45. static unsigned int c = 0;
  46. if( ! done )
  47. {
  48. asm( "movl $1, %%eax \n\t"
  49. "cpuid \n\t"
  50. : "=c" (c)
  51. :
  52. : "eax", "ebx", "edx" );
  53. done = 1;
  54. }
  55. return( ( c & what ) != 0 );
  56. }
  57. /*
  58. * Binutils needs to be at least 2.19 to support AES-NI instructions.
  59. * Unfortunately, a lot of users have a lower version now (2014-04).
  60. * Emit bytecode directly in order to support "old" version of gas.
  61. *
  62. * Opcodes from the Intel architecture reference manual, vol. 3.
  63. * We always use registers, so we don't need prefixes for memory operands.
  64. * Operand macros are in gas order (src, dst) as opposed to Intel order
  65. * (dst, src) in order to blend better into the surrounding assembly code.
  66. */
  67. #define AESDEC ".byte 0x66,0x0F,0x38,0xDE,"
  68. #define AESDECLAST ".byte 0x66,0x0F,0x38,0xDF,"
  69. #define AESENC ".byte 0x66,0x0F,0x38,0xDC,"
  70. #define AESENCLAST ".byte 0x66,0x0F,0x38,0xDD,"
  71. #define AESIMC ".byte 0x66,0x0F,0x38,0xDB,"
  72. #define AESKEYGENA ".byte 0x66,0x0F,0x3A,0xDF,"
  73. #define PCLMULQDQ ".byte 0x66,0x0F,0x3A,0x44,"
  74. #define xmm0_xmm0 "0xC0"
  75. #define xmm0_xmm1 "0xC8"
  76. #define xmm0_xmm2 "0xD0"
  77. #define xmm0_xmm3 "0xD8"
  78. #define xmm0_xmm4 "0xE0"
  79. #define xmm1_xmm0 "0xC1"
  80. #define xmm1_xmm2 "0xD1"
  81. /*
  82. * AES-NI AES-ECB block en(de)cryption
  83. */
  84. int mbedtls_aesni_crypt_ecb( mbedtls_aes_context *ctx,
  85. int mode,
  86. const unsigned char input[16],
  87. unsigned char output[16] )
  88. {
  89. asm( "movdqu (%3), %%xmm0 \n\t" // load input
  90. "movdqu (%1), %%xmm1 \n\t" // load round key 0
  91. "pxor %%xmm1, %%xmm0 \n\t" // round 0
  92. "add $16, %1 \n\t" // point to next round key
  93. "subl $1, %0 \n\t" // normal rounds = nr - 1
  94. "test %2, %2 \n\t" // mode?
  95. "jz 2f \n\t" // 0 = decrypt
  96. "1: \n\t" // encryption loop
  97. "movdqu (%1), %%xmm1 \n\t" // load round key
  98. AESENC xmm1_xmm0 "\n\t" // do round
  99. "add $16, %1 \n\t" // point to next round key
  100. "subl $1, %0 \n\t" // loop
  101. "jnz 1b \n\t"
  102. "movdqu (%1), %%xmm1 \n\t" // load round key
  103. AESENCLAST xmm1_xmm0 "\n\t" // last round
  104. "jmp 3f \n\t"
  105. "2: \n\t" // decryption loop
  106. "movdqu (%1), %%xmm1 \n\t"
  107. AESDEC xmm1_xmm0 "\n\t" // do round
  108. "add $16, %1 \n\t"
  109. "subl $1, %0 \n\t"
  110. "jnz 2b \n\t"
  111. "movdqu (%1), %%xmm1 \n\t" // load round key
  112. AESDECLAST xmm1_xmm0 "\n\t" // last round
  113. "3: \n\t"
  114. "movdqu %%xmm0, (%4) \n\t" // export output
  115. :
  116. : "r" (ctx->nr), "r" (ctx->rk), "r" (mode), "r" (input), "r" (output)
  117. : "memory", "cc", "xmm0", "xmm1" );
  118. return( 0 );
  119. }
  120. /*
  121. * GCM multiplication: c = a times b in GF(2^128)
  122. * Based on [CLMUL-WP] algorithms 1 (with equation 27) and 5.
  123. */
  124. void mbedtls_aesni_gcm_mult( unsigned char c[16],
  125. const unsigned char a[16],
  126. const unsigned char b[16] )
  127. {
  128. unsigned char aa[16], bb[16], cc[16];
  129. size_t i;
  130. /* The inputs are in big-endian order, so byte-reverse them */
  131. for( i = 0; i < 16; i++ )
  132. {
  133. aa[i] = a[15 - i];
  134. bb[i] = b[15 - i];
  135. }
  136. asm( "movdqu (%0), %%xmm0 \n\t" // a1:a0
  137. "movdqu (%1), %%xmm1 \n\t" // b1:b0
  138. /*
  139. * Caryless multiplication xmm2:xmm1 = xmm0 * xmm1
  140. * using [CLMUL-WP] algorithm 1 (p. 13).
  141. */
  142. "movdqa %%xmm1, %%xmm2 \n\t" // copy of b1:b0
  143. "movdqa %%xmm1, %%xmm3 \n\t" // same
  144. "movdqa %%xmm1, %%xmm4 \n\t" // same
  145. PCLMULQDQ xmm0_xmm1 ",0x00 \n\t" // a0*b0 = c1:c0
  146. PCLMULQDQ xmm0_xmm2 ",0x11 \n\t" // a1*b1 = d1:d0
  147. PCLMULQDQ xmm0_xmm3 ",0x10 \n\t" // a0*b1 = e1:e0
  148. PCLMULQDQ xmm0_xmm4 ",0x01 \n\t" // a1*b0 = f1:f0
  149. "pxor %%xmm3, %%xmm4 \n\t" // e1+f1:e0+f0
  150. "movdqa %%xmm4, %%xmm3 \n\t" // same
  151. "psrldq $8, %%xmm4 \n\t" // 0:e1+f1
  152. "pslldq $8, %%xmm3 \n\t" // e0+f0:0
  153. "pxor %%xmm4, %%xmm2 \n\t" // d1:d0+e1+f1
  154. "pxor %%xmm3, %%xmm1 \n\t" // c1+e0+f1:c0
  155. /*
  156. * Now shift the result one bit to the left,
  157. * taking advantage of [CLMUL-WP] eq 27 (p. 20)
  158. */
  159. "movdqa %%xmm1, %%xmm3 \n\t" // r1:r0
  160. "movdqa %%xmm2, %%xmm4 \n\t" // r3:r2
  161. "psllq $1, %%xmm1 \n\t" // r1<<1:r0<<1
  162. "psllq $1, %%xmm2 \n\t" // r3<<1:r2<<1
  163. "psrlq $63, %%xmm3 \n\t" // r1>>63:r0>>63
  164. "psrlq $63, %%xmm4 \n\t" // r3>>63:r2>>63
  165. "movdqa %%xmm3, %%xmm5 \n\t" // r1>>63:r0>>63
  166. "pslldq $8, %%xmm3 \n\t" // r0>>63:0
  167. "pslldq $8, %%xmm4 \n\t" // r2>>63:0
  168. "psrldq $8, %%xmm5 \n\t" // 0:r1>>63
  169. "por %%xmm3, %%xmm1 \n\t" // r1<<1|r0>>63:r0<<1
  170. "por %%xmm4, %%xmm2 \n\t" // r3<<1|r2>>62:r2<<1
  171. "por %%xmm5, %%xmm2 \n\t" // r3<<1|r2>>62:r2<<1|r1>>63
  172. /*
  173. * Now reduce modulo the GCM polynomial x^128 + x^7 + x^2 + x + 1
  174. * using [CLMUL-WP] algorithm 5 (p. 20).
  175. * Currently xmm2:xmm1 holds x3:x2:x1:x0 (already shifted).
  176. */
  177. /* Step 2 (1) */
  178. "movdqa %%xmm1, %%xmm3 \n\t" // x1:x0
  179. "movdqa %%xmm1, %%xmm4 \n\t" // same
  180. "movdqa %%xmm1, %%xmm5 \n\t" // same
  181. "psllq $63, %%xmm3 \n\t" // x1<<63:x0<<63 = stuff:a
  182. "psllq $62, %%xmm4 \n\t" // x1<<62:x0<<62 = stuff:b
  183. "psllq $57, %%xmm5 \n\t" // x1<<57:x0<<57 = stuff:c
  184. /* Step 2 (2) */
  185. "pxor %%xmm4, %%xmm3 \n\t" // stuff:a+b
  186. "pxor %%xmm5, %%xmm3 \n\t" // stuff:a+b+c
  187. "pslldq $8, %%xmm3 \n\t" // a+b+c:0
  188. "pxor %%xmm3, %%xmm1 \n\t" // x1+a+b+c:x0 = d:x0
  189. /* Steps 3 and 4 */
  190. "movdqa %%xmm1,%%xmm0 \n\t" // d:x0
  191. "movdqa %%xmm1,%%xmm4 \n\t" // same
  192. "movdqa %%xmm1,%%xmm5 \n\t" // same
  193. "psrlq $1, %%xmm0 \n\t" // e1:x0>>1 = e1:e0'
  194. "psrlq $2, %%xmm4 \n\t" // f1:x0>>2 = f1:f0'
  195. "psrlq $7, %%xmm5 \n\t" // g1:x0>>7 = g1:g0'
  196. "pxor %%xmm4, %%xmm0 \n\t" // e1+f1:e0'+f0'
  197. "pxor %%xmm5, %%xmm0 \n\t" // e1+f1+g1:e0'+f0'+g0'
  198. // e0'+f0'+g0' is almost e0+f0+g0, ex\tcept for some missing
  199. // bits carried from d. Now get those\t bits back in.
  200. "movdqa %%xmm1,%%xmm3 \n\t" // d:x0
  201. "movdqa %%xmm1,%%xmm4 \n\t" // same
  202. "movdqa %%xmm1,%%xmm5 \n\t" // same
  203. "psllq $63, %%xmm3 \n\t" // d<<63:stuff
  204. "psllq $62, %%xmm4 \n\t" // d<<62:stuff
  205. "psllq $57, %%xmm5 \n\t" // d<<57:stuff
  206. "pxor %%xmm4, %%xmm3 \n\t" // d<<63+d<<62:stuff
  207. "pxor %%xmm5, %%xmm3 \n\t" // missing bits of d:stuff
  208. "psrldq $8, %%xmm3 \n\t" // 0:missing bits of d
  209. "pxor %%xmm3, %%xmm0 \n\t" // e1+f1+g1:e0+f0+g0
  210. "pxor %%xmm1, %%xmm0 \n\t" // h1:h0
  211. "pxor %%xmm2, %%xmm0 \n\t" // x3+h1:x2+h0
  212. "movdqu %%xmm0, (%2) \n\t" // done
  213. :
  214. : "r" (aa), "r" (bb), "r" (cc)
  215. : "memory", "cc", "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5" );
  216. /* Now byte-reverse the outputs */
  217. for( i = 0; i < 16; i++ )
  218. c[i] = cc[15 - i];
  219. return;
  220. }
  221. /*
  222. * Compute decryption round keys from encryption round keys
  223. */
  224. void mbedtls_aesni_inverse_key( unsigned char *invkey,
  225. const unsigned char *fwdkey, int nr )
  226. {
  227. unsigned char *ik = invkey;
  228. const unsigned char *fk = fwdkey + 16 * nr;
  229. memcpy( ik, fk, 16 );
  230. for( fk -= 16, ik += 16; fk > fwdkey; fk -= 16, ik += 16 )
  231. asm( "movdqu (%0), %%xmm0 \n\t"
  232. AESIMC xmm0_xmm0 "\n\t"
  233. "movdqu %%xmm0, (%1) \n\t"
  234. :
  235. : "r" (fk), "r" (ik)
  236. : "memory", "xmm0" );
  237. memcpy( ik, fk, 16 );
  238. }
  239. /*
  240. * Key expansion, 128-bit case
  241. */
  242. static void aesni_setkey_enc_128( unsigned char *rk,
  243. const unsigned char *key )
  244. {
  245. asm( "movdqu (%1), %%xmm0 \n\t" // copy the original key
  246. "movdqu %%xmm0, (%0) \n\t" // as round key 0
  247. "jmp 2f \n\t" // skip auxiliary routine
  248. /*
  249. * Finish generating the next round key.
  250. *
  251. * On entry xmm0 is r3:r2:r1:r0 and xmm1 is X:stuff:stuff:stuff
  252. * with X = rot( sub( r3 ) ) ^ RCON.
  253. *
  254. * On exit, xmm0 is r7:r6:r5:r4
  255. * with r4 = X + r0, r5 = r4 + r1, r6 = r5 + r2, r7 = r6 + r3
  256. * and those are written to the round key buffer.
  257. */
  258. "1: \n\t"
  259. "pshufd $0xff, %%xmm1, %%xmm1 \n\t" // X:X:X:X
  260. "pxor %%xmm0, %%xmm1 \n\t" // X+r3:X+r2:X+r1:r4
  261. "pslldq $4, %%xmm0 \n\t" // r2:r1:r0:0
  262. "pxor %%xmm0, %%xmm1 \n\t" // X+r3+r2:X+r2+r1:r5:r4
  263. "pslldq $4, %%xmm0 \n\t" // etc
  264. "pxor %%xmm0, %%xmm1 \n\t"
  265. "pslldq $4, %%xmm0 \n\t"
  266. "pxor %%xmm1, %%xmm0 \n\t" // update xmm0 for next time!
  267. "add $16, %0 \n\t" // point to next round key
  268. "movdqu %%xmm0, (%0) \n\t" // write it
  269. "ret \n\t"
  270. /* Main "loop" */
  271. "2: \n\t"
  272. AESKEYGENA xmm0_xmm1 ",0x01 \n\tcall 1b \n\t"
  273. AESKEYGENA xmm0_xmm1 ",0x02 \n\tcall 1b \n\t"
  274. AESKEYGENA xmm0_xmm1 ",0x04 \n\tcall 1b \n\t"
  275. AESKEYGENA xmm0_xmm1 ",0x08 \n\tcall 1b \n\t"
  276. AESKEYGENA xmm0_xmm1 ",0x10 \n\tcall 1b \n\t"
  277. AESKEYGENA xmm0_xmm1 ",0x20 \n\tcall 1b \n\t"
  278. AESKEYGENA xmm0_xmm1 ",0x40 \n\tcall 1b \n\t"
  279. AESKEYGENA xmm0_xmm1 ",0x80 \n\tcall 1b \n\t"
  280. AESKEYGENA xmm0_xmm1 ",0x1B \n\tcall 1b \n\t"
  281. AESKEYGENA xmm0_xmm1 ",0x36 \n\tcall 1b \n\t"
  282. :
  283. : "r" (rk), "r" (key)
  284. : "memory", "cc", "0" );
  285. }
  286. /*
  287. * Key expansion, 192-bit case
  288. */
  289. static void aesni_setkey_enc_192( unsigned char *rk,
  290. const unsigned char *key )
  291. {
  292. asm( "movdqu (%1), %%xmm0 \n\t" // copy original round key
  293. "movdqu %%xmm0, (%0) \n\t"
  294. "add $16, %0 \n\t"
  295. "movq 16(%1), %%xmm1 \n\t"
  296. "movq %%xmm1, (%0) \n\t"
  297. "add $8, %0 \n\t"
  298. "jmp 2f \n\t" // skip auxiliary routine
  299. /*
  300. * Finish generating the next 6 quarter-keys.
  301. *
  302. * On entry xmm0 is r3:r2:r1:r0, xmm1 is stuff:stuff:r5:r4
  303. * and xmm2 is stuff:stuff:X:stuff with X = rot( sub( r3 ) ) ^ RCON.
  304. *
  305. * On exit, xmm0 is r9:r8:r7:r6 and xmm1 is stuff:stuff:r11:r10
  306. * and those are written to the round key buffer.
  307. */
  308. "1: \n\t"
  309. "pshufd $0x55, %%xmm2, %%xmm2 \n\t" // X:X:X:X
  310. "pxor %%xmm0, %%xmm2 \n\t" // X+r3:X+r2:X+r1:r4
  311. "pslldq $4, %%xmm0 \n\t" // etc
  312. "pxor %%xmm0, %%xmm2 \n\t"
  313. "pslldq $4, %%xmm0 \n\t"
  314. "pxor %%xmm0, %%xmm2 \n\t"
  315. "pslldq $4, %%xmm0 \n\t"
  316. "pxor %%xmm2, %%xmm0 \n\t" // update xmm0 = r9:r8:r7:r6
  317. "movdqu %%xmm0, (%0) \n\t"
  318. "add $16, %0 \n\t"
  319. "pshufd $0xff, %%xmm0, %%xmm2 \n\t" // r9:r9:r9:r9
  320. "pxor %%xmm1, %%xmm2 \n\t" // stuff:stuff:r9+r5:r10
  321. "pslldq $4, %%xmm1 \n\t" // r2:r1:r0:0
  322. "pxor %%xmm2, %%xmm1 \n\t" // xmm1 = stuff:stuff:r11:r10
  323. "movq %%xmm1, (%0) \n\t"
  324. "add $8, %0 \n\t"
  325. "ret \n\t"
  326. "2: \n\t"
  327. AESKEYGENA xmm1_xmm2 ",0x01 \n\tcall 1b \n\t"
  328. AESKEYGENA xmm1_xmm2 ",0x02 \n\tcall 1b \n\t"
  329. AESKEYGENA xmm1_xmm2 ",0x04 \n\tcall 1b \n\t"
  330. AESKEYGENA xmm1_xmm2 ",0x08 \n\tcall 1b \n\t"
  331. AESKEYGENA xmm1_xmm2 ",0x10 \n\tcall 1b \n\t"
  332. AESKEYGENA xmm1_xmm2 ",0x20 \n\tcall 1b \n\t"
  333. AESKEYGENA xmm1_xmm2 ",0x40 \n\tcall 1b \n\t"
  334. AESKEYGENA xmm1_xmm2 ",0x80 \n\tcall 1b \n\t"
  335. :
  336. : "r" (rk), "r" (key)
  337. : "memory", "cc", "0" );
  338. }
  339. /*
  340. * Key expansion, 256-bit case
  341. */
  342. static void aesni_setkey_enc_256( unsigned char *rk,
  343. const unsigned char *key )
  344. {
  345. asm( "movdqu (%1), %%xmm0 \n\t"
  346. "movdqu %%xmm0, (%0) \n\t"
  347. "add $16, %0 \n\t"
  348. "movdqu 16(%1), %%xmm1 \n\t"
  349. "movdqu %%xmm1, (%0) \n\t"
  350. "jmp 2f \n\t" // skip auxiliary routine
  351. /*
  352. * Finish generating the next two round keys.
  353. *
  354. * On entry xmm0 is r3:r2:r1:r0, xmm1 is r7:r6:r5:r4 and
  355. * xmm2 is X:stuff:stuff:stuff with X = rot( sub( r7 )) ^ RCON
  356. *
  357. * On exit, xmm0 is r11:r10:r9:r8 and xmm1 is r15:r14:r13:r12
  358. * and those have been written to the output buffer.
  359. */
  360. "1: \n\t"
  361. "pshufd $0xff, %%xmm2, %%xmm2 \n\t"
  362. "pxor %%xmm0, %%xmm2 \n\t"
  363. "pslldq $4, %%xmm0 \n\t"
  364. "pxor %%xmm0, %%xmm2 \n\t"
  365. "pslldq $4, %%xmm0 \n\t"
  366. "pxor %%xmm0, %%xmm2 \n\t"
  367. "pslldq $4, %%xmm0 \n\t"
  368. "pxor %%xmm2, %%xmm0 \n\t"
  369. "add $16, %0 \n\t"
  370. "movdqu %%xmm0, (%0) \n\t"
  371. /* Set xmm2 to stuff:Y:stuff:stuff with Y = subword( r11 )
  372. * and proceed to generate next round key from there */
  373. AESKEYGENA xmm0_xmm2 ",0x00 \n\t"
  374. "pshufd $0xaa, %%xmm2, %%xmm2 \n\t"
  375. "pxor %%xmm1, %%xmm2 \n\t"
  376. "pslldq $4, %%xmm1 \n\t"
  377. "pxor %%xmm1, %%xmm2 \n\t"
  378. "pslldq $4, %%xmm1 \n\t"
  379. "pxor %%xmm1, %%xmm2 \n\t"
  380. "pslldq $4, %%xmm1 \n\t"
  381. "pxor %%xmm2, %%xmm1 \n\t"
  382. "add $16, %0 \n\t"
  383. "movdqu %%xmm1, (%0) \n\t"
  384. "ret \n\t"
  385. /*
  386. * Main "loop" - Generating one more key than necessary,
  387. * see definition of mbedtls_aes_context.buf
  388. */
  389. "2: \n\t"
  390. AESKEYGENA xmm1_xmm2 ",0x01 \n\tcall 1b \n\t"
  391. AESKEYGENA xmm1_xmm2 ",0x02 \n\tcall 1b \n\t"
  392. AESKEYGENA xmm1_xmm2 ",0x04 \n\tcall 1b \n\t"
  393. AESKEYGENA xmm1_xmm2 ",0x08 \n\tcall 1b \n\t"
  394. AESKEYGENA xmm1_xmm2 ",0x10 \n\tcall 1b \n\t"
  395. AESKEYGENA xmm1_xmm2 ",0x20 \n\tcall 1b \n\t"
  396. AESKEYGENA xmm1_xmm2 ",0x40 \n\tcall 1b \n\t"
  397. :
  398. : "r" (rk), "r" (key)
  399. : "memory", "cc", "0" );
  400. }
  401. /*
  402. * Key expansion, wrapper
  403. */
  404. int mbedtls_aesni_setkey_enc( unsigned char *rk,
  405. const unsigned char *key,
  406. size_t bits )
  407. {
  408. switch( bits )
  409. {
  410. case 128: aesni_setkey_enc_128( rk, key ); break;
  411. case 192: aesni_setkey_enc_192( rk, key ); break;
  412. case 256: aesni_setkey_enc_256( rk, key ); break;
  413. default : return( MBEDTLS_ERR_AES_INVALID_KEY_LENGTH );
  414. }
  415. return( 0 );
  416. }
  417. #endif /* MBEDTLS_HAVE_X86_64 */
  418. #endif /* MBEDTLS_AESNI_C */