12874c5fdSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
21da177e4SLinus Torvalds /*
31da177e4SLinus Torvalds * Scatterlist Cryptographic API.
41da177e4SLinus Torvalds *
51da177e4SLinus Torvalds * Procfs information.
61da177e4SLinus Torvalds *
71da177e4SLinus Torvalds * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
85cb1454bSHerbert Xu * Copyright (c) 2005 Herbert Xu <herbert@gondor.apana.org.au>
91da177e4SLinus Torvalds */
106521f302SHerbert Xu
1160063497SArun Sharma #include <linux/atomic.h>
121da177e4SLinus Torvalds #include <linux/init.h>
131da177e4SLinus Torvalds #include <linux/crypto.h>
14*c43cc882SHerbert Xu #include <linux/fips.h>
154bb33cc8SPaul Gortmaker #include <linux/module.h> /* for module_name() */
161da177e4SLinus Torvalds #include <linux/rwsem.h>
171da177e4SLinus Torvalds #include <linux/proc_fs.h>
181da177e4SLinus Torvalds #include <linux/seq_file.h>
191da177e4SLinus Torvalds #include "internal.h"
201da177e4SLinus Torvalds
c_start(struct seq_file * m,loff_t * pos)211da177e4SLinus Torvalds static void *c_start(struct seq_file *m, loff_t *pos)
221da177e4SLinus Torvalds {
231da177e4SLinus Torvalds down_read(&crypto_alg_sem);
2413d31894SPavel Emelianov return seq_list_start(&crypto_alg_list, *pos);
251da177e4SLinus Torvalds }
261da177e4SLinus Torvalds
c_next(struct seq_file * m,void * p,loff_t * pos)271da177e4SLinus Torvalds static void *c_next(struct seq_file *m, void *p, loff_t *pos)
281da177e4SLinus Torvalds {
2913d31894SPavel Emelianov return seq_list_next(p, &crypto_alg_list, pos);
301da177e4SLinus Torvalds }
311da177e4SLinus Torvalds
c_stop(struct seq_file * m,void * p)321da177e4SLinus Torvalds static void c_stop(struct seq_file *m, void *p)
331da177e4SLinus Torvalds {
341da177e4SLinus Torvalds up_read(&crypto_alg_sem);
351da177e4SLinus Torvalds }
361da177e4SLinus Torvalds
c_show(struct seq_file * m,void * p)371da177e4SLinus Torvalds static int c_show(struct seq_file *m, void *p)
381da177e4SLinus Torvalds {
3913d31894SPavel Emelianov struct crypto_alg *alg = list_entry(p, struct crypto_alg, cra_list);
401da177e4SLinus Torvalds
411da177e4SLinus Torvalds seq_printf(m, "name : %s\n", alg->cra_name);
425cb1454bSHerbert Xu seq_printf(m, "driver : %s\n", alg->cra_driver_name);
431da177e4SLinus Torvalds seq_printf(m, "module : %s\n", module_name(alg->cra_module));
445cb1454bSHerbert Xu seq_printf(m, "priority : %d\n", alg->cra_priority);
45ce8614a3SEric Biggers seq_printf(m, "refcnt : %u\n", refcount_read(&alg->cra_refcnt));
4673d3864aSHerbert Xu seq_printf(m, "selftest : %s\n",
4773d3864aSHerbert Xu (alg->cra_flags & CRYPTO_ALG_TESTED) ?
4873d3864aSHerbert Xu "passed" : "unknown");
49b0cda2baSStephan Mueller seq_printf(m, "internal : %s\n",
50b0cda2baSStephan Mueller (alg->cra_flags & CRYPTO_ALG_INTERNAL) ?
51b0cda2baSStephan Mueller "yes" : "no");
52*c43cc882SHerbert Xu if (fips_enabled) {
53*c43cc882SHerbert Xu seq_printf(m, "fips : %s\n",
54*c43cc882SHerbert Xu (alg->cra_flags & CRYPTO_ALG_FIPS_INTERNAL) ?
55*c43cc882SHerbert Xu "no" : "yes");
56*c43cc882SHerbert Xu }
571da177e4SLinus Torvalds
5867cd080cSHerbert Xu if (alg->cra_flags & CRYPTO_ALG_LARVAL) {
5967cd080cSHerbert Xu seq_printf(m, "type : larval\n");
6067cd080cSHerbert Xu seq_printf(m, "flags : 0x%x\n", alg->cra_flags);
6167cd080cSHerbert Xu goto out;
6267cd080cSHerbert Xu }
6367cd080cSHerbert Xu
6467cd080cSHerbert Xu if (alg->cra_type && alg->cra_type->show) {
6567cd080cSHerbert Xu alg->cra_type->show(m, alg);
6667cd080cSHerbert Xu goto out;
6767cd080cSHerbert Xu }
6867cd080cSHerbert Xu
697f1cfe41STianjia Zhang switch (alg->cra_flags & CRYPTO_ALG_TYPE_MASK) {
701da177e4SLinus Torvalds case CRYPTO_ALG_TYPE_CIPHER:
711da177e4SLinus Torvalds seq_printf(m, "type : cipher\n");
721da177e4SLinus Torvalds seq_printf(m, "blocksize : %u\n", alg->cra_blocksize);
731da177e4SLinus Torvalds seq_printf(m, "min keysize : %u\n",
741da177e4SLinus Torvalds alg->cra_cipher.cia_min_keysize);
751da177e4SLinus Torvalds seq_printf(m, "max keysize : %u\n",
761da177e4SLinus Torvalds alg->cra_cipher.cia_max_keysize);
771da177e4SLinus Torvalds break;
781da177e4SLinus Torvalds case CRYPTO_ALG_TYPE_COMPRESS:
791da177e4SLinus Torvalds seq_printf(m, "type : compression\n");
801da177e4SLinus Torvalds break;
811da177e4SLinus Torvalds default:
821da177e4SLinus Torvalds seq_printf(m, "type : unknown\n");
831da177e4SLinus Torvalds break;
841da177e4SLinus Torvalds }
851da177e4SLinus Torvalds
8667cd080cSHerbert Xu out:
871da177e4SLinus Torvalds seq_putc(m, '\n');
881da177e4SLinus Torvalds return 0;
891da177e4SLinus Torvalds }
901da177e4SLinus Torvalds
9148c8949eSJan Engelhardt static const struct seq_operations crypto_seq_ops = {
921da177e4SLinus Torvalds .start = c_start,
931da177e4SLinus Torvalds .next = c_next,
941da177e4SLinus Torvalds .stop = c_stop,
951da177e4SLinus Torvalds .show = c_show
961da177e4SLinus Torvalds };
971da177e4SLinus Torvalds
crypto_init_proc(void)981da177e4SLinus Torvalds void __init crypto_init_proc(void)
991da177e4SLinus Torvalds {
100fddda2b7SChristoph Hellwig proc_create_seq("crypto", 0, NULL, &crypto_seq_ops);
1011da177e4SLinus Torvalds }
102cce9e06dSHerbert Xu
crypto_exit_proc(void)103cce9e06dSHerbert Xu void __exit crypto_exit_proc(void)
104cce9e06dSHerbert Xu {
105cce9e06dSHerbert Xu remove_proc_entry("crypto", NULL);
106cce9e06dSHerbert Xu }
107