crypto: inside-secure - rework the alg type settings in the context
authorAntoine Tenart <antoine.tenart@bootlin.com>
Mon, 14 May 2018 13:10:57 +0000 (15:10 +0200)
committerHerbert Xu <herbert@gondor.apana.org.au>
Sat, 26 May 2018 16:11:36 +0000 (00:11 +0800)
This patches reworks the way the algorithm type is set in the context,
by using the fact that the decryption algorithms are just a combination
of the algorithm encryption type and CONTEXT_CONTROL_TYPE_NULL_IN.

This will help having simpler code when adding the AEAD support, to
avoid ending up with an endless switch case block.

Signed-off-by: Antoine Tenart <antoine.tenart@bootlin.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
drivers/crypto/inside-secure/safexcel_cipher.c

index 51f88f93ed998fb48a889a1999375402fc7b4f7d..9ed3f2641ef3ce037522ea95d07d79e1e036b6af 100644 (file)
@@ -104,10 +104,13 @@ static int safexcel_context_control(struct safexcel_cipher_ctx *ctx,
        struct safexcel_crypto_priv *priv = ctx->priv;
        int ctrl_size;
 
-       if (sreq->direction == SAFEXCEL_ENCRYPT)
-               cdesc->control_data.control0 |= CONTEXT_CONTROL_TYPE_CRYPTO_OUT;
-       else
-               cdesc->control_data.control0 |= CONTEXT_CONTROL_TYPE_CRYPTO_IN;
+       cdesc->control_data.control0 |= CONTEXT_CONTROL_TYPE_CRYPTO_OUT;
+
+       /* The decryption control type is a combination of the encryption type
+        * and CONTEXT_CONTROL_TYPE_NULL_IN, for all types.
+        */
+       if (sreq->direction == SAFEXCEL_DECRYPT)
+               cdesc->control_data.control0 |= CONTEXT_CONTROL_TYPE_NULL_IN;
 
        cdesc->control_data.control0 |= CONTEXT_CONTROL_KEY_EN;
        cdesc->control_data.control1 |= ctx->mode;