Linux Audio

Check our new training course

Loading...
v6.13.7
 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
68static struct ctl_table_header *crypto_sysctls;
69
70static void crypto_proc_fips_init(void)
71{
72	crypto_sysctls = register_sysctl("crypto", crypto_sysctl_table);
73}
74
75static void crypto_proc_fips_exit(void)
76{
77	unregister_sysctl_table(crypto_sysctls);
78}
79
80void fips_fail_notify(void)
81{
82	if (fips_enabled)
83		atomic_notifier_call_chain(&fips_fail_notif_chain, 0, NULL);
84}
85EXPORT_SYMBOL_GPL(fips_fail_notify);
86
87static int __init fips_init(void)
88{
89	crypto_proc_fips_init();
90	return 0;
91}
92
93static void __exit fips_exit(void)
94{
95	crypto_proc_fips_exit();
96}
97
98subsys_initcall(fips_init);
99module_exit(fips_exit);
v4.17
 
 1/*
 2 * FIPS 200 support.
 3 *
 4 * Copyright (c) 2008 Neil Horman <nhorman@tuxdriver.com>
 5 *
 6 * This program is free software; you can redistribute it and/or modify it
 7 * under the terms of the GNU General Public License as published by the Free
 8 * Software Foundation; either version 2 of the License, or (at your option)
 9 * any later version.
10 *
11 */
12
13#include <linux/export.h>
14#include <linux/fips.h>
15#include <linux/init.h>
16#include <linux/module.h>
17#include <linux/kernel.h>
18#include <linux/sysctl.h>
 
 
19
20int fips_enabled;
21EXPORT_SYMBOL_GPL(fips_enabled);
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
 
 
 
 
 
 
 
 
 
 
34static struct ctl_table crypto_sysctl_table[] = {
35	{
36		.procname       = "fips_enabled",
37		.data           = &fips_enabled,
38		.maxlen         = sizeof(int),
39		.mode           = 0444,
40		.proc_handler   = proc_dointvec
 
 
 
 
 
 
 
41	},
42	{}
43};
44
45static struct ctl_table crypto_dir_table[] = {
46	{
47		.procname       = "crypto",
48		.mode           = 0555,
49		.child          = crypto_sysctl_table
 
 
50	},
51	{}
52};
53
54static struct ctl_table_header *crypto_sysctls;
55
56static void crypto_proc_fips_init(void)
57{
58	crypto_sysctls = register_sysctl_table(crypto_dir_table);
59}
60
61static void crypto_proc_fips_exit(void)
62{
63	unregister_sysctl_table(crypto_sysctls);
64}
65
 
 
 
 
 
 
 
66static int __init fips_init(void)
67{
68	crypto_proc_fips_init();
69	return 0;
70}
71
72static void __exit fips_exit(void)
73{
74	crypto_proc_fips_exit();
75}
76
77module_init(fips_init);
78module_exit(fips_exit);