crypto: DRBG - initialize SGL only once
authorStephan Mueller <smueller@chronox.de>
Wed, 22 Mar 2017 14:26:36 +0000 (15:26 +0100)
committerHerbert Xu <herbert@gondor.apana.org.au>
Fri, 24 Mar 2017 14:03:01 +0000 (22:03 +0800)
An SGL to be initialized only once even when its buffers are written
to several times.

Signed-off-by: Stephan Mueller <smueller@chronox.de>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
crypto/drbg.c

index 8a4d98b4adba46bafb30928cc6b28426427802ce..fa749f47013508d562366fb0484e7ea80535ba0a 100644 (file)
@@ -1749,17 +1749,16 @@ static int drbg_kcapi_sym_ctr(struct drbg_state *drbg,
                              u8 *inbuf, u32 inlen,
                              u8 *outbuf, u32 outlen)
 {
-       struct scatterlist sg_in;
+       struct scatterlist sg_in, sg_out;
        int ret;
 
        sg_init_one(&sg_in, inbuf, inlen);
+       sg_init_one(&sg_out, drbg->outscratchpad, DRBG_OUTSCRATCHLEN);
 
        while (outlen) {
                u32 cryptlen = min3(inlen, outlen, (u32)DRBG_OUTSCRATCHLEN);
-               struct scatterlist sg_out;
 
                /* Output buffer may not be valid for SGL, use scratchpad */
-               sg_init_one(&sg_out, drbg->outscratchpad, cryptlen);
                skcipher_request_set_crypt(drbg->ctr_req, &sg_in, &sg_out,
                                           cryptlen, drbg->V);
                ret = crypto_skcipher_encrypt(drbg->ctr_req);