From b7abc00044a1942bb8ac7eef55ad73d2fbc53e72 Mon Sep 17 00:00:00 2001 From: Piotr Dyraga Date: Thu, 28 Jun 2018 15:47:41 +0200 Subject: [PATCH] Test of an additively homomorphic property for a small modulus --- paillier_test.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/paillier_test.go b/paillier_test.go index 8918e27..e157ec2 100644 --- a/paillier_test.go +++ b/paillier_test.go @@ -78,3 +78,17 @@ func TestAddCyphers(t *testing.T) { t.Errorf("Unexpected decrypted value [%v]", m) } } + +func TestAddCypherWithSmallKeyModulus(t *testing.T) { + privateKey := CreatePrivateKey(big.NewInt(7), big.NewInt(5)) + + cypher1, _ := privateKey.Encrypt(big.NewInt(41), rand.Reader) + cypher2, _ := privateKey.Encrypt(big.NewInt(219), rand.Reader) + cypher3, _ := privateKey.Encrypt(big.NewInt(54), rand.Reader) + cypher4 := privateKey.Add(cypher1, cypher2, cypher3) + + m := privateKey.Decrypt(cypher4) + if !reflect.DeepEqual(m, big.NewInt(34)) { + t.Errorf("Unexpected decrypted value [%v]", m) + } +}