From ccbe55b7cd9e373cc5dbdb6a1ebded87c9bde054 Mon Sep 17 00:00:00 2001 From: tb Date: Thu, 1 Dec 2022 22:31:59 +0000 Subject: [PATCH] Check that the bn_isqrt -C output isn't changed bn_isqrt -C generates code included in lib/libcrypto/lib/bn_isqrt.c. The regress tests already ensure that the content of the tables don't change. Ensure further that the code generation doesn't get out of sync. --- regress/lib/libcrypto/bn/Makefile | 14 ++++++++- regress/lib/libcrypto/bn/bn_isqrt_tables.txt | 30 ++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 regress/lib/libcrypto/bn/bn_isqrt_tables.txt diff --git a/regress/lib/libcrypto/bn/Makefile b/regress/lib/libcrypto/bn/Makefile index b5d146c71b4..7dc5ef75c8e 100644 --- a/regress/lib/libcrypto/bn/Makefile +++ b/regress/lib/libcrypto/bn/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.9 2022/12/01 21:21:51 tb Exp $ +# $OpenBSD: Makefile,v 1.10 2022/12/01 22:31:59 tb Exp $ PROGS += bn_add_sub PROGS += bn_cmp @@ -32,9 +32,21 @@ run-$p: $p ./$p .endfor +# Verify that the bn_isqrt -C output isn't changed by accident. isqrt-print-tables: bn_isqrt @./bn_isqrt -C +CLEANFILES += bn_isqrt_gen_tables.txt.tmp bn_isqrt_gen_tables.txt +bn_isqrt_gen_tables.txt: bn_isqrt + ${.MAKE} -C ${.CURDIR} isqrt-print-tables > $@.tmp + mv -f $@.tmp $@ + +REGRESS_TARGETS += run-bn_isqrt_check_tables +.PHONY: run-bn_isqrt_check_tables +run-bn_isqrt_check_tables: bn_isqrt_gen_tables.txt + diff -pu ${.CURDIR}/bn_isqrt_tables.txt bn_isqrt_gen_tables.txt + + # Keep bn_test last since it is special PROGS += bn_test STATIC_LINK += bn_test diff --git a/regress/lib/libcrypto/bn/bn_isqrt_tables.txt b/regress/lib/libcrypto/bn/bn_isqrt_tables.txt new file mode 100644 index 00000000000..bc045a220e0 --- /dev/null +++ b/regress/lib/libcrypto/bn/bn_isqrt_tables.txt @@ -0,0 +1,30 @@ +const uint8_t is_square_mod_11[] = { + 1, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, +}; +CTASSERT(sizeof(is_square_mod_11) == 11); + +const uint8_t is_square_mod_63[] = { + 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, + 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, + 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, +}; +CTASSERT(sizeof(is_square_mod_63) == 63); + +const uint8_t is_square_mod_64[] = { + 1, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, + 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, + 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, + 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, +}; +CTASSERT(sizeof(is_square_mod_64) == 64); + +const uint8_t is_square_mod_65[] = { + 1, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, + 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, + 0, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, + 1, +}; +CTASSERT(sizeof(is_square_mod_65) == 65); + -- 2.20.1