Add BN_cmp()/BN_ucmp() tests with zero padded inputs.
authorjsing <jsing@openbsd.org>
Wed, 21 Jun 2023 07:16:08 +0000 (07:16 +0000)
committerjsing <jsing@openbsd.org>
Wed, 21 Jun 2023 07:16:08 +0000 (07:16 +0000)
Currently BN_hex2bn() removes the leading zeros, however this will not be
the case in the future.

regress/lib/libcrypto/bn/bn_cmp.c

index 2f5c7c0..047fac3 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: bn_cmp.c,v 1.1 2022/11/30 02:51:05 jsing Exp $ */
+/*     $OpenBSD: bn_cmp.c,v 1.2 2023/06/21 07:16:08 jsing Exp $ */
 /*
  * Copyright (c) 2022 Joel Sing <jsing@openbsd.org>
  *
@@ -75,6 +75,30 @@ struct bn_cmp_test bn_cmp_tests[] = {
                .cmp = -1,
                .ucmp = 1,
        },
+       {
+               .a = "1ffffffffffffffff",
+               .b = "00000000000000001ffffffffffffffff",
+               .cmp = 0,
+               .ucmp = 0,
+       },
+       {
+               .a = "-1ffffffffffffffff",
+               .b = "-00000000000000001ffffffffffffffff",
+               .cmp = 0,
+               .ucmp = 0,
+       },
+       {
+               .a = "1ffffffffffffffff",
+               .b = "-00000000000000001ffffffffffffffff",
+               .cmp = 1,
+               .ucmp = 0,
+       },
+       {
+               .a = "-1ffffffffffffffff",
+               .b = "00000000000000001ffffffffffffffff",
+               .cmp = -1,
+               .ucmp = 0,
+       },
 };
 
 #define N_BN_CMP_TESTS \