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