Commit e289a95
committed
SP int: fixes from review by Claude
1. sp_cond_swap_ct_ex (line ~5524) — XOR typo: b->sign ^= b->sign always
zeroed the sign. Fixed to b->sign ^= t->sign to correctly swap signs.
2. sp_mod_d (line ~7271) — Negative modulo correction was applied even
when the remainder was 0. Added (*r != 0) guard to avoid producing d
instead of 0.
3. sp_lshb (line ~8444) — Left-shift size check was off. Refactored to
correctly distinguish between pure-digit shifts and bit-within-digit
shifts when checking if the result fits, using separate overflow checks
for each case.
4. sp_div (line ~9003) — Quotient size check could underflow (a->used
- d->used) when a->used <= d->used. Added a->used > d->used guard before
the subtraction.
5. _sp_mulmod_tmp (line ~12160) — Zero inputs caused an allocation of
size 0, which is problematic. Added an early path: if either operand is
zero, set result to zero and skip the allocation/multiply entirely.
6. sp_mod_2d — copy path (line ~14762) — XMEMCPY copied digits *
SP_WORD_SIZEOF bytes but a may have fewer than digits used digits. Fixed
to copy min(a->used, digits) digits to avoid reading uninitialized
memory.
7. sp_mod_2d — negation loop (line ~14782) — Negation loop iterated
over r->used, which could exceed digits. Fixed to loop over min(r->used,
digits).
8. _sp_sqrmod (line ~17314) — Same zero-input issue as _sp_mulmod_tmp.
Added early zero path to skip the allocation/squaring when input is
zero.
9. sp_to_unsigned_bin_len_ct (line ~18312) — Constant-time mask update
had undefined behavior when a->used == 0 (i < a->used - 1 would wrap).
Rewritten as (i + 1) < a->used to be safe.
10. sp_lcm (line ~19838) — Typo in sign check: b->sign >= MP_NEG
(comparing against a value that is 1, so >= 1 would also match MP_ZPOS)
changed to b->sign == MP_NEG.1 parent 20f640a commit e289a95
1 file changed
Lines changed: 56 additions & 37 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5521 | 5521 | | |
5522 | 5522 | | |
5523 | 5523 | | |
5524 | | - | |
| 5524 | + | |
5525 | 5525 | | |
5526 | 5526 | | |
5527 | 5527 | | |
| |||
7268 | 7268 | | |
7269 | 7269 | | |
7270 | 7270 | | |
7271 | | - | |
| 7271 | + | |
7272 | 7272 | | |
7273 | 7273 | | |
7274 | 7274 | | |
| |||
8441 | 8441 | | |
8442 | 8442 | | |
8443 | 8443 | | |
| 8444 | + | |
| 8445 | + | |
8444 | 8446 | | |
8445 | 8447 | | |
8446 | | - | |
| 8448 | + | |
| 8449 | + | |
| 8450 | + | |
| 8451 | + | |
8447 | 8452 | | |
8448 | 8453 | | |
8449 | 8454 | | |
8450 | | - | |
8451 | | - | |
8452 | 8455 | | |
8453 | 8456 | | |
8454 | 8457 | | |
| |||
8997 | 9000 | | |
8998 | 9001 | | |
8999 | 9002 | | |
9000 | | - | |
| 9003 | + | |
| 9004 | + | |
9001 | 9005 | | |
9002 | 9006 | | |
9003 | 9007 | | |
| |||
12153 | 12157 | | |
12154 | 12158 | | |
12155 | 12159 | | |
12156 | | - | |
12157 | | - | |
12158 | 12160 | | |
12159 | | - | |
12160 | | - | |
12161 | | - | |
| 12161 | + | |
| 12162 | + | |
12162 | 12163 | | |
| 12164 | + | |
| 12165 | + | |
| 12166 | + | |
12163 | 12167 | | |
12164 | | - | |
12165 | | - | |
12166 | | - | |
12167 | | - | |
12168 | | - | |
12169 | | - | |
12170 | | - | |
| 12168 | + | |
| 12169 | + | |
| 12170 | + | |
| 12171 | + | |
12171 | 12172 | | |
12172 | | - | |
12173 | | - | |
| 12173 | + | |
| 12174 | + | |
| 12175 | + | |
| 12176 | + | |
| 12177 | + | |
| 12178 | + | |
| 12179 | + | |
| 12180 | + | |
| 12181 | + | |
| 12182 | + | |
| 12183 | + | |
12174 | 12184 | | |
12175 | 12185 | | |
12176 | 12186 | | |
| |||
14749 | 14759 | | |
14750 | 14760 | | |
14751 | 14761 | | |
14752 | | - | |
| 14762 | + | |
| 14763 | + | |
14753 | 14764 | | |
14754 | 14765 | | |
14755 | 14766 | | |
| |||
14768 | 14779 | | |
14769 | 14780 | | |
14770 | 14781 | | |
| 14782 | + | |
14771 | 14783 | | |
14772 | 14784 | | |
14773 | | - | |
| 14785 | + | |
14774 | 14786 | | |
14775 | 14787 | | |
14776 | 14788 | | |
| |||
17299 | 17311 | | |
17300 | 17312 | | |
17301 | 17313 | | |
17302 | | - | |
17303 | | - | |
17304 | 17314 | | |
17305 | | - | |
17306 | | - | |
17307 | | - | |
| 17315 | + | |
| 17316 | + | |
17308 | 17317 | | |
| 17318 | + | |
| 17319 | + | |
| 17320 | + | |
17309 | 17321 | | |
17310 | | - | |
17311 | | - | |
17312 | | - | |
17313 | | - | |
17314 | | - | |
17315 | | - | |
| 17322 | + | |
| 17323 | + | |
| 17324 | + | |
| 17325 | + | |
| 17326 | + | |
| 17327 | + | |
| 17328 | + | |
| 17329 | + | |
| 17330 | + | |
| 17331 | + | |
| 17332 | + | |
| 17333 | + | |
| 17334 | + | |
| 17335 | + | |
| 17336 | + | |
17316 | 17337 | | |
17317 | 17338 | | |
17318 | | - | |
17319 | | - | |
17320 | 17339 | | |
17321 | 17340 | | |
17322 | 17341 | | |
| |||
18290 | 18309 | | |
18291 | 18310 | | |
18292 | 18311 | | |
18293 | | - | |
| 18312 | + | |
18294 | 18313 | | |
18295 | 18314 | | |
18296 | 18315 | | |
| |||
19816 | 19835 | | |
19817 | 19836 | | |
19818 | 19837 | | |
19819 | | - | |
| 19838 | + | |
19820 | 19839 | | |
19821 | 19840 | | |
19822 | 19841 | | |
| |||
0 commit comments