hash.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * Cryptographic Hash operations.
  3. *
  4. * Copyright (c) 2006 Herbert Xu <herbert@gondor.apana.org.au>
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the Free
  8. * Software Foundation; either version 2 of the License, or (at your option)
  9. * any later version.
  10. */
  11. #include <linux/errno.h>
  12. #include <linux/kernel.h>
  13. #include <linux/module.h>
  14. #include <linux/seq_file.h>
  15. #include "internal.h"
  16. static unsigned int crypto_hash_ctxsize(struct crypto_alg *alg)
  17. {
  18. return alg->cra_ctxsize;
  19. }
  20. static int crypto_init_hash_ops(struct crypto_tfm *tfm)
  21. {
  22. struct hash_tfm *crt = &tfm->crt_hash;
  23. struct hash_alg *alg = &tfm->__crt_alg->cra_hash;
  24. if (alg->digestsize > crypto_tfm_alg_blocksize(tfm))
  25. return -EINVAL;
  26. crt->init = alg->init;
  27. crt->update = alg->update;
  28. crt->final = alg->final;
  29. crt->digest = alg->digest;
  30. crt->setkey = alg->setkey;
  31. crt->digestsize = alg->digestsize;
  32. return 0;
  33. }
  34. static void crypto_hash_show(struct seq_file *m, struct crypto_alg *alg)
  35. __attribute_used__;
  36. static void crypto_hash_show(struct seq_file *m, struct crypto_alg *alg)
  37. {
  38. seq_printf(m, "type : hash\n");
  39. seq_printf(m, "blocksize : %u\n", alg->cra_blocksize);
  40. seq_printf(m, "digestsize : %u\n", alg->cra_hash.digestsize);
  41. }
  42. const struct crypto_type crypto_hash_type = {
  43. .ctxsize = crypto_hash_ctxsize,
  44. .init = crypto_init_hash_ops,
  45. #ifdef CONFIG_PROC_FS
  46. .show = crypto_hash_show,
  47. #endif
  48. };
  49. EXPORT_SYMBOL_GPL(crypto_hash_type);
  50. MODULE_LICENSE("GPL");
  51. MODULE_DESCRIPTION("Generic cryptographic hash type");