Skip to content

Commit 2ed5ba6

Browse files
smuellerDDherbertx
authored andcommitted
crypto: dh - SP800-56A rev 3 local public key validation
After the generation of a local public key, SP800-56A rev 3 section 5.6.2.1.3 mandates a validation of that key with a full validation compliant to section 5.6.2.3.1. Only if the full validation passes, the key is allowed to be used. Signed-off-by: Stephan Mueller <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent 90fa9ae commit 2ed5ba6

File tree

1 file changed

+34
-25
lines changed

1 file changed

+34
-25
lines changed

crypto/dh.c

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -180,32 +180,41 @@ static int dh_compute_value(struct kpp_request *req)
180180
if (ret)
181181
goto err_free_base;
182182

183-
/* SP800-56A rev3 5.7.1.1 check: Validation of shared secret */
184-
if (fips_enabled && req->src) {
185-
MPI pone;
186-
187-
/* z <= 1 */
188-
if (mpi_cmp_ui(val, 1) < 1) {
189-
ret = -EBADMSG;
190-
goto err_free_base;
191-
}
192-
193-
/* z == p - 1 */
194-
pone = mpi_alloc(0);
195-
196-
if (!pone) {
197-
ret = -ENOMEM;
198-
goto err_free_base;
183+
if (fips_enabled) {
184+
/* SP800-56A rev3 5.7.1.1 check: Validation of shared secret */
185+
if (req->src) {
186+
MPI pone;
187+
188+
/* z <= 1 */
189+
if (mpi_cmp_ui(val, 1) < 1) {
190+
ret = -EBADMSG;
191+
goto err_free_base;
192+
}
193+
194+
/* z == p - 1 */
195+
pone = mpi_alloc(0);
196+
197+
if (!pone) {
198+
ret = -ENOMEM;
199+
goto err_free_base;
200+
}
201+
202+
ret = mpi_sub_ui(pone, ctx->p, 1);
203+
if (!ret && !mpi_cmp(pone, val))
204+
ret = -EBADMSG;
205+
206+
mpi_free(pone);
207+
208+
if (ret)
209+
goto err_free_base;
210+
211+
/* SP800-56A rev 3 5.6.2.1.3 key check */
212+
} else {
213+
if (dh_is_pubkey_valid(ctx, val)) {
214+
ret = -EAGAIN;
215+
goto err_free_val;
216+
}
199217
}
200-
201-
ret = mpi_sub_ui(pone, ctx->p, 1);
202-
if (!ret && !mpi_cmp(pone, val))
203-
ret = -EBADMSG;
204-
205-
mpi_free(pone);
206-
207-
if (ret)
208-
goto err_free_base;
209218
}
210219

211220
ret = mpi_write_to_sgl(val, req->dst, req->dst_len, &sign);

0 commit comments

Comments
 (0)