linux-secure: Add Pairwise consistency test for ECC keys
Change-Id: If83e9bc50ad41697a8c816641de303d74229ec7d
Signed-off-by: Keerthana K <keerthanak@vmware.com>
Reviewed-on: http://photon-jenkins.eng.vmware.com:8082/c/photon/+/22129
Tested-by: gerrit-photon <photon-checkins@vmware.com>
Reviewed-by: Alexey Makhalov <amakhalov@vmware.com>
Reviewed-on: http://photon-jenkins.eng.vmware.com:8082/c/photon/+/22522
Tested-by: Ajay Kaher <akaher@vmware.com>
| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,145 @@ |
| 0 |
+From 1216f535bb8c385e2ec10ed7e892695cef673438 Mon Sep 17 00:00:00 2001 |
|
| 1 |
+From: Keerthana K <keerthanak@vmware.com> |
|
| 2 |
+Date: Sun, 15 Oct 2023 03:25:33 +0000 |
|
| 3 |
+Subject: [PATCH] ecc: Add pairwise consistency test for every generated ECC |
|
| 4 |
+ keypairs |
|
| 5 |
+ |
|
| 6 |
+Signed-off-by: Keerthana K <keerthanak@vmware.com> |
|
| 7 |
+--- |
|
| 8 |
+ crypto/ecc.c | 113 +++++++++++++++++++++++++++++++++++++++++++++++++++ |
|
| 9 |
+ 1 file changed, 113 insertions(+) |
|
| 10 |
+ |
|
| 11 |
+diff --git a/crypto/ecc.c b/crypto/ecc.c |
|
| 12 |
+index fe3792c41..d2dee9323 100644 |
|
| 13 |
+--- a/crypto/ecc.c |
|
| 14 |
+@@ -1492,6 +1492,117 @@ int ecc_gen_privkey(unsigned int curve_id, unsigned int ndigits, u64 *privkey) |
|
| 15 |
+ return 0; |
|
| 16 |
+ } |
|
| 17 |
+ |
|
| 18 |
++#define ECC_MAX_PRIV_KEY_SZ 8 |
|
| 19 |
++#define ECC_MAX_PUB_KEY_SZ 12 |
|
| 20 |
++#define ECC_P256_SS_SZ 32 |
|
| 21 |
++#define ECC_P384_SS_SZ 48 |
|
| 22 |
++ |
|
| 23 |
++struct static_keypair {
|
|
| 24 |
++ u64 priv_key[ECC_MAX_PRIV_KEY_SZ]; |
|
| 25 |
++ u64 pub_key[ECC_MAX_PUB_KEY_SZ]; |
|
| 26 |
++}; |
|
| 27 |
++ |
|
| 28 |
++static const struct static_keypair ecc_p256 = {
|
|
| 29 |
++ .priv_key = {
|
|
| 30 |
++ 9452439779319861540ULL, |
|
| 31 |
++ 11761858801976435446ULL, |
|
| 32 |
++ 10581797902970445963ULL, |
|
| 33 |
++ 9419536734775104336ULL, |
|
| 34 |
++ 0, 0, 0, 0, |
|
| 35 |
++ }, |
|
| 36 |
++ .pub_key = {
|
|
| 37 |
++ 3547918415549923098ULL, |
|
| 38 |
++ 14179485049500513917ULL, |
|
| 39 |
++ 17671096273477813563ULL, |
|
| 40 |
++ 6890828708320535478ULL, |
|
| 41 |
++ 216030908325808746ULL, |
|
| 42 |
++ 7709452682360784951ULL, |
|
| 43 |
++ 8590731219336823402ULL, |
|
| 44 |
++ 16071639722929465850ULL, |
|
| 45 |
++ 0, 0, 0, 0, |
|
| 46 |
++ }, |
|
| 47 |
++}; |
|
| 48 |
++ |
|
| 49 |
++static const struct static_keypair ecc_p384 = {
|
|
| 50 |
++ .priv_key = {
|
|
| 51 |
++ 14313235887423266569ULL, |
|
| 52 |
++ 9198168633825396889ULL, |
|
| 53 |
++ 1589555625840288886ULL, |
|
| 54 |
++ 6189876718282884870ULL, |
|
| 55 |
++ 17170508223326936035ULL, |
|
| 56 |
++ 10714409278094487103ULL, |
|
| 57 |
++ 0, 0, |
|
| 58 |
++ |
|
| 59 |
++ }, |
|
| 60 |
++ .pub_key = {
|
|
| 61 |
++ 3219089472411039846ULL, |
|
| 62 |
++ 6338061617631358942ULL, |
|
| 63 |
++ 16389706391199467349ULL, |
|
| 64 |
++ 16599922655348274198ULL, |
|
| 65 |
++ 13023764348400057054ULL, |
|
| 66 |
++ 12268192317188507592ULL, |
|
| 67 |
++ 14607969375289705108ULL, |
|
| 68 |
++ 4594462565568104956ULL, |
|
| 69 |
++ 12485352420393681765ULL, |
|
| 70 |
++ 10300752922574070944ULL, |
|
| 71 |
++ 15728762062766055403ULL, |
|
| 72 |
++ 2065027171005275110ULL, |
|
| 73 |
++ }, |
|
| 74 |
++}; |
|
| 75 |
++ |
|
| 76 |
++static int ecc_pct(unsigned int curve_id, unsigned int ndigits, |
|
| 77 |
++ const u64 *private_key, const u64 *public_key) |
|
| 78 |
++{
|
|
| 79 |
++ int ret = 0; |
|
| 80 |
++ u64 *shared_secret_a = NULL; |
|
| 81 |
++ u64 *shared_secret_b = NULL; |
|
| 82 |
++ unsigned short ss_size = 0; |
|
| 83 |
++ const u64* static_priv_key = NULL; |
|
| 84 |
++ const u64* static_pub_key = NULL; |
|
| 85 |
++ |
|
| 86 |
++ if (curve_id == 2) {
|
|
| 87 |
++ ss_size = ECC_P256_SS_SZ; |
|
| 88 |
++ static_priv_key = ecc_p256.priv_key; |
|
| 89 |
++ static_pub_key = ecc_p256.pub_key; |
|
| 90 |
++ } else if (curve_id == 3) {
|
|
| 91 |
++ ss_size = ECC_P384_SS_SZ; |
|
| 92 |
++ static_priv_key = ecc_p384.priv_key; |
|
| 93 |
++ static_pub_key = ecc_p384.pub_key; |
|
| 94 |
++ } |
|
| 95 |
++ |
|
| 96 |
++ shared_secret_a = fcw_kmalloc(ss_size, GFP_KERNEL); |
|
| 97 |
++ if (!shared_secret_a) {
|
|
| 98 |
++ ret = -ENOMEM; |
|
| 99 |
++ goto out; |
|
| 100 |
++ } |
|
| 101 |
++ shared_secret_b = fcw_kmalloc(ss_size, GFP_KERNEL); |
|
| 102 |
++ if (!shared_secret_b) {
|
|
| 103 |
++ ret = -ENOMEM; |
|
| 104 |
++ goto out; |
|
| 105 |
++ } |
|
| 106 |
++ |
|
| 107 |
++ ret = crypto_ecdh_shared_secret(curve_id, ndigits, |
|
| 108 |
++ static_priv_key, public_key, shared_secret_a); |
|
| 109 |
++ if (ret < 0) |
|
| 110 |
++ goto out; |
|
| 111 |
++ ret = crypto_ecdh_shared_secret(curve_id, ndigits, |
|
| 112 |
++ private_key, static_pub_key, shared_secret_b); |
|
| 113 |
++ if (ret < 0) |
|
| 114 |
++ goto out; |
|
| 115 |
++ |
|
| 116 |
++ if (memcmp(shared_secret_a, shared_secret_b, ss_size)) {
|
|
| 117 |
++ fcw_printk("Pairwise Consistency Test for ECC keys failed\n");
|
|
| 118 |
++ ret = -EFAULT; |
|
| 119 |
++ goto out; |
|
| 120 |
++ } |
|
| 121 |
++ fcw_printk("Pairwise Consistency Test for ECC keys passed\n");
|
|
| 122 |
++ |
|
| 123 |
++out: |
|
| 124 |
++ kfree(shared_secret_a); |
|
| 125 |
++ kfree(shared_secret_b); |
|
| 126 |
++ return ret; |
|
| 127 |
++} |
|
| 128 |
++ |
|
| 129 |
+ int ecc_make_pub_key(unsigned int curve_id, unsigned int ndigits, |
|
| 130 |
+ const u64 *private_key, u64 *public_key) |
|
| 131 |
+ {
|
|
| 132 |
+@@ -1524,6 +1635,8 @@ int ecc_make_pub_key(unsigned int curve_id, unsigned int ndigits, |
|
| 133 |
+ ecc_swap_digits(pk->x, public_key, ndigits); |
|
| 134 |
+ ecc_swap_digits(pk->y, &public_key[ndigits], ndigits); |
|
| 135 |
+ |
|
| 136 |
++ ret = ecc_pct(curve_id, ndigits, private_key, public_key); |
|
| 137 |
++ |
|
| 138 |
+ err_free_point: |
|
| 139 |
+ ecc_free_point(pk); |
|
| 140 |
+ out: |
|
| 141 |
+-- |
|
| 142 |
+2.19.0 |
|
| 143 |
+ |
| ... | ... |
@@ -1945,7 +1945,7 @@ index 2e6b280f9..b23d8f1d9 100644 |
| 1945 | 1945 |
static const struct kpp_testvec dh_tv_template[] = {
|
| 1946 | 1946 |
{
|
| 1947 | 1947 |
.secret = |
| 1948 |
-@@ -4399,6 +5958,58 @@ static const struct kpp_testvec ecdh_p384_tv_template[] = {
|
|
| 1948 |
+@@ -4399,6 +5952,52 @@ static const struct kpp_testvec ecdh_p384_tv_template[] = {
|
|
| 1949 | 1949 |
.b_public_size = 96, |
| 1950 | 1950 |
.expected_a_public_size = 96, |
| 1951 | 1951 |
.expected_ss_size = 48 |
| ... | ... |
@@ -1953,19 +1953,13 @@ index 2e6b280f9..b23d8f1d9 100644 |
| 1953 | 1953 |
+ .secret = |
| 1954 | 1954 |
+#ifdef __LITTLE_ENDIAN |
| 1955 | 1955 |
+ "\x02\x00" /* type */ |
| 1956 |
-+ "\x36\x00" /* len */ |
|
| 1957 |
-+ "\x30\x00" /* key_size */ |
|
| 1956 |
++ "\x06\x00" /* len */ |
|
| 1957 |
++ "\x00\x00", /* key_size */ |
|
| 1958 | 1958 |
+#else |
| 1959 | 1959 |
+ "\x00\x02" /* type */ |
| 1960 |
-+ "\x00\x36" /* len */ |
|
| 1961 |
-+ "\x00\x30" /* key_size */ |
|
| 1960 |
++ "\x00\x06" /* len */ |
|
| 1961 |
++ "\x00\x00", /* key_size */ |
|
| 1962 | 1962 |
+#endif |
| 1963 |
-+ "\x09\x9F\x3C\x70\x34\xD4\xA2\xC6" |
|
| 1964 |
-+ "\x99\x88\x4D\x73\xA3\x75\xA6\x7F" |
|
| 1965 |
-+ "\x76\x24\xEF\x7C\x6B\x3C\x0F\x16" |
|
| 1966 |
-+ "\x06\x47\xB6\x74\x14\xDC\xE6\x55" |
|
| 1967 |
-+ "\xE3\x5B\x53\x80\x41\xE6\x49\xEE" |
|
| 1968 |
-+ "\x3F\xAE\xF8\x96\x78\x3A\xB1\x94", |
|
| 1969 | 1963 |
+ .b_secret = |
| 1970 | 1964 |
+#ifdef __LITTLE_ENDIAN |
| 1971 | 1965 |
+ "\x02\x00" /* type */ |
| ... | ... |
@@ -1995,7 +1989,7 @@ index 2e6b280f9..b23d8f1d9 100644 |
| 1995 | 1995 |
+ "\xDD\x5F\x0C\x68\x75\x9D\xD1\xFF" |
| 1996 | 1996 |
+ "\xF8\x3F\xA4\x01\x42\x20\x9D\xFF" |
| 1997 | 1997 |
+ "\x5E\xAA\xD9\x6D\xB9\xE6\x38\x6C", |
| 1998 |
-+ .secret_size = 54, |
|
| 1998 |
++ .secret_size = 6, |
|
| 1999 | 1999 |
+ .b_secret_size = 54, |
| 2000 | 2000 |
+ .b_public_size = 96, |
| 2001 | 2001 |
+ .expected_a_public_size = 96, |
| ... | ... |
@@ -23,7 +23,7 @@ |
| 23 | 23 |
Summary: Kernel |
| 24 | 24 |
Name: linux-esx |
| 25 | 25 |
Version: 6.1.56 |
| 26 |
-Release: 4%{?kat_build:.kat}%{?dist}
|
|
| 26 |
+Release: 5%{?kat_build:.kat}%{?dist}
|
|
| 27 | 27 |
License: GPLv2 |
| 28 | 28 |
URL: http://www.kernel.org |
| 29 | 29 |
Group: System Environment/Kernel |
| ... | ... |
@@ -529,6 +529,8 @@ ln -sf linux-%{uname_r}.cfg /boot/photon.cfg
|
| 529 | 529 |
%{_usrsrc}/linux-headers-%{uname_r}
|
| 530 | 530 |
|
| 531 | 531 |
%changelog |
| 532 |
+* Wed Nov 29 2023 Keerthana K <keerthanak@vmware.com> 6.1.56-5 |
|
| 533 |
+- Modified ecdh-nist-p384 vector to generate ECC keypair |
|
| 532 | 534 |
* Wed Nov 29 2023 Vamsi Krishna Brahmajosyula <vbrahmajosyula@vmware.com> 6.1.56-4 |
| 533 | 535 |
- Upgrade canister to 5.0.0-6.1.56-3 |
| 534 | 536 |
* Wed Nov 29 2023 Srish Srinivasan <ssrish@vmware.com> 6.1.56-3 |
| ... | ... |
@@ -16,7 +16,7 @@ |
| 16 | 16 |
Summary: Kernel |
| 17 | 17 |
Name: linux-rt |
| 18 | 18 |
Version: 6.1.56 |
| 19 |
-Release: 4%{?kat_build:.kat}%{?dist}
|
|
| 19 |
+Release: 5%{?kat_build:.kat}%{?dist}
|
|
| 20 | 20 |
License: GPLv2 |
| 21 | 21 |
URL: http://www.kernel.org |
| 22 | 22 |
Group: System Environment/Kernel |
| ... | ... |
@@ -560,6 +560,8 @@ ln -sf linux-%{uname_r}.cfg /boot/photon.cfg
|
| 560 | 560 |
%{_usrsrc}/linux-headers-%{uname_r}
|
| 561 | 561 |
|
| 562 | 562 |
%changelog |
| 563 |
+* Wed Nov 29 2023 Keerthana K <keerthanak@vmware.com> 6.1.56-5 |
|
| 564 |
+- Modified ecdh-nist-p384 vector to generate ECC keypair |
|
| 563 | 565 |
* Wed Nov 29 2023 Vamsi Krishna Brahmajosyula <vbrahmajosyula@vmware.com> 6.1.56-4 |
| 564 | 566 |
- Upgrade canister to 5.0.0-6.1.56-3 |
| 565 | 567 |
* Wed Nov 29 2023 Srish Srinivasan <ssrish@vmware.com> 6.1.56-3 |
| ... | ... |
@@ -16,7 +16,7 @@ |
| 16 | 16 |
Summary: Kernel |
| 17 | 17 |
Name: linux-secure |
| 18 | 18 |
Version: 6.1.56 |
| 19 |
-Release: 4%{?kat_build:.kat}%{?dist}
|
|
| 19 |
+Release: 5%{?kat_build:.kat}%{?dist}
|
|
| 20 | 20 |
License: GPLv2 |
| 21 | 21 |
URL: http://www.kernel.org |
| 22 | 22 |
Group: System Environment/Kernel |
| ... | ... |
@@ -166,6 +166,7 @@ Patch10006: 0005-Move-__bug_table-section-to-fips_canister_wrapper.patch |
| 166 | 166 |
Patch10007: 0006-crypto-Add-prandom-module_kthread_exit-to-canister-w.patch |
| 167 | 167 |
Patch10008: 0007-crypto-Remove-EXPORT_SYMBOL-EXPORT_SYMBOL_GPL-from-c.patch |
| 168 | 168 |
Patch10009: 0008-Move-kernel-structures-usage.patch |
| 169 |
+Patch10010: 0009-ecc-Add-pairwise-consistency-test-for-every-generate.patch |
|
| 169 | 170 |
%endif |
| 170 | 171 |
|
| 171 | 172 |
BuildArch: x86_64 |
| ... | ... |
@@ -276,7 +277,7 @@ The kernel fips-canister |
| 276 | 276 |
%endif |
| 277 | 277 |
|
| 278 | 278 |
%if 0%{?canister_build}
|
| 279 |
-%autopatch -p1 -m10000 -M10009 |
|
| 279 |
+%autopatch -p1 -m10000 -M10010 |
|
| 280 | 280 |
%endif |
| 281 | 281 |
|
| 282 | 282 |
%ifarch x86_64 |
| ... | ... |
@@ -459,6 +460,9 @@ ln -sf linux-%{uname_r}.cfg /boot/photon.cfg
|
| 459 | 459 |
%endif |
| 460 | 460 |
|
| 461 | 461 |
%changelog |
| 462 |
+* Wed Nov 29 2023 Keerthana K <keerthanak@vmware.com> 6.1.56-5 |
|
| 463 |
+- Add Pairwise Consistency Test for ECC generated keypairs |
|
| 464 |
+- Modified ecdh-nist-p384 vector to generate ECC keypair |
|
| 462 | 465 |
* Wed Nov 29 2023 Vamsi Krishna Brahmajosyula <vbrahmajosyula@vmware.com> 6.1.56-4 |
| 463 | 466 |
- Upgrade canister to 5.0.0-6.1.56-3 |
| 464 | 467 |
* Wed Nov 29 2023 Srish Srinivasan <ssrish@vmware.com> 6.1.56-3 |
| ... | ... |
@@ -27,7 +27,7 @@ |
| 27 | 27 |
Summary: Kernel |
| 28 | 28 |
Name: linux |
| 29 | 29 |
Version: 6.1.56 |
| 30 |
-Release: 5%{?acvp_build:.acvp}%{?kat_build:.kat}%{?dist}
|
|
| 30 |
+Release: 6%{?acvp_build:.acvp}%{?kat_build:.kat}%{?dist}
|
|
| 31 | 31 |
License: GPLv2 |
| 32 | 32 |
URL: http://www.kernel.org/ |
| 33 | 33 |
Group: System Environment/Kernel |
| ... | ... |
@@ -793,6 +793,8 @@ ln -sf linux-%{uname_r}.cfg /boot/photon.cfg
|
| 793 | 793 |
%{_datadir}/bash-completion/completions/bpftool
|
| 794 | 794 |
|
| 795 | 795 |
%changelog |
| 796 |
+* Wed Nov 29 2023 Keerthana K <keerthanak@vmware.com> 6.1.56-6 |
|
| 797 |
+- Modified ecdh-nist-p384 vector to generate ECC keypair |
|
| 796 | 798 |
* Wed Nov 29 2023 Vamsi Krishna Brahmajosyula <vbrahmajosyula@vmware.com> 6.1.56-5 |
| 797 | 799 |
- Upgrade canister to 5.0.0-6.1.56-3 |
| 798 | 800 |
* Wed Nov 29 2023 Srish Srinivasan <ssrish@vmware.com> 6.1.56-4 |