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
|
N *big.Int
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *PublicKey) GetNSquare() *big.Int {
|
func (pk *PublicKey) GetNSquare() *big.Int {
|
||||||
return new(big.Int).Mul(this.N, this.N)
|
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
|
// N and bigger or equal than zero. random is usually rand.Reader from the
|
||||||
// package crypto/rand.
|
// package crypto/rand.
|
||||||
//
|
//
|
||||||
@@ -24,19 +24,19 @@ func (this *PublicKey) GetNSquare() *big.Int {
|
|||||||
// See [KL 08] construction 11.32, page 414.
|
// See [KL 08] construction 11.32, page 414.
|
||||||
//
|
//
|
||||||
// Returns an error if an error has be returned by io.Reader.
|
// Returns an error if an error has be returned by io.Reader.
|
||||||
func (pub *PublicKey) Encrypt(m *big.Int, random io.Reader) (*Cypher, error) {
|
func (pk *PublicKey) Encrypt(m *big.Int, random io.Reader) (*Cypher, error) {
|
||||||
r, err := GetRandomNumberInMultiplicativeGroup(pub.N, random)
|
r, err := GetRandomNumberInMultiplicativeGroup(pk.N, random)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
nSquare := pub.GetNSquare()
|
nSquare := pk.GetNSquare()
|
||||||
|
|
||||||
// g is _always_ equal n+1
|
// g is _always_ equal n+1
|
||||||
// Threshold encryption is safe only for g=n+1 choice.
|
// Threshold encryption is safe only for g=n+1 choice.
|
||||||
// See [DJN 10], section 5.1
|
// 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)
|
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
|
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:
|
// plaintexts:
|
||||||
//
|
//
|
||||||
// D( (E(m1) * E(m2) mod n^2) ) = m1 + m2 mod n
|
// 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)
|
accumulator := big.NewInt(1)
|
||||||
|
|
||||||
for _, c := range cypher {
|
for _, c := range cypher {
|
||||||
accumulator = new(big.Int).Mod(
|
accumulator = new(big.Int).Mod(
|
||||||
new(big.Int).Mul(accumulator, c.C),
|
new(big.Int).Mul(accumulator, c.C),
|
||||||
pub.GetNSquare(),
|
pk.GetNSquare(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user