blob: 9e573b17e887961d0706b66c0fda6fb1e1cf2e6b [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Scatterlist Cryptographic API.
3 *
4 * Procfs information.
5 *
6 * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
Herbert Xu5cb14542005-11-05 16:58:14 +11007 * Copyright (c) 2005 Herbert Xu <herbert@gondor.apana.org.au>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 *
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 */
Herbert Xu6521f302006-08-06 20:28:44 +100015
16#include <asm/atomic.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <linux/init.h>
18#include <linux/crypto.h>
19#include <linux/rwsem.h>
20#include <linux/proc_fs.h>
21#include <linux/seq_file.h>
22#include "internal.h"
23
Linus Torvalds1da177e2005-04-16 15:20:36 -070024static void *c_start(struct seq_file *m, loff_t *pos)
25{
26 struct list_head *v;
27 loff_t n = *pos;
28
29 down_read(&crypto_alg_sem);
30 list_for_each(v, &crypto_alg_list)
31 if (!n--)
32 return list_entry(v, struct crypto_alg, cra_list);
33 return NULL;
34}
35
36static void *c_next(struct seq_file *m, void *p, loff_t *pos)
37{
38 struct list_head *v = p;
39
40 (*pos)++;
41 v = v->next;
42 return (v == &crypto_alg_list) ?
43 NULL : list_entry(v, struct crypto_alg, cra_list);
44}
45
46static void c_stop(struct seq_file *m, void *p)
47{
48 up_read(&crypto_alg_sem);
49}
50
51static int c_show(struct seq_file *m, void *p)
52{
53 struct crypto_alg *alg = (struct crypto_alg *)p;
54
55 seq_printf(m, "name : %s\n", alg->cra_name);
Herbert Xu5cb14542005-11-05 16:58:14 +110056 seq_printf(m, "driver : %s\n", alg->cra_driver_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 seq_printf(m, "module : %s\n", module_name(alg->cra_module));
Herbert Xu5cb14542005-11-05 16:58:14 +110058 seq_printf(m, "priority : %d\n", alg->cra_priority);
Herbert Xu6521f302006-08-06 20:28:44 +100059 seq_printf(m, "refcnt : %d\n", atomic_read(&alg->cra_refcnt));
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
61 switch (alg->cra_flags & CRYPTO_ALG_TYPE_MASK) {
62 case CRYPTO_ALG_TYPE_CIPHER:
63 seq_printf(m, "type : cipher\n");
64 seq_printf(m, "blocksize : %u\n", alg->cra_blocksize);
65 seq_printf(m, "min keysize : %u\n",
66 alg->cra_cipher.cia_min_keysize);
67 seq_printf(m, "max keysize : %u\n",
68 alg->cra_cipher.cia_max_keysize);
69 break;
70
71 case CRYPTO_ALG_TYPE_DIGEST:
72 seq_printf(m, "type : digest\n");
73 seq_printf(m, "blocksize : %u\n", alg->cra_blocksize);
74 seq_printf(m, "digestsize : %u\n",
75 alg->cra_digest.dia_digestsize);
76 break;
77 case CRYPTO_ALG_TYPE_COMPRESS:
78 seq_printf(m, "type : compression\n");
79 break;
80 default:
81 seq_printf(m, "type : unknown\n");
82 break;
83 }
84
85 seq_putc(m, '\n');
86 return 0;
87}
88
89static struct seq_operations crypto_seq_ops = {
90 .start = c_start,
91 .next = c_next,
92 .stop = c_stop,
93 .show = c_show
94};
95
96static int crypto_info_open(struct inode *inode, struct file *file)
97{
98 return seq_open(file, &crypto_seq_ops);
99}
100
101static struct file_operations proc_crypto_ops = {
102 .open = crypto_info_open,
103 .read = seq_read,
104 .llseek = seq_lseek,
105 .release = seq_release
106};
107
108void __init crypto_init_proc(void)
109{
110 struct proc_dir_entry *proc;
111
112 proc = create_proc_entry("crypto", 0, NULL);
113 if (proc)
114 proc->proc_fops = &proc_crypto_ops;
115}
Herbert Xucce9e062006-08-21 21:08:13 +1000116
117void __exit crypto_exit_proc(void)
118{
119 remove_proc_entry("crypto", NULL);
120}