From: jsing Date: Fri, 23 Dec 2022 02:13:15 +0000 (+0000) Subject: Add regress coverage for shifts of zero bits. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=0c6046f558d8122f7bcc7681fc52b8e74c1880eb;p=openbsd Add regress coverage for shifts of zero bits. --- diff --git a/regress/lib/libcrypto/bn/bn_shift.c b/regress/lib/libcrypto/bn/bn_shift.c index fd5184523bd..743a911cbee 100644 --- a/regress/lib/libcrypto/bn/bn_shift.c +++ b/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: