Merge pull request #7 from keep-network/cypher-multiplication

Added support for a Cypher multiplication
This commit is contained in:
Jakub Nowakowski authored and GitHub committed 2018-07-17 15:27:34 +02:00
commit 3eb21f405c
2 files changed
+57 -11

No files matched your search

+13
View File
@@ -81,6 +81,19 @@ func (pk *PublicKey) Add(cypher ...*Cypher) *Cypher {
}
}
// Mul returns a product of `cypher` and `scalar` without decrypting `cypher`.
//
// It's possible because Paillier is a homomorphic encryption scheme, where
// an encrypted plaintext `m` raised to an integer `k` will decrypt to the
// product of the plaintext `m` and `k`:
//
// D( E(m)^k mod N^2 ) = km mod N
func (pk *PublicKey) Mul(cypher *Cypher, scalar *big.Int) *Cypher {
return &Cypher{
C: new(big.Int).Exp(cypher.C, scalar, pk.GetNSquare()),
}
}
type PrivateKey struct {
PublicKey
Lambda *big.Int