Skip to content

Commit 1884c19

Browse files
jallisonciqPlaidCat
authored andcommitted
SUSE: patch: crypto-ecdh-implement-FIPS-PCT.patch
Signed-off-by: Jeremy Allison <jallison@ciq.com>
1 parent f8b1d05 commit 1884c19

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

crypto/ecdh.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <crypto/kpp.h>
1111
#include <crypto/ecdh.h>
1212
#include <linux/scatterlist.h>
13+
#include <linux/fips.h>
1314
#include "ecc.h"
1415

1516
struct ecdh_ctx {
@@ -94,6 +95,36 @@ static int ecdh_compute_value(struct kpp_request *req)
9495
ctx->private_key, public_key);
9596
buf = public_key;
9697
nbytes = public_key_sz;
98+
99+
/*
100+
* SP800-56Arev3, 5.6.2.1.4: ("Owner Assurance of
101+
* Pair-wise Consistency"): recompute the public key
102+
* and check if the results match.
103+
*/
104+
if (fips_enabled) {
105+
u64 *public_key_pct;
106+
107+
if (ret < 0)
108+
goto free_all;
109+
110+
public_key_pct = kmalloc(public_key_sz, GFP_KERNEL);
111+
if (!public_key_pct) {
112+
ret = -ENOMEM;
113+
goto free_all;
114+
}
115+
116+
ret = ecc_make_pub_key(ctx->curve_id, ctx->ndigits,
117+
ctx->private_key,
118+
public_key_pct);
119+
if (ret < 0) {
120+
kfree(public_key_pct);
121+
goto free_all;
122+
}
123+
124+
if (memcmp(public_key, public_key_pct, public_key_sz))
125+
panic("ECDH PCT failed in FIPS mode");
126+
kfree(public_key_pct);
127+
}
97128
}
98129

99130
if (ret < 0)

0 commit comments

Comments
 (0)