-/* $OpenBSD: ec_asn1_test.c,v 1.3 2024/10/12 16:15:28 tb Exp $ */
+/* $OpenBSD: ec_asn1_test.c,v 1.4 2024/10/14 13:16:06 tb Exp $ */
/*
* Copyright (c) 2017, 2021 Joel Sing <jsing@openbsd.org>
+ * Copyright (c) 2024 Theo Buehler <tb@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
0x01, 0x01,
};
+const uint8_t ec_secp256k1_pkparameters_parameters[] = {
+ 0x30, 0x81, 0xe0, 0x02, 0x01, 0x01, 0x30, 0x2c,
+ 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x01,
+ 0x01, 0x02, 0x21, 0x00, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe,
+ 0xff, 0xff, 0xfc, 0x2f, 0x30, 0x44, 0x04, 0x20,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x04, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x07, 0x04, 0x41, 0x04, 0x79, 0xbe, 0x66,
+ 0x7e, 0xf9, 0xdc, 0xbb, 0xac, 0x55, 0xa0, 0x62,
+ 0x95, 0xce, 0x87, 0x0b, 0x07, 0x02, 0x9b, 0xfc,
+ 0xdb, 0x2d, 0xce, 0x28, 0xd9, 0x59, 0xf2, 0x81,
+ 0x5b, 0x16, 0xf8, 0x17, 0x98, 0x48, 0x3a, 0xda,
+ 0x77, 0x26, 0xa3, 0xc4, 0x65, 0x5d, 0xa4, 0xfb,
+ 0xfc, 0x0e, 0x11, 0x08, 0xa8, 0xfd, 0x17, 0xb4,
+ 0x48, 0xa6, 0x85, 0x54, 0x19, 0x9c, 0x47, 0xd0,
+ 0x8f, 0xfb, 0x10, 0xd4, 0xb8, 0x02, 0x21, 0x00,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe,
+ 0xba, 0xae, 0xdc, 0xe6, 0xaf, 0x48, 0xa0, 0x3b,
+ 0xbf, 0xd2, 0x5e, 0x8c, 0xd0, 0x36, 0x41, 0x41,
+ 0x02, 0x01, 0x01,
+};
+
static void
hexdump(const unsigned char *buf, size_t len)
{
}
static int
-ec_group_pkparameters_test(const char *label, int asn1_flag,
+ec_group_pkparameters_test(const char *label, int nid, int asn1_flag,
const uint8_t *test_data, size_t test_data_len)
{
EC_GROUP *group_a = NULL, *group_b = NULL;
/*
* Test i2d_ECPKParameters/d2i_ECPKParameters.
*/
- if ((group_a = EC_GROUP_new_by_curve_name(NID_X9_62_prime256v1)) == NULL)
+ if ((group_a = EC_GROUP_new_by_curve_name(nid)) == NULL)
errx(1, "failed to create EC_GROUP");
EC_GROUP_set_asn1_flag(group_a, asn1_flag);
ec_group_pkparameters_named_curve_test(void)
{
return ec_group_pkparameters_test("ECPKPARAMETERS named curve",
- OPENSSL_EC_NAMED_CURVE, ec_secp256r1_pkparameters_named_curve,
+ NID_X9_62_prime256v1, OPENSSL_EC_NAMED_CURVE,
+ ec_secp256r1_pkparameters_named_curve,
sizeof(ec_secp256r1_pkparameters_named_curve));
}
ec_group_pkparameters_parameters_test(void)
{
return ec_group_pkparameters_test("ECPKPARAMETERS parameters",
- OPENSSL_EC_EXPLICIT_CURVE, ec_secp256r1_pkparameters_parameters,
+ NID_X9_62_prime256v1, OPENSSL_EC_EXPLICIT_CURVE,
+ ec_secp256r1_pkparameters_parameters,
sizeof(ec_secp256r1_pkparameters_parameters));
}
+static int
+ec_group_pkparameters_correct_padding_test(void)
+{
+ return ec_group_pkparameters_test("ECPKPARAMETERS parameters",
+ NID_secp256k1, OPENSSL_EC_EXPLICIT_CURVE,
+ ec_secp256k1_pkparameters_parameters,
+ sizeof(ec_secp256k1_pkparameters_parameters));
+}
+
static int
ec_group_roundtrip_curve(const EC_GROUP *group, const char *descr, int nid)
{
failed |= ec_group_pkparameters_named_curve_test();
failed |= ec_group_pkparameters_parameters_test();
+ failed |= ec_group_pkparameters_correct_padding_test();
failed |= ec_group_roundtrip_builtin_curves();
return (failed);