crypto: aria: implement aria-avx2 and aria-avx512
Subsystems (2)
v5 cover crypto: aria: implement aria-avx2 and aria-avx512
This patchset is to implement aria-avx2 and aria-avx512. There are some differences between aria-avx, aria-avx2, and aria-avx512, but they are not core logic(s-box, diffusion layer).
ARIA-AVX2
It supports 32way parallel processing using 256bit registers. Like ARIA-AVX, it supports both AES-NI based s-box layer algorithm and GFNI based s-box layer algorithm.
These algorithms are the same as ARIA-AVX except that AES-NI doesn't support 256bit registers, so it is used twice.
ARIA-AVX512
It supports 64way parallel processing using 512bit registers. It supports only GFNI based s-box layer algorithm.
Benchmarks with i3-12100
commands: modprobe tcrypt mode=610 num_mb=8192
ARIA-AVX512(128bit and 256bit)
testing speed of multibuffer ecb(aria) (ecb-aria-avx512) encryption
tcrypt: 1 operation in 1504 cycles (1024 bytes)
tcrypt: 1 operation in 4595 cycles (4096 bytes)
tcrypt: 1 operation in 1763 cycles (1024 bytes)
tcrypt: 1 operation in 5540 cycles (4096 bytes)
testing speed of multibuffer ecb(aria) (ecb-aria-avx512) decryption
tcrypt: 1 operation in 1502 cycles (1024 bytes)
tcrypt: 1 operation in 4615 cycles (4096 bytes)
tcrypt: 1 operation in 1759 cycles (1024 bytes)
tcrypt: 1 operation in 5554 cycles (4096 bytes)
ARIA-AVX2 with GFNI(128bit and 256bit)
testing speed of multibuffer ecb(aria) (ecb-aria-avx2) encryption
tcrypt: 1 operation in 2003 cycles (1024 bytes)
tcrypt: 1 operation in 5867 cycles (4096 bytes)
tcrypt: 1 operation in 2358 cycles (1024 bytes)
tcrypt: 1 operation in 7295 cycles (4096 bytes)
testing speed of multibuffer ecb(aria) (ecb-aria-avx2) decryption
tcrypt: 1 operation in 2004 cycles (1024 bytes)
tcrypt: 1 operation in 5956 cycles (4096 bytes)
tcrypt: 1 operation in 2409 cycles (1024 bytes)
tcrypt: 1 operation in 7564 cycles (4096 bytes)
ARIA-AVX with GFNI(128bit and 256bit)
testing speed of multibuffer ecb(aria) (ecb-aria-avx) encryption
tcrypt: 1 operation in 2761 cycles (1024 bytes)
tcrypt: 1 operation in 9390 cycles (4096 bytes)
tcrypt: 1 operation in 3401 cycles (1024 bytes)
tcrypt: 1 operation in 11876 cycles (4096 bytes)
testing speed of multibuffer ecb(aria) (ecb-aria-avx) decryption
tcrypt: 1 operation in 2735 cycles (1024 bytes)
tcrypt: 1 operation in 9424 cycles (4096 bytes)
tcrypt: 1 operation in 3369 cycles (1024 bytes)
tcrypt: 1 operation in 11954 cycles (4096 bytes)
v5:
- Set CRYPTO_ALG_SKCIPHER_REQSIZE_LARGE flag to avx2, and avx512.
v4:
- Use keystream array in the request ctx.
v3:
- Use ARIA_CTX_enc_key, ARIA_CTX_dec_key, and ARIA_CTX_rounds defines.
v2:
- Add new "add keystream array into struct aria_ctx" patch.
- Use keystream array in the aria_ctx instead of stack memory
Taehee Yoo (4):
crypto: aria: add keystream array into request ctx
crypto: aria: do not use magic number offsets of aria_ctx
crypto: aria: implement aria-avx2
crypto: aria: implement aria-avx512
arch/x86/crypto/Kconfig | 38 + arch/x86/crypto/Makefile | 6 + arch/x86/crypto/aria-aesni-avx-asm_64.S | 26 +- arch/x86/crypto/aria-aesni-avx2-asm_64.S | 1432 +++++++++++++++++++++ arch/x86/crypto/aria-avx.h | 46 + arch/x86/crypto/aria-gfni-avx512-asm_64.S | 1019 +++++++++++++++ arch/x86/crypto/aria_aesni_avx2_glue.c | 252 ++++ arch/x86/crypto/aria_aesni_avx_glue.c | 45 +- arch/x86/crypto/aria_gfni_avx512_glue.c | 250 ++++ arch/x86/kernel/asm-offsets.c | 11 + crypto/aria_generic.c | 4 + 11 files changed, 3101 insertions(+), 28 deletions(-) create mode 100644 arch/x86/crypto/aria-aesni-avx2-asm_64.S create mode 100644 arch/x86/crypto/aria-gfni-avx512-asm_64.S create mode 100644 arch/x86/crypto/aria_aesni_avx2_glue.c create mode 100644 arch/x86/crypto/aria_gfni_avx512_glue.c
Signature · 1 line
2.17.1
PATCH v5 1/4 crypto: aria: add keystream array into request ctx
avx accelerated aria module used local keystream array. But, keystream array size is too big.
So, it puts the keystream array into request ctx.
---
v5:
- No changes.
v4:
- Add aria_avx_request ctx for keystream array
v3:
- No changes.
v2:
- Patch introduced.
arch/x86/crypto/aria_aesni_avx_glue.c | 39 ++++++++++++++++++--------- 1 file changed, 26 insertions(+), 13 deletions(-)
arch/x86/crypto/aria_aesni_avx_glue.c +26 -13
@@ -33,6 +33,10 @@ asmlinkage void aria_aesni_avx_gfni_ctr_crypt_16way(const void *ctx, u8 *dst,static struct aria_avx_ops aria_ops; +struct aria_avx_request_ctx { +u8 keystream[ARIA_AESNI_PARALLEL_BLOCK_SIZE ]; +}; +static int ecb_do_encrypt (struct skcipher_request *req,const u32 *rkey) {ECB_WALK_START (req,ARIA_BLOCK_SIZE ,ARIA_AESNI_PARALLEL_BLOCKS );
@@ -73,6 +77,7 @@ static int aria_avx_set_key(struct crypto_skcipher *tfm, const u8 *key,static int aria_avx_ctr_encrypt (struct skcipher_request *req) { +struct aria_avx_request_ctx *req_ctx =skcipher_request_ctx (req);struct crypto_skcipher *tfm =crypto_skcipher_reqtfm (req);struct aria_ctx *ctx =crypto_skcipher_ctx (tfm);struct skcipher_walk walk;
@@ -86,10 +91,9 @@ static int aria_avx_ctr_encrypt(struct skcipher_request *req)u8 *dst = walk.dst.virt.addr;while (nbytes >=ARIA_AESNI_PARALLEL_BLOCK_SIZE ) { -u8 keystream[ARIA_AESNI_PARALLEL_BLOCK_SIZE ]; -kernel_fpu_begin (); - aria_ops.aria_ctr_crypt_16way (ctx, dst, src, keystream, + aria_ops.aria_ctr_crypt_16way (ctx, dst, src, + &req_ctx->keystream[0 ], walk.iv);kernel_fpu_end (); dst +=ARIA_AESNI_PARALLEL_BLOCK_SIZE ;
@@ -98,28 +102,29 @@ static int aria_avx_ctr_encrypt(struct skcipher_request *req) }while (nbytes >=ARIA_BLOCK_SIZE ) { -u8 keystream[ARIA_BLOCK_SIZE ]; - -memcpy (keystream, walk.iv,ARIA_BLOCK_SIZE ); +memcpy (&req_ctx->keystream[0 ], walk.iv,ARIA_BLOCK_SIZE );crypto_inc (walk.iv,ARIA_BLOCK_SIZE ); -aria_encrypt (ctx, keystream, keystream); +aria_encrypt (ctx, &req_ctx->keystream[0 ], + &req_ctx->keystream[0 ]); -crypto_xor_cpy (dst, src, keystream,ARIA_BLOCK_SIZE ); +crypto_xor_cpy (dst, src, &req_ctx->keystream[0 ], +ARIA_BLOCK_SIZE ); dst +=ARIA_BLOCK_SIZE ; src +=ARIA_BLOCK_SIZE ; nbytes -=ARIA_BLOCK_SIZE ; }if (walk.nbytes == walk.total && nbytes >0 ) { -u8 keystream[ARIA_BLOCK_SIZE ]; - -memcpy (keystream, walk.iv,ARIA_BLOCK_SIZE ); +memcpy (&req_ctx->keystream[0 ], walk.iv, +ARIA_BLOCK_SIZE );crypto_inc (walk.iv,ARIA_BLOCK_SIZE ); -aria_encrypt (ctx, keystream, keystream); +aria_encrypt (ctx, &req_ctx->keystream[0 ], + &req_ctx->keystream[0 ]); -crypto_xor_cpy (dst, src, keystream, nbytes); +crypto_xor_cpy (dst, src, &req_ctx->keystream[0 ], + nbytes); dst += nbytes; src += nbytes; nbytes =0 ;
@@ -130,6 +135,13 @@ static int aria_avx_ctr_encrypt(struct skcipher_request *req)return err; } +static int aria_avx_init_tfm (struct crypto_skcipher *tfm) +{ +crypto_skcipher_set_reqsize (tfm,sizeof (struct aria_avx_request_ctx )); + +return 0 ; +} +static struct skcipher_alg aria_algs[] = { { .base.cra_name ="__ecb(aria)" ,
@@ -160,6 +172,7 @@ static struct skcipher_alg aria_algs[] = { .setkey = aria_avx_set_key, .encrypt = aria_avx_ctr_encrypt, .decrypt = aria_avx_ctr_encrypt, + .init = aria_avx_init_tfm, } };
Signature · 1 line
2.17.1
PATCH v5 2/4 crypto: aria: do not use magic number offsets of aria_ctx
In reply to Taehee Yooaria-avx assembly code accesses members of aria_ctx with magic number offset. If the shape of struct aria_ctx is changed carelessly, aria-avx will not work.
So, we need to ensure accessing members of aria_ctx with correct offset values, not with magic numbers.
It adds ARIA_CTX_enc_key, ARIA_CTX_dec_key, and ARIA_CTX_rounds in the asm-offsets.c So, correct offset definitions will be generated. aria-avx assembly code can access members of aria_ctx safely with these definitions.
---
v5:
- No changes.
v4:
- Add BUILD_BUG_ON() to check size of fields of aria_ctx.
v3:
- Patch introduced.
arch/x86/crypto/aria-aesni-avx-asm_64.S | 26 +++++++++++-------------- arch/x86/kernel/asm-offsets.c | 11 +++++++++++ crypto/aria_generic.c | 4 ++++ 3 files changed, 26 insertions(+), 15 deletions(-)
arch/x86/crypto/aria-aesni-avx-asm_64.S +11 -15
@@ -8,11 +8,7 @@ #include <linux/linkage.h> #include <asm/frame.h> - -/* struct aria_ctx: */ -#define enc_key 0 -#define dec_key 272 -#define rounds 544 +#include <asm/asm-offsets.h> /* register macros */ #define CTX %rdi
@@ -873,7 +869,7 @@ SYM_FUNC_START_LOCAL(__aria_aesni_avx_crypt_16way) aria_fo(%xmm9, %xmm8, %xmm11, %xmm10, %xmm12, %xmm13, %xmm14, %xmm15, %xmm0, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, %xmm7, %rax, %r9, 10); - cmpl $12, rounds(CTX); + cmpl $12, ARIA_CTX_rounds(CTX); jne .Laria_192; aria_ff(%xmm1, %xmm0, %xmm3, %xmm2, %xmm4, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
@@ -886,7 +882,7 @@ SYM_FUNC_START_LOCAL(__aria_aesni_avx_crypt_16way) aria_fo(%xmm9, %xmm8, %xmm11, %xmm10, %xmm12, %xmm13, %xmm14, %xmm15, %xmm0, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, %xmm7, %rax, %r9, 12); - cmpl $14, rounds(CTX); + cmpl $14, ARIA_CTX_rounds(CTX); jne .Laria_256; aria_ff(%xmm1, %xmm0, %xmm3, %xmm2, %xmm4, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
@@ -922,7 +918,7 @@ SYM_FUNC_START(aria_aesni_avx_encrypt_16way) FRAME_BEGIN - leaq enc_key(CTX), %r9; + leaq ARIA_CTX_enc_key(CTX), %r9; inpack16_pre(%xmm0, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
@@ -947,7 +943,7 @@ SYM_FUNC_START(aria_aesni_avx_decrypt_16way) FRAME_BEGIN - leaq dec_key(CTX), %r9; + leaq ARIA_CTX_dec_key(CTX), %r9; inpack16_pre(%xmm0, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
@@ -1055,7 +1051,7 @@ SYM_FUNC_START(aria_aesni_avx_ctr_crypt_16way) leaq (%rdx), %r11; leaq (%rcx), %rsi; leaq (%rcx), %rdx; - leaq enc_key(CTX), %r9; + leaq ARIA_CTX_enc_key(CTX), %r9; call __aria_aesni_avx_crypt_16way;
@@ -1156,7 +1152,7 @@ SYM_FUNC_START_LOCAL(__aria_aesni_avx_gfni_crypt_16way) %xmm0, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, %xmm7, %rax, %r9, 10); - cmpl $12, rounds(CTX); + cmpl $12, ARIA_CTX_rounds(CTX); jne .Laria_gfni_192; aria_ff_gfni(%xmm1, %xmm0, %xmm3, %xmm2, %xmm4, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
@@ -1173,7 +1169,7 @@ SYM_FUNC_START_LOCAL(__aria_aesni_avx_gfni_crypt_16way) %xmm0, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, %xmm7, %rax, %r9, 12); - cmpl $14, rounds(CTX); + cmpl $14, ARIA_CTX_rounds(CTX); jne .Laria_gfni_256; aria_ff_gfni(%xmm1, %xmm0, %xmm3, %xmm2, %xmm4, %xmm5, %xmm6, %xmm7,
@@ -1217,7 +1213,7 @@ SYM_FUNC_START(aria_aesni_avx_gfni_encrypt_16way) FRAME_BEGIN - leaq enc_key(CTX), %r9; + leaq ARIA_CTX_enc_key(CTX), %r9; inpack16_pre(%xmm0, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
@@ -1242,7 +1238,7 @@ SYM_FUNC_START(aria_aesni_avx_gfni_decrypt_16way) FRAME_BEGIN - leaq dec_key(CTX), %r9; + leaq ARIA_CTX_dec_key(CTX), %r9; inpack16_pre(%xmm0, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
@@ -1274,7 +1270,7 @@ SYM_FUNC_START(aria_aesni_avx_gfni_ctr_crypt_16way) leaq (%rdx), %r11; leaq (%rcx), %rsi; leaq (%rcx), %rdx; - leaq enc_key(CTX), %r9; + leaq ARIA_CTX_enc_key(CTX), %r9; call __aria_aesni_avx_gfni_crypt_16way;
arch/x86/kernel/asm-offsets.c +11 -0
@@ -7,6 +7,7 @@#define COMPILE_OFFSETS #include <linux/crypto.h> +#include <crypto/aria.h> #include <linux/sched.h> #include <linux/stddef.h> #include <linux/hardirq.h>
@@ -109,6 +110,16 @@ static void __used common(void)OFFSET (TSS_sp1, tss_struct, x86_tss.sp1);OFFSET (TSS_sp2, tss_struct, x86_tss.sp2); +#if defined(CONFIG_CRYPTO_ARIA_AESNI_AVX_X86_64 ) || \ + defined(CONFIG_CRYPTO_ARIA_AESNI_AVX_X86_64_MODULE ) + +/* Offset for fields in aria_ctx */ +BLANK (); +OFFSET (ARIA_CTX_enc_key, aria_ctx, enc_key); +OFFSET (ARIA_CTX_dec_key, aria_ctx, dec_key); +OFFSET (ARIA_CTX_rounds, aria_ctx, rounds); +#endif +if (IS_ENABLED (CONFIG_KVM_INTEL )) {BLANK ();OFFSET (VMX_spec_ctrl, vcpu_vmx, spec_ctrl);
crypto/aria_generic.c +4 -0
@@ -178,6 +178,10 @@ int aria_set_key(struct crypto_tfm *tfm, const u8 *in_key, unsigned int key_len)if (key_len !=16 && key_len !=24 && key_len !=32 )return -EINVAL ; +BUILD_BUG_ON (sizeof (ctx->enc_key) !=272 ); +BUILD_BUG_ON (sizeof (ctx->dec_key) !=272 ); +BUILD_BUG_ON (sizeof (int ) !=sizeof (ctx->rounds)); + ctx->key_length = key_len; ctx->rounds = (key_len +32 ) /4 ;
Signature · 1 line
2.17.1
PATCH v5 3/4 crypto: aria: implement aria-avx2
In reply to Taehee Yooaria-avx2 implementation uses AVX2, AES-NI, and GFNI.
It supports 32way parallel processing.
So, byteslicing code is changed to support 32way parallel. And it exports some aria-avx functions such as encrypt() and decrypt().
There are two main logics, s-box layer and diffusion layer. These codes are the same as aria-avx implementation.
But some instruction are exchanged because they don't support 256bit registers.
Also, AES-NI doesn't support 256bit register.
So, aesenclast and aesdeclast are used twice like below:
vextracti128 $1, ymm0, xmm6; vaesenclast xmm7, xmm0, xmm0; vaesenclast xmm7, xmm6, xmm6; vinserti128 $1, xmm6, ymm0, ymm0;
Benchmark with modprobe tcrypt mode=610 num_mb=8192, i3-12100:
ARIA-AVX2 with GFNI(128bit and 256bit)
testing speed of multibuffer ecb(aria) (ecb-aria-avx2) encryption
tcrypt: 1 operation in 2003 cycles (1024 bytes)
tcrypt: 1 operation in 5867 cycles (4096 bytes)
tcrypt: 1 operation in 2358 cycles (1024 bytes)
tcrypt: 1 operation in 7295 cycles (4096 bytes)
testing speed of multibuffer ecb(aria) (ecb-aria-avx2) decryption
tcrypt: 1 operation in 2004 cycles (1024 bytes)
tcrypt: 1 operation in 5956 cycles (4096 bytes)
tcrypt: 1 operation in 2409 cycles (1024 bytes)
tcrypt: 1 operation in 7564 cycles (4096 bytes)
ARIA-AVX with GFNI(128bit and 256bit)
testing speed of multibuffer ecb(aria) (ecb-aria-avx) encryption
tcrypt: 1 operation in 2761 cycles (1024 bytes)
tcrypt: 1 operation in 9390 cycles (4096 bytes)
tcrypt: 1 operation in 3401 cycles (1024 bytes)
tcrypt: 1 operation in 11876 cycles (4096 bytes)
testing speed of multibuffer ecb(aria) (ecb-aria-avx) decryption
tcrypt: 1 operation in 2735 cycles (1024 bytes)
tcrypt: 1 operation in 9424 cycles (4096 bytes)
tcrypt: 1 operation in 3369 cycles (1024 bytes)
tcrypt: 1 operation in 11954 cycles (4096 bytes)
---
v5:
- Set CRYPTO_ALG_SKCIPHER_REQSIZE_LARGE flag.
v4:
- Add aria_avx2_request_ctx for keystream array.
v3:
- Use ARIA_CTX_enc_key, ARIA_CTX_dec_key, and ARIA_CTX_rounds defines.
v2:
- Add new "add keystream array into struct aria_ctx" patch.
- Use keystream array in the aria_ctx instead of stack memory
arch/x86/crypto/Kconfig | 19 + arch/x86/crypto/Makefile | 3 + arch/x86/crypto/aria-aesni-avx2-asm_64.S | 1432 ++++++++++++++++++++++ arch/x86/crypto/aria-avx.h | 38 + arch/x86/crypto/aria_aesni_avx2_glue.c | 252 ++++ arch/x86/crypto/aria_aesni_avx_glue.c | 6 + 6 files changed, 1750 insertions(+) create mode 100644 arch/x86/crypto/aria-aesni-avx2-asm_64.S create mode 100644 arch/x86/crypto/aria_aesni_avx2_glue.c
arch/x86/crypto/Kconfig +19 -0
@@ -304,6 +304,25 @@ config CRYPTO_ARIA_AESNI_AVX_X86_64 Processes 16 blocks in parallel. +config CRYPTO_ARIA_AESNI_AVX2_X86_64 + tristate "Ciphers: ARIA with modes: ECB, CTR (AES-NI/AVX2/GFNI)" + depends on X86 && 64BIT + select CRYPTO_SKCIPHER + select CRYPTO_SIMD + select CRYPTO_ALGAPI + select CRYPTO_ARIA + select CRYPTO_ARIA_AESNI_AVX_X86_64 + help + Length-preserving cipher: ARIA cipher algorithms + (RFC 5794) with ECB and CTR modes + + Architecture: x86_64 using: + - AES-NI (AES New Instructions) + - AVX2 (Advanced Vector Extensions) + - GFNI (Galois Field New Instructions) + + Processes 32 blocks in parallel. + config CRYPTO_CHACHA20_X86_64 tristate "Ciphers: ChaCha20, XChaCha20, XChaCha12 (SSSE3/AVX2/AVX-512VL)" depends on X86 && 64BIT
arch/x86/crypto/Makefile +3 -0
@@ -103,6 +103,9 @@ sm4-aesni-avx2-x86_64-y := sm4-aesni-avx2-asm_64.o sm4_aesni_avx2_glue.o obj-$(CONFIG_CRYPTO_ARIA_AESNI_AVX_X86_64) += aria-aesni-avx-x86_64.o aria-aesni-avx-x86_64-y := aria-aesni-avx-asm_64.o aria_aesni_avx_glue.o +obj-$(CONFIG_CRYPTO_ARIA_AESNI_AVX2_X86_64) += aria-aesni-avx2-x86_64.o +aria-aesni-avx2-x86_64-y := aria-aesni-avx2-asm_64.o aria_aesni_avx2_glue.o + quiet_cmd_perlasm = PERLASM $@ cmd_perlasm = $(PERL) $< > $@ $(obj)/%.S: $(src)/%.pl FORCE
arch/x86/crypto/aria-aesni-avx2-asm_64.S new file +1432 -0
1,432 lines not on this page · raw message
arch/x86/crypto/aria-avx.h +38 -0
@@ -7,10 +7,48 @@#define ARIA_AESNI_PARALLEL_BLOCKS 16#define ARIA_AESNI_PARALLEL_BLOCK_SIZE (ARIA_BLOCK_SIZE * 16) +#define ARIA_AESNI_AVX2_PARALLEL_BLOCKS 32 +#define ARIA_AESNI_AVX2_PARALLEL_BLOCK_SIZE (ARIA_BLOCK_SIZE * 32) + +asmlinkage void aria_aesni_avx_encrypt_16way(const void *ctx, u8 *dst, +const u8 *src); +asmlinkage void aria_aesni_avx_decrypt_16way(const void *ctx, u8 *dst, +const u8 *src); +asmlinkage void aria_aesni_avx_ctr_crypt_16way(const void *ctx, u8 *dst, +const u8 *src, +u8 *keystream,u8 *iv); +asmlinkage void aria_aesni_avx_gfni_encrypt_16way(const void *ctx, u8 *dst, +const u8 *src); +asmlinkage void aria_aesni_avx_gfni_decrypt_16way(const void *ctx, u8 *dst, +const u8 *src); +asmlinkage void aria_aesni_avx_gfni_ctr_crypt_16way(const void *ctx, u8 *dst, +const u8 *src, +u8 *keystream,u8 *iv); + +asmlinkage void aria_aesni_avx2_encrypt_32way(const void *ctx, u8 *dst, +const u8 *src); +asmlinkage void aria_aesni_avx2_decrypt_32way(const void *ctx, u8 *dst, +const u8 *src); +asmlinkage void aria_aesni_avx2_ctr_crypt_32way(const void *ctx, u8 *dst, +const u8 *src, +u8 *keystream,u8 *iv); +asmlinkage void aria_aesni_avx2_gfni_encrypt_32way(const void *ctx, u8 *dst, +const u8 *src); +asmlinkage void aria_aesni_avx2_gfni_decrypt_32way(const void *ctx, u8 *dst, +const u8 *src); +asmlinkage void aria_aesni_avx2_gfni_ctr_crypt_32way(const void *ctx, u8 *dst, +const u8 *src, +u8 *keystream,u8 *iv); +struct aria_avx_ops {void (*aria_encrypt_16way)(const void *ctx,u8 *dst,const u8 *src);void (*aria_decrypt_16way)(const void *ctx,u8 *dst,const u8 *src);void (*aria_ctr_crypt_16way)(const void *ctx,u8 *dst,const u8 *src,u8 *keystream,u8 *iv); +void (*aria_encrypt_32way)(const void *ctx,u8 *dst,const u8 *src); +void (*aria_decrypt_32way)(const void *ctx,u8 *dst,const u8 *src); +void (*aria_ctr_crypt_32way)(const void *ctx,u8 *dst,const u8 *src, +u8 *keystream,u8 *iv); + };#endif
arch/x86/crypto/aria_aesni_avx2_glue.c new file +252 -0
252 lines not on this page · raw message
arch/x86/crypto/aria_aesni_avx_glue.c +6 -0
@@ -18,18 +18,24 @@ asmlinkage void aria_aesni_avx_encrypt_16way(const void *ctx, u8 *dst,const u8 *src); +EXPORT_SYMBOL_GPL (aria_aesni_avx_encrypt_16way); asmlinkage void aria_aesni_avx_decrypt_16way(const void *ctx, u8 *dst,const u8 *src); +EXPORT_SYMBOL_GPL (aria_aesni_avx_decrypt_16way); asmlinkage void aria_aesni_avx_ctr_crypt_16way(const void *ctx, u8 *dst,const u8 *src,u8 *keystream,u8 *iv); +EXPORT_SYMBOL_GPL (aria_aesni_avx_ctr_crypt_16way); asmlinkage void aria_aesni_avx_gfni_encrypt_16way(const void *ctx, u8 *dst,const u8 *src); +EXPORT_SYMBOL_GPL (aria_aesni_avx_gfni_encrypt_16way); asmlinkage void aria_aesni_avx_gfni_decrypt_16way(const void *ctx, u8 *dst,const u8 *src); +EXPORT_SYMBOL_GPL (aria_aesni_avx_gfni_decrypt_16way); asmlinkage void aria_aesni_avx_gfni_ctr_crypt_16way(const void *ctx, u8 *dst,const u8 *src,u8 *keystream,u8 *iv); +EXPORT_SYMBOL_GPL (aria_aesni_avx_gfni_ctr_crypt_16way);static struct aria_avx_ops aria_ops;
Signature · 1 line
2.17.1
Re: [PATCH v5 3/4] crypto: aria: implement aria-avx2
Quoted 1 line · Taehee Yoo
+SYM_FUNC_START(aria_aesni_avx2_encrypt_32way)
Please use SYM_TYPED_FUNC_START (and include <linux/cfi_types.h>) for all assembly functions that are called via indirect function calls. Otherwise the code will crash when built with CONFIG_CFI_CLANG=y.
- Eric
Re: [PATCH v5 3/4] crypto: aria: implement aria-avx2
Hi Eric,
Thank you so much for your review!
Quoted 8 lines · Eric Biggers
Quoted 1 line · Taehee Yoo
+SYM_FUNC_START(aria_aesni_avx2_encrypt_32way)
Please use
SYM_TYPED_FUNC_START(and include <linux/cfi_types.h>) for all assembly functions that are called via indirect function calls. Otherwise the code will crash when built withCONFIG_CFI_CLANG=y.- Eric
Okay, I will use SYM_TYPED_FUNC_START for avx2 and avx512 in the v6 patchset.
Thanks a lot!
Taehee Yoo
PATCH v5 4/4 crypto: aria: implement aria-avx512
In reply to Taehee Yooaria-avx512 implementation uses AVX512 and GFNI.
It supports 64way parallel processing.
So, byteslicing code is changed to support 64way parallel. And it exports some aria-avx2 functions such as encrypt() and decrypt().
AVX and AVX2 have 16 registers.
They should use memory to store/load state because of lack of registers. But AVX512 supports 32 registers.
So, it doesn't require store/load in the s-box layer.
It means that it can reduce overhead of store/load in the s-box layer. Also code become much simpler.
Benchmark with modprobe tcrypt mode=610 num_mb=8192, i3-12100:
ARIA-AVX512(128bit and 256bit)
testing speed of multibuffer ecb(aria) (ecb-aria-avx512) encryption
tcrypt: 1 operation in 1504 cycles (1024 bytes)
tcrypt: 1 operation in 4595 cycles (4096 bytes)
tcrypt: 1 operation in 1763 cycles (1024 bytes)
tcrypt: 1 operation in 5540 cycles (4096 bytes)
testing speed of multibuffer ecb(aria) (ecb-aria-avx512) decryption
tcrypt: 1 operation in 1502 cycles (1024 bytes)
tcrypt: 1 operation in 4615 cycles (4096 bytes)
tcrypt: 1 operation in 1759 cycles (1024 bytes)
tcrypt: 1 operation in 5554 cycles (4096 bytes)
ARIA-AVX2 with GFNI(128bit and 256bit)
testing speed of multibuffer ecb(aria) (ecb-aria-avx2) encryption
tcrypt: 1 operation in 2003 cycles (1024 bytes)
tcrypt: 1 operation in 5867 cycles (4096 bytes)
tcrypt: 1 operation in 2358 cycles (1024 bytes)
tcrypt: 1 operation in 7295 cycles (4096 bytes)
testing speed of multibuffer ecb(aria) (ecb-aria-avx2) decryption
tcrypt: 1 operation in 2004 cycles (1024 bytes)
tcrypt: 1 operation in 5956 cycles (4096 bytes)
tcrypt: 1 operation in 2409 cycles (1024 bytes)
tcrypt: 1 operation in 7564 cycles (4096 bytes)
---
v5:
- Set CRYPTO_ALG_SKCIPHER_REQSIZE_LARGE flag.
v4:
- Add aria_avx512_request_ctx for keystream array.
v3:
- Use ARIA_CTX_enc_key, ARIA_CTX_dec_key, and ARIA_CTX_rounds defines.
v2:
- Add new "add keystream array into struct aria_ctx" patch.
- Use keystream array in the aria_ctx instead of stack memory
arch/x86/crypto/Kconfig | 19 + arch/x86/crypto/Makefile | 3 + arch/x86/crypto/aria-avx.h | 8 + arch/x86/crypto/aria-gfni-avx512-asm_64.S | 1019 +++++++++++++++++++++ arch/x86/crypto/aria_gfni_avx512_glue.c | 250 +++++ 5 files changed, 1299 insertions(+) create mode 100644 arch/x86/crypto/aria-gfni-avx512-asm_64.S create mode 100644 arch/x86/crypto/aria_gfni_avx512_glue.c
arch/x86/crypto/Kconfig +19 -0
@@ -323,6 +323,25 @@ config CRYPTO_ARIA_AESNI_AVX2_X86_64 Processes 32 blocks in parallel. +config CRYPTO_ARIA_GFNI_AVX512_X86_64 + tristate "Ciphers: ARIA with modes: ECB, CTR (AVX512/GFNI)" + depends on X86 && 64BIT + select CRYPTO_SKCIPHER + select CRYPTO_SIMD + select CRYPTO_ALGAPI + select CRYPTO_ARIA + select CRYPTO_ARIA_AESNI_AVX_X86_64 + select CRYPTO_ARIA_AESNI_AVX2_X86_64 + help + Length-preserving cipher: ARIA cipher algorithms + (RFC 5794) with ECB and CTR modes + + Architecture: x86_64 using: + - AVX512 (Advanced Vector Extensions) + - GFNI (Galois Field New Instructions) + + Processes 64 blocks in parallel. + config CRYPTO_CHACHA20_X86_64 tristate "Ciphers: ChaCha20, XChaCha20, XChaCha12 (SSSE3/AVX2/AVX-512VL)" depends on X86 && 64BIT
arch/x86/crypto/Makefile +3 -0
@@ -106,6 +106,9 @@ aria-aesni-avx-x86_64-y := aria-aesni-avx-asm_64.o aria_aesni_avx_glue.o obj-$(CONFIG_CRYPTO_ARIA_AESNI_AVX2_X86_64) += aria-aesni-avx2-x86_64.o aria-aesni-avx2-x86_64-y := aria-aesni-avx2-asm_64.o aria_aesni_avx2_glue.o +obj-$(CONFIG_CRYPTO_ARIA_GFNI_AVX512_X86_64) += aria-gfni-avx512-x86_64.o +aria-gfni-avx512-x86_64-y := aria-gfni-avx512-asm_64.o aria_gfni_avx512_glue.o + quiet_cmd_perlasm = PERLASM $@ cmd_perlasm = $(PERL) $< > $@ $(obj)/%.S: $(src)/%.pl FORCE
arch/x86/crypto/aria-avx.h +8 -0
@@ -10,6 +10,9 @@#define ARIA_AESNI_AVX2_PARALLEL_BLOCKS 32#define ARIA_AESNI_AVX2_PARALLEL_BLOCK_SIZE (ARIA_BLOCK_SIZE * 32) +#define ARIA_GFNI_AVX512_PARALLEL_BLOCKS 64 +#define ARIA_GFNI_AVX512_PARALLEL_BLOCK_SIZE (ARIA_BLOCK_SIZE * 64) + asmlinkage void aria_aesni_avx_encrypt_16way(const void *ctx, u8 *dst,const u8 *src); asmlinkage void aria_aesni_avx_decrypt_16way(const void *ctx, u8 *dst,
@@ -49,6 +52,11 @@ struct aria_avx_ops {void (*aria_decrypt_32way)(const void *ctx,u8 *dst,const u8 *src);void (*aria_ctr_crypt_32way)(const void *ctx,u8 *dst,const u8 *src,u8 *keystream,u8 *iv); +void (*aria_encrypt_64way)(const void *ctx,u8 *dst,const u8 *src); +void (*aria_decrypt_64way)(const void *ctx,u8 *dst,const u8 *src); +void (*aria_ctr_crypt_64way)(const void *ctx,u8 *dst,const u8 *src, + u8 *keystream, u8 *iv); + };#endif
arch/x86/crypto/aria-gfni-avx512-asm_64.S new file +1019 -0
1,019 lines not on this page · raw message
arch/x86/crypto/aria_gfni_avx512_glue.c new file +250 -0
250 lines not on this page · raw message
Signature · 1 line
2.17.1