Skip to content

Commit 622befe

Browse files
committed
tests/wolfmath: size sp_gcd dest by b->used, not a hard-coded 2
test_wc_SpIntExptGcdDecisionCoverage sized r with sp_init_size(&r, 2) expecting sp_gcd(2^140, 2^70, &r) == 0, on the assumption that 2^70 occupies 2 digits. That only holds for 64-bit SP_WORD_SIZE; on a 32-bit build (e.g. --enable-sp-math-all with ALT_ECC_SIZE under -m32) 2^70 spans 3 digits, so r->size(2) < b->used(3) trips sp_gcd's dest-size check and it returns MP_VAL. Size r to b.used so the "r->size < b->used" operand stays false (the intended MC/DC pair) for any word size.
1 parent 4fb6cfe commit 622befe

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

tests/api/test_wolfmath.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -946,8 +946,10 @@ int test_wc_SpIntExptGcdDecisionCoverage(void)
946946
ExpectIntEQ(sp_gcd(&a, &b, &r), WC_NO_ERR_TRACE(MP_VAL));
947947
/* Same a > b shape, but r sized to cover b->used exactly: the second
948948
* clause's r->size < b->used half now goes false while a->used <
949-
* b->used stays true, isolating that operand's independence pair. */
950-
ExpectIntEQ(sp_init_size(&r, 2), 0);
949+
* b->used stays true, isolating that operand's independence pair.
950+
* Size r to b->used (not a hard-coded 2) so this holds regardless of
951+
* SP_WORD_SIZE - at 32-bit words 2^70 occupies 3 digits, not 2. */
952+
ExpectIntEQ(sp_init_size(&r, b.used), 0);
951953
ExpectIntEQ(sp_gcd(&a, &b, &r), 0);
952954
ExpectIntEQ(sp_init(&r), 0);
953955
ExpectIntEQ(sp_gcd(&a, &b, &r), 0);

0 commit comments

Comments
 (0)