sync with OpenBSD -current

This commit is contained in:
purplerain 2025-01-22 18:06:03 +00:00
parent 6f15bbf720
commit c170139b8d
Signed by: purplerain
GPG key ID: F42C07F07E2E35B7
42 changed files with 899 additions and 815 deletions

View file

@ -1,4 +1,4 @@
/* $OpenBSD: bn_test.c,v 1.19 2023/04/25 17:17:21 tb Exp $ */
/* $OpenBSD: bn_test.c,v 1.22 2025/01/22 13:02:14 tb Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@ -224,7 +224,7 @@ main(int argc, char *argv[])
goto err;
(void)BIO_flush(out);
message(out, "BN_div_recp");
message(out, "BN_div_reciprocal");
if (!test_div_recp(out, ctx))
goto err;
(void)BIO_flush(out);
@ -581,9 +581,6 @@ test_div_recp(BIO *bp, BN_CTX *ctx)
if ((e = BN_CTX_get(ctx)) == NULL)
goto err;
if ((recp = BN_RECP_CTX_new()) == NULL)
goto err;
for (i = 0; i < num0 + num1; i++) {
if (i < num1) {
CHECK_GOTO(BN_bntest_rand(a, 400, 0, 0));
@ -592,10 +589,9 @@ test_div_recp(BIO *bp, BN_CTX *ctx)
CHECK_GOTO(BN_add_word(a, i));
} else
CHECK_GOTO(BN_bntest_rand(b, 50 + 3 * (i - num1), 0, 0));
BN_set_negative(a, rand_neg());
BN_set_negative(b, rand_neg());
CHECK_GOTO(BN_RECP_CTX_set(recp, b, ctx));
CHECK_GOTO(BN_div_recp(d, c, a, recp, ctx));
BN_RECP_CTX_free(recp);
CHECK_GOTO(recp = BN_RECP_CTX_create(b));
CHECK_GOTO(BN_div_reciprocal(d, c, a, recp, ctx));
if (bp != NULL) {
if (!results) {
CHECK_GOTO(BN_print(bp, a));

View file

@ -1,4 +1,4 @@
# $OpenBSD: Makefile,v 1.9 2024/11/04 09:51:51 tb Exp $
# $OpenBSD: Makefile,v 1.10 2025/01/21 16:47:52 tb Exp $
.ifdef EOPENSSL33
LDADD += -Wl,-rpath,/usr/local/lib/eopenssl33 -L/usr/local/lib/eopenssl33
@ -6,14 +6,14 @@ CFLAGS += -I/usr/local/include/eopenssl33/
CFLAGS += -DOPENSSL_SUPPRESS_DEPRECATED
.endif
PROGS += ectest
PROGS += ec_asn1_test
PROGS += ec_point_conversion
PROGS += ectest
PROGS += ec_asn1_test
PROGS += ec_point_conversion
LDADD = -lcrypto
DPADD = ${LIBCRYPTO}
WARNINGS = Yes
CFLAGS += -DLIBRESSL_CRYPTO_INTERNAL -DLIBRESSL_INTERNAL
CFLAGS += -Wall -Wundef -Werror
LDADD = -lcrypto
DPADD = ${LIBCRYPTO}
WARNINGS = Yes
CFLAGS += -DLIBRESSL_CRYPTO_INTERNAL -DLIBRESSL_INTERNAL
CFLAGS += -Wall -Wundef -Werror
.include <bsd.regress.mk>

View file

@ -1,4 +1,4 @@
/* $OpenBSD: ectest.c,v 1.26 2025/01/06 10:43:26 tb Exp $ */
/* $OpenBSD: ectest.c,v 1.34 2025/01/22 15:38:25 tb Exp $ */
/*
* Originally written by Bodo Moeller for the OpenSSL project.
*/
@ -88,27 +88,24 @@
exit(1); \
} while (0)
#define TIMING_BASE_PT 0
#define TIMING_RAND_PT 1
#define TIMING_SIMUL 2
/* test multiplication with group order, long and negative scalars */
static void
group_order_tests(EC_GROUP *group)
group_order_tests(EC_GROUP *group, BN_CTX *ctx)
{
BIGNUM *n1, *n2, *order;
EC_POINT *P = EC_POINT_new(group);
EC_POINT *Q = EC_POINT_new(group);
BN_CTX *ctx;
if ((ctx = BN_CTX_new()) == NULL)
if (P == NULL || Q == NULL)
ABORT;
if ((n1 = BN_new()) == NULL)
BN_CTX_start(ctx);
if ((n1 = BN_CTX_get(ctx)) == NULL)
ABORT;
if ((n2 = BN_new()) == NULL)
if ((n2 = BN_CTX_get(ctx)) == NULL)
ABORT;
if ((order = BN_new()) == NULL)
if ((order = BN_CTX_get(ctx)) == NULL)
ABORT;
fprintf(stdout, "verify group order ...");
fflush(stdout);
@ -128,8 +125,7 @@ group_order_tests(EC_GROUP *group)
ABORT;
fprintf(stdout, " ok\n");
fprintf(stdout, "long/negative scalar tests ... ");
/* XXX - switch back to BN_one() after next bump. */
if (!BN_set_word(n1, 1))
if (!BN_one(n1))
ABORT;
/* n1 = 1 - order */
if (!BN_sub(n1, n1, order))
@ -155,10 +151,7 @@ group_order_tests(EC_GROUP *group)
fprintf(stdout, "ok\n");
EC_POINT_free(P);
EC_POINT_free(Q);
BN_free(n1);
BN_free(n2);
BN_free(order);
BN_CTX_free(ctx);
BN_CTX_end(ctx);
}
static void
@ -191,20 +184,13 @@ prime_field_tests(void)
if (!BN_hex2bn(&b, "1"))
ABORT;
group = EC_GROUP_new(EC_GFp_mont_method()); /* applications should use EC_GROUP_new_curve_GFp
* so that the library gets to choose the EC_METHOD */
if (!group)
ABORT;
if (!EC_GROUP_set_curve(group, p, a, b, ctx))
if ((group = EC_GROUP_new_curve_GFp(p, a, b, ctx)) == NULL)
ABORT;
{
EC_GROUP *tmp;
tmp = EC_GROUP_new(EC_GROUP_method_of(group));
if (!tmp)
ABORT;
if (!EC_GROUP_copy(tmp, group))
if ((tmp = EC_GROUP_dup(group)) == NULL)
ABORT;
EC_GROUP_free(group);
group = tmp;
@ -263,18 +249,16 @@ prime_field_tests(void)
}
fprintf(stdout, "A cyclic subgroup:\n");
k = 100;
k = 0;
do {
if (k-- == 0)
ABORT;
fprintf(stderr, " %d - ", k);
if (EC_POINT_is_at_infinity(group, P))
fprintf(stdout, " point at infinity\n");
fprintf(stdout, "point at infinity\n");
else {
if (!EC_POINT_get_affine_coordinates(group, P, x, y, ctx))
ABORT;
fprintf(stdout, " x = 0x");
fprintf(stdout, "x = 0x");
BN_print_fp(stdout, x);
fprintf(stdout, ", y = 0x");
BN_print_fp(stdout, y);
@ -285,8 +269,15 @@ prime_field_tests(void)
ABORT;
if (!EC_POINT_add(group, P, P, Q, ctx))
ABORT;
if (k++ > 99)
ABORT;
} while (!EC_POINT_is_at_infinity(group, P));
if (k != 7) {
fprintf(stderr, "cycled in %d iterations, want 7\n", k);
ABORT;
}
if (!EC_POINT_add(group, P, Q, R, ctx))
ABORT;
if (!EC_POINT_is_at_infinity(group, P))
@ -300,9 +291,10 @@ prime_field_tests(void)
if (0 != EC_POINT_cmp(group, P, Q, ctx))
ABORT;
fprintf(stdout, "Generator as octet string, compressed form:\n ");
for (i = 0; i < len; i++) fprintf(stdout, "%02X", buf[i]);
for (i = 0; i < len; i++)
fprintf(stdout, "%02X", buf[i]);
len = EC_POINT_point2oct(group, Q, POINT_CONVERSION_UNCOMPRESSED, buf, sizeof buf, ctx);
len = EC_POINT_point2oct(group, Q, POINT_CONVERSION_UNCOMPRESSED, buf, sizeof buf, ctx);
if (len == 0)
ABORT;
if (!EC_POINT_oct2point(group, P, buf, len, ctx))
@ -310,9 +302,10 @@ prime_field_tests(void)
if (0 != EC_POINT_cmp(group, P, Q, ctx))
ABORT;
fprintf(stdout, "\nGenerator as octet string, uncompressed form:\n ");
for (i = 0; i < len; i++) fprintf(stdout, "%02X", buf[i]);
for (i = 0; i < len; i++)
fprintf(stdout, "%02X", buf[i]);
len = EC_POINT_point2oct(group, Q, POINT_CONVERSION_HYBRID, buf, sizeof buf, ctx);
len = EC_POINT_point2oct(group, Q, POINT_CONVERSION_HYBRID, buf, sizeof buf, ctx);
if (len == 0)
ABORT;
if (!EC_POINT_oct2point(group, P, buf, len, ctx))
@ -322,8 +315,8 @@ 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_affine_coordinates(group, R, x, y, ctx))
ABORT;
if (!EC_POINT_get_affine_coordinates(group, R, x, y, ctx))
ABORT;
fprintf(stdout, "\nThe inverse of that generator:\n X = 0x");
BN_print_fp(stdout, x);
fprintf(stdout, ", Y = 0x");
@ -381,13 +374,10 @@ prime_field_tests(void)
ABORT;
fprintf(stdout, " ok\n");
group_order_tests(group);
group_order_tests(group, ctx);
if (!(P_160 = EC_GROUP_new(EC_GROUP_method_of(group))))
if ((P_160 = EC_GROUP_dup(group)) == NULL)
ABORT;
if (!EC_GROUP_copy(P_160, group))
ABORT;
/* Curve P-192 (FIPS PUB 186-2, App. 6) */
@ -431,13 +421,10 @@ prime_field_tests(void)
ABORT;
fprintf(stdout, " ok\n");
group_order_tests(group);
group_order_tests(group, ctx);
if (!(P_192 = EC_GROUP_new(EC_GROUP_method_of(group))))
if ((P_192 = EC_GROUP_dup(group)) == NULL)
ABORT;
if (!EC_GROUP_copy(P_192, group))
ABORT;
/* Curve P-224 (FIPS PUB 186-2, App. 6) */
@ -481,13 +468,10 @@ prime_field_tests(void)
ABORT;
fprintf(stdout, " ok\n");
group_order_tests(group);
group_order_tests(group, ctx);
if (!(P_224 = EC_GROUP_new(EC_GROUP_method_of(group))))
if ((P_224 = EC_GROUP_dup(group)) == NULL)
ABORT;
if (!EC_GROUP_copy(P_224, group))
ABORT;
/* Curve P-256 (FIPS PUB 186-2, App. 6) */
@ -531,13 +515,10 @@ prime_field_tests(void)
ABORT;
fprintf(stdout, " ok\n");
group_order_tests(group);
group_order_tests(group, ctx);
if (!(P_256 = EC_GROUP_new(EC_GROUP_method_of(group))))
if ((P_256 = EC_GROUP_dup(group)) == NULL)
ABORT;
if (!EC_GROUP_copy(P_256, group))
ABORT;
/* Curve P-384 (FIPS PUB 186-2, App. 6) */
@ -581,13 +562,10 @@ prime_field_tests(void)
ABORT;
fprintf(stdout, " ok\n");
group_order_tests(group);
group_order_tests(group, ctx);
if (!(P_384 = EC_GROUP_new(EC_GROUP_method_of(group))))
if ((P_384 = EC_GROUP_dup(group)) == NULL)
ABORT;
if (!EC_GROUP_copy(P_384, group))
ABORT;
/* Curve P-521 (FIPS PUB 186-2, App. 6) */
@ -637,13 +615,10 @@ prime_field_tests(void)
ABORT;
fprintf(stdout, " ok\n");
group_order_tests(group);
group_order_tests(group, ctx);
if (!(P_521 = EC_GROUP_new(EC_GROUP_method_of(group))))
if ((P_521 = EC_GROUP_dup(group)) == NULL)
ABORT;
if (!EC_GROUP_copy(P_521, group))
ABORT;
/* more tests using the last curve */
fprintf(stdout, "infinity tests ...");
@ -683,19 +658,12 @@ prime_field_tests(void)
BN_free(y);
BN_free(z);
if (P_160)
EC_GROUP_free(P_160);
if (P_192)
EC_GROUP_free(P_192);
if (P_224)
EC_GROUP_free(P_224);
if (P_256)
EC_GROUP_free(P_256);
if (P_384)
EC_GROUP_free(P_384);
if (P_521)
EC_GROUP_free(P_521);
EC_GROUP_free(P_160);
EC_GROUP_free(P_192);
EC_GROUP_free(P_224);
EC_GROUP_free(P_256);
EC_GROUP_free(P_384);
EC_GROUP_free(P_521);
}
int

View file

@ -1,4 +1,4 @@
# $OpenBSD: Makefile,v 1.2 2016/09/27 06:52:50 kettenis Exp $
# $OpenBSD: Makefile,v 1.3 2025/01/21 19:14:27 anton Exp $
.include <bsd.obj.mk>
@ -29,6 +29,6 @@ LDADD+=-laa
LDFLAGS=-L$(AA_OBJDIR) -L$(AB_OBJDIR)
LDFLAGS+= -Wl,-rpath,$(AA_OBJDIR) -Wl,-rpath,$(AB_OBJDIR)
NOMAN=
CC=c++
CC=${CXX}
.include <bsd.regress.mk>

View file

@ -1,4 +1,4 @@
# $OpenBSD: Makefile,v 1.2 2016/09/27 06:52:50 kettenis Exp $
# $OpenBSD: Makefile,v 1.3 2025/01/21 19:14:28 anton Exp $
.include <bsd.obj.mk>
@ -29,6 +29,6 @@ LDADD+=-lab
LDFLAGS=-L$(AA_OBJDIR) -L$(AB_OBJDIR)
LDFLAGS+= -Wl,-rpath,$(AA_OBJDIR) -Wl,-rpath,$(AB_OBJDIR)
NOMAN=
CC=c++
CC=${CXX}
.include <bsd.regress.mk>

View file

@ -1,4 +1,4 @@
# $OpenBSD: Makefile,v 1.4 2015/06/15 01:10:19 deraadt Exp $
# $OpenBSD: Makefile,v 1.5 2025/01/21 19:14:28 anton Exp $
.include <bsd.obj.mk>
@ -29,7 +29,7 @@ LDADD=
#LDFLAGS=-L$(AA_OBJDIR) -L$(AB_OBJDIR)
LDFLAGS+= -Wl,-rpath,$(AA_OBJDIR) -Wl,-rpath,$(AB_OBJDIR)
NOMAN=
CC=c++
CC=${CXX}
LD_LIBRARY_PATH=$(AA_OBJDIR):$(AB_OBJDIR)
.include <bsd.regress.mk>

View file

@ -1,4 +1,4 @@
# $OpenBSD: Makefile,v 1.2 2015/06/15 01:10:19 deraadt Exp $
# $OpenBSD: Makefile,v 1.3 2025/01/21 19:14:28 anton Exp $
.include <bsd.obj.mk>
@ -29,6 +29,6 @@ LDADD+=-lab
LDFLAGS=-L$(AA_OBJDIR) -L$(AB_OBJDIR)
LDFLAGS+= -Wl,-rpath,$(AA_OBJDIR) -Wl,-rpath,$(AB_OBJDIR)
NOMAN=
CC=c++
CC=${CXX}
.include <bsd.regress.mk>

View file

@ -1,4 +1,4 @@
# $OpenBSD: Makefile,v 1.4 2017/03/18 16:45:32 kettenis Exp $
# $OpenBSD: Makefile,v 1.5 2025/01/21 19:14:28 anton Exp $
.include <bsd.obj.mk>
@ -29,6 +29,6 @@ LDFLAGS=-L$(AA_OBJDIR) -L$(AC_OBJDIR)
LDFLAGS+= -Wl,-disable-new-dtags
LDFLAGS+= -Wl,-rpath,$(AA_OBJDIR) -Wl,-rpath,$(AC_OBJDIR)
NOMAN=
CC=c++
CC=${CXX}
.include <bsd.regress.mk>

View file

@ -1,4 +1,4 @@
# $OpenBSD: Makefile,v 1.3 2015/06/15 01:10:19 deraadt Exp $
# $OpenBSD: Makefile,v 1.4 2025/01/21 19:14:28 anton Exp $
.include <bsd.obj.mk>
@ -30,6 +30,6 @@ LDFLAGS=-L$(AA_OBJDIR) -L$(AC_OBJDIR)
# This intentionally leaves out AA_OBJDIR from -rpath
LDFLAGS+= -Wl,-rpath,$(AC_OBJDIR)
NOMAN=
CC=c++
CC=${CXX}
.include <bsd.regress.mk>

View file

@ -1,4 +1,4 @@
# $OpenBSD: Makefile,v 1.1 2016/03/20 05:13:22 guenther Exp $
# $OpenBSD: Makefile,v 1.2 2025/01/21 19:14:28 anton Exp $
.include <bsd.obj.mk>
@ -18,6 +18,6 @@ LDADD+=-laa
LDFLAGS=-L$(AA_OBJDIR)
LDFLAGS+= -Wl,-rpath,$(AA_OBJDIR)
NOMAN=
CC=c++
CC=${CXX}
.include <bsd.regress.mk>

View file

@ -1,4 +1,4 @@
# $OpenBSD: Makefile,v 1.2 2017/03/18 16:58:22 kettenis Exp $
# $OpenBSD: Makefile,v 1.3 2025/01/21 19:14:28 anton Exp $
.include <bsd.obj.mk>
@ -50,7 +50,7 @@ LDFLAGS+= -Wl,-rpath,$(AC_OBJDIR)
LDFLAGS+= -Wl,-rpath,$(AD_OBJDIR)
LDFLAGS+= -Wl,-rpath,$(AE_OBJDIR)
NOMAN=
CC=c++
CC=${CXX}
run-regress-${PROG}: ${PROG}
[ "`./${PROG}`" = "DBECAPpacebd" ]

View file

@ -1,4 +1,4 @@
# $OpenBSD: Makefile,v 1.2 2017/03/18 16:58:22 kettenis Exp $
# $OpenBSD: Makefile,v 1.3 2025/01/21 19:14:28 anton Exp $
.include <bsd.obj.mk>
@ -50,7 +50,7 @@ LDFLAGS+= -Wl,-rpath,$(AC_OBJDIR)
LDFLAGS+= -Wl,-rpath,$(AD_OBJDIR)
LDFLAGS+= -Wl,-rpath,$(AE_OBJDIR)
NOMAN=
CC=c++
CC=${CXX}
run-regress-${PROG}: ${PROG}
[ "`./${PROG}`" = "DBECAacebd" ]