blob: 56c7c78df29713e301d6aee4082d62e867a83c64 [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>
Herbert Xuc43cc882023-02-09 09:16:45 +080014#include <linux/fips.h>
Paul Gortmaker4bb33cc2011-05-27 14:41:48 -040015#include <linux/module.h> /* for module_name() */
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <linux/rwsem.h>
17#include <linux/proc_fs.h>
18#include <linux/seq_file.h>
19#include "internal.h"
20
Linus Torvalds1da177e2005-04-16 15:20:36 -070021static void *c_start(struct seq_file *m, loff_t *pos)
22{
Linus Torvalds1da177e2005-04-16 15:20:36 -070023 down_read(&crypto_alg_sem);
Pavel Emelianov13d31892007-07-15 23:39:53 -070024 return seq_list_start(&crypto_alg_list, *pos);
Linus Torvalds1da177e2005-04-16 15:20:36 -070025}
26
27static void *c_next(struct seq_file *m, void *p, loff_t *pos)
28{
Pavel Emelianov13d31892007-07-15 23:39:53 -070029 return seq_list_next(p, &crypto_alg_list, pos);
Linus Torvalds1da177e2005-04-16 15:20:36 -070030}
31
32static void c_stop(struct seq_file *m, void *p)
33{
34 up_read(&crypto_alg_sem);
35}
36
37static int c_show(struct seq_file *m, void *p)
38{
Pavel Emelianov13d31892007-07-15 23:39:53 -070039 struct crypto_alg *alg = list_entry(p, struct crypto_alg, cra_list);
Corentin Labbefde2f572020-09-17 18:59:36 +000040
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 seq_printf(m, "name : %s\n", alg->cra_name);
Herbert Xu5cb1454b2005-11-05 16:58:14 +110042 seq_printf(m, "driver : %s\n", alg->cra_driver_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -070043 seq_printf(m, "module : %s\n", module_name(alg->cra_module));
Herbert Xu5cb1454b2005-11-05 16:58:14 +110044 seq_printf(m, "priority : %d\n", alg->cra_priority);
Eric Biggersce8614a2017-12-29 10:00:46 -060045 seq_printf(m, "refcnt : %u\n", refcount_read(&alg->cra_refcnt));
Herbert Xu73d38642008-08-03 21:15:23 +080046 seq_printf(m, "selftest : %s\n",
47 (alg->cra_flags & CRYPTO_ALG_TESTED) ?
48 "passed" : "unknown");
Stephan Muellerb0cda2b2015-03-30 21:57:42 +020049 seq_printf(m, "internal : %s\n",
50 (alg->cra_flags & CRYPTO_ALG_INTERNAL) ?
51 "yes" : "no");
Herbert Xuc43cc882023-02-09 09:16:45 +080052 if (fips_enabled) {
53 seq_printf(m, "fips : %s\n",
54 (alg->cra_flags & CRYPTO_ALG_FIPS_INTERNAL) ?
55 "no" : "yes");
56 }
Herbert Xu67cd0802008-11-06 14:39:16 +080057
58 if (alg->cra_flags & CRYPTO_ALG_LARVAL) {
59 seq_printf(m, "type : larval\n");
60 seq_printf(m, "flags : 0x%x\n", alg->cra_flags);
61 goto out;
62 }
63
64 if (alg->cra_type && alg->cra_type->show) {
65 alg->cra_type->show(m, alg);
66 goto out;
67 }
Corentin Labbefde2f572020-09-17 18:59:36 +000068
Tianjia Zhang7f1cfe42020-02-05 15:25:23 +080069 switch (alg->cra_flags & CRYPTO_ALG_TYPE_MASK) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 case CRYPTO_ALG_TYPE_CIPHER:
71 seq_printf(m, "type : cipher\n");
72 seq_printf(m, "blocksize : %u\n", alg->cra_blocksize);
73 seq_printf(m, "min keysize : %u\n",
74 alg->cra_cipher.cia_min_keysize);
75 seq_printf(m, "max keysize : %u\n",
76 alg->cra_cipher.cia_max_keysize);
77 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 case CRYPTO_ALG_TYPE_COMPRESS:
79 seq_printf(m, "type : compression\n");
80 break;
81 default:
Herbert Xu67cd0802008-11-06 14:39:16 +080082 seq_printf(m, "type : unknown\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 break;
84 }
85
Herbert Xu67cd0802008-11-06 14:39:16 +080086out:
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 seq_putc(m, '\n');
88 return 0;
89}
90
Jan Engelhardt48c89492008-03-13 19:37:45 +080091static const struct seq_operations crypto_seq_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 .start = c_start,
93 .next = c_next,
94 .stop = c_stop,
95 .show = c_show
96};
97
Linus Torvalds1da177e2005-04-16 15:20:36 -070098void __init crypto_init_proc(void)
99{
Christoph Hellwigfddda2b2018-04-13 19:44:18 +0200100 proc_create_seq("crypto", 0, NULL, &crypto_seq_ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101}
Herbert Xucce9e062006-08-21 21:08:13 +1000102
103void __exit crypto_exit_proc(void)
104{
105 remove_proc_entry("crypto", NULL);
106}