mirror of
https://github.com/tuneinsight/lattigo.git
synced 2025-09-13 03:27:14 +00:00
[bgv]: added tests for IsBatched = false
This commit is contained in:
@@ -217,33 +217,76 @@ func testParameters(tc *testContext, t *testing.T) {
|
|||||||
func testEncoder(tc *testContext, t *testing.T) {
|
func testEncoder(tc *testContext, t *testing.T) {
|
||||||
|
|
||||||
for _, lvl := range tc.testLevel {
|
for _, lvl := range tc.testLevel {
|
||||||
t.Run(GetTestName("Encoder/Uint", tc.params, lvl), func(t *testing.T) {
|
t.Run(GetTestName("Encoder/Uint/IsBatched=true", tc.params, lvl), func(t *testing.T) {
|
||||||
values, plaintext, _ := newTestVectorsLvl(lvl, tc.params.DefaultScale(), tc, nil)
|
values, plaintext, _ := newTestVectorsLvl(lvl, tc.params.DefaultScale(), tc, nil)
|
||||||
verifyTestVectors(tc, nil, values, plaintext, t)
|
verifyTestVectors(tc, nil, values, plaintext, t)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, lvl := range tc.testLevel {
|
for _, lvl := range tc.testLevel {
|
||||||
t.Run(GetTestName("Encoder/Int", tc.params, lvl), func(t *testing.T) {
|
t.Run(GetTestName("Encoder/Int/IsBatched=true", tc.params, lvl), func(t *testing.T) {
|
||||||
|
|
||||||
T := tc.params.PlaintextModulus()
|
T := tc.params.PlaintextModulus()
|
||||||
THalf := T >> 1
|
THalf := T >> 1
|
||||||
coeffs := tc.uSampler.ReadNew()
|
poly := tc.uSampler.ReadNew()
|
||||||
coeffsInt := make([]int64, coeffs.N())
|
coeffs := make([]int64, poly.N())
|
||||||
for i, c := range coeffs.Coeffs[0] {
|
for i, c := range poly.Coeffs[0] {
|
||||||
c %= T
|
c %= T
|
||||||
if c >= THalf {
|
if c >= THalf {
|
||||||
coeffsInt[i] = -int64(T - c)
|
coeffs[i] = -int64(T - c)
|
||||||
} else {
|
} else {
|
||||||
coeffsInt[i] = int64(c)
|
coeffs[i] = int64(c)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
plaintext := NewPlaintext(tc.params, lvl)
|
plaintext := NewPlaintext(tc.params, lvl)
|
||||||
tc.encoder.Encode(coeffsInt, plaintext)
|
tc.encoder.Encode(coeffs, plaintext)
|
||||||
have := make([]int64, tc.params.MaxSlots())
|
have := make([]int64, tc.params.MaxSlots())
|
||||||
tc.encoder.Decode(plaintext, have)
|
tc.encoder.Decode(plaintext, have)
|
||||||
require.True(t, utils.EqualSlice(coeffsInt, have))
|
require.True(t, utils.EqualSlice(coeffs, have))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, lvl := range tc.testLevel {
|
||||||
|
t.Run(GetTestName("Encoder/Uint/IsBatched=false", tc.params, lvl), func(t *testing.T) {
|
||||||
|
T := tc.params.PlaintextModulus()
|
||||||
|
poly := tc.uSampler.ReadNew()
|
||||||
|
coeffs := make([]uint64, poly.N())
|
||||||
|
for i, c := range poly.Coeffs[0] {
|
||||||
|
coeffs[i] = c % T
|
||||||
|
}
|
||||||
|
|
||||||
|
plaintext := NewPlaintext(tc.params, lvl)
|
||||||
|
plaintext.IsBatched = false
|
||||||
|
require.NoError(t, tc.encoder.Encode(coeffs, plaintext))
|
||||||
|
have := make([]uint64, tc.params.MaxSlots())
|
||||||
|
require.NoError(t, tc.encoder.Decode(plaintext, have))
|
||||||
|
require.True(t, utils.EqualSlice(coeffs, have))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, lvl := range tc.testLevel {
|
||||||
|
t.Run(GetTestName("Encoder/Int/IsBatched=false", tc.params, lvl), func(t *testing.T) {
|
||||||
|
|
||||||
|
T := tc.params.PlaintextModulus()
|
||||||
|
THalf := T >> 1
|
||||||
|
poly := tc.uSampler.ReadNew()
|
||||||
|
coeffs := make([]int64, poly.N())
|
||||||
|
for i, c := range poly.Coeffs[0] {
|
||||||
|
c %= T
|
||||||
|
if c >= THalf {
|
||||||
|
coeffs[i] = -int64(T - c)
|
||||||
|
} else {
|
||||||
|
coeffs[i] = int64(c)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
plaintext := NewPlaintext(tc.params, lvl)
|
||||||
|
plaintext.IsBatched = false
|
||||||
|
require.NoError(t, tc.encoder.Encode(coeffs, plaintext))
|
||||||
|
have := make([]int64, tc.params.MaxSlots())
|
||||||
|
require.NoError(t, tc.encoder.Decode(plaintext, have))
|
||||||
|
require.True(t, utils.EqualSlice(coeffs, have))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -408,7 +451,7 @@ func testEvaluator(tc *testContext, t *testing.T) {
|
|||||||
t.Run(GetTestName("Evaluator/Mul/Ct/Ct/Inplace", tc.params, lvl), func(t *testing.T) {
|
t.Run(GetTestName("Evaluator/Mul/Ct/Ct/Inplace", tc.params, lvl), func(t *testing.T) {
|
||||||
|
|
||||||
if lvl == 0 {
|
if lvl == 0 {
|
||||||
t.Skip("Level = 0")
|
t.Skip("Skipping: Level = 0")
|
||||||
}
|
}
|
||||||
|
|
||||||
values0, _, ciphertext0 := newTestVectorsLvl(lvl, tc.params.NewScale(3), tc, tc.encryptorSk)
|
values0, _, ciphertext0 := newTestVectorsLvl(lvl, tc.params.NewScale(3), tc, tc.encryptorSk)
|
||||||
@@ -428,7 +471,7 @@ func testEvaluator(tc *testContext, t *testing.T) {
|
|||||||
t.Run(GetTestName("Evaluator/Mul/Ct/Pt/Inplace", tc.params, lvl), func(t *testing.T) {
|
t.Run(GetTestName("Evaluator/Mul/Ct/Pt/Inplace", tc.params, lvl), func(t *testing.T) {
|
||||||
|
|
||||||
if lvl == 0 {
|
if lvl == 0 {
|
||||||
t.Skip("Level = 0")
|
t.Skip("Skipping: Level = 0")
|
||||||
}
|
}
|
||||||
|
|
||||||
values0, _, ciphertext0 := newTestVectorsLvl(lvl, tc.params.NewScale(3), tc, tc.encryptorSk)
|
values0, _, ciphertext0 := newTestVectorsLvl(lvl, tc.params.NewScale(3), tc, tc.encryptorSk)
|
||||||
@@ -448,7 +491,7 @@ func testEvaluator(tc *testContext, t *testing.T) {
|
|||||||
t.Run(GetTestName("Evaluator/Mul/Ct/Scalar/Inplace", tc.params, lvl), func(t *testing.T) {
|
t.Run(GetTestName("Evaluator/Mul/Ct/Scalar/Inplace", tc.params, lvl), func(t *testing.T) {
|
||||||
|
|
||||||
if lvl == 0 {
|
if lvl == 0 {
|
||||||
t.Skip("Level = 0")
|
t.Skip("Skipping: Level = 0")
|
||||||
}
|
}
|
||||||
|
|
||||||
values, _, ciphertext := newTestVectorsLvl(lvl, tc.params.DefaultScale(), tc, tc.encryptorSk)
|
values, _, ciphertext := newTestVectorsLvl(lvl, tc.params.DefaultScale(), tc, tc.encryptorSk)
|
||||||
@@ -466,7 +509,7 @@ func testEvaluator(tc *testContext, t *testing.T) {
|
|||||||
t.Run(GetTestName("Evaluator/Mul/Ct/Vector/Inplace", tc.params, lvl), func(t *testing.T) {
|
t.Run(GetTestName("Evaluator/Mul/Ct/Vector/Inplace", tc.params, lvl), func(t *testing.T) {
|
||||||
|
|
||||||
if lvl == 0 {
|
if lvl == 0 {
|
||||||
t.Skip("Level = 0")
|
t.Skip("Skipping: Level = 0")
|
||||||
}
|
}
|
||||||
|
|
||||||
values, _, ciphertext := newTestVectorsLvl(lvl, tc.params.DefaultScale(), tc, tc.encryptorSk)
|
values, _, ciphertext := newTestVectorsLvl(lvl, tc.params.DefaultScale(), tc, tc.encryptorSk)
|
||||||
@@ -482,7 +525,7 @@ func testEvaluator(tc *testContext, t *testing.T) {
|
|||||||
t.Run(GetTestName("Evaluator/Square/Ct/Ct/Inplace", tc.params, lvl), func(t *testing.T) {
|
t.Run(GetTestName("Evaluator/Square/Ct/Ct/Inplace", tc.params, lvl), func(t *testing.T) {
|
||||||
|
|
||||||
if lvl == 0 {
|
if lvl == 0 {
|
||||||
t.Skip("Level = 0")
|
t.Skip("Skipping: Level = 0")
|
||||||
}
|
}
|
||||||
|
|
||||||
values0, _, ciphertext0 := newTestVectorsLvl(lvl, tc.params.NewScale(3), tc, tc.encryptorSk)
|
values0, _, ciphertext0 := newTestVectorsLvl(lvl, tc.params.NewScale(3), tc, tc.encryptorSk)
|
||||||
@@ -498,7 +541,7 @@ func testEvaluator(tc *testContext, t *testing.T) {
|
|||||||
t.Run(GetTestName("Evaluator/MulRelin/Ct/Ct/Inplace", tc.params, lvl), func(t *testing.T) {
|
t.Run(GetTestName("Evaluator/MulRelin/Ct/Ct/Inplace", tc.params, lvl), func(t *testing.T) {
|
||||||
|
|
||||||
if lvl == 0 {
|
if lvl == 0 {
|
||||||
t.Skip("Level = 0")
|
t.Skip("Skipping: Level = 0")
|
||||||
}
|
}
|
||||||
|
|
||||||
values0, _, ciphertext0 := newTestVectorsLvl(lvl, tc.params.NewScale(3), tc, tc.encryptorSk)
|
values0, _, ciphertext0 := newTestVectorsLvl(lvl, tc.params.NewScale(3), tc, tc.encryptorSk)
|
||||||
@@ -522,7 +565,7 @@ func testEvaluator(tc *testContext, t *testing.T) {
|
|||||||
t.Run(GetTestName("Evaluator/MulThenAdd/Ct/Ct/Inplace", tc.params, lvl), func(t *testing.T) {
|
t.Run(GetTestName("Evaluator/MulThenAdd/Ct/Ct/Inplace", tc.params, lvl), func(t *testing.T) {
|
||||||
|
|
||||||
if lvl == 0 {
|
if lvl == 0 {
|
||||||
t.Skip("Level = 0")
|
t.Skip("Skipping: Level = 0")
|
||||||
}
|
}
|
||||||
|
|
||||||
values0, _, ciphertext0 := newTestVectorsLvl(lvl, tc.params.DefaultScale(), tc, tc.encryptorSk)
|
values0, _, ciphertext0 := newTestVectorsLvl(lvl, tc.params.DefaultScale(), tc, tc.encryptorSk)
|
||||||
@@ -543,7 +586,7 @@ func testEvaluator(tc *testContext, t *testing.T) {
|
|||||||
t.Run(GetTestName("Evaluator/MulThenAdd/Ct/Pt/Inplace", tc.params, lvl), func(t *testing.T) {
|
t.Run(GetTestName("Evaluator/MulThenAdd/Ct/Pt/Inplace", tc.params, lvl), func(t *testing.T) {
|
||||||
|
|
||||||
if lvl == 0 {
|
if lvl == 0 {
|
||||||
t.Skip("Level = 0")
|
t.Skip("Skipping: Level = 0")
|
||||||
}
|
}
|
||||||
|
|
||||||
values0, _, ciphertext0 := newTestVectorsLvl(lvl, tc.params.DefaultScale(), tc, tc.encryptorSk)
|
values0, _, ciphertext0 := newTestVectorsLvl(lvl, tc.params.DefaultScale(), tc, tc.encryptorSk)
|
||||||
@@ -564,7 +607,7 @@ func testEvaluator(tc *testContext, t *testing.T) {
|
|||||||
t.Run(GetTestName("Evaluator/MulThenAdd/Ct/Scalar/Inplace", tc.params, lvl), func(t *testing.T) {
|
t.Run(GetTestName("Evaluator/MulThenAdd/Ct/Scalar/Inplace", tc.params, lvl), func(t *testing.T) {
|
||||||
|
|
||||||
if lvl == 0 {
|
if lvl == 0 {
|
||||||
t.Skip("Level = 0")
|
t.Skip("Skipping: Level = 0")
|
||||||
}
|
}
|
||||||
|
|
||||||
values0, _, ciphertext0 := newTestVectorsLvl(lvl, tc.params.NewScale(7), tc, tc.encryptorSk)
|
values0, _, ciphertext0 := newTestVectorsLvl(lvl, tc.params.NewScale(7), tc, tc.encryptorSk)
|
||||||
@@ -585,7 +628,7 @@ func testEvaluator(tc *testContext, t *testing.T) {
|
|||||||
t.Run(GetTestName("Evaluator/MulThenAdd/Ct/Vector/Inplace", tc.params, lvl), func(t *testing.T) {
|
t.Run(GetTestName("Evaluator/MulThenAdd/Ct/Vector/Inplace", tc.params, lvl), func(t *testing.T) {
|
||||||
|
|
||||||
if lvl == 0 {
|
if lvl == 0 {
|
||||||
t.Skip("Level = 0")
|
t.Skip("Skipping: Level = 0")
|
||||||
}
|
}
|
||||||
|
|
||||||
values0, _, ciphertext0 := newTestVectorsLvl(lvl, tc.params.NewScale(7), tc, tc.encryptorSk)
|
values0, _, ciphertext0 := newTestVectorsLvl(lvl, tc.params.NewScale(7), tc, tc.encryptorSk)
|
||||||
@@ -609,7 +652,7 @@ func testEvaluator(tc *testContext, t *testing.T) {
|
|||||||
t.Run(GetTestName("Evaluator/MulRelinThenAdd/Ct/Ct/Inplace", tc.params, lvl), func(t *testing.T) {
|
t.Run(GetTestName("Evaluator/MulRelinThenAdd/Ct/Ct/Inplace", tc.params, lvl), func(t *testing.T) {
|
||||||
|
|
||||||
if lvl == 0 {
|
if lvl == 0 {
|
||||||
t.Skip("Level = 0")
|
t.Skip("Skipping: Level = 0")
|
||||||
}
|
}
|
||||||
|
|
||||||
values0, _, ciphertext0 := newTestVectorsLvl(lvl, tc.params.DefaultScale(), tc, tc.encryptorSk)
|
values0, _, ciphertext0 := newTestVectorsLvl(lvl, tc.params.DefaultScale(), tc, tc.encryptorSk)
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ func NewPRNG() (*KeyedPRNG, error) {
|
|||||||
prng := new(KeyedPRNG)
|
prng := new(KeyedPRNG)
|
||||||
key := make([]byte, 64)
|
key := make([]byte, 64)
|
||||||
if _, err := rand.Read(key); err != nil {
|
if _, err := rand.Read(key); err != nil {
|
||||||
return fmt.Errorf("crypto rand error: %w", err)
|
return nil, fmt.Errorf("crypto rand error: %w", err)
|
||||||
}
|
}
|
||||||
prng.key = key
|
prng.key = key
|
||||||
prng.xof, err = blake2b.NewXOF(blake2b.OutputLengthUnknown, key)
|
prng.xof, err = blake2b.NewXOF(blake2b.OutputLengthUnknown, key)
|
||||||
|
|||||||
Reference in New Issue
Block a user