diff options
author | Andrzej Zaborowski <andrew.zaborowski@intel.com> | 2015-11-13 06:01:33 -0500 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2015-11-17 09:00:39 -0500 |
commit | 457e6f73a12bb713cc3eec2c979d707cb5716a07 (patch) | |
tree | 7a015db4e9723caadf89b4ac86179f57e1fff210 | |
parent | 9cbe21d8f89dfa851e593ca12725e910ec60c10c (diff) |
crypto: rsa - only require output buffers as big as needed.
rhe RSA operations explicitly left-align the integers being written
skipping any leading zero bytes, but still require the output buffers to
include just enough space for the integer + the leading zero bytes.
Since the size of integer + the leading zero bytes (i.e. the key modulus
size) can now be obtained more easily through crypto_akcipher_maxsize
change the operations to only require as big a buffer as actually needed
if the caller has that information. The semantics for request->dst_len
don't change.
Signed-off-by: Andrew Zaborowski <andrew.zaborowski@intel.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
-rw-r--r-- | crypto/rsa.c | 24 |
1 files changed, 0 insertions, 24 deletions
diff --git a/crypto/rsa.c b/crypto/rsa.c index 1093e041db03..58aad69a490c 100644 --- a/crypto/rsa.c +++ b/crypto/rsa.c | |||
@@ -91,12 +91,6 @@ static int rsa_enc(struct akcipher_request *req) | |||
91 | goto err_free_c; | 91 | goto err_free_c; |
92 | } | 92 | } |
93 | 93 | ||
94 | if (req->dst_len < mpi_get_size(pkey->n)) { | ||
95 | req->dst_len = mpi_get_size(pkey->n); | ||
96 | ret = -EOVERFLOW; | ||
97 | goto err_free_c; | ||
98 | } | ||
99 | |||
100 | ret = -ENOMEM; | 94 | ret = -ENOMEM; |
101 | m = mpi_read_raw_from_sgl(req->src, req->src_len); | 95 | m = mpi_read_raw_from_sgl(req->src, req->src_len); |
102 | if (!m) | 96 | if (!m) |
@@ -136,12 +130,6 @@ static int rsa_dec(struct akcipher_request *req) | |||
136 | goto err_free_m; | 130 | goto err_free_m; |
137 | } | 131 | } |
138 | 132 | ||
139 | if (req->dst_len < mpi_get_size(pkey->n)) { | ||
140 | req->dst_len = mpi_get_size(pkey->n); | ||
141 | ret = -EOVERFLOW; | ||
142 | goto err_free_m; | ||
143 | } | ||
144 | |||
145 | ret = -ENOMEM; | 133 | ret = -ENOMEM; |
146 | c = mpi_read_raw_from_sgl(req->src, req->src_len); | 134 | c = mpi_read_raw_from_sgl(req->src, req->src_len); |
147 | if (!c) | 135 | if (!c) |
@@ -180,12 +168,6 @@ static int rsa_sign(struct akcipher_request *req) | |||
180 | goto err_free_s; | 168 | goto err_free_s; |
181 | } | 169 | } |
182 | 170 | ||
183 | if (req->dst_len < mpi_get_size(pkey->n)) { | ||
184 | req->dst_len = mpi_get_size(pkey->n); | ||
185 | ret = -EOVERFLOW; | ||
186 | goto err_free_s; | ||
187 | } | ||
188 | |||
189 | ret = -ENOMEM; | 171 | ret = -ENOMEM; |
190 | m = mpi_read_raw_from_sgl(req->src, req->src_len); | 172 | m = mpi_read_raw_from_sgl(req->src, req->src_len); |
191 | if (!m) | 173 | if (!m) |
@@ -225,12 +207,6 @@ static int rsa_verify(struct akcipher_request *req) | |||
225 | goto err_free_m; | 207 | goto err_free_m; |
226 | } | 208 | } |
227 | 209 | ||
228 | if (req->dst_len < mpi_get_size(pkey->n)) { | ||
229 | req->dst_len = mpi_get_size(pkey->n); | ||
230 | ret = -EOVERFLOW; | ||
231 | goto err_free_m; | ||
232 | } | ||
233 | |||
234 | ret = -ENOMEM; | 210 | ret = -ENOMEM; |
235 | s = mpi_read_raw_from_sgl(req->src, req->src_len); | 211 | s = mpi_read_raw_from_sgl(req->src, req->src_len); |
236 | if (!s) { | 212 | if (!s) { |