diff mbox series

[v4,27/35] crypto: testmgr - implement testing for KPP failures

Message ID 20191017190932.1947-28-ard.biesheuvel@linaro.org
State New
Headers show
Series crypto: crypto API library interfaces for WireGuard | expand

Commit Message

Ard Biesheuvel Oct. 17, 2019, 7:09 p.m. UTC
The Curve25519 drivers we will be implementing will perform validation
of the inputs, and in order to ensure that these checks work as expected,
we need to be able to test for expected errors. So implement this in the
KPP test routines in the testmgr framework.

Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>

---
 crypto/testmgr.c | 14 ++++++++++----
 crypto/testmgr.h |  2 ++
 2 files changed, 12 insertions(+), 4 deletions(-)

-- 
2.20.1
diff mbox series

Patch

diff --git a/crypto/testmgr.c b/crypto/testmgr.c
index 767fc5444771..4548559b2f0b 100644
--- a/crypto/testmgr.c
+++ b/crypto/testmgr.c
@@ -3499,8 +3499,11 @@  static int do_test_kpp(struct crypto_kpp *tfm, const struct kpp_testvec *vec,
 	/* Compute party A's public key */
 	err = crypto_wait_req(crypto_kpp_generate_public_key(req), &wait);
 	if (err) {
-		pr_err("alg: %s: Party A: generate public key test failed. err %d\n",
-		       alg, err);
+		if (err != vec->gen_pubkey_error)
+			pr_err("alg: %s: Party A: generate public key test failed. err %d (expected %d)\n",
+			       alg, err, vec->gen_pubkey_error);
+		else
+			err = 0;
 		goto free_output;
 	}
 
@@ -3537,8 +3540,11 @@  static int do_test_kpp(struct crypto_kpp *tfm, const struct kpp_testvec *vec,
 				 crypto_req_done, &wait);
 	err = crypto_wait_req(crypto_kpp_compute_shared_secret(req), &wait);
 	if (err) {
-		pr_err("alg: %s: Party A: compute shared secret test failed. err %d\n",
-		       alg, err);
+		if (err != vec->comp_ss_error)
+			pr_err("alg: %s: Party A: compute shared secret test failed. err %d (expected %d)\n",
+			       alg, err, vec->comp_ss_error);
+		else
+			err = 0;
 		goto free_all;
 	}
 
diff --git a/crypto/testmgr.h b/crypto/testmgr.h
index b717afc0926e..c39be00a8125 100644
--- a/crypto/testmgr.h
+++ b/crypto/testmgr.h
@@ -166,6 +166,8 @@  struct kpp_testvec {
 	unsigned short expected_a_public_size;
 	unsigned short expected_ss_size;
 	bool genkey;
+	int gen_pubkey_error;
+	int comp_ss_error;
 };
 
 static const char zeroed_string[48];