-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #417 from tuneinsight/dev_fix_benchmarks
Dev fix benchmarks
- Loading branch information
Showing
10 changed files
with
1,641 additions
and
216 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package hebin | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/tuneinsight/lattigo/v5/core/rlwe" | ||
"github.com/tuneinsight/lattigo/v5/utils" | ||
"github.com/tuneinsight/lattigo/v5/utils/sampling" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func BenchmarkHEBin(b *testing.B) { | ||
|
||
b.Run("BlindRotateCore/LogN=(9, 10)/LogQ=(13.6,26.99)/Gadget=2^7", func(b *testing.B) { | ||
|
||
// RLWE parameters of the BlindRotation | ||
// N=1024, Q=0x7fff801 -> 131 bit secure | ||
paramsBR, err := rlwe.NewParametersFromLiteral(rlwe.ParametersLiteral{ | ||
LogN: 10, | ||
Q: []uint64{0x7fff801}, | ||
NTTFlag: NTTFlag, | ||
}) | ||
|
||
require.NoError(b, err) | ||
|
||
// RLWE parameters of the samples | ||
// N=512, Q=0x3001 -> 135 bit secure | ||
paramsLWE, err := rlwe.NewParametersFromLiteral(rlwe.ParametersLiteral{ | ||
LogN: 9, | ||
Q: []uint64{0x3001}, | ||
NTTFlag: NTTFlag, | ||
}) | ||
|
||
require.NoError(b, err) | ||
|
||
evkParams := rlwe.EvaluationKeyParameters{BaseTwoDecomposition: utils.Pointy(7)} | ||
|
||
// RLWE secret for the samples | ||
skLWE := rlwe.NewKeyGenerator(paramsLWE).GenSecretKeyNew() | ||
|
||
// Secret of the RGSW ciphertexts encrypting the bits of skLWE | ||
skBR := rlwe.NewKeyGenerator(paramsBR).GenSecretKeyNew() | ||
|
||
// Collection of RGSW ciphertexts encrypting the bits of skLWE under skBR | ||
BRK := GenEvaluationKeyNew(paramsBR, skBR, paramsLWE, skLWE, evkParams) | ||
|
||
// Random LWE mask mod 2N with odd coefficients | ||
a := make([]uint64, paramsLWE.N()) | ||
mask := uint64(2*paramsLWE.N() - 1) | ||
for i := range a { | ||
ai := sampling.RandUint64() & mask | ||
if ai&1 == 0 && ai != 0 { | ||
ai ^= 1 | ||
} | ||
a[i] = ai | ||
} | ||
|
||
acc := rlwe.NewCiphertext(paramsBR, 1, paramsBR.MaxLevel()) | ||
|
||
// Evaluator for the Blind Rotation evaluation | ||
eval := NewEvaluator(paramsBR, paramsLWE) | ||
|
||
b.ResetTimer() | ||
|
||
for i := 0; i < b.N; i++ { | ||
if err := eval.BlindRotateCore(a, acc, BRK); err != nil { | ||
panic(err) | ||
} | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.