mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-06-29 10:01:25 +00:00
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>
This commit is contained in:
parent
109568e110
commit
07bf44f869
4 changed files with 38 additions and 17 deletions
|
@ -41,14 +41,14 @@
|
||||||
#define tlen 1024 // length of each of 4 'xor' arrays (256 32-bit words)
|
#define tlen 1024 // length of each of 4 'xor' arrays (256 32-bit words)
|
||||||
|
|
||||||
/* offsets to parameters with one register pushed onto stack */
|
/* offsets to parameters with one register pushed onto stack */
|
||||||
#define tfm 8
|
#define ctx 8
|
||||||
#define out_blk 12
|
#define out_blk 12
|
||||||
#define in_blk 16
|
#define in_blk 16
|
||||||
|
|
||||||
/* offsets in crypto_tfm structure */
|
/* offsets in crypto_aes_ctx structure */
|
||||||
#define klen (crypto_tfm_ctx_offset + 480)
|
#define klen (480)
|
||||||
#define ekey (crypto_tfm_ctx_offset + 0)
|
#define ekey (0)
|
||||||
#define dkey (crypto_tfm_ctx_offset + 240)
|
#define dkey (240)
|
||||||
|
|
||||||
// register mapping for encrypt and decrypt subroutines
|
// register mapping for encrypt and decrypt subroutines
|
||||||
|
|
||||||
|
@ -217,7 +217,7 @@
|
||||||
do_col (table, r5,r0,r1,r4, r2,r3); /* idx=r5 */
|
do_col (table, r5,r0,r1,r4, r2,r3); /* idx=r5 */
|
||||||
|
|
||||||
// AES (Rijndael) Encryption Subroutine
|
// AES (Rijndael) Encryption Subroutine
|
||||||
/* void aes_enc_blk(struct crypto_tfm *tfm, u8 *out_blk, const u8 *in_blk) */
|
/* void aes_enc_blk(struct crypto_aes_ctx *ctx, u8 *out_blk, const u8 *in_blk) */
|
||||||
|
|
||||||
.global aes_enc_blk
|
.global aes_enc_blk
|
||||||
|
|
||||||
|
@ -228,7 +228,7 @@
|
||||||
|
|
||||||
aes_enc_blk:
|
aes_enc_blk:
|
||||||
push %ebp
|
push %ebp
|
||||||
mov tfm(%esp),%ebp
|
mov ctx(%esp),%ebp
|
||||||
|
|
||||||
// CAUTION: the order and the values used in these assigns
|
// CAUTION: the order and the values used in these assigns
|
||||||
// rely on the register mappings
|
// rely on the register mappings
|
||||||
|
@ -292,7 +292,7 @@ aes_enc_blk:
|
||||||
ret
|
ret
|
||||||
|
|
||||||
// AES (Rijndael) Decryption Subroutine
|
// AES (Rijndael) Decryption Subroutine
|
||||||
/* void aes_dec_blk(struct crypto_tfm *tfm, u8 *out_blk, const u8 *in_blk) */
|
/* void aes_dec_blk(struct crypto_aes_ctx *ctx, u8 *out_blk, const u8 *in_blk) */
|
||||||
|
|
||||||
.global aes_dec_blk
|
.global aes_dec_blk
|
||||||
|
|
||||||
|
@ -303,7 +303,7 @@ aes_enc_blk:
|
||||||
|
|
||||||
aes_dec_blk:
|
aes_dec_blk:
|
||||||
push %ebp
|
push %ebp
|
||||||
mov tfm(%esp),%ebp
|
mov ctx(%esp),%ebp
|
||||||
|
|
||||||
// CAUTION: the order and the values used in these assigns
|
// CAUTION: the order and the values used in these assigns
|
||||||
// rely on the register mappings
|
// rely on the register mappings
|
||||||
|
|
|
@ -17,8 +17,6 @@
|
||||||
|
|
||||||
#include <asm/asm-offsets.h>
|
#include <asm/asm-offsets.h>
|
||||||
|
|
||||||
#define BASE crypto_tfm_ctx_offset
|
|
||||||
|
|
||||||
#define R1 %rax
|
#define R1 %rax
|
||||||
#define R1E %eax
|
#define R1E %eax
|
||||||
#define R1X %ax
|
#define R1X %ax
|
||||||
|
@ -56,13 +54,13 @@
|
||||||
.align 8; \
|
.align 8; \
|
||||||
FUNC: movq r1,r2; \
|
FUNC: movq r1,r2; \
|
||||||
movq r3,r4; \
|
movq r3,r4; \
|
||||||
leaq BASE+KEY+48(r8),r9; \
|
leaq KEY+48(r8),r9; \
|
||||||
movq r10,r11; \
|
movq r10,r11; \
|
||||||
movl (r7),r5 ## E; \
|
movl (r7),r5 ## E; \
|
||||||
movl 4(r7),r1 ## E; \
|
movl 4(r7),r1 ## E; \
|
||||||
movl 8(r7),r6 ## E; \
|
movl 8(r7),r6 ## E; \
|
||||||
movl 12(r7),r7 ## E; \
|
movl 12(r7),r7 ## E; \
|
||||||
movl BASE+480(r8),r10 ## E; \
|
movl 480(r8),r10 ## E; \
|
||||||
xorl -48(r9),r5 ## E; \
|
xorl -48(r9),r5 ## E; \
|
||||||
xorl -44(r9),r1 ## E; \
|
xorl -44(r9),r1 ## E; \
|
||||||
xorl -40(r9),r6 ## E; \
|
xorl -40(r9),r6 ## E; \
|
||||||
|
|
|
@ -5,17 +5,29 @@
|
||||||
|
|
||||||
#include <crypto/aes.h>
|
#include <crypto/aes.h>
|
||||||
|
|
||||||
asmlinkage void aes_enc_blk(struct crypto_tfm *tfm, u8 *out, const u8 *in);
|
asmlinkage void aes_enc_blk(struct crypto_aes_ctx *ctx, u8 *out, const u8 *in);
|
||||||
asmlinkage void aes_dec_blk(struct crypto_tfm *tfm, u8 *out, const u8 *in);
|
asmlinkage void aes_dec_blk(struct crypto_aes_ctx *ctx, u8 *out, const u8 *in);
|
||||||
|
|
||||||
|
void crypto_aes_encrypt_x86(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
|
||||||
|
{
|
||||||
|
aes_enc_blk(ctx, dst, src);
|
||||||
|
}
|
||||||
|
EXPORT_SYMBOL_GPL(crypto_aes_encrypt_x86);
|
||||||
|
|
||||||
|
void crypto_aes_decrypt_x86(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
|
||||||
|
{
|
||||||
|
aes_dec_blk(ctx, dst, src);
|
||||||
|
}
|
||||||
|
EXPORT_SYMBOL_GPL(crypto_aes_decrypt_x86);
|
||||||
|
|
||||||
static void aes_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
|
static void aes_encrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
|
||||||
{
|
{
|
||||||
aes_enc_blk(tfm, dst, src);
|
aes_enc_blk(crypto_tfm_ctx(tfm), dst, src);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void aes_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
|
static void aes_decrypt(struct crypto_tfm *tfm, u8 *dst, const u8 *src)
|
||||||
{
|
{
|
||||||
aes_dec_blk(tfm, dst, src);
|
aes_dec_blk(crypto_tfm_ctx(tfm), dst, src);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct crypto_alg aes_alg = {
|
static struct crypto_alg aes_alg = {
|
||||||
|
|
11
arch/x86/include/asm/aes.h
Normal file
11
arch/x86/include/asm/aes.h
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
#ifndef ASM_X86_AES_H
|
||||||
|
#define ASM_X86_AES_H
|
||||||
|
|
||||||
|
#include <linux/crypto.h>
|
||||||
|
#include <crypto/aes.h>
|
||||||
|
|
||||||
|
void crypto_aes_encrypt_x86(struct crypto_aes_ctx *ctx, u8 *dst,
|
||||||
|
const u8 *src);
|
||||||
|
void crypto_aes_decrypt_x86(struct crypto_aes_ctx *ctx, u8 *dst,
|
||||||
|
const u8 *src);
|
||||||
|
#endif
|
Loading…
Add table
Add a link
Reference in a new issue