[PATCH 3/3] camellia-aesni-avx2-amd64: Move register clearing to assembly functions

Jussi Kivilinna jussi.kivilinna at iki.fi
Sun Sep 1 15:54:19 CEST 2013


* cipher/camellia-aesni-avx2-amd64.S
(_gcry_camellia_aesni_avx2_ctr_enc): Add 'vzeroall'.
(_gcry_camellia_aesni_avx2_cbc_dec)
(_gcry_camellia_aesni_avx2_cfb_dec): Add 'vzeroupper' at head and
'vzeroall' at tail.
* cipher/camellia-glue.c (_gcry_serpent_ctr_enc, _gcry_serpent_cbc_dec)
(_gcry_serpent_avx2_cfb_dec) [USE_AESNI_AVX2]: Remove register
clearing.
--

Patch moves register clearing with 'vzeroall' to assembly functions and
adds missing 'vzeroupper' instructions at head of assembly functions.

Signed-off-by: Jussi Kivilinna <jussi.kivilinna at iki.fi>
---
 cipher/camellia-aesni-avx2-amd64.S |   10 ++++++++++
 cipher/camellia-glue.c             |    9 ---------
 2 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/cipher/camellia-aesni-avx2-amd64.S b/cipher/camellia-aesni-avx2-amd64.S
index da427b4..7e31323 100644
--- a/cipher/camellia-aesni-avx2-amd64.S
+++ b/cipher/camellia-aesni-avx2-amd64.S
@@ -1104,6 +1104,8 @@ _gcry_camellia_aesni_avx2_ctr_enc:
 		     %ymm15, %ymm14, %ymm13, %ymm12, %ymm11, %ymm10, %ymm9,
 		     %ymm8, %rsi);
 
+	vzeroall;
+
 	ret;
 .size _gcry_camellia_aesni_avx2_ctr_enc,.-_gcry_camellia_aesni_avx2_ctr_enc;
 
@@ -1119,6 +1121,8 @@ _gcry_camellia_aesni_avx2_cbc_dec:
 	 *	%rcx: iv
 	 */
 
+	vzeroupper;
+
 	movq %rcx, %r9;
 
 	cmpl $128, key_bitlength(CTX);
@@ -1171,6 +1175,8 @@ _gcry_camellia_aesni_avx2_cbc_dec:
 	movq %rax, (0)(%r9);
 	movq %rcx, (8)(%r9);
 
+	vzeroall;
+
 	ret;
 .size _gcry_camellia_aesni_avx2_cbc_dec,.-_gcry_camellia_aesni_avx2_cbc_dec;
 
@@ -1186,6 +1192,8 @@ _gcry_camellia_aesni_avx2_cfb_dec:
 	 *	%rcx: iv
 	 */
 
+	vzeroupper;
+
 	movq %rsp, %r10;
 	subq $(16 * 32), %rsp;
 	andq $~31, %rsp;
@@ -1240,6 +1248,8 @@ _gcry_camellia_aesni_avx2_cfb_dec:
 		     %ymm15, %ymm14, %ymm13, %ymm12, %ymm11, %ymm10, %ymm9,
 		     %ymm8, %rsi);
 
+	vzeroall;
+
 	ret;
 .size _gcry_camellia_aesni_avx2_cfb_dec,.-_gcry_camellia_aesni_avx2_cfb_dec;
 
diff --git a/cipher/camellia-glue.c b/cipher/camellia-glue.c
index 7d8a4cd..d6d6005 100644
--- a/cipher/camellia-glue.c
+++ b/cipher/camellia-glue.c
@@ -314,9 +314,6 @@ _gcry_camellia_ctr_enc(void *context, unsigned char *ctr,
           int avx2_burn_stack_depth = 32 * CAMELLIA_BLOCK_SIZE + 16 +
                                         2 * sizeof(void *);
 
-          /* clear AVX registers */
-          asm volatile ("vzeroall;\n":::);
-
           if (burn_stack_depth < avx2_burn_stack_depth)
             burn_stack_depth = avx2_burn_stack_depth;
         }
@@ -408,9 +405,6 @@ _gcry_camellia_cbc_dec(void *context, unsigned char *iv,
           int avx2_burn_stack_depth = 32 * CAMELLIA_BLOCK_SIZE + 16 +
                                         2 * sizeof(void *);
 
-          /* clear AVX registers */
-          asm volatile ("vzeroall;\n":::);
-
           if (burn_stack_depth < avx2_burn_stack_depth)
             burn_stack_depth = avx2_burn_stack_depth;
         }
@@ -496,9 +490,6 @@ _gcry_camellia_cfb_dec(void *context, unsigned char *iv,
           int avx2_burn_stack_depth = 32 * CAMELLIA_BLOCK_SIZE + 16 +
                                         2 * sizeof(void *);
 
-          /* clear AVX registers */
-          asm volatile ("vzeroall;\n":::);
-
           if (burn_stack_depth < avx2_burn_stack_depth)
             burn_stack_depth = avx2_burn_stack_depth;
         }




More information about the Gcrypt-devel mailing list