aboutsummaryrefslogtreecommitdiffstats
path: root/crypto
diff options
context:
space:
mode:
authorStephan Müller <smueller@chronox.de>2020-07-20 19:08:52 +0200
committerHerbert Xu <herbert@gondor.apana.org.au>2020-07-31 18:08:59 +1000
commit2ed5ba61cc78f102656eedc0b4c80fd14a5e8c7c (patch)
tree9f182b5842efb5e15a8c0b1669b2a75918333d55 /crypto
parentcrypto: dh - check validity of Z before export (diff)
downloadlinux-dev-2ed5ba61cc78f102656eedc0b4c80fd14a5e8c7c.tar.xz
linux-dev-2ed5ba61cc78f102656eedc0b4c80fd14a5e8c7c.zip
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 <smueller@chronox.de> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Diffstat (limited to 'crypto')
-rw-r--r--crypto/dh.c59
1 files changed, 34 insertions, 25 deletions
diff --git a/crypto/dh.c b/crypto/dh.c
index f84fd50ec79b..cd4f32092e5c 100644
--- a/crypto/dh.c
+++ b/crypto/dh.c
@@ -180,32 +180,41 @@ static int dh_compute_value(struct kpp_request *req)
if (ret)
goto err_free_base;
- /* SP800-56A rev3 5.7.1.1 check: Validation of shared secret */
- if (fips_enabled && req->src) {
- MPI pone;
-
- /* z <= 1 */
- if (mpi_cmp_ui(val, 1) < 1) {
- ret = -EBADMSG;
- goto err_free_base;
- }
-
- /* z == p - 1 */
- pone = mpi_alloc(0);
-
- if (!pone) {
- ret = -ENOMEM;
- goto err_free_base;
+ if (fips_enabled) {
+ /* SP800-56A rev3 5.7.1.1 check: Validation of shared secret */
+ if (req->src) {
+ MPI pone;
+
+ /* z <= 1 */
+ if (mpi_cmp_ui(val, 1) < 1) {
+ ret = -EBADMSG;
+ goto err_free_base;
+ }
+
+ /* z == p - 1 */
+ pone = mpi_alloc(0);
+
+ if (!pone) {
+ ret = -ENOMEM;
+ goto err_free_base;
+ }
+
+ ret = mpi_sub_ui(pone, ctx->p, 1);
+ if (!ret && !mpi_cmp(pone, val))
+ ret = -EBADMSG;
+
+ mpi_free(pone);
+
+ if (ret)
+ goto err_free_base;
+
+ /* SP800-56A rev 3 5.6.2.1.3 key check */
+ } else {
+ if (dh_is_pubkey_valid(ctx, val)) {
+ ret = -EAGAIN;
+ goto err_free_val;
+ }
}
-
- ret = mpi_sub_ui(pone, ctx->p, 1);
- if (!ret && !mpi_cmp(pone, val))
- ret = -EBADMSG;
-
- mpi_free(pone);
-
- if (ret)
- goto err_free_base;
}
ret = mpi_write_to_sgl(val, req->dst, req->dst_len, &sign);