Skip to content

Commit 60af520

Browse files
tstrukherbertx
authored andcommitted
crypto: aesni-intel - fixed problem with packets that are not multiple of 64bytes
This patch fixes problem with packets that are not multiple of 64bytes. Signed-off-by: Adrian Hoban <adrian.hoban@intel.com> Signed-off-by: Aidan O'Mahony <aidan.o.mahony@intel.com> Signed-off-by: Gabriele Paoloni <gabriele.paoloni@intel.com> Signed-off-by: Tadeusz Struk <tadeusz.struk@intel.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 16c29da commit 60af520

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

‎arch/x86/crypto/aesni-intel_asm.S‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1612,6 +1612,7 @@ _zero_cipher_left_encrypt:
16121612
movdqa SHUF_MASK(%rip), %xmm10
16131613
PSHUFB_XMM %xmm10, %xmm0
16141614

1615+
16151616
ENCRYPT_SINGLE_BLOCK %xmm0, %xmm1 # Encrypt(K, Yn)
16161617
sub $16, %r11
16171618
add %r13, %r11
@@ -1634,7 +1635,9 @@ _zero_cipher_left_encrypt:
16341635
# GHASH computation for the last <16 byte block
16351636
sub %r13, %r11
16361637
add $16, %r11
1637-
PSHUFB_XMM %xmm10, %xmm1
1638+
1639+
movdqa SHUF_MASK(%rip), %xmm10
1640+
PSHUFB_XMM %xmm10, %xmm0
16381641

16391642
# shuffle xmm0 back to output as ciphertext
16401643

‎arch/x86/crypto/aesni-intel_glue.c‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -828,9 +828,15 @@ static int rfc4106_init(struct crypto_tfm *tfm)
828828
struct cryptd_aead *cryptd_tfm;
829829
struct aesni_rfc4106_gcm_ctx *ctx = (struct aesni_rfc4106_gcm_ctx *)
830830
PTR_ALIGN((u8 *)crypto_tfm_ctx(tfm), AESNI_ALIGN);
831+
struct crypto_aead *cryptd_child;
832+
struct aesni_rfc4106_gcm_ctx *child_ctx;
831833
cryptd_tfm = cryptd_alloc_aead("__driver-gcm-aes-aesni", 0, 0);
832834
if (IS_ERR(cryptd_tfm))
833835
return PTR_ERR(cryptd_tfm);
836+
837+
cryptd_child = cryptd_aead_child(cryptd_tfm);
838+
child_ctx = aesni_rfc4106_gcm_ctx_get(cryptd_child);
839+
memcpy(child_ctx, ctx, sizeof(*ctx));
834840
ctx->cryptd_tfm = cryptd_tfm;
835841
tfm->crt_aead.reqsize = sizeof(struct aead_request)
836842
+ crypto_aead_reqsize(&cryptd_tfm->base);
@@ -923,6 +929,9 @@ static int rfc4106_set_key(struct crypto_aead *parent, const u8 *key,
923929
int ret = 0;
924930
struct crypto_tfm *tfm = crypto_aead_tfm(parent);
925931
struct aesni_rfc4106_gcm_ctx *ctx = aesni_rfc4106_gcm_ctx_get(parent);
932+
struct crypto_aead *cryptd_child = cryptd_aead_child(ctx->cryptd_tfm);
933+
struct aesni_rfc4106_gcm_ctx *child_ctx =
934+
aesni_rfc4106_gcm_ctx_get(cryptd_child);
926935
u8 *new_key_mem = NULL;
927936

928937
if (key_len < 4) {
@@ -966,6 +975,7 @@ static int rfc4106_set_key(struct crypto_aead *parent, const u8 *key,
966975
goto exit;
967976
}
968977
ret = rfc4106_set_hash_subkey(ctx->hash_subkey, key, key_len);
978+
memcpy(child_ctx, ctx, sizeof(*ctx));
969979
exit:
970980
kfree(new_key_mem);
971981
return ret;
@@ -997,7 +1007,6 @@ static int rfc4106_encrypt(struct aead_request *req)
9971007
int ret;
9981008
struct crypto_aead *tfm = crypto_aead_reqtfm(req);
9991009
struct aesni_rfc4106_gcm_ctx *ctx = aesni_rfc4106_gcm_ctx_get(tfm);
1000-
struct crypto_aead *cryptd_child = cryptd_aead_child(ctx->cryptd_tfm);
10011010

10021011
if (!irq_fpu_usable()) {
10031012
struct aead_request *cryptd_req =
@@ -1006,6 +1015,7 @@ static int rfc4106_encrypt(struct aead_request *req)
10061015
aead_request_set_tfm(cryptd_req, &ctx->cryptd_tfm->base);
10071016
return crypto_aead_encrypt(cryptd_req);
10081017
} else {
1018+
struct crypto_aead *cryptd_child = cryptd_aead_child(ctx->cryptd_tfm);
10091019
kernel_fpu_begin();
10101020
ret = cryptd_child->base.crt_aead.encrypt(req);
10111021
kernel_fpu_end();
@@ -1018,7 +1028,6 @@ static int rfc4106_decrypt(struct aead_request *req)
10181028
int ret;
10191029
struct crypto_aead *tfm = crypto_aead_reqtfm(req);
10201030
struct aesni_rfc4106_gcm_ctx *ctx = aesni_rfc4106_gcm_ctx_get(tfm);
1021-
struct crypto_aead *cryptd_child = cryptd_aead_child(ctx->cryptd_tfm);
10221031

10231032
if (!irq_fpu_usable()) {
10241033
struct aead_request *cryptd_req =
@@ -1027,6 +1036,7 @@ static int rfc4106_decrypt(struct aead_request *req)
10271036
aead_request_set_tfm(cryptd_req, &ctx->cryptd_tfm->base);
10281037
return crypto_aead_decrypt(cryptd_req);
10291038
} else {
1039+
struct crypto_aead *cryptd_child = cryptd_aead_child(ctx->cryptd_tfm);
10301040
kernel_fpu_begin();
10311041
ret = cryptd_child->base.crt_aead.decrypt(req);
10321042
kernel_fpu_end();

0 commit comments

Comments
 (0)