pub self-reference renamed to pk
We want to use a noun-ish name, not an adjective.
This commit is contained in:
1 file changed
+10
-10
+10
-10
@@ -10,11 +10,11 @@ type PublicKey struct {
|
||||
N *big.Int
|
||||
}
|
||||
|
||||
func (this *PublicKey) GetNSquare() *big.Int {
|
||||
return new(big.Int).Mul(this.N, this.N)
|
||||
func (pk *PublicKey) GetNSquare() *big.Int {
|
||||
return new(big.Int).Mul(pk.N, pk.N)
|
||||
}
|
||||
|
||||
// Encode a plaintext in a cypher one. The plain text must be smaller that
|
||||
// Encrypt a plaintext into a cypher one. The plain text must be smaller that
|
||||
// N and bigger or equal than zero. random is usually rand.Reader from the
|
||||
// package crypto/rand.
|
||||
//
|
||||
@@ -24,19 +24,19 @@ func (this *PublicKey) GetNSquare() *big.Int {
|
||||
// See [KL 08] construction 11.32, page 414.
|
||||
//
|
||||
// Returns an error if an error has be returned by io.Reader.
|
||||
func (pub *PublicKey) Encrypt(m *big.Int, random io.Reader) (*Cypher, error) {
|
||||
r, err := GetRandomNumberInMultiplicativeGroup(pub.N, random)
|
||||
func (pk *PublicKey) Encrypt(m *big.Int, random io.Reader) (*Cypher, error) {
|
||||
r, err := GetRandomNumberInMultiplicativeGroup(pk.N, random)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
nSquare := pub.GetNSquare()
|
||||
nSquare := pk.GetNSquare()
|
||||
|
||||
// g is _always_ equal n+1
|
||||
// Threshold encryption is safe only for g=n+1 choice.
|
||||
// See [DJN 10], section 5.1
|
||||
g := new(big.Int).Add(pub.N, big.NewInt(1))
|
||||
g := new(big.Int).Add(pk.N, big.NewInt(1))
|
||||
gm := new(big.Int).Exp(g, m, nSquare)
|
||||
rn := new(big.Int).Exp(r, pub.N, nSquare)
|
||||
rn := new(big.Int).Exp(r, pk.N, nSquare)
|
||||
return &Cypher{new(big.Int).Mod(new(big.Int).Mul(rn, gm), nSquare)}, nil
|
||||
}
|
||||
|
||||
@@ -48,13 +48,13 @@ func (pub *PublicKey) Encrypt(m *big.Int, random io.Reader) (*Cypher, error) {
|
||||
// plaintexts:
|
||||
//
|
||||
// D( (E(m1) * E(m2) mod n^2) ) = m1 + m2 mod n
|
||||
func (pub *PublicKey) Add(cypher ...*Cypher) *Cypher {
|
||||
func (pk *PublicKey) Add(cypher ...*Cypher) *Cypher {
|
||||
accumulator := big.NewInt(1)
|
||||
|
||||
for _, c := range cypher {
|
||||
accumulator = new(big.Int).Mod(
|
||||
new(big.Int).Mul(accumulator, c.C),
|
||||
pub.GetNSquare(),
|
||||
pk.GetNSquare(),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user