summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortb <>2024-10-25 07:31:02 +0000
committertb <>2024-10-25 07:31:02 +0000
commitfdbd7e1f9e402dcad866c4b90773f2e4118b6b26 (patch)
tree6598b7450250402bbaa3a05d44c33ac0930f0392 /src
parent2d0e5da61d38a5b3eb06ca9991a33f5a2e380902 (diff)
downloadopenbsd-fdbd7e1f9e402dcad866c4b90773f2e4118b6b26.tar.gz
openbsd-fdbd7e1f9e402dcad866c4b90773f2e4118b6b26.tar.bz2
openbsd-fdbd7e1f9e402dcad866c4b90773f2e4118b6b26.zip
Use macros describing the intent rather than #if 0
Diffstat (limited to 'src')
-rw-r--r--src/regress/lib/libcrypto/ec/ec_asn1_test.c46
1 files changed, 38 insertions, 8 deletions
diff --git a/src/regress/lib/libcrypto/ec/ec_asn1_test.c b/src/regress/lib/libcrypto/ec/ec_asn1_test.c
index 5fd4475466..c899c418fd 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.14 2024/10/25 00:18:19 tb Exp $ */ 1/* $OpenBSD: ec_asn1_test.c,v 1.15 2024/10/25 07:31:02 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,6 +24,11 @@
24#include <openssl/err.h> 24#include <openssl/err.h>
25#include <openssl/objects.h> 25#include <openssl/objects.h>
26 26
27/* set to 0 if/when we are going to enforce 0 <= a,b < p. */
28#define NEGATIVE_CURVE_COEFFICIENTS_ALLOWED 1
29/* unifdef once private key padding in i2d_ECPrivateKey() is fixed. */
30#define CORRECT_PRIV_KEY_PADDING 0
31
27static const uint8_t ec_secp256r1_pkparameters_named_curve[] = { 32static const uint8_t ec_secp256r1_pkparameters_named_curve[] = {
28 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 33 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03,
29 0x01, 0x07, 34 0x01, 0x07,
@@ -525,13 +530,32 @@ static const struct curve wei25519_3 = {
525 .sn = "Wei25519", 530 .sn = "Wei25519",
526 .p = "7fffffff" "ffffffff" "ffffffff" "ffffffff" 531 .p = "7fffffff" "ffffffff" "ffffffff" "ffffffff"
527 "ffffffff" "ffffffff" "ffffffff" "ffffffed", 532 "ffffffff" "ffffffff" "ffffffff" "ffffffed",
528/* XXX - change this if we are going to enforce 0 <= a,b < p. */
529#if 0
530 .a = "7fffffff" "ffffffff" "ffffffff" "ffffffff" 533 .a = "7fffffff" "ffffffff" "ffffffff" "ffffffff"
531 "ffffffff" "ffffffff" "ffffffff" "ffffffea", 534 "ffffffff" "ffffffff" "ffffffff" "ffffffea",
532#else 535 .b = "41a3b6bf" "c668778e" "be2954a4" "b1df36d1"
536 "485ecef1" "ea614295" "796e1022" "40891faa",
537 .x = "7706c37b" "5a84128a" "3884a5d7" "1811f1b5"
538 "5da3230f" "fb17a8ab" "0b32e48d" "31a6685c",
539 .y = "0f60480c" "7a5c0e11" "40340adc" "79d6a2bf"
540 "0cb57ad0" "49d025dc" "38d80c77" "985f0329",
541 .order = "10000000" "00000000" "00000000" "00000000"
542 "14def9de" "a2f79cd6" "5812631a" "5cf5d3ed",
543 .cofactor = "8",
544 .named = ec_wei25519_pkparameters_named_curve,
545 .named_len = sizeof(ec_wei25519_pkparameters_named_curve),
546 .param = ec_wei25519_3_pkparameters_parameters,
547 .param_len = sizeof(ec_wei25519_3_pkparameters_parameters),
548};
549
550#if NEGATIVE_CURVE_COEFFICIENTS_ALLOWED
551/* Same as wei25519_3 except for a. */
552static const struct curve wei25519_3_neg = {
553 .descr = "short Weierstrass 25519.-3 with negative a",
554 .oid = "1.3.101.108",
555 .sn = "Wei25519",
556 .p = "7fffffff" "ffffffff" "ffffffff" "ffffffff"
557 "ffffffff" "ffffffff" "ffffffff" "ffffffed",
533 .a = "-03", 558 .a = "-03",
534#endif
535 .b = "41a3b6bf" "c668778e" "be2954a4" "b1df36d1" 559 .b = "41a3b6bf" "c668778e" "be2954a4" "b1df36d1"
536 "485ecef1" "ea614295" "796e1022" "40891faa", 560 "485ecef1" "ea614295" "796e1022" "40891faa",
537 .x = "7706c37b" "5a84128a" "3884a5d7" "1811f1b5" 561 .x = "7706c37b" "5a84128a" "3884a5d7" "1811f1b5"
@@ -546,6 +570,7 @@ static const struct curve wei25519_3 = {
546 .param = ec_wei25519_3_pkparameters_parameters, 570 .param = ec_wei25519_3_pkparameters_parameters,
547 .param_len = sizeof(ec_wei25519_3_pkparameters_parameters), 571 .param_len = sizeof(ec_wei25519_3_pkparameters_parameters),
548}; 572};
573#endif
549 574
550/* 575/*
551 * From draft-ietf-lwig-curve-representation-23, Appendix L.3 576 * From draft-ietf-lwig-curve-representation-23, Appendix L.3
@@ -888,6 +913,11 @@ ec_group_non_builtin_curves(void)
888 failed |= ec_group_non_builtin_curve(&wei25519_3, EC_GFp_mont_method(), ctx); 913 failed |= ec_group_non_builtin_curve(&wei25519_3, EC_GFp_mont_method(), ctx);
889 failed |= ec_group_non_builtin_curve(&wei25519_3, EC_GFp_simple_method(), ctx); 914 failed |= ec_group_non_builtin_curve(&wei25519_3, EC_GFp_simple_method(), ctx);
890 915
916#if NEGATIVE_CURVE_COEFFICIENTS_ALLOWED
917 failed |= ec_group_non_builtin_curve(&wei25519_3_neg, EC_GFp_mont_method(), ctx);
918 failed |= ec_group_non_builtin_curve(&wei25519_3_neg, EC_GFp_simple_method(), ctx);
919#endif
920
891 failed |= ec_group_non_builtin_curve(&secp256k1_m, EC_GFp_mont_method(), ctx); 921 failed |= ec_group_non_builtin_curve(&secp256k1_m, EC_GFp_mont_method(), ctx);
892 failed |= ec_group_non_builtin_curve(&secp256k1_m, EC_GFp_simple_method(), ctx); 922 failed |= ec_group_non_builtin_curve(&secp256k1_m, EC_GFp_simple_method(), ctx);
893 923
@@ -959,7 +989,7 @@ static const struct ec_private_key {
959 0x19, 0xbb, 0x6e, 0xcf, 0x3c, 0xe2, 989 0x19, 0xbb, 0x6e, 0xcf, 0x3c, 0xe2,
960 }, 990 },
961 }, 991 },
962#if 0 992#if CORRECT_PRIV_KEY_PADDING
963 { 993 {
964 .name = "secp160k1", 994 .name = "secp160k1",
965 .der_len = 83, 995 .der_len = 83,
@@ -1030,7 +1060,7 @@ static const struct ec_private_key {
1030 0x0c, 0x73, 0x6e, 0x73, 0x7c, 0xdc, 1060 0x0c, 0x73, 0x6e, 0x73, 0x7c, 0xdc,
1031 }, 1061 },
1032 }, 1062 },
1033#if 0 1063#if CORRECT_PRIV_KEY_PADDING
1034 { 1064 {
1035 .name = "secp224k1", 1065 .name = "secp224k1",
1036 .der_len = 107, 1066 .der_len = 107,
@@ -1310,7 +1340,7 @@ static const struct ec_private_key {
1310 0xb8, 0xf6, 0x80, 0xfe, 0x7a, 0xb1, 0xa2, 0x74, 1340 0xb8, 0xf6, 0x80, 0xfe, 0x7a, 0xb1, 0xa2, 0x74,
1311 }, 1341 },
1312 }, 1342 },
1313#if 0 1343#if CORRECT_PRIV_KEY_PADDING
1314 { 1344 {
1315 .name = "wap-wsg-idm-ecid-wtls7", 1345 .name = "wap-wsg-idm-ecid-wtls7",
1316 .der_len = 83, 1346 .der_len = 83,