Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

crypto: aes - Export x86 AES encrypt/decrypt functions

Intel AES-NI AES acceleration instructions touch XMM state, to use
that in soft_irq context, general x86 AES implementation is used as
fallback. The first parameter is changed from struct crypto_tfm * to
struct crypto_aes_ctx * to make it easier to deal with 16 bytes
alignment requirement of AES-NI implementation.

Signed-off-by: Huang Ying <ying.huang@intel.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

authored by

Huang Ying and committed by
Herbert Xu
07bf44f8 109568e1

+38 -17
+9 -9
arch/x86/crypto/aes-i586-asm_32.S
··· 41 41 #define tlen 1024 // length of each of 4 'xor' arrays (256 32-bit words) 42 42 43 43 /* offsets to parameters with one register pushed onto stack */ 44 - #define tfm 8 44 + #define ctx 8 45 45 #define out_blk 12 46 46 #define in_blk 16 47 47 48 - /* offsets in crypto_tfm structure */ 49 - #define klen (crypto_tfm_ctx_offset + 480) 50 - #define ekey (crypto_tfm_ctx_offset + 0) 51 - #define dkey (crypto_tfm_ctx_offset + 240) 48 + /* offsets in crypto_aes_ctx structure */ 49 + #define klen (480) 50 + #define ekey (0) 51 + #define dkey (240) 52 52 53 53 // register mapping for encrypt and decrypt subroutines 54 54 ··· 217 217 do_col (table, r5,r0,r1,r4, r2,r3); /* idx=r5 */ 218 218 219 219 // AES (Rijndael) Encryption Subroutine 220 - /* void aes_enc_blk(struct crypto_tfm *tfm, u8 *out_blk, const u8 *in_blk) */ 220 + /* void aes_enc_blk(struct crypto_aes_ctx *ctx, u8 *out_blk, const u8 *in_blk) */ 221 221 222 222 .global aes_enc_blk 223 223 ··· 228 228 229 229 aes_enc_blk: 230 230 push %ebp 231 - mov tfm(%esp),%ebp 231 + mov ctx(%esp),%ebp 232 232 233 233 // CAUTION: the order and the values used in these assigns 234 234 // rely on the register mappings ··· 292 292 ret 293 293 294 294 // AES (Rijndael) Decryption Subroutine 295 - /* void aes_dec_blk(struct crypto_tfm *tfm, u8 *out_blk, const u8 *in_blk) */ 295 + /* void aes_dec_blk(struct crypto_aes_ctx *ctx, u8 *out_blk, const u8 *in_blk) */ 296 296 297 297 .global aes_dec_blk 298 298 ··· 303 303 304 304 aes_dec_blk: 305 305 push %ebp 306 - mov tfm(%esp),%ebp 306 + mov ctx(%esp),%ebp 307 307 308 308 // CAUTION: the order and the values used in these assigns 309 309 // rely on the register mappings
+2 -4
arch/x86/crypto/aes-x86_64-asm_64.S
··· 17 17 18 18 #include <asm/asm-offsets.h> 19 19 20 - #define BASE crypto_tfm_ctx_offset 21 - 22 20 #define R1 %rax 23 21 #define R1E %eax 24 22 #define R1X %ax ··· 54 56 .align 8; \ 55 57 FUNC: movq r1,r2; \ 56 58 movq r3,r4; \ 57 - leaq BASE+KEY+48(r8),r9; \ 59 + leaq KEY+48(r8),r9; \ 58 60 movq r10,r11; \ 59 61 movl (r7),r5 ## E; \ 60 62 movl 4(r7),r1 ## E; \ 61 63 movl 8(r7),r6 ## E; \ 62 64 movl 12(r7),r7 ## E; \ 63 - movl BASE+480(r8),r10 ## E; \ 65 + movl 480(r8),r10 ## E; \ 64 66 xorl -48(r9),r5 ## E; \ 65 67 xorl -44(r9),r1 ## E; \ 66 68 xorl -40(r9),r6 ## E; \
+16 -4
arch/x86/crypto/aes_glue.c
··· 5 5 6 6 #include <crypto/aes.h> 7 7 8 - asmlinkage void aes_enc_blk(struct crypto_tfm *tfm, u8 *out, const u8 *in); 9 - asmlinkage void aes_dec_blk(struct crypto_tfm *tfm, u8 *out, const u8 *in); 8 + asmlinkage void aes_enc_blk(struct crypto_aes_ctx *ctx, u8 *out, const u8 *in); 9 + asmlinkage void aes_dec_blk(struct crypto_aes_ctx *ctx, u8 *out, const u8 *in); 10 + 11 + void crypto_aes_encrypt_x86(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src) 12 + { 13 + aes_enc_blk(ctx, dst, src); 14 + } 15 + EXPORT_SYMBOL_GPL(crypto_aes_encrypt_x86); 16 + 17 + void crypto_aes_decrypt_x86(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src) 18 + { 19 + aes_dec_blk(ctx, dst, src); 20 + } 21 + EXPORT_SYMBOL_GPL(crypto_aes_decrypt_x86); 10 22 11 23 static void aes_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) 12 24 { 13 - aes_enc_blk(tfm, dst, src); 25 + aes_enc_blk(crypto_tfm_ctx(tfm), dst, src); 14 26 } 15 27 16 28 static void aes_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src) 17 29 { 18 - aes_dec_blk(tfm, dst, src); 30 + aes_dec_blk(crypto_tfm_ctx(tfm), dst, src); 19 31 } 20 32 21 33 static struct crypto_alg aes_alg = {
+11
arch/x86/include/asm/aes.h
··· 1 + #ifndef ASM_X86_AES_H 2 + #define ASM_X86_AES_H 3 + 4 + #include <linux/crypto.h> 5 + #include <crypto/aes.h> 6 + 7 + void crypto_aes_encrypt_x86(struct crypto_aes_ctx *ctx, u8 *dst, 8 + const u8 *src); 9 + void crypto_aes_decrypt_x86(struct crypto_aes_ctx *ctx, u8 *dst, 10 + const u8 *src); 11 + #endif