From 9e90e215abb213cc74a4d12c0e9374478e9b82c7 Mon Sep 17 00:00:00 2001 From: JC-000 <3798556+JC-000@users.noreply.github.com> Date: Wed, 20 May 2026 15:34:47 -0500 Subject: [PATCH] fix(crypto/shared): mul_tables.s stub size .res 256 -> .res 512 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Each quarter-square multiply table is 512 bytes (n in 0..510 -> 511 entries, padded to 512), not 256. Every in-the-wild implementation across sibling libs uses 512 B per table — including this repo's own src/data.s:136 — but the Phase C.0 stub at .res 256 would silently truncate at n >= 256 the moment any sibling redirected its init here. Fixes the stub before that redirect lands. No segment changes, no API changes, no runtime change in Phase C.0 (CANONICAL_SQTAB is not defined; the labels here stay dormant). Build verified with default profile (BACKEND=ip65). Refs c64-lib-contract issue #5 (size bug confirmed in audit there) and c64-ChaCha20-Poly1305 issue #34 (the originating sibling-ingestion thread). --- src/crypto/shared/mul_tables.s | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/crypto/shared/mul_tables.s b/src/crypto/shared/mul_tables.s index 71a444f..803db77 100644 --- a/src/crypto/shared/mul_tables.s +++ b/src/crypto/shared/mul_tables.s @@ -15,9 +15,18 @@ ; Public API: ; mul_tables_init - build the 256x256 quarter-square tables ; (currently: stub; returns immediately). -; sqtab_lo, sqtab_hi - 256-byte tables, page-aligned, in TABLES_BSS +; sqtab_lo, sqtab_hi - 512-byte tables each (1 KB total), page-aligned, +; in TABLES_BSS. Layout `sqtab_hi = sqtab_lo + $0200`; +; semantics `(sqtab_hi[n] << 8) | sqtab_lo[n] = +; floor(n^2 / 4)` for n in 0..510. ; (currently: defined by src/data.s; re-homed here -; under CANONICAL_SQTAB in a later phase). +; under CANONICAL_SQTAB in a later phase.) +; +; Size note: each table is 512 bytes, not 256. The earlier stub used +; `.res 256` which would silently truncate at n >= 256 once any sibling +; lib redirected its init here — every in-the-wild implementation uses +; 512 B per table (see `src/data.s:136` here, and the audit in +; `c64-lib-contract` issue #5). Fixed before any redirect lands. ; ============================================================================= .export mul_tables_init @@ -41,6 +50,6 @@ mul_tables_init: .export sqtab_hi .segment "TABLES_BSS" -sqtab_lo: .res 256 -sqtab_hi: .res 256 +sqtab_lo: .res 512 +sqtab_hi: .res 512 .endif