Skip to content
This repository has been archived by the owner on Jan 16, 2024. It is now read-only.

Commit

Permalink
bugfix:KyberSlash2 case d=3
Browse files Browse the repository at this point in the history
  • Loading branch information
tgkudelski authored Jan 16, 2024
1 parent a7cf5ef commit 8380db8
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions crystals-kyber/poly.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,17 @@ func (p *Poly) compress(d int) []byte {

case 3:
var t [8]uint16
var d0 uint32 /* accumulation value for fixing KyberSlash2 */
id := 0
for i := 0; i < n/8; i++ {
for j := 0; j < 8; j++ { //TODO: fix KyberSlash2 here
t[j] = uint16(((uint32(p[8*i+j])<<3)+uint32(q)/2)/
uint32(q)) & ((1 << 3) - 1)
for j := 0; j < 8; j++ {
/* t[j] = uint16(((uint32(p[8*i+j])<<3)+uint32(q)/2)/
uint32(q)) & ((1 << 3) - 1) */
d0 = uint32(p[8*i+j]) << 3
d0 += 1664
d0 *= 161271
d0 >>= 29
t[j] = uint16(d0 & 0x7)
}
c[id] = byte(t[0]) | byte(t[1]<<3) | byte(t[2]<<6)
c[id+1] = byte(t[2]>>2) | byte(t[3]<<1) | byte(t[4]<<4) | byte(t[5]<<7)
Expand Down

0 comments on commit 8380db8

Please sign in to comment.