From e1d3281c2d23bffbb56c3eaa1a17c82d4fa20cd6 Mon Sep 17 00:00:00 2001 From: Henry de Valence Date: Sun, 12 Mar 2017 23:18:48 -0700 Subject: [PATCH] Add debug asserts for multiplication preconditions. --- src/field.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/field.rs b/src/field.rs index d74f270..7f922cf 100644 --- a/src/field.rs +++ b/src/field.rs @@ -884,6 +884,11 @@ impl FieldElement { // The carry (c[i] >> 51) fits into a u64 iff 2b+6.27 < 64+51 iff b <= 54. // After the first carry pass, all c[i] fit into u64. + debug_assert!(a[0] < (1 << 54)); debug_assert!(b[0] < (1 << 54)); + debug_assert!(a[1] < (1 << 54)); debug_assert!(b[1] < (1 << 54)); + debug_assert!(a[2] < (1 << 54)); debug_assert!(b[2] < (1 << 54)); + debug_assert!(a[3] < (1 << 54)); debug_assert!(b[3] < (1 << 54)); + debug_assert!(a[4] < (1 << 54)); debug_assert!(b[4] < (1 << 54)); // The 128-bit output limbs are stored in two 64-bit registers (low/high part). // By rebinding the names after carrying, we free the upper registers for reuse. @@ -969,6 +974,11 @@ impl FieldElement { // // The carry (c[i] >> 51) fits into a u64 iff 2b+6.27 < 64+51 iff b <= 54. // After the first carry pass, all c[i] fit into u64. + debug_assert!(a[0] < (1 << 54)); + debug_assert!(a[1] < (1 << 54)); + debug_assert!(a[2] < (1 << 54)); + debug_assert!(a[3] < (1 << 54)); + debug_assert!(a[4] < (1 << 54)); // The 128-bit output limbs are stored in two 64-bit registers (low/high part). // By rebinding the names after carrying, we free the upper registers for reuse.