Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Scatterlist Cryptographic API. |
| 4 | * |
| 5 | * Procfs information. |
| 6 | * |
| 7 | * Copyright (c) 2002 James Morris <jmorris@intercode.com.au> |
Herbert Xu | 5cb1454b | 2005-11-05 16:58:14 +1100 | [diff] [blame] | 8 | * Copyright (c) 2005 Herbert Xu <herbert@gondor.apana.org.au> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | */ |
Herbert Xu | 6521f30 | 2006-08-06 20:28:44 +1000 | [diff] [blame] | 10 | |
Arun Sharma | 60063497 | 2011-07-26 16:09:06 -0700 | [diff] [blame] | 11 | #include <linux/atomic.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <linux/init.h> |
| 13 | #include <linux/crypto.h> |
Paul Gortmaker | 4bb33cc | 2011-05-27 14:41:48 -0400 | [diff] [blame] | 14 | #include <linux/module.h> /* for module_name() */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/rwsem.h> |
| 16 | #include <linux/proc_fs.h> |
| 17 | #include <linux/seq_file.h> |
| 18 | #include "internal.h" |
| 19 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | static void *c_start(struct seq_file *m, loff_t *pos) |
| 21 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | down_read(&crypto_alg_sem); |
Pavel Emelianov | 13d3189 | 2007-07-15 23:39:53 -0700 | [diff] [blame] | 23 | return seq_list_start(&crypto_alg_list, *pos); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | } |
| 25 | |
| 26 | static void *c_next(struct seq_file *m, void *p, loff_t *pos) |
| 27 | { |
Pavel Emelianov | 13d3189 | 2007-07-15 23:39:53 -0700 | [diff] [blame] | 28 | return seq_list_next(p, &crypto_alg_list, pos); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | static void c_stop(struct seq_file *m, void *p) |
| 32 | { |
| 33 | up_read(&crypto_alg_sem); |
| 34 | } |
| 35 | |
| 36 | static int c_show(struct seq_file *m, void *p) |
| 37 | { |
Pavel Emelianov | 13d3189 | 2007-07-15 23:39:53 -0700 | [diff] [blame] | 38 | struct crypto_alg *alg = list_entry(p, struct crypto_alg, cra_list); |
Corentin Labbe | fde2f57 | 2020-09-17 18:59:36 +0000 | [diff] [blame^] | 39 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | seq_printf(m, "name : %s\n", alg->cra_name); |
Herbert Xu | 5cb1454b | 2005-11-05 16:58:14 +1100 | [diff] [blame] | 41 | seq_printf(m, "driver : %s\n", alg->cra_driver_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | seq_printf(m, "module : %s\n", module_name(alg->cra_module)); |
Herbert Xu | 5cb1454b | 2005-11-05 16:58:14 +1100 | [diff] [blame] | 43 | seq_printf(m, "priority : %d\n", alg->cra_priority); |
Eric Biggers | ce8614a | 2017-12-29 10:00:46 -0600 | [diff] [blame] | 44 | seq_printf(m, "refcnt : %u\n", refcount_read(&alg->cra_refcnt)); |
Herbert Xu | 73d3864 | 2008-08-03 21:15:23 +0800 | [diff] [blame] | 45 | seq_printf(m, "selftest : %s\n", |
| 46 | (alg->cra_flags & CRYPTO_ALG_TESTED) ? |
| 47 | "passed" : "unknown"); |
Stephan Mueller | b0cda2b | 2015-03-30 21:57:42 +0200 | [diff] [blame] | 48 | seq_printf(m, "internal : %s\n", |
| 49 | (alg->cra_flags & CRYPTO_ALG_INTERNAL) ? |
| 50 | "yes" : "no"); |
Herbert Xu | 67cd080 | 2008-11-06 14:39:16 +0800 | [diff] [blame] | 51 | |
| 52 | if (alg->cra_flags & CRYPTO_ALG_LARVAL) { |
| 53 | seq_printf(m, "type : larval\n"); |
| 54 | seq_printf(m, "flags : 0x%x\n", alg->cra_flags); |
| 55 | goto out; |
| 56 | } |
| 57 | |
| 58 | if (alg->cra_type && alg->cra_type->show) { |
| 59 | alg->cra_type->show(m, alg); |
| 60 | goto out; |
| 61 | } |
Corentin Labbe | fde2f57 | 2020-09-17 18:59:36 +0000 | [diff] [blame^] | 62 | |
Tianjia Zhang | 7f1cfe4 | 2020-02-05 15:25:23 +0800 | [diff] [blame] | 63 | switch (alg->cra_flags & CRYPTO_ALG_TYPE_MASK) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | case CRYPTO_ALG_TYPE_CIPHER: |
| 65 | seq_printf(m, "type : cipher\n"); |
| 66 | seq_printf(m, "blocksize : %u\n", alg->cra_blocksize); |
| 67 | seq_printf(m, "min keysize : %u\n", |
| 68 | alg->cra_cipher.cia_min_keysize); |
| 69 | seq_printf(m, "max keysize : %u\n", |
| 70 | alg->cra_cipher.cia_max_keysize); |
| 71 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | case CRYPTO_ALG_TYPE_COMPRESS: |
| 73 | seq_printf(m, "type : compression\n"); |
| 74 | break; |
| 75 | default: |
Herbert Xu | 67cd080 | 2008-11-06 14:39:16 +0800 | [diff] [blame] | 76 | seq_printf(m, "type : unknown\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | break; |
| 78 | } |
| 79 | |
Herbert Xu | 67cd080 | 2008-11-06 14:39:16 +0800 | [diff] [blame] | 80 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | seq_putc(m, '\n'); |
| 82 | return 0; |
| 83 | } |
| 84 | |
Jan Engelhardt | 48c8949 | 2008-03-13 19:37:45 +0800 | [diff] [blame] | 85 | static const struct seq_operations crypto_seq_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | .start = c_start, |
| 87 | .next = c_next, |
| 88 | .stop = c_stop, |
| 89 | .show = c_show |
| 90 | }; |
| 91 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | void __init crypto_init_proc(void) |
| 93 | { |
Christoph Hellwig | fddda2b | 2018-04-13 19:44:18 +0200 | [diff] [blame] | 94 | proc_create_seq("crypto", 0, NULL, &crypto_seq_ops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | } |
Herbert Xu | cce9e06 | 2006-08-21 21:08:13 +1000 | [diff] [blame] | 96 | |
| 97 | void __exit crypto_exit_proc(void) |
| 98 | { |
| 99 | remove_proc_entry("crypto", NULL); |
| 100 | } |