0001
0002
0003
0004
0005
0006
0007
0008 #include <linux/export.h>
0009 #include <linux/fips.h>
0010 #include <linux/init.h>
0011 #include <linux/module.h>
0012 #include <linux/kernel.h>
0013 #include <linux/sysctl.h>
0014 #include <linux/notifier.h>
0015 #include <generated/utsrelease.h>
0016
0017 int fips_enabled;
0018 EXPORT_SYMBOL_GPL(fips_enabled);
0019
0020 ATOMIC_NOTIFIER_HEAD(fips_fail_notif_chain);
0021 EXPORT_SYMBOL_GPL(fips_fail_notif_chain);
0022
0023
0024 static int fips_enable(char *str)
0025 {
0026 fips_enabled = !!simple_strtol(str, NULL, 0);
0027 printk(KERN_INFO "fips mode: %s\n",
0028 fips_enabled ? "enabled" : "disabled");
0029 return 1;
0030 }
0031
0032 __setup("fips=", fips_enable);
0033
0034 #define FIPS_MODULE_NAME CONFIG_CRYPTO_FIPS_NAME
0035 #ifdef CONFIG_CRYPTO_FIPS_CUSTOM_VERSION
0036 #define FIPS_MODULE_VERSION CONFIG_CRYPTO_FIPS_VERSION
0037 #else
0038 #define FIPS_MODULE_VERSION UTS_RELEASE
0039 #endif
0040
0041 static char fips_name[] = FIPS_MODULE_NAME;
0042 static char fips_version[] = FIPS_MODULE_VERSION;
0043
0044 static struct ctl_table crypto_sysctl_table[] = {
0045 {
0046 .procname = "fips_enabled",
0047 .data = &fips_enabled,
0048 .maxlen = sizeof(int),
0049 .mode = 0444,
0050 .proc_handler = proc_dointvec
0051 },
0052 {
0053 .procname = "fips_name",
0054 .data = &fips_name,
0055 .maxlen = 64,
0056 .mode = 0444,
0057 .proc_handler = proc_dostring
0058 },
0059 {
0060 .procname = "fips_version",
0061 .data = &fips_version,
0062 .maxlen = 64,
0063 .mode = 0444,
0064 .proc_handler = proc_dostring
0065 },
0066 {}
0067 };
0068
0069 static struct ctl_table crypto_dir_table[] = {
0070 {
0071 .procname = "crypto",
0072 .mode = 0555,
0073 .child = crypto_sysctl_table
0074 },
0075 {}
0076 };
0077
0078 static struct ctl_table_header *crypto_sysctls;
0079
0080 static void crypto_proc_fips_init(void)
0081 {
0082 crypto_sysctls = register_sysctl_table(crypto_dir_table);
0083 }
0084
0085 static void crypto_proc_fips_exit(void)
0086 {
0087 unregister_sysctl_table(crypto_sysctls);
0088 }
0089
0090 void fips_fail_notify(void)
0091 {
0092 if (fips_enabled)
0093 atomic_notifier_call_chain(&fips_fail_notif_chain, 0, NULL);
0094 }
0095 EXPORT_SYMBOL_GPL(fips_fail_notify);
0096
0097 static int __init fips_init(void)
0098 {
0099 crypto_proc_fips_init();
0100 return 0;
0101 }
0102
0103 static void __exit fips_exit(void)
0104 {
0105 crypto_proc_fips_exit();
0106 }
0107
0108 subsys_initcall(fips_init);
0109 module_exit(fips_exit);