Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  * Scatterlist Cryptographic API.
0004  *
0005  * Procfs information.
0006  *
0007  * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
0008  * Copyright (c) 2005 Herbert Xu <herbert@gondor.apana.org.au>
0009  */
0010 
0011 #include <linux/atomic.h>
0012 #include <linux/init.h>
0013 #include <linux/crypto.h>
0014 #include <linux/module.h>   /* for module_name() */
0015 #include <linux/rwsem.h>
0016 #include <linux/proc_fs.h>
0017 #include <linux/seq_file.h>
0018 #include "internal.h"
0019 
0020 static void *c_start(struct seq_file *m, loff_t *pos)
0021 {
0022     down_read(&crypto_alg_sem);
0023     return seq_list_start(&crypto_alg_list, *pos);
0024 }
0025 
0026 static void *c_next(struct seq_file *m, void *p, loff_t *pos)
0027 {
0028     return seq_list_next(p, &crypto_alg_list, pos);
0029 }
0030 
0031 static void c_stop(struct seq_file *m, void *p)
0032 {
0033     up_read(&crypto_alg_sem);
0034 }
0035 
0036 static int c_show(struct seq_file *m, void *p)
0037 {
0038     struct crypto_alg *alg = list_entry(p, struct crypto_alg, cra_list);
0039 
0040     seq_printf(m, "name         : %s\n", alg->cra_name);
0041     seq_printf(m, "driver       : %s\n", alg->cra_driver_name);
0042     seq_printf(m, "module       : %s\n", module_name(alg->cra_module));
0043     seq_printf(m, "priority     : %d\n", alg->cra_priority);
0044     seq_printf(m, "refcnt       : %u\n", refcount_read(&alg->cra_refcnt));
0045     seq_printf(m, "selftest     : %s\n",
0046            (alg->cra_flags & CRYPTO_ALG_TESTED) ?
0047            "passed" : "unknown");
0048     seq_printf(m, "internal     : %s\n",
0049            (alg->cra_flags & CRYPTO_ALG_INTERNAL) ?
0050            "yes" : "no");
0051 
0052     if (alg->cra_flags & CRYPTO_ALG_LARVAL) {
0053         seq_printf(m, "type         : larval\n");
0054         seq_printf(m, "flags        : 0x%x\n", alg->cra_flags);
0055         goto out;
0056     }
0057 
0058     if (alg->cra_type && alg->cra_type->show) {
0059         alg->cra_type->show(m, alg);
0060         goto out;
0061     }
0062 
0063     switch (alg->cra_flags & CRYPTO_ALG_TYPE_MASK) {
0064     case CRYPTO_ALG_TYPE_CIPHER:
0065         seq_printf(m, "type         : cipher\n");
0066         seq_printf(m, "blocksize    : %u\n", alg->cra_blocksize);
0067         seq_printf(m, "min keysize  : %u\n",
0068                     alg->cra_cipher.cia_min_keysize);
0069         seq_printf(m, "max keysize  : %u\n",
0070                     alg->cra_cipher.cia_max_keysize);
0071         break;
0072     case CRYPTO_ALG_TYPE_COMPRESS:
0073         seq_printf(m, "type         : compression\n");
0074         break;
0075     default:
0076         seq_printf(m, "type         : unknown\n");
0077         break;
0078     }
0079 
0080 out:
0081     seq_putc(m, '\n');
0082     return 0;
0083 }
0084 
0085 static const struct seq_operations crypto_seq_ops = {
0086     .start      = c_start,
0087     .next       = c_next,
0088     .stop       = c_stop,
0089     .show       = c_show
0090 };
0091 
0092 void __init crypto_init_proc(void)
0093 {
0094     proc_create_seq("crypto", 0, NULL, &crypto_seq_ops);
0095 }
0096 
0097 void __exit crypto_exit_proc(void)
0098 {
0099     remove_proc_entry("crypto", NULL);
0100 }