blob: 7b91557adccbcaeb26abbca7c0e9e41338720aef [file] [log] [blame]
Thomas Gleixner2874c5f2019-05-27 08:55:01 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * Scatterlist Cryptographic API.
4 *
5 * Procfs information.
6 *
7 * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
Herbert Xu5cb1454b2005-11-05 16:58:14 +11008 * Copyright (c) 2005 Herbert Xu <herbert@gondor.apana.org.au>
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 */
Herbert Xu6521f302006-08-06 20:28:44 +100010
Arun Sharma600634972011-07-26 16:09:06 -070011#include <linux/atomic.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <linux/init.h>
13#include <linux/crypto.h>
Paul Gortmaker4bb33cc2011-05-27 14:41:48 -040014#include <linux/module.h> /* for module_name() */
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/rwsem.h>
16#include <linux/proc_fs.h>
17#include <linux/seq_file.h>
18#include "internal.h"
19
Linus Torvalds1da177e2005-04-16 15:20:36 -070020static void *c_start(struct seq_file *m, loff_t *pos)
21{
Linus Torvalds1da177e2005-04-16 15:20:36 -070022 down_read(&crypto_alg_sem);
Pavel Emelianov13d31892007-07-15 23:39:53 -070023 return seq_list_start(&crypto_alg_list, *pos);
Linus Torvalds1da177e2005-04-16 15:20:36 -070024}
25
26static void *c_next(struct seq_file *m, void *p, loff_t *pos)
27{
Pavel Emelianov13d31892007-07-15 23:39:53 -070028 return seq_list_next(p, &crypto_alg_list, pos);
Linus Torvalds1da177e2005-04-16 15:20:36 -070029}
30
31static void c_stop(struct seq_file *m, void *p)
32{
33 up_read(&crypto_alg_sem);
34}
35
36static int c_show(struct seq_file *m, void *p)
37{
Pavel Emelianov13d31892007-07-15 23:39:53 -070038 struct crypto_alg *alg = list_entry(p, struct crypto_alg, cra_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
40 seq_printf(m, "name : %s\n", alg->cra_name);
Herbert Xu5cb1454b2005-11-05 16:58:14 +110041 seq_printf(m, "driver : %s\n", alg->cra_driver_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -070042 seq_printf(m, "module : %s\n", module_name(alg->cra_module));
Herbert Xu5cb1454b2005-11-05 16:58:14 +110043 seq_printf(m, "priority : %d\n", alg->cra_priority);
Eric Biggersce8614a2017-12-29 10:00:46 -060044 seq_printf(m, "refcnt : %u\n", refcount_read(&alg->cra_refcnt));
Herbert Xu73d38642008-08-03 21:15:23 +080045 seq_printf(m, "selftest : %s\n",
46 (alg->cra_flags & CRYPTO_ALG_TESTED) ?
47 "passed" : "unknown");
Stephan Muellerb0cda2b2015-03-30 21:57:42 +020048 seq_printf(m, "internal : %s\n",
49 (alg->cra_flags & CRYPTO_ALG_INTERNAL) ?
50 "yes" : "no");
Herbert Xu67cd0802008-11-06 14:39:16 +080051
52 if (alg->cra_flags & CRYPTO_ALG_LARVAL) {
53 seq_printf(m, "type : larval\n");
54 seq_printf(m, "flags : 0x%x\n", alg->cra_flags);
55 goto out;
56 }
57
58 if (alg->cra_type && alg->cra_type->show) {
59 alg->cra_type->show(m, alg);
60 goto out;
61 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
Herbert Xua7581a02008-08-04 14:22:29 +080063 switch (alg->cra_flags & (CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_LARVAL)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 case CRYPTO_ALG_TYPE_CIPHER:
65 seq_printf(m, "type : cipher\n");
66 seq_printf(m, "blocksize : %u\n", alg->cra_blocksize);
67 seq_printf(m, "min keysize : %u\n",
68 alg->cra_cipher.cia_min_keysize);
69 seq_printf(m, "max keysize : %u\n",
70 alg->cra_cipher.cia_max_keysize);
71 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 case CRYPTO_ALG_TYPE_COMPRESS:
73 seq_printf(m, "type : compression\n");
74 break;
75 default:
Herbert Xu67cd0802008-11-06 14:39:16 +080076 seq_printf(m, "type : unknown\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 break;
78 }
79
Herbert Xu67cd0802008-11-06 14:39:16 +080080out:
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 seq_putc(m, '\n');
82 return 0;
83}
84
Jan Engelhardt48c89492008-03-13 19:37:45 +080085static const struct seq_operations crypto_seq_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 .start = c_start,
87 .next = c_next,
88 .stop = c_stop,
89 .show = c_show
90};
91
Linus Torvalds1da177e2005-04-16 15:20:36 -070092void __init crypto_init_proc(void)
93{
Christoph Hellwigfddda2b2018-04-13 19:44:18 +020094 proc_create_seq("crypto", 0, NULL, &crypto_seq_ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -070095}
Herbert Xucce9e062006-08-21 21:08:13 +100096
97void __exit crypto_exit_proc(void)
98{
99 remove_proc_entry("crypto", NULL);
100}