Skip to content

Commit 7eddf95

Browse files
committed
crypto: shash - Export async functions
This patch exports the async functions so that they can be reused by cryptd when it switches over to using shash. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent 6941c3a commit 7eddf95

2 files changed

Lines changed: 25 additions & 20 deletions

File tree

‎crypto/shash.c‎

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,8 @@ static int shash_async_init(struct ahash_request *req)
202202
return crypto_shash_init(desc);
203203
}
204204

205-
static int shash_async_update(struct ahash_request *req)
205+
int shash_ahash_update(struct ahash_request *req, struct shash_desc *desc)
206206
{
207-
struct shash_desc *desc = ahash_request_ctx(req);
208207
struct crypto_hash_walk walk;
209208
int nbytes;
210209

@@ -214,48 +213,51 @@ static int shash_async_update(struct ahash_request *req)
214213

215214
return nbytes;
216215
}
216+
EXPORT_SYMBOL_GPL(shash_ahash_update);
217+
218+
static int shash_async_update(struct ahash_request *req)
219+
{
220+
return shash_ahash_update(req, ahash_request_ctx(req));
221+
}
217222

218223
static int shash_async_final(struct ahash_request *req)
219224
{
220225
return crypto_shash_final(ahash_request_ctx(req), req->result);
221226
}
222227

223-
static int shash_async_digest(struct ahash_request *req)
228+
int shash_ahash_digest(struct ahash_request *req, struct shash_desc *desc)
224229
{
225230
struct scatterlist *sg = req->src;
226231
unsigned int offset = sg->offset;
227232
unsigned int nbytes = req->nbytes;
228233
int err;
229234

230235
if (nbytes < min(sg->length, ((unsigned int)(PAGE_SIZE)) - offset)) {
231-
struct crypto_shash **ctx =
232-
crypto_ahash_ctx(crypto_ahash_reqtfm(req));
233-
struct shash_desc *desc = ahash_request_ctx(req);
234236
void *data;
235237

236-
desc->tfm = *ctx;
237-
desc->flags = req->base.flags;
238-
239238
data = crypto_kmap(sg_page(sg), 0);
240239
err = crypto_shash_digest(desc, data + offset, nbytes,
241240
req->result);
242241
crypto_kunmap(data, 0);
243242
crypto_yield(desc->flags);
244-
goto out;
245-
}
243+
} else
244+
err = crypto_shash_init(desc) ?:
245+
shash_ahash_update(req, desc) ?:
246+
crypto_shash_final(desc, req->result);
246247

247-
err = shash_async_init(req);
248-
if (err)
249-
goto out;
248+
return err;
249+
}
250+
EXPORT_SYMBOL_GPL(shash_ahash_digest);
250251

251-
err = shash_async_update(req);
252-
if (err)
253-
goto out;
252+
static int shash_async_digest(struct ahash_request *req)
253+
{
254+
struct crypto_shash **ctx = crypto_ahash_ctx(crypto_ahash_reqtfm(req));
255+
struct shash_desc *desc = ahash_request_ctx(req);
254256

255-
err = shash_async_final(req);
257+
desc->tfm = *ctx;
258+
desc->flags = req->base.flags;
256259

257-
out:
258-
return err;
260+
return shash_ahash_digest(req, desc);
259261
}
260262

261263
static void crypto_exit_shash_ops_async(struct crypto_tfm *tfm)

‎include/crypto/internal/hash.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ int crypto_init_shash_spawn(struct crypto_shash_spawn *spawn,
6363

6464
struct shash_alg *shash_attr_alg(struct rtattr *rta, u32 type, u32 mask);
6565

66+
int shash_ahash_update(struct ahash_request *req, struct shash_desc *desc);
67+
int shash_ahash_digest(struct ahash_request *req, struct shash_desc *desc);
68+
6669
static inline void *crypto_ahash_ctx(struct crypto_ahash *tfm)
6770
{
6871
return crypto_tfm_ctx(&tfm->base);

0 commit comments

Comments
 (0)