Skip to content

Commit 6721b84

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

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
@@ -14,6 +14,7 @@
1414
#include <crypto/kpp.h>
1515
#include <crypto/ecdh.h>
1616
#include <linux/scatterlist.h>
17+
#include <linux/fips.h>
1718
#include "ecc.h"
1819

1920
struct ecdh_ctx {
@@ -113,6 +114,36 @@ static int ecdh_compute_value(struct kpp_request *req)
113114
ctx->private_key, public_key);
114115
buf = public_key;
115116
nbytes = public_key_sz;
117+
118+
/*
119+
* SP800-56Arev3, 5.6.2.1.4: ("Owner Assurance of
120+
* Pair-wise Consistency"): recompute the public key
121+
* and check if the results match.
122+
*/
123+
if (fips_enabled) {
124+
u64 *public_key_pct;
125+
126+
if (ret < 0)
127+
goto free_all;
128+
129+
public_key_pct = kmalloc(public_key_sz, GFP_KERNEL);
130+
if (!public_key_pct) {
131+
ret = -ENOMEM;
132+
goto free_all;
133+
}
134+
135+
ret = ecc_make_pub_key(ctx->curve_id, ctx->ndigits,
136+
ctx->private_key,
137+
public_key_pct);
138+
if (ret < 0) {
139+
kfree(public_key_pct);
140+
goto free_all;
141+
}
142+
143+
if (memcmp(public_key, public_key_pct, public_key_sz))
144+
panic("ECDH PCT failed in FIPS mode");
145+
kfree(public_key_pct);
146+
}
116147
}
117148

118149
if (ret < 0)

0 commit comments

Comments
 (0)