Skip to content

Commit 7af964c

Browse files
Dave Watsonherbertx
authored andcommitted
crypto: aesni - Add GCM_INIT macro
Reduce code duplication by introducting GCM_INIT macro. This macro will also be exposed as a function for implementing scatter/gather support, since INIT only needs to be called once for the full operation. Signed-off-by: Dave Watson <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent 6c2c86b commit 7af964c

File tree

1 file changed

+33
-51
lines changed

1 file changed

+33
-51
lines changed

arch/x86/crypto/aesni-intel_asm.S

Lines changed: 33 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,37 @@ ALL_F: .octa 0xffffffffffffffffffffffffffffffff
192192
pop %r12
193193
.endm
194194

195+
196+
# GCM_INIT initializes a gcm_context struct to prepare for encoding/decoding.
197+
# Clobbers rax, r10-r13 and xmm0-xmm6, %xmm13
198+
.macro GCM_INIT
199+
mov %arg6, %r12
200+
movdqu (%r12), %xmm13
201+
movdqa SHUF_MASK(%rip), %xmm2
202+
PSHUFB_XMM %xmm2, %xmm13
203+
204+
# precompute HashKey<<1 mod poly from the HashKey (required for GHASH)
205+
206+
movdqa %xmm13, %xmm2
207+
psllq $1, %xmm13
208+
psrlq $63, %xmm2
209+
movdqa %xmm2, %xmm1
210+
pslldq $8, %xmm2
211+
psrldq $8, %xmm1
212+
por %xmm2, %xmm13
213+
214+
# reduce HashKey<<1
215+
216+
pshufd $0x24, %xmm1, %xmm2
217+
pcmpeqd TWOONE(%rip), %xmm2
218+
pand POLY(%rip), %xmm2
219+
pxor %xmm2, %xmm13
220+
movdqa %xmm13, HashKey(%rsp)
221+
mov %arg4, %r13 # %xmm13 holds HashKey<<1 (mod poly)
222+
and $-16, %r13
223+
mov %r13, %r12
224+
.endm
225+
195226
#ifdef __x86_64__
196227
/* GHASH_MUL MACRO to implement: Data*HashKey mod (128,127,126,121,0)
197228
*
@@ -1152,36 +1183,11 @@ _esb_loop_\@:
11521183
*****************************************************************************/
11531184
ENTRY(aesni_gcm_dec)
11541185
FUNC_SAVE
1155-
mov %arg6, %r12
1156-
movdqu (%r12), %xmm13 # %xmm13 = HashKey
1157-
movdqa SHUF_MASK(%rip), %xmm2
1158-
PSHUFB_XMM %xmm2, %xmm13
1159-
1160-
1161-
# Precompute HashKey<<1 (mod poly) from the hash key (required for GHASH)
1162-
1163-
movdqa %xmm13, %xmm2
1164-
psllq $1, %xmm13
1165-
psrlq $63, %xmm2
1166-
movdqa %xmm2, %xmm1
1167-
pslldq $8, %xmm2
1168-
psrldq $8, %xmm1
1169-
por %xmm2, %xmm13
1170-
1171-
# Reduction
1172-
1173-
pshufd $0x24, %xmm1, %xmm2
1174-
pcmpeqd TWOONE(%rip), %xmm2
1175-
pand POLY(%rip), %xmm2
1176-
pxor %xmm2, %xmm13 # %xmm13 holds the HashKey<<1 (mod poly)
11771186

1187+
GCM_INIT
11781188

11791189
# Decrypt first few blocks
11801190

1181-
movdqa %xmm13, HashKey(%rsp) # store HashKey<<1 (mod poly)
1182-
mov %arg4, %r13 # save the number of bytes of plaintext/ciphertext
1183-
and $-16, %r13 # %r13 = %r13 - (%r13 mod 16)
1184-
mov %r13, %r12
11851191
and $(3<<4), %r12
11861192
jz _initial_num_blocks_is_0_decrypt
11871193
cmp $(2<<4), %r12
@@ -1403,32 +1409,8 @@ ENDPROC(aesni_gcm_dec)
14031409
***************************************************************************/
14041410
ENTRY(aesni_gcm_enc)
14051411
FUNC_SAVE
1406-
mov %arg6, %r12
1407-
movdqu (%r12), %xmm13
1408-
movdqa SHUF_MASK(%rip), %xmm2
1409-
PSHUFB_XMM %xmm2, %xmm13
1410-
1411-
# precompute HashKey<<1 mod poly from the HashKey (required for GHASH)
1412-
1413-
movdqa %xmm13, %xmm2
1414-
psllq $1, %xmm13
1415-
psrlq $63, %xmm2
1416-
movdqa %xmm2, %xmm1
1417-
pslldq $8, %xmm2
1418-
psrldq $8, %xmm1
1419-
por %xmm2, %xmm13
1420-
1421-
# reduce HashKey<<1
1422-
1423-
pshufd $0x24, %xmm1, %xmm2
1424-
pcmpeqd TWOONE(%rip), %xmm2
1425-
pand POLY(%rip), %xmm2
1426-
pxor %xmm2, %xmm13
1427-
movdqa %xmm13, HashKey(%rsp)
1428-
mov %arg4, %r13 # %xmm13 holds HashKey<<1 (mod poly)
1429-
and $-16, %r13
1430-
mov %r13, %r12
14311412

1413+
GCM_INIT
14321414
# Encrypt first few blocks
14331415

14341416
and $(3<<4), %r12

0 commit comments

Comments
 (0)