diff options
author | tb <> | 2024-10-14 13:16:06 +0000 |
---|---|---|
committer | tb <> | 2024-10-14 13:16:06 +0000 |
commit | 939ccd0e181b428fca15e1490ea4674e1889b09e (patch) | |
tree | 394e7d26d335d720cf761699db54ca676aca52e3 /src | |
parent | eed149b404574c0b530d9a1504778f70e207eb9e (diff) | |
download | openbsd-939ccd0e181b428fca15e1490ea4674e1889b09e.tar.gz openbsd-939ccd0e181b428fca15e1490ea4674e1889b09e.tar.bz2 openbsd-939ccd0e181b428fca15e1490ea4674e1889b09e.zip |
Extend ec_asn1_test to check for correct curve coefficient encoding
Diffstat (limited to 'src')
-rw-r--r-- | src/regress/lib/libcrypto/ec/ec_asn1_test.c | 55 |
1 files changed, 50 insertions, 5 deletions
diff --git a/src/regress/lib/libcrypto/ec/ec_asn1_test.c b/src/regress/lib/libcrypto/ec/ec_asn1_test.c index 321ee5c657..467fd17bc8 100644 --- a/src/regress/lib/libcrypto/ec/ec_asn1_test.c +++ b/src/regress/lib/libcrypto/ec/ec_asn1_test.c | |||
@@ -1,6 +1,7 @@ | |||
1 | /* $OpenBSD: ec_asn1_test.c,v 1.3 2024/10/12 16:15:28 tb Exp $ */ | 1 | /* $OpenBSD: ec_asn1_test.c,v 1.4 2024/10/14 13:16:06 tb Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2017, 2021 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2017, 2021 Joel Sing <jsing@openbsd.org> |
4 | * Copyright (c) 2024 Theo Buehler <tb@openbsd.org> | ||
4 | * | 5 | * |
5 | * Permission to use, copy, modify, and distribute this software for any | 6 | * Permission to use, copy, modify, and distribute this software for any |
6 | * purpose with or without fee is hereby granted, provided that the above | 7 | * purpose with or without fee is hereby granted, provided that the above |
@@ -62,6 +63,38 @@ const uint8_t ec_secp256r1_pkparameters_parameters[] = { | |||
62 | 0x01, 0x01, | 63 | 0x01, 0x01, |
63 | }; | 64 | }; |
64 | 65 | ||
66 | const uint8_t ec_secp256k1_pkparameters_parameters[] = { | ||
67 | 0x30, 0x81, 0xe0, 0x02, 0x01, 0x01, 0x30, 0x2c, | ||
68 | 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x01, | ||
69 | 0x01, 0x02, 0x21, 0x00, 0xff, 0xff, 0xff, 0xff, | ||
70 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | ||
71 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | ||
72 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, | ||
73 | 0xff, 0xff, 0xfc, 0x2f, 0x30, 0x44, 0x04, 0x20, | ||
74 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
75 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
76 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
77 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
78 | 0x04, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
79 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
80 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
81 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
82 | 0x00, 0x07, 0x04, 0x41, 0x04, 0x79, 0xbe, 0x66, | ||
83 | 0x7e, 0xf9, 0xdc, 0xbb, 0xac, 0x55, 0xa0, 0x62, | ||
84 | 0x95, 0xce, 0x87, 0x0b, 0x07, 0x02, 0x9b, 0xfc, | ||
85 | 0xdb, 0x2d, 0xce, 0x28, 0xd9, 0x59, 0xf2, 0x81, | ||
86 | 0x5b, 0x16, 0xf8, 0x17, 0x98, 0x48, 0x3a, 0xda, | ||
87 | 0x77, 0x26, 0xa3, 0xc4, 0x65, 0x5d, 0xa4, 0xfb, | ||
88 | 0xfc, 0x0e, 0x11, 0x08, 0xa8, 0xfd, 0x17, 0xb4, | ||
89 | 0x48, 0xa6, 0x85, 0x54, 0x19, 0x9c, 0x47, 0xd0, | ||
90 | 0x8f, 0xfb, 0x10, 0xd4, 0xb8, 0x02, 0x21, 0x00, | ||
91 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | ||
92 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, | ||
93 | 0xba, 0xae, 0xdc, 0xe6, 0xaf, 0x48, 0xa0, 0x3b, | ||
94 | 0xbf, 0xd2, 0x5e, 0x8c, 0xd0, 0x36, 0x41, 0x41, | ||
95 | 0x02, 0x01, 0x01, | ||
96 | }; | ||
97 | |||
65 | static void | 98 | static void |
66 | hexdump(const unsigned char *buf, size_t len) | 99 | hexdump(const unsigned char *buf, size_t len) |
67 | { | 100 | { |
@@ -94,7 +127,7 @@ compare_data(const char *label, const unsigned char *d1, size_t d1_len, | |||
94 | } | 127 | } |
95 | 128 | ||
96 | static int | 129 | static int |
97 | ec_group_pkparameters_test(const char *label, int asn1_flag, | 130 | ec_group_pkparameters_test(const char *label, int nid, int asn1_flag, |
98 | const uint8_t *test_data, size_t test_data_len) | 131 | const uint8_t *test_data, size_t test_data_len) |
99 | { | 132 | { |
100 | EC_GROUP *group_a = NULL, *group_b = NULL; | 133 | EC_GROUP *group_a = NULL, *group_b = NULL; |
@@ -107,7 +140,7 @@ ec_group_pkparameters_test(const char *label, int asn1_flag, | |||
107 | /* | 140 | /* |
108 | * Test i2d_ECPKParameters/d2i_ECPKParameters. | 141 | * Test i2d_ECPKParameters/d2i_ECPKParameters. |
109 | */ | 142 | */ |
110 | if ((group_a = EC_GROUP_new_by_curve_name(NID_X9_62_prime256v1)) == NULL) | 143 | if ((group_a = EC_GROUP_new_by_curve_name(nid)) == NULL) |
111 | errx(1, "failed to create EC_GROUP"); | 144 | errx(1, "failed to create EC_GROUP"); |
112 | 145 | ||
113 | EC_GROUP_set_asn1_flag(group_a, asn1_flag); | 146 | EC_GROUP_set_asn1_flag(group_a, asn1_flag); |
@@ -182,7 +215,8 @@ static int | |||
182 | ec_group_pkparameters_named_curve_test(void) | 215 | ec_group_pkparameters_named_curve_test(void) |
183 | { | 216 | { |
184 | return ec_group_pkparameters_test("ECPKPARAMETERS named curve", | 217 | return ec_group_pkparameters_test("ECPKPARAMETERS named curve", |
185 | OPENSSL_EC_NAMED_CURVE, ec_secp256r1_pkparameters_named_curve, | 218 | NID_X9_62_prime256v1, OPENSSL_EC_NAMED_CURVE, |
219 | ec_secp256r1_pkparameters_named_curve, | ||
186 | sizeof(ec_secp256r1_pkparameters_named_curve)); | 220 | sizeof(ec_secp256r1_pkparameters_named_curve)); |
187 | } | 221 | } |
188 | 222 | ||
@@ -190,11 +224,21 @@ static int | |||
190 | ec_group_pkparameters_parameters_test(void) | 224 | ec_group_pkparameters_parameters_test(void) |
191 | { | 225 | { |
192 | return ec_group_pkparameters_test("ECPKPARAMETERS parameters", | 226 | return ec_group_pkparameters_test("ECPKPARAMETERS parameters", |
193 | OPENSSL_EC_EXPLICIT_CURVE, ec_secp256r1_pkparameters_parameters, | 227 | NID_X9_62_prime256v1, OPENSSL_EC_EXPLICIT_CURVE, |
228 | ec_secp256r1_pkparameters_parameters, | ||
194 | sizeof(ec_secp256r1_pkparameters_parameters)); | 229 | sizeof(ec_secp256r1_pkparameters_parameters)); |
195 | } | 230 | } |
196 | 231 | ||
197 | static int | 232 | static int |
233 | ec_group_pkparameters_correct_padding_test(void) | ||
234 | { | ||
235 | return ec_group_pkparameters_test("ECPKPARAMETERS parameters", | ||
236 | NID_secp256k1, OPENSSL_EC_EXPLICIT_CURVE, | ||
237 | ec_secp256k1_pkparameters_parameters, | ||
238 | sizeof(ec_secp256k1_pkparameters_parameters)); | ||
239 | } | ||
240 | |||
241 | static int | ||
198 | ec_group_roundtrip_curve(const EC_GROUP *group, const char *descr, int nid) | 242 | ec_group_roundtrip_curve(const EC_GROUP *group, const char *descr, int nid) |
199 | { | 243 | { |
200 | EC_GROUP *new_group = NULL; | 244 | EC_GROUP *new_group = NULL; |
@@ -302,6 +346,7 @@ main(int argc, char **argv) | |||
302 | 346 | ||
303 | failed |= ec_group_pkparameters_named_curve_test(); | 347 | failed |= ec_group_pkparameters_named_curve_test(); |
304 | failed |= ec_group_pkparameters_parameters_test(); | 348 | failed |= ec_group_pkparameters_parameters_test(); |
349 | failed |= ec_group_pkparameters_correct_padding_test(); | ||
305 | failed |= ec_group_roundtrip_builtin_curves(); | 350 | failed |= ec_group_roundtrip_builtin_curves(); |
306 | 351 | ||
307 | return (failed); | 352 | return (failed); |