aboutsummaryrefslogtreecommitdiffstats
path: root/crypto
diff options
context:
space:
mode:
authorStephan Mueller <smueller@chronox.de>2014-11-30 04:55:26 -0500
committerHerbert Xu <herbert@gondor.apana.org.au>2014-12-02 09:55:46 -0500
commitf26b7b8052daee7ba8bc3f732aa2c20e8c69aea6 (patch)
tree361d232716f9b532789ec7480c35bba37afb33e9 /crypto
parent9ba0905f1740f4dbd26c51883511079944e9c97d (diff)
crypto: algif_skcipher - initialize upon init request
When using the algif_skcipher, the following call sequence causess a re-initialization: 1. sendmsg with ALG_SET_OP and iov == NULL, iovlen == 0 (i.e initializing the cipher, but not sending data) 2. sendmsg with msg->msg-controllen == 0 and iov != NULL (using the initalized cipher handle by sending data) In step 2, the cipher operation type (encryption or decryption) is reset to always decryption, because the local variable of enc is put into ctx->enc as ctx->user is still zero. The same applies when all send data is processed and ctx->used falls to zero followed by user space to send new data. This patch changes the behavior to only reset the cipher operation type (and the IV) if such configuration request is received. Signed-off-by: Stephan Mueller <smueller@chronox.de> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto')
-rw-r--r--crypto/algif_skcipher.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/crypto/algif_skcipher.c b/crypto/algif_skcipher.c
index f2a88a7a71d3..3e84f4a729f0 100644
--- a/crypto/algif_skcipher.c
+++ b/crypto/algif_skcipher.c
@@ -251,6 +251,7 @@ static int skcipher_sendmsg(struct kiocb *unused, struct socket *sock,
251 struct af_alg_control con = {}; 251 struct af_alg_control con = {};
252 long copied = 0; 252 long copied = 0;
253 bool enc = 0; 253 bool enc = 0;
254 bool init = 0;
254 int err; 255 int err;
255 int i; 256 int i;
256 257
@@ -259,6 +260,7 @@ static int skcipher_sendmsg(struct kiocb *unused, struct socket *sock,
259 if (err) 260 if (err)
260 return err; 261 return err;
261 262
263 init = 1;
262 switch (con.op) { 264 switch (con.op) {
263 case ALG_OP_ENCRYPT: 265 case ALG_OP_ENCRYPT:
264 enc = 1; 266 enc = 1;
@@ -280,7 +282,7 @@ static int skcipher_sendmsg(struct kiocb *unused, struct socket *sock,
280 if (!ctx->more && ctx->used) 282 if (!ctx->more && ctx->used)
281 goto unlock; 283 goto unlock;
282 284
283 if (!ctx->used) { 285 if (init) {
284 ctx->enc = enc; 286 ctx->enc = enc;
285 if (con.iv) 287 if (con.iv)
286 memcpy(ctx->iv, con.iv->iv, ivsize); 288 memcpy(ctx->iv, con.iv->iv, ivsize);