proc.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * Scatterlist Cryptographic API.
  3. *
  4. * Procfs information.
  5. *
  6. * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
  7. * Copyright (c) 2005 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 <linux/atomic.h>
  16. #include <linux/init.h>
  17. #include <linux/crypto.h>
  18. #include <linux/module.h> /* for module_name() */
  19. #include <linux/rwsem.h>
  20. #include <linux/proc_fs.h>
  21. #include <linux/seq_file.h>
  22. #include "internal.h"
  23. static void *c_start(struct seq_file *m, loff_t *pos)
  24. {
  25. down_read(&crypto_alg_sem);
  26. return seq_list_start(&crypto_alg_list, *pos);
  27. }
  28. static void *c_next(struct seq_file *m, void *p, loff_t *pos)
  29. {
  30. return seq_list_next(p, &crypto_alg_list, pos);
  31. }
  32. static void c_stop(struct seq_file *m, void *p)
  33. {
  34. up_read(&crypto_alg_sem);
  35. }
  36. static int c_show(struct seq_file *m, void *p)
  37. {
  38. struct crypto_alg *alg = list_entry(p, struct crypto_alg, cra_list);
  39. seq_printf(m, "name : %s\n", alg->cra_name);
  40. seq_printf(m, "driver : %s\n", alg->cra_driver_name);
  41. seq_printf(m, "module : %s\n", module_name(alg->cra_module));
  42. seq_printf(m, "priority : %d\n", alg->cra_priority);
  43. seq_printf(m, "refcnt : %d\n", atomic_read(&alg->cra_refcnt));
  44. seq_printf(m, "selftest : %s\n",
  45. (alg->cra_flags & CRYPTO_ALG_TESTED) ?
  46. "passed" : "unknown");
  47. seq_printf(m, "internal : %s\n",
  48. (alg->cra_flags & CRYPTO_ALG_INTERNAL) ?
  49. "yes" : "no");
  50. if (alg->cra_flags & CRYPTO_ALG_LARVAL) {
  51. seq_printf(m, "type : larval\n");
  52. seq_printf(m, "flags : 0x%x\n", alg->cra_flags);
  53. goto out;
  54. }
  55. if (alg->cra_type && alg->cra_type->show) {
  56. alg->cra_type->show(m, alg);
  57. goto out;
  58. }
  59. switch (alg->cra_flags & (CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_LARVAL)) {
  60. case CRYPTO_ALG_TYPE_CIPHER:
  61. seq_printf(m, "type : cipher\n");
  62. seq_printf(m, "blocksize : %u\n", alg->cra_blocksize);
  63. seq_printf(m, "min keysize : %u\n",
  64. alg->cra_cipher.cia_min_keysize);
  65. seq_printf(m, "max keysize : %u\n",
  66. alg->cra_cipher.cia_max_keysize);
  67. break;
  68. case CRYPTO_ALG_TYPE_COMPRESS:
  69. seq_printf(m, "type : compression\n");
  70. break;
  71. default:
  72. seq_printf(m, "type : unknown\n");
  73. break;
  74. }
  75. out:
  76. seq_putc(m, '\n');
  77. return 0;
  78. }
  79. static const struct seq_operations crypto_seq_ops = {
  80. .start = c_start,
  81. .next = c_next,
  82. .stop = c_stop,
  83. .show = c_show
  84. };
  85. static int crypto_info_open(struct inode *inode, struct file *file)
  86. {
  87. return seq_open(file, &crypto_seq_ops);
  88. }
  89. static const struct file_operations proc_crypto_ops = {
  90. .open = crypto_info_open,
  91. .read = seq_read,
  92. .llseek = seq_lseek,
  93. .release = seq_release
  94. };
  95. void __init crypto_init_proc(void)
  96. {
  97. proc_create("crypto", 0, NULL, &proc_crypto_ops);
  98. }
  99. void __exit crypto_exit_proc(void)
  100. {
  101. remove_proc_entry("crypto", NULL);
  102. }