From 4bec30b6d97c43070ce6facec227cd8cb2a5a470 Mon Sep 17 00:00:00 2001 From: tb Date: Mon, 17 Apr 2023 20:41:02 +0000 Subject: [PATCH] Switch all ec tests to using dynamic linking 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 | 4 ++-- regress/lib/libcrypto/ec/ec_point_conversion.c | 8 +++++--- regress/lib/libcrypto/ec/ectest.c | 10 +++++++--- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/regress/lib/libcrypto/ec/Makefile b/regress/lib/libcrypto/ec/Makefile index 081eeb56bd0..0826b44a25d 100644 --- a/regress/lib/libcrypto/ec/Makefile +++ b/regress/lib/libcrypto/ec/Makefile @@ -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 diff --git a/regress/lib/libcrypto/ec/ec_point_conversion.c b/regress/lib/libcrypto/ec/ec_point_conversion.c index 5a97f67b941..dca35ced590 100644 --- a/regress/lib/libcrypto/ec/ec_point_conversion.c +++ b/regress/lib/libcrypto/ec/ec_point_conversion.c @@ -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 * Copyright (c) 2021 Joel Sing @@ -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"); diff --git a/regress/lib/libcrypto/ec/ectest.c b/regress/lib/libcrypto/ec/ectest.c index 2b9c6a99f38..d2253609cdd 100644 --- a/regress/lib/libcrypto/ec/ectest.c +++ b/regress/lib/libcrypto/ec/ectest.c @@ -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); -- 2.20.1