Skip to content

Commit 25baaf8

Browse files
chunkeeyherbertx
authored andcommitted
crypto: crypto4xx - fix ctr-aes missing output IV
Commit 8efd972 ("crypto: testmgr - support checking skcipher output IV") caused the crypto4xx driver to produce the following error: | ctr-aes-ppc4xx encryption test failed (wrong output IV) | on test vector 0, cfg="in-place" This patch fixes this by reworking the crypto4xx_setkey_aes() function to: - not save the iv for ECB (as per 18.2.38 CRYP0_SA_CMD_0: "This bit mut be cleared for DES ECB mode or AES ECB mode, when no IV is used.") - instruct the hardware to save the generated IV for all other modes of operations that have IV and then supply it back to the callee in pretty much the same way as we do it for cbc-aes already. - make it clear that the DIR_(IN|OUT)BOUND is the important bit that tells the hardware to encrypt or decrypt the data. (this is cosmetic - but it hopefully prevents me from getting confused again). - don't load any bogus hash when we don't use any hash operation to begin with. Cc: [email protected] Fixes: f2a13e7 ("crypto: crypto4xx - enable AES RFC3686, ECB, CFB and OFB offloads") Signed-off-by: Christian Lamparter <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent 1036633 commit 25baaf8

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

drivers/crypto/amcc/crypto4xx_alg.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,10 @@ static int crypto4xx_setkey_aes(struct crypto_skcipher *cipher,
141141
/* Setup SA */
142142
sa = ctx->sa_in;
143143

144-
set_dynamic_sa_command_0(sa, SA_NOT_SAVE_HASH, (cm == CRYPTO_MODE_CBC ?
145-
SA_SAVE_IV : SA_NOT_SAVE_IV),
146-
SA_LOAD_HASH_FROM_SA, SA_LOAD_IV_FROM_STATE,
144+
set_dynamic_sa_command_0(sa, SA_NOT_SAVE_HASH, (cm == CRYPTO_MODE_ECB ?
145+
SA_NOT_SAVE_IV : SA_SAVE_IV),
146+
SA_NOT_LOAD_HASH, (cm == CRYPTO_MODE_ECB ?
147+
SA_LOAD_IV_FROM_SA : SA_LOAD_IV_FROM_STATE),
147148
SA_NO_HEADER_PROC, SA_HASH_ALG_NULL,
148149
SA_CIPHER_ALG_AES, SA_PAD_TYPE_ZERO,
149150
SA_OP_GROUP_BASIC, SA_OPCODE_DECRYPT,
@@ -162,6 +163,11 @@ static int crypto4xx_setkey_aes(struct crypto_skcipher *cipher,
162163
memcpy(ctx->sa_out, ctx->sa_in, ctx->sa_len * 4);
163164
sa = ctx->sa_out;
164165
sa->sa_command_0.bf.dir = DIR_OUTBOUND;
166+
/*
167+
* SA_OPCODE_ENCRYPT is the same value as SA_OPCODE_DECRYPT.
168+
* it's the DIR_(IN|OUT)BOUND that matters
169+
*/
170+
sa->sa_command_0.bf.opcode = SA_OPCODE_ENCRYPT;
165171

166172
return 0;
167173
}

0 commit comments

Comments
 (0)