aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarek Vasut <marex@denx.de>2014-03-13 21:37:05 -0400
committerHerbert Xu <herbert@gondor.apana.org.au>2014-03-21 09:54:21 -0400
commit1ffc9fbd1e5071948b6d48f9a27d845738ee890f (patch)
treed125f7d9bde442e04cf1bd6433f7d4136660b4f6
parentab6bf4e5e5e4298e8649e635bee25542cccbfd97 (diff)
crypto: hash - Pull out the functions to save/restore request
The functions to save original request within a newly adjusted request and it's counterpart to restore the original request can be re-used by more code in the crypto/ahash.c file. Pull these functions out from the code so they're available. Signed-off-by: Marek Vasut <marex@denx.de> Cc: David S. Miller <davem@davemloft.net> Cc: Fabio Estevam <fabio.estevam@freescale.com> Cc: Herbert Xu <herbert@gondor.apana.org.au> Cc: Shawn Guo <shawn.guo@linaro.org> Cc: Tom Lendacky <thomas.lendacky@amd.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
-rw-r--r--crypto/ahash.c107
1 files changed, 62 insertions, 45 deletions
diff --git a/crypto/ahash.c b/crypto/ahash.c
index 4fdb4d3fddec..fcc6077b9af0 100644
--- a/crypto/ahash.c
+++ b/crypto/ahash.c
@@ -190,55 +190,12 @@ static inline unsigned int ahash_align_buffer_size(unsigned len,
190 return len + (mask & ~(crypto_tfm_ctx_alignment() - 1)); 190 return len + (mask & ~(crypto_tfm_ctx_alignment() - 1));
191} 191}
192 192
193static void ahash_op_unaligned_finish(struct ahash_request *req, int err) 193static int ahash_save_req(struct ahash_request *req, crypto_completion_t cplt)
194{
195 struct ahash_request_priv *priv = req->priv;
196
197 if (err == -EINPROGRESS)
198 return;
199
200 if (!err)
201 memcpy(priv->result, req->result,
202 crypto_ahash_digestsize(crypto_ahash_reqtfm(req)));
203
204 /* Restore the original crypto request. */
205 req->result = priv->result;
206 req->base.complete = priv->complete;
207 req->base.data = priv->data;
208 req->priv = NULL;
209
210 /* Free the req->priv.priv from the ADJUSTED request. */
211 kzfree(priv);
212}
213
214static void ahash_op_unaligned_done(struct crypto_async_request *req, int err)
215{
216 struct ahash_request *areq = req->data;
217
218 /*
219 * Restore the original request, see ahash_op_unaligned() for what
220 * goes where.
221 *
222 * The "struct ahash_request *req" here is in fact the "req.base"
223 * from the ADJUSTED request from ahash_op_unaligned(), thus as it
224 * is a pointer to self, it is also the ADJUSTED "req" .
225 */
226
227 /* First copy areq->result into areq->priv.result */
228 ahash_op_unaligned_finish(areq, err);
229
230 /* Complete the ORIGINAL request. */
231 areq->base.complete(&areq->base, err);
232}
233
234static int ahash_op_unaligned(struct ahash_request *req,
235 int (*op)(struct ahash_request *))
236{ 194{
237 struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); 195 struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
238 unsigned long alignmask = crypto_ahash_alignmask(tfm); 196 unsigned long alignmask = crypto_ahash_alignmask(tfm);
239 unsigned int ds = crypto_ahash_digestsize(tfm); 197 unsigned int ds = crypto_ahash_digestsize(tfm);
240 struct ahash_request_priv *priv; 198 struct ahash_request_priv *priv;
241 int err;
242 199
243 priv = kmalloc(sizeof(*priv) + ahash_align_buffer_size(ds, alignmask), 200 priv = kmalloc(sizeof(*priv) + ahash_align_buffer_size(ds, alignmask),
244 (req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP) ? 201 (req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP) ?
@@ -281,10 +238,70 @@ static int ahash_op_unaligned(struct ahash_request *req,
281 */ 238 */
282 239
283 req->result = PTR_ALIGN((u8 *)priv->ubuf, alignmask + 1); 240 req->result = PTR_ALIGN((u8 *)priv->ubuf, alignmask + 1);
284 req->base.complete = ahash_op_unaligned_done; 241 req->base.complete = cplt;
285 req->base.data = req; 242 req->base.data = req;
286 req->priv = priv; 243 req->priv = priv;
287 244
245 return 0;
246}
247
248static void ahash_restore_req(struct ahash_request *req)
249{
250 struct ahash_request_priv *priv = req->priv;
251
252 /* Restore the original crypto request. */
253 req->result = priv->result;
254 req->base.complete = priv->complete;
255 req->base.data = priv->data;
256 req->priv = NULL;
257
258 /* Free the req->priv.priv from the ADJUSTED request. */
259 kzfree(priv);
260}
261
262static void ahash_op_unaligned_finish(struct ahash_request *req, int err)
263{
264 struct ahash_request_priv *priv = req->priv;
265
266 if (err == -EINPROGRESS)
267 return;
268
269 if (!err)
270 memcpy(priv->result, req->result,
271 crypto_ahash_digestsize(crypto_ahash_reqtfm(req)));
272
273 ahash_restore_req(req);
274}
275
276static void ahash_op_unaligned_done(struct crypto_async_request *req, int err)
277{
278 struct ahash_request *areq = req->data;
279
280 /*
281 * Restore the original request, see ahash_op_unaligned() for what
282 * goes where.
283 *
284 * The "struct ahash_request *req" here is in fact the "req.base"
285 * from the ADJUSTED request from ahash_op_unaligned(), thus as it
286 * is a pointer to self, it is also the ADJUSTED "req" .
287 */
288
289 /* First copy req->result into req->priv.result */
290 ahash_op_unaligned_finish(areq, err);
291
292 /* Complete the ORIGINAL request. */
293 areq->base.complete(&areq->base, err);
294}
295
296static int ahash_op_unaligned(struct ahash_request *req,
297 int (*op)(struct ahash_request *))
298{
299 int err;
300
301 err = ahash_save_req(req, ahash_op_unaligned_done);
302 if (err)
303 return err;
304
288 err = op(req); 305 err = op(req);
289 ahash_op_unaligned_finish(req, err); 306 ahash_op_unaligned_finish(req, err);
290 307