ablkcipher.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * Asynchronous block chaining cipher operations.
  3. *
  4. * This is the asynchronous version of blkcipher.c indicating completion
  5. * via a callback.
  6. *
  7. * Copyright (c) 2006 Herbert Xu <herbert@gondor.apana.org.au>
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License as published by the Free
  11. * Software Foundation; either version 2 of the License, or (at your option)
  12. * any later version.
  13. *
  14. */
  15. #include <crypto/algapi.h>
  16. #include <linux/errno.h>
  17. #include <linux/init.h>
  18. #include <linux/module.h>
  19. #include <linux/seq_file.h>
  20. static int setkey(struct crypto_ablkcipher *tfm, const u8 *key,
  21. unsigned int keylen)
  22. {
  23. struct ablkcipher_alg *cipher = crypto_ablkcipher_alg(tfm);
  24. if (keylen < cipher->min_keysize || keylen > cipher->max_keysize) {
  25. crypto_ablkcipher_set_flags(tfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
  26. return -EINVAL;
  27. }
  28. return cipher->setkey(tfm, key, keylen);
  29. }
  30. static unsigned int crypto_ablkcipher_ctxsize(struct crypto_alg *alg, u32 type,
  31. u32 mask)
  32. {
  33. return alg->cra_ctxsize;
  34. }
  35. static int crypto_init_ablkcipher_ops(struct crypto_tfm *tfm, u32 type,
  36. u32 mask)
  37. {
  38. struct ablkcipher_alg *alg = &tfm->__crt_alg->cra_ablkcipher;
  39. struct ablkcipher_tfm *crt = &tfm->crt_ablkcipher;
  40. if (alg->ivsize > PAGE_SIZE / 8)
  41. return -EINVAL;
  42. crt->setkey = setkey;
  43. crt->encrypt = alg->encrypt;
  44. crt->decrypt = alg->decrypt;
  45. crt->ivsize = alg->ivsize;
  46. return 0;
  47. }
  48. static void crypto_ablkcipher_show(struct seq_file *m, struct crypto_alg *alg)
  49. __attribute__ ((unused));
  50. static void crypto_ablkcipher_show(struct seq_file *m, struct crypto_alg *alg)
  51. {
  52. struct ablkcipher_alg *ablkcipher = &alg->cra_ablkcipher;
  53. seq_printf(m, "type : ablkcipher\n");
  54. seq_printf(m, "blocksize : %u\n", alg->cra_blocksize);
  55. seq_printf(m, "min keysize : %u\n", ablkcipher->min_keysize);
  56. seq_printf(m, "max keysize : %u\n", ablkcipher->max_keysize);
  57. seq_printf(m, "ivsize : %u\n", ablkcipher->ivsize);
  58. seq_printf(m, "qlen : %u\n", ablkcipher->queue->qlen);
  59. seq_printf(m, "max qlen : %u\n", ablkcipher->queue->max_qlen);
  60. }
  61. const struct crypto_type crypto_ablkcipher_type = {
  62. .ctxsize = crypto_ablkcipher_ctxsize,
  63. .init = crypto_init_ablkcipher_ops,
  64. #ifdef CONFIG_PROC_FS
  65. .show = crypto_ablkcipher_show,
  66. #endif
  67. };
  68. EXPORT_SYMBOL_GPL(crypto_ablkcipher_type);
  69. MODULE_LICENSE("GPL");
  70. MODULE_DESCRIPTION("Asynchronous block chaining cipher type");