ahash.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Asynchronous Cryptographic Hash operations.
  4. *
  5. * This is the asynchronous version of hash.c with notification of
  6. * completion via a callback.
  7. *
  8. * Copyright (c) 2008 Loc Ho <lho@amcc.com>
  9. */
  10. #include <crypto/internal/hash.h>
  11. #include <crypto/scatterwalk.h>
  12. #include <linux/bug.h>
  13. #include <linux/err.h>
  14. #include <linux/kernel.h>
  15. #include <linux/module.h>
  16. #include <linux/sched.h>
  17. #include <linux/slab.h>
  18. #include <linux/seq_file.h>
  19. #include <linux/cryptouser.h>
  20. #include <linux/compiler.h>
  21. #include <net/netlink.h>
  22. #include "internal.h"
  23. struct ahash_request_priv {
  24. crypto_completion_t complete;
  25. void *data;
  26. u8 *result;
  27. u32 flags;
  28. void *ubuf[] CRYPTO_MINALIGN_ATTR;
  29. };
  30. static inline struct ahash_alg *crypto_ahash_alg(struct crypto_ahash *hash)
  31. {
  32. return container_of(crypto_hash_alg_common(hash), struct ahash_alg,
  33. halg);
  34. }
  35. static int hash_walk_next(struct crypto_hash_walk *walk)
  36. {
  37. unsigned int alignmask = walk->alignmask;
  38. unsigned int offset = walk->offset;
  39. unsigned int nbytes = min(walk->entrylen,
  40. ((unsigned int)(PAGE_SIZE)) - offset);
  41. if (walk->flags & CRYPTO_ALG_ASYNC)
  42. walk->data = kmap(walk->pg);
  43. else
  44. walk->data = kmap_atomic(walk->pg);
  45. walk->data += offset;
  46. if (offset & alignmask) {
  47. unsigned int unaligned = alignmask + 1 - (offset & alignmask);
  48. if (nbytes > unaligned)
  49. nbytes = unaligned;
  50. }
  51. walk->entrylen -= nbytes;
  52. return nbytes;
  53. }
  54. static int hash_walk_new_entry(struct crypto_hash_walk *walk)
  55. {
  56. struct scatterlist *sg;
  57. sg = walk->sg;
  58. walk->offset = sg->offset;
  59. walk->pg = sg_page(walk->sg) + (walk->offset >> PAGE_SHIFT);
  60. walk->offset = offset_in_page(walk->offset);
  61. walk->entrylen = sg->length;
  62. if (walk->entrylen > walk->total)
  63. walk->entrylen = walk->total;
  64. walk->total -= walk->entrylen;
  65. return hash_walk_next(walk);
  66. }
  67. int crypto_hash_walk_done(struct crypto_hash_walk *walk, int err)
  68. {
  69. unsigned int alignmask = walk->alignmask;
  70. walk->data -= walk->offset;
  71. if (walk->entrylen && (walk->offset & alignmask) && !err) {
  72. unsigned int nbytes;
  73. walk->offset = ALIGN(walk->offset, alignmask + 1);
  74. nbytes = min(walk->entrylen,
  75. (unsigned int)(PAGE_SIZE - walk->offset));
  76. if (nbytes) {
  77. walk->entrylen -= nbytes;
  78. walk->data += walk->offset;
  79. return nbytes;
  80. }
  81. }
  82. if (walk->flags & CRYPTO_ALG_ASYNC)
  83. kunmap(walk->pg);
  84. else {
  85. kunmap_atomic(walk->data);
  86. /*
  87. * The may sleep test only makes sense for sync users.
  88. * Async users don't need to sleep here anyway.
  89. */
  90. crypto_yield(walk->flags);
  91. }
  92. if (err)
  93. return err;
  94. if (walk->entrylen) {
  95. walk->offset = 0;
  96. walk->pg++;
  97. return hash_walk_next(walk);
  98. }
  99. if (!walk->total)
  100. return 0;
  101. walk->sg = sg_next(walk->sg);
  102. return hash_walk_new_entry(walk);
  103. }
  104. EXPORT_SYMBOL_GPL(crypto_hash_walk_done);
  105. int crypto_hash_walk_first(struct ahash_request *req,
  106. struct crypto_hash_walk *walk)
  107. {
  108. walk->total = req->nbytes;
  109. if (!walk->total) {
  110. walk->entrylen = 0;
  111. return 0;
  112. }
  113. walk->alignmask = crypto_ahash_alignmask(crypto_ahash_reqtfm(req));
  114. walk->sg = req->src;
  115. walk->flags = req->base.flags & CRYPTO_TFM_REQ_MASK;
  116. return hash_walk_new_entry(walk);
  117. }
  118. EXPORT_SYMBOL_GPL(crypto_hash_walk_first);
  119. int crypto_ahash_walk_first(struct ahash_request *req,
  120. struct crypto_hash_walk *walk)
  121. {
  122. walk->total = req->nbytes;
  123. if (!walk->total) {
  124. walk->entrylen = 0;
  125. return 0;
  126. }
  127. walk->alignmask = crypto_ahash_alignmask(crypto_ahash_reqtfm(req));
  128. walk->sg = req->src;
  129. walk->flags = req->base.flags & CRYPTO_TFM_REQ_MASK;
  130. walk->flags |= CRYPTO_ALG_ASYNC;
  131. BUILD_BUG_ON(CRYPTO_TFM_REQ_MASK & CRYPTO_ALG_ASYNC);
  132. return hash_walk_new_entry(walk);
  133. }
  134. EXPORT_SYMBOL_GPL(crypto_ahash_walk_first);
  135. static int ahash_setkey_unaligned(struct crypto_ahash *tfm, const u8 *key,
  136. unsigned int keylen)
  137. {
  138. unsigned long alignmask = crypto_ahash_alignmask(tfm);
  139. int ret;
  140. u8 *buffer, *alignbuffer;
  141. unsigned long absize;
  142. absize = keylen + alignmask;
  143. buffer = kmalloc(absize, GFP_KERNEL);
  144. if (!buffer)
  145. return -ENOMEM;
  146. alignbuffer = (u8 *)ALIGN((unsigned long)buffer, alignmask + 1);
  147. memcpy(alignbuffer, key, keylen);
  148. ret = tfm->setkey(tfm, alignbuffer, keylen);
  149. kzfree(buffer);
  150. return ret;
  151. }
  152. static int ahash_nosetkey(struct crypto_ahash *tfm, const u8 *key,
  153. unsigned int keylen)
  154. {
  155. return -ENOSYS;
  156. }
  157. static void ahash_set_needkey(struct crypto_ahash *tfm)
  158. {
  159. const struct hash_alg_common *alg = crypto_hash_alg_common(tfm);
  160. if (tfm->setkey != ahash_nosetkey &&
  161. !(alg->base.cra_flags & CRYPTO_ALG_OPTIONAL_KEY))
  162. crypto_ahash_set_flags(tfm, CRYPTO_TFM_NEED_KEY);
  163. }
  164. int crypto_ahash_setkey(struct crypto_ahash *tfm, const u8 *key,
  165. unsigned int keylen)
  166. {
  167. unsigned long alignmask = crypto_ahash_alignmask(tfm);
  168. int err;
  169. if ((unsigned long)key & alignmask)
  170. err = ahash_setkey_unaligned(tfm, key, keylen);
  171. else
  172. err = tfm->setkey(tfm, key, keylen);
  173. if (unlikely(err)) {
  174. ahash_set_needkey(tfm);
  175. return err;
  176. }
  177. crypto_ahash_clear_flags(tfm, CRYPTO_TFM_NEED_KEY);
  178. return 0;
  179. }
  180. EXPORT_SYMBOL_GPL(crypto_ahash_setkey);
  181. static inline unsigned int ahash_align_buffer_size(unsigned len,
  182. unsigned long mask)
  183. {
  184. return len + (mask & ~(crypto_tfm_ctx_alignment() - 1));
  185. }
  186. static int ahash_save_req(struct ahash_request *req, crypto_completion_t cplt)
  187. {
  188. struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
  189. unsigned long alignmask = crypto_ahash_alignmask(tfm);
  190. unsigned int ds = crypto_ahash_digestsize(tfm);
  191. struct ahash_request_priv *priv;
  192. priv = kmalloc(sizeof(*priv) + ahash_align_buffer_size(ds, alignmask),
  193. (req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP) ?
  194. GFP_KERNEL : GFP_ATOMIC);
  195. if (!priv)
  196. return -ENOMEM;
  197. /*
  198. * WARNING: Voodoo programming below!
  199. *
  200. * The code below is obscure and hard to understand, thus explanation
  201. * is necessary. See include/crypto/hash.h and include/linux/crypto.h
  202. * to understand the layout of structures used here!
  203. *
  204. * The code here will replace portions of the ORIGINAL request with
  205. * pointers to new code and buffers so the hashing operation can store
  206. * the result in aligned buffer. We will call the modified request
  207. * an ADJUSTED request.
  208. *
  209. * The newly mangled request will look as such:
  210. *
  211. * req {
  212. * .result = ADJUSTED[new aligned buffer]
  213. * .base.complete = ADJUSTED[pointer to completion function]
  214. * .base.data = ADJUSTED[*req (pointer to self)]
  215. * .priv = ADJUSTED[new priv] {
  216. * .result = ORIGINAL(result)
  217. * .complete = ORIGINAL(base.complete)
  218. * .data = ORIGINAL(base.data)
  219. * }
  220. */
  221. priv->result = req->result;
  222. priv->complete = req->base.complete;
  223. priv->data = req->base.data;
  224. priv->flags = req->base.flags;
  225. /*
  226. * WARNING: We do not backup req->priv here! The req->priv
  227. * is for internal use of the Crypto API and the
  228. * user must _NOT_ _EVER_ depend on it's content!
  229. */
  230. req->result = PTR_ALIGN((u8 *)priv->ubuf, alignmask + 1);
  231. req->base.complete = cplt;
  232. req->base.data = req;
  233. req->priv = priv;
  234. return 0;
  235. }
  236. static void ahash_restore_req(struct ahash_request *req, int err)
  237. {
  238. struct ahash_request_priv *priv = req->priv;
  239. if (!err)
  240. memcpy(priv->result, req->result,
  241. crypto_ahash_digestsize(crypto_ahash_reqtfm(req)));
  242. /* Restore the original crypto request. */
  243. req->result = priv->result;
  244. ahash_request_set_callback(req, priv->flags,
  245. priv->complete, priv->data);
  246. req->priv = NULL;
  247. /* Free the req->priv.priv from the ADJUSTED request. */
  248. kzfree(priv);
  249. }
  250. static void ahash_notify_einprogress(struct ahash_request *req)
  251. {
  252. struct ahash_request_priv *priv = req->priv;
  253. struct crypto_async_request oreq;
  254. oreq.data = priv->data;
  255. priv->complete(&oreq, -EINPROGRESS);
  256. }
  257. static void ahash_op_unaligned_done(struct crypto_async_request *req, int err)
  258. {
  259. struct ahash_request *areq = req->data;
  260. if (err == -EINPROGRESS) {
  261. ahash_notify_einprogress(areq);
  262. return;
  263. }
  264. /*
  265. * Restore the original request, see ahash_op_unaligned() for what
  266. * goes where.
  267. *
  268. * The "struct ahash_request *req" here is in fact the "req.base"
  269. * from the ADJUSTED request from ahash_op_unaligned(), thus as it
  270. * is a pointer to self, it is also the ADJUSTED "req" .
  271. */
  272. /* First copy req->result into req->priv.result */
  273. ahash_restore_req(areq, err);
  274. /* Complete the ORIGINAL request. */
  275. areq->base.complete(&areq->base, err);
  276. }
  277. static int ahash_op_unaligned(struct ahash_request *req,
  278. int (*op)(struct ahash_request *))
  279. {
  280. int err;
  281. err = ahash_save_req(req, ahash_op_unaligned_done);
  282. if (err)
  283. return err;
  284. err = op(req);
  285. if (err == -EINPROGRESS || err == -EBUSY)
  286. return err;
  287. ahash_restore_req(req, err);
  288. return err;
  289. }
  290. static int crypto_ahash_op(struct ahash_request *req,
  291. int (*op)(struct ahash_request *))
  292. {
  293. struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
  294. unsigned long alignmask = crypto_ahash_alignmask(tfm);
  295. if ((unsigned long)req->result & alignmask)
  296. return ahash_op_unaligned(req, op);
  297. return op(req);
  298. }
  299. int crypto_ahash_final(struct ahash_request *req)
  300. {
  301. struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
  302. struct crypto_alg *alg = tfm->base.__crt_alg;
  303. unsigned int nbytes = req->nbytes;
  304. int ret;
  305. crypto_stats_get(alg);
  306. ret = crypto_ahash_op(req, crypto_ahash_reqtfm(req)->final);
  307. crypto_stats_ahash_final(nbytes, ret, alg);
  308. return ret;
  309. }
  310. EXPORT_SYMBOL_GPL(crypto_ahash_final);
  311. int crypto_ahash_finup(struct ahash_request *req)
  312. {
  313. struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
  314. struct crypto_alg *alg = tfm->base.__crt_alg;
  315. unsigned int nbytes = req->nbytes;
  316. int ret;
  317. crypto_stats_get(alg);
  318. ret = crypto_ahash_op(req, crypto_ahash_reqtfm(req)->finup);
  319. crypto_stats_ahash_final(nbytes, ret, alg);
  320. return ret;
  321. }
  322. EXPORT_SYMBOL_GPL(crypto_ahash_finup);
  323. int crypto_ahash_digest(struct ahash_request *req)
  324. {
  325. struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
  326. struct crypto_alg *alg = tfm->base.__crt_alg;
  327. unsigned int nbytes = req->nbytes;
  328. int ret;
  329. crypto_stats_get(alg);
  330. if (crypto_ahash_get_flags(tfm) & CRYPTO_TFM_NEED_KEY)
  331. ret = -ENOKEY;
  332. else
  333. ret = crypto_ahash_op(req, tfm->digest);
  334. crypto_stats_ahash_final(nbytes, ret, alg);
  335. return ret;
  336. }
  337. EXPORT_SYMBOL_GPL(crypto_ahash_digest);
  338. static void ahash_def_finup_done2(struct crypto_async_request *req, int err)
  339. {
  340. struct ahash_request *areq = req->data;
  341. if (err == -EINPROGRESS)
  342. return;
  343. ahash_restore_req(areq, err);
  344. areq->base.complete(&areq->base, err);
  345. }
  346. static int ahash_def_finup_finish1(struct ahash_request *req, int err)
  347. {
  348. if (err)
  349. goto out;
  350. req->base.complete = ahash_def_finup_done2;
  351. err = crypto_ahash_reqtfm(req)->final(req);
  352. if (err == -EINPROGRESS || err == -EBUSY)
  353. return err;
  354. out:
  355. ahash_restore_req(req, err);
  356. return err;
  357. }
  358. static void ahash_def_finup_done1(struct crypto_async_request *req, int err)
  359. {
  360. struct ahash_request *areq = req->data;
  361. if (err == -EINPROGRESS) {
  362. ahash_notify_einprogress(areq);
  363. return;
  364. }
  365. areq->base.flags &= ~CRYPTO_TFM_REQ_MAY_SLEEP;
  366. err = ahash_def_finup_finish1(areq, err);
  367. if (areq->priv)
  368. return;
  369. areq->base.complete(&areq->base, err);
  370. }
  371. static int ahash_def_finup(struct ahash_request *req)
  372. {
  373. struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
  374. int err;
  375. err = ahash_save_req(req, ahash_def_finup_done1);
  376. if (err)
  377. return err;
  378. err = tfm->update(req);
  379. if (err == -EINPROGRESS || err == -EBUSY)
  380. return err;
  381. return ahash_def_finup_finish1(req, err);
  382. }
  383. static int crypto_ahash_init_tfm(struct crypto_tfm *tfm)
  384. {
  385. struct crypto_ahash *hash = __crypto_ahash_cast(tfm);
  386. struct ahash_alg *alg = crypto_ahash_alg(hash);
  387. hash->setkey = ahash_nosetkey;
  388. if (tfm->__crt_alg->cra_type != &crypto_ahash_type)
  389. return crypto_init_shash_ops_async(tfm);
  390. hash->init = alg->init;
  391. hash->update = alg->update;
  392. hash->final = alg->final;
  393. hash->finup = alg->finup ?: ahash_def_finup;
  394. hash->digest = alg->digest;
  395. hash->export = alg->export;
  396. hash->import = alg->import;
  397. if (alg->setkey) {
  398. hash->setkey = alg->setkey;
  399. ahash_set_needkey(hash);
  400. }
  401. return 0;
  402. }
  403. static unsigned int crypto_ahash_extsize(struct crypto_alg *alg)
  404. {
  405. if (alg->cra_type != &crypto_ahash_type)
  406. return sizeof(struct crypto_shash *);
  407. return crypto_alg_extsize(alg);
  408. }
  409. #ifdef CONFIG_NET
  410. static int crypto_ahash_report(struct sk_buff *skb, struct crypto_alg *alg)
  411. {
  412. struct crypto_report_hash rhash;
  413. memset(&rhash, 0, sizeof(rhash));
  414. strscpy(rhash.type, "ahash", sizeof(rhash.type));
  415. rhash.blocksize = alg->cra_blocksize;
  416. rhash.digestsize = __crypto_hash_alg_common(alg)->digestsize;
  417. return nla_put(skb, CRYPTOCFGA_REPORT_HASH, sizeof(rhash), &rhash);
  418. }
  419. #else
  420. static int crypto_ahash_report(struct sk_buff *skb, struct crypto_alg *alg)
  421. {
  422. return -ENOSYS;
  423. }
  424. #endif
  425. static void crypto_ahash_show(struct seq_file *m, struct crypto_alg *alg)
  426. __maybe_unused;
  427. static void crypto_ahash_show(struct seq_file *m, struct crypto_alg *alg)
  428. {
  429. seq_printf(m, "type : ahash\n");
  430. seq_printf(m, "async : %s\n", alg->cra_flags & CRYPTO_ALG_ASYNC ?
  431. "yes" : "no");
  432. seq_printf(m, "blocksize : %u\n", alg->cra_blocksize);
  433. seq_printf(m, "digestsize : %u\n",
  434. __crypto_hash_alg_common(alg)->digestsize);
  435. }
  436. const struct crypto_type crypto_ahash_type = {
  437. .extsize = crypto_ahash_extsize,
  438. .init_tfm = crypto_ahash_init_tfm,
  439. #ifdef CONFIG_PROC_FS
  440. .show = crypto_ahash_show,
  441. #endif
  442. .report = crypto_ahash_report,
  443. .maskclear = ~CRYPTO_ALG_TYPE_MASK,
  444. .maskset = CRYPTO_ALG_TYPE_AHASH_MASK,
  445. .type = CRYPTO_ALG_TYPE_AHASH,
  446. .tfmsize = offsetof(struct crypto_ahash, base),
  447. };
  448. EXPORT_SYMBOL_GPL(crypto_ahash_type);
  449. struct crypto_ahash *crypto_alloc_ahash(const char *alg_name, u32 type,
  450. u32 mask)
  451. {
  452. return crypto_alloc_tfm(alg_name, &crypto_ahash_type, type, mask);
  453. }
  454. EXPORT_SYMBOL_GPL(crypto_alloc_ahash);
  455. int crypto_has_ahash(const char *alg_name, u32 type, u32 mask)
  456. {
  457. return crypto_type_has_alg(alg_name, &crypto_ahash_type, type, mask);
  458. }
  459. EXPORT_SYMBOL_GPL(crypto_has_ahash);
  460. static int ahash_prepare_alg(struct ahash_alg *alg)
  461. {
  462. struct crypto_alg *base = &alg->halg.base;
  463. if (alg->halg.digestsize > HASH_MAX_DIGESTSIZE ||
  464. alg->halg.statesize > HASH_MAX_STATESIZE ||
  465. alg->halg.statesize == 0)
  466. return -EINVAL;
  467. base->cra_type = &crypto_ahash_type;
  468. base->cra_flags &= ~CRYPTO_ALG_TYPE_MASK;
  469. base->cra_flags |= CRYPTO_ALG_TYPE_AHASH;
  470. return 0;
  471. }
  472. int crypto_register_ahash(struct ahash_alg *alg)
  473. {
  474. struct crypto_alg *base = &alg->halg.base;
  475. int err;
  476. err = ahash_prepare_alg(alg);
  477. if (err)
  478. return err;
  479. return crypto_register_alg(base);
  480. }
  481. EXPORT_SYMBOL_GPL(crypto_register_ahash);
  482. int crypto_unregister_ahash(struct ahash_alg *alg)
  483. {
  484. return crypto_unregister_alg(&alg->halg.base);
  485. }
  486. EXPORT_SYMBOL_GPL(crypto_unregister_ahash);
  487. int crypto_register_ahashes(struct ahash_alg *algs, int count)
  488. {
  489. int i, ret;
  490. for (i = 0; i < count; i++) {
  491. ret = crypto_register_ahash(&algs[i]);
  492. if (ret)
  493. goto err;
  494. }
  495. return 0;
  496. err:
  497. for (--i; i >= 0; --i)
  498. crypto_unregister_ahash(&algs[i]);
  499. return ret;
  500. }
  501. EXPORT_SYMBOL_GPL(crypto_register_ahashes);
  502. void crypto_unregister_ahashes(struct ahash_alg *algs, int count)
  503. {
  504. int i;
  505. for (i = count - 1; i >= 0; --i)
  506. crypto_unregister_ahash(&algs[i]);
  507. }
  508. EXPORT_SYMBOL_GPL(crypto_unregister_ahashes);
  509. int ahash_register_instance(struct crypto_template *tmpl,
  510. struct ahash_instance *inst)
  511. {
  512. int err;
  513. err = ahash_prepare_alg(&inst->alg);
  514. if (err)
  515. return err;
  516. return crypto_register_instance(tmpl, ahash_crypto_instance(inst));
  517. }
  518. EXPORT_SYMBOL_GPL(ahash_register_instance);
  519. void ahash_free_instance(struct crypto_instance *inst)
  520. {
  521. crypto_drop_spawn(crypto_instance_ctx(inst));
  522. kfree(ahash_instance(inst));
  523. }
  524. EXPORT_SYMBOL_GPL(ahash_free_instance);
  525. int crypto_init_ahash_spawn(struct crypto_ahash_spawn *spawn,
  526. struct hash_alg_common *alg,
  527. struct crypto_instance *inst)
  528. {
  529. return crypto_init_spawn2(&spawn->base, &alg->base, inst,
  530. &crypto_ahash_type);
  531. }
  532. EXPORT_SYMBOL_GPL(crypto_init_ahash_spawn);
  533. struct hash_alg_common *ahash_attr_alg(struct rtattr *rta, u32 type, u32 mask)
  534. {
  535. struct crypto_alg *alg;
  536. alg = crypto_attr_alg2(rta, &crypto_ahash_type, type, mask);
  537. return IS_ERR(alg) ? ERR_CAST(alg) : __crypto_hash_alg_common(alg);
  538. }
  539. EXPORT_SYMBOL_GPL(ahash_attr_alg);
  540. bool crypto_hash_alg_has_setkey(struct hash_alg_common *halg)
  541. {
  542. struct crypto_alg *alg = &halg->base;
  543. if (alg->cra_type != &crypto_ahash_type)
  544. return crypto_shash_alg_has_setkey(__crypto_shash_alg(alg));
  545. return __crypto_ahash_alg(alg)->setkey != NULL;
  546. }
  547. EXPORT_SYMBOL_GPL(crypto_hash_alg_has_setkey);
  548. MODULE_LICENSE("GPL");
  549. MODULE_DESCRIPTION("Asynchronous cryptographic hash type");