[rlwe]: fixed nil interface bug in evaluator

This commit is contained in:
Jean-Philippe Bossuat
2023-04-13 14:41:32 +02:00
parent fa7759e1d9
commit 3e9369f2fa
3 changed files with 9 additions and 2 deletions

View File

@@ -48,7 +48,7 @@ func (evk *EvaluationKeySet) GetGaloisKey(galEl uint64) (gk *GaloisKey, err erro
// for which a Galois key exists in the object.
func (evk *EvaluationKeySet) GetGaloisKeysList() (galEls []uint64) {
if evk.GaloisKeys == nil {
if evk == nil || evk.GaloisKeys == nil {
return []uint64{}
}

View File

@@ -85,7 +85,7 @@ func NewEvaluator(params Parameters, evk EvaluationKeySetInterface) (eval *Evalu
var AutomorphismIndex map[uint64][]uint64
if evk != nil {
if !utils.IsNil(evk) {
if galEls := evk.GetGaloisKeysList(); len(galEls) != 0 {
AutomorphismIndex = make(map[uint64][]uint64)

View File

@@ -3,6 +3,7 @@ package utils
import (
"math/bits"
"reflect"
"golang.org/x/exp/constraints"
)
@@ -23,6 +24,12 @@ func Max[V constraints.Ordered](a, b V) (r V) {
return b
}
// IsNil returns true either type or value are nil.
// Only interfaces or pointers to objects should be passed as argument.
func IsNil(i interface{}) bool {
return i == nil || reflect.ValueOf(i).IsNil()
}
// BitReverse64 returns the bit-reverse value of the input value, within a context of 2^bitLen.
func BitReverse64[V uint64 | uint32 | int | int64](index V, bitLen int) uint64 {
return bits.Reverse64(uint64(index)) >> (64 - bitLen)