xref: /openbsd-src/regress/lib/libcrypto/ec/ec_asn1_test.c (revision 35671554a3f71a3620dfbda5649acdb27119f8c8)
1*35671554Stb /* $OpenBSD: ec_asn1_test.c,v 1.31 2024/12/24 18:32:31 tb Exp $ */
26bd9d0e3Sjsing /*
36bd9d0e3Sjsing  * Copyright (c) 2017, 2021 Joel Sing <jsing@openbsd.org>
4cdd7a87bStb  * Copyright (c) 2024 Theo Buehler <tb@openbsd.org>
56bd9d0e3Sjsing  *
66bd9d0e3Sjsing  * Permission to use, copy, modify, and distribute this software for any
76bd9d0e3Sjsing  * purpose with or without fee is hereby granted, provided that the above
86bd9d0e3Sjsing  * copyright notice and this permission notice appear in all copies.
96bd9d0e3Sjsing  *
106bd9d0e3Sjsing  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
116bd9d0e3Sjsing  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
126bd9d0e3Sjsing  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
136bd9d0e3Sjsing  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
146bd9d0e3Sjsing  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
156bd9d0e3Sjsing  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
166bd9d0e3Sjsing  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
176bd9d0e3Sjsing  */
186bd9d0e3Sjsing 
196bd9d0e3Sjsing #include <err.h>
206bd9d0e3Sjsing #include <string.h>
216bd9d0e3Sjsing 
226bd9d0e3Sjsing #include <openssl/bio.h>
236bd9d0e3Sjsing #include <openssl/ec.h>
2467604119Stb #include <openssl/err.h>
256bd9d0e3Sjsing #include <openssl/objects.h>
266bd9d0e3Sjsing 
27aea18883Stb /* set to 0 if/when we are going to enforce 0 <= a,b < p. */
28aea18883Stb #define NEGATIVE_CURVE_COEFFICIENTS_ALLOWED	1
29aea18883Stb 
30dc9810dbStb static const uint8_t ec_secp256r1_pkparameters_named_curve[] = {
316bd9d0e3Sjsing 	0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03,
326bd9d0e3Sjsing 	0x01, 0x07,
336bd9d0e3Sjsing };
346bd9d0e3Sjsing 
35dc9810dbStb static const uint8_t ec_secp256r1_pkparameters_parameters[] = {
366bd9d0e3Sjsing 	0x30, 0x81, 0xf7, 0x02, 0x01, 0x01, 0x30, 0x2c,
376bd9d0e3Sjsing 	0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x01,
386bd9d0e3Sjsing 	0x01, 0x02, 0x21, 0x00, 0xff, 0xff, 0xff, 0xff,
396bd9d0e3Sjsing 	0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
406bd9d0e3Sjsing 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
416bd9d0e3Sjsing 	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
426bd9d0e3Sjsing 	0xff, 0xff, 0xff, 0xff, 0x30, 0x5b, 0x04, 0x20,
436bd9d0e3Sjsing 	0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x01,
446bd9d0e3Sjsing 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
456bd9d0e3Sjsing 	0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
466bd9d0e3Sjsing 	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc,
476bd9d0e3Sjsing 	0x04, 0x20, 0x5a, 0xc6, 0x35, 0xd8, 0xaa, 0x3a,
486bd9d0e3Sjsing 	0x93, 0xe7, 0xb3, 0xeb, 0xbd, 0x55, 0x76, 0x98,
496bd9d0e3Sjsing 	0x86, 0xbc, 0x65, 0x1d, 0x06, 0xb0, 0xcc, 0x53,
506bd9d0e3Sjsing 	0xb0, 0xf6, 0x3b, 0xce, 0x3c, 0x3e, 0x27, 0xd2,
516bd9d0e3Sjsing 	0x60, 0x4b, 0x03, 0x15, 0x00, 0xc4, 0x9d, 0x36,
526bd9d0e3Sjsing 	0x08, 0x86, 0xe7, 0x04, 0x93, 0x6a, 0x66, 0x78,
536bd9d0e3Sjsing 	0xe1, 0x13, 0x9d, 0x26, 0xb7, 0x81, 0x9f, 0x7e,
546bd9d0e3Sjsing 	0x90, 0x04, 0x41, 0x04, 0x6b, 0x17, 0xd1, 0xf2,
556bd9d0e3Sjsing 	0xe1, 0x2c, 0x42, 0x47, 0xf8, 0xbc, 0xe6, 0xe5,
566bd9d0e3Sjsing 	0x63, 0xa4, 0x40, 0xf2, 0x77, 0x03, 0x7d, 0x81,
576bd9d0e3Sjsing 	0x2d, 0xeb, 0x33, 0xa0, 0xf4, 0xa1, 0x39, 0x45,
586bd9d0e3Sjsing 	0xd8, 0x98, 0xc2, 0x96, 0x4f, 0xe3, 0x42, 0xe2,
596bd9d0e3Sjsing 	0xfe, 0x1a, 0x7f, 0x9b, 0x8e, 0xe7, 0xeb, 0x4a,
606bd9d0e3Sjsing 	0x7c, 0x0f, 0x9e, 0x16, 0x2b, 0xce, 0x33, 0x57,
616bd9d0e3Sjsing 	0x6b, 0x31, 0x5e, 0xce, 0xcb, 0xb6, 0x40, 0x68,
626bd9d0e3Sjsing 	0x37, 0xbf, 0x51, 0xf5, 0x02, 0x21, 0x00, 0xff,
636bd9d0e3Sjsing 	0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff,
646bd9d0e3Sjsing 	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xbc,
656bd9d0e3Sjsing 	0xe6, 0xfa, 0xad, 0xa7, 0x17, 0x9e, 0x84, 0xf3,
666bd9d0e3Sjsing 	0xb9, 0xca, 0xc2, 0xfc, 0x63, 0x25, 0x51, 0x02,
676bd9d0e3Sjsing 	0x01, 0x01,
686bd9d0e3Sjsing };
696bd9d0e3Sjsing 
70dc9810dbStb static const uint8_t ec_secp256k1_pkparameters_parameters[] = {
71cdd7a87bStb 	0x30, 0x81, 0xe0, 0x02, 0x01, 0x01, 0x30, 0x2c,
72cdd7a87bStb 	0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x01,
73cdd7a87bStb 	0x01, 0x02, 0x21, 0x00, 0xff, 0xff, 0xff, 0xff,
74cdd7a87bStb 	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
75cdd7a87bStb 	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
76cdd7a87bStb 	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe,
77cdd7a87bStb 	0xff, 0xff, 0xfc, 0x2f, 0x30, 0x44, 0x04, 0x20,
78cdd7a87bStb 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
79cdd7a87bStb 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
80cdd7a87bStb 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
81cdd7a87bStb 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
82cdd7a87bStb 	0x04, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
83cdd7a87bStb 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
84cdd7a87bStb 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
85cdd7a87bStb 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
86cdd7a87bStb 	0x00, 0x07, 0x04, 0x41, 0x04, 0x79, 0xbe, 0x66,
87cdd7a87bStb 	0x7e, 0xf9, 0xdc, 0xbb, 0xac, 0x55, 0xa0, 0x62,
88cdd7a87bStb 	0x95, 0xce, 0x87, 0x0b, 0x07, 0x02, 0x9b, 0xfc,
89cdd7a87bStb 	0xdb, 0x2d, 0xce, 0x28, 0xd9, 0x59, 0xf2, 0x81,
90cdd7a87bStb 	0x5b, 0x16, 0xf8, 0x17, 0x98, 0x48, 0x3a, 0xda,
91cdd7a87bStb 	0x77, 0x26, 0xa3, 0xc4, 0x65, 0x5d, 0xa4, 0xfb,
92cdd7a87bStb 	0xfc, 0x0e, 0x11, 0x08, 0xa8, 0xfd, 0x17, 0xb4,
93cdd7a87bStb 	0x48, 0xa6, 0x85, 0x54, 0x19, 0x9c, 0x47, 0xd0,
94cdd7a87bStb 	0x8f, 0xfb, 0x10, 0xd4, 0xb8, 0x02, 0x21, 0x00,
95cdd7a87bStb 	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
96cdd7a87bStb 	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe,
97cdd7a87bStb 	0xba, 0xae, 0xdc, 0xe6, 0xaf, 0x48, 0xa0, 0x3b,
98cdd7a87bStb 	0xbf, 0xd2, 0x5e, 0x8c, 0xd0, 0x36, 0x41, 0x41,
99cdd7a87bStb 	0x02, 0x01, 0x01,
100cdd7a87bStb };
101cdd7a87bStb 
1026bd9d0e3Sjsing static void
1036bd9d0e3Sjsing hexdump(const unsigned char *buf, size_t len)
1046bd9d0e3Sjsing {
1056bd9d0e3Sjsing 	size_t i;
1066bd9d0e3Sjsing 
1076bd9d0e3Sjsing 	for (i = 1; i <= len; i++)
1086bd9d0e3Sjsing 		fprintf(stderr, " 0x%02hhx,%s", buf[i - 1], i % 8 ? "" : "\n");
1096bd9d0e3Sjsing 
1106bd9d0e3Sjsing 	fprintf(stderr, "\n");
1116bd9d0e3Sjsing }
1126bd9d0e3Sjsing 
1136bd9d0e3Sjsing static int
1146bd9d0e3Sjsing compare_data(const char *label, const unsigned char *d1, size_t d1_len,
1156bd9d0e3Sjsing     const unsigned char *d2, size_t d2_len)
1166bd9d0e3Sjsing {
1176bd9d0e3Sjsing 	if (d1_len != d2_len) {
1186bd9d0e3Sjsing 		fprintf(stderr, "FAIL: got %s with length %zu, want %zu\n",
1196bd9d0e3Sjsing 		    label, d1_len, d2_len);
1206bd9d0e3Sjsing 		return -1;
1216bd9d0e3Sjsing 	}
1226bd9d0e3Sjsing 	if (memcmp(d1, d2, d1_len) != 0) {
1236bd9d0e3Sjsing 		fprintf(stderr, "FAIL: %s differ\n", label);
1246bd9d0e3Sjsing 		fprintf(stderr, "got:\n");
1256bd9d0e3Sjsing 		hexdump(d1, d1_len);
1266bd9d0e3Sjsing 		fprintf(stderr, "want:\n");
1276bd9d0e3Sjsing 		hexdump(d2, d2_len);
1286bd9d0e3Sjsing 		return -1;
1296bd9d0e3Sjsing 	}
1306bd9d0e3Sjsing 	return 0;
1316bd9d0e3Sjsing }
1326bd9d0e3Sjsing 
1336bd9d0e3Sjsing static int
134cdd7a87bStb ec_group_pkparameters_test(const char *label, int nid, int asn1_flag,
1356bd9d0e3Sjsing     const uint8_t *test_data, size_t test_data_len)
1366bd9d0e3Sjsing {
1376bd9d0e3Sjsing 	EC_GROUP *group_a = NULL, *group_b = NULL;
1386bd9d0e3Sjsing 	unsigned char *out = NULL, *data = NULL;
1396bd9d0e3Sjsing 	const unsigned char *p;
1406bd9d0e3Sjsing 	BIO *bio_mem = NULL;
1416bd9d0e3Sjsing 	int failure = 1;
1426bd9d0e3Sjsing 	int len;
1436bd9d0e3Sjsing 
1446bd9d0e3Sjsing 	/*
1456bd9d0e3Sjsing 	 * Test i2d_ECPKParameters/d2i_ECPKParameters.
1466bd9d0e3Sjsing 	 */
147cdd7a87bStb 	if ((group_a = EC_GROUP_new_by_curve_name(nid)) == NULL)
1486bd9d0e3Sjsing 		errx(1, "failed to create EC_GROUP");
1496bd9d0e3Sjsing 
1506bd9d0e3Sjsing 	EC_GROUP_set_asn1_flag(group_a, asn1_flag);
1516bd9d0e3Sjsing 
1526bd9d0e3Sjsing 	if ((len = i2d_ECPKParameters(group_a, &out)) < 0) {
1536bd9d0e3Sjsing 		fprintf(stderr, "FAIL: i2d_ECPKParameters failed\n");
1546bd9d0e3Sjsing 		goto done;
1556bd9d0e3Sjsing 	}
1566bd9d0e3Sjsing 	if (compare_data(label, out, len, test_data, test_data_len) == -1)
1576bd9d0e3Sjsing 		goto done;
1586bd9d0e3Sjsing 
1596bd9d0e3Sjsing 	p = out;
1606bd9d0e3Sjsing 	if ((group_b = d2i_ECPKParameters(NULL, &p, len)) == NULL) {
1616bd9d0e3Sjsing 		fprintf(stderr, "FAIL: d2i_ECPKParameters failed\n");
1626bd9d0e3Sjsing 		goto done;
1636bd9d0e3Sjsing 	}
1646bd9d0e3Sjsing 
1656bd9d0e3Sjsing 	if (EC_GROUP_cmp(group_a, group_b, NULL) != 0) {
1666bd9d0e3Sjsing 		fprintf(stderr, "FAIL: EC_GROUPs do not match!\n");
1676bd9d0e3Sjsing 		goto done;
1686bd9d0e3Sjsing 	}
1696bd9d0e3Sjsing 
1706bd9d0e3Sjsing 	p = out;
1716bd9d0e3Sjsing 	if ((group_a = d2i_ECPKParameters(&group_a, &p, len)) == NULL) {
1726bd9d0e3Sjsing 		fprintf(stderr, "FAIL: d2i_ECPKParameters failed\n");
1736bd9d0e3Sjsing 		goto done;
1746bd9d0e3Sjsing 	}
1756bd9d0e3Sjsing 
1766bd9d0e3Sjsing 	if (EC_GROUP_cmp(group_a, group_b, NULL) != 0) {
1776bd9d0e3Sjsing 		fprintf(stderr, "FAIL: EC_GROUPs do not match!\n");
1786bd9d0e3Sjsing 		goto done;
1796bd9d0e3Sjsing 	}
1806bd9d0e3Sjsing 
1816bd9d0e3Sjsing 	/*
1826bd9d0e3Sjsing 	 * Test i2d_ECPKParameters_bio/d2i_ECPKParameters_bio.
1836bd9d0e3Sjsing 	 */
1846bd9d0e3Sjsing 	if ((bio_mem = BIO_new(BIO_s_mem())) == NULL)
1856bd9d0e3Sjsing                 errx(1, "BIO_new failed for BIO_s_mem");
1866bd9d0e3Sjsing 
18792c4bfc1Stb 	if (i2d_ECPKParameters_bio(bio_mem, group_a) < 0) {
1886bd9d0e3Sjsing 		fprintf(stderr, "FAIL: i2d_ECPKParameters_bio failed\n");
1896bd9d0e3Sjsing 		goto done;
1906bd9d0e3Sjsing 	}
1916bd9d0e3Sjsing 
1926bd9d0e3Sjsing 	len = BIO_get_mem_data(bio_mem, &data);
1936bd9d0e3Sjsing 	if (compare_data(label, out, len, test_data, test_data_len) == -1)
1946bd9d0e3Sjsing 		goto done;
1956bd9d0e3Sjsing 
1966bd9d0e3Sjsing 	EC_GROUP_free(group_b);
1976bd9d0e3Sjsing 	if ((group_b = d2i_ECPKParameters_bio(bio_mem, NULL)) == NULL) {
1986bd9d0e3Sjsing 		fprintf(stderr, "FAIL: d2i_ECPKParameters_bio failed\n");
1996bd9d0e3Sjsing 		goto done;
2006bd9d0e3Sjsing 	}
2016bd9d0e3Sjsing 
2026bd9d0e3Sjsing 	if (EC_GROUP_cmp(group_a, group_b, NULL) != 0) {
2036bd9d0e3Sjsing 		fprintf(stderr, "FAIL: EC_GROUPs do not match!\n");
2046bd9d0e3Sjsing 		goto done;
2056bd9d0e3Sjsing 	}
2066bd9d0e3Sjsing 
2076bd9d0e3Sjsing 	failure = 0;
2086bd9d0e3Sjsing 
2096bd9d0e3Sjsing  done:
2106bd9d0e3Sjsing 	BIO_free_all(bio_mem);
2116bd9d0e3Sjsing 	EC_GROUP_free(group_a);
2126bd9d0e3Sjsing 	EC_GROUP_free(group_b);
2136bd9d0e3Sjsing 	free(out);
2146bd9d0e3Sjsing 
21592c4bfc1Stb 	return failure;
2166bd9d0e3Sjsing }
2176bd9d0e3Sjsing 
2186bd9d0e3Sjsing static int
2196bd9d0e3Sjsing ec_group_pkparameters_named_curve_test(void)
2206bd9d0e3Sjsing {
2216bd9d0e3Sjsing 	return ec_group_pkparameters_test("ECPKPARAMETERS named curve",
222cdd7a87bStb 	    NID_X9_62_prime256v1, OPENSSL_EC_NAMED_CURVE,
223cdd7a87bStb 	    ec_secp256r1_pkparameters_named_curve,
2246bd9d0e3Sjsing 	    sizeof(ec_secp256r1_pkparameters_named_curve));
2256bd9d0e3Sjsing }
2266bd9d0e3Sjsing 
2276bd9d0e3Sjsing static int
2286bd9d0e3Sjsing ec_group_pkparameters_parameters_test(void)
2296bd9d0e3Sjsing {
2306bd9d0e3Sjsing 	return ec_group_pkparameters_test("ECPKPARAMETERS parameters",
231cdd7a87bStb 	    NID_X9_62_prime256v1, OPENSSL_EC_EXPLICIT_CURVE,
232cdd7a87bStb 	    ec_secp256r1_pkparameters_parameters,
2336bd9d0e3Sjsing 	    sizeof(ec_secp256r1_pkparameters_parameters));
2346bd9d0e3Sjsing }
2356bd9d0e3Sjsing 
23633e95073Stb static int
237cdd7a87bStb ec_group_pkparameters_correct_padding_test(void)
238cdd7a87bStb {
239cdd7a87bStb 	return ec_group_pkparameters_test("ECPKPARAMETERS parameters",
240cdd7a87bStb 	    NID_secp256k1, OPENSSL_EC_EXPLICIT_CURVE,
241cdd7a87bStb 	    ec_secp256k1_pkparameters_parameters,
242cdd7a87bStb 	    sizeof(ec_secp256k1_pkparameters_parameters));
243cdd7a87bStb }
244cdd7a87bStb 
24592c4bfc1Stb static EC_GROUP *
24692c4bfc1Stb ec_group_simple_from_builtin(const EC_GROUP *group, int nid, BN_CTX *ctx)
24792c4bfc1Stb {
24892c4bfc1Stb 	EC_GROUP *simple_group;
24992c4bfc1Stb 	BIGNUM *p, *a, *b, *x, *y, *order, *cofactor;
25092c4bfc1Stb 	const EC_POINT *generator;
25192c4bfc1Stb 	EC_POINT *simple_generator = NULL;
25292c4bfc1Stb 
25392c4bfc1Stb 	BN_CTX_start(ctx);
25492c4bfc1Stb 
25592c4bfc1Stb 	if ((p = BN_CTX_get(ctx)) == NULL)
25692c4bfc1Stb 		errx(1, "BN_CTX_get");
25792c4bfc1Stb 	if ((a = BN_CTX_get(ctx)) == NULL)
25892c4bfc1Stb 		errx(1, "BN_CTX_get");
25992c4bfc1Stb 	if ((b = BN_CTX_get(ctx)) == NULL)
26092c4bfc1Stb 		errx(1, "BN_CTX_get");
26192c4bfc1Stb 
26292c4bfc1Stb 	if ((x = BN_CTX_get(ctx)) == NULL)
26392c4bfc1Stb 		errx(1, "BN_CTX_get");
26492c4bfc1Stb 	if ((y = BN_CTX_get(ctx)) == NULL)
26592c4bfc1Stb 		errx(1, "BN_CTX_get");
26692c4bfc1Stb 
26792c4bfc1Stb 	if ((order = BN_CTX_get(ctx)) == NULL)
26892c4bfc1Stb 		errx(1, "BN_CTX_get");
26992c4bfc1Stb 	if ((cofactor = BN_CTX_get(ctx)) == NULL)
27092c4bfc1Stb 		errx(1, "BN_CTX_get");
27192c4bfc1Stb 
27292c4bfc1Stb 	if (!EC_GROUP_get_curve(group, p, a, b, ctx))
27392c4bfc1Stb 		errx(1, "EC_GROUP_get_curve");
27492c4bfc1Stb 	if (!EC_GROUP_get_order(group, order, ctx))
27592c4bfc1Stb 		errx(1, "EC_GROUP_get_order");
27692c4bfc1Stb 	if (!EC_GROUP_get_cofactor(group, cofactor, ctx))
27792c4bfc1Stb 		errx(1, "EC_GROUP_get_cofactor");
27892c4bfc1Stb 	if ((generator = EC_GROUP_get0_generator(group)) == NULL)
27992c4bfc1Stb 		errx(1, "EC_GROUP_get0_generator");
28092c4bfc1Stb 	if (!EC_POINT_get_affine_coordinates(group, generator, x, y, ctx))
28192c4bfc1Stb 		errx(1, "EC_POINT_get_affine_coordinates");
28292c4bfc1Stb 
28392c4bfc1Stb 	if ((simple_group = EC_GROUP_new(EC_GFp_simple_method())) == NULL)
28492c4bfc1Stb 		errx(1, "EC_GROUP_new");
28592c4bfc1Stb 	if (!EC_GROUP_set_curve(simple_group, p, a, b, ctx))
28692c4bfc1Stb 		errx(1, "EC_GROUP_set_curve");
28792c4bfc1Stb 	EC_GROUP_set_curve_name(simple_group, nid);
28892c4bfc1Stb 
28992c4bfc1Stb 	if ((simple_generator = EC_POINT_new(simple_group)) == NULL)
29092c4bfc1Stb 		errx(1, "EC_POINT_new");
2912a88cfdfStb 	if (!EC_POINT_set_compressed_coordinates(simple_group, simple_generator,
2922a88cfdfStb 	    x, BN_is_odd(y), ctx))
29392c4bfc1Stb 		errx(1, "EC_POINT_set_affine_coordinates");
29492c4bfc1Stb 	if (!EC_GROUP_set_generator(simple_group, simple_generator, order,
29592c4bfc1Stb 	    cofactor))
29692c4bfc1Stb 		errx(1, "EC_GROUP_set_generator");
29792c4bfc1Stb 
29892c4bfc1Stb 	BN_CTX_end(ctx);
29992c4bfc1Stb 
30092c4bfc1Stb 	EC_POINT_free(simple_generator);
30192c4bfc1Stb 
30292c4bfc1Stb 	return simple_group;
30392c4bfc1Stb }
30492c4bfc1Stb 
305cdd7a87bStb static int
30633e95073Stb ec_group_roundtrip_curve(const EC_GROUP *group, const char *descr, int nid)
30733e95073Stb {
30833e95073Stb 	EC_GROUP *new_group = NULL;
30992c4bfc1Stb 	unsigned char *der = NULL, *new_der = NULL;
310a5e50783Stb 	int der_len = 0, new_der_len = 0;
31133e95073Stb 	const unsigned char *p;
31233e95073Stb 	int failed = 1;
31333e95073Stb 
31433e95073Stb 	der = NULL;
31533e95073Stb 	if ((der_len = i2d_ECPKParameters(group, &der)) <= 0)
31633e95073Stb 		errx(1, "failed to serialize %s %d", descr, nid);
31733e95073Stb 
31833e95073Stb 	p = der;
31933e95073Stb 	if ((new_group = d2i_ECPKParameters(NULL, &p, der_len)) == NULL)
32033e95073Stb 		errx(1, "failed to deserialize %s %d", descr, nid);
32133e95073Stb 
32292c4bfc1Stb 	new_der = NULL;
32392c4bfc1Stb 	if ((new_der_len = i2d_ECPKParameters(new_group, &new_der)) <= 0)
32492c4bfc1Stb 		errx(1, "failed to serialize new %s %d", descr, nid);
32592c4bfc1Stb 
32692c4bfc1Stb 	if (compare_data(__func__, der, der_len, new_der, new_der_len) == -1) {
32792c4bfc1Stb 		fprintf(stderr, "FAIL: new and old der for %s %d\n", descr, nid);
32892c4bfc1Stb 		goto err;
32992c4bfc1Stb 	}
33092c4bfc1Stb 
33192c4bfc1Stb 	if (EC_GROUP_method_of(group) == EC_GFp_mont_method()) {
33233e95073Stb 		if (EC_GROUP_cmp(group, new_group, NULL) != 0) {
33333e95073Stb 			fprintf(stderr, "FAIL: %s %d groups mismatch\n", descr, nid);
33433e95073Stb 			goto err;
33533e95073Stb 		}
33692c4bfc1Stb 	}
33733e95073Stb 	if (EC_GROUP_get_asn1_flag(group) != EC_GROUP_get_asn1_flag(new_group)) {
33833e95073Stb 		fprintf(stderr, "FAIL: %s %d asn1_flag %x != %x\n", descr, nid,
33933e95073Stb 		    EC_GROUP_get_asn1_flag(group),
34033e95073Stb 		    EC_GROUP_get_asn1_flag(new_group));
34133e95073Stb 		goto err;
34233e95073Stb 	}
34333e95073Stb 	if (EC_GROUP_get_point_conversion_form(group) !=
34433e95073Stb 	    EC_GROUP_get_point_conversion_form(new_group)) {
34533e95073Stb 		fprintf(stderr, "FAIL: %s %d form %02x != %02x\n", descr, nid,
34633e95073Stb 		    EC_GROUP_get_point_conversion_form(group),
34733e95073Stb 		    EC_GROUP_get_point_conversion_form(new_group));
34833e95073Stb 		goto err;
34933e95073Stb 	}
35033e95073Stb 
35133e95073Stb 	failed = 0;
35233e95073Stb 
35333e95073Stb  err:
35433e95073Stb 	EC_GROUP_free(new_group);
355a5e50783Stb 	freezero(der, der_len);
356a5e50783Stb 	freezero(new_der, new_der_len);
35733e95073Stb 
35833e95073Stb 	return failed;
35933e95073Stb }
36033e95073Stb 
36133e95073Stb static int
36292c4bfc1Stb ec_group_roundtrip_group(EC_GROUP *group, int nid)
36333e95073Stb {
364435d593cStb 	int failed = 1;
36533e95073Stb 
36692c4bfc1Stb 	if (EC_GROUP_get_asn1_flag(group) != OPENSSL_EC_NAMED_CURVE) {
36792c4bfc1Stb 		fprintf(stderr, "FAIL: ASN.1 flag not set for %d\n", nid);
36892c4bfc1Stb 		goto err;
36992c4bfc1Stb 	}
37092c4bfc1Stb 	if (EC_GROUP_get_point_conversion_form(group) !=
37192c4bfc1Stb 	    POINT_CONVERSION_UNCOMPRESSED) {
37292c4bfc1Stb 		fprintf(stderr, "FAIL: %d has point conversion form %02x\n",
37392c4bfc1Stb 		    nid, EC_GROUP_get_point_conversion_form(group));
37492c4bfc1Stb 		goto err;
37592c4bfc1Stb 	}
37692c4bfc1Stb 
37792c4bfc1Stb 	failed = 0;
37892c4bfc1Stb 
37992c4bfc1Stb 	failed |= ec_group_roundtrip_curve(group, "named", nid);
38092c4bfc1Stb 
38192c4bfc1Stb 	EC_GROUP_set_asn1_flag(group, 0);
38292c4bfc1Stb 	failed |= ec_group_roundtrip_curve(group, "explicit", nid);
38392c4bfc1Stb 
38492c4bfc1Stb 	EC_GROUP_set_point_conversion_form(group, POINT_CONVERSION_COMPRESSED);
38592c4bfc1Stb 	failed |= ec_group_roundtrip_curve(group, "compressed", nid);
38692c4bfc1Stb 
38792c4bfc1Stb 	EC_GROUP_set_point_conversion_form(group, POINT_CONVERSION_HYBRID);
38892c4bfc1Stb 	failed |= ec_group_roundtrip_curve(group, "hybrid", nid);
38992c4bfc1Stb 
39092c4bfc1Stb  err:
39192c4bfc1Stb 	return failed;
39292c4bfc1Stb }
39392c4bfc1Stb 
39492c4bfc1Stb static int
39592c4bfc1Stb ec_group_roundtrip_builtin_curve(const EC_builtin_curve *curve, BN_CTX *ctx)
39692c4bfc1Stb {
39792c4bfc1Stb 	EC_GROUP *group = NULL, *simple_group = NULL;
39892c4bfc1Stb 	int failed = 0;
39992c4bfc1Stb 
40033e95073Stb 	if ((group = EC_GROUP_new_by_curve_name(curve->nid)) == NULL)
40133e95073Stb 		errx(1, "failed to instantiate curve %d", curve->nid);
40233e95073Stb 
4034acc544fStb 	if (!EC_GROUP_check(group, NULL)) {
4044acc544fStb 		fprintf(stderr, "FAIL: EC_GROUP_check(%d) failed\n", curve->nid);
4054acc544fStb 		goto err;
4064acc544fStb 	}
4074acc544fStb 
40892c4bfc1Stb 	if ((simple_group = ec_group_simple_from_builtin(group, curve->nid,
40992c4bfc1Stb 	    ctx)) == NULL)
41092c4bfc1Stb 		errx(1, "failed to instantiate simple group %d", curve->nid);
41192c4bfc1Stb 
41292c4bfc1Stb 	if (!EC_GROUP_check(group, NULL)) {
41392c4bfc1Stb 		fprintf(stderr, "FAIL: EC_GROUP_check(%d) failed\n", curve->nid);
41433e95073Stb 		goto err;
41533e95073Stb 	}
41633e95073Stb 
41792c4bfc1Stb 	failed |= ec_group_roundtrip_group(group, curve->nid);
41892c4bfc1Stb 	failed |= ec_group_roundtrip_group(simple_group, curve->nid);
41933e95073Stb 
42033e95073Stb  err:
42133e95073Stb 	EC_GROUP_free(group);
42292c4bfc1Stb 	EC_GROUP_free(simple_group);
42333e95073Stb 
42433e95073Stb 	return failed;
42533e95073Stb }
42633e95073Stb 
42733e95073Stb static int
42833e95073Stb ec_group_roundtrip_builtin_curves(void)
42933e95073Stb {
43092c4bfc1Stb 	BN_CTX *ctx = NULL;
43133e95073Stb 	EC_builtin_curve *all_curves = NULL;
43233e95073Stb 	size_t curve_id, ncurves;
43333e95073Stb 	int failed = 0;
43433e95073Stb 
43592c4bfc1Stb 	if ((ctx = BN_CTX_new()) == NULL)
43692c4bfc1Stb 		errx(1, "BN_CTX_new");
43792c4bfc1Stb 
43833e95073Stb 	ncurves = EC_get_builtin_curves(NULL, 0);
43933e95073Stb 	if ((all_curves = calloc(ncurves, sizeof(*all_curves))) == NULL)
44033e95073Stb 		err(1, "calloc builtin curves");
44133e95073Stb 	EC_get_builtin_curves(all_curves, ncurves);
44233e95073Stb 
44333e95073Stb 	for (curve_id = 0; curve_id < ncurves; curve_id++)
44492c4bfc1Stb 		failed |= ec_group_roundtrip_builtin_curve(&all_curves[curve_id], ctx);
44533e95073Stb 
44633e95073Stb 	free(all_curves);
44792c4bfc1Stb 	BN_CTX_free(ctx);
44833e95073Stb 
44933e95073Stb 	return failed;
45033e95073Stb }
45133e95073Stb 
452ae66052dStb struct curve {
453ae66052dStb 	const char *descr;
454ae66052dStb 	const char *oid;
455ae66052dStb 	const char *sn;
456ae66052dStb 	const char *ln;
457ae66052dStb 	const char *p;
458ae66052dStb 	const char *a;
459ae66052dStb 	const char *b;
460ae66052dStb 	const char *order;
461ae66052dStb 	const char *cofactor;
462ae66052dStb 	const char *x;
463ae66052dStb 	const char *y;
464dc9810dbStb 	int known_named_curve;
465ae66052dStb 	const char *named;
466ae66052dStb 	size_t named_len;
467ae66052dStb 	const char *param;
468ae66052dStb 	size_t param_len;
469ae66052dStb };
470ae66052dStb 
47167604119Stb /*
47267604119Stb  * From draft-ietf-lwig-curve-representation-23, Appendix E.3
47367604119Stb  */
47467604119Stb 
475dc9810dbStb static const uint8_t ec_wei25519_pkparameters_named_curve[] = {
47667604119Stb 	0x06, 0x03, 0x2b, 0x65, 0x6c,
47767604119Stb };
47867604119Stb 
479dc9810dbStb static const uint8_t ec_wei25519_pkparameters_parameters[] = {
48067604119Stb 	0x30, 0x81, 0xde, 0x02, 0x01, 0x01, 0x30, 0x2b,
48167604119Stb 	0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x01,
48267604119Stb 	0x01, 0x02, 0x20, 0x7f, 0xff, 0xff, 0xff, 0xff,
48367604119Stb 	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
48467604119Stb 	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
48567604119Stb 	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
48667604119Stb 	0xff, 0xff, 0xed, 0x30, 0x44, 0x04, 0x20, 0x2a,
48767604119Stb 	0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
48867604119Stb 	0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
48967604119Stb 	0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
49067604119Stb 	0xaa, 0xaa, 0x98, 0x49, 0x14, 0xa1, 0x44, 0x04,
49167604119Stb 	0x20, 0x7b, 0x42, 0x5e, 0xd0, 0x97, 0xb4, 0x25,
49267604119Stb 	0xed, 0x09, 0x7b, 0x42, 0x5e, 0xd0, 0x97, 0xb4,
49367604119Stb 	0x25, 0xed, 0x09, 0x7b, 0x42, 0x5e, 0xd0, 0x97,
49467604119Stb 	0xb4, 0x26, 0x0b, 0x5e, 0x9c, 0x77, 0x10, 0xc8,
49567604119Stb 	0x64, 0x04, 0x41, 0x04, 0x2a, 0xaa, 0xaa, 0xaa,
49667604119Stb 	0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
49767604119Stb 	0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
49867604119Stb 	0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
49967604119Stb 	0xaa, 0xad, 0x24, 0x5a, 0x20, 0xae, 0x19, 0xa1,
50067604119Stb 	0xb8, 0xa0, 0x86, 0xb4, 0xe0, 0x1e, 0xdd, 0x2c,
50167604119Stb 	0x77, 0x48, 0xd1, 0x4c, 0x92, 0x3d, 0x4d, 0x7e,
50267604119Stb 	0x6d, 0x7c, 0x61, 0xb2, 0x29, 0xe9, 0xc5, 0xa2,
50367604119Stb 	0x7e, 0xce, 0xd3, 0xd9, 0x02, 0x20, 0x10, 0x00,
50467604119Stb 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
50567604119Stb 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0xde,
50667604119Stb 	0xf9, 0xde, 0xa2, 0xf7, 0x9c, 0xd6, 0x58, 0x12,
50767604119Stb 	0x63, 0x1a, 0x5c, 0xf5, 0xd3, 0xed, 0x02, 0x01,
50867604119Stb 	0x08,
50967604119Stb };
51067604119Stb 
511194b9aa8Stb static const struct curve wei25519 = {
512ae66052dStb 	.descr = "short Weierstrass 25519",
513194b9aa8Stb 	.oid = "1.3.101.108",
514194b9aa8Stb 	.sn = "Wei25519",
515194b9aa8Stb 	.p =	 "7fffffff" "ffffffff" "ffffffff" "ffffffff"
516194b9aa8Stb 		 "ffffffff" "ffffffff" "ffffffff" "ffffffed",
517194b9aa8Stb 	.a =	 "2aaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa"
518194b9aa8Stb 		 "aaaaaaaa" "aaaaaaaa" "aaaaaa98" "4914a144",
519194b9aa8Stb 	.b =	 "7b425ed0" "97b425ed" "097b425e" "d097b425"
520194b9aa8Stb 		 "ed097b42" "5ed097b4" "260b5e9c" "7710c864",
521194b9aa8Stb 	.x =	 "2aaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa"
522194b9aa8Stb 		 "aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaad245a",
523194b9aa8Stb 	.y =	 "20ae19a1" "b8a086b4" "e01edd2c" "7748d14c"
524194b9aa8Stb 		 "923d4d7e" "6d7c61b2" "29e9c5a2" "7eced3d9",
525194b9aa8Stb 	.order = "10000000" "00000000" "00000000" "00000000"
526194b9aa8Stb 		 "14def9de" "a2f79cd6" "5812631a" "5cf5d3ed",
527194b9aa8Stb 	.cofactor = "8",
528194b9aa8Stb 	.named = ec_wei25519_pkparameters_named_curve,
529194b9aa8Stb 	.named_len = sizeof(ec_wei25519_pkparameters_named_curve),
530194b9aa8Stb 	.param = ec_wei25519_pkparameters_parameters,
531194b9aa8Stb 	.param_len = sizeof(ec_wei25519_pkparameters_parameters),
532194b9aa8Stb };
533194b9aa8Stb 
534ae66052dStb /*
535ae66052dStb  * From draft-ietf-lwig-curve-representation-23, Appendix G.3
536ae66052dStb  */
537ae66052dStb 
538dc9810dbStb static const uint8_t ec_wei25519_2_pkparameters_parameters[] = {
539ae66052dStb 	0x30, 0x81, 0xde, 0x02, 0x01, 0x01, 0x30, 0x2b,
540ae66052dStb 	0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x01,
541ae66052dStb 	0x01, 0x02, 0x20, 0x7f, 0xff, 0xff, 0xff, 0xff,
542ae66052dStb 	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
543ae66052dStb 	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
544ae66052dStb 	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
545ae66052dStb 	0xff, 0xff, 0xed, 0x30, 0x44, 0x04, 0x20, 0x00,
546ae66052dStb 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
547ae66052dStb 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
548ae66052dStb 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
549ae66052dStb 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x04,
550ae66052dStb 	0x20, 0x1a, 0xc1, 0xda, 0x05, 0xb5, 0x5b, 0xc1,
551ae66052dStb 	0x46, 0x33, 0xbd, 0x39, 0xe4, 0x7f, 0x94, 0x30,
552ae66052dStb 	0x2e, 0xf1, 0x98, 0x43, 0xdc, 0xf6, 0x69, 0x91,
553ae66052dStb 	0x6f, 0x6a, 0x5d, 0xfd, 0x01, 0x65, 0x53, 0x8c,
554ae66052dStb 	0xd1, 0x04, 0x41, 0x04, 0x17, 0xcf, 0xea, 0xc3,
555ae66052dStb 	0x78, 0xae, 0xd6, 0x61, 0x31, 0x8e, 0x86, 0x34,
556ae66052dStb 	0x58, 0x22, 0x75, 0xb6, 0xd9, 0xad, 0x4d, 0xef,
557ae66052dStb 	0x07, 0x2e, 0xa1, 0x93, 0x5e, 0xe3, 0xc4, 0xe8,
558ae66052dStb 	0x7a, 0x94, 0x0f, 0xfa, 0x0c, 0x08, 0xa9, 0x52,
559ae66052dStb 	0xc5, 0x5d, 0xfa, 0xd6, 0x2c, 0x4f, 0x13, 0xf1,
560ae66052dStb 	0xa8, 0xf6, 0x8d, 0xca, 0xdc, 0x5c, 0x33, 0x1d,
561ae66052dStb 	0x29, 0x7a, 0x37, 0xb6, 0xf0, 0xd7, 0xfd, 0xcc,
562ae66052dStb 	0x51, 0xe1, 0x6b, 0x4d, 0x02, 0x20, 0x10, 0x00,
563ae66052dStb 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
564ae66052dStb 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0xde,
565ae66052dStb 	0xf9, 0xde, 0xa2, 0xf7, 0x9c, 0xd6, 0x58, 0x12,
566ae66052dStb 	0x63, 0x1a, 0x5c, 0xf5, 0xd3, 0xed, 0x02, 0x01,
567ae66052dStb 	0x08,
568ae66052dStb };
569ae66052dStb 
570ae66052dStb static const struct curve wei25519_2 = {
571ae66052dStb 	.descr = "short Weierstrass 25519.2",
572ae66052dStb 	.oid = "1.3.101.108",
573ae66052dStb 	.sn = "Wei25519",
574ae66052dStb 	.p =	 "7fffffff" "ffffffff" "ffffffff" "ffffffff"
575ae66052dStb 		 "ffffffff" "ffffffff" "ffffffff" "ffffffed",
576ae66052dStb 	.a =	 "02",
577ae66052dStb 	.b =	 "1ac1da05" "b55bc146" "33bd39e4" "7f94302e"
578ae66052dStb 		 "f19843dc" "f669916f" "6a5dfd01" "65538cd1",
579ae66052dStb 	.x =	 "17cfeac3" "78aed661" "318e8634" "582275b6"
580ae66052dStb 		 "d9ad4def" "072ea193" "5ee3c4e8" "7a940ffa",
581ae66052dStb 	.y =	 "0c08a952" "c55dfad6" "2c4f13f1" "a8f68dca"
582ae66052dStb 		 "dc5c331d" "297a37b6" "f0d7fdcc" "51e16b4d",
583ae66052dStb 	.order = "10000000" "00000000" "00000000" "00000000"
584ae66052dStb 		 "14def9de" "a2f79cd6" "5812631a" "5cf5d3ed",
585ae66052dStb 	.cofactor = "8",
586ae66052dStb 	.named = ec_wei25519_pkparameters_named_curve,
587ae66052dStb 	.named_len = sizeof(ec_wei25519_pkparameters_named_curve),
588ae66052dStb 	.param = ec_wei25519_2_pkparameters_parameters,
589ae66052dStb 	.param_len = sizeof(ec_wei25519_2_pkparameters_parameters),
590ae66052dStb };
591ae66052dStb 
592dc9810dbStb static const uint8_t ec_wei25519_3_pkparameters_parameters[] = {
593ae66052dStb 	0x30, 0x81, 0xde, 0x02, 0x01, 0x01, 0x30, 0x2b,
594ae66052dStb 	0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x01,
595ae66052dStb 	0x01, 0x02, 0x20, 0x7f, 0xff, 0xff, 0xff, 0xff,
596ae66052dStb 	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
597ae66052dStb 	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
598ae66052dStb 	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
599ae66052dStb 	0xff, 0xff, 0xed, 0x30, 0x44, 0x04, 0x20, 0x7f,
600ae66052dStb 	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
601ae66052dStb 	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
602ae66052dStb 	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
603ae66052dStb 	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xea, 0x04,
604ae66052dStb 	0x20, 0x41, 0xa3, 0xb6, 0xbf, 0xc6, 0x68, 0x77,
605ae66052dStb 	0x8e, 0xbe, 0x29, 0x54, 0xa4, 0xb1, 0xdf, 0x36,
606ae66052dStb 	0xd1, 0x48, 0x5e, 0xce, 0xf1, 0xea, 0x61, 0x42,
607ae66052dStb 	0x95, 0x79, 0x6e, 0x10, 0x22, 0x40, 0x89, 0x1f,
608ae66052dStb 	0xaa, 0x04, 0x41, 0x04, 0x77, 0x06, 0xc3, 0x7b,
609ae66052dStb 	0x5a, 0x84, 0x12, 0x8a, 0x38, 0x84, 0xa5, 0xd7,
610ae66052dStb 	0x18, 0x11, 0xf1, 0xb5, 0x5d, 0xa3, 0x23, 0x0f,
611ae66052dStb 	0xfb, 0x17, 0xa8, 0xab, 0x0b, 0x32, 0xe4, 0x8d,
612ae66052dStb 	0x31, 0xa6, 0x68, 0x5c, 0x0f, 0x60, 0x48, 0x0c,
613ae66052dStb 	0x7a, 0x5c, 0x0e, 0x11, 0x40, 0x34, 0x0a, 0xdc,
614ae66052dStb 	0x79, 0xd6, 0xa2, 0xbf, 0x0c, 0xb5, 0x7a, 0xd0,
615ae66052dStb 	0x49, 0xd0, 0x25, 0xdc, 0x38, 0xd8, 0x0c, 0x77,
616ae66052dStb 	0x98, 0x5f, 0x03, 0x29, 0x02, 0x20, 0x10, 0x00,
617ae66052dStb 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
618ae66052dStb 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0xde,
619ae66052dStb 	0xf9, 0xde, 0xa2, 0xf7, 0x9c, 0xd6, 0x58, 0x12,
620ae66052dStb 	0x63, 0x1a, 0x5c, 0xf5, 0xd3, 0xed, 0x02, 0x01,
621ae66052dStb 	0x08,
622ae66052dStb };
623ae66052dStb 
624ae66052dStb static const struct curve wei25519_3 = {
625ae66052dStb 	.descr = "short Weierstrass 25519.-3",
626ae66052dStb 	.oid = "1.3.101.108",
627ae66052dStb 	.sn = "Wei25519",
628ae66052dStb 	.p =	 "7fffffff" "ffffffff" "ffffffff" "ffffffff"
629ae66052dStb 		 "ffffffff" "ffffffff" "ffffffff" "ffffffed",
630ae66052dStb 	.a =	 "7fffffff" "ffffffff" "ffffffff" "ffffffff"
631ae66052dStb 		 "ffffffff" "ffffffff" "ffffffff" "ffffffea",
632ae66052dStb 	.b =	 "41a3b6bf" "c668778e" "be2954a4" "b1df36d1"
633ae66052dStb 		 "485ecef1" "ea614295" "796e1022" "40891faa",
634ae66052dStb 	.x =	 "7706c37b" "5a84128a" "3884a5d7" "1811f1b5"
635ae66052dStb 		 "5da3230f" "fb17a8ab" "0b32e48d" "31a6685c",
636ae66052dStb 	.y =	 "0f60480c" "7a5c0e11" "40340adc" "79d6a2bf"
637ae66052dStb 		 "0cb57ad0" "49d025dc" "38d80c77" "985f0329",
638ae66052dStb 	.order = "10000000" "00000000" "00000000" "00000000"
639ae66052dStb 		 "14def9de" "a2f79cd6" "5812631a" "5cf5d3ed",
640ae66052dStb 	.cofactor = "8",
641ae66052dStb 	.named = ec_wei25519_pkparameters_named_curve,
642ae66052dStb 	.named_len = sizeof(ec_wei25519_pkparameters_named_curve),
643ae66052dStb 	.param = ec_wei25519_3_pkparameters_parameters,
644ae66052dStb 	.param_len = sizeof(ec_wei25519_3_pkparameters_parameters),
645ae66052dStb };
646ae66052dStb 
647aea18883Stb #if NEGATIVE_CURVE_COEFFICIENTS_ALLOWED
648aea18883Stb /* Same as wei25519_3 except for a. */
649aea18883Stb static const struct curve wei25519_3_neg = {
650aea18883Stb 	.descr = "short Weierstrass 25519.-3 with negative a",
651aea18883Stb 	.oid = "1.3.101.108",
652aea18883Stb 	.sn = "Wei25519",
653aea18883Stb 	.p =	 "7fffffff" "ffffffff" "ffffffff" "ffffffff"
654aea18883Stb 		 "ffffffff" "ffffffff" "ffffffff" "ffffffed",
655aea18883Stb 	.a =	 "-03",
656aea18883Stb 	.b =	 "41a3b6bf" "c668778e" "be2954a4" "b1df36d1"
657aea18883Stb 		 "485ecef1" "ea614295" "796e1022" "40891faa",
658aea18883Stb 	.x =	 "7706c37b" "5a84128a" "3884a5d7" "1811f1b5"
659aea18883Stb 		 "5da3230f" "fb17a8ab" "0b32e48d" "31a6685c",
660aea18883Stb 	.y =	 "0f60480c" "7a5c0e11" "40340adc" "79d6a2bf"
661aea18883Stb 		 "0cb57ad0" "49d025dc" "38d80c77" "985f0329",
662aea18883Stb 	.order = "10000000" "00000000" "00000000" "00000000"
663aea18883Stb 		 "14def9de" "a2f79cd6" "5812631a" "5cf5d3ed",
664aea18883Stb 	.cofactor = "8",
665aea18883Stb 	.named = ec_wei25519_pkparameters_named_curve,
666aea18883Stb 	.named_len = sizeof(ec_wei25519_pkparameters_named_curve),
667aea18883Stb 	.param = ec_wei25519_3_pkparameters_parameters,
668aea18883Stb 	.param_len = sizeof(ec_wei25519_3_pkparameters_parameters),
669aea18883Stb };
670aea18883Stb #endif
671aea18883Stb 
672dc9810dbStb /*
673dc9810dbStb  * From draft-ietf-lwig-curve-representation-23, Appendix L.3
674dc9810dbStb  */
675dc9810dbStb 
676dc9810dbStb static const uint8_t ec_secp256k1_m_pkparameters_named_curve[] = {
677dc9810dbStb 	0x06, 0x05, 0x2b, 0x81, 0x04, 0x00, 0x0a,
678dc9810dbStb };
679dc9810dbStb 
680dc9810dbStb static const uint8_t ec_secp256k1_m_pkparameters_parameters[] = {
681dc9810dbStb 	0x30, 0x81, 0xe0, 0x02, 0x01, 0x01, 0x30, 0x2c,
682dc9810dbStb 	0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x01,
683dc9810dbStb 	0x01, 0x02, 0x21, 0x00, 0xff, 0xff, 0xff, 0xff,
684dc9810dbStb 	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
685dc9810dbStb 	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
686dc9810dbStb 	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe,
687dc9810dbStb 	0xff, 0xff, 0xfc, 0x2f, 0x30, 0x44, 0x04, 0x20,
688dc9810dbStb 	0xcf, 0xcd, 0x5c, 0x21, 0x75, 0xe2, 0xef, 0x7d,
689dc9810dbStb 	0xcc, 0xdc, 0xe7, 0x37, 0x77, 0x0b, 0x73, 0x81,
690dc9810dbStb 	0x5a, 0x2f, 0x13, 0xc5, 0x09, 0x03, 0x5c, 0xa2,
691dc9810dbStb 	0x54, 0xa1, 0x4a, 0xc9, 0xf0, 0x89, 0x74, 0xaf,
692dc9810dbStb 	0x04, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
693dc9810dbStb 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
694dc9810dbStb 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
695dc9810dbStb 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
696dc9810dbStb 	0x06, 0xeb, 0x04, 0x41, 0x04, 0x3a, 0xca, 0x53,
697dc9810dbStb 	0x00, 0x95, 0x9f, 0xa1, 0xd0, 0xba, 0xf7, 0x8d,
698dc9810dbStb 	0xcf, 0xf7, 0x7a, 0x61, 0x6f, 0x39, 0x5e, 0x58,
699dc9810dbStb 	0x6d, 0x67, 0xac, 0xed, 0x0a, 0x88, 0x79, 0x81,
700dc9810dbStb 	0x29, 0x0c, 0x27, 0x91, 0x45, 0x95, 0x80, 0xfc,
701dc9810dbStb 	0xe5, 0x3a, 0x17, 0x0f, 0x4f, 0xb7, 0x44, 0x57,
702dc9810dbStb 	0x9f, 0xf3, 0xd6, 0x20, 0x86, 0x12, 0xcd, 0x6a,
703dc9810dbStb 	0x23, 0x3e, 0x2d, 0xe2, 0x37, 0xf9, 0x76, 0xc6,
704dc9810dbStb 	0xa7, 0x86, 0x11, 0xc8, 0x00, 0x02, 0x21, 0x00,
705dc9810dbStb 	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
706dc9810dbStb 	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe,
707dc9810dbStb 	0xba, 0xae, 0xdc, 0xe6, 0xaf, 0x48, 0xa0, 0x3b,
708dc9810dbStb 	0xbf, 0xd2, 0x5e, 0x8c, 0xd0, 0x36, 0x41, 0x41,
709dc9810dbStb 	0x02, 0x01, 0x01,
710dc9810dbStb };
711dc9810dbStb 
712dc9810dbStb static const struct curve secp256k1_m = {
713dc9810dbStb 	.descr = "short Weierstrass secp256k1.m",
714dc9810dbStb 	.oid =	 "1.3.132.0.10",
715dc9810dbStb 	.sn =	 SN_secp256k1,
716dc9810dbStb 	.p =	 "ffffffff" "ffffffff" "ffffffff" "ffffffff"
717dc9810dbStb 		 "ffffffff" "ffffffff" "fffffffe" "fffffc2f",
718dc9810dbStb 	.a =	 "cfcd5c21" "75e2ef7d" "ccdce737" "770b7381"
719dc9810dbStb 		 "5a2f13c5" "09035ca2" "54a14ac9" "f08974af",
720dc9810dbStb 	.b =	 "06eb",
721dc9810dbStb 	.x =	 "3aca5300" "959fa1d0" "baf78dcf" "f77a616f"
722dc9810dbStb 		 "395e586d" "67aced0a" "88798129" "0c279145",
723dc9810dbStb 	.y =	 "9580fce5" "3a170f4f" "b744579f" "f3d62086"
724dc9810dbStb 		 "12cd6a23" "3e2de237" "f976c6a7" "8611c800",
725dc9810dbStb 	.order = "ffffffff" "ffffffff" "ffffffff" "fffffffe"
726dc9810dbStb 		 "baaedce6" "af48a03b" "bfd25e8c" "d0364141",
727dc9810dbStb 	.cofactor = "1",
728dc9810dbStb 	.known_named_curve = 1,
729dc9810dbStb 	.named = ec_secp256k1_m_pkparameters_named_curve,
730dc9810dbStb 	.named_len = sizeof(ec_secp256k1_m_pkparameters_named_curve),
731dc9810dbStb 	.param = ec_secp256k1_m_pkparameters_parameters,
732dc9810dbStb 	.param_len = sizeof(ec_secp256k1_m_pkparameters_parameters),
733dc9810dbStb };
734dc9810dbStb 
735194b9aa8Stb static EC_GROUP *
736194b9aa8Stb ec_group_from_curve_method(const struct curve *curve, const EC_METHOD *method,
737194b9aa8Stb     BN_CTX *ctx)
73867604119Stb {
739194b9aa8Stb 	EC_GROUP *group;
74067604119Stb 	EC_POINT *generator = NULL;
74167604119Stb 	BIGNUM *p, *a, *b;
742194b9aa8Stb 	BIGNUM *order, *x, *y;
74367604119Stb 
74467604119Stb 	BN_CTX_start(ctx);
74567604119Stb 
74667604119Stb 	if ((p = BN_CTX_get(ctx)) == NULL)
74767604119Stb 		errx(1, "BN_CTX_get");
74867604119Stb 	if ((a = BN_CTX_get(ctx)) == NULL)
74967604119Stb 		errx(1, "BN_CTX_get");
75067604119Stb 	if ((b = BN_CTX_get(ctx)) == NULL)
75167604119Stb 		errx(1, "BN_CTX_get");
752194b9aa8Stb 
75367604119Stb 	if ((order = BN_CTX_get(ctx)) == NULL)
75467604119Stb 		errx(1, "BN_CTX_get");
75567604119Stb 	if ((x = BN_CTX_get(ctx)) == NULL)
75667604119Stb 		errx(1, "BN_CTX_get");
75767604119Stb 	if ((y = BN_CTX_get(ctx)) == NULL)
75867604119Stb 		errx(1, "BN_CTX_get");
75967604119Stb 
760194b9aa8Stb 	if (BN_hex2bn(&p, curve->p) == 0)
76167604119Stb 		errx(1, "BN_hex2bn(p)");
762194b9aa8Stb 	if (BN_hex2bn(&a, curve->a) == 0)
76367604119Stb 		errx(1, "BN_hex2bn(a)");
764194b9aa8Stb 	if (BN_hex2bn(&b, curve->b) == 0)
76567604119Stb 		errx(1, "BN_hex2bn(b)");
76667604119Stb 
767194b9aa8Stb 	if ((group = EC_GROUP_new(method)) == NULL)
768194b9aa8Stb 		errx(1, "EC_GROUP_new");
76967604119Stb 
770194b9aa8Stb 	if (!EC_GROUP_set_curve(group, p, a, b, ctx))
771194b9aa8Stb 		errx(1, "EC_GROUP_set_curve");
772194b9aa8Stb 
773194b9aa8Stb 	if (BN_hex2bn(&x, curve->x) == 0)
77467604119Stb 		errx(1, "BN_hex2bn(x)");
775194b9aa8Stb 	if (BN_hex2bn(&x, curve->x) == 0)
77667604119Stb 		errx(1, "BN_hex2bn(x)");
777194b9aa8Stb 	if (BN_hex2bn(&y, curve->y) == 0)
77867604119Stb 		errx(1, "BN_hex2bn(y)");
77967604119Stb 
78067604119Stb 	if ((generator = EC_POINT_new(group)) == NULL)
78167604119Stb 		errx(1, "EC_POINT_new()");
78267604119Stb 
78367604119Stb 	if (!EC_POINT_set_affine_coordinates(group, generator, x, y, ctx)) {
784ae66052dStb 		fprintf(stderr, "FAIL: %s EC_POINT_set_affine_coordinates\n",
785ae66052dStb 		    curve->descr);
78667604119Stb 		ERR_print_errors_fp(stderr);
78767604119Stb 		goto err;
78867604119Stb 	}
78967604119Stb 
790194b9aa8Stb 	if (BN_hex2bn(&order, curve->order) == 0)
79167604119Stb 		errx(1, "BN_hex2bn(order)");
79267604119Stb 
79367604119Stb 	/* Don't set cofactor to exercise the cofactor guessing code. */
79467604119Stb 	if (!EC_GROUP_set_generator(group, generator, order, NULL)) {
795ae66052dStb 		fprintf(stderr, "FAIL: %s EC_GROUP_set_generator\n", curve->descr);
796194b9aa8Stb 		ERR_print_errors_fp(stderr);
797194b9aa8Stb 		goto err;
798194b9aa8Stb 	}
799194b9aa8Stb 
800194b9aa8Stb 	EC_POINT_free(generator);
801194b9aa8Stb 
802194b9aa8Stb 	BN_CTX_end(ctx);
803194b9aa8Stb 
804194b9aa8Stb 	return group;
805194b9aa8Stb 
806194b9aa8Stb  err:
807194b9aa8Stb 	BN_CTX_end(ctx);
808194b9aa8Stb 
809194b9aa8Stb 	EC_POINT_free(generator);
810194b9aa8Stb 	EC_GROUP_free(group);
811194b9aa8Stb 
812194b9aa8Stb 	return NULL;
813194b9aa8Stb }
814194b9aa8Stb 
815194b9aa8Stb static EC_GROUP *
816194b9aa8Stb ec_group_new(const struct curve *curve, const EC_METHOD *method, BN_CTX *ctx)
817194b9aa8Stb {
818194b9aa8Stb 	EC_GROUP *group = NULL;
819194b9aa8Stb 	BIGNUM *cofactor, *guessed_cofactor;
820194b9aa8Stb 	int nid;
821194b9aa8Stb 
822194b9aa8Stb 	BN_CTX_start(ctx);
823194b9aa8Stb 
824194b9aa8Stb 	if ((nid = OBJ_txt2nid(curve->oid)) == NID_undef)
825194b9aa8Stb 		nid = OBJ_create(curve->oid, curve->sn, curve->ln);
826194b9aa8Stb 	if (nid == NID_undef) {
827ae66052dStb 		fprintf(stderr, "FAIL: OBJ_create(%s)\n", curve->descr);
828194b9aa8Stb 		goto err;
829194b9aa8Stb 	}
830194b9aa8Stb 
831194b9aa8Stb 	if ((cofactor = BN_CTX_get(ctx)) == NULL)
832194b9aa8Stb 		errx(1, "BN_CTX_get");
833194b9aa8Stb 	if ((guessed_cofactor = BN_CTX_get(ctx)) == NULL)
834194b9aa8Stb 		errx(1, "BN_CTX_get");
835194b9aa8Stb 
836194b9aa8Stb 	if (BN_hex2bn(&cofactor, curve->cofactor) == 0)
837194b9aa8Stb 		errx(1, "BN_hex2bn(cofactor)");
838194b9aa8Stb 
839194b9aa8Stb 	if ((group = ec_group_from_curve_method(curve, method, ctx)) == NULL) {
840ae66052dStb 		fprintf(stderr, "FAIL: %s ec_group_from_curve_method\n", curve->descr);
84167604119Stb 		ERR_print_errors_fp(stderr);
84267604119Stb 		goto err;
84367604119Stb 	}
84467604119Stb 
84567604119Stb 	if (!EC_GROUP_get_cofactor(group, guessed_cofactor, ctx)) {
846ae66052dStb 		fprintf(stderr, "FAIL: %s EC_GROUP_get_cofactor\n", curve->descr);
84767604119Stb 		ERR_print_errors_fp(stderr);
84867604119Stb 		goto err;
84967604119Stb 	}
85067604119Stb 
85167604119Stb 	if (BN_cmp(cofactor, guessed_cofactor) != 0) {
852ae66052dStb 		fprintf(stderr, "FAIL: %s cofactor: want ", curve->descr);
85367604119Stb 		BN_print_fp(stderr, cofactor);
85467604119Stb 		fprintf(stderr, ", got ");
85567604119Stb 		BN_print_fp(stderr, guessed_cofactor);
85667604119Stb 		fprintf(stderr, "\n");
85767604119Stb 		goto err;
85867604119Stb 	}
85967604119Stb 
86067604119Stb 	if (!EC_GROUP_check(group, ctx)) {
861ae66052dStb 		fprintf(stderr, "FAIL: %s EC_GROUP_check\n", curve->descr);
86267604119Stb 		ERR_print_errors_fp(stderr);
86367604119Stb 		goto err;
86467604119Stb 	}
86567604119Stb 
86667604119Stb 	EC_GROUP_set_curve_name(group, nid);
867194b9aa8Stb 
868194b9aa8Stb 	BN_CTX_end(ctx);
869194b9aa8Stb 
870194b9aa8Stb 	return group;
871194b9aa8Stb 
872194b9aa8Stb  err:
873194b9aa8Stb 	BN_CTX_end(ctx);
874194b9aa8Stb 
875194b9aa8Stb 	EC_GROUP_free(group);
876194b9aa8Stb 
877194b9aa8Stb 	return NULL;
878194b9aa8Stb }
879194b9aa8Stb 
880194b9aa8Stb static int
881194b9aa8Stb ec_group_non_builtin_curve(const struct curve *curve, const EC_METHOD *method,
882194b9aa8Stb     BN_CTX *ctx)
883194b9aa8Stb {
884194b9aa8Stb 	EC_GROUP *group = NULL, *new_group = NULL;
885194b9aa8Stb 	const unsigned char *pder;
886194b9aa8Stb 	unsigned char *der = NULL;
8875ae9088aStb #ifndef OPENSSL_SUPPRESS_DEPRECATED
888194b9aa8Stb 	long error;
8895ae9088aStb #endif
890194b9aa8Stb 	int der_len = 0;
891194b9aa8Stb 	int failed = 1;
892194b9aa8Stb 
893194b9aa8Stb 	ERR_clear_error();
894194b9aa8Stb 	BN_CTX_start(ctx);
895194b9aa8Stb 
896194b9aa8Stb 	if ((group = ec_group_new(curve, method, ctx)) == NULL)
897194b9aa8Stb 		goto err;
898194b9aa8Stb 
89992c4bfc1Stb 	if (EC_GROUP_get_curve_name(group) == NID_undef) {
900ae66052dStb 		fprintf(stderr, "FAIL: no curve name set for %s\n", curve->descr);
901194b9aa8Stb 		goto err;
902194b9aa8Stb 	}
903194b9aa8Stb 
90467604119Stb 	EC_GROUP_set_asn1_flag(group, OPENSSL_EC_NAMED_CURVE);
90567604119Stb 
90667604119Stb 	der = NULL;
90767604119Stb 	if ((der_len = i2d_ECPKParameters(group, &der)) <= 0) {
908194b9aa8Stb 		fprintf(stderr, "FAIL: %s i2d_ECPKParameters (named)\n",
909ae66052dStb 		    curve->descr);
91067604119Stb 		ERR_print_errors_fp(stderr);
91167604119Stb 		goto err;
91267604119Stb 	}
91367604119Stb 
91483e2e67dStb 	if (compare_data(curve->descr, der, der_len,
91583e2e67dStb 	    curve->named, curve->named_len) == -1)
91667604119Stb 		goto err;
91767604119Stb 
91867604119Stb 	freezero(der, der_len);
91967604119Stb 	der = NULL;
92067604119Stb 
921194b9aa8Stb 	/* Explicit curve parameter encoding should work without NID set. */
922194b9aa8Stb 	EC_GROUP_set_curve_name(group, NID_undef);
923194b9aa8Stb 	EC_GROUP_set_asn1_flag(group, OPENSSL_EC_EXPLICIT_CURVE);
924194b9aa8Stb 
925194b9aa8Stb 	der = NULL;
926194b9aa8Stb 	if ((der_len = i2d_ECPKParameters(group, &der)) <= 0) {
927194b9aa8Stb 		fprintf(stderr, "FAIL: i2d_ECPKParameters (explicit) %s\n",
928ae66052dStb 		    curve->descr);
929194b9aa8Stb 		ERR_print_errors_fp(stderr);
930194b9aa8Stb 		goto err;
931194b9aa8Stb 	}
932194b9aa8Stb 
933ae66052dStb 	if (compare_data(curve->descr, der, der_len,
934194b9aa8Stb 	    curve->param, curve->param_len) == -1)
935194b9aa8Stb 		goto err;
936194b9aa8Stb 
937194b9aa8Stb 	freezero(der, der_len);
938194b9aa8Stb 	der = NULL;
939194b9aa8Stb 
94067604119Stb 	/* At this point we should have no error on the stack. */
94167604119Stb 	if (ERR_peek_last_error() != 0) {
942ae66052dStb 		fprintf(stderr, "FAIL: %s unexpected error %lu\n", curve->descr,
94367604119Stb 		    ERR_peek_last_error());
94467604119Stb 		goto err;
94567604119Stb 	}
94667604119Stb 
947194b9aa8Stb 	pder = curve->named;
948194b9aa8Stb 	der_len = curve->named_len;
949dc9810dbStb 	new_group = d2i_ECPKParameters(NULL, &pder, der_len);
950dc9810dbStb 	if (!curve->known_named_curve && new_group != NULL) {
951194b9aa8Stb 		fprintf(stderr, "FAIL: managed to decode unknown named curve %s\n",
952ae66052dStb 		    curve->descr);
95367604119Stb 		goto err;
95467604119Stb 	}
955dc9810dbStb 	EC_GROUP_free(new_group);
956dc9810dbStb 	new_group = NULL;
9575ae9088aStb #ifndef OPENSSL_SUPPRESS_DEPRECATED
95867604119Stb 	error = ERR_get_error();
959dc9810dbStb 	if (!curve->known_named_curve &&
960dc9810dbStb 	    ERR_GET_REASON(error) != EC_R_UNKNOWN_GROUP) {
96167604119Stb 		fprintf(stderr, "FAIL: %s unexpected error: want %d, got %d\n",
962ae66052dStb 		    curve->descr, EC_R_UNKNOWN_GROUP, ERR_GET_REASON(error));
96367604119Stb 		goto err;
96467604119Stb 	}
9655ae9088aStb #endif
96667604119Stb 
96767604119Stb 	ERR_clear_error();
9681634662bStb 
969194b9aa8Stb 	pder = curve->param;
970194b9aa8Stb 	der_len = curve->param_len;
97167604119Stb 	if ((new_group = d2i_ECPKParameters(NULL, &pder, der_len)) != NULL) {
972194b9aa8Stb 		fprintf(stderr, "FAIL: managed to decode non-builtin parameters %s\n",
973ae66052dStb 		    curve->descr);
97467604119Stb 		goto err;
97567604119Stb 	}
97667604119Stb 
9775ae9088aStb #ifndef OPENSSL_SUPPRESS_DEPRECATED
97867604119Stb 	error = ERR_peek_last_error();
97967604119Stb 	if (ERR_GET_REASON(error) != EC_R_PKPARAMETERS2GROUP_FAILURE) {
98067604119Stb 		fprintf(stderr, "FAIL: %s unexpected error: want %d, got %d\n",
981ae66052dStb 		    curve->descr, EC_R_UNKNOWN_GROUP, ERR_GET_REASON(error));
98267604119Stb 		goto err;
98367604119Stb 	}
9845ae9088aStb #endif
98567604119Stb 
98667604119Stb 	failed = 0;
98767604119Stb 
98867604119Stb  err:
98967604119Stb 	BN_CTX_end(ctx);
99067604119Stb 
99167604119Stb 	EC_GROUP_free(group);
99267604119Stb 	EC_GROUP_free(new_group);
99367604119Stb 
99467604119Stb 	freezero(der, der_len);
99567604119Stb 
99667604119Stb 	return failed;
99767604119Stb }
99867604119Stb 
999194b9aa8Stb static int
1000194b9aa8Stb ec_group_non_builtin_curves(void)
1001194b9aa8Stb {
1002194b9aa8Stb 	BN_CTX *ctx;
1003194b9aa8Stb 	int failed = 0;
1004194b9aa8Stb 
1005194b9aa8Stb 	if ((ctx = BN_CTX_new()) == NULL)
1006194b9aa8Stb 		errx(1, "BN_CTX_new");
1007194b9aa8Stb 
1008194b9aa8Stb 	failed |= ec_group_non_builtin_curve(&wei25519, EC_GFp_mont_method(), ctx);
1009194b9aa8Stb 	failed |= ec_group_non_builtin_curve(&wei25519, EC_GFp_simple_method(), ctx);
1010194b9aa8Stb 
1011ae66052dStb 	failed |= ec_group_non_builtin_curve(&wei25519_2, EC_GFp_mont_method(), ctx);
1012ae66052dStb 	failed |= ec_group_non_builtin_curve(&wei25519_2, EC_GFp_simple_method(), ctx);
1013ae66052dStb 
1014ae66052dStb 	failed |= ec_group_non_builtin_curve(&wei25519_3, EC_GFp_mont_method(), ctx);
1015ae66052dStb 	failed |= ec_group_non_builtin_curve(&wei25519_3, EC_GFp_simple_method(), ctx);
1016ae66052dStb 
1017aea18883Stb #if NEGATIVE_CURVE_COEFFICIENTS_ALLOWED
1018aea18883Stb 	failed |= ec_group_non_builtin_curve(&wei25519_3_neg, EC_GFp_mont_method(), ctx);
1019aea18883Stb 	failed |= ec_group_non_builtin_curve(&wei25519_3_neg, EC_GFp_simple_method(), ctx);
1020aea18883Stb #endif
1021aea18883Stb 
1022dc9810dbStb 	failed |= ec_group_non_builtin_curve(&secp256k1_m, EC_GFp_mont_method(), ctx);
1023dc9810dbStb 	failed |= ec_group_non_builtin_curve(&secp256k1_m, EC_GFp_simple_method(), ctx);
1024dc9810dbStb 
1025194b9aa8Stb 	BN_CTX_free(ctx);
1026194b9aa8Stb 
1027194b9aa8Stb 	return failed;
1028194b9aa8Stb }
1029194b9aa8Stb 
1030da4fd04eStb static const struct ec_private_key {
1031da4fd04eStb 	const char *name;
1032da4fd04eStb 	size_t der_len;
1033da4fd04eStb 	uint8_t der[256];
1034683169a9Stb 	const char *hex;
1035683169a9Stb 	int oct_len;
1036683169a9Stb 	uint8_t oct[256];
1037da4fd04eStb } ec_private_keys[] = {
1038da4fd04eStb 	{
1039da4fd04eStb 		.name = "secp224k1",
1040da4fd04eStb 		.der_len = 107,
1041da4fd04eStb 		.der = {
1042da4fd04eStb 			0x30, 0x69, 0x02, 0x01, 0x01, 0x04, 0x1d, 0x00,
1043da4fd04eStb 			0x32, 0x2b, 0x6d, 0xe3, 0x62, 0x60, 0xda, 0xb2,
1044da4fd04eStb 			0x62, 0x0a, 0x38, 0x3e, 0xd3, 0x8c, 0x70, 0x9e,
1045da4fd04eStb 			0x76, 0x38, 0xac, 0x26, 0x17, 0xa9, 0x00, 0xdf,
1046da4fd04eStb 			0xfb, 0x1e, 0xf3, 0xbd, 0xa0, 0x07, 0x06, 0x05,
1047da4fd04eStb 			0x2b, 0x81, 0x04, 0x00, 0x20, 0xa1, 0x3c, 0x03,
1048da4fd04eStb 			0x3a, 0x00, 0x04, 0x51, 0xc4, 0x69, 0xdf, 0x2d,
1049da4fd04eStb 			0x49, 0x7b, 0x05, 0x6c, 0x12, 0x5f, 0x9a, 0x83,
1050da4fd04eStb 			0x51, 0x7d, 0xf3, 0x4a, 0x6c, 0xe1, 0x3a, 0xea,
1051da4fd04eStb 			0x44, 0x35, 0x3e, 0x7a, 0xa4, 0x40, 0xdf, 0xc4,
1052da4fd04eStb 			0x90, 0x18, 0xfc, 0x2f, 0x5d, 0x4b, 0x12, 0x37,
1053da4fd04eStb 			0x87, 0x4d, 0x2a, 0xf8, 0xbd, 0x29, 0xfb, 0x13,
1054da4fd04eStb 			0x34, 0xef, 0xfb, 0x04, 0xa1, 0x28, 0x7d, 0x51,
1055da4fd04eStb 			0xbe, 0xe7, 0x0b,
1056da4fd04eStb 		},
1057683169a9Stb 		.hex =	"0451C469DF2D497B"
1058683169a9Stb 			"056C125F9A83517D"
1059683169a9Stb 			"F34A6CE13AEA4435"
1060683169a9Stb 			"3E7AA440DFC49018"
1061683169a9Stb 			"FC2F5D4B1237874D"
1062683169a9Stb 			"2AF8BD29FB1334EF"
1063683169a9Stb 			"FB04A1287D51BEE7"
1064683169a9Stb 			"0B",
1065683169a9Stb 		.oct_len = 57,
1066683169a9Stb 		.oct = {
1067683169a9Stb 			0x04, 0x51, 0xc4, 0x69, 0xdf, 0x2d, 0x49, 0x7b,
1068683169a9Stb 			0x05, 0x6c, 0x12, 0x5f, 0x9a, 0x83, 0x51, 0x7d,
1069683169a9Stb 			0xf3, 0x4a, 0x6c, 0xe1, 0x3a, 0xea, 0x44, 0x35,
1070683169a9Stb 			0x3e, 0x7a, 0xa4, 0x40, 0xdf, 0xc4, 0x90, 0x18,
1071683169a9Stb 			0xfc, 0x2f, 0x5d, 0x4b, 0x12, 0x37, 0x87, 0x4d,
1072683169a9Stb 			0x2a, 0xf8, 0xbd, 0x29, 0xfb, 0x13, 0x34, 0xef,
1073683169a9Stb 			0xfb, 0x04, 0xa1, 0x28, 0x7d, 0x51, 0xbe, 0xe7,
1074683169a9Stb 			0x0b,
1075683169a9Stb 		},
1076da4fd04eStb 	},
1077da4fd04eStb 	{
1078da4fd04eStb 		.name = "secp224r1",
1079da4fd04eStb 		.der_len = 106,
1080da4fd04eStb 		.der = {
1081da4fd04eStb 			0x30, 0x68, 0x02, 0x01, 0x01, 0x04, 0x1c, 0x76,
1082da4fd04eStb 			0x9b, 0x2f, 0x62, 0xff, 0x5f, 0x84, 0x6c, 0x7e,
1083da4fd04eStb 			0x90, 0xda, 0xfb, 0x70, 0x62, 0xc1, 0xb9, 0xa2,
1084da4fd04eStb 			0xc9, 0xf7, 0x1b, 0x76, 0x7f, 0xbb, 0xb1, 0xd4,
1085da4fd04eStb 			0xa4, 0xa0, 0x42, 0xa0, 0x07, 0x06, 0x05, 0x2b,
1086da4fd04eStb 			0x81, 0x04, 0x00, 0x21, 0xa1, 0x3c, 0x03, 0x3a,
1087da4fd04eStb 			0x00, 0x04, 0x94, 0x84, 0xb0, 0xcd, 0x65, 0xef,
1088da4fd04eStb 			0xc5, 0x5d, 0xc9, 0xe4, 0x91, 0x71, 0xcb, 0xc7,
1089da4fd04eStb 			0xf1, 0x8e, 0x44, 0x39, 0xc2, 0xd3, 0x07, 0xf0,
1090da4fd04eStb 			0x6c, 0xb6, 0xef, 0x77, 0xc0, 0x84, 0x30, 0x2c,
1091da4fd04eStb 			0xd2, 0xf2, 0xf0, 0xb5, 0xb6, 0x6f, 0x0a, 0xf4,
1092da4fd04eStb 			0x43, 0xab, 0x5e, 0x5d, 0xd8, 0x97, 0xbf, 0xab,
1093da4fd04eStb 			0xf4, 0x2d, 0x34, 0x25, 0xee, 0x4c, 0xec, 0xfb,
1094da4fd04eStb 			0x4d, 0x0b,
1095da4fd04eStb 		},
1096683169a9Stb 		.hex =	"049484B0CD65EFC5"
1097683169a9Stb 			"5DC9E49171CBC7F1"
1098683169a9Stb 			"8E4439C2D307F06C"
1099683169a9Stb 			"B6EF77C084302CD2"
1100683169a9Stb 			"F2F0B5B66F0AF443"
1101683169a9Stb 			"AB5E5DD897BFABF4"
1102683169a9Stb 			"2D3425EE4CECFB4D"
1103683169a9Stb 			"0B",
1104683169a9Stb 		.oct_len = 57,
1105683169a9Stb 		.oct = {
1106683169a9Stb 			0x04, 0x94, 0x84, 0xb0, 0xcd, 0x65, 0xef, 0xc5,
1107683169a9Stb 			0x5d, 0xc9, 0xe4, 0x91, 0x71, 0xcb, 0xc7, 0xf1,
1108683169a9Stb 			0x8e, 0x44, 0x39, 0xc2, 0xd3, 0x07, 0xf0, 0x6c,
1109683169a9Stb 			0xb6, 0xef, 0x77, 0xc0, 0x84, 0x30, 0x2c, 0xd2,
1110683169a9Stb 			0xf2, 0xf0, 0xb5, 0xb6, 0x6f, 0x0a, 0xf4, 0x43,
1111683169a9Stb 			0xab, 0x5e, 0x5d, 0xd8, 0x97, 0xbf, 0xab, 0xf4,
1112683169a9Stb 			0x2d, 0x34, 0x25, 0xee, 0x4c, 0xec, 0xfb, 0x4d,
1113683169a9Stb 			0x0b,
1114683169a9Stb 		},
1115da4fd04eStb 	},
1116da4fd04eStb 	{
1117da4fd04eStb 		.name = "secp256k1",
1118da4fd04eStb 		.der_len = 118,
1119da4fd04eStb 		.der = {
1120da4fd04eStb 			0x30, 0x74, 0x02, 0x01, 0x01, 0x04, 0x20, 0xf2,
1121da4fd04eStb 			0xe5, 0x5c, 0x24, 0x66, 0x01, 0x2b, 0x95, 0x96,
1122da4fd04eStb 			0xbf, 0xbd, 0x0e, 0x33, 0x3d, 0xfd, 0x8a, 0x22,
1123da4fd04eStb 			0x79, 0x12, 0xc5, 0x93, 0x28, 0x1b, 0x74, 0x39,
1124da4fd04eStb 			0x61, 0x80, 0x1c, 0x17, 0xb1, 0x36, 0xab, 0xa0,
1125da4fd04eStb 			0x07, 0x06, 0x05, 0x2b, 0x81, 0x04, 0x00, 0x0a,
1126da4fd04eStb 			0xa1, 0x44, 0x03, 0x42, 0x00, 0x04, 0x9f, 0xd2,
1127da4fd04eStb 			0xbe, 0xcc, 0xf8, 0x00, 0xe8, 0xd0, 0x40, 0x73,
1128da4fd04eStb 			0x11, 0xb9, 0x34, 0x76, 0x68, 0xb2, 0x6b, 0x88,
1129da4fd04eStb 			0xea, 0xa6, 0x64, 0x37, 0xe7, 0x06, 0xdf, 0x9f,
1130da4fd04eStb 			0x20, 0xb8, 0xc3, 0x7f, 0x9f, 0x8f, 0xbc, 0x80,
1131da4fd04eStb 			0x65, 0xe9, 0x73, 0xcb, 0x1d, 0xa1, 0xfa, 0x34,
1132da4fd04eStb 			0x23, 0x66, 0xb9, 0x47, 0x89, 0xe9, 0x08, 0x92,
1133da4fd04eStb 			0x5e, 0xb5, 0x37, 0x44, 0x40, 0x1c, 0x34, 0x6c,
1134da4fd04eStb 			0xf2, 0xdb, 0x44, 0x71, 0x26, 0xeb,
1135da4fd04eStb 		},
1136683169a9Stb 		.hex =	"049FD2BECCF800E8"
1137683169a9Stb 			"D0407311B9347668"
1138683169a9Stb 			"B26B88EAA66437E7"
1139683169a9Stb 			"06DF9F20B8C37F9F"
1140683169a9Stb 			"8FBC8065E973CB1D"
1141683169a9Stb 			"A1FA342366B94789"
1142683169a9Stb 			"E908925EB5374440"
1143683169a9Stb 			"1C346CF2DB447126"
1144683169a9Stb 			"EB",
1145683169a9Stb 		.oct_len = 65,
1146683169a9Stb 		.oct = {
1147683169a9Stb 			0x04, 0x9f, 0xd2, 0xbe, 0xcc, 0xf8, 0x00, 0xe8,
1148683169a9Stb 			0xd0, 0x40, 0x73, 0x11, 0xb9, 0x34, 0x76, 0x68,
1149683169a9Stb 			0xb2, 0x6b, 0x88, 0xea, 0xa6, 0x64, 0x37, 0xe7,
1150683169a9Stb 			0x06, 0xdf, 0x9f, 0x20, 0xb8, 0xc3, 0x7f, 0x9f,
1151683169a9Stb 			0x8f, 0xbc, 0x80, 0x65, 0xe9, 0x73, 0xcb, 0x1d,
1152683169a9Stb 			0xa1, 0xfa, 0x34, 0x23, 0x66, 0xb9, 0x47, 0x89,
1153683169a9Stb 			0xe9, 0x08, 0x92, 0x5e, 0xb5, 0x37, 0x44, 0x40,
1154683169a9Stb 			0x1c, 0x34, 0x6c, 0xf2, 0xdb, 0x44, 0x71, 0x26,
1155683169a9Stb 			0xeb,
1156683169a9Stb 		},
1157da4fd04eStb 	},
1158da4fd04eStb 	{
1159da4fd04eStb 		.name = "secp384r1",
1160da4fd04eStb 		.der_len = 167,
1161da4fd04eStb 		.der = {
1162da4fd04eStb 			0x30, 0x81, 0xa4, 0x02, 0x01, 0x01, 0x04, 0x30,
1163da4fd04eStb 			0xa0, 0xd3, 0x78, 0x23, 0x51, 0xe1, 0x20, 0x5c,
1164da4fd04eStb 			0xbe, 0x84, 0x11, 0x2f, 0x82, 0x55, 0xfc, 0xd1,
1165da4fd04eStb 			0x5d, 0xae, 0xfc, 0x72, 0x60, 0x50, 0x3c, 0x2d,
1166da4fd04eStb 			0x70, 0xb4, 0x00, 0xe2, 0xe6, 0x0a, 0xdf, 0xc5,
1167da4fd04eStb 			0x56, 0xe6, 0xb8, 0x69, 0xf8, 0xad, 0xf5, 0xfc,
1168da4fd04eStb 			0x95, 0xb3, 0x5b, 0x3d, 0xda, 0x6c, 0x5f, 0x74,
1169da4fd04eStb 			0xa0, 0x07, 0x06, 0x05, 0x2b, 0x81, 0x04, 0x00,
1170da4fd04eStb 			0x22, 0xa1, 0x64, 0x03, 0x62, 0x00, 0x04, 0xce,
1171da4fd04eStb 			0x9a, 0x3b, 0x4b, 0x01, 0xe6, 0xc4, 0x5a, 0xfa,
1172da4fd04eStb 			0x97, 0x03, 0xc1, 0xce, 0x18, 0xd5, 0x6c, 0x47,
1173da4fd04eStb 			0x27, 0x4d, 0x6c, 0x9a, 0xbd, 0x47, 0xab, 0x20,
1174da4fd04eStb 			0x0f, 0x99, 0x83, 0x19, 0x8b, 0xcb, 0x18, 0xd7,
1175da4fd04eStb 			0xa3, 0xb2, 0xe7, 0x3b, 0xd0, 0xf1, 0xf3, 0x29,
1176da4fd04eStb 			0xb2, 0x6d, 0x38, 0xd6, 0xcc, 0x8e, 0x5e, 0xf0,
1177da4fd04eStb 			0xb2, 0xb9, 0xbd, 0x85, 0x2c, 0xab, 0x4b, 0xb6,
1178da4fd04eStb 			0x9d, 0x98, 0xa1, 0xce, 0xf1, 0x8a, 0xdb, 0x92,
1179da4fd04eStb 			0x75, 0x7d, 0xf7, 0x82, 0x4c, 0x0a, 0xc7, 0x3b,
1180da4fd04eStb 			0x52, 0x6e, 0x97, 0xc6, 0x23, 0xc9, 0x6f, 0x3f,
1181da4fd04eStb 			0xe5, 0xd2, 0xa2, 0x79, 0x47, 0xb0, 0x6e, 0x5f,
1182da4fd04eStb 			0x85, 0x39, 0x94, 0x57, 0xbf, 0x54, 0x76,
1183da4fd04eStb 		},
1184683169a9Stb 		.hex =	"04CE9A3B4B01E6C4"
1185683169a9Stb 			"5AFA9703C1CE18D5"
1186683169a9Stb 			"6C47274D6C9ABD47"
1187683169a9Stb 			"AB200F9983198BCB"
1188683169a9Stb 			"18D7A3B2E73BD0F1"
1189683169a9Stb 			"F329B26D38D6CC8E"
1190683169a9Stb 			"5EF0B2B9BD852CAB"
1191683169a9Stb 			"4BB69D98A1CEF18A"
1192683169a9Stb 			"DB92757DF7824C0A"
1193683169a9Stb 			"C73B526E97C623C9"
1194683169a9Stb 			"6F3FE5D2A27947B0"
1195683169a9Stb 			"6E5F85399457BF54"
1196683169a9Stb 			"76",
1197683169a9Stb 		.oct_len = 97,
1198683169a9Stb 		.oct = {
1199683169a9Stb 			0x04, 0xce, 0x9a, 0x3b, 0x4b, 0x01, 0xe6, 0xc4,
1200683169a9Stb 			0x5a, 0xfa, 0x97, 0x03, 0xc1, 0xce, 0x18, 0xd5,
1201683169a9Stb 			0x6c, 0x47, 0x27, 0x4d, 0x6c, 0x9a, 0xbd, 0x47,
1202683169a9Stb 			0xab, 0x20, 0x0f, 0x99, 0x83, 0x19, 0x8b, 0xcb,
1203683169a9Stb 			0x18, 0xd7, 0xa3, 0xb2, 0xe7, 0x3b, 0xd0, 0xf1,
1204683169a9Stb 			0xf3, 0x29, 0xb2, 0x6d, 0x38, 0xd6, 0xcc, 0x8e,
1205683169a9Stb 			0x5e, 0xf0, 0xb2, 0xb9, 0xbd, 0x85, 0x2c, 0xab,
1206683169a9Stb 			0x4b, 0xb6, 0x9d, 0x98, 0xa1, 0xce, 0xf1, 0x8a,
1207683169a9Stb 			0xdb, 0x92, 0x75, 0x7d, 0xf7, 0x82, 0x4c, 0x0a,
1208683169a9Stb 			0xc7, 0x3b, 0x52, 0x6e, 0x97, 0xc6, 0x23, 0xc9,
1209683169a9Stb 			0x6f, 0x3f, 0xe5, 0xd2, 0xa2, 0x79, 0x47, 0xb0,
1210683169a9Stb 			0x6e, 0x5f, 0x85, 0x39, 0x94, 0x57, 0xbf, 0x54,
1211683169a9Stb 			0x76,
1212683169a9Stb 		},
1213da4fd04eStb 	},
1214da4fd04eStb 	{
1215da4fd04eStb 		.name = "secp521r1",
1216da4fd04eStb 		.der_len = 223,
1217da4fd04eStb 		.der = {
1218da4fd04eStb 			0x30, 0x81, 0xdc, 0x02, 0x01, 0x01, 0x04, 0x42,
1219da4fd04eStb 			0x01, 0x6e, 0xff, 0x5d, 0x18, 0x50, 0x5b, 0x09,
1220da4fd04eStb 			0xf8, 0x38, 0x10, 0x6c, 0x54, 0x19, 0x59, 0xdb,
1221da4fd04eStb 			0x30, 0xc5, 0x60, 0x28, 0xb1, 0x7f, 0xba, 0x22,
1222da4fd04eStb 			0x06, 0x4d, 0x8a, 0x69, 0x53, 0xb0, 0xc5, 0x8f,
1223da4fd04eStb 			0x17, 0x4d, 0x51, 0xc6, 0x2f, 0x41, 0x4e, 0xf0,
1224da4fd04eStb 			0xab, 0xb4, 0x3a, 0x8f, 0x00, 0x6f, 0x32, 0xe7,
1225da4fd04eStb 			0xe6, 0x56, 0xb7, 0xe9, 0xb1, 0xcd, 0x3a, 0x93,
1226da4fd04eStb 			0xe6, 0x8f, 0xe6, 0x60, 0xb6, 0x80, 0xbd, 0x02,
1227da4fd04eStb 			0xfb, 0x90, 0xa0, 0x07, 0x06, 0x05, 0x2b, 0x81,
1228da4fd04eStb 			0x04, 0x00, 0x23, 0xa1, 0x81, 0x89, 0x03, 0x81,
1229da4fd04eStb 			0x86, 0x00, 0x04, 0x01, 0xd2, 0xc3, 0x78, 0x41,
1230da4fd04eStb 			0xb1, 0x86, 0x24, 0xca, 0x6d, 0x80, 0x5c, 0x97,
1231da4fd04eStb 			0xcf, 0x96, 0xf0, 0x87, 0xb4, 0x25, 0xbe, 0x37,
1232da4fd04eStb 			0x9a, 0xf3, 0xe5, 0x4a, 0x70, 0xd1, 0xe6, 0x36,
1233da4fd04eStb 			0x9e, 0x69, 0xcc, 0xfb, 0x83, 0xd6, 0xa1, 0x62,
1234da4fd04eStb 			0x6d, 0xa8, 0xe6, 0xca, 0xe7, 0x0e, 0x24, 0xe6,
1235da4fd04eStb 			0x26, 0xcd, 0xc0, 0x0d, 0x2a, 0x01, 0x81, 0x6a,
1236da4fd04eStb 			0xd6, 0x94, 0xf2, 0x90, 0xcd, 0x26, 0x68, 0x28,
1237da4fd04eStb 			0x2c, 0x57, 0xd3, 0xf0, 0x37, 0x00, 0xbc, 0x5e,
1238da4fd04eStb 			0xfa, 0xf9, 0x36, 0xcd, 0x0f, 0xeb, 0x4f, 0x82,
1239da4fd04eStb 			0x17, 0x6a, 0xa0, 0x73, 0xd2, 0x48, 0xfc, 0xfb,
1240da4fd04eStb 			0xf0, 0x54, 0xc3, 0x23, 0x29, 0x76, 0xc7, 0x21,
1241da4fd04eStb 			0x98, 0x09, 0x29, 0x8b, 0xce, 0x6e, 0x6b, 0xe3,
1242da4fd04eStb 			0x97, 0x94, 0xb2, 0x30, 0xaa, 0xf6, 0x43, 0x5c,
1243da4fd04eStb 			0x15, 0xd7, 0xb8, 0xdb, 0x06, 0x92, 0xa8, 0x36,
1244da4fd04eStb 			0x8f, 0x89, 0xb6, 0x39, 0x2c, 0x2c, 0x23, 0x0a,
1245da4fd04eStb 			0xb6, 0x95, 0x9c, 0x6b, 0xce, 0xc4, 0x8e,
1246da4fd04eStb 		},
1247683169a9Stb 		.hex =	"0401D2C37841B186"
1248683169a9Stb 			"24CA6D805C97CF96"
1249683169a9Stb 			"F087B425BE379AF3"
1250683169a9Stb 			"E54A70D1E6369E69"
1251683169a9Stb 			"CCFB83D6A1626DA8"
1252683169a9Stb 			"E6CAE70E24E626CD"
1253683169a9Stb 			"C00D2A01816AD694"
1254683169a9Stb 			"F290CD2668282C57"
1255683169a9Stb 			"D3F03700BC5EFAF9"
1256683169a9Stb 			"36CD0FEB4F82176A"
1257683169a9Stb 			"A073D248FCFBF054"
1258683169a9Stb 			"C3232976C7219809"
1259683169a9Stb 			"298BCE6E6BE39794"
1260683169a9Stb 			"B230AAF6435C15D7"
1261683169a9Stb 			"B8DB0692A8368F89"
1262683169a9Stb 			"B6392C2C230AB695"
1263683169a9Stb 			"9C6BCEC48E",
1264683169a9Stb 		.oct_len = 133,
1265683169a9Stb 		.oct = {
1266683169a9Stb 			0x04, 0x01, 0xd2, 0xc3, 0x78, 0x41, 0xb1, 0x86,
1267683169a9Stb 			0x24, 0xca, 0x6d, 0x80, 0x5c, 0x97, 0xcf, 0x96,
1268683169a9Stb 			0xf0, 0x87, 0xb4, 0x25, 0xbe, 0x37, 0x9a, 0xf3,
1269683169a9Stb 			0xe5, 0x4a, 0x70, 0xd1, 0xe6, 0x36, 0x9e, 0x69,
1270683169a9Stb 			0xcc, 0xfb, 0x83, 0xd6, 0xa1, 0x62, 0x6d, 0xa8,
1271683169a9Stb 			0xe6, 0xca, 0xe7, 0x0e, 0x24, 0xe6, 0x26, 0xcd,
1272683169a9Stb 			0xc0, 0x0d, 0x2a, 0x01, 0x81, 0x6a, 0xd6, 0x94,
1273683169a9Stb 			0xf2, 0x90, 0xcd, 0x26, 0x68, 0x28, 0x2c, 0x57,
1274683169a9Stb 			0xd3, 0xf0, 0x37, 0x00, 0xbc, 0x5e, 0xfa, 0xf9,
1275683169a9Stb 			0x36, 0xcd, 0x0f, 0xeb, 0x4f, 0x82, 0x17, 0x6a,
1276683169a9Stb 			0xa0, 0x73, 0xd2, 0x48, 0xfc, 0xfb, 0xf0, 0x54,
1277683169a9Stb 			0xc3, 0x23, 0x29, 0x76, 0xc7, 0x21, 0x98, 0x09,
1278683169a9Stb 			0x29, 0x8b, 0xce, 0x6e, 0x6b, 0xe3, 0x97, 0x94,
1279683169a9Stb 			0xb2, 0x30, 0xaa, 0xf6, 0x43, 0x5c, 0x15, 0xd7,
1280683169a9Stb 			0xb8, 0xdb, 0x06, 0x92, 0xa8, 0x36, 0x8f, 0x89,
1281683169a9Stb 			0xb6, 0x39, 0x2c, 0x2c, 0x23, 0x0a, 0xb6, 0x95,
1282683169a9Stb 			0x9c, 0x6b, 0xce, 0xc4, 0x8e,
1283683169a9Stb 		},
1284da4fd04eStb 	},
1285da4fd04eStb 	{
1286da4fd04eStb 		.name = "prime239v1",
1287da4fd04eStb 		.der_len = 115,
1288da4fd04eStb 		.der = {
1289da4fd04eStb 			0x30, 0x71, 0x02, 0x01, 0x01, 0x04, 0x1e, 0x6e,
1290da4fd04eStb 			0x26, 0x5e, 0xde, 0x5b, 0x67, 0xd6, 0x38, 0x52,
1291da4fd04eStb 			0xe7, 0x1e, 0x8d, 0x44, 0xb1, 0xfb, 0xf8, 0xaf,
1292da4fd04eStb 			0xf9, 0x94, 0x2c, 0xe2, 0x0d, 0xa8, 0x5f, 0x03,
1293da4fd04eStb 			0x67, 0x53, 0x7b, 0x8b, 0x2e, 0xa0, 0x0a, 0x06,
1294da4fd04eStb 			0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01,
1295da4fd04eStb 			0x04, 0xa1, 0x40, 0x03, 0x3e, 0x00, 0x04, 0x33,
1296da4fd04eStb 			0xc6, 0xe5, 0x8a, 0xc1, 0x8b, 0x7c, 0x96, 0x19,
1297da4fd04eStb 			0xc9, 0xe1, 0x54, 0x7f, 0x81, 0x9e, 0x59, 0x62,
1298da4fd04eStb 			0xec, 0xc0, 0x1e, 0xe5, 0x53, 0xd5, 0xae, 0x6b,
1299da4fd04eStb 			0xd3, 0xe0, 0x09, 0x07, 0xc5, 0x27, 0x81, 0xa6,
1300da4fd04eStb 			0x8d, 0x39, 0x8e, 0xfe, 0x01, 0xc2, 0x1d, 0xda,
1301da4fd04eStb 			0xde, 0x7b, 0xdc, 0x76, 0x27, 0x17, 0xf9, 0x6f,
1302da4fd04eStb 			0xe3, 0x04, 0xef, 0x5d, 0x65, 0x75, 0x98, 0x7f,
1303da4fd04eStb 			0x2d, 0xd0, 0x68,
1304da4fd04eStb 		},
1305683169a9Stb 		.hex =	"0433C6E58AC18B7C"
1306683169a9Stb 			"9619C9E1547F819E"
1307683169a9Stb 			"5962ECC01EE553D5"
1308683169a9Stb 			"AE6BD3E00907C527"
1309683169a9Stb 			"81A68D398EFE01C2"
1310683169a9Stb 			"1DDADE7BDC762717"
1311683169a9Stb 			"F96FE304EF5D6575"
1312683169a9Stb 			"987F2DD068",
1313683169a9Stb 		.oct_len = 61,
1314683169a9Stb 		.oct = {
1315683169a9Stb 			0x04, 0x33, 0xc6, 0xe5, 0x8a, 0xc1, 0x8b, 0x7c,
1316683169a9Stb 			0x96, 0x19, 0xc9, 0xe1, 0x54, 0x7f, 0x81, 0x9e,
1317683169a9Stb 			0x59, 0x62, 0xec, 0xc0, 0x1e, 0xe5, 0x53, 0xd5,
1318683169a9Stb 			0xae, 0x6b, 0xd3, 0xe0, 0x09, 0x07, 0xc5, 0x27,
1319683169a9Stb 			0x81, 0xa6, 0x8d, 0x39, 0x8e, 0xfe, 0x01, 0xc2,
1320683169a9Stb 			0x1d, 0xda, 0xde, 0x7b, 0xdc, 0x76, 0x27, 0x17,
1321683169a9Stb 			0xf9, 0x6f, 0xe3, 0x04, 0xef, 0x5d, 0x65, 0x75,
1322683169a9Stb 			0x98, 0x7f, 0x2d, 0xd0, 0x68,
1323683169a9Stb 		},
1324da4fd04eStb 	},
1325da4fd04eStb 	{
1326da4fd04eStb 		.name = "prime239v2",
1327da4fd04eStb 		.der_len = 115,
1328da4fd04eStb 		.der = {
1329da4fd04eStb 			0x30, 0x71, 0x02, 0x01, 0x01, 0x04, 0x1e, 0x30,
1330da4fd04eStb 			0x2f, 0x01, 0x10, 0xe9, 0x09, 0x15, 0xdd, 0xe3,
1331da4fd04eStb 			0xdd, 0xae, 0xcb, 0x9d, 0x3a, 0x58, 0x92, 0x02,
1332da4fd04eStb 			0x1e, 0x6e, 0x02, 0x57, 0xa8, 0x36, 0x0b, 0x20,
1333da4fd04eStb 			0x0b, 0x7e, 0xf4, 0xad, 0x0b, 0xa0, 0x0a, 0x06,
1334da4fd04eStb 			0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01,
1335da4fd04eStb 			0x05, 0xa1, 0x40, 0x03, 0x3e, 0x00, 0x04, 0x3c,
1336da4fd04eStb 			0x10, 0x27, 0x7b, 0xac, 0xdf, 0x86, 0xc9, 0x4f,
1337da4fd04eStb 			0xf8, 0x39, 0x87, 0x02, 0x39, 0xaf, 0x41, 0xbc,
1338da4fd04eStb 			0x4b, 0x67, 0xd8, 0x5e, 0x04, 0x96, 0x84, 0xb5,
1339da4fd04eStb 			0x60, 0x50, 0x48, 0x6a, 0x20, 0x1d, 0x2b, 0x7e,
1340da4fd04eStb 			0x9f, 0xaf, 0xf8, 0x8e, 0x7e, 0xa4, 0xcd, 0x00,
1341da4fd04eStb 			0xad, 0xb1, 0xad, 0x22, 0x69, 0x32, 0x10, 0x6c,
1342da4fd04eStb 			0xe0, 0xcc, 0xdd, 0x45, 0xd8, 0xa6, 0x29, 0x2f,
1343da4fd04eStb 			0xad, 0x6b, 0xf9,
1344da4fd04eStb 		},
1345683169a9Stb 		.hex =	"043C10277BACDF86"
1346683169a9Stb 			"C94FF839870239AF"
1347683169a9Stb 			"41BC4B67D85E0496"
1348683169a9Stb 			"84B56050486A201D"
1349683169a9Stb 			"2B7E9FAFF88E7EA4"
1350683169a9Stb 			"CD00ADB1AD226932"
1351683169a9Stb 			"106CE0CCDD45D8A6"
1352683169a9Stb 			"292FAD6BF9",
1353683169a9Stb 		.oct_len = 61,
1354683169a9Stb 		.oct = {
1355683169a9Stb 			0x04, 0x3c, 0x10, 0x27, 0x7b, 0xac, 0xdf, 0x86,
1356683169a9Stb 			0xc9, 0x4f, 0xf8, 0x39, 0x87, 0x02, 0x39, 0xaf,
1357683169a9Stb 			0x41, 0xbc, 0x4b, 0x67, 0xd8, 0x5e, 0x04, 0x96,
1358683169a9Stb 			0x84, 0xb5, 0x60, 0x50, 0x48, 0x6a, 0x20, 0x1d,
1359683169a9Stb 			0x2b, 0x7e, 0x9f, 0xaf, 0xf8, 0x8e, 0x7e, 0xa4,
1360683169a9Stb 			0xcd, 0x00, 0xad, 0xb1, 0xad, 0x22, 0x69, 0x32,
1361683169a9Stb 			0x10, 0x6c, 0xe0, 0xcc, 0xdd, 0x45, 0xd8, 0xa6,
1362683169a9Stb 			0x29, 0x2f, 0xad, 0x6b, 0xf9,
1363683169a9Stb 		},
1364da4fd04eStb 	},
1365da4fd04eStb 	{
1366da4fd04eStb 		.name = "prime239v3",
1367da4fd04eStb 		.der_len = 115,
1368da4fd04eStb 		.der = {
1369da4fd04eStb 			0x30, 0x71, 0x02, 0x01, 0x01, 0x04, 0x1e, 0x26,
1370da4fd04eStb 			0x3f, 0x23, 0x4c, 0xe7, 0xbd, 0xa8, 0xe4, 0xfe,
1371da4fd04eStb 			0x7c, 0xf6, 0x18, 0x6a, 0xb2, 0xa6, 0x39, 0x15,
1372da4fd04eStb 			0x6d, 0x72, 0xe8, 0x9e, 0x3f, 0x0f, 0x10, 0x1e,
1373da4fd04eStb 			0xe5, 0xdf, 0xac, 0xe8, 0x2f, 0xa0, 0x0a, 0x06,
1374da4fd04eStb 			0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01,
1375da4fd04eStb 			0x06, 0xa1, 0x40, 0x03, 0x3e, 0x00, 0x04, 0x37,
1376da4fd04eStb 			0xba, 0x07, 0x7f, 0xd9, 0x46, 0x5a, 0x33, 0x03,
1377da4fd04eStb 			0x31, 0x77, 0x38, 0xef, 0xee, 0xcc, 0x3d, 0xe1,
1378da4fd04eStb 			0xaa, 0x57, 0xe3, 0x8d, 0xb7, 0xcd, 0xe3, 0x01,
1379da4fd04eStb 			0xf4, 0xd6, 0x75, 0x49, 0x72, 0x61, 0x4c, 0xbf,
1380da4fd04eStb 			0xc0, 0x1f, 0x8b, 0x5f, 0x98, 0x9b, 0xa7, 0xe5,
1381da4fd04eStb 			0x6a, 0xb7, 0xfe, 0x63, 0xdb, 0xb0, 0x40, 0xcb,
1382da4fd04eStb 			0x26, 0x81, 0x2a, 0x91, 0x14, 0x0f, 0xc7, 0x31,
1383da4fd04eStb 			0x13, 0x78, 0x16,
1384da4fd04eStb 		},
1385683169a9Stb 		.hex =	"0437BA077FD9465A"
1386683169a9Stb 			"3303317738EFEECC"
1387683169a9Stb 			"3DE1AA57E38DB7CD"
1388683169a9Stb 			"E301F4D675497261"
1389683169a9Stb 			"4CBFC01F8B5F989B"
1390683169a9Stb 			"A7E56AB7FE63DBB0"
1391683169a9Stb 			"40CB26812A91140F"
1392683169a9Stb 			"C731137816",
1393683169a9Stb 		.oct_len = 61,
1394683169a9Stb 		.oct = {
1395683169a9Stb 			0x04, 0x37, 0xba, 0x07, 0x7f, 0xd9, 0x46, 0x5a,
1396683169a9Stb 			0x33, 0x03, 0x31, 0x77, 0x38, 0xef, 0xee, 0xcc,
1397683169a9Stb 			0x3d, 0xe1, 0xaa, 0x57, 0xe3, 0x8d, 0xb7, 0xcd,
1398683169a9Stb 			0xe3, 0x01, 0xf4, 0xd6, 0x75, 0x49, 0x72, 0x61,
1399683169a9Stb 			0x4c, 0xbf, 0xc0, 0x1f, 0x8b, 0x5f, 0x98, 0x9b,
1400683169a9Stb 			0xa7, 0xe5, 0x6a, 0xb7, 0xfe, 0x63, 0xdb, 0xb0,
1401683169a9Stb 			0x40, 0xcb, 0x26, 0x81, 0x2a, 0x91, 0x14, 0x0f,
1402683169a9Stb 			0xc7, 0x31, 0x13, 0x78, 0x16,
1403683169a9Stb 		},
1404da4fd04eStb 	},
1405da4fd04eStb 	{
1406da4fd04eStb 		.name = "prime256v1",
1407da4fd04eStb 		.der_len = 121,
1408da4fd04eStb 		.der = {
1409da4fd04eStb 			0x30, 0x77, 0x02, 0x01, 0x01, 0x04, 0x20, 0x6c,
1410da4fd04eStb 			0x83, 0x81, 0x90, 0x65, 0x7b, 0x45, 0x98, 0x66,
1411da4fd04eStb 			0x4b, 0x91, 0x8e, 0xcf, 0x71, 0x61, 0x22, 0xb6,
1412da4fd04eStb 			0xd6, 0x93, 0x74, 0x84, 0xa3, 0xc6, 0x44, 0x71,
1413da4fd04eStb 			0x25, 0xc5, 0xef, 0x77, 0x52, 0xd2, 0x32, 0xa0,
1414da4fd04eStb 			0x0a, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d,
1415da4fd04eStb 			0x03, 0x01, 0x07, 0xa1, 0x44, 0x03, 0x42, 0x00,
1416da4fd04eStb 			0x04, 0x96, 0x8a, 0xc3, 0x66, 0x1e, 0xf7, 0xcf,
1417da4fd04eStb 			0xf6, 0xcc, 0x4e, 0x73, 0xae, 0xe2, 0x64, 0xc4,
1418da4fd04eStb 			0x56, 0x5f, 0x2d, 0xfe, 0xde, 0xac, 0x92, 0xbe,
1419da4fd04eStb 			0x10, 0x40, 0x37, 0xce, 0x24, 0x12, 0x30, 0x19,
1420da4fd04eStb 			0x08, 0x66, 0xcf, 0x90, 0xc9, 0x37, 0x03, 0xd1,
1421da4fd04eStb 			0xd5, 0x8d, 0xaa, 0x18, 0x2a, 0xbc, 0xed, 0x82,
1422da4fd04eStb 			0x32, 0xc9, 0x43, 0x4b, 0x98, 0x7f, 0xdc, 0xb1,
1423da4fd04eStb 			0x0b, 0xa6, 0xdd, 0x16, 0xc5, 0x8d, 0x5a, 0xcf,
1424da4fd04eStb 			0xe3,
1425da4fd04eStb 		},
1426683169a9Stb 		.hex =	"04968AC3661EF7CF"
1427683169a9Stb 			"F6CC4E73AEE264C4"
1428683169a9Stb 			"565F2DFEDEAC92BE"
1429683169a9Stb 			"104037CE24123019"
1430683169a9Stb 			"0866CF90C93703D1"
1431683169a9Stb 			"D58DAA182ABCED82"
1432683169a9Stb 			"32C9434B987FDCB1"
1433683169a9Stb 			"0BA6DD16C58D5ACF"
1434683169a9Stb 			"E3",
1435683169a9Stb 		.oct_len = 65,
1436683169a9Stb 		.oct = {
1437683169a9Stb 			0x04, 0x96, 0x8a, 0xc3, 0x66, 0x1e, 0xf7, 0xcf,
1438683169a9Stb 			0xf6, 0xcc, 0x4e, 0x73, 0xae, 0xe2, 0x64, 0xc4,
1439683169a9Stb 			0x56, 0x5f, 0x2d, 0xfe, 0xde, 0xac, 0x92, 0xbe,
1440683169a9Stb 			0x10, 0x40, 0x37, 0xce, 0x24, 0x12, 0x30, 0x19,
1441683169a9Stb 			0x08, 0x66, 0xcf, 0x90, 0xc9, 0x37, 0x03, 0xd1,
1442683169a9Stb 			0xd5, 0x8d, 0xaa, 0x18, 0x2a, 0xbc, 0xed, 0x82,
1443683169a9Stb 			0x32, 0xc9, 0x43, 0x4b, 0x98, 0x7f, 0xdc, 0xb1,
1444683169a9Stb 			0x0b, 0xa6, 0xdd, 0x16, 0xc5, 0x8d, 0x5a, 0xcf,
1445683169a9Stb 			0xe3,
1446683169a9Stb 		},
1447da4fd04eStb 	},
1448da4fd04eStb 	{
1449da4fd04eStb 		.name = "brainpoolP224r1",
1450da4fd04eStb 		.der_len = 110,
1451da4fd04eStb 		.der = {
1452da4fd04eStb 			0x30, 0x6c, 0x02, 0x01, 0x01, 0x04, 0x1c, 0xae,
1453da4fd04eStb 			0x9c, 0xe1, 0x9c, 0xaf, 0xbd, 0x9d, 0xec, 0x9a,
1454da4fd04eStb 			0xe4, 0xdc, 0x5a, 0x9f, 0xdb, 0x0d, 0x51, 0x65,
1455da4fd04eStb 			0xe2, 0x49, 0xa7, 0x35, 0xea, 0xbc, 0x8b, 0x4a,
1456da4fd04eStb 			0x27, 0xfd, 0xa8, 0xa0, 0x0b, 0x06, 0x09, 0x2b,
1457da4fd04eStb 			0x24, 0x03, 0x03, 0x02, 0x08, 0x01, 0x01, 0x05,
1458da4fd04eStb 			0xa1, 0x3c, 0x03, 0x3a, 0x00, 0x04, 0x30, 0x88,
1459da4fd04eStb 			0x20, 0xb3, 0x47, 0x2e, 0x40, 0x1e, 0x68, 0xae,
1460da4fd04eStb 			0xe1, 0x00, 0x58, 0xa2, 0x4b, 0xb9, 0xac, 0xf7,
1461da4fd04eStb 			0x5d, 0xc1, 0xee, 0xf5, 0xfb, 0xdd, 0x34, 0xae,
1462da4fd04eStb 			0xbe, 0x3c, 0x93, 0xdd, 0xc2, 0xd8, 0x3a, 0x9a,
1463da4fd04eStb 			0x72, 0x65, 0x41, 0xac, 0xcc, 0x25, 0x6a, 0xcf,
1464da4fd04eStb 			0x71, 0x50, 0x6b, 0xed, 0xe3, 0xc5, 0xd4, 0xe9,
1465da4fd04eStb 			0x1b, 0x59, 0x92, 0xa4, 0xa8, 0x81,
1466da4fd04eStb 		},
1467683169a9Stb 		.hex =	"04308820B3472E40"
1468683169a9Stb 			"1E68AEE10058A24B"
1469683169a9Stb 			"B9ACF75DC1EEF5FB"
1470683169a9Stb 			"DD34AEBE3C93DDC2"
1471683169a9Stb 			"D83A9A726541ACCC"
1472683169a9Stb 			"256ACF71506BEDE3"
1473683169a9Stb 			"C5D4E91B5992A4A8"
1474683169a9Stb 			"81",
1475683169a9Stb 		.oct_len = 57,
1476683169a9Stb 		.oct = {
1477683169a9Stb 			0x04, 0x30, 0x88, 0x20, 0xb3, 0x47, 0x2e, 0x40,
1478683169a9Stb 			0x1e, 0x68, 0xae, 0xe1, 0x00, 0x58, 0xa2, 0x4b,
1479683169a9Stb 			0xb9, 0xac, 0xf7, 0x5d, 0xc1, 0xee, 0xf5, 0xfb,
1480683169a9Stb 			0xdd, 0x34, 0xae, 0xbe, 0x3c, 0x93, 0xdd, 0xc2,
1481683169a9Stb 			0xd8, 0x3a, 0x9a, 0x72, 0x65, 0x41, 0xac, 0xcc,
1482683169a9Stb 			0x25, 0x6a, 0xcf, 0x71, 0x50, 0x6b, 0xed, 0xe3,
1483683169a9Stb 			0xc5, 0xd4, 0xe9, 0x1b, 0x59, 0x92, 0xa4, 0xa8,
1484683169a9Stb 			0x81,
1485683169a9Stb 		},
1486da4fd04eStb 	},
1487da4fd04eStb 	{
1488da4fd04eStb 		.name = "brainpoolP224t1",
1489da4fd04eStb 		.der_len = 110,
1490da4fd04eStb 		.der = {
1491da4fd04eStb 			0x30, 0x6c, 0x02, 0x01, 0x01, 0x04, 0x1c, 0xc0,
1492da4fd04eStb 			0x10, 0xc2, 0xf4, 0xab, 0xbb, 0x00, 0xa0, 0x14,
1493da4fd04eStb 			0x62, 0x13, 0x24, 0xc2, 0x8d, 0x9e, 0x78, 0x92,
1494da4fd04eStb 			0x24, 0x3b, 0xa8, 0xd0, 0xf1, 0x06, 0x69, 0x77,
1495da4fd04eStb 			0x1d, 0x9d, 0x6c, 0xa0, 0x0b, 0x06, 0x09, 0x2b,
1496da4fd04eStb 			0x24, 0x03, 0x03, 0x02, 0x08, 0x01, 0x01, 0x06,
1497da4fd04eStb 			0xa1, 0x3c, 0x03, 0x3a, 0x00, 0x04, 0x0b, 0xbf,
1498da4fd04eStb 			0x95, 0xea, 0x8b, 0xa8, 0x24, 0x94, 0x68, 0x54,
1499da4fd04eStb 			0x69, 0xd9, 0x55, 0xa5, 0x36, 0x34, 0xf1, 0x4a,
1500da4fd04eStb 			0x45, 0xf9, 0x9f, 0x66, 0x7b, 0x5d, 0xc9, 0x8b,
1501da4fd04eStb 			0x0a, 0x7a, 0x5d, 0xef, 0x25, 0x9a, 0xa3, 0x86,
1502da4fd04eStb 			0xe1, 0x98, 0x1b, 0x5b, 0xe3, 0xe3, 0x55, 0xa0,
1503da4fd04eStb 			0x59, 0xb2, 0xfd, 0xe7, 0xdf, 0x41, 0xff, 0x4f,
1504da4fd04eStb 			0x36, 0xe9, 0x56, 0xe9, 0x07, 0xc2,
1505da4fd04eStb 		},
1506683169a9Stb 		.hex =	"040BBF95EA8BA824"
1507683169a9Stb 			"94685469D955A536"
1508683169a9Stb 			"34F14A45F99F667B"
1509683169a9Stb 			"5DC98B0A7A5DEF25"
1510683169a9Stb 			"9AA386E1981B5BE3"
1511683169a9Stb 			"E355A059B2FDE7DF"
1512683169a9Stb 			"41FF4F36E956E907"
1513683169a9Stb 			"C2",
1514683169a9Stb 		.oct_len = 57,
1515683169a9Stb 		.oct = {
1516683169a9Stb 			0x04, 0x0b, 0xbf, 0x95, 0xea, 0x8b, 0xa8, 0x24,
1517683169a9Stb 			0x94, 0x68, 0x54, 0x69, 0xd9, 0x55, 0xa5, 0x36,
1518683169a9Stb 			0x34, 0xf1, 0x4a, 0x45, 0xf9, 0x9f, 0x66, 0x7b,
1519683169a9Stb 			0x5d, 0xc9, 0x8b, 0x0a, 0x7a, 0x5d, 0xef, 0x25,
1520683169a9Stb 			0x9a, 0xa3, 0x86, 0xe1, 0x98, 0x1b, 0x5b, 0xe3,
1521683169a9Stb 			0xe3, 0x55, 0xa0, 0x59, 0xb2, 0xfd, 0xe7, 0xdf,
1522683169a9Stb 			0x41, 0xff, 0x4f, 0x36, 0xe9, 0x56, 0xe9, 0x07,
1523683169a9Stb 			0xc2,
1524683169a9Stb 		},
1525da4fd04eStb 	},
1526da4fd04eStb 	{
1527da4fd04eStb 		.name = "brainpoolP256r1",
1528da4fd04eStb 		.der_len = 122,
1529da4fd04eStb 		.der = {
1530da4fd04eStb 			0x30, 0x78, 0x02, 0x01, 0x01, 0x04, 0x20, 0x98,
1531da4fd04eStb 			0x48, 0x86, 0x7a, 0x5b, 0x60, 0xb9, 0xba, 0xab,
1532da4fd04eStb 			0xa2, 0x34, 0x55, 0x43, 0x17, 0xbc, 0xfd, 0xc2,
1533da4fd04eStb 			0x18, 0xc9, 0xa8, 0x4b, 0x28, 0xbe, 0x5e, 0xa0,
1534da4fd04eStb 			0x37, 0xab, 0x0d, 0xe0, 0x54, 0x65, 0x87, 0xa0,
1535da4fd04eStb 			0x0b, 0x06, 0x09, 0x2b, 0x24, 0x03, 0x03, 0x02,
1536da4fd04eStb 			0x08, 0x01, 0x01, 0x07, 0xa1, 0x44, 0x03, 0x42,
1537da4fd04eStb 			0x00, 0x04, 0x08, 0xd7, 0x77, 0xf5, 0x10, 0xa9,
1538da4fd04eStb 			0x83, 0xd9, 0xdf, 0xfd, 0x40, 0xe4, 0x42, 0xce,
1539da4fd04eStb 			0xd8, 0x3b, 0x9b, 0xef, 0xe6, 0x4d, 0x4e, 0xca,
1540da4fd04eStb 			0x2d, 0xea, 0xe6, 0x69, 0xfe, 0xd3, 0xa9, 0x3f,
1541da4fd04eStb 			0x30, 0xfa, 0x7e, 0xa7, 0x14, 0x9d, 0x37, 0x77,
1542da4fd04eStb 			0xc5, 0xcc, 0x1e, 0x32, 0xf6, 0xce, 0x17, 0x91,
1543da4fd04eStb 			0x1b, 0xeb, 0xa3, 0x8f, 0xce, 0x70, 0x55, 0xc1,
1544da4fd04eStb 			0xcf, 0xe3, 0x38, 0xa0, 0xb7, 0x95, 0x85, 0x26,
1545da4fd04eStb 			0xf5, 0xb2,
1546da4fd04eStb 		},
1547683169a9Stb 		.hex =	"0408D777F510A983"
1548683169a9Stb 			"D9DFFD40E442CED8"
1549683169a9Stb 			"3B9BEFE64D4ECA2D"
1550683169a9Stb 			"EAE669FED3A93F30"
1551683169a9Stb 			"FA7EA7149D3777C5"
1552683169a9Stb 			"CC1E32F6CE17911B"
1553683169a9Stb 			"EBA38FCE7055C1CF"
1554683169a9Stb 			"E338A0B7958526F5"
1555683169a9Stb 			"B2",
1556683169a9Stb 		.oct_len = 65,
1557683169a9Stb 		.oct = {
1558683169a9Stb 			0x04, 0x08, 0xd7, 0x77, 0xf5, 0x10, 0xa9, 0x83,
1559683169a9Stb 			0xd9, 0xdf, 0xfd, 0x40, 0xe4, 0x42, 0xce, 0xd8,
1560683169a9Stb 			0x3b, 0x9b, 0xef, 0xe6, 0x4d, 0x4e, 0xca, 0x2d,
1561683169a9Stb 			0xea, 0xe6, 0x69, 0xfe, 0xd3, 0xa9, 0x3f, 0x30,
1562683169a9Stb 			0xfa, 0x7e, 0xa7, 0x14, 0x9d, 0x37, 0x77, 0xc5,
1563683169a9Stb 			0xcc, 0x1e, 0x32, 0xf6, 0xce, 0x17, 0x91, 0x1b,
1564683169a9Stb 			0xeb, 0xa3, 0x8f, 0xce, 0x70, 0x55, 0xc1, 0xcf,
1565683169a9Stb 			0xe3, 0x38, 0xa0, 0xb7, 0x95, 0x85, 0x26, 0xf5,
1566683169a9Stb 			0xb2,
1567683169a9Stb 		},
1568da4fd04eStb 	},
1569da4fd04eStb 	{
1570da4fd04eStb 		.name = "brainpoolP256t1",
1571da4fd04eStb 		.der_len = 122,
1572da4fd04eStb 		.der = {
1573da4fd04eStb 			0x30, 0x78, 0x02, 0x01, 0x01, 0x04, 0x20, 0x21,
1574da4fd04eStb 			0xb0, 0x02, 0x6c, 0xac, 0x68, 0xe7, 0xaf, 0xb6,
1575da4fd04eStb 			0x8b, 0xb9, 0xe6, 0x68, 0xec, 0x2a, 0xfa, 0x55,
1576da4fd04eStb 			0xb0, 0xd4, 0x23, 0xaa, 0xb9, 0xfb, 0x7c, 0xf5,
1577da4fd04eStb 			0xd1, 0x2f, 0x61, 0x52, 0x19, 0xc0, 0x19, 0xa0,
1578da4fd04eStb 			0x0b, 0x06, 0x09, 0x2b, 0x24, 0x03, 0x03, 0x02,
1579da4fd04eStb 			0x08, 0x01, 0x01, 0x08, 0xa1, 0x44, 0x03, 0x42,
1580da4fd04eStb 			0x00, 0x04, 0x7b, 0x1d, 0x55, 0x29, 0x0b, 0x0a,
1581da4fd04eStb 			0x0d, 0x02, 0x7a, 0x1d, 0x72, 0x53, 0xc1, 0x84,
1582da4fd04eStb 			0xb9, 0x90, 0x00, 0xb9, 0x45, 0xe5, 0xa5, 0xd4,
1583da4fd04eStb 			0xee, 0xd6, 0x9a, 0x1d, 0xb0, 0x3a, 0x91, 0xa8,
1584da4fd04eStb 			0x95, 0x56, 0x58, 0x32, 0xcb, 0xf3, 0x28, 0x95,
1585da4fd04eStb 			0xa6, 0x82, 0x46, 0xe6, 0x0a, 0x33, 0x00, 0xd1,
1586da4fd04eStb 			0x0c, 0x61, 0xac, 0x1e, 0xa0, 0xb0, 0xad, 0x3a,
1587da4fd04eStb 			0xbd, 0x1e, 0x53, 0x8d, 0x26, 0x96, 0xab, 0x44,
1588da4fd04eStb 			0x6b, 0x84,
1589da4fd04eStb 		},
1590683169a9Stb 		.hex =	"047B1D55290B0A0D"
1591683169a9Stb 			"027A1D7253C184B9"
1592683169a9Stb 			"9000B945E5A5D4EE"
1593683169a9Stb 			"D69A1DB03A91A895"
1594683169a9Stb 			"565832CBF32895A6"
1595683169a9Stb 			"8246E60A3300D10C"
1596683169a9Stb 			"61AC1EA0B0AD3ABD"
1597683169a9Stb 			"1E538D2696AB446B"
1598683169a9Stb 			"84",
1599683169a9Stb 		.oct_len = 65,
1600683169a9Stb 		.oct = {
1601683169a9Stb 			0x04, 0x7b, 0x1d, 0x55, 0x29, 0x0b, 0x0a, 0x0d,
1602683169a9Stb 			0x02, 0x7a, 0x1d, 0x72, 0x53, 0xc1, 0x84, 0xb9,
1603683169a9Stb 			0x90, 0x00, 0xb9, 0x45, 0xe5, 0xa5, 0xd4, 0xee,
1604683169a9Stb 			0xd6, 0x9a, 0x1d, 0xb0, 0x3a, 0x91, 0xa8, 0x95,
1605683169a9Stb 			0x56, 0x58, 0x32, 0xcb, 0xf3, 0x28, 0x95, 0xa6,
1606683169a9Stb 			0x82, 0x46, 0xe6, 0x0a, 0x33, 0x00, 0xd1, 0x0c,
1607683169a9Stb 			0x61, 0xac, 0x1e, 0xa0, 0xb0, 0xad, 0x3a, 0xbd,
1608683169a9Stb 			0x1e, 0x53, 0x8d, 0x26, 0x96, 0xab, 0x44, 0x6b,
1609683169a9Stb 			0x84,
1610683169a9Stb 		},
1611da4fd04eStb 	},
1612da4fd04eStb 	{
1613da4fd04eStb 		.name = "brainpoolP320r1",
1614da4fd04eStb 		.der_len = 147,
1615da4fd04eStb 		.der = {
1616da4fd04eStb 			0x30, 0x81, 0x90, 0x02, 0x01, 0x01, 0x04, 0x28,
1617da4fd04eStb 			0x1f, 0x7e, 0x6e, 0x51, 0x13, 0x87, 0x9b, 0x09,
1618da4fd04eStb 			0x2b, 0x3f, 0x1c, 0x39, 0x0f, 0x9f, 0x48, 0x79,
1619da4fd04eStb 			0x48, 0xa1, 0x44, 0xe0, 0x5c, 0x73, 0x2a, 0x6c,
1620da4fd04eStb 			0x6e, 0x60, 0x59, 0xd0, 0xf6, 0x6f, 0x32, 0x0e,
1621da4fd04eStb 			0x6b, 0x2b, 0x0c, 0xf2, 0x39, 0xbd, 0x42, 0xaf,
1622da4fd04eStb 			0xa0, 0x0b, 0x06, 0x09, 0x2b, 0x24, 0x03, 0x03,
1623da4fd04eStb 			0x02, 0x08, 0x01, 0x01, 0x09, 0xa1, 0x54, 0x03,
1624da4fd04eStb 			0x52, 0x00, 0x04, 0xa3, 0x37, 0x85, 0xe2, 0xf2,
1625da4fd04eStb 			0x5f, 0xa1, 0x71, 0xa6, 0x75, 0xfe, 0xa1, 0xea,
1626da4fd04eStb 			0x66, 0x35, 0x7a, 0x53, 0x71, 0x24, 0x83, 0xcd,
1627da4fd04eStb 			0xc9, 0x5d, 0x3f, 0x43, 0xc4, 0x97, 0x6d, 0xcc,
1628da4fd04eStb 			0x0c, 0xed, 0x9a, 0x51, 0x51, 0x7d, 0x1e, 0xd0,
1629da4fd04eStb 			0xea, 0xd2, 0x8c, 0x36, 0xb0, 0x93, 0x62, 0xeb,
1630da4fd04eStb 			0x26, 0xda, 0xe1, 0xef, 0xc7, 0x1a, 0xfa, 0x0c,
1631da4fd04eStb 			0xea, 0x84, 0x7a, 0xf1, 0x50, 0x2c, 0xee, 0xf1,
1632da4fd04eStb 			0xb3, 0xcc, 0xb7, 0xa0, 0x98, 0x5d, 0xde, 0xc2,
1633da4fd04eStb 			0x54, 0xcc, 0x11, 0x2a, 0x84, 0xc6, 0x79, 0x10,
1634da4fd04eStb 			0x7b, 0x20, 0x26,
1635da4fd04eStb 		},
1636683169a9Stb 		.hex =	"04A33785E2F25FA1"
1637683169a9Stb 			"71A675FEA1EA6635"
1638683169a9Stb 			"7A53712483CDC95D"
1639683169a9Stb 			"3F43C4976DCC0CED"
1640683169a9Stb 			"9A51517D1ED0EAD2"
1641683169a9Stb 			"8C36B09362EB26DA"
1642683169a9Stb 			"E1EFC71AFA0CEA84"
1643683169a9Stb 			"7AF1502CEEF1B3CC"
1644683169a9Stb 			"B7A0985DDEC254CC"
1645683169a9Stb 			"112A84C679107B20"
1646683169a9Stb 			"26",
1647683169a9Stb 		.oct_len = 81,
1648683169a9Stb 		.oct = {
1649683169a9Stb 			0x04, 0xa3, 0x37, 0x85, 0xe2, 0xf2, 0x5f, 0xa1,
1650683169a9Stb 			0x71, 0xa6, 0x75, 0xfe, 0xa1, 0xea, 0x66, 0x35,
1651683169a9Stb 			0x7a, 0x53, 0x71, 0x24, 0x83, 0xcd, 0xc9, 0x5d,
1652683169a9Stb 			0x3f, 0x43, 0xc4, 0x97, 0x6d, 0xcc, 0x0c, 0xed,
1653683169a9Stb 			0x9a, 0x51, 0x51, 0x7d, 0x1e, 0xd0, 0xea, 0xd2,
1654683169a9Stb 			0x8c, 0x36, 0xb0, 0x93, 0x62, 0xeb, 0x26, 0xda,
1655683169a9Stb 			0xe1, 0xef, 0xc7, 0x1a, 0xfa, 0x0c, 0xea, 0x84,
1656683169a9Stb 			0x7a, 0xf1, 0x50, 0x2c, 0xee, 0xf1, 0xb3, 0xcc,
1657683169a9Stb 			0xb7, 0xa0, 0x98, 0x5d, 0xde, 0xc2, 0x54, 0xcc,
1658683169a9Stb 			0x11, 0x2a, 0x84, 0xc6, 0x79, 0x10, 0x7b, 0x20,
1659683169a9Stb 			0x26,
1660683169a9Stb 		},
1661da4fd04eStb 	},
1662da4fd04eStb 	{
1663da4fd04eStb 		.name = "brainpoolP320t1",
1664da4fd04eStb 		.der_len = 147,
1665da4fd04eStb 		.der = {
1666da4fd04eStb 			0x30, 0x81, 0x90, 0x02, 0x01, 0x01, 0x04, 0x28,
1667da4fd04eStb 			0x4a, 0x8a, 0x25, 0xd9, 0xfa, 0x04, 0x8f, 0x6b,
1668da4fd04eStb 			0xd5, 0xa3, 0x83, 0xd6, 0xf2, 0xca, 0x82, 0xd5,
1669da4fd04eStb 			0xe2, 0x8e, 0x3f, 0xe6, 0x07, 0xcd, 0xa2, 0x22,
1670da4fd04eStb 			0xa0, 0x3f, 0x0a, 0x7c, 0x09, 0x0f, 0x9f, 0xf4,
1671da4fd04eStb 			0xe3, 0x59, 0x4b, 0x43, 0x0c, 0xfd, 0x5a, 0x96,
1672da4fd04eStb 			0xa0, 0x0b, 0x06, 0x09, 0x2b, 0x24, 0x03, 0x03,
1673da4fd04eStb 			0x02, 0x08, 0x01, 0x01, 0x0a, 0xa1, 0x54, 0x03,
1674da4fd04eStb 			0x52, 0x00, 0x04, 0x3d, 0x8c, 0x4c, 0xbb, 0x30,
1675da4fd04eStb 			0x3f, 0xa0, 0x84, 0x61, 0x43, 0x50, 0x23, 0x70,
1676da4fd04eStb 			0xe3, 0x70, 0xb6, 0x4d, 0x89, 0xc8, 0x95, 0xa0,
1677da4fd04eStb 			0x09, 0xae, 0xfc, 0x55, 0x9c, 0x2f, 0xef, 0x16,
1678da4fd04eStb 			0xc0, 0x72, 0x3c, 0x3e, 0x07, 0xa1, 0xbb, 0xd8,
1679da4fd04eStb 			0x8a, 0xfa, 0xaf, 0x9f, 0xaf, 0x07, 0x7c, 0x15,
1680da4fd04eStb 			0x4d, 0x75, 0x6b, 0xf5, 0x25, 0x65, 0x5b, 0xc4,
1681da4fd04eStb 			0x78, 0x59, 0x22, 0xe5, 0x92, 0x5c, 0xc2, 0x8f,
1682da4fd04eStb 			0xdc, 0x97, 0x59, 0x82, 0xc5, 0x0d, 0x24, 0x70,
1683da4fd04eStb 			0x03, 0xbe, 0xa5, 0x05, 0x88, 0x16, 0x47, 0x9f,
1684da4fd04eStb 			0xe5, 0x3b, 0xb8,
1685da4fd04eStb 		},
1686683169a9Stb 		.hex =	"043D8C4CBB303FA0"
1687683169a9Stb 			"846143502370E370"
1688683169a9Stb 			"B64D89C895A009AE"
1689683169a9Stb 			"FC559C2FEF16C072"
1690683169a9Stb 			"3C3E07A1BBD88AFA"
1691683169a9Stb 			"AF9FAF077C154D75"
1692683169a9Stb 			"6BF525655BC47859"
1693683169a9Stb 			"22E5925CC28FDC97"
1694683169a9Stb 			"5982C50D247003BE"
1695683169a9Stb 			"A5058816479FE53B"
1696683169a9Stb 			"B8",
1697683169a9Stb 		.oct_len = 81,
1698683169a9Stb 		.oct = {
1699683169a9Stb 			0x04, 0x3d, 0x8c, 0x4c, 0xbb, 0x30, 0x3f, 0xa0,
1700683169a9Stb 			0x84, 0x61, 0x43, 0x50, 0x23, 0x70, 0xe3, 0x70,
1701683169a9Stb 			0xb6, 0x4d, 0x89, 0xc8, 0x95, 0xa0, 0x09, 0xae,
1702683169a9Stb 			0xfc, 0x55, 0x9c, 0x2f, 0xef, 0x16, 0xc0, 0x72,
1703683169a9Stb 			0x3c, 0x3e, 0x07, 0xa1, 0xbb, 0xd8, 0x8a, 0xfa,
1704683169a9Stb 			0xaf, 0x9f, 0xaf, 0x07, 0x7c, 0x15, 0x4d, 0x75,
1705683169a9Stb 			0x6b, 0xf5, 0x25, 0x65, 0x5b, 0xc4, 0x78, 0x59,
1706683169a9Stb 			0x22, 0xe5, 0x92, 0x5c, 0xc2, 0x8f, 0xdc, 0x97,
1707683169a9Stb 			0x59, 0x82, 0xc5, 0x0d, 0x24, 0x70, 0x03, 0xbe,
1708683169a9Stb 			0xa5, 0x05, 0x88, 0x16, 0x47, 0x9f, 0xe5, 0x3b,
1709683169a9Stb 			0xb8,
1710683169a9Stb 		},
1711da4fd04eStb 	},
1712da4fd04eStb 	{
1713da4fd04eStb 		.name = "brainpoolP384r1",
1714da4fd04eStb 		.der_len = 171,
1715da4fd04eStb 		.der = {
1716da4fd04eStb 			0x30, 0x81, 0xa8, 0x02, 0x01, 0x01, 0x04, 0x30,
1717da4fd04eStb 			0x02, 0x57, 0xb6, 0xfe, 0x31, 0xda, 0x87, 0xcd,
1718da4fd04eStb 			0x68, 0x2a, 0x67, 0x98, 0xd1, 0x72, 0x5c, 0xd8,
1719da4fd04eStb 			0x2e, 0x25, 0xf9, 0x39, 0x36, 0x3b, 0x93, 0x98,
1720da4fd04eStb 			0x79, 0x81, 0xc0, 0x7e, 0xa3, 0x44, 0x99, 0xd8,
1721da4fd04eStb 			0xe5, 0x07, 0x1f, 0xea, 0xa1, 0x66, 0x60, 0x00,
1722da4fd04eStb 			0x29, 0x84, 0xa3, 0x35, 0xdd, 0x64, 0x96, 0x93,
1723da4fd04eStb 			0xa0, 0x0b, 0x06, 0x09, 0x2b, 0x24, 0x03, 0x03,
1724da4fd04eStb 			0x02, 0x08, 0x01, 0x01, 0x0b, 0xa1, 0x64, 0x03,
1725da4fd04eStb 			0x62, 0x00, 0x04, 0x4f, 0x79, 0xe0, 0xe7, 0xf9,
1726da4fd04eStb 			0x57, 0x33, 0xf9, 0x9d, 0x6a, 0x5c, 0x00, 0x6e,
1727da4fd04eStb 			0xb8, 0xbc, 0xe6, 0x4f, 0x70, 0x1d, 0x73, 0x02,
1728da4fd04eStb 			0x5c, 0x87, 0xa1, 0x88, 0xea, 0xe3, 0x57, 0x5c,
1729da4fd04eStb 			0x1a, 0x27, 0x40, 0xcf, 0xcc, 0x6f, 0x7e, 0x6d,
1730da4fd04eStb 			0xfd, 0x96, 0x0b, 0xaa, 0xc5, 0x02, 0x92, 0x10,
1731da4fd04eStb 			0x6d, 0x7e, 0xd5, 0x17, 0xda, 0xab, 0x52, 0x9b,
1732da4fd04eStb 			0xcd, 0x87, 0x08, 0x64, 0x2a, 0x61, 0x03, 0xc9,
1733da4fd04eStb 			0xfe, 0x97, 0x79, 0xf0, 0x5c, 0x84, 0x72, 0x50,
1734da4fd04eStb 			0x53, 0x95, 0x56, 0x7a, 0x97, 0xce, 0x36, 0x13,
1735da4fd04eStb 			0x23, 0x78, 0x31, 0x82, 0x36, 0x07, 0x45, 0xad,
1736da4fd04eStb 			0x92, 0x00, 0xaf, 0x3d, 0xe8, 0x5a, 0x7d, 0x7b,
1737da4fd04eStb 			0x63, 0xc2, 0xde,
1738da4fd04eStb 		},
1739683169a9Stb 		.hex =	"044F79E0E7F95733"
1740683169a9Stb 			"F99D6A5C006EB8BC"
1741683169a9Stb 			"E64F701D73025C87"
1742683169a9Stb 			"A188EAE3575C1A27"
1743683169a9Stb 			"40CFCC6F7E6DFD96"
1744683169a9Stb 			"0BAAC50292106D7E"
1745683169a9Stb 			"D517DAAB529BCD87"
1746683169a9Stb 			"08642A6103C9FE97"
1747683169a9Stb 			"79F05C8472505395"
1748683169a9Stb 			"567A97CE36132378"
1749683169a9Stb 			"3182360745AD9200"
1750683169a9Stb 			"AF3DE85A7D7B63C2"
1751683169a9Stb 			"DE",
1752683169a9Stb 		.oct_len = 97,
1753683169a9Stb 		.oct = {
1754683169a9Stb 			0x04, 0x4f, 0x79, 0xe0, 0xe7, 0xf9, 0x57, 0x33,
1755683169a9Stb 			0xf9, 0x9d, 0x6a, 0x5c, 0x00, 0x6e, 0xb8, 0xbc,
1756683169a9Stb 			0xe6, 0x4f, 0x70, 0x1d, 0x73, 0x02, 0x5c, 0x87,
1757683169a9Stb 			0xa1, 0x88, 0xea, 0xe3, 0x57, 0x5c, 0x1a, 0x27,
1758683169a9Stb 			0x40, 0xcf, 0xcc, 0x6f, 0x7e, 0x6d, 0xfd, 0x96,
1759683169a9Stb 			0x0b, 0xaa, 0xc5, 0x02, 0x92, 0x10, 0x6d, 0x7e,
1760683169a9Stb 			0xd5, 0x17, 0xda, 0xab, 0x52, 0x9b, 0xcd, 0x87,
1761683169a9Stb 			0x08, 0x64, 0x2a, 0x61, 0x03, 0xc9, 0xfe, 0x97,
1762683169a9Stb 			0x79, 0xf0, 0x5c, 0x84, 0x72, 0x50, 0x53, 0x95,
1763683169a9Stb 			0x56, 0x7a, 0x97, 0xce, 0x36, 0x13, 0x23, 0x78,
1764683169a9Stb 			0x31, 0x82, 0x36, 0x07, 0x45, 0xad, 0x92, 0x00,
1765683169a9Stb 			0xaf, 0x3d, 0xe8, 0x5a, 0x7d, 0x7b, 0x63, 0xc2,
1766683169a9Stb 			0xde,
1767683169a9Stb 		},
1768da4fd04eStb 	},
1769da4fd04eStb 	{
1770da4fd04eStb 		.name = "brainpoolP384t1",
1771da4fd04eStb 		.der_len = 171,
1772da4fd04eStb 		.der = {
1773da4fd04eStb 			0x30, 0x81, 0xa8, 0x02, 0x01, 0x01, 0x04, 0x30,
1774da4fd04eStb 			0x35, 0xea, 0xbc, 0x66, 0xd4, 0xa9, 0xc0, 0xe1,
1775da4fd04eStb 			0xcd, 0xd4, 0xe5, 0xb1, 0xac, 0x8f, 0x66, 0x82,
1776da4fd04eStb 			0x56, 0xc1, 0xbd, 0xf2, 0xf5, 0x30, 0x95, 0xab,
1777da4fd04eStb 			0x30, 0xaa, 0xc0, 0xc3, 0x07, 0xca, 0x97, 0xc9,
1778da4fd04eStb 			0x53, 0x45, 0xd3, 0xff, 0xbf, 0xfe, 0xdf, 0x39,
1779da4fd04eStb 			0x32, 0x40, 0xe0, 0x45, 0x15, 0xa7, 0x22, 0x5f,
1780da4fd04eStb 			0xa0, 0x0b, 0x06, 0x09, 0x2b, 0x24, 0x03, 0x03,
1781da4fd04eStb 			0x02, 0x08, 0x01, 0x01, 0x0c, 0xa1, 0x64, 0x03,
1782da4fd04eStb 			0x62, 0x00, 0x04, 0x85, 0xdb, 0x57, 0x4b, 0x71,
1783da4fd04eStb 			0xb1, 0x65, 0x93, 0x51, 0x83, 0x7c, 0xb3, 0x24,
1784da4fd04eStb 			0x07, 0x6b, 0x7b, 0x57, 0x33, 0x73, 0x3a, 0xa6,
1785da4fd04eStb 			0x14, 0x86, 0x83, 0xa8, 0x88, 0x81, 0xf2, 0x90,
1786da4fd04eStb 			0xdf, 0x93, 0x4f, 0x67, 0x41, 0xef, 0xcb, 0x35,
1787da4fd04eStb 			0x14, 0xad, 0x4c, 0x67, 0x0b, 0xdb, 0x86, 0x03,
1788da4fd04eStb 			0x5e, 0x6d, 0x5e, 0x7e, 0x4b, 0x0f, 0x73, 0x9e,
1789da4fd04eStb 			0x73, 0x50, 0x86, 0x29, 0x09, 0x7c, 0x38, 0xfc,
1790da4fd04eStb 			0xbe, 0xaf, 0x59, 0x9c, 0x69, 0xdf, 0xb4, 0x60,
1791da4fd04eStb 			0x14, 0x3e, 0xb2, 0x1a, 0x72, 0x86, 0x57, 0xcb,
1792da4fd04eStb 			0x6b, 0x42, 0x20, 0x67, 0x7f, 0xbc, 0xa8, 0x57,
1793da4fd04eStb 			0x88, 0x76, 0x72, 0x9a, 0xb4, 0xea, 0xc0, 0x48,
1794da4fd04eStb 			0x01, 0x5d, 0x8e,
1795da4fd04eStb 		},
1796683169a9Stb 		.hex =	"0485DB574B71B165"
1797683169a9Stb 			"9351837CB324076B"
1798683169a9Stb 			"7B5733733AA61486"
1799683169a9Stb 			"83A88881F290DF93"
1800683169a9Stb 			"4F6741EFCB3514AD"
1801683169a9Stb 			"4C670BDB86035E6D"
1802683169a9Stb 			"5E7E4B0F739E7350"
1803683169a9Stb 			"8629097C38FCBEAF"
1804683169a9Stb 			"599C69DFB460143E"
1805683169a9Stb 			"B21A728657CB6B42"
1806683169a9Stb 			"20677FBCA8578876"
1807683169a9Stb 			"729AB4EAC048015D"
1808683169a9Stb 			"8E",
1809683169a9Stb 		.oct_len = 97,
1810683169a9Stb 		.oct = {
1811683169a9Stb 			0x04, 0x85, 0xdb, 0x57, 0x4b, 0x71, 0xb1, 0x65,
1812683169a9Stb 			0x93, 0x51, 0x83, 0x7c, 0xb3, 0x24, 0x07, 0x6b,
1813683169a9Stb 			0x7b, 0x57, 0x33, 0x73, 0x3a, 0xa6, 0x14, 0x86,
1814683169a9Stb 			0x83, 0xa8, 0x88, 0x81, 0xf2, 0x90, 0xdf, 0x93,
1815683169a9Stb 			0x4f, 0x67, 0x41, 0xef, 0xcb, 0x35, 0x14, 0xad,
1816683169a9Stb 			0x4c, 0x67, 0x0b, 0xdb, 0x86, 0x03, 0x5e, 0x6d,
1817683169a9Stb 			0x5e, 0x7e, 0x4b, 0x0f, 0x73, 0x9e, 0x73, 0x50,
1818683169a9Stb 			0x86, 0x29, 0x09, 0x7c, 0x38, 0xfc, 0xbe, 0xaf,
1819683169a9Stb 			0x59, 0x9c, 0x69, 0xdf, 0xb4, 0x60, 0x14, 0x3e,
1820683169a9Stb 			0xb2, 0x1a, 0x72, 0x86, 0x57, 0xcb, 0x6b, 0x42,
1821683169a9Stb 			0x20, 0x67, 0x7f, 0xbc, 0xa8, 0x57, 0x88, 0x76,
1822683169a9Stb 			0x72, 0x9a, 0xb4, 0xea, 0xc0, 0x48, 0x01, 0x5d,
1823683169a9Stb 			0x8e,
1824683169a9Stb 		},
1825da4fd04eStb 	},
1826da4fd04eStb 	{
1827da4fd04eStb 		.name = "brainpoolP512r1",
1828da4fd04eStb 		.der_len = 221,
1829da4fd04eStb 		.der = {
1830da4fd04eStb 			0x30, 0x81, 0xda, 0x02, 0x01, 0x01, 0x04, 0x40,
1831da4fd04eStb 			0x7e, 0x04, 0x7d, 0xab, 0x42, 0xc6, 0xdb, 0x95,
1832da4fd04eStb 			0xfb, 0x22, 0x0b, 0xe4, 0x09, 0xff, 0x4a, 0x1e,
1833da4fd04eStb 			0x7b, 0x42, 0x62, 0x82, 0x41, 0xf4, 0x1e, 0xc2,
1834da4fd04eStb 			0x1f, 0x9e, 0x52, 0xea, 0xce, 0x1b, 0x75, 0x07,
1835da4fd04eStb 			0x7c, 0xaf, 0x49, 0xdf, 0xf3, 0x20, 0xfa, 0x88,
1836da4fd04eStb 			0x23, 0xc4, 0x5e, 0x6d, 0x82, 0x45, 0x32, 0x19,
1837da4fd04eStb 			0x04, 0x4a, 0x3d, 0x80, 0xa1, 0xa8, 0x99, 0x09,
1838da4fd04eStb 			0xce, 0x78, 0xde, 0x32, 0x18, 0xf4, 0x83, 0x2c,
1839da4fd04eStb 			0xa0, 0x0b, 0x06, 0x09, 0x2b, 0x24, 0x03, 0x03,
1840da4fd04eStb 			0x02, 0x08, 0x01, 0x01, 0x0d, 0xa1, 0x81, 0x85,
1841da4fd04eStb 			0x03, 0x81, 0x82, 0x00, 0x04, 0x1e, 0x99, 0xea,
1842da4fd04eStb 			0x54, 0xb6, 0x1a, 0x4f, 0x44, 0x25, 0xf4, 0xf8,
1843da4fd04eStb 			0xbe, 0x33, 0x7c, 0xd1, 0x62, 0x35, 0xf5, 0xd1,
1844da4fd04eStb 			0x8e, 0x9f, 0xae, 0xa8, 0x8f, 0x6d, 0x61, 0x27,
1845da4fd04eStb 			0x2d, 0x2a, 0xb1, 0x96, 0x48, 0x6d, 0xb2, 0x63,
1846da4fd04eStb 			0x05, 0x9f, 0xec, 0xa1, 0xcd, 0x65, 0x45, 0xc8,
1847da4fd04eStb 			0xcd, 0xf1, 0xa4, 0xba, 0x20, 0xb7, 0xe4, 0xc7,
1848da4fd04eStb 			0x92, 0x3c, 0x1f, 0x16, 0xf4, 0x5b, 0x75, 0xe4,
1849da4fd04eStb 			0x2a, 0x2e, 0x44, 0x72, 0x65, 0x63, 0xc3, 0x78,
1850da4fd04eStb 			0x54, 0x50, 0xcb, 0x50, 0xe0, 0xbe, 0xe7, 0x6f,
1851da4fd04eStb 			0x2a, 0xdc, 0x24, 0x7b, 0xf8, 0x4b, 0xa8, 0xe2,
1852da4fd04eStb 			0x1b, 0x27, 0x00, 0x2d, 0xe8, 0x99, 0xdc, 0x5f,
1853da4fd04eStb 			0xa4, 0x43, 0xa8, 0xf7, 0xb1, 0x55, 0xea, 0xd7,
1854da4fd04eStb 			0x02, 0x09, 0x08, 0x97, 0x5f, 0x21, 0x1e, 0x16,
1855da4fd04eStb 			0xa0, 0xd8, 0x27, 0xe4, 0x5e, 0x3a, 0xa5, 0x51,
1856da4fd04eStb 			0x68, 0xe7, 0x19, 0xc1, 0x7d, 0xb6, 0x9d, 0xb9,
1857da4fd04eStb 			0xc6, 0xc2, 0x1b, 0x48, 0x7f,
1858da4fd04eStb 		},
1859683169a9Stb 		.hex =	"041E99EA54B61A4F"
1860683169a9Stb 			"4425F4F8BE337CD1"
1861683169a9Stb 			"6235F5D18E9FAEA8"
1862683169a9Stb 			"8F6D61272D2AB196"
1863683169a9Stb 			"486DB263059FECA1"
1864683169a9Stb 			"CD6545C8CDF1A4BA"
1865683169a9Stb 			"20B7E4C7923C1F16"
1866683169a9Stb 			"F45B75E42A2E4472"
1867683169a9Stb 			"6563C3785450CB50"
1868683169a9Stb 			"E0BEE76F2ADC247B"
1869683169a9Stb 			"F84BA8E21B27002D"
1870683169a9Stb 			"E899DC5FA443A8F7"
1871683169a9Stb 			"B155EAD702090897"
1872683169a9Stb 			"5F211E16A0D827E4"
1873683169a9Stb 			"5E3AA55168E719C1"
1874683169a9Stb 			"7DB69DB9C6C21B48"
1875683169a9Stb 			"7F",
1876683169a9Stb 		.oct_len = 129,
1877683169a9Stb 		.oct = {
1878683169a9Stb 			0x04, 0x1e, 0x99, 0xea, 0x54, 0xb6, 0x1a, 0x4f,
1879683169a9Stb 			0x44, 0x25, 0xf4, 0xf8, 0xbe, 0x33, 0x7c, 0xd1,
1880683169a9Stb 			0x62, 0x35, 0xf5, 0xd1, 0x8e, 0x9f, 0xae, 0xa8,
1881683169a9Stb 			0x8f, 0x6d, 0x61, 0x27, 0x2d, 0x2a, 0xb1, 0x96,
1882683169a9Stb 			0x48, 0x6d, 0xb2, 0x63, 0x05, 0x9f, 0xec, 0xa1,
1883683169a9Stb 			0xcd, 0x65, 0x45, 0xc8, 0xcd, 0xf1, 0xa4, 0xba,
1884683169a9Stb 			0x20, 0xb7, 0xe4, 0xc7, 0x92, 0x3c, 0x1f, 0x16,
1885683169a9Stb 			0xf4, 0x5b, 0x75, 0xe4, 0x2a, 0x2e, 0x44, 0x72,
1886683169a9Stb 			0x65, 0x63, 0xc3, 0x78, 0x54, 0x50, 0xcb, 0x50,
1887683169a9Stb 			0xe0, 0xbe, 0xe7, 0x6f, 0x2a, 0xdc, 0x24, 0x7b,
1888683169a9Stb 			0xf8, 0x4b, 0xa8, 0xe2, 0x1b, 0x27, 0x00, 0x2d,
1889683169a9Stb 			0xe8, 0x99, 0xdc, 0x5f, 0xa4, 0x43, 0xa8, 0xf7,
1890683169a9Stb 			0xb1, 0x55, 0xea, 0xd7, 0x02, 0x09, 0x08, 0x97,
1891683169a9Stb 			0x5f, 0x21, 0x1e, 0x16, 0xa0, 0xd8, 0x27, 0xe4,
1892683169a9Stb 			0x5e, 0x3a, 0xa5, 0x51, 0x68, 0xe7, 0x19, 0xc1,
1893683169a9Stb 			0x7d, 0xb6, 0x9d, 0xb9, 0xc6, 0xc2, 0x1b, 0x48,
1894683169a9Stb 			0x7f,
1895683169a9Stb 		},
1896da4fd04eStb 	},
1897da4fd04eStb 	{
1898da4fd04eStb 		.name = "brainpoolP512t1",
1899da4fd04eStb 		.der_len = 221,
1900da4fd04eStb 		.der = {
1901da4fd04eStb 			0x30, 0x81, 0xda, 0x02, 0x01, 0x01, 0x04, 0x40,
1902da4fd04eStb 			0xa0, 0xcb, 0xab, 0x2e, 0xdb, 0xb0, 0x17, 0x53,
1903da4fd04eStb 			0x91, 0x23, 0x8c, 0x86, 0x29, 0x8b, 0x33, 0x27,
1904da4fd04eStb 			0x27, 0x86, 0x71, 0xdd, 0x9f, 0x92, 0x8a, 0x8a,
1905da4fd04eStb 			0x28, 0xac, 0x1f, 0x4b, 0x67, 0x8d, 0xd3, 0x7a,
1906da4fd04eStb 			0x71, 0xd9, 0x95, 0x3c, 0xc2, 0x48, 0x9a, 0x1e,
1907da4fd04eStb 			0x75, 0xcf, 0x33, 0x6f, 0xdc, 0x88, 0x8c, 0x29,
1908da4fd04eStb 			0x1d, 0x41, 0xf8, 0xe1, 0xb3, 0x8f, 0xf9, 0x9e,
1909da4fd04eStb 			0x13, 0x14, 0xbc, 0x4f, 0xa5, 0x8e, 0x06, 0xba,
1910da4fd04eStb 			0xa0, 0x0b, 0x06, 0x09, 0x2b, 0x24, 0x03, 0x03,
1911da4fd04eStb 			0x02, 0x08, 0x01, 0x01, 0x0e, 0xa1, 0x81, 0x85,
1912da4fd04eStb 			0x03, 0x81, 0x82, 0x00, 0x04, 0x5b, 0x2b, 0x47,
1913da4fd04eStb 			0x83, 0x61, 0xea, 0x80, 0x14, 0x85, 0x06, 0xe7,
1914da4fd04eStb 			0x03, 0xbd, 0x24, 0x04, 0x47, 0x5d, 0x33, 0x4e,
1915da4fd04eStb 			0xde, 0x0c, 0x92, 0x09, 0x54, 0x77, 0x53, 0x0e,
1916da4fd04eStb 			0x33, 0x30, 0x73, 0xc0, 0xc0, 0x6a, 0xf2, 0xb5,
1917da4fd04eStb 			0xb5, 0xd4, 0xd3, 0x02, 0x2f, 0x20, 0xe2, 0x88,
1918da4fd04eStb 			0xb2, 0x07, 0x4a, 0x9f, 0x90, 0xbf, 0xba, 0xb5,
1919da4fd04eStb 			0x3d, 0xc4, 0x5b, 0x65, 0x76, 0xb5, 0xe5, 0xa1,
1920da4fd04eStb 			0x7d, 0x63, 0x39, 0x57, 0xaa, 0x1d, 0x1f, 0x99,
1921da4fd04eStb 			0x52, 0x43, 0x5d, 0x0b, 0x58, 0xa6, 0x51, 0x1e,
1922da4fd04eStb 			0x6f, 0x7b, 0x9e, 0x2f, 0x45, 0x5a, 0x2d, 0x6f,
1923da4fd04eStb 			0xaa, 0x2b, 0xfc, 0xe1, 0x9f, 0x78, 0x11, 0x70,
1924da4fd04eStb 			0x80, 0xf8, 0xfe, 0x51, 0x45, 0x12, 0xbf, 0x79,
1925da4fd04eStb 			0xd8, 0xaf, 0x05, 0x59, 0x14, 0x01, 0x81, 0x9c,
1926da4fd04eStb 			0x12, 0x5c, 0x8d, 0x4d, 0xed, 0xc7, 0x44, 0x61,
1927da4fd04eStb 			0x68, 0x0f, 0x3f, 0x34, 0xee, 0x90, 0x4e, 0xab,
1928da4fd04eStb 			0x80, 0x7c, 0x41, 0xd7, 0x8f,
1929da4fd04eStb 		},
1930683169a9Stb 		.hex =	"045B2B478361EA80"
1931683169a9Stb 			"148506E703BD2404"
1932683169a9Stb 			"475D334EDE0C9209"
1933683169a9Stb 			"5477530E333073C0"
1934683169a9Stb 			"C06AF2B5B5D4D302"
1935683169a9Stb 			"2F20E288B2074A9F"
1936683169a9Stb 			"90BFBAB53DC45B65"
1937683169a9Stb 			"76B5E5A17D633957"
1938683169a9Stb 			"AA1D1F9952435D0B"
1939683169a9Stb 			"58A6511E6F7B9E2F"
1940683169a9Stb 			"455A2D6FAA2BFCE1"
1941683169a9Stb 			"9F78117080F8FE51"
1942683169a9Stb 			"4512BF79D8AF0559"
1943683169a9Stb 			"1401819C125C8D4D"
1944683169a9Stb 			"EDC74461680F3F34"
1945683169a9Stb 			"EE904EAB807C41D7"
1946683169a9Stb 			"8F",
1947683169a9Stb 		.oct_len = 129,
1948683169a9Stb 		.oct = {
1949683169a9Stb 			0x04, 0x5b, 0x2b, 0x47, 0x83, 0x61, 0xea, 0x80,
1950683169a9Stb 			0x14, 0x85, 0x06, 0xe7, 0x03, 0xbd, 0x24, 0x04,
1951683169a9Stb 			0x47, 0x5d, 0x33, 0x4e, 0xde, 0x0c, 0x92, 0x09,
1952683169a9Stb 			0x54, 0x77, 0x53, 0x0e, 0x33, 0x30, 0x73, 0xc0,
1953683169a9Stb 			0xc0, 0x6a, 0xf2, 0xb5, 0xb5, 0xd4, 0xd3, 0x02,
1954683169a9Stb 			0x2f, 0x20, 0xe2, 0x88, 0xb2, 0x07, 0x4a, 0x9f,
1955683169a9Stb 			0x90, 0xbf, 0xba, 0xb5, 0x3d, 0xc4, 0x5b, 0x65,
1956683169a9Stb 			0x76, 0xb5, 0xe5, 0xa1, 0x7d, 0x63, 0x39, 0x57,
1957683169a9Stb 			0xaa, 0x1d, 0x1f, 0x99, 0x52, 0x43, 0x5d, 0x0b,
1958683169a9Stb 			0x58, 0xa6, 0x51, 0x1e, 0x6f, 0x7b, 0x9e, 0x2f,
1959683169a9Stb 			0x45, 0x5a, 0x2d, 0x6f, 0xaa, 0x2b, 0xfc, 0xe1,
1960683169a9Stb 			0x9f, 0x78, 0x11, 0x70, 0x80, 0xf8, 0xfe, 0x51,
1961683169a9Stb 			0x45, 0x12, 0xbf, 0x79, 0xd8, 0xaf, 0x05, 0x59,
1962683169a9Stb 			0x14, 0x01, 0x81, 0x9c, 0x12, 0x5c, 0x8d, 0x4d,
1963683169a9Stb 			0xed, 0xc7, 0x44, 0x61, 0x68, 0x0f, 0x3f, 0x34,
1964683169a9Stb 			0xee, 0x90, 0x4e, 0xab, 0x80, 0x7c, 0x41, 0xd7,
1965683169a9Stb 			0x8f,
1966683169a9Stb 		},
1967da4fd04eStb 	},
1968da4fd04eStb 	{
1969da4fd04eStb 		.name = "FRP256v1",
1970da4fd04eStb 		.der_len = 123,
1971da4fd04eStb 		.der = {
1972da4fd04eStb 			0x30, 0x79, 0x02, 0x01, 0x01, 0x04, 0x20, 0x66,
1973da4fd04eStb 			0xe4, 0xdb, 0x37, 0x46, 0x8d, 0xa1, 0xc8, 0x20,
1974da4fd04eStb 			0x0d, 0xdf, 0xcb, 0x3b, 0x5c, 0x5b, 0x84, 0xe1,
1975da4fd04eStb 			0x89, 0xed, 0x30, 0x37, 0xaa, 0xfa, 0xb2, 0x5b,
1976da4fd04eStb 			0xf4, 0xf6, 0x13, 0x66, 0xfe, 0xfc, 0x7c, 0xa0,
1977da4fd04eStb 			0x0c, 0x06, 0x0a, 0x2a, 0x81, 0x7a, 0x01, 0x81,
1978da4fd04eStb 			0x5f, 0x65, 0x82, 0x00, 0x01, 0xa1, 0x44, 0x03,
1979da4fd04eStb 			0x42, 0x00, 0x04, 0x17, 0xc7, 0xae, 0x1b, 0xe4,
1980da4fd04eStb 			0xc6, 0xd6, 0x3a, 0xcf, 0x6b, 0x7e, 0x43, 0x29,
1981da4fd04eStb 			0x9f, 0xdc, 0xc2, 0xa3, 0x90, 0x53, 0x62, 0x42,
1982da4fd04eStb 			0x6e, 0xa3, 0xa4, 0xca, 0xd3, 0xf6, 0x53, 0x53,
1983da4fd04eStb 			0xd4, 0xa6, 0x1f, 0xa8, 0x03, 0x1f, 0x6d, 0xd4,
1984da4fd04eStb 			0x75, 0x77, 0x23, 0xf7, 0x92, 0xa4, 0x7c, 0x5a,
1985da4fd04eStb 			0x4c, 0xc7, 0xc6, 0x96, 0x54, 0x62, 0x94, 0x9b,
1986da4fd04eStb 			0xa7, 0xe0, 0x31, 0x1c, 0x4d, 0x1c, 0xa8, 0x2a,
1987da4fd04eStb 			0x51, 0x11, 0x24,
1988da4fd04eStb 		},
1989683169a9Stb 		.hex =	"0417C7AE1BE4C6D6"
1990683169a9Stb 			"3ACF6B7E43299FDC"
1991683169a9Stb 			"C2A3905362426EA3"
1992683169a9Stb 			"A4CAD3F65353D4A6"
1993683169a9Stb 			"1FA8031F6DD47577"
1994683169a9Stb 			"23F792A47C5A4CC7"
1995683169a9Stb 			"C6965462949BA7E0"
1996683169a9Stb 			"311C4D1CA82A5111"
1997683169a9Stb 			"24",
1998683169a9Stb 		.oct_len = 65,
1999683169a9Stb 		.oct = {
2000683169a9Stb 			0x04, 0x17, 0xc7, 0xae, 0x1b, 0xe4, 0xc6, 0xd6,
2001683169a9Stb 			0x3a, 0xcf, 0x6b, 0x7e, 0x43, 0x29, 0x9f, 0xdc,
2002683169a9Stb 			0xc2, 0xa3, 0x90, 0x53, 0x62, 0x42, 0x6e, 0xa3,
2003683169a9Stb 			0xa4, 0xca, 0xd3, 0xf6, 0x53, 0x53, 0xd4, 0xa6,
2004683169a9Stb 			0x1f, 0xa8, 0x03, 0x1f, 0x6d, 0xd4, 0x75, 0x77,
2005683169a9Stb 			0x23, 0xf7, 0x92, 0xa4, 0x7c, 0x5a, 0x4c, 0xc7,
2006683169a9Stb 			0xc6, 0x96, 0x54, 0x62, 0x94, 0x9b, 0xa7, 0xe0,
2007683169a9Stb 			0x31, 0x1c, 0x4d, 0x1c, 0xa8, 0x2a, 0x51, 0x11,
2008683169a9Stb 			0x24,
2009683169a9Stb 		},
2010da4fd04eStb 	},
2011da4fd04eStb };
2012da4fd04eStb 
2013da4fd04eStb #define N_EC_PRIVATE_KEYS (sizeof(ec_private_keys) / sizeof(ec_private_keys[0]))
2014da4fd04eStb 
20155ca31ee3Stb static EC_KEY *
20165ca31ee3Stb ec_key_check_sanity(const struct ec_private_key *key)
2017da4fd04eStb {
20185ca31ee3Stb 	EC_KEY *ec_key;
2019da4fd04eStb 	const unsigned char *p;
20205ca31ee3Stb 	unsigned char *der = NULL;
20215ca31ee3Stb 	int der_len = 0;
2022da4fd04eStb 	unsigned int flags;
2023da4fd04eStb 	uint8_t form;
2024da4fd04eStb 
2025da4fd04eStb 	p = key->der;
2026da4fd04eStb 	if ((ec_key = d2i_ECPrivateKey(NULL, &p, key->der_len)) == NULL) {
2027da4fd04eStb 		fprintf(stderr, "FAIL: d2i_ECPrivateKey for %s\n", key->name);
2028da4fd04eStb 		goto err;
2029da4fd04eStb 	}
2030da4fd04eStb 
2031da4fd04eStb 	if ((flags = EC_KEY_get_enc_flags(ec_key)) != 0) {
2032da4fd04eStb 		fprintf(stderr, "FAIL: EC_KEY_get_enc_flags() returned %x for %s\n",
2033da4fd04eStb 		    flags, key->name);
2034da4fd04eStb 		goto err;
2035da4fd04eStb 	}
2036683169a9Stb 	if ((form = EC_KEY_get_conv_form(ec_key)) != POINT_CONVERSION_UNCOMPRESSED) {
2037683169a9Stb 		fprintf(stderr, "FAIL: got conversion form %02x, want %02x\n",
2038683169a9Stb 		    form, POINT_CONVERSION_UNCOMPRESSED);
2039683169a9Stb 		goto err;
2040683169a9Stb 	}
2041da4fd04eStb 
2042da4fd04eStb 	ERR_clear_error();
2043da4fd04eStb 	if (!EC_KEY_check_key(ec_key)) {
2044da4fd04eStb 		fprintf(stderr, "FAIL: EC_KEY_check_key() for %s\n", key->name);
2045da4fd04eStb 		ERR_print_errors_fp(stderr);
20465ca31ee3Stb 		goto err;
2047da4fd04eStb 	}
2048da4fd04eStb 
2049da4fd04eStb 	der = NULL;
2050da4fd04eStb 	if ((der_len = i2d_ECPrivateKey(ec_key, &der)) <= 0) {
2051da4fd04eStb 		fprintf(stderr, "FAIL: i2d_ECPrivateKey() for %s\n", key->name);
2052da4fd04eStb 		der_len = 0;
2053da4fd04eStb 		goto err;
2054da4fd04eStb 	}
2055da4fd04eStb 
2056da4fd04eStb 	if (compare_data(key->name, der, der_len, key->der, key->der_len) == -1)
2057da4fd04eStb 		goto err;
2058da4fd04eStb 
2059da4fd04eStb 	freezero(der, der_len);
2060da4fd04eStb 	der = NULL;
2061da4fd04eStb 
20625ca31ee3Stb 	return ec_key;
20635ca31ee3Stb 
20645ca31ee3Stb  err:
20655ca31ee3Stb 	EC_KEY_free(ec_key);
20665ca31ee3Stb 	freezero(der, der_len);
20675ca31ee3Stb 
20685ca31ee3Stb 	return NULL;
20695ca31ee3Stb }
20705ca31ee3Stb 
20715ca31ee3Stb static int
20725ca31ee3Stb ec_key_test_point_encoding(const struct ec_private_key *key, const EC_KEY *ec_key)
20735ca31ee3Stb {
20745ca31ee3Stb 	const EC_GROUP *group;
20755ca31ee3Stb 	const EC_POINT *ec_public_point;
20765ca31ee3Stb 	char *hex = NULL;
20775ca31ee3Stb 	unsigned char *ostr = NULL;
20785ca31ee3Stb 	int hex_len = 0, ostr_len = 0;
20795ca31ee3Stb 	int failed = 1;
2080683169a9Stb 
2081683169a9Stb 	if ((group = EC_KEY_get0_group(ec_key)) == NULL) {
2082683169a9Stb 		fprintf(stderr, "FAIL: EC_KEY_get0_group() for %s\n", key->name);
2083683169a9Stb 		goto err;
2084683169a9Stb 	}
2085683169a9Stb 	if ((ec_public_point = EC_KEY_get0_public_key(ec_key)) == NULL) {
2086683169a9Stb 		fprintf(stderr, "FAIL: EC_KEY_get0_public_key() for %s\n", key->name);
2087683169a9Stb 		goto err;
2088683169a9Stb 	}
2089683169a9Stb 
2090683169a9Stb 	if ((hex = EC_POINT_point2hex(group, ec_public_point,
2091683169a9Stb 	    POINT_CONVERSION_UNCOMPRESSED, NULL)) == NULL) {
2092683169a9Stb 		fprintf(stderr, "FAIL: EC_POINT_point2hex() for %s\n", key->name);
2093683169a9Stb 		goto err;
2094683169a9Stb 	}
2095683169a9Stb 
2096683169a9Stb 	if ((hex_len = strlen(hex)) != 2 * key->oct_len) {
2097683169a9Stb 		fprintf(stderr, "FAIL: hex_len: %d, oct_len %d for %s\n",
2098683169a9Stb 		    hex_len, key->oct_len, key->name);
2099683169a9Stb 		goto err;
2100683169a9Stb 	}
2101683169a9Stb 
21025ca31ee3Stb 	if (compare_data(key->name, hex, hex_len, key->hex, hex_len) == -1) {
21035ca31ee3Stb 		fprintf(stderr, "FAIL: EC_POINT_point2hex() comparison for %s\n",
21045ca31ee3Stb 		    key->name);
21055ca31ee3Stb 		goto err;
21065ca31ee3Stb 	}
21075ca31ee3Stb 
2108683169a9Stb 	if ((ostr_len = i2o_ECPublicKey(ec_key, &ostr)) <= 0) {
2109683169a9Stb 		fprintf(stderr, "FAIL: i2o_ECPublicKey for %s\n", key->name);
2110683169a9Stb 		goto err;
2111683169a9Stb 	}
2112683169a9Stb 
2113683169a9Stb 	if (compare_data(key->name, ostr, ostr_len, key->oct, key->oct_len) == -1) {
2114683169a9Stb 		fprintf(stderr, "FAIL: i2o_ECPublicKey comparison for %s\n",
2115683169a9Stb 		    key->name);
2116683169a9Stb 		goto err;
2117683169a9Stb 	}
2118683169a9Stb 
21195ca31ee3Stb 	failed = 0;
21205ca31ee3Stb 
21215ca31ee3Stb  err:
21225ca31ee3Stb 	free(hex);
21235ca31ee3Stb 	freezero(ostr, ostr_len);
21245ca31ee3Stb 
21255ca31ee3Stb 	return failed;
21265ca31ee3Stb }
21275ca31ee3Stb 
21285ca31ee3Stb static int
21295ca31ee3Stb ec_key_test_point_versus_bn(const struct ec_private_key *key, const EC_KEY *ec_key)
21305ca31ee3Stb {
21315ca31ee3Stb 	const EC_GROUP *group;
21325ca31ee3Stb 	const EC_POINT *ec_public_point;
21335ca31ee3Stb 	EC_POINT *point = NULL;
21345ca31ee3Stb 	BIGNUM *hex_bn = NULL, *point_bn = NULL;
21355ca31ee3Stb 	int rv;
21365ca31ee3Stb 	int failed = 1;
21375ca31ee3Stb 
21385ca31ee3Stb 	if ((group = EC_KEY_get0_group(ec_key)) == NULL) {
21395ca31ee3Stb 		fprintf(stderr, "FAIL: EC_KEY_get0_group() for %s\n", key->name);
21405ca31ee3Stb 		goto err;
21415ca31ee3Stb 	}
21425ca31ee3Stb 	if ((ec_public_point = EC_KEY_get0_public_key(ec_key)) == NULL) {
21435ca31ee3Stb 		fprintf(stderr, "FAIL: EC_KEY_get0_public_key() for %s\n", key->name);
21445ca31ee3Stb 		goto err;
21455ca31ee3Stb 	}
21465ca31ee3Stb 
2147683169a9Stb 	/*
21485ca31ee3Stb 	 * Check that point2bn matches hex2bn.
2149683169a9Stb 	 */
2150683169a9Stb 
2151683169a9Stb 	if ((point_bn = BN_new()) == NULL)
2152683169a9Stb 		err(1, "BN_new()");
215312cba3bdStb 	if (EC_POINT_point2bn(group, ec_public_point,
215412cba3bdStb 	    POINT_CONVERSION_UNCOMPRESSED, point_bn, NULL) == NULL) {
2155683169a9Stb 		fprintf(stderr, "FAIL: EC_POINT_point2bn() for %s\n", key->name);
2156683169a9Stb 		goto err;
2157683169a9Stb 	}
2158683169a9Stb 
215912cba3bdStb 	if (BN_hex2bn(&hex_bn, key->hex) == 0) {
2160683169a9Stb 		fprintf(stderr, "FAIL: BN_hex2bn() for %s\n", key->name);
2161683169a9Stb 		goto err;
2162683169a9Stb 	}
2163683169a9Stb 
2164683169a9Stb 	if (BN_cmp(hex_bn, point_bn) != 0) {
2165683169a9Stb 		fprintf(stderr, "FAIL: mismatch between "
2166683169a9Stb 		    "hex point and curve point for %s\n", key->name);
2167683169a9Stb 		goto err;
2168683169a9Stb 	}
2169683169a9Stb 
2170683169a9Stb 	/*
21715ca31ee3Stb 	 * Translate back to a point on the curve.
2172683169a9Stb 	 */
2173683169a9Stb 
21745ca31ee3Stb 	if ((point = EC_POINT_hex2point(group, key->hex, NULL, NULL)) == NULL) {
2175683169a9Stb 		fprintf(stderr, "FAIL: EC_POINT_hex2point() failed for %s\n",
2176683169a9Stb 		    key->name);
2177683169a9Stb 		goto err;
2178683169a9Stb 	}
2179683169a9Stb 
2180683169a9Stb 	if ((rv = EC_POINT_cmp(group, ec_public_point, point, NULL)) != 0) {
2181683169a9Stb 		fprintf(stderr, "FAIL: EC_POINT_cmp() returned %d for %s\n",
2182683169a9Stb 		    rv, key->name);
2183683169a9Stb 		goto err;
2184683169a9Stb 	}
2185683169a9Stb 
2186470193d6Stb 	/*
2187470193d6Stb 	 * Invalidate the point by doubling and inverting it. Then see if
2188470193d6Stb 	 * point reuse works.
2189470193d6Stb 	 */
2190470193d6Stb 
2191470193d6Stb 	if (!EC_POINT_dbl(group, point, point, NULL)) {
2192470193d6Stb 		fprintf(stderr, "FAIL: EC_POINT_dbl() failed for %s\n",
2193470193d6Stb 		    key->name);
2194470193d6Stb 		goto err;
2195470193d6Stb 	}
2196470193d6Stb 	if (!EC_POINT_invert(group, point, NULL)) {
2197470193d6Stb 		fprintf(stderr, "FAIL: EC_POINT_invert() failed for %s\n",
2198470193d6Stb 		    key->name);
2199470193d6Stb 		goto err;
2200470193d6Stb 	}
2201470193d6Stb 	if (!EC_POINT_is_on_curve(group, point, NULL)) {
2202470193d6Stb 		fprintf(stderr, "FAIL: EC_POINT_is_on_curve() failed for %s\n",
2203470193d6Stb 		    key->name);
2204470193d6Stb 		goto err;
2205470193d6Stb 	}
2206470193d6Stb 	if (EC_POINT_is_at_infinity(group, point)) {
2207470193d6Stb 		fprintf(stderr, "FAIL: EC_POINT_is_at_infinity() is true for %s\n",
2208470193d6Stb 		    key->name);
2209470193d6Stb 		goto err;
2210470193d6Stb 	}
2211470193d6Stb 
2212470193d6Stb 	/* The points are now different. */
2213470193d6Stb 	if ((rv = EC_POINT_cmp(group, ec_public_point, point, NULL)) == 0) {
2214470193d6Stb 		fprintf(stderr, "FAIL: EC_POINT_cmp() returned %d for %s\n",
2215470193d6Stb 		    rv, key->name);
2216470193d6Stb 		goto err;
2217470193d6Stb 	}
2218470193d6Stb 
22195ca31ee3Stb 	if (EC_POINT_hex2point(group, key->hex, point, NULL) == NULL) {
22205ca31ee3Stb 		fprintf(stderr, "FAIL: EC_POINT_hex2point() 2 failed for %s\n",
2221470193d6Stb 		    key->name);
2222470193d6Stb 		goto err;
2223470193d6Stb 	}
2224470193d6Stb 
2225470193d6Stb 	/* And after reuse they should be the same again. */
2226470193d6Stb 	if ((rv = EC_POINT_cmp(group, ec_public_point, point, NULL)) != 0) {
2227470193d6Stb 		fprintf(stderr, "FAIL: EC_POINT_cmp() returned %d for %s\n",
2228470193d6Stb 		    rv, key->name);
2229470193d6Stb 		goto err;
2230470193d6Stb 	}
2231470193d6Stb 
22325ca31ee3Stb 	failed = 0;
2233683169a9Stb 
22345ca31ee3Stb  err:
22355ca31ee3Stb 	BN_free(hex_bn);
22365ca31ee3Stb 	BN_free(point_bn);
22375ca31ee3Stb 	EC_POINT_free(point);
2238683169a9Stb 
22395ca31ee3Stb 	return failed;
22405ca31ee3Stb }
22415ca31ee3Stb 
22425ca31ee3Stb static int
22435ca31ee3Stb ec_key_test_i2o_and_o2i(const struct ec_private_key *key, const EC_KEY *ec_key_orig)
22445ca31ee3Stb {
22455ca31ee3Stb 	EC_KEY *ec_key = NULL, *ec_pub_key = NULL;
22465ca31ee3Stb 	const unsigned char *p;
22475ca31ee3Stb 	unsigned char *ostr = NULL;
22485ca31ee3Stb 	int ostr_len = 0;
22495ca31ee3Stb 	uint8_t form;
22505ca31ee3Stb 	int rv;
22515ca31ee3Stb 	int failed = 1;
22525ca31ee3Stb 
22535ca31ee3Stb 	if ((ec_key = EC_KEY_dup(ec_key_orig)) == NULL) {
22545ca31ee3Stb 		fprintf(stderr, "FAIL: EC_KEY_dup failed for %s", key->name);
22555ca31ee3Stb 		goto err;
22565ca31ee3Stb 	}
2257da4fd04eStb 
2258da4fd04eStb 	EC_KEY_set_conv_form(ec_key, POINT_CONVERSION_COMPRESSED);
2259da4fd04eStb 
2260da4fd04eStb 	ostr = NULL;
2261da4fd04eStb 	if ((ostr_len = i2o_ECPublicKey(ec_key, &ostr)) <= 0) {
2262da4fd04eStb 		fprintf(stderr, "FAIL: i2o_ECPublicKey for %s\n", key->name);
2263da4fd04eStb 		ostr_len = 0;
2264da4fd04eStb 		goto err;
2265da4fd04eStb 	}
2266da4fd04eStb 
2267da4fd04eStb 	if ((ec_pub_key = EC_KEY_new()) == NULL)
2268da4fd04eStb 		errx(1, "EC_KEY_new");
2269da4fd04eStb 	if (!EC_KEY_set_group(ec_pub_key, EC_KEY_get0_group(ec_key))) {
2270da4fd04eStb 		fprintf(stderr, "FAIL: EC_KEY_set_group() for %s\n", key->name);
2271da4fd04eStb 		goto err;
2272da4fd04eStb 	}
2273da4fd04eStb 
2274da4fd04eStb 	if ((form = EC_KEY_get_conv_form(ec_pub_key)) != POINT_CONVERSION_UNCOMPRESSED) {
2275da4fd04eStb 		fprintf(stderr, "FAIL: EC_KEY_get_conv_form() for %s:\n"
2276da4fd04eStb 		    "got %02x, want %02x\n", key->name, form, POINT_CONVERSION_UNCOMPRESSED);
2277da4fd04eStb 		goto err;
2278da4fd04eStb 	}
2279da4fd04eStb 
2280da4fd04eStb 	/* Need to pass in the public key to tell o2i about the group... */
2281da4fd04eStb 	p = ostr;
2282da4fd04eStb 	if (o2i_ECPublicKey(&ec_pub_key, &p, ostr_len) == NULL) {
2283da4fd04eStb 		fprintf(stderr, "FAIL: o2i_ECPublicKey() for %s\n", key->name);
2284da4fd04eStb 		goto err;
2285da4fd04eStb 	}
2286da4fd04eStb 
2287da4fd04eStb 	if ((form = EC_KEY_get_conv_form(ec_pub_key)) != POINT_CONVERSION_COMPRESSED) {
2288da4fd04eStb 		fprintf(stderr, "FAIL: EC_KEY_get_conv_form() for %s:\n"
2289da4fd04eStb 		    "got %02x, want %02x\n", key->name, form, POINT_CONVERSION_COMPRESSED);
2290da4fd04eStb 		goto err;
2291da4fd04eStb 	}
2292da4fd04eStb 
2293da4fd04eStb 	if ((rv = EC_POINT_cmp(EC_KEY_get0_group(ec_pub_key),
2294da4fd04eStb 	    EC_KEY_get0_public_key(ec_pub_key), EC_KEY_get0_public_key(ec_key),
2295da4fd04eStb 	    NULL)) != 0) {
2296da4fd04eStb 		fprintf(stderr, "FAIL: EC_POINT_cmp() returned %d for %s\n",
2297da4fd04eStb 		    rv, key->name);
2298da4fd04eStb 		goto err;
2299da4fd04eStb 	}
2300da4fd04eStb 
23015ca31ee3Stb 	failed = 0;
23025ca31ee3Stb 
23035ca31ee3Stb  err:
23045ca31ee3Stb 	EC_KEY_free(ec_key);
23055ca31ee3Stb 	EC_KEY_free(ec_pub_key);
23065ca31ee3Stb 	freezero(ostr, ostr_len);
23075ca31ee3Stb 
23085ca31ee3Stb 	return failed;
23095ca31ee3Stb }
23105ca31ee3Stb 
23115ca31ee3Stb static int
23125ca31ee3Stb ec_key_test_hybrid_roundtrip(const struct ec_private_key *key,
23135ca31ee3Stb     const EC_KEY *ec_key_orig)
23145ca31ee3Stb {
23155ca31ee3Stb 	EC_KEY *ec_key = NULL, *ec_pub_key = NULL;
23165ca31ee3Stb 	const unsigned char *p;
23175ca31ee3Stb 	unsigned char *der = NULL;
23185ca31ee3Stb 	int der_len = 0;
23195ca31ee3Stb 	unsigned int flags;
23205ca31ee3Stb 	int rv;
23215ca31ee3Stb 	uint8_t form;
23225ca31ee3Stb 	int failed = 1;
23235ca31ee3Stb 
23245ca31ee3Stb 	if ((ec_key = EC_KEY_new()) == NULL)
23255ca31ee3Stb 		errx(1, "EC_KEY_new()");
23265ca31ee3Stb 
23275ca31ee3Stb 	if (EC_KEY_copy(ec_key, ec_key_orig) == NULL) {
23285ca31ee3Stb 		fprintf(stderr, "FAIL: failed to kopy EC_KEY for %s\n", key->name);
23295ca31ee3Stb 		goto err;
23305ca31ee3Stb 	}
23315ca31ee3Stb 
2332da4fd04eStb 	EC_KEY_set_conv_form(ec_key, POINT_CONVERSION_HYBRID);
2333da4fd04eStb 	EC_KEY_set_enc_flags(ec_key, EC_PKEY_NO_PARAMETERS | EC_PKEY_NO_PUBKEY);
2334da4fd04eStb 
2335da4fd04eStb 	if ((der_len = i2d_ECPrivateKey(ec_key, &der)) <= 0) {
2336da4fd04eStb 		fprintf(stderr, "FAIL: i2d_ECPrivateKey(2) for %s\n", key->name);
2337da4fd04eStb 		der_len = 0;
2338da4fd04eStb 		goto err;
2339da4fd04eStb 	}
2340da4fd04eStb 
23415ca31ee3Stb 	if ((ec_pub_key = EC_KEY_new()) == NULL)
23425ca31ee3Stb 		errx(1, "EC_KEY_new");
23435ca31ee3Stb 	if (!EC_KEY_set_group(ec_pub_key, EC_KEY_get0_group(ec_key))) {
23445ca31ee3Stb 		fprintf(stderr, "FAIL: EC_KEY_set_group() for %s\n", key->name);
23455ca31ee3Stb 		goto err;
23465ca31ee3Stb 	}
23475ca31ee3Stb 	/* Change away from the default to see if it changed below. */
23485ca31ee3Stb 	EC_KEY_set_conv_form(ec_pub_key, POINT_CONVERSION_COMPRESSED);
23495ca31ee3Stb 
2350da4fd04eStb 	if ((flags = EC_KEY_get_enc_flags(ec_pub_key)) != 0) {
2351da4fd04eStb 		fprintf(stderr, "FAIL: EC_KEY_get_enc_flags() returned %x for %s\n",
2352da4fd04eStb 		    flags, key->name);
2353da4fd04eStb 		goto err;
2354da4fd04eStb 	}
2355da4fd04eStb 
2356da4fd04eStb 	p = der;
2357da4fd04eStb 	if (d2i_ECPrivateKey(&ec_pub_key, &p, der_len) == NULL) {
2358da4fd04eStb 		fprintf(stderr, "FAIL: d2i_ECPrivateKey for public %s\n", key->name);
2359da4fd04eStb 		goto err;
2360da4fd04eStb 	}
2361da4fd04eStb 
2362da4fd04eStb 	/* For reasons of inconsistency, only EC_PKEY_NO_PUBKEY is set. */
2363da4fd04eStb 	if ((flags = EC_KEY_get_enc_flags(ec_pub_key)) != EC_PKEY_NO_PUBKEY) {
2364da4fd04eStb 		fprintf(stderr, "FAIL: EC_KEY_get_enc_flags() for public %s: "
2365da4fd04eStb 		    " got %x, want %x\n", key->name, flags, EC_PKEY_NO_PUBKEY);
2366da4fd04eStb 		goto err;
2367da4fd04eStb 	}
2368da4fd04eStb 
2369da4fd04eStb 	/* We had to compute the public key, so point conversion form is unchanged. */
2370da4fd04eStb 	if ((form = EC_KEY_get_conv_form(ec_pub_key)) != POINT_CONVERSION_COMPRESSED) {
2371da4fd04eStb 		fprintf(stderr, "FAIL: EC_KEY_get_conv_form() not compressed for %s:\n"
2372da4fd04eStb 		    "got %02x, want %02x\n", key->name, form, POINT_CONVERSION_COMPRESSED);
2373da4fd04eStb 		goto err;
2374da4fd04eStb 	}
2375da4fd04eStb 
2376da4fd04eStb 	if ((rv = EC_POINT_cmp(EC_KEY_get0_group(ec_pub_key),
2377da4fd04eStb 	    EC_KEY_get0_public_key(ec_pub_key), EC_KEY_get0_public_key(ec_key),
2378da4fd04eStb 	    NULL)) != 0) {
2379da4fd04eStb 		fprintf(stderr, "FAIL: EC_POINT_cmp() returned %d for %s "
2380da4fd04eStb 		    "after DER roundtrip\n", rv, key->name);
2381da4fd04eStb 		goto err;
2382da4fd04eStb 	}
2383da4fd04eStb 
23845ca31ee3Stb 	failed = 0;
23857336055fStb 
23865ca31ee3Stb  err:
23875ca31ee3Stb 	EC_KEY_free(ec_key);
23885ca31ee3Stb 	EC_KEY_free(ec_pub_key);
23897336055fStb 	freezero(der, der_len);
23905ca31ee3Stb 
23915ca31ee3Stb 	return failed;
23925ca31ee3Stb }
23935ca31ee3Stb 
23945ca31ee3Stb static int
23955ca31ee3Stb ec_key_test_parameter_roundtrip(const struct ec_private_key *key,
23965ca31ee3Stb     EC_KEY *ec_key)
23975ca31ee3Stb {
23985ca31ee3Stb 	EC_KEY *ec_pub_key = NULL;
23995ca31ee3Stb 	const unsigned char *p;
24005ca31ee3Stb 	unsigned char *der = NULL;
24015ca31ee3Stb 	int der_len = 0;
24025ca31ee3Stb 	int rv;
24035ca31ee3Stb 	int failed = 1;
24047336055fStb 
24057336055fStb 	if ((der_len = i2d_ECParameters(ec_key, &der)) <= 0) {
24067336055fStb 		fprintf(stderr, "FAIL: i2d_ECParameters returned %d for %s\n",
24077336055fStb 		    der_len, key->name);
24087336055fStb 		goto err;
24097336055fStb 	}
24107336055fStb 
24115ca31ee3Stb 	/* See if we leak on reuse, whether the curve is right or not. */
24125ca31ee3Stb 	if ((ec_pub_key = EC_KEY_new_by_curve_name(NID_secp256k1)) == NULL)
24135ca31ee3Stb 		errx(1, "EC_KEY_new_by_curve_name");
24145ca31ee3Stb 
24157336055fStb 	p = der;
24167336055fStb 	if (d2i_ECParameters(&ec_pub_key, &p, der_len) == NULL) {
24177336055fStb 		fprintf(stderr, "FAIL: d2i_ECParameters for %s\n", key->name);
24187336055fStb 		goto err;
24197336055fStb 	}
24207336055fStb 
24217336055fStb 	if ((rv = EC_GROUP_cmp(EC_KEY_get0_group(ec_key),
24227336055fStb 	    EC_KEY_get0_group(ec_pub_key), NULL)) != 0) {
24237336055fStb 		fprintf(stderr, "FAIL: EC_GROUP_cmp returned %d for %s\n",
24247336055fStb 		    rv, key->name);
24257336055fStb 		goto err;
24267336055fStb 	}
24277336055fStb 
2428da4fd04eStb 	failed = 0;
2429da4fd04eStb 
2430da4fd04eStb  err:
2431da4fd04eStb 	EC_KEY_free(ec_pub_key);
2432da4fd04eStb 	freezero(der, der_len);
2433683169a9Stb 
24345ca31ee3Stb 	return failed;
24355ca31ee3Stb }
2436683169a9Stb 
24375ca31ee3Stb static int
24385ca31ee3Stb ec_group_check_private_key(const struct ec_private_key *key)
24395ca31ee3Stb {
24405ca31ee3Stb 	EC_KEY *ec_key = NULL;
24415ca31ee3Stb 	int failed = 0;
24425ca31ee3Stb 
24435ca31ee3Stb 	if ((ec_key = ec_key_check_sanity(key)) == NULL) {
24445ca31ee3Stb 		fprintf(stderr, "FAIL: ec_key_check_sanity() for %s\n", key->name);
24455ca31ee3Stb 		failed = 1;
24465ca31ee3Stb 		goto err;
24475ca31ee3Stb 	}
24485ca31ee3Stb 
24495ca31ee3Stb 	failed |= ec_key_test_point_encoding(key, ec_key);
24505ca31ee3Stb 	failed |= ec_key_test_point_versus_bn(key, ec_key);
24515ca31ee3Stb 	failed |= ec_key_test_i2o_and_o2i(key, ec_key);
24525ca31ee3Stb 	failed |= ec_key_test_hybrid_roundtrip(key, ec_key);
24535ca31ee3Stb 	failed |= ec_key_test_parameter_roundtrip(key, ec_key);
24545ca31ee3Stb 
24555ca31ee3Stb  err:
24565ca31ee3Stb 	EC_KEY_free(ec_key);
2457da4fd04eStb 
2458da4fd04eStb 	return failed;
2459da4fd04eStb }
2460da4fd04eStb 
2461da4fd04eStb static int
2462da4fd04eStb ec_group_check_private_keys(void)
2463da4fd04eStb {
2464da4fd04eStb 	size_t i;
2465da4fd04eStb 	int failed = 0;
2466da4fd04eStb 
2467da4fd04eStb 	for (i = 0; i < N_EC_PRIVATE_KEYS; i++)
2468da4fd04eStb 		failed |= ec_group_check_private_key(&ec_private_keys[i]);
2469da4fd04eStb 
2470da4fd04eStb 	return failed;
2471da4fd04eStb }
2472da4fd04eStb 
24736bd9d0e3Sjsing int
24746bd9d0e3Sjsing main(int argc, char **argv)
24756bd9d0e3Sjsing {
24766bd9d0e3Sjsing 	int failed = 0;
24776bd9d0e3Sjsing 
24786bd9d0e3Sjsing 	failed |= ec_group_pkparameters_named_curve_test();
24796bd9d0e3Sjsing 	failed |= ec_group_pkparameters_parameters_test();
2480cdd7a87bStb 	failed |= ec_group_pkparameters_correct_padding_test();
248133e95073Stb 	failed |= ec_group_roundtrip_builtin_curves();
2482194b9aa8Stb 	failed |= ec_group_non_builtin_curves();
2483da4fd04eStb 	failed |= ec_group_check_private_keys();
24846bd9d0e3Sjsing 
248592c4bfc1Stb 	return failed;
24866bd9d0e3Sjsing }
2487