proc.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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 "internal.h"
  22. static void *c_start(struct seq_file *m, loff_t *pos)
  23. {
  24. struct list_head *v;
  25. loff_t n = *pos;
  26. down_read(&crypto_alg_sem);
  27. list_for_each(v, &crypto_alg_list)
  28. if (!n--)
  29. return list_entry(v, struct crypto_alg, cra_list);
  30. return NULL;
  31. }
  32. static void *c_next(struct seq_file *m, void *p, loff_t *pos)
  33. {
  34. struct list_head *v = p;
  35. (*pos)++;
  36. v = v->next;
  37. return (v == &crypto_alg_list) ?
  38. NULL : list_entry(v, struct crypto_alg, cra_list);
  39. }
  40. static void c_stop(struct seq_file *m, void *p)
  41. {
  42. up_read(&crypto_alg_sem);
  43. }
  44. static int c_show(struct seq_file *m, void *p)
  45. {
  46. struct crypto_alg *alg = (struct crypto_alg *)p;
  47. seq_printf(m, "name : %s\n", alg->cra_name);
  48. seq_printf(m, "driver : %s\n", alg->cra_driver_name);
  49. seq_printf(m, "module : %s\n", module_name(alg->cra_module));
  50. seq_printf(m, "priority : %d\n", alg->cra_priority);
  51. seq_printf(m, "refcnt : %d\n", atomic_read(&alg->cra_refcnt));
  52. switch (alg->cra_flags & CRYPTO_ALG_TYPE_MASK) {
  53. case CRYPTO_ALG_TYPE_CIPHER:
  54. seq_printf(m, "type : cipher\n");
  55. seq_printf(m, "blocksize : %u\n", alg->cra_blocksize);
  56. seq_printf(m, "min keysize : %u\n",
  57. alg->cra_cipher.cia_min_keysize);
  58. seq_printf(m, "max keysize : %u\n",
  59. alg->cra_cipher.cia_max_keysize);
  60. break;
  61. case CRYPTO_ALG_TYPE_DIGEST:
  62. seq_printf(m, "type : digest\n");
  63. seq_printf(m, "blocksize : %u\n", alg->cra_blocksize);
  64. seq_printf(m, "digestsize : %u\n",
  65. alg->cra_digest.dia_digestsize);
  66. break;
  67. case CRYPTO_ALG_TYPE_COMPRESS:
  68. seq_printf(m, "type : compression\n");
  69. break;
  70. default:
  71. if (alg->cra_type && alg->cra_type->show)
  72. alg->cra_type->show(m, alg);
  73. else
  74. seq_printf(m, "type : unknown\n");
  75. break;
  76. }
  77. seq_putc(m, '\n');
  78. return 0;
  79. }
  80. static struct seq_operations crypto_seq_ops = {
  81. .start = c_start,
  82. .next = c_next,
  83. .stop = c_stop,
  84. .show = c_show
  85. };
  86. static int crypto_info_open(struct inode *inode, struct file *file)
  87. {
  88. return seq_open(file, &crypto_seq_ops);
  89. }
  90. static const struct file_operations proc_crypto_ops = {
  91. .open = crypto_info_open,
  92. .read = seq_read,
  93. .llseek = seq_lseek,
  94. .release = seq_release
  95. };
  96. void __init crypto_init_proc(void)
  97. {
  98. struct proc_dir_entry *proc;
  99. proc = create_proc_entry("crypto", 0, NULL);
  100. if (proc)
  101. proc->proc_fops = &proc_crypto_ops;
  102. }
  103. void __exit crypto_exit_proc(void)
  104. {
  105. remove_proc_entry("crypto", NULL);
  106. }