mirror of
https://github.com/luxfi/lattice.git
synced 2026-09-24 00:25:44 +00:00
fix: cbdEta3 3-byte read for cross-boundary bits
When bitOff >= 3, 6 bits can span 3 bytes. Previously only read 2 bytes, which would silently lose high bits and produce incorrect coefficients.
This commit is contained in:
+3
-1
@@ -157,7 +157,9 @@ func (s *CBDSampler) cbdEta3(coeffs [][]uint64, moduli []uint64, N int, buf []by
|
||||
bitOff := uint(bitPos % 8)
|
||||
|
||||
var bits6 uint64
|
||||
if byteIdx+1 < len(buf) {
|
||||
if byteIdx+2 < len(buf) {
|
||||
bits6 = (uint64(buf[byteIdx]) | uint64(buf[byteIdx+1])<<8 | uint64(buf[byteIdx+2])<<16) >> bitOff
|
||||
} else if byteIdx+1 < len(buf) {
|
||||
bits6 = (uint64(buf[byteIdx]) | uint64(buf[byteIdx+1])<<8) >> bitOff
|
||||
} else {
|
||||
bits6 = uint64(buf[byteIdx]) >> bitOff
|
||||
|
||||
Reference in New Issue
Block a user