Add regress coverage for shifts of zero bits.
authorjsing <jsing@openbsd.org>
Fri, 23 Dec 2022 02:13:15 +0000 (02:13 +0000)
committerjsing <jsing@openbsd.org>
Fri, 23 Dec 2022 02:13:15 +0000 (02:13 +0000)
regress/lib/libcrypto/bn/bn_shift.c

index fd51845..743a911 100644 (file)
@@ -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 <jsing@openbsd.org>
  *
@@ -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: