Back to home page

LXR

 
 

    


0001 /*
0002  * Scatterlist Cryptographic API.
0003  *
0004  * Procfs information.
0005  *
0006  * Copyright (c) 2002 James Morris <jmorris@intercode.com.au>
0007  * Copyright (c) 2005 Herbert Xu <herbert@gondor.apana.org.au>
0008  *
0009  * This program is free software; you can redistribute it and/or modify it
0010  * under the terms of the GNU General Public License as published by the Free
0011  * Software Foundation; either version 2 of the License, or (at your option) 
0012  * any later version.
0013  *
0014  */
0015 
0016 #include <linux/atomic.h>
0017 #include <linux/init.h>
0018 #include <linux/crypto.h>
0019 #include <linux/module.h>   /* for module_name() */
0020 #include <linux/rwsem.h>
0021 #include <linux/proc_fs.h>
0022 #include <linux/seq_file.h>
0023 #include "internal.h"
0024 
0025 static void *c_start(struct seq_file *m, loff_t *pos)
0026 {
0027     down_read(&crypto_alg_sem);
0028     return seq_list_start(&crypto_alg_list, *pos);
0029 }
0030 
0031 static void *c_next(struct seq_file *m, void *p, loff_t *pos)
0032 {
0033     return seq_list_next(p, &crypto_alg_list, pos);
0034 }
0035 
0036 static void c_stop(struct seq_file *m, void *p)
0037 {
0038     up_read(&crypto_alg_sem);
0039 }
0040 
0041 static int c_show(struct seq_file *m, void *p)
0042 {
0043     struct crypto_alg *alg = list_entry(p, struct crypto_alg, cra_list);
0044     
0045     seq_printf(m, "name         : %s\n", alg->cra_name);
0046     seq_printf(m, "driver       : %s\n", alg->cra_driver_name);
0047     seq_printf(m, "module       : %s\n", module_name(alg->cra_module));
0048     seq_printf(m, "priority     : %d\n", alg->cra_priority);
0049     seq_printf(m, "refcnt       : %d\n", atomic_read(&alg->cra_refcnt));
0050     seq_printf(m, "selftest     : %s\n",
0051            (alg->cra_flags & CRYPTO_ALG_TESTED) ?
0052            "passed" : "unknown");
0053     seq_printf(m, "internal     : %s\n",
0054            (alg->cra_flags & CRYPTO_ALG_INTERNAL) ?
0055            "yes" : "no");
0056 
0057     if (alg->cra_flags & CRYPTO_ALG_LARVAL) {
0058         seq_printf(m, "type         : larval\n");
0059         seq_printf(m, "flags        : 0x%x\n", alg->cra_flags);
0060         goto out;
0061     }
0062 
0063     if (alg->cra_type && alg->cra_type->show) {
0064         alg->cra_type->show(m, alg);
0065         goto out;
0066     }
0067     
0068     switch (alg->cra_flags & (CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_LARVAL)) {
0069     case CRYPTO_ALG_TYPE_CIPHER:
0070         seq_printf(m, "type         : cipher\n");
0071         seq_printf(m, "blocksize    : %u\n", alg->cra_blocksize);
0072         seq_printf(m, "min keysize  : %u\n",
0073                     alg->cra_cipher.cia_min_keysize);
0074         seq_printf(m, "max keysize  : %u\n",
0075                     alg->cra_cipher.cia_max_keysize);
0076         break;
0077     case CRYPTO_ALG_TYPE_COMPRESS:
0078         seq_printf(m, "type         : compression\n");
0079         break;
0080     default:
0081         seq_printf(m, "type         : unknown\n");
0082         break;
0083     }
0084 
0085 out:
0086     seq_putc(m, '\n');
0087     return 0;
0088 }
0089 
0090 static const struct seq_operations crypto_seq_ops = {
0091     .start      = c_start,
0092     .next       = c_next,
0093     .stop       = c_stop,
0094     .show       = c_show
0095 };
0096 
0097 static int crypto_info_open(struct inode *inode, struct file *file)
0098 {
0099     return seq_open(file, &crypto_seq_ops);
0100 }
0101         
0102 static const struct file_operations proc_crypto_ops = {
0103     .open       = crypto_info_open,
0104     .read       = seq_read,
0105     .llseek     = seq_lseek,
0106     .release    = seq_release
0107 };
0108 
0109 void __init crypto_init_proc(void)
0110 {
0111     proc_create("crypto", 0, NULL, &proc_crypto_ops);
0112 }
0113 
0114 void __exit crypto_exit_proc(void)
0115 {
0116     remove_proc_entry("crypto", NULL);
0117 }