Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Neil Horman | ccb778e | 2008-08-05 14:13:08 +0800 | [diff] [blame] | 2 | /* |
| 3 | * FIPS 200 support. |
| 4 | * |
| 5 | * Copyright (c) 2008 Neil Horman <nhorman@tuxdriver.com> |
Neil Horman | ccb778e | 2008-08-05 14:13:08 +0800 | [diff] [blame] | 6 | */ |
| 7 | |
Herbert Xu | 76450f9 | 2015-04-22 13:25:54 +0800 | [diff] [blame] | 8 | #include <linux/export.h> |
| 9 | #include <linux/fips.h> |
| 10 | #include <linux/init.h> |
Herbert Xu | 94072cb | 2015-04-22 13:25:56 +0800 | [diff] [blame] | 11 | #include <linux/module.h> |
Herbert Xu | 76450f9 | 2015-04-22 13:25:54 +0800 | [diff] [blame] | 12 | #include <linux/kernel.h> |
Herbert Xu | 94072cb | 2015-04-22 13:25:56 +0800 | [diff] [blame] | 13 | #include <linux/sysctl.h> |
Neil Horman | ccb778e | 2008-08-05 14:13:08 +0800 | [diff] [blame] | 14 | |
| 15 | int fips_enabled; |
| 16 | EXPORT_SYMBOL_GPL(fips_enabled); |
| 17 | |
| 18 | /* Process kernel command-line parameter at boot time. fips=0 or fips=1 */ |
| 19 | static int fips_enable(char *str) |
| 20 | { |
| 21 | fips_enabled = !!simple_strtol(str, NULL, 0); |
| 22 | printk(KERN_INFO "fips mode: %s\n", |
| 23 | fips_enabled ? "enabled" : "disabled"); |
| 24 | return 1; |
| 25 | } |
| 26 | |
| 27 | __setup("fips=", fips_enable); |
Herbert Xu | 94072cb | 2015-04-22 13:25:56 +0800 | [diff] [blame] | 28 | |
| 29 | static struct ctl_table crypto_sysctl_table[] = { |
| 30 | { |
| 31 | .procname = "fips_enabled", |
| 32 | .data = &fips_enabled, |
| 33 | .maxlen = sizeof(int), |
| 34 | .mode = 0444, |
| 35 | .proc_handler = proc_dointvec |
| 36 | }, |
| 37 | {} |
| 38 | }; |
| 39 | |
| 40 | static struct ctl_table crypto_dir_table[] = { |
| 41 | { |
| 42 | .procname = "crypto", |
| 43 | .mode = 0555, |
| 44 | .child = crypto_sysctl_table |
| 45 | }, |
| 46 | {} |
| 47 | }; |
| 48 | |
| 49 | static struct ctl_table_header *crypto_sysctls; |
| 50 | |
| 51 | static void crypto_proc_fips_init(void) |
| 52 | { |
| 53 | crypto_sysctls = register_sysctl_table(crypto_dir_table); |
| 54 | } |
| 55 | |
| 56 | static void crypto_proc_fips_exit(void) |
| 57 | { |
| 58 | unregister_sysctl_table(crypto_sysctls); |
| 59 | } |
| 60 | |
| 61 | static int __init fips_init(void) |
| 62 | { |
| 63 | crypto_proc_fips_init(); |
| 64 | return 0; |
| 65 | } |
| 66 | |
| 67 | static void __exit fips_exit(void) |
| 68 | { |
| 69 | crypto_proc_fips_exit(); |
| 70 | } |
| 71 | |
Eric Biggers | c4741b2 | 2019-04-11 21:57:42 -0700 | [diff] [blame] | 72 | subsys_initcall(fips_init); |
Herbert Xu | 94072cb | 2015-04-22 13:25:56 +0800 | [diff] [blame] | 73 | module_exit(fips_exit); |