diff options
author | tb <> | 2024-10-18 10:40:31 +0000 |
---|---|---|
committer | tb <> | 2024-10-18 10:40:31 +0000 |
commit | f6b142438e4de70bc2690dcdfa2e354386b6b58b (patch) | |
tree | 4878fcf0ffa1642089d2f0b6b86d4008f9cb9346 /src | |
parent | d8d69638ed30e51875ebb0eed8f79fce680b1a2d (diff) | |
download | openbsd-f6b142438e4de70bc2690dcdfa2e354386b6b58b.tar.gz openbsd-f6b142438e4de70bc2690dcdfa2e354386b6b58b.tar.bz2 openbsd-f6b142438e4de70bc2690dcdfa2e354386b6b58b.zip |
ec_asn1_test: add secp256k1.m
Diffstat (limited to 'src')
-rw-r--r-- | src/regress/lib/libcrypto/ec/ec_asn1_test.c | 91 |
1 files changed, 81 insertions, 10 deletions
diff --git a/src/regress/lib/libcrypto/ec/ec_asn1_test.c b/src/regress/lib/libcrypto/ec/ec_asn1_test.c index 060d8e581f..e5e899264d 100644 --- a/src/regress/lib/libcrypto/ec/ec_asn1_test.c +++ b/src/regress/lib/libcrypto/ec/ec_asn1_test.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ec_asn1_test.c,v 1.9 2024/10/18 10:12:25 tb Exp $ */ | 1 | /* $OpenBSD: ec_asn1_test.c,v 1.10 2024/10/18 10:40:31 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 | * Copyright (c) 2024 Theo Buehler <tb@openbsd.org> |
@@ -24,12 +24,12 @@ | |||
24 | #include <openssl/err.h> | 24 | #include <openssl/err.h> |
25 | #include <openssl/objects.h> | 25 | #include <openssl/objects.h> |
26 | 26 | ||
27 | const uint8_t ec_secp256r1_pkparameters_named_curve[] = { | 27 | static const uint8_t ec_secp256r1_pkparameters_named_curve[] = { |
28 | 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, | 28 | 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, |
29 | 0x01, 0x07, | 29 | 0x01, 0x07, |
30 | }; | 30 | }; |
31 | 31 | ||
32 | const uint8_t ec_secp256r1_pkparameters_parameters[] = { | 32 | static const uint8_t ec_secp256r1_pkparameters_parameters[] = { |
33 | 0x30, 0x81, 0xf7, 0x02, 0x01, 0x01, 0x30, 0x2c, | 33 | 0x30, 0x81, 0xf7, 0x02, 0x01, 0x01, 0x30, 0x2c, |
34 | 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x01, | 34 | 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x01, |
35 | 0x01, 0x02, 0x21, 0x00, 0xff, 0xff, 0xff, 0xff, | 35 | 0x01, 0x02, 0x21, 0x00, 0xff, 0xff, 0xff, 0xff, |
@@ -64,7 +64,7 @@ const uint8_t ec_secp256r1_pkparameters_parameters[] = { | |||
64 | 0x01, 0x01, | 64 | 0x01, 0x01, |
65 | }; | 65 | }; |
66 | 66 | ||
67 | const uint8_t ec_secp256k1_pkparameters_parameters[] = { | 67 | static const uint8_t ec_secp256k1_pkparameters_parameters[] = { |
68 | 0x30, 0x81, 0xe0, 0x02, 0x01, 0x01, 0x30, 0x2c, | 68 | 0x30, 0x81, 0xe0, 0x02, 0x01, 0x01, 0x30, 0x2c, |
69 | 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x01, | 69 | 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x01, |
70 | 0x01, 0x02, 0x21, 0x00, 0xff, 0xff, 0xff, 0xff, | 70 | 0x01, 0x02, 0x21, 0x00, 0xff, 0xff, 0xff, 0xff, |
@@ -352,6 +352,7 @@ struct curve { | |||
352 | const char *cofactor; | 352 | const char *cofactor; |
353 | const char *x; | 353 | const char *x; |
354 | const char *y; | 354 | const char *y; |
355 | int known_named_curve; | ||
355 | const char *named; | 356 | const char *named; |
356 | size_t named_len; | 357 | size_t named_len; |
357 | const char *param; | 358 | const char *param; |
@@ -362,11 +363,11 @@ struct curve { | |||
362 | * From draft-ietf-lwig-curve-representation-23, Appendix E.3 | 363 | * From draft-ietf-lwig-curve-representation-23, Appendix E.3 |
363 | */ | 364 | */ |
364 | 365 | ||
365 | const uint8_t ec_wei25519_pkparameters_named_curve[] = { | 366 | static const uint8_t ec_wei25519_pkparameters_named_curve[] = { |
366 | 0x06, 0x03, 0x2b, 0x65, 0x6c, | 367 | 0x06, 0x03, 0x2b, 0x65, 0x6c, |
367 | }; | 368 | }; |
368 | 369 | ||
369 | const uint8_t ec_wei25519_pkparameters_parameters[] = { | 370 | static const uint8_t ec_wei25519_pkparameters_parameters[] = { |
370 | 0x30, 0x81, 0xde, 0x02, 0x01, 0x01, 0x30, 0x2b, | 371 | 0x30, 0x81, 0xde, 0x02, 0x01, 0x01, 0x30, 0x2b, |
371 | 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x01, | 372 | 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x01, |
372 | 0x01, 0x02, 0x20, 0x7f, 0xff, 0xff, 0xff, 0xff, | 373 | 0x01, 0x02, 0x20, 0x7f, 0xff, 0xff, 0xff, 0xff, |
@@ -425,7 +426,7 @@ static const struct curve wei25519 = { | |||
425 | * From draft-ietf-lwig-curve-representation-23, Appendix G.3 | 426 | * From draft-ietf-lwig-curve-representation-23, Appendix G.3 |
426 | */ | 427 | */ |
427 | 428 | ||
428 | const uint8_t ec_wei25519_2_pkparameters_parameters[] = { | 429 | static const uint8_t ec_wei25519_2_pkparameters_parameters[] = { |
429 | 0x30, 0x81, 0xde, 0x02, 0x01, 0x01, 0x30, 0x2b, | 430 | 0x30, 0x81, 0xde, 0x02, 0x01, 0x01, 0x30, 0x2b, |
430 | 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x01, | 431 | 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x01, |
431 | 0x01, 0x02, 0x20, 0x7f, 0xff, 0xff, 0xff, 0xff, | 432 | 0x01, 0x02, 0x20, 0x7f, 0xff, 0xff, 0xff, 0xff, |
@@ -479,7 +480,7 @@ static const struct curve wei25519_2 = { | |||
479 | .param_len = sizeof(ec_wei25519_2_pkparameters_parameters), | 480 | .param_len = sizeof(ec_wei25519_2_pkparameters_parameters), |
480 | }; | 481 | }; |
481 | 482 | ||
482 | const uint8_t ec_wei25519_3_pkparameters_parameters[] = { | 483 | static const uint8_t ec_wei25519_3_pkparameters_parameters[] = { |
483 | 0x30, 0x81, 0xde, 0x02, 0x01, 0x01, 0x30, 0x2b, | 484 | 0x30, 0x81, 0xde, 0x02, 0x01, 0x01, 0x30, 0x2b, |
484 | 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x01, | 485 | 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x01, |
485 | 0x01, 0x02, 0x20, 0x7f, 0xff, 0xff, 0xff, 0xff, | 486 | 0x01, 0x02, 0x20, 0x7f, 0xff, 0xff, 0xff, 0xff, |
@@ -539,6 +540,69 @@ static const struct curve wei25519_3 = { | |||
539 | .param_len = sizeof(ec_wei25519_3_pkparameters_parameters), | 540 | .param_len = sizeof(ec_wei25519_3_pkparameters_parameters), |
540 | }; | 541 | }; |
541 | 542 | ||
543 | /* | ||
544 | * From draft-ietf-lwig-curve-representation-23, Appendix L.3 | ||
545 | */ | ||
546 | |||
547 | static const uint8_t ec_secp256k1_m_pkparameters_named_curve[] = { | ||
548 | 0x06, 0x05, 0x2b, 0x81, 0x04, 0x00, 0x0a, | ||
549 | }; | ||
550 | |||
551 | static const uint8_t ec_secp256k1_m_pkparameters_parameters[] = { | ||
552 | 0x30, 0x81, 0xe0, 0x02, 0x01, 0x01, 0x30, 0x2c, | ||
553 | 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x01, | ||
554 | 0x01, 0x02, 0x21, 0x00, 0xff, 0xff, 0xff, 0xff, | ||
555 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | ||
556 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | ||
557 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, | ||
558 | 0xff, 0xff, 0xfc, 0x2f, 0x30, 0x44, 0x04, 0x20, | ||
559 | 0xcf, 0xcd, 0x5c, 0x21, 0x75, 0xe2, 0xef, 0x7d, | ||
560 | 0xcc, 0xdc, 0xe7, 0x37, 0x77, 0x0b, 0x73, 0x81, | ||
561 | 0x5a, 0x2f, 0x13, 0xc5, 0x09, 0x03, 0x5c, 0xa2, | ||
562 | 0x54, 0xa1, 0x4a, 0xc9, 0xf0, 0x89, 0x74, 0xaf, | ||
563 | 0x04, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
564 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
565 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
566 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
567 | 0x06, 0xeb, 0x04, 0x41, 0x04, 0x3a, 0xca, 0x53, | ||
568 | 0x00, 0x95, 0x9f, 0xa1, 0xd0, 0xba, 0xf7, 0x8d, | ||
569 | 0xcf, 0xf7, 0x7a, 0x61, 0x6f, 0x39, 0x5e, 0x58, | ||
570 | 0x6d, 0x67, 0xac, 0xed, 0x0a, 0x88, 0x79, 0x81, | ||
571 | 0x29, 0x0c, 0x27, 0x91, 0x45, 0x95, 0x80, 0xfc, | ||
572 | 0xe5, 0x3a, 0x17, 0x0f, 0x4f, 0xb7, 0x44, 0x57, | ||
573 | 0x9f, 0xf3, 0xd6, 0x20, 0x86, 0x12, 0xcd, 0x6a, | ||
574 | 0x23, 0x3e, 0x2d, 0xe2, 0x37, 0xf9, 0x76, 0xc6, | ||
575 | 0xa7, 0x86, 0x11, 0xc8, 0x00, 0x02, 0x21, 0x00, | ||
576 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, | ||
577 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, | ||
578 | 0xba, 0xae, 0xdc, 0xe6, 0xaf, 0x48, 0xa0, 0x3b, | ||
579 | 0xbf, 0xd2, 0x5e, 0x8c, 0xd0, 0x36, 0x41, 0x41, | ||
580 | 0x02, 0x01, 0x01, | ||
581 | }; | ||
582 | |||
583 | static const struct curve secp256k1_m = { | ||
584 | .descr = "short Weierstrass secp256k1.m", | ||
585 | .oid = "1.3.132.0.10", | ||
586 | .sn = SN_secp256k1, | ||
587 | .p = "ffffffff" "ffffffff" "ffffffff" "ffffffff" | ||
588 | "ffffffff" "ffffffff" "fffffffe" "fffffc2f", | ||
589 | .a = "cfcd5c21" "75e2ef7d" "ccdce737" "770b7381" | ||
590 | "5a2f13c5" "09035ca2" "54a14ac9" "f08974af", | ||
591 | .b = "06eb", | ||
592 | .x = "3aca5300" "959fa1d0" "baf78dcf" "f77a616f" | ||
593 | "395e586d" "67aced0a" "88798129" "0c279145", | ||
594 | .y = "9580fce5" "3a170f4f" "b744579f" "f3d62086" | ||
595 | "12cd6a23" "3e2de237" "f976c6a7" "8611c800", | ||
596 | .order = "ffffffff" "ffffffff" "ffffffff" "fffffffe" | ||
597 | "baaedce6" "af48a03b" "bfd25e8c" "d0364141", | ||
598 | .cofactor = "1", | ||
599 | .known_named_curve = 1, | ||
600 | .named = ec_secp256k1_m_pkparameters_named_curve, | ||
601 | .named_len = sizeof(ec_secp256k1_m_pkparameters_named_curve), | ||
602 | .param = ec_secp256k1_m_pkparameters_parameters, | ||
603 | .param_len = sizeof(ec_secp256k1_m_pkparameters_parameters), | ||
604 | }; | ||
605 | |||
542 | static EC_GROUP * | 606 | static EC_GROUP * |
543 | ec_group_from_curve_method(const struct curve *curve, const EC_METHOD *method, | 607 | ec_group_from_curve_method(const struct curve *curve, const EC_METHOD *method, |
544 | BN_CTX *ctx) | 608 | BN_CTX *ctx) |
@@ -752,14 +816,18 @@ ec_group_non_builtin_curve(const struct curve *curve, const EC_METHOD *method, | |||
752 | 816 | ||
753 | pder = curve->named; | 817 | pder = curve->named; |
754 | der_len = curve->named_len; | 818 | der_len = curve->named_len; |
755 | if ((new_group = d2i_ECPKParameters(NULL, &pder, der_len)) != NULL) { | 819 | new_group = d2i_ECPKParameters(NULL, &pder, der_len); |
820 | if (!curve->known_named_curve && new_group != NULL) { | ||
756 | fprintf(stderr, "FAIL: managed to decode unknown named curve %s\n", | 821 | fprintf(stderr, "FAIL: managed to decode unknown named curve %s\n", |
757 | curve->descr); | 822 | curve->descr); |
758 | goto err; | 823 | goto err; |
759 | } | 824 | } |
825 | EC_GROUP_free(new_group); | ||
826 | new_group = NULL; | ||
760 | 827 | ||
761 | error = ERR_get_error(); | 828 | error = ERR_get_error(); |
762 | if (ERR_GET_REASON(error) != EC_R_UNKNOWN_GROUP) { | 829 | if (!curve->known_named_curve && |
830 | ERR_GET_REASON(error) != EC_R_UNKNOWN_GROUP) { | ||
763 | fprintf(stderr, "FAIL: %s unexpected error: want %d, got %d\n", | 831 | fprintf(stderr, "FAIL: %s unexpected error: want %d, got %d\n", |
764 | curve->descr, EC_R_UNKNOWN_GROUP, ERR_GET_REASON(error)); | 832 | curve->descr, EC_R_UNKNOWN_GROUP, ERR_GET_REASON(error)); |
765 | goto err; | 833 | goto err; |
@@ -825,6 +893,9 @@ ec_group_non_builtin_curves(void) | |||
825 | failed |= ec_group_non_builtin_curve(&wei25519_3, EC_GFp_mont_method(), ctx); | 893 | failed |= ec_group_non_builtin_curve(&wei25519_3, EC_GFp_mont_method(), ctx); |
826 | failed |= ec_group_non_builtin_curve(&wei25519_3, EC_GFp_simple_method(), ctx); | 894 | failed |= ec_group_non_builtin_curve(&wei25519_3, EC_GFp_simple_method(), ctx); |
827 | 895 | ||
896 | failed |= ec_group_non_builtin_curve(&secp256k1_m, EC_GFp_mont_method(), ctx); | ||
897 | failed |= ec_group_non_builtin_curve(&secp256k1_m, EC_GFp_simple_method(), ctx); | ||
898 | |||
828 | BN_CTX_free(ctx); | 899 | BN_CTX_free(ctx); |
829 | 900 | ||
830 | return failed; | 901 | return failed; |