Skip to content

Commit 78cf1c8

Browse files
committed
crypto: inside-secure - Move ipad/opad into safexcel_context
As both safexcel_ahash_ctx and safexcel_cipher_ctx contain ipad and opad buffers this patch moves them into the common struct safexcel_context. It also adds a union so that they can be accessed in the appropriate endian without crazy casts. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 18e5189 commit 78cf1c8

3 files changed

Lines changed: 72 additions & 63 deletions

File tree

‎drivers/crypto/inside-secure/safexcel.h‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
#include <crypto/algapi.h>
1313
#include <crypto/internal/hash.h>
1414
#include <crypto/sha.h>
15+
#include <crypto/sha3.h>
1516
#include <crypto/skcipher.h>
17+
#include <linux/types.h>
1618

1719
#define EIP197_HIA_VERSION_BE 0xca35
1820
#define EIP197_HIA_VERSION_LE 0x35ca
@@ -835,6 +837,13 @@ struct safexcel_context {
835837
struct safexcel_crypto_priv *priv;
836838
dma_addr_t ctxr_dma;
837839

840+
union {
841+
__le32 le[SHA3_512_BLOCK_SIZE / 4];
842+
__be32 be[SHA3_512_BLOCK_SIZE / 4];
843+
u32 word[SHA3_512_BLOCK_SIZE / 4];
844+
u8 byte[SHA3_512_BLOCK_SIZE];
845+
} ipad, opad;
846+
838847
int ring;
839848
bool needs_inv;
840849
bool exit_inv;

‎drivers/crypto/inside-secure/safexcel_cipher.c‎

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@ struct safexcel_cipher_ctx {
6161
/* All the below is AEAD specific */
6262
u32 hash_alg;
6363
u32 state_sz;
64-
__be32 ipad[SHA512_DIGEST_SIZE / sizeof(u32)];
65-
__be32 opad[SHA512_DIGEST_SIZE / sizeof(u32)];
6664

6765
struct crypto_cipher *hkaes;
6866
struct crypto_aead *fback;
@@ -500,17 +498,17 @@ static int safexcel_aead_setkey(struct crypto_aead *ctfm, const u8 *key,
500498
}
501499

502500
if (priv->flags & EIP197_TRC_CACHE && ctx->base.ctxr_dma &&
503-
(memcmp(ctx->ipad, istate.state, ctx->state_sz) ||
504-
memcmp(ctx->opad, ostate.state, ctx->state_sz)))
501+
(memcmp(&ctx->base.ipad, istate.state, ctx->state_sz) ||
502+
memcmp(&ctx->base.opad, ostate.state, ctx->state_sz)))
505503
ctx->base.needs_inv = true;
506504

507505
/* Now copy the keys into the context */
508506
for (i = 0; i < keys.enckeylen / sizeof(u32); i++)
509507
ctx->key[i] = cpu_to_le32(((u32 *)keys.enckey)[i]);
510508
ctx->key_len = keys.enckeylen;
511509

512-
memcpy(ctx->ipad, &istate.state, ctx->state_sz);
513-
memcpy(ctx->opad, &ostate.state, ctx->state_sz);
510+
memcpy(&ctx->base.ipad, &istate.state, ctx->state_sz);
511+
memcpy(&ctx->base.opad, &ostate.state, ctx->state_sz);
514512

515513
memzero_explicit(&keys, sizeof(keys));
516514
return 0;
@@ -718,10 +716,10 @@ static int safexcel_send_req(struct crypto_async_request *base, int ring,
718716
totlen_dst += digestsize;
719717

720718
memcpy(ctx->base.ctxr->data + ctx->key_len / sizeof(u32),
721-
ctx->ipad, ctx->state_sz);
719+
&ctx->base.ipad, ctx->state_sz);
722720
if (!ctx->xcm)
723721
memcpy(ctx->base.ctxr->data + (ctx->key_len +
724-
ctx->state_sz) / sizeof(u32), ctx->opad,
722+
ctx->state_sz) / sizeof(u32), &ctx->base.opad,
725723
ctx->state_sz);
726724
} else if ((ctx->mode == CONTEXT_CONTROL_CRYPTO_MODE_CBC) &&
727725
(sreq->direction == SAFEXCEL_DECRYPT)) {
@@ -2618,15 +2616,15 @@ static int safexcel_aead_gcm_setkey(struct crypto_aead *ctfm, const u8 *key,
26182616

26192617
if (priv->flags & EIP197_TRC_CACHE && ctx->base.ctxr_dma) {
26202618
for (i = 0; i < AES_BLOCK_SIZE / sizeof(u32); i++) {
2621-
if (be32_to_cpu(ctx->ipad[i]) != hashkey[i]) {
2619+
if (be32_to_cpu(ctx->base.ipad.be[i]) != hashkey[i]) {
26222620
ctx->base.needs_inv = true;
26232621
break;
26242622
}
26252623
}
26262624
}
26272625

26282626
for (i = 0; i < AES_BLOCK_SIZE / sizeof(u32); i++)
2629-
ctx->ipad[i] = cpu_to_be32(hashkey[i]);
2627+
ctx->base.ipad.be[i] = cpu_to_be32(hashkey[i]);
26302628

26312629
memzero_explicit(hashkey, AES_BLOCK_SIZE);
26322630
memzero_explicit(&aes, sizeof(aes));
@@ -2714,7 +2712,7 @@ static int safexcel_aead_ccm_setkey(struct crypto_aead *ctfm, const u8 *key,
27142712

27152713
for (i = 0; i < len / sizeof(u32); i++) {
27162714
ctx->key[i] = cpu_to_le32(aes.key_enc[i]);
2717-
ctx->ipad[i + 2 * AES_BLOCK_SIZE / sizeof(u32)] =
2715+
ctx->base.ipad.be[i + 2 * AES_BLOCK_SIZE / sizeof(u32)] =
27182716
cpu_to_be32(aes.key_enc[i]);
27192717
}
27202718

0 commit comments

Comments
 (0)