proc.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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 <asm/atomic.h>
  16. #include <linux/init.h>
  17. #include <linux/crypto.h>
  18. #include <linux/rwsem.h>
  19. #include <linux/proc_fs.h>
  20. #include <linux/seq_file.h>
  21. #include <linux/sysctl.h>
  22. #include "internal.h"
  23. #ifdef CONFIG_CRYPTO_FIPS
  24. static struct ctl_table crypto_sysctl_table[] = {
  25. {
  26. .procname = "fips_enabled",
  27. .data = &fips_enabled,
  28. .maxlen = sizeof(int),
  29. .mode = 0444,
  30. .proc_handler = proc_dointvec
  31. },
  32. {}
  33. };
  34. static struct ctl_table crypto_dir_table[] = {
  35. {
  36. .procname = "crypto",
  37. .mode = 0555,
  38. .child = crypto_sysctl_table
  39. },
  40. {}
  41. };
  42. static struct ctl_table_header *crypto_sysctls;
  43. static void crypto_proc_fips_init(void)
  44. {
  45. crypto_sysctls = register_sysctl_table(crypto_dir_table);
  46. }
  47. static void crypto_proc_fips_exit(void)
  48. {
  49. if (crypto_sysctls)
  50. unregister_sysctl_table(crypto_sysctls);
  51. }
  52. #else
  53. #define crypto_proc_fips_init()
  54. #define crypto_proc_fips_exit()
  55. #endif
  56. static void *c_start(struct seq_file *m, loff_t *pos)
  57. {
  58. down_read(&crypto_alg_sem);
  59. return seq_list_start(&crypto_alg_list, *pos);
  60. }
  61. static void *c_next(struct seq_file *m, void *p, loff_t *pos)
  62. {
  63. return seq_list_next(p, &crypto_alg_list, pos);
  64. }
  65. static void c_stop(struct seq_file *m, void *p)
  66. {
  67. up_read(&crypto_alg_sem);
  68. }
  69. static int c_show(struct seq_file *m, void *p)
  70. {
  71. struct crypto_alg *alg = list_entry(p, struct crypto_alg, cra_list);
  72. seq_printf(m, "name : %s\n", alg->cra_name);
  73. seq_printf(m, "driver : %s\n", alg->cra_driver_name);
  74. seq_printf(m, "module : %s\n", module_name(alg->cra_module));
  75. seq_printf(m, "priority : %d\n", alg->cra_priority);
  76. seq_printf(m, "refcnt : %d\n", atomic_read(&alg->cra_refcnt));
  77. seq_printf(m, "selftest : %s\n",
  78. (alg->cra_flags & CRYPTO_ALG_TESTED) ?
  79. "passed" : "unknown");
  80. if (alg->cra_flags & CRYPTO_ALG_LARVAL) {
  81. seq_printf(m, "type : larval\n");
  82. seq_printf(m, "flags : 0x%x\n", alg->cra_flags);
  83. goto out;
  84. }
  85. if (alg->cra_type && alg->cra_type->show) {
  86. alg->cra_type->show(m, alg);
  87. goto out;
  88. }
  89. switch (alg->cra_flags & (CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_LARVAL)) {
  90. case CRYPTO_ALG_TYPE_CIPHER:
  91. seq_printf(m, "type : cipher\n");
  92. seq_printf(m, "blocksize : %u\n", alg->cra_blocksize);
  93. seq_printf(m, "min keysize : %u\n",
  94. alg->cra_cipher.cia_min_keysize);
  95. seq_printf(m, "max keysize : %u\n",
  96. alg->cra_cipher.cia_max_keysize);
  97. break;
  98. case CRYPTO_ALG_TYPE_COMPRESS:
  99. seq_printf(m, "type : compression\n");
  100. break;
  101. default:
  102. seq_printf(m, "type : unknown\n");
  103. break;
  104. }
  105. out:
  106. seq_putc(m, '\n');
  107. return 0;
  108. }
  109. static const struct seq_operations crypto_seq_ops = {
  110. .start = c_start,
  111. .next = c_next,
  112. .stop = c_stop,
  113. .show = c_show
  114. };
  115. static int crypto_info_open(struct inode *inode, struct file *file)
  116. {
  117. return seq_open(file, &crypto_seq_ops);
  118. }
  119. static const struct file_operations proc_crypto_ops = {
  120. .open = crypto_info_open,
  121. .read = seq_read,
  122. .llseek = seq_lseek,
  123. .release = seq_release
  124. };
  125. void __init crypto_init_proc(void)
  126. {
  127. proc_create("crypto", 0, NULL, &proc_crypto_ops);
  128. crypto_proc_fips_init();
  129. }
  130. void __exit crypto_exit_proc(void)
  131. {
  132. crypto_proc_fips_exit();
  133. remove_proc_entry("crypto", NULL);
  134. }