@@ -192,6 +192,37 @@ ALL_F: .octa 0xffffffffffffffffffffffffffffffff
192
192
pop %r12
193
193
.endm
194
194
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
+
195
226
#ifdef __x86_64__
196
227
/* GHASH_MUL MACRO to implement: Data*HashKey mod (128,127,126,121,0)
197
228
*
@@ -1152,36 +1183,11 @@ _esb_loop_\@:
1152
1183
*****************************************************************************/
1153
1184
ENTRY(aesni_gcm_dec)
1154
1185
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)
1177
1186
1187
+ GCM_INIT
1178
1188
1179
1189
# Decrypt first few blocks
1180
1190
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
1185
1191
and $(3 <<4 ), %r12
1186
1192
jz _initial_num_blocks_is_0_decrypt
1187
1193
cmp $(2 <<4 ), %r12
@@ -1403,32 +1409,8 @@ ENDPROC(aesni_gcm_dec)
1403
1409
***************************************************************************/
1404
1410
ENTRY(aesni_gcm_enc)
1405
1411
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
1431
1412
1413
+ GCM_INIT
1432
1414
# Encrypt first few blocks
1433
1415
1434
1416
and $(3 <<4 ), %r12
0 commit comments