forked from vmware/photon
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
jitterentropy-3.4.1: Support for sample collection
- Add support for jitterentropy sample collection. Signed-off-by: srinidhira0 <[email protected]> Change-Id: Ia8c1c7b1ede1472894207d2a1091634ff4e00952 Reviewed-on: http://photon-jenkins.eng.vmware.com:8082/c/photon/+/22222 Tested-by: gerrit-photon <[email protected]> Reviewed-on: http://photon-jenkins.eng.vmware.com:8082/c/photon/+/22528 Reviewed-by: Keerthana K <[email protected]> Tested-by: Ajay Kaher <[email protected]>
- Loading branch information
1 parent
605f0ee
commit e9dc55a
Showing
5 changed files
with
185 additions
and
13 deletions.
There are no files selected for viewing
163 changes: 163 additions & 0 deletions
163
SPECS/linux/0012-jitterentropy-Support-for-sample-collection.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
From b0c455ca32e43741df1f110b8cf7142c35e6bd1d Mon Sep 17 00:00:00 2001 | ||
From: srinidhira0 <[email protected]> | ||
Date: Thu, 12 Oct 2023 06:36:46 +0000 | ||
Subject: [PATCH] jitterentropy: Support for sample collection | ||
|
||
- Add support for collecting jitterentropy samples for testing. | ||
|
||
Signed-off-by: srinidhira0 <[email protected]> | ||
--- | ||
crypto/jitterentropy-kcapi.c | 112 ++++++++++++++++++++++++++++++++++ | ||
include/crypto/internal/rng.h | 3 + | ||
2 files changed, 115 insertions(+) | ||
|
||
diff --git a/crypto/jitterentropy-kcapi.c b/crypto/jitterentropy-kcapi.c | ||
index 72065d5c0..451485f75 100644 | ||
--- a/crypto/jitterentropy-kcapi.c | ||
+++ b/crypto/jitterentropy-kcapi.c | ||
@@ -44,11 +44,22 @@ | ||
#include <linux/time.h> | ||
#include <crypto/internal/rng.h> | ||
#include <crypto/internal/hash.h> | ||
+#include <linux/string.h> | ||
+#include <linux/fs.h> | ||
+#include <asm/uaccess.h> | ||
+#include <linux/vmalloc.h> | ||
|
||
#include "jitterentropy-3.4.1/jitterentropy.h" | ||
#include "jitterentropy-3.4.1/jitterentropy-timer.h" | ||
#include "jitterentropy-3.4.1/jitterentropy-sha3.h" | ||
|
||
+#ifndef TOTAL_SAMPLES | ||
+#define TOTAL_SAMPLES 1000000 | ||
+#endif | ||
+ | ||
+#define RESTART_ROUNDS 1 | ||
+#define TOTAL_ROUNDS 1000 | ||
+ | ||
/*************************************************************************** | ||
* Helper function | ||
***************************************************************************/ | ||
@@ -229,6 +240,107 @@ static void __exit jent_mod_exit(void) | ||
crypto_unregister_shashes(algs, ARRAY_SIZE(algs)); | ||
} | ||
|
||
+EXPORT_SYMBOL(jent_entropy_collector_alloc); | ||
+EXPORT_SYMBOL(jent_entropy_collector_free); | ||
+EXPORT_SYMBOL(jent_entropy_init); | ||
+EXPORT_SYMBOL(jent_measure_jitter); | ||
+EXPORT_SYMBOL(jent_health_failure); | ||
+EXPORT_SYMBOL(jent_get_nstime); | ||
+ | ||
+void jitterentropy_kcapi_write_sample_file(const char *sample_file_name, | ||
+ int rounds) | ||
+{ | ||
+ struct file *fp = NULL; | ||
+ char tmp_rdata[53] = {0}; | ||
+ loff_t ppos = 0; | ||
+ int wr_siz = 0; | ||
+ __u64 *duration = NULL; | ||
+ __u64 *duration_min = NULL; | ||
+ __u64 size = 0; | ||
+ | ||
+ unsigned int health_test_result = 0, flags = 0; | ||
+ int ret = 0; | ||
+ | ||
+ struct rand_data *ec = NULL, *ec_min = NULL; | ||
+ | ||
+ flags |= flags; | ||
+ | ||
+ ret = jent_entropy_init(); | ||
+ if (ret) { | ||
+ pr_err("\n Failed to initialize jitterentropy \n"); | ||
+ return; | ||
+ } | ||
+ ec = jent_entropy_collector_alloc(0, flags); | ||
+ if (!ec) { | ||
+ pr_err("Failed to allocate jitter entropy rng for sample\n"); | ||
+ return; | ||
+ } | ||
+ ec_min = jent_entropy_collector_alloc(0, flags); | ||
+ if (!ec_min) { | ||
+ pr_err("Failed to allocate jitter entropy rng for sample\n"); | ||
+ return; | ||
+ } | ||
+ | ||
+ duration = (__u64 *)vzalloc(sizeof(__u64)*rounds); | ||
+ duration_min = (__u64 *)vzalloc(sizeof(__u64)*rounds); | ||
+ if (IS_ERR_OR_NULL(duration) || IS_ERR_OR_NULL(duration_min)) { | ||
+ pr_err("\n Failed to allocate memory for duration\n"); | ||
+ goto out; | ||
+ } | ||
+ /* Prime the test */ | ||
+ jent_measure_jitter(ec, 0, NULL); | ||
+ | ||
+ for (size = 0; size < rounds; size++) { | ||
+ /* Disregard stuck indicator*/ | ||
+ jent_measure_jitter(ec, 0, &duration[size]); | ||
+ } | ||
+ /* Prime the test */ | ||
+ jent_measure_jitter(ec_min, 0, NULL); | ||
+ for (size = 0; size < rounds; size++) { | ||
+ /* Disregard stuck indicator*/ | ||
+ jent_measure_jitter(ec_min, 1, &duration_min[size]); | ||
+ } | ||
+ | ||
+ fp = filp_open(sample_file_name, | ||
+ O_CREAT | O_WRONLY | O_CLOEXEC, S_IRUSR | S_IWUSR); | ||
+ if ( IS_ERR_OR_NULL(fp)) { | ||
+ pr_err("JENT: Failed to open fp for writing\n"); | ||
+ return; | ||
+ } | ||
+ for (size = 0; size < rounds; size++) { | ||
+ memset(tmp_rdata, 0 ,sizeof(tmp_rdata)); | ||
+ wr_siz = snprintf(tmp_rdata, sizeof(tmp_rdata), "%llu %llu", | ||
+ duration[size], duration_min[size]); | ||
+ kernel_write(fp, &tmp_rdata, wr_siz, &ppos); | ||
+ ppos += wr_siz; | ||
+ kernel_write(fp, "\n", sizeof(char), &ppos); | ||
+ ppos++; | ||
+ } | ||
+ if ((health_test_result = jent_health_failure(ec))) { | ||
+ printk(KERN_ERR"\nent collector health test failure(s):\n"); | ||
+ if(health_test_result & JENT_RCT_FAILURE) | ||
+ printk(KERN_CONT" RCT "); | ||
+ if(health_test_result & JENT_APT_FAILURE) | ||
+ printk(KERN_CONT" APT "); | ||
+ if(health_test_result & JENT_LAG_FAILURE) | ||
+ printk(KERN_CONT" Lag "); | ||
+ printk("\n"); | ||
+ } | ||
+ | ||
+out: | ||
+ if (fp) | ||
+ filp_close(fp, NULL); | ||
+ if (ec) | ||
+ jent_entropy_collector_free(ec); | ||
+ if (ec_min) | ||
+ jent_entropy_collector_free(ec_min); | ||
+ if (duration) | ||
+ vfree(duration); | ||
+ if (duration_min) | ||
+ vfree(duration_min); | ||
+} | ||
+EXPORT_SYMBOL(jitterentropy_kcapi_write_sample_file); | ||
+ | ||
/* Must be initialized before tcrypt */ | ||
subsys_initcall(jent_mod_init); | ||
module_exit(jent_mod_exit); | ||
diff --git a/include/crypto/internal/rng.h b/include/crypto/internal/rng.h | ||
index e0711b6a5..74b515e87 100644 | ||
--- a/include/crypto/internal/rng.h | ||
+++ b/include/crypto/internal/rng.h | ||
@@ -37,4 +37,7 @@ static inline void crypto_rng_set_entropy(struct crypto_rng *tfm, | ||
crypto_rng_alg(tfm)->set_ent(tfm, data, len); | ||
} | ||
|
||
+void jitterentropy_kcapi_write_sample_file(const char *sample_file_name, | ||
+ int rounds); | ||
+ | ||
#endif | ||
-- | ||
2.23.3 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,7 @@ | |
Summary: Kernel | ||
Name: linux-esx | ||
Version: 6.1.60 | ||
Release: 1%{?kat_build:.kat}%{?dist} | ||
Release: 2%{?kat_build:.kat}%{?dist} | ||
License: GPLv2 | ||
URL: http://www.kernel.org | ||
Group: System Environment/Kernel | ||
|
@@ -78,9 +78,9 @@ Source20: %{name}-dracut.conf | |
Source25: linux-sbat.csv.in | ||
|
||
%define jent_major_version 3.4.1 | ||
%define jent_ph_version 3 | ||
%define jent_ph_version 4 | ||
Source32: jitterentropy-%{jent_major_version}-%{jent_ph_version}.tar.bz2 | ||
%define sha512 jitterentropy=b5aa389d331e0a8b22e696e83cccaddb17f98da06fe9592e75cd7efb24877e1cb65b24c2f909e82d247e0dcbb77043b0235f8df94d40d6cb4c4f9a7c113b4f18 | ||
%define sha512 jitterentropy=37a9380b14d5e56eb3a16b8e46649bc5182813aadb5ec627c31910e4cc622269dfd29359789cb4c13112182f4f8d3c084a6b9c576df06dae9689da44e4735dd2 | ||
Source33: jitterentropy_canister_wrapper.c | ||
Source34: jitterentropy_canister_wrapper.h | ||
Source35: jitterentropy_canister_wrapper_asm.S | ||
|
@@ -558,6 +558,8 @@ ln -sf linux-%{uname_r}.cfg /boot/photon.cfg | |
%{_usrsrc}/linux-headers-%{uname_r} | ||
|
||
%changelog | ||
* Wed Nov 29 2023 Srinidhi Rao <[email protected]> 6.1.60-2 | ||
- Jitterentropy sample collection support in ACVP Build. | ||
* Wed Nov 29 2023 Vamsi Krishna Brahmajosyula <[email protected]> 6.1.60-1 | ||
- Upgrade to 6.1.60 | ||
* Wed Nov 29 2023 Alexey Makhalov <[email protected]> 6.1.56-9 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ | |
Summary: Kernel | ||
Name: linux-rt | ||
Version: 6.1.60 | ||
Release: 1%{?kat_build:.kat}%{?dist} | ||
Release: 2%{?kat_build:.kat}%{?dist} | ||
License: GPLv2 | ||
URL: http://www.kernel.org | ||
Group: System Environment/Kernel | ||
|
@@ -76,9 +76,9 @@ Source21: photon_sb2020.pem | |
Source25: linux-sbat.csv.in | ||
|
||
%define jent_major_version 3.4.1 | ||
%define jent_ph_version 3 | ||
%define jent_ph_version 4 | ||
Source32: jitterentropy-%{jent_major_version}-%{jent_ph_version}.tar.bz2 | ||
%define sha512 jitterentropy=b5aa389d331e0a8b22e696e83cccaddb17f98da06fe9592e75cd7efb24877e1cb65b24c2f909e82d247e0dcbb77043b0235f8df94d40d6cb4c4f9a7c113b4f18 | ||
%define sha512 jitterentropy=37a9380b14d5e56eb3a16b8e46649bc5182813aadb5ec627c31910e4cc622269dfd29359789cb4c13112182f4f8d3c084a6b9c576df06dae9689da44e4735dd2 | ||
Source33: jitterentropy_canister_wrapper.c | ||
Source34: jitterentropy_canister_wrapper.h | ||
Source35: jitterentropy_canister_wrapper_asm.S | ||
|
@@ -573,6 +573,8 @@ ln -sf linux-%{uname_r}.cfg /boot/photon.cfg | |
%{_usrsrc}/linux-headers-%{uname_r} | ||
|
||
%changelog | ||
* Wed Nov 29 2023 Srinidhi Rao <[email protected]> 6.1.60-2 | ||
- Jitterentropy sample collection support in ACVP Build. | ||
* Wed Nov 29 2023 Vamsi Krishna Brahmajosyula <[email protected]> 6.1.60-1 | ||
- Upgrade to 6.1.60 | ||
* Wed Nov 29 2023 Alexey Makhalov <[email protected]> 6.1.56-8 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ | |
Summary: Kernel | ||
Name: linux-secure | ||
Version: 6.1.60 | ||
Release: 1%{?kat_build:.kat}%{?dist} | ||
Release: 2%{?kat_build:.kat}%{?dist} | ||
License: GPLv2 | ||
URL: http://www.kernel.org | ||
Group: System Environment/Kernel | ||
|
@@ -71,9 +71,9 @@ Source31: photon_sb2020.pem | |
|
||
%ifarch x86_64 | ||
%define jent_major_version 3.4.1 | ||
%define jent_ph_version 3 | ||
%define jent_ph_version 4 | ||
Source32: jitterentropy-%{jent_major_version}-%{jent_ph_version}.tar.bz2 | ||
%define sha512 jitterentropy=b5aa389d331e0a8b22e696e83cccaddb17f98da06fe9592e75cd7efb24877e1cb65b24c2f909e82d247e0dcbb77043b0235f8df94d40d6cb4c4f9a7c113b4f18 | ||
%define sha512 jitterentropy=37a9380b14d5e56eb3a16b8e46649bc5182813aadb5ec627c31910e4cc622269dfd29359789cb4c13112182f4f8d3c084a6b9c576df06dae9689da44e4735dd2 | ||
Source33: jitterentropy_canister_wrapper.c | ||
Source34: jitterentropy_canister_wrapper.h | ||
Source35: jitterentropy_canister_wrapper_asm.S | ||
|
@@ -477,6 +477,8 @@ ln -sf linux-%{uname_r}.cfg /boot/photon.cfg | |
%endif | ||
|
||
%changelog | ||
* Wed Nov 29 2023 Srinidhi Rao <[email protected]> 6.1.60-2 | ||
- Jitterentropy sample collection support in ACVP Build. | ||
* Wed Nov 29 2023 Vamsi Krishna Brahmajosyula <[email protected]> 6.1.60-1 | ||
- Upgrade to 6.1.60 | ||
* Wed Nov 29 2023 Alexey Makhalov <[email protected]> 6.1.56-8 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,7 +30,7 @@ | |
Summary: Kernel | ||
Name: linux | ||
Version: 6.1.60 | ||
Release: 1%{?acvp_build:.acvp}%{?kat_build:.kat}%{?dist} | ||
Release: 2%{?acvp_build:.acvp}%{?kat_build:.kat}%{?dist} | ||
License: GPLv2 | ||
URL: http://www.kernel.org/ | ||
Group: System Environment/Kernel | ||
|
@@ -89,9 +89,9 @@ Source20: photon_sb2020.pem | |
Source25: linux-sbat.csv.in | ||
|
||
%define jent_major_version 3.4.1 | ||
%define jent_ph_version 3 | ||
%define jent_ph_version 4 | ||
Source32: jitterentropy-%{jent_major_version}-%{jent_ph_version}.tar.bz2 | ||
%define sha512 jitterentropy=b5aa389d331e0a8b22e696e83cccaddb17f98da06fe9592e75cd7efb24877e1cb65b24c2f909e82d247e0dcbb77043b0235f8df94d40d6cb4c4f9a7c113b4f18 | ||
%define sha512 jitterentropy=37a9380b14d5e56eb3a16b8e46649bc5182813aadb5ec627c31910e4cc622269dfd29359789cb4c13112182f4f8d3c084a6b9c576df06dae9689da44e4735dd2 | ||
Source33: jitterentropy_canister_wrapper.c | ||
Source34: jitterentropy_canister_wrapper.h | ||
Source35: jitterentropy_canister_wrapper_asm.S | ||
|
@@ -243,6 +243,7 @@ Patch519: 0008-crypto-AF_ALG-add-ECC-support.patch | |
Patch520: 0009-kernels-net-Export-sock_getsockopt.patch | ||
Patch521: 0010-DRBG-Fix-issues-with-DRBG.patch | ||
Patch522: 0011-Added-jitterentropy-implementation-of-SHA3-256.patch | ||
Patch523: 0012-jitterentropy-Support-for-sample-collection.patch | ||
%endif | ||
|
||
%ifarch x86_64 | ||
|
@@ -436,7 +437,7 @@ manipulation of eBPF programs and maps. | |
%if 0%{?acvp_build:1} | ||
#ACVP test harness patches. | ||
#Need to be applied on top of FIPS canister usage patch to avoid HUNK failure | ||
%autopatch -p1 -m512 -M522 | ||
%autopatch -p1 -m512 -M523 | ||
%endif | ||
|
||
%ifarch x86_64 | ||
|
@@ -808,6 +809,8 @@ ln -sf linux-%{uname_r}.cfg /boot/photon.cfg | |
%{_datadir}/bash-completion/completions/bpftool | ||
|
||
%changelog | ||
* Wed Nov 29 2023 Srinidhi Rao <[email protected]> 6.1.60-2 | ||
- Jitterentropy sample collection support in ACVP Build. | ||
* Wed Nov 29 2023 Vamsi Krishna Brahmajosyula <[email protected]> 6.1.60-1 | ||
- Upgrade to 6.1.60 | ||
* Wed Nov 29 2023 Alexey Makhalov <[email protected]> 6.1.56-9 | ||
|