Do not cache N^2 value in PublicKey
Let's keep this structure clean. Computing N^2 is just a really small piece of encryption/decryption work and if we decide we need to tweak performance, we will need a different approach anyway.
This commit is contained in:
2 files changed
+2
-7
No files matched your search
+1
-6
@@ -8,7 +8,6 @@ import (
|
||||
|
||||
type PublicKey struct {
|
||||
N, G *big.Int // usually G is set to N+1
|
||||
n2 *big.Int // the cache value of N^2
|
||||
}
|
||||
|
||||
func (this *PublicKey) GetBSON() (interface{}, error) {
|
||||
@@ -19,11 +18,7 @@ func (this *PublicKey) GetBSON() (interface{}, error) {
|
||||
}
|
||||
|
||||
func (this *PublicKey) GetNSquare() *big.Int {
|
||||
if this.n2 != nil {
|
||||
return this.n2
|
||||
}
|
||||
this.n2 = new(big.Int).Mul(this.N, this.N)
|
||||
return this.n2
|
||||
return new(big.Int).Mul(this.N, this.N)
|
||||
}
|
||||
|
||||
// Encode a plaintext in a cypher one. The plain text must be smaller that
|
||||
|
||||
Reference in new issue
Block a user