Linux Audio

Check our new training course

Loading...
v5.4
 1// SPDX-License-Identifier: GPL-2.0-or-later
 2/*
 3 * FIPS 200 support.
 4 *
 5 * Copyright (c) 2008 Neil Horman <nhorman@tuxdriver.com>
 6 */
 7
 8#include <linux/export.h>
 9#include <linux/fips.h>
10#include <linux/init.h>
11#include <linux/module.h>
12#include <linux/kernel.h>
13#include <linux/sysctl.h>
14#include <linux/notifier.h>
 
15
16int fips_enabled;
17EXPORT_SYMBOL_GPL(fips_enabled);
18
19ATOMIC_NOTIFIER_HEAD(fips_fail_notif_chain);
20EXPORT_SYMBOL_GPL(fips_fail_notif_chain);
21
22/* Process kernel command-line parameter at boot time. fips=0 or fips=1 */
23static int fips_enable(char *str)
24{
25	fips_enabled = !!simple_strtol(str, NULL, 0);
26	printk(KERN_INFO "fips mode: %s\n",
27		fips_enabled ? "enabled" : "disabled");
28	return 1;
29}
30
31__setup("fips=", fips_enable);
32
 
 
 
 
 
 
 
 
 
 
33static struct ctl_table crypto_sysctl_table[] = {
34	{
35		.procname       = "fips_enabled",
36		.data           = &fips_enabled,
37		.maxlen         = sizeof(int),
38		.mode           = 0444,
39		.proc_handler   = proc_dointvec
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40	},
41	{}
42};
43
44static struct ctl_table crypto_dir_table[] = {
45	{
46		.procname       = "crypto",
47		.mode           = 0555,
48		.child          = crypto_sysctl_table
49	},
50	{}
51};
52
53static struct ctl_table_header *crypto_sysctls;
54
55static void crypto_proc_fips_init(void)
56{
57	crypto_sysctls = register_sysctl_table(crypto_dir_table);
58}
59
60static void crypto_proc_fips_exit(void)
61{
62	unregister_sysctl_table(crypto_sysctls);
63}
64
65void fips_fail_notify(void)
66{
67	if (fips_enabled)
68		atomic_notifier_call_chain(&fips_fail_notif_chain, 0, NULL);
69}
70EXPORT_SYMBOL_GPL(fips_fail_notify);
71
72static int __init fips_init(void)
73{
74	crypto_proc_fips_init();
75	return 0;
76}
77
78static void __exit fips_exit(void)
79{
80	crypto_proc_fips_exit();
81}
82
83subsys_initcall(fips_init);
84module_exit(fips_exit);
v6.2
  1// SPDX-License-Identifier: GPL-2.0-or-later
  2/*
  3 * FIPS 200 support.
  4 *
  5 * Copyright (c) 2008 Neil Horman <nhorman@tuxdriver.com>
  6 */
  7
  8#include <linux/export.h>
  9#include <linux/fips.h>
 10#include <linux/init.h>
 11#include <linux/module.h>
 12#include <linux/kernel.h>
 13#include <linux/sysctl.h>
 14#include <linux/notifier.h>
 15#include <generated/utsrelease.h>
 16
 17int fips_enabled;
 18EXPORT_SYMBOL_GPL(fips_enabled);
 19
 20ATOMIC_NOTIFIER_HEAD(fips_fail_notif_chain);
 21EXPORT_SYMBOL_GPL(fips_fail_notif_chain);
 22
 23/* Process kernel command-line parameter at boot time. fips=0 or fips=1 */
 24static int fips_enable(char *str)
 25{
 26	fips_enabled = !!simple_strtol(str, NULL, 0);
 27	printk(KERN_INFO "fips mode: %s\n",
 28		fips_enabled ? "enabled" : "disabled");
 29	return 1;
 30}
 31
 32__setup("fips=", fips_enable);
 33
 34#define FIPS_MODULE_NAME CONFIG_CRYPTO_FIPS_NAME
 35#ifdef CONFIG_CRYPTO_FIPS_CUSTOM_VERSION
 36#define FIPS_MODULE_VERSION CONFIG_CRYPTO_FIPS_VERSION
 37#else
 38#define FIPS_MODULE_VERSION UTS_RELEASE
 39#endif
 40
 41static char fips_name[] = FIPS_MODULE_NAME;
 42static char fips_version[] = FIPS_MODULE_VERSION;
 43
 44static struct ctl_table crypto_sysctl_table[] = {
 45	{
 46		.procname	= "fips_enabled",
 47		.data		= &fips_enabled,
 48		.maxlen		= sizeof(int),
 49		.mode		= 0444,
 50		.proc_handler	= proc_dointvec
 51	},
 52	{
 53		.procname	= "fips_name",
 54		.data		= &fips_name,
 55		.maxlen		= 64,
 56		.mode		= 0444,
 57		.proc_handler	= proc_dostring
 58	},
 59	{
 60		.procname	= "fips_version",
 61		.data		= &fips_version,
 62		.maxlen		= 64,
 63		.mode		= 0444,
 64		.proc_handler	= proc_dostring
 65	},
 66	{}
 67};
 68
 69static struct ctl_table crypto_dir_table[] = {
 70	{
 71		.procname       = "crypto",
 72		.mode           = 0555,
 73		.child          = crypto_sysctl_table
 74	},
 75	{}
 76};
 77
 78static struct ctl_table_header *crypto_sysctls;
 79
 80static void crypto_proc_fips_init(void)
 81{
 82	crypto_sysctls = register_sysctl_table(crypto_dir_table);
 83}
 84
 85static void crypto_proc_fips_exit(void)
 86{
 87	unregister_sysctl_table(crypto_sysctls);
 88}
 89
 90void fips_fail_notify(void)
 91{
 92	if (fips_enabled)
 93		atomic_notifier_call_chain(&fips_fail_notif_chain, 0, NULL);
 94}
 95EXPORT_SYMBOL_GPL(fips_fail_notify);
 96
 97static int __init fips_init(void)
 98{
 99	crypto_proc_fips_init();
100	return 0;
101}
102
103static void __exit fips_exit(void)
104{
105	crypto_proc_fips_exit();
106}
107
108subsys_initcall(fips_init);
109module_exit(fips_exit);