File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change 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
1516struct 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 )
You can’t perform that action at this time.
0 commit comments