Switch all ec tests to using dynamic linking
authortb <tb@openbsd.org>
Mon, 17 Apr 2023 20:41:02 +0000 (20:41 +0000)
committertb <tb@openbsd.org>
Mon, 17 Apr 2023 20:41:02 +0000 (20:41 +0000)
This only requires very minor changes and simplifies testing quite a bit.
Some of the changes can be undone after the next bump.

regress/lib/libcrypto/ec/Makefile
regress/lib/libcrypto/ec/ec_point_conversion.c
regress/lib/libcrypto/ec/ectest.c

index 081eeb5..0826b44 100644 (file)
@@ -1,10 +1,10 @@
-#      $OpenBSD: Makefile,v 1.7 2023/04/17 20:36:08 tb Exp $
+#      $OpenBSD: Makefile,v 1.8 2023/04/17 20:41:02 tb Exp $
 
 PROGS +=               ectest
 PROGS +=               ec_asn1_test
 PROGS +=               ec_point_conversion
 
-LDADD =                        ${CRYPTO_INT}
+LDADD =                        -lcrypto
 DPADD =                        ${LIBCRYPTO}
 WARNINGS =             Yes
 CFLAGS +=              -DLIBRESSL_CRYPTO_INTERNAL -DLIBRESSL_INTERNAL
index 5a97f67..dca35ce 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: ec_point_conversion.c,v 1.9 2023/04/15 21:53:38 tb Exp $ */
+/*     $OpenBSD: ec_point_conversion.c,v 1.10 2023/04/17 20:41:02 tb Exp $ */
 /*
  * Copyright (c) 2021 Theo Buehler <tb@openbsd.org>
  * Copyright (c) 2021 Joel Sing <jsing@openbsd.org>
@@ -177,8 +177,10 @@ test_random_points_on_curve(EC_builtin_curve *curve)
        for (i = 0; i < N_RANDOM_POINTS; i++) {
                EC_POINT *random_point;
 
-               if (!bn_rand_interval(random, BN_value_one(), order))
-                       errx(1, "bn_rand_interval");
+               do {
+                       if (!BN_rand_range(random, order))
+                               errx(1, "BN_rand_range");
+               } while (BN_is_zero(random));
 
                if ((random_point = EC_POINT_new(group)) == NULL)
                        errx(1, "EC_POINT_new");
index 2b9c6a9..d225360 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: ectest.c,v 1.13 2023/04/13 05:25:30 tb Exp $  */
+/*     $OpenBSD: ectest.c,v 1.14 2023/04/17 20:41:02 tb Exp $  */
 /* crypto/ec/ectest.c */
 /*
  * Originally written by Bodo Moeller for the OpenSSL project.
@@ -96,6 +96,9 @@
 #define TIMING_RAND_PT 1
 #define TIMING_SIMUL 2
 
+int EC_POINT_get_Jprojective_coordinates_GFp(const EC_GROUP *group,
+    const EC_POINT *point, BIGNUM *x, BIGNUM *y, BIGNUM *z, BN_CTX *ctx);
+
 /* test multiplication with group order, long and negative scalars */
 static void
 group_order_tests(EC_GROUP *group)
@@ -132,7 +135,8 @@ group_order_tests(EC_GROUP *group)
                ABORT;
        fprintf(stdout, " ok\n");
        fprintf(stdout, "long/negative scalar tests ... ");
-       if (!BN_one(n1))
+       /* XXX - switch back to BN_one() after next bump. */
+       if (!BN_set_word(n1, 1))
                ABORT;
        /* n1 = 1 - order */
        if (!BN_sub(n1, n1, order))
@@ -342,7 +346,7 @@ prime_field_tests(void)
        fprintf(stdout, "\nGenerator as octet string, hybrid form:\n     ");
        for (i = 0; i < len; i++) fprintf(stdout, "%02X", buf[i]);
 
-               if (!EC_POINT_get_Jprojective_coordinates(group, R, x, y, z, ctx))
+               if (!EC_POINT_get_Jprojective_coordinates_GFp(group, R, x, y, z, ctx))
                        ABORT;
        fprintf(stdout, "\nA representation of the inverse of that generator in\nJacobian projective coordinates:\n     X = 0x");
        BN_print_fp(stdout, x);