From cbe70dd07d4650c041b37b035949887a36a7dd54 Mon Sep 17 00:00:00 2001 From: jsing <> Date: Fri, 23 Dec 2022 02:13:15 +0000 Subject: Add regress coverage for shifts of zero bits. --- src/regress/lib/libcrypto/bn/bn_shift.c | 39 ++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/regress/lib/libcrypto/bn/bn_shift.c b/src/regress/lib/libcrypto/bn/bn_shift.c index fd5184523b..743a911cbe 100644 --- a/src/regress/lib/libcrypto/bn/bn_shift.c +++ b/src/regress/lib/libcrypto/bn/bn_shift.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bn_shift.c,v 1.4 2022/12/23 02:12:11 jsing Exp $ */ +/* $OpenBSD: bn_shift.c,v 1.5 2022/12/23 02:13:15 jsing Exp $ */ /* * Copyright (c) 2022 Joel Sing * @@ -233,6 +233,43 @@ test_bn_shift(void) if (!check_shift_result(bn1)) goto failure; + /* + * Shift of zero (equivalent to a copy). + */ + BN_zero(bn2); + if (!BN_lshift(bn2, bn1, 0)) { + fprintf(stderr, "FAIL: failed to BN_lshift()\n"); + goto failure; + } + + if (!check_shift_result(bn2)) + goto failure; + + if (!BN_lshift(bn2, bn2, 0)) { + fprintf(stderr, "FAIL: failed to BN_lshift()\n"); + goto failure; + } + + if (!check_shift_result(bn2)) + goto failure; + + BN_zero(bn2); + if (!BN_rshift(bn2, bn1, 0)) { + fprintf(stderr, "FAIL: failed to BN_rshift()\n"); + goto failure; + } + + if (!check_shift_result(bn2)) + goto failure; + + if (!BN_rshift(bn2, bn2, 0)) { + fprintf(stderr, "FAIL: failed to BN_rshift()\n"); + goto failure; + } + + if (!check_shift_result(bn2)) + goto failure; + failed = 0; failure: -- cgit v1.2.3-55-g6feb