proc.c 2.8 KB

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