Skip to content

Commit

Permalink
fixed sparse ternary sampler to wipe poly before sampling (#179)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pro7ech authored Feb 21, 2022
1 parent 672f065 commit 27fee8b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
7 changes: 7 additions & 0 deletions ring/ring_sampler_ternary.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,13 @@ func (ts *TernarySampler) sampleSparse(lvl int, pol *Poly) {
pointer = 0
}
}

for _, i := range index {
for k := 0; k < lvl+1; k++ {
pol.Coeffs[k][i] = 0
}

}
}

// kysampling uses the binary expansion and random bytes matrix to sample a discrete Gaussian value and its sign.
Expand Down
24 changes: 16 additions & 8 deletions ring/ring_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,17 +391,25 @@ func testTernarySampler(testContext *testParams, t *testing.T) {

ternarySampler := NewTernarySamplerWithHammingWeight(prng, testContext.ringQ, p, false)

pol := ternarySampler.ReadNew()

for i := range testContext.ringQ.Modulus {
hw := 0
for _, c := range pol.Coeffs[i] {
if c != 0 {
hw++
checkPoly := func(pol *Poly) {
for i := range testContext.ringQ.Modulus {
hw := 0
for _, c := range pol.Coeffs[i] {
if c != 0 {
hw++
}
}
require.True(t, hw == p)
}
require.True(t, hw == p)
}

pol := ternarySampler.ReadNew()

checkPoly(pol)

ternarySampler.Read(pol)

checkPoly(pol)
})
}
}
Expand Down

0 comments on commit 27fee8b

Please sign in to comment.