From 006d7c3076578fcef6ac032817998dd65be08307 Mon Sep 17 00:00:00 2001 From: tb Date: Tue, 11 Oct 2022 13:51:41 +0000 Subject: [PATCH] Handle corner case in which the test case can actually be a square --- regress/lib/libcrypto/bn/general/bn_isqrt.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/regress/lib/libcrypto/bn/general/bn_isqrt.c b/regress/lib/libcrypto/bn/general/bn_isqrt.c index 40b23f8dfd9..b9939dc59c4 100644 --- a/regress/lib/libcrypto/bn/general/bn_isqrt.c +++ b/regress/lib/libcrypto/bn/general/bn_isqrt.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bn_isqrt.c,v 1.6 2022/08/12 16:13:40 tb Exp $ */ +/* $OpenBSD: bn_isqrt.c,v 1.7 2022/10/11 13:51:41 tb Exp $ */ /* * Copyright (c) 2022 Theo Buehler * @@ -148,9 +148,7 @@ validate_tables(void) fill[i]); failed |= 1; } - } - } return failed; @@ -251,7 +249,8 @@ isqrt_test(void) if (!bn_isqrt(isqrt, &is_perfect_square, testcase, ctx)) errx(1, "bn_isqrt testcase"); - if ((cmp = BN_cmp(n, isqrt)) != 0 || is_perfect_square) { + if ((cmp = BN_cmp(n, isqrt)) != 0 || + (is_perfect_square && BN_cmp(n_sqr, testcase) != 0)) { fprintf(stderr, "n = "); BN_print_fp(stderr, n); fprintf(stderr, "\ntestcase = "); -- 2.20.1