Commit 84a2368c9e for strongswan.org
commit 84a2368c9ec94f33fa326d31318b7e9c70b5485c
Author: Tobias Brunner <tobias@strongswan.org>
Date: Thu Mar 12 12:11:41 2026 +0100
unit-tests: Add tests for ECDSA with Brainpool curves
AWS-LC doesn't support the Brainpool curves currently, so we skip those
tests there but still ensure that generating keys with NIST curves via
OID is supported.
diff --git a/src/libstrongswan/tests/suites/test_ecdsa.c b/src/libstrongswan/tests/suites/test_ecdsa.c
index 3d2ed01163..3bb510d13a 100644
--- a/src/libstrongswan/tests/suites/test_ecdsa.c
+++ b/src/libstrongswan/tests/suites/test_ecdsa.c
@@ -18,6 +18,12 @@
#include <plugins/plugin_feature.h>
+/**
+ * Whether the currently loaded plugins support non-NIST curves (in case of
+ * our test suite Brainpool curves).
+ */
+static bool non_nist_curves_supported;
+
/**
* Signature schemes to test
*/
@@ -38,11 +44,13 @@ static struct {
/**
* Perform a signature verification "good" test having a key pair
*/
-static void test_good_sig(private_key_t *privkey, public_key_t *pubkey)
+static void test_good_sig(private_key_t *privkey, public_key_t *pubkey,
+ bool nist)
{
chunk_t sig, data = chunk_from_chars(0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x00,
0x07,0x06,0x05,0x04,0x03,0x02,0x01,0x00,
0xFC,0xFD,0xFE,0xFF);
+ bool allow_failure, expect_failure;
int i;
for (i = 0; i < countof(schemes); i++)
@@ -54,15 +62,30 @@ static void test_good_sig(private_key_t *privkey, public_key_t *pubkey)
{
continue;
}
- if (schemes[i].key_size != 0 &&
- schemes[i].key_size != privkey->get_keysize(privkey))
+ /* not all plugins can reject the classic ECDSA schemes for non-NIST
+ * curves, but some do, which we allow. make sure plugins that don't at
+ * least match hash and key size for these schemes */
+ allow_failure = schemes[i].key_size != 0 && !nist;
+ expect_failure = schemes[i].key_size != 0 &&
+ schemes[i].key_size != privkey->get_keysize(privkey);
+ sig = chunk_empty;
+ if (privkey->sign(privkey, schemes[i].scheme, NULL, data, &sig))
{
- continue;
- }
- fail_unless(privkey->sign(privkey, schemes[i].scheme, NULL, data, &sig),
- "sign %N", signature_scheme_names, schemes[i].scheme);
- fail_unless(pubkey->verify(pubkey, schemes[i].scheme, NULL, data, sig),
+ fail_if(expect_failure, "sign %N did not fail",
+ signature_scheme_names, schemes[i].scheme);
+ if (allow_failure)
+ {
+ warn("sign %N accepted with non-NIST curve",
+ signature_scheme_names, schemes[i].scheme);
+ }
+ fail_if(!pubkey->verify(pubkey, schemes[i].scheme, NULL, data, sig),
"verify %N", signature_scheme_names, schemes[i].scheme);
+ }
+ else
+ {
+ fail_if(!expect_failure && !allow_failure, "sign %N failed",
+ signature_scheme_names, schemes[i].scheme);
+ }
free(sig.ptr);
}
}
@@ -152,7 +175,60 @@ START_TEST(test_gen)
pubkey = privkey->get_public_key(privkey);
ck_assert(pubkey != NULL);
- test_good_sig(privkey, pubkey);
+ test_good_sig(privkey, pubkey, TRUE);
+
+ test_bad_sigs(pubkey);
+
+ pubkey->destroy(pubkey);
+ privkey->destroy(privkey);
+}
+END_TEST
+
+/**
+ * ECDSA curves to test ordered by increasing size
+ */
+static chunk_t curves[] = {
+ /** secp256r1 */
+ chunk_from_chars(0x06,0x08,0x2a,0x86,0x48,0xce,0x3d,0x03,0x01,0x07),
+ /** brainpoolP256r1 */
+ chunk_from_chars(0x06,0x09,0x2b,0x24,0x03,0x03,0x02,0x08,0x01,0x01,0x07),
+ /** secp384r1 */
+ chunk_from_chars(0x06,0x05,0x2b,0x81,0x04,0x00,0x22),
+ /** brainpoolP384r1 */
+ chunk_from_chars(0x06,0x09,0x2b,0x24,0x03,0x03,0x02,0x08,0x01,0x01,0x0b),
+ /** secp521r1 */
+ chunk_from_chars(0x06,0x05,0x2b,0x81,0x04,0x00,0x23),
+ /** brainpoolP512r1 */
+ chunk_from_chars(0x06,0x09,0x2b,0x24,0x03,0x03,0x02,0x08,0x01,0x01,0x0d),
+};
+
+START_TEST(test_gen_curve)
+{
+ private_key_t *privkey;
+ public_key_t *pubkey;
+ bool nist = _i % 2 == 0;
+
+ if (!nist && !non_nist_curves_supported)
+ {
+ warn("skipped generating EC key with non-NIST curve %#B",
+ &curves[_i]);
+ return;
+ }
+
+ privkey = lib->creds->create(lib->creds, CRED_PRIVATE_KEY, KEY_ECDSA,
+ BUILD_ECDSA_CURVE, curves[_i], BUILD_END);
+ if (!nist && !privkey)
+ {
+ warn("failed to generate EC key with non-NIST curve %#B, skipping "
+ "further tests with non-NIST curves", &curves[_i]);
+ non_nist_curves_supported = FALSE;
+ return;
+ }
+ ck_assert(privkey != NULL);
+ pubkey = privkey->get_public_key(privkey);
+ ck_assert(pubkey != NULL);
+
+ test_good_sig(privkey, pubkey, nist);
test_bad_sigs(pubkey);
@@ -295,6 +371,129 @@ static struct {
0xd4,0x6d,0x34,0x22,0xd4,0xdd,0xca,0x63,0x26,0x95,0xb5,0x47,0x9b,0x8b,0x4a,0x30,
0x67,0x27,0x3e,0xcd),
},
+ { chunk_from_chars( /* brainpoolP256r1 */
+ 0x30,0x78,0x02,0x01,0x01,0x04,0x20,0x8f,0xbd,0x3a,0x82,0x19,0x53,0xdc,0x46,0x89,
+ 0xe6,0x5d,0x88,0x79,0xd6,0x53,0x61,0x77,0xe9,0xff,0x26,0x00,0xe1,0xe9,0xee,0xaf,
+ 0xc0,0xad,0xeb,0x29,0xa0,0x71,0xd7,0xa0,0x0b,0x06,0x09,0x2b,0x24,0x03,0x03,0x02,
+ 0x08,0x01,0x01,0x07,0xa1,0x44,0x03,0x42,0x00,0x04,0x18,0x2c,0xa4,0x79,0x85,0xe9,
+ 0xbf,0xbf,0x14,0xc5,0x68,0xb9,0x3e,0x9d,0x0a,0x9e,0xbe,0xe8,0x46,0x01,0x9e,0x6a,
+ 0xb4,0x93,0xc4,0xb4,0x63,0x85,0x8b,0xbd,0xa2,0x99,0x1e,0xda,0xe7,0xdf,0x82,0x30,
+ 0x7f,0x06,0xdb,0xd0,0x4f,0xaa,0x30,0xd1,0xa9,0x7b,0x04,0x85,0x54,0x43,0xef,0x4d,
+ 0x0d,0x4a,0xa3,0x1e,0xb1,0x8e,0xa1,0x43,0xba,0x2c),
+ chunk_from_chars(
+ 0x30,0x81,0x88,0x02,0x01,0x00,0x30,0x14,0x06,0x07,0x2a,0x86,0x48,0xce,0x3d,0x02,
+ 0x01,0x06,0x09,0x2b,0x24,0x03,0x03,0x02,0x08,0x01,0x01,0x07,0x04,0x6d,0x30,0x6b,
+ 0x02,0x01,0x01,0x04,0x20,0x8f,0xbd,0x3a,0x82,0x19,0x53,0xdc,0x46,0x89,0xe6,0x5d,
+ 0x88,0x79,0xd6,0x53,0x61,0x77,0xe9,0xff,0x26,0x00,0xe1,0xe9,0xee,0xaf,0xc0,0xad,
+ 0xeb,0x29,0xa0,0x71,0xd7,0xa1,0x44,0x03,0x42,0x00,0x04,0x18,0x2c,0xa4,0x79,0x85,
+ 0xe9,0xbf,0xbf,0x14,0xc5,0x68,0xb9,0x3e,0x9d,0x0a,0x9e,0xbe,0xe8,0x46,0x01,0x9e,
+ 0x6a,0xb4,0x93,0xc4,0xb4,0x63,0x85,0x8b,0xbd,0xa2,0x99,0x1e,0xda,0xe7,0xdf,0x82,
+ 0x30,0x7f,0x06,0xdb,0xd0,0x4f,0xaa,0x30,0xd1,0xa9,0x7b,0x04,0x85,0x54,0x43,0xef,
+ 0x4d,0x0d,0x4a,0xa3,0x1e,0xb1,0x8e,0xa1,0x43,0xba,0x2c),
+ chunk_from_chars(
+ 0x30,0x5a,0x30,0x14,0x06,0x07,0x2a,0x86,0x48,0xce,0x3d,0x02,0x01,0x06,0x09,0x2b,
+ 0x24,0x03,0x03,0x02,0x08,0x01,0x01,0x07,0x03,0x42,0x00,0x04,0x18,0x2c,0xa4,0x79,
+ 0x85,0xe9,0xbf,0xbf,0x14,0xc5,0x68,0xb9,0x3e,0x9d,0x0a,0x9e,0xbe,0xe8,0x46,0x01,
+ 0x9e,0x6a,0xb4,0x93,0xc4,0xb4,0x63,0x85,0x8b,0xbd,0xa2,0x99,0x1e,0xda,0xe7,0xdf,
+ 0x82,0x30,0x7f,0x06,0xdb,0xd0,0x4f,0xaa,0x30,0xd1,0xa9,0x7b,0x04,0x85,0x54,0x43,
+ 0xef,0x4d,0x0d,0x4a,0xa3,0x1e,0xb1,0x8e,0xa1,0x43,0xba,0x2c),
+ chunk_from_chars(
+ 0x40,0x62,0xfc,0xd8,0x70,0x0d,0x06,0xd5,0xdb,0x10,0x01,0xf4,0x9d,0xf6,0xc2,0xf5,
+ 0x6f,0x66,0xdf,0x72),
+ chunk_from_chars(
+ 0xe3,0x9b,0x2c,0x23,0x4d,0x91,0xe0,0x2d,0x52,0x33,0x92,0x8d,0x23,0x54,0xcd,0x41,
+ 0x2d,0x1a,0x8b,0x0b),
+ },
+ { chunk_from_chars( /* brainpoolP384r1 */
+ 0x30,0x81,0xa8,0x02,0x01,0x01,0x04,0x30,0x82,0xe6,0xf3,0x18,0x48,0xac,0x8e,0xf5,
+ 0xd5,0xf4,0x9f,0x5e,0x8c,0x94,0x2e,0x9e,0xd9,0x83,0x12,0x65,0x39,0x90,0x0c,0x26,
+ 0xa4,0x6d,0x62,0xbe,0x0b,0xa5,0xcc,0x88,0x8a,0xe5,0x7e,0xc2,0xd1,0xf4,0x64,0x2f,
+ 0xf2,0x24,0xa4,0xe9,0xee,0xbd,0x74,0x09,0xa0,0x0b,0x06,0x09,0x2b,0x24,0x03,0x03,
+ 0x02,0x08,0x01,0x01,0x0b,0xa1,0x64,0x03,0x62,0x00,0x04,0x65,0xe2,0x54,0x33,0x07,
+ 0x44,0x88,0x2a,0x17,0x71,0xda,0xfa,0xbd,0x31,0x45,0x34,0x9c,0x55,0x86,0xd4,0xf0,
+ 0x4a,0x2d,0x4d,0x06,0x6a,0x0d,0x4d,0x36,0xe4,0x2e,0xdc,0x0a,0xc4,0xeb,0x9c,0x60,
+ 0x0d,0x60,0x64,0x74,0xab,0xb7,0x64,0x81,0x9d,0xd5,0xf1,0x70,0x1c,0xe7,0xab,0x73,
+ 0x1a,0x44,0xa0,0xc7,0xa1,0xd5,0xb3,0x29,0x24,0x1a,0x81,0xfe,0x34,0x6d,0xd0,0xd0,
+ 0x2b,0x84,0x12,0x52,0xb4,0xee,0x91,0xb6,0xc9,0xd0,0xd1,0xf5,0x69,0x36,0x34,0xdb,
+ 0xe5,0xb0,0xd5,0x02,0xba,0xaf,0x7c,0xe1,0xab,0x95,0x89),
+ chunk_from_chars(
+ 0x30,0x81,0xba,0x02,0x01,0x00,0x30,0x14,0x06,0x07,0x2a,0x86,0x48,0xce,0x3d,0x02,
+ 0x01,0x06,0x09,0x2b,0x24,0x03,0x03,0x02,0x08,0x01,0x01,0x0b,0x04,0x81,0x9e,0x30,
+ 0x81,0x9b,0x02,0x01,0x01,0x04,0x30,0x82,0xe6,0xf3,0x18,0x48,0xac,0x8e,0xf5,0xd5,
+ 0xf4,0x9f,0x5e,0x8c,0x94,0x2e,0x9e,0xd9,0x83,0x12,0x65,0x39,0x90,0x0c,0x26,0xa4,
+ 0x6d,0x62,0xbe,0x0b,0xa5,0xcc,0x88,0x8a,0xe5,0x7e,0xc2,0xd1,0xf4,0x64,0x2f,0xf2,
+ 0x24,0xa4,0xe9,0xee,0xbd,0x74,0x09,0xa1,0x64,0x03,0x62,0x00,0x04,0x65,0xe2,0x54,
+ 0x33,0x07,0x44,0x88,0x2a,0x17,0x71,0xda,0xfa,0xbd,0x31,0x45,0x34,0x9c,0x55,0x86,
+ 0xd4,0xf0,0x4a,0x2d,0x4d,0x06,0x6a,0x0d,0x4d,0x36,0xe4,0x2e,0xdc,0x0a,0xc4,0xeb,
+ 0x9c,0x60,0x0d,0x60,0x64,0x74,0xab,0xb7,0x64,0x81,0x9d,0xd5,0xf1,0x70,0x1c,0xe7,
+ 0xab,0x73,0x1a,0x44,0xa0,0xc7,0xa1,0xd5,0xb3,0x29,0x24,0x1a,0x81,0xfe,0x34,0x6d,
+ 0xd0,0xd0,0x2b,0x84,0x12,0x52,0xb4,0xee,0x91,0xb6,0xc9,0xd0,0xd1,0xf5,0x69,0x36,
+ 0x34,0xdb,0xe5,0xb0,0xd5,0x02,0xba,0xaf,0x7c,0xe1,0xab,0x95,0x89),
+ chunk_from_chars(
+ 0x30,0x7a,0x30,0x14,0x06,0x07,0x2a,0x86,0x48,0xce,0x3d,0x02,0x01,0x06,0x09,0x2b,
+ 0x24,0x03,0x03,0x02,0x08,0x01,0x01,0x0b,0x03,0x62,0x00,0x04,0x65,0xe2,0x54,0x33,
+ 0x07,0x44,0x88,0x2a,0x17,0x71,0xda,0xfa,0xbd,0x31,0x45,0x34,0x9c,0x55,0x86,0xd4,
+ 0xf0,0x4a,0x2d,0x4d,0x06,0x6a,0x0d,0x4d,0x36,0xe4,0x2e,0xdc,0x0a,0xc4,0xeb,0x9c,
+ 0x60,0x0d,0x60,0x64,0x74,0xab,0xb7,0x64,0x81,0x9d,0xd5,0xf1,0x70,0x1c,0xe7,0xab,
+ 0x73,0x1a,0x44,0xa0,0xc7,0xa1,0xd5,0xb3,0x29,0x24,0x1a,0x81,0xfe,0x34,0x6d,0xd0,
+ 0xd0,0x2b,0x84,0x12,0x52,0xb4,0xee,0x91,0xb6,0xc9,0xd0,0xd1,0xf5,0x69,0x36,0x34,
+ 0xdb,0xe5,0xb0,0xd5,0x02,0xba,0xaf,0x7c,0xe1,0xab,0x95,0x89),
+ chunk_from_chars(
+ 0x26,0x38,0x82,0x10,0xab,0xaf,0x97,0x76,0xd2,0x59,0x1e,0x43,0xed,0x74,0x15,0x51,
+ 0x73,0x55,0xdf,0xfe),
+ chunk_from_chars(
+ 0xf5,0x1c,0xa6,0x0c,0x47,0x5b,0x3e,0x56,0x89,0x4a,0x73,0xd5,0x3f,0x96,0x53,0xf7,
+ 0x7b,0xff,0x6d,0x85),
+ },
+ { chunk_from_chars( /* brainpoolP512r1 */
+ 0x30,0x81,0xda,0x02,0x01,0x01,0x04,0x40,0x7b,0x18,0xba,0x69,0x84,0xde,0x25,0x59,
+ 0xf9,0xfa,0x82,0xa9,0x38,0x9e,0xf5,0x02,0x9d,0x49,0x6d,0x1e,0xd1,0xda,0xab,0xf1,
+ 0xe2,0x00,0x96,0x43,0x28,0x42,0x8e,0xb4,0x69,0xfb,0x02,0xee,0xc0,0x6c,0xaf,0xee,
+ 0x8f,0x7d,0xf0,0xce,0xc3,0xca,0xcb,0xa4,0x0f,0x4f,0x24,0x08,0xc0,0x48,0x3e,0xfc,
+ 0xba,0xa1,0xf2,0xd6,0xab,0xbc,0xa7,0x70,0xa0,0x0b,0x06,0x09,0x2b,0x24,0x03,0x03,
+ 0x02,0x08,0x01,0x01,0x0d,0xa1,0x81,0x85,0x03,0x81,0x82,0x00,0x04,0xa1,0xf1,0xbf,
+ 0x7c,0x9d,0x57,0x6b,0xfe,0xab,0xe8,0x66,0x3a,0x2f,0x22,0x83,0x65,0x83,0xfa,0xeb,
+ 0xb3,0x45,0x7c,0xfd,0x86,0x6a,0xaa,0x1e,0xea,0xcb,0xf1,0x2b,0xec,0x42,0xd1,0xff,
+ 0xf7,0x70,0x5c,0x45,0xc4,0x88,0x84,0xcb,0x8c,0x3a,0x90,0x64,0x58,0x53,0xfc,0xac,
+ 0x58,0x15,0xe8,0xd1,0xb4,0x99,0x23,0xde,0x2a,0x86,0x20,0xf0,0x5b,0xa3,0xf1,0x22,
+ 0x0e,0x16,0xa5,0xb6,0x35,0x06,0xe5,0xd2,0xcc,0x75,0x9d,0x9c,0xf5,0xe0,0xbd,0x6c,
+ 0x77,0xa5,0x99,0xba,0x49,0x65,0xdf,0x23,0xf1,0x0a,0xd8,0xed,0x12,0x65,0x5a,0xdf,
+ 0x6c,0xdc,0x5e,0x06,0x63,0x5e,0xf3,0xb6,0x57,0x57,0x14,0x8e,0x2a,0xce,0xca,0x14,
+ 0x7f,0x0e,0xe9,0x73,0x01,0xc9,0x65,0x23,0xf3,0xab,0x3e,0x32,0x81),
+ chunk_from_chars(
+ 0x30,0x81,0xec,0x02,0x01,0x00,0x30,0x14,0x06,0x07,0x2a,0x86,0x48,0xce,0x3d,0x02,
+ 0x01,0x06,0x09,0x2b,0x24,0x03,0x03,0x02,0x08,0x01,0x01,0x0d,0x04,0x81,0xd0,0x30,
+ 0x81,0xcd,0x02,0x01,0x01,0x04,0x40,0x7b,0x18,0xba,0x69,0x84,0xde,0x25,0x59,0xf9,
+ 0xfa,0x82,0xa9,0x38,0x9e,0xf5,0x02,0x9d,0x49,0x6d,0x1e,0xd1,0xda,0xab,0xf1,0xe2,
+ 0x00,0x96,0x43,0x28,0x42,0x8e,0xb4,0x69,0xfb,0x02,0xee,0xc0,0x6c,0xaf,0xee,0x8f,
+ 0x7d,0xf0,0xce,0xc3,0xca,0xcb,0xa4,0x0f,0x4f,0x24,0x08,0xc0,0x48,0x3e,0xfc,0xba,
+ 0xa1,0xf2,0xd6,0xab,0xbc,0xa7,0x70,0xa1,0x81,0x85,0x03,0x81,0x82,0x00,0x04,0xa1,
+ 0xf1,0xbf,0x7c,0x9d,0x57,0x6b,0xfe,0xab,0xe8,0x66,0x3a,0x2f,0x22,0x83,0x65,0x83,
+ 0xfa,0xeb,0xb3,0x45,0x7c,0xfd,0x86,0x6a,0xaa,0x1e,0xea,0xcb,0xf1,0x2b,0xec,0x42,
+ 0xd1,0xff,0xf7,0x70,0x5c,0x45,0xc4,0x88,0x84,0xcb,0x8c,0x3a,0x90,0x64,0x58,0x53,
+ 0xfc,0xac,0x58,0x15,0xe8,0xd1,0xb4,0x99,0x23,0xde,0x2a,0x86,0x20,0xf0,0x5b,0xa3,
+ 0xf1,0x22,0x0e,0x16,0xa5,0xb6,0x35,0x06,0xe5,0xd2,0xcc,0x75,0x9d,0x9c,0xf5,0xe0,
+ 0xbd,0x6c,0x77,0xa5,0x99,0xba,0x49,0x65,0xdf,0x23,0xf1,0x0a,0xd8,0xed,0x12,0x65,
+ 0x5a,0xdf,0x6c,0xdc,0x5e,0x06,0x63,0x5e,0xf3,0xb6,0x57,0x57,0x14,0x8e,0x2a,0xce,
+ 0xca,0x14,0x7f,0x0e,0xe9,0x73,0x01,0xc9,0x65,0x23,0xf3,0xab,0x3e,0x32,0x81),
+ chunk_from_chars(
+ 0x30,0x81,0x9b,0x30,0x14,0x06,0x07,0x2a,0x86,0x48,0xce,0x3d,0x02,0x01,0x06,0x09,
+ 0x2b,0x24,0x03,0x03,0x02,0x08,0x01,0x01,0x0d,0x03,0x81,0x82,0x00,0x04,0xa1,0xf1,
+ 0xbf,0x7c,0x9d,0x57,0x6b,0xfe,0xab,0xe8,0x66,0x3a,0x2f,0x22,0x83,0x65,0x83,0xfa,
+ 0xeb,0xb3,0x45,0x7c,0xfd,0x86,0x6a,0xaa,0x1e,0xea,0xcb,0xf1,0x2b,0xec,0x42,0xd1,
+ 0xff,0xf7,0x70,0x5c,0x45,0xc4,0x88,0x84,0xcb,0x8c,0x3a,0x90,0x64,0x58,0x53,0xfc,
+ 0xac,0x58,0x15,0xe8,0xd1,0xb4,0x99,0x23,0xde,0x2a,0x86,0x20,0xf0,0x5b,0xa3,0xf1,
+ 0x22,0x0e,0x16,0xa5,0xb6,0x35,0x06,0xe5,0xd2,0xcc,0x75,0x9d,0x9c,0xf5,0xe0,0xbd,
+ 0x6c,0x77,0xa5,0x99,0xba,0x49,0x65,0xdf,0x23,0xf1,0x0a,0xd8,0xed,0x12,0x65,0x5a,
+ 0xdf,0x6c,0xdc,0x5e,0x06,0x63,0x5e,0xf3,0xb6,0x57,0x57,0x14,0x8e,0x2a,0xce,0xca,
+ 0x14,0x7f,0x0e,0xe9,0x73,0x01,0xc9,0x65,0x23,0xf3,0xab,0x3e,0x32,0x81),
+ chunk_from_chars(
+ 0xf0,0x7c,0x48,0xed,0xdd,0xf0,0x37,0xab,0xf4,0x1a,0xbd,0x83,0x10,0x8e,0xd6,0xce,
+ 0x14,0x7c,0xb2,0x6d),
+ chunk_from_chars(
+ 0x74,0x6a,0xaa,0xfc,0x1e,0xec,0x0c,0xf9,0x23,0x1b,0x96,0x50,0xf9,0x5c,0xf0,0x69,
+ 0xe3,0x0a,0x05,0x9d),
+ },
};
START_TEST(test_load)
@@ -302,6 +501,13 @@ START_TEST(test_load)
private_key_t *privkey;
public_key_t *pubkey;
chunk_t encoding, fp;
+ bool nist = _i < 3;
+
+ if (!nist && !non_nist_curves_supported)
+ {
+ warn("skipped loading EC key with non-NIST curve");
+ return;
+ }
privkey = lib->creds->create(lib->creds, CRED_PRIVATE_KEY, KEY_ECDSA,
BUILD_BLOB_ASN1_DER, keys[_i].key, BUILD_END);
@@ -333,7 +539,7 @@ START_TEST(test_load)
ck_assert(pubkey->get_fingerprint(pubkey, KEYID_PUBKEY_INFO_SHA1, &fp));
ck_assert_chunk_eq(keys[_i].fp_spki, fp);
- test_good_sig(privkey, pubkey);
+ test_good_sig(privkey, pubkey, nist);
test_bad_sigs(pubkey);
@@ -427,16 +633,21 @@ Suite *ecdsa_suite_create()
Suite *s;
TCase *tc;
int gen_count = countof(key_sizes);
+ int curve_count = countof(curves);
s = suite_create("ecdsa");
+ non_nist_curves_supported = TRUE;
+
if (getenv("TESTS_REDUCED_KEYLENGTHS") != NULL)
- {
+ { /* generate 256-bit keys only */
gen_count = min(1, gen_count);
+ curve_count = min(2, curve_count);
}
tc = tcase_create("generate");
tcase_add_loop_test(tc, test_gen, 0, gen_count);
+ tcase_add_loop_test(tc, test_gen_curve, 0, curve_count);
suite_add_tcase(s, tc);
tc = tcase_create("load");