standardize naming

This commit is contained in:
sachaservan committed 2018-08-18 14:54:38 -04:00
1 parent 63e4695b16
commit 970db06efc
3 files changed
+16 -13

No files matched your search

+10 -8
View File
@@ -8,6 +8,7 @@ import (
type PublicKey struct {
N *big.Int
G *big.Int
}
func (pk *PublicKey) GetNSquare() *big.Int {
@@ -41,8 +42,7 @@ func (pk *PublicKey) EncryptWithR(m *big.Int, r *big.Int) (*Ciphertext, error) {
// 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(pk.N, big.NewInt(1))
gm := new(big.Int).Exp(g, m, nSquare)
gm := new(big.Int).Exp(pk.G, m, nSquare)
rn := new(big.Int).Exp(r, pk.N, nSquare)
return &Ciphertext{new(big.Int).Mod(new(big.Int).Mul(rn, gm), nSquare)}, nil
}
@@ -66,7 +66,7 @@ func (pk *PublicKey) Encrypt(m *big.Int, random io.Reader) (*Ciphertext, error)
return pk.EncryptWithR(m, r)
}
// Add takes an arbitrary number of cyphertexts and returns one that encodes
// Add takes an arbitrary number of ciphertexts and returns one that encodes
// their sum.
//
// It's possible because Paillier is a homomorphic encryption scheme, where
@@ -109,17 +109,17 @@ type SecretKey struct {
// Decodes ciphertext into a plaintext message.
//
// c - cyphertext to decrypt
// c - ciphertext to decrypt
// N, lambda - key attributes
//
// D(c) = [ ((c^lambda) mod N^2) - 1) / N ] lambda^-1 mod N
// D(c) = [ ((c^lambda)*mu mod N^2) - 1) / N ] lambda^-1 mod N
//
// See [KL 08] construction 11.32, page 414.
func (sk *SecretKey) Decrypt(ct *Ciphertext) (msg *big.Int) {
func (sk *SecretKey) Decrypt(ct *Ciphertext) *big.Int {
mu := new(big.Int).ModInverse(sk.Lambda, sk.N)
tmp := new(big.Int).Exp(ct.C, sk.Lambda, sk.GetNSquare())
msg = new(big.Int).Mod(new(big.Int).Mul(L(tmp, sk.N), mu), sk.N)
return
m := new(big.Int).Mod(new(big.Int).Mul(L(tmp, sk.N), mu), sk.N)
return m
}
type Ciphertext struct {
@@ -162,10 +162,12 @@ func computePhi(p, q *big.Int) *big.Int {
func CreateSecretKey(p, q *big.Int) *SecretKey {
n := new(big.Int).Mul(p, q)
lambda := computePhi(p, q)
g := new(big.Int).Add(n, big.NewInt(1))
return &SecretKey{
PublicKey: PublicKey{
N: n,
G: g,
},
Lambda: lambda,
}
+5 -5
View File
@@ -124,7 +124,7 @@ func TestCheckPlaintextSpace(t *testing.T) {
}
}
func TestAddCyphers(t *testing.T) {
func TestAddCiphertexts(t *testing.T) {
p, q := GenKeyPrimes(10)
sk := CreateSecretKey(p, q)
@@ -140,7 +140,7 @@ func TestAddCyphers(t *testing.T) {
}
}
func TestAddCypherWithSmallKeyModulus(t *testing.T) {
func TestAddCiphertextWithSmallKeyModulus(t *testing.T) {
sk := CreateSecretKey(big.NewInt(7), big.NewInt(5))
ct1, _ := sk.Encrypt(big.NewInt(30), rand.Reader)
@@ -154,7 +154,7 @@ func TestAddCypherWithSmallKeyModulus(t *testing.T) {
}
}
func TestMulCypher(t *testing.T) {
func TestMulCiphertext(t *testing.T) {
p, q := GenKeyPrimes(10)
sk := CreateSecretKey(p, q)
@@ -172,7 +172,7 @@ func TestMulCypher(t *testing.T) {
}
}
func TestMulCypherWithSmallKeyModulus(t *testing.T) {
func TestMulCiphertextWithSmallKeyModulus(t *testing.T) {
sk := CreateSecretKey(big.NewInt(7), big.NewInt(5))
ct, err := sk.Encrypt(big.NewInt(30), rand.Reader)
@@ -197,7 +197,7 @@ func GenKeyPrimes(bits int) (p, q *big.Int) {
continue
}
q, err = rand.Prime(rand.Reader, bits)
if err != nil {
if err != nil || p.Cmp(q) == 0 {
continue
}
+1
View File
@@ -243,6 +243,7 @@ func (tkg *ThresholdKeyGenerator) createViArray(shares []*big.Int) (viArray []*b
func (tkg *ThresholdKeyGenerator) createSecretKey(i int, share *big.Int, viArray []*big.Int) *ThresholdSecretKey {
ret := new(ThresholdSecretKey)
ret.N = tkg.n
ret.G = new(big.Int).Add(tkg.n, big.NewInt(1))
ret.V = tkg.v
ret.TotalNumberOfDecryptionServers = tkg.TotalNumberOfDecryptionServers