Commit c4daf4cc authored by Ofer Heifetz's avatar Ofer Heifetz Committed by Herbert Xu

crypto: inside-secure - refrain from unneeded invalidations

The check to know if an invalidation is needed (i.e. when the context
changes) is done even if the context does not exist yet. This happens
when first setting a key for ciphers and/or hmac operations.

This commits adds a check in the _setkey functions to only check if an
invalidation is needed when a context exists, as there is no need to
perform this check otherwise.
Signed-off-by: default avatarOfer Heifetz <oferh@marvell.com>
[Antoine: commit message and added a comment and reworked one of the
checks]
Signed-off-by: default avatarAntoine Tenart <antoine.tenart@free-electrons.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent cc75f5ce
...@@ -78,12 +78,14 @@ static int safexcel_aes_setkey(struct crypto_skcipher *ctfm, const u8 *key, ...@@ -78,12 +78,14 @@ static int safexcel_aes_setkey(struct crypto_skcipher *ctfm, const u8 *key,
return ret; return ret;
} }
if (ctx->base.ctxr_dma) {
for (i = 0; i < len / sizeof(u32); i++) { for (i = 0; i < len / sizeof(u32); i++) {
if (ctx->key[i] != cpu_to_le32(aes.key_enc[i])) { if (ctx->key[i] != cpu_to_le32(aes.key_enc[i])) {
ctx->base.needs_inv = true; ctx->base.needs_inv = true;
break; break;
} }
} }
}
for (i = 0; i < len / sizeof(u32); i++) for (i = 0; i < len / sizeof(u32); i++)
ctx->key[i] = cpu_to_le32(aes.key_enc[i]); ctx->key[i] = cpu_to_le32(aes.key_enc[i]);
......
...@@ -527,10 +527,16 @@ static int safexcel_ahash_enqueue(struct ahash_request *areq) ...@@ -527,10 +527,16 @@ static int safexcel_ahash_enqueue(struct ahash_request *areq)
req->needs_inv = false; req->needs_inv = false;
if (req->processed && ctx->digest == CONTEXT_CONTROL_DIGEST_PRECOMPUTED) if (ctx->base.ctxr) {
if (!ctx->base.needs_inv && req->processed &&
ctx->digest == CONTEXT_CONTROL_DIGEST_PRECOMPUTED)
/* We're still setting needs_inv here, even though it is
* cleared right away, because the needs_inv flag can be
* set in other functions and we want to keep the same
* logic.
*/
ctx->base.needs_inv = safexcel_ahash_needs_inv_get(areq); ctx->base.needs_inv = safexcel_ahash_needs_inv_get(areq);
if (ctx->base.ctxr) {
if (ctx->base.needs_inv) { if (ctx->base.needs_inv) {
ctx->base.needs_inv = false; ctx->base.needs_inv = false;
req->needs_inv = true; req->needs_inv = true;
...@@ -928,6 +934,7 @@ static int safexcel_hmac_sha1_setkey(struct crypto_ahash *tfm, const u8 *key, ...@@ -928,6 +934,7 @@ static int safexcel_hmac_sha1_setkey(struct crypto_ahash *tfm, const u8 *key,
if (ret) if (ret)
return ret; return ret;
if (ctx->base.ctxr) {
for (i = 0; i < SHA1_DIGEST_SIZE / sizeof(u32); i++) { for (i = 0; i < SHA1_DIGEST_SIZE / sizeof(u32); i++) {
if (ctx->ipad[i] != le32_to_cpu(istate.state[i]) || if (ctx->ipad[i] != le32_to_cpu(istate.state[i]) ||
ctx->opad[i] != le32_to_cpu(ostate.state[i])) { ctx->opad[i] != le32_to_cpu(ostate.state[i])) {
...@@ -935,6 +942,7 @@ static int safexcel_hmac_sha1_setkey(struct crypto_ahash *tfm, const u8 *key, ...@@ -935,6 +942,7 @@ static int safexcel_hmac_sha1_setkey(struct crypto_ahash *tfm, const u8 *key,
break; break;
} }
} }
}
memcpy(ctx->ipad, &istate.state, SHA1_DIGEST_SIZE); memcpy(ctx->ipad, &istate.state, SHA1_DIGEST_SIZE);
memcpy(ctx->opad, &ostate.state, SHA1_DIGEST_SIZE); memcpy(ctx->opad, &ostate.state, SHA1_DIGEST_SIZE);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment