11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * Scatterlist Cryptographic API. 31da177e4SLinus Torvalds * 41da177e4SLinus Torvalds * Procfs information. 51da177e4SLinus Torvalds * 61da177e4SLinus Torvalds * Copyright (c) 2002 James Morris <jmorris@intercode.com.au> 75cb1454bSHerbert Xu * Copyright (c) 2005 Herbert Xu <herbert@gondor.apana.org.au> 81da177e4SLinus Torvalds * 91da177e4SLinus Torvalds * This program is free software; you can redistribute it and/or modify it 101da177e4SLinus Torvalds * under the terms of the GNU General Public License as published by the Free 111da177e4SLinus Torvalds * Software Foundation; either version 2 of the License, or (at your option) 121da177e4SLinus Torvalds * any later version. 131da177e4SLinus Torvalds * 141da177e4SLinus Torvalds */ 156521f302SHerbert Xu 1660063497SArun Sharma #include <linux/atomic.h> 171da177e4SLinus Torvalds #include <linux/init.h> 181da177e4SLinus Torvalds #include <linux/crypto.h> 194bb33cc8SPaul Gortmaker #include <linux/module.h> /* for module_name() */ 201da177e4SLinus Torvalds #include <linux/rwsem.h> 211da177e4SLinus Torvalds #include <linux/proc_fs.h> 221da177e4SLinus Torvalds #include <linux/seq_file.h> 231da177e4SLinus Torvalds #include "internal.h" 241da177e4SLinus Torvalds 251da177e4SLinus Torvalds static void *c_start(struct seq_file *m, loff_t *pos) 261da177e4SLinus Torvalds { 271da177e4SLinus Torvalds down_read(&crypto_alg_sem); 2813d31894SPavel Emelianov return seq_list_start(&crypto_alg_list, *pos); 291da177e4SLinus Torvalds } 301da177e4SLinus Torvalds 311da177e4SLinus Torvalds static void *c_next(struct seq_file *m, void *p, loff_t *pos) 321da177e4SLinus Torvalds { 3313d31894SPavel Emelianov return seq_list_next(p, &crypto_alg_list, pos); 341da177e4SLinus Torvalds } 351da177e4SLinus Torvalds 361da177e4SLinus Torvalds static void c_stop(struct seq_file *m, void *p) 371da177e4SLinus Torvalds { 381da177e4SLinus Torvalds up_read(&crypto_alg_sem); 391da177e4SLinus Torvalds } 401da177e4SLinus Torvalds 411da177e4SLinus Torvalds static int c_show(struct seq_file *m, void *p) 421da177e4SLinus Torvalds { 4313d31894SPavel Emelianov struct crypto_alg *alg = list_entry(p, struct crypto_alg, cra_list); 441da177e4SLinus Torvalds 451da177e4SLinus Torvalds seq_printf(m, "name : %s\n", alg->cra_name); 465cb1454bSHerbert Xu seq_printf(m, "driver : %s\n", alg->cra_driver_name); 471da177e4SLinus Torvalds seq_printf(m, "module : %s\n", module_name(alg->cra_module)); 485cb1454bSHerbert Xu seq_printf(m, "priority : %d\n", alg->cra_priority); 49*ce8614a3SEric Biggers seq_printf(m, "refcnt : %u\n", refcount_read(&alg->cra_refcnt)); 5073d3864aSHerbert Xu seq_printf(m, "selftest : %s\n", 5173d3864aSHerbert Xu (alg->cra_flags & CRYPTO_ALG_TESTED) ? 5273d3864aSHerbert Xu "passed" : "unknown"); 53b0cda2baSStephan Mueller seq_printf(m, "internal : %s\n", 54b0cda2baSStephan Mueller (alg->cra_flags & CRYPTO_ALG_INTERNAL) ? 55b0cda2baSStephan Mueller "yes" : "no"); 561da177e4SLinus Torvalds 5767cd080cSHerbert Xu if (alg->cra_flags & CRYPTO_ALG_LARVAL) { 5867cd080cSHerbert Xu seq_printf(m, "type : larval\n"); 5967cd080cSHerbert Xu seq_printf(m, "flags : 0x%x\n", alg->cra_flags); 6067cd080cSHerbert Xu goto out; 6167cd080cSHerbert Xu } 6267cd080cSHerbert Xu 6367cd080cSHerbert Xu if (alg->cra_type && alg->cra_type->show) { 6467cd080cSHerbert Xu alg->cra_type->show(m, alg); 6567cd080cSHerbert Xu goto out; 6667cd080cSHerbert Xu } 6767cd080cSHerbert Xu 68a7581a01SHerbert Xu switch (alg->cra_flags & (CRYPTO_ALG_TYPE_MASK | CRYPTO_ALG_LARVAL)) { 691da177e4SLinus Torvalds case CRYPTO_ALG_TYPE_CIPHER: 701da177e4SLinus Torvalds seq_printf(m, "type : cipher\n"); 711da177e4SLinus Torvalds seq_printf(m, "blocksize : %u\n", alg->cra_blocksize); 721da177e4SLinus Torvalds seq_printf(m, "min keysize : %u\n", 731da177e4SLinus Torvalds alg->cra_cipher.cia_min_keysize); 741da177e4SLinus Torvalds seq_printf(m, "max keysize : %u\n", 751da177e4SLinus Torvalds alg->cra_cipher.cia_max_keysize); 761da177e4SLinus Torvalds break; 771da177e4SLinus Torvalds case CRYPTO_ALG_TYPE_COMPRESS: 781da177e4SLinus Torvalds seq_printf(m, "type : compression\n"); 791da177e4SLinus Torvalds break; 801da177e4SLinus Torvalds default: 811da177e4SLinus Torvalds seq_printf(m, "type : unknown\n"); 821da177e4SLinus Torvalds break; 831da177e4SLinus Torvalds } 841da177e4SLinus Torvalds 8567cd080cSHerbert Xu out: 861da177e4SLinus Torvalds seq_putc(m, '\n'); 871da177e4SLinus Torvalds return 0; 881da177e4SLinus Torvalds } 891da177e4SLinus Torvalds 9048c8949eSJan Engelhardt static const struct seq_operations crypto_seq_ops = { 911da177e4SLinus Torvalds .start = c_start, 921da177e4SLinus Torvalds .next = c_next, 931da177e4SLinus Torvalds .stop = c_stop, 941da177e4SLinus Torvalds .show = c_show 951da177e4SLinus Torvalds }; 961da177e4SLinus Torvalds 971da177e4SLinus Torvalds static int crypto_info_open(struct inode *inode, struct file *file) 981da177e4SLinus Torvalds { 991da177e4SLinus Torvalds return seq_open(file, &crypto_seq_ops); 1001da177e4SLinus Torvalds } 1011da177e4SLinus Torvalds 1022b8693c0SArjan van de Ven static const struct file_operations proc_crypto_ops = { 1031da177e4SLinus Torvalds .open = crypto_info_open, 1041da177e4SLinus Torvalds .read = seq_read, 1051da177e4SLinus Torvalds .llseek = seq_lseek, 1061da177e4SLinus Torvalds .release = seq_release 1071da177e4SLinus Torvalds }; 1081da177e4SLinus Torvalds 1091da177e4SLinus Torvalds void __init crypto_init_proc(void) 1101da177e4SLinus Torvalds { 111607424d8SAlexey Dobriyan proc_create("crypto", 0, NULL, &proc_crypto_ops); 1121da177e4SLinus Torvalds } 113cce9e06dSHerbert Xu 114cce9e06dSHerbert Xu void __exit crypto_exit_proc(void) 115cce9e06dSHerbert Xu { 116cce9e06dSHerbert Xu remove_proc_entry("crypto", NULL); 117cce9e06dSHerbert Xu } 118