-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Rename BootstrapKey -> BlindRotateKey
- Loading branch information
Showing
4 changed files
with
110 additions
and
110 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
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 |
---|---|---|
@@ -1,100 +1,100 @@ | ||
package tfhe | ||
|
||
// EvaluationKey is a public key for Evaluator, | ||
// which consists of Bootstrapping Key and KeySwitching Key. | ||
// which consists of BlindRotation Key and KeySwitching Key. | ||
// All keys should be treated as read-only. | ||
// Changing them mid-operation will usually result in wrong results. | ||
type EvaluationKey[T TorusInt] struct { | ||
// BootstrapKey is a bootstrap key. | ||
BootstrapKey BootstrapKey[T] | ||
// BlindRotateKey is a blindrotate key. | ||
BlindRotateKey BlindRotateKey[T] | ||
// KeySwitchKey is a keyswitch key switching LWELargeKey -> LWEKey. | ||
KeySwitchKey LWEKeySwitchKey[T] | ||
} | ||
|
||
// NewEvaluationKey allocates an empty EvaluationKey. | ||
func NewEvaluationKey[T TorusInt](params Parameters[T]) EvaluationKey[T] { | ||
return EvaluationKey[T]{ | ||
BootstrapKey: NewBootstrapKey(params), | ||
KeySwitchKey: NewKeySwitchKeyForBootstrap(params), | ||
BlindRotateKey: NewBlindRotateKey(params), | ||
KeySwitchKey: NewKeySwitchKeyForBootstrap(params), | ||
} | ||
} | ||
|
||
// NewEvaluationKeyCustom allocates an empty EvaluationKey with custom parameters. | ||
func NewEvaluationKeyCustom[T TorusInt](lweDimension, glweRank, polyDegree int, bootstrapParams, keyswitchParams GadgetParameters[T]) EvaluationKey[T] { | ||
return EvaluationKey[T]{ | ||
BootstrapKey: NewBootstrapKeyCustom(lweDimension, glweRank, polyDegree, bootstrapParams), | ||
KeySwitchKey: NewKeySwitchKeyForBootstrapCustom(lweDimension, glweRank, polyDegree, keyswitchParams), | ||
BlindRotateKey: NewBlindRotateKeyCustom(lweDimension, glweRank, polyDegree, bootstrapParams), | ||
KeySwitchKey: NewKeySwitchKeyForBootstrapCustom(lweDimension, glweRank, polyDegree, keyswitchParams), | ||
} | ||
} | ||
|
||
// Copy returns a copy of the key. | ||
func (evk EvaluationKey[T]) Copy() EvaluationKey[T] { | ||
return EvaluationKey[T]{ | ||
BootstrapKey: evk.BootstrapKey.Copy(), | ||
KeySwitchKey: evk.KeySwitchKey.Copy(), | ||
BlindRotateKey: evk.BlindRotateKey.Copy(), | ||
KeySwitchKey: evk.KeySwitchKey.Copy(), | ||
} | ||
} | ||
|
||
// CopyFrom copies values from key. | ||
func (evk *EvaluationKey[T]) CopyFrom(evkIn EvaluationKey[T]) { | ||
evk.BootstrapKey.CopyFrom(evkIn.BootstrapKey) | ||
evk.BlindRotateKey.CopyFrom(evkIn.BlindRotateKey) | ||
evk.KeySwitchKey.CopyFrom(evkIn.KeySwitchKey) | ||
} | ||
|
||
// Clear clears the key. | ||
func (evk *EvaluationKey[T]) Clear() { | ||
evk.BootstrapKey.Clear() | ||
evk.BlindRotateKey.Clear() | ||
evk.KeySwitchKey.Clear() | ||
} | ||
|
||
// BootstrapKey is a key for bootstrapping. | ||
// BlindRotateKey is a key for blind rotation. | ||
// Essentially, this is a GGSW encryption of LWEKey with GLWEKey. | ||
// However, FFT is already applied for fast external product. | ||
type BootstrapKey[T TorusInt] struct { | ||
type BlindRotateKey[T TorusInt] struct { | ||
GadgetParameters GadgetParameters[T] | ||
|
||
// Value has length LWEDimension. | ||
Value []FourierGGSWCiphertext[T] | ||
} | ||
|
||
// NewBootstrapKey allocates an empty BootstrappingKey. | ||
func NewBootstrapKey[T TorusInt](params Parameters[T]) BootstrapKey[T] { | ||
bsk := make([]FourierGGSWCiphertext[T], params.lweDimension) | ||
// NewBlindRotateKey allocates an empty BlindRotateKey. | ||
func NewBlindRotateKey[T TorusInt](params Parameters[T]) BlindRotateKey[T] { | ||
brk := make([]FourierGGSWCiphertext[T], params.lweDimension) | ||
for i := 0; i < params.lweDimension; i++ { | ||
bsk[i] = NewFourierGGSWCiphertext(params, params.bootstrapParameters) | ||
brk[i] = NewFourierGGSWCiphertext(params, params.bootstrapParameters) | ||
} | ||
return BootstrapKey[T]{Value: bsk, GadgetParameters: params.bootstrapParameters} | ||
return BlindRotateKey[T]{Value: brk, GadgetParameters: params.bootstrapParameters} | ||
} | ||
|
||
// NewBootstrapKeyCustom allocates an empty BootstrappingKey with custom parameters. | ||
func NewBootstrapKeyCustom[T TorusInt](lweDimension, glweRank, polyDegree int, gadgetParams GadgetParameters[T]) BootstrapKey[T] { | ||
bsk := make([]FourierGGSWCiphertext[T], lweDimension) | ||
// NewBlindRotateKeyCustom allocates an empty BlindRotateKey with custom parameters. | ||
func NewBlindRotateKeyCustom[T TorusInt](lweDimension, glweRank, polyDegree int, gadgetParams GadgetParameters[T]) BlindRotateKey[T] { | ||
brk := make([]FourierGGSWCiphertext[T], lweDimension) | ||
for i := 0; i < lweDimension; i++ { | ||
bsk[i] = NewFourierGGSWCiphertextCustom(glweRank, polyDegree, gadgetParams) | ||
brk[i] = NewFourierGGSWCiphertextCustom(glweRank, polyDegree, gadgetParams) | ||
} | ||
return BootstrapKey[T]{Value: bsk, GadgetParameters: gadgetParams} | ||
return BlindRotateKey[T]{Value: brk, GadgetParameters: gadgetParams} | ||
} | ||
|
||
// Copy returns a copy of the key. | ||
func (bsk BootstrapKey[T]) Copy() BootstrapKey[T] { | ||
bskCopy := make([]FourierGGSWCiphertext[T], len(bsk.Value)) | ||
for i := range bsk.Value { | ||
bskCopy[i] = bsk.Value[i].Copy() | ||
func (brk BlindRotateKey[T]) Copy() BlindRotateKey[T] { | ||
brkCopy := make([]FourierGGSWCiphertext[T], len(brk.Value)) | ||
for i := range brk.Value { | ||
brkCopy[i] = brk.Value[i].Copy() | ||
} | ||
return BootstrapKey[T]{Value: bskCopy, GadgetParameters: bsk.GadgetParameters} | ||
return BlindRotateKey[T]{Value: brkCopy, GadgetParameters: brk.GadgetParameters} | ||
} | ||
|
||
// CopyFrom copies values from key. | ||
func (bsk *BootstrapKey[T]) CopyFrom(bskIn BootstrapKey[T]) { | ||
for i := range bsk.Value { | ||
bsk.Value[i].CopyFrom(bskIn.Value[i]) | ||
func (brk *BlindRotateKey[T]) CopyFrom(brkIn BlindRotateKey[T]) { | ||
for i := range brk.Value { | ||
brk.Value[i].CopyFrom(brkIn.Value[i]) | ||
} | ||
bsk.GadgetParameters = bskIn.GadgetParameters | ||
brk.GadgetParameters = brkIn.GadgetParameters | ||
} | ||
|
||
// Clear clears the key. | ||
func (bsk *BootstrapKey[T]) Clear() { | ||
for i := range bsk.Value { | ||
bsk.Value[i].Clear() | ||
func (brk *BlindRotateKey[T]) Clear() { | ||
for i := range brk.Value { | ||
brk.Value[i].Clear() | ||
} | ||
} |
Oops, something went wrong.