proc.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. * Scatterlist Cryptographic API.
  3. *
  4. * Procfs information.
  5. *
  6. * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the Free
  10. * Software Foundation; either version 2 of the License, or (at your option)
  11. * any later version.
  12. *
  13. */
  14. #include <linux/init.h>
  15. #include <linux/crypto.h>
  16. #include <linux/rwsem.h>
  17. #include <linux/proc_fs.h>
  18. #include <linux/seq_file.h>
  19. #include "internal.h"
  20. extern struct list_head crypto_alg_list;
  21. extern struct rw_semaphore crypto_alg_sem;
  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, "module : %s\n", module_name(alg->cra_module));
  49. switch (alg->cra_flags & CRYPTO_ALG_TYPE_MASK) {
  50. case CRYPTO_ALG_TYPE_CIPHER:
  51. seq_printf(m, "type : cipher\n");
  52. seq_printf(m, "blocksize : %u\n", alg->cra_blocksize);
  53. seq_printf(m, "min keysize : %u\n",
  54. alg->cra_cipher.cia_min_keysize);
  55. seq_printf(m, "max keysize : %u\n",
  56. alg->cra_cipher.cia_max_keysize);
  57. break;
  58. case CRYPTO_ALG_TYPE_DIGEST:
  59. seq_printf(m, "type : digest\n");
  60. seq_printf(m, "blocksize : %u\n", alg->cra_blocksize);
  61. seq_printf(m, "digestsize : %u\n",
  62. alg->cra_digest.dia_digestsize);
  63. break;
  64. case CRYPTO_ALG_TYPE_COMPRESS:
  65. seq_printf(m, "type : compression\n");
  66. break;
  67. default:
  68. seq_printf(m, "type : unknown\n");
  69. break;
  70. }
  71. seq_putc(m, '\n');
  72. return 0;
  73. }
  74. static struct seq_operations crypto_seq_ops = {
  75. .start = c_start,
  76. .next = c_next,
  77. .stop = c_stop,
  78. .show = c_show
  79. };
  80. static int crypto_info_open(struct inode *inode, struct file *file)
  81. {
  82. return seq_open(file, &crypto_seq_ops);
  83. }
  84. static struct file_operations proc_crypto_ops = {
  85. .open = crypto_info_open,
  86. .read = seq_read,
  87. .llseek = seq_lseek,
  88. .release = seq_release
  89. };
  90. void __init crypto_init_proc(void)
  91. {
  92. struct proc_dir_entry *proc;
  93. proc = create_proc_entry("crypto", 0, NULL);
  94. if (proc)
  95. proc->proc_fops = &proc_crypto_ops;
  96. }