diff options
author | Stephan Mueller <smueller@chronox.de> | 2018-07-10 11:56:33 -0400 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2018-07-20 01:51:21 -0400 |
commit | cf862cbc831982a27f14a08adf82ad9ca8d86205 (patch) | |
tree | 84b26e66645be295e8e91bace8bcd793daf4c51b | |
parent | 3fd8093b41e745448ffeb0a0d3becc2cd1f9d7ad (diff) |
crypto: drbg - eliminate constant reinitialization of SGL
The CTR DRBG requires two SGLs pointing to input/output buffers for the
CTR AES operation. The used SGLs always have only one entry. Thus, the
SGL can be initialized during allocation time, preventing a
re-initialization of the SGLs during each call.
The performance is increased by about 1 to 3 percent depending on the
size of the requested buffer size.
Signed-off-by: Stephan Mueller <smueller@chronox.de>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
-rw-r--r-- | crypto/drbg.c | 11 | ||||
-rw-r--r-- | include/crypto/drbg.h | 1 |
2 files changed, 8 insertions, 4 deletions
diff --git a/crypto/drbg.c b/crypto/drbg.c index 466a112a4446..ee302fd229ad 100644 --- a/crypto/drbg.c +++ b/crypto/drbg.c | |||
@@ -1715,6 +1715,9 @@ static int drbg_init_sym_kernel(struct drbg_state *drbg) | |||
1715 | drbg->outscratchpad = (u8 *)PTR_ALIGN(drbg->outscratchpadbuf, | 1715 | drbg->outscratchpad = (u8 *)PTR_ALIGN(drbg->outscratchpadbuf, |
1716 | alignmask + 1); | 1716 | alignmask + 1); |
1717 | 1717 | ||
1718 | sg_init_table(&drbg->sg_in, 1); | ||
1719 | sg_init_table(&drbg->sg_out, 1); | ||
1720 | |||
1718 | return alignmask; | 1721 | return alignmask; |
1719 | } | 1722 | } |
1720 | 1723 | ||
@@ -1743,17 +1746,17 @@ static int drbg_kcapi_sym_ctr(struct drbg_state *drbg, | |||
1743 | u8 *inbuf, u32 inlen, | 1746 | u8 *inbuf, u32 inlen, |
1744 | u8 *outbuf, u32 outlen) | 1747 | u8 *outbuf, u32 outlen) |
1745 | { | 1748 | { |
1746 | struct scatterlist sg_in, sg_out; | 1749 | struct scatterlist *sg_in = &drbg->sg_in, *sg_out = &drbg->sg_out; |
1747 | int ret; | 1750 | int ret; |
1748 | 1751 | ||
1749 | sg_init_one(&sg_in, inbuf, inlen); | 1752 | sg_set_buf(sg_in, inbuf, inlen); |
1750 | sg_init_one(&sg_out, drbg->outscratchpad, DRBG_OUTSCRATCHLEN); | 1753 | sg_set_buf(sg_out, drbg->outscratchpad, DRBG_OUTSCRATCHLEN); |
1751 | 1754 | ||
1752 | while (outlen) { | 1755 | while (outlen) { |
1753 | u32 cryptlen = min3(inlen, outlen, (u32)DRBG_OUTSCRATCHLEN); | 1756 | u32 cryptlen = min3(inlen, outlen, (u32)DRBG_OUTSCRATCHLEN); |
1754 | 1757 | ||
1755 | /* Output buffer may not be valid for SGL, use scratchpad */ | 1758 | /* Output buffer may not be valid for SGL, use scratchpad */ |
1756 | skcipher_request_set_crypt(drbg->ctr_req, &sg_in, &sg_out, | 1759 | skcipher_request_set_crypt(drbg->ctr_req, sg_in, sg_out, |
1757 | cryptlen, drbg->V); | 1760 | cryptlen, drbg->V); |
1758 | ret = crypto_wait_req(crypto_skcipher_encrypt(drbg->ctr_req), | 1761 | ret = crypto_wait_req(crypto_skcipher_encrypt(drbg->ctr_req), |
1759 | &drbg->ctr_wait); | 1762 | &drbg->ctr_wait); |
diff --git a/include/crypto/drbg.h b/include/crypto/drbg.h index 8f941102af36..54b9f5d375f5 100644 --- a/include/crypto/drbg.h +++ b/include/crypto/drbg.h | |||
@@ -127,6 +127,7 @@ struct drbg_state { | |||
127 | __u8 *outscratchpadbuf; /* CTR mode output scratchpad */ | 127 | __u8 *outscratchpadbuf; /* CTR mode output scratchpad */ |
128 | __u8 *outscratchpad; /* CTR mode aligned outbuf */ | 128 | __u8 *outscratchpad; /* CTR mode aligned outbuf */ |
129 | struct crypto_wait ctr_wait; /* CTR mode async wait obj */ | 129 | struct crypto_wait ctr_wait; /* CTR mode async wait obj */ |
130 | struct scatterlist sg_in, sg_out; /* CTR mode SGLs */ | ||
130 | 131 | ||
131 | bool seeded; /* DRBG fully seeded? */ | 132 | bool seeded; /* DRBG fully seeded? */ |
132 | bool pr; /* Prediction resistance enabled? */ | 133 | bool pr; /* Prediction resistance enabled? */ |