Skip to content

Commit

Permalink
crypto: DRBG - initialize SGL only once
Browse files Browse the repository at this point in the history
An SGL to be initialized only once even when its buffers are written
to several times.

Signed-off-by: Stephan Mueller <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
  • Loading branch information
smuellerDD authored and herbertx committed Mar 24, 2017
1 parent 0d8da10 commit 44068d5
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions crypto/drbg.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 44068d5

Please sign in to comment.