mirror of
https://github.com/tuneinsight/lattigo.git
synced 2025-09-13 03:27:14 +00:00
[utils/sampling]: removed panics & removed PRNG in ckks.Encoder
This commit is contained in:
@@ -2,6 +2,7 @@ package sampling
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"golang.org/x/crypto/blake2b"
|
||||
@@ -37,7 +38,7 @@ func NewPRNG() (*KeyedPRNG, error) {
|
||||
prng := new(KeyedPRNG)
|
||||
key := make([]byte, 64)
|
||||
if _, err := rand.Read(key); err != nil {
|
||||
panic("crypto rand error")
|
||||
return fmt.Errorf("crypto rand error: %w", err)
|
||||
}
|
||||
prng.key = key
|
||||
prng.xof, err = blake2b.NewXOF(blake2b.OutputLengthUnknown, key)
|
||||
@@ -55,10 +56,7 @@ func (prng *KeyedPRNG) Key() (key []byte) {
|
||||
|
||||
// Read reads bytes from the KeyedPRNG on sum.
|
||||
func (prng *KeyedPRNG) Read(sum []byte) (n int, err error) {
|
||||
if n, err = prng.xof.Read(sum); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return n, nil
|
||||
return prng.xof.Read(sum)
|
||||
}
|
||||
|
||||
// Reset resets the PRNG to its initial state.
|
||||
|
||||
Reference in New Issue
Block a user