Commit be6b9198 authored by Sietse Ringers's avatar Sietse Ringers
Browse files

Add Paillier unit test

parent 89082567
......@@ -9,6 +9,7 @@ import (
"encoding/json"
"github.com/mhe/gabi"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
......@@ -327,3 +328,35 @@ func TestTransport(t *testing.T) {
t.Fatalf("%+v\n", err)
}
}
func TestPaillier(t *testing.T) {
parseMetaStore(t)
parseStorage(t)
parseAndroidStorage(t)
challenge, _ := gabi.RandomBigInt(256)
comm, _ := gabi.RandomBigInt(1000)
resp, _ := gabi.RandomBigInt(1000)
sk := Manager.paillierKey(true)
bytes, err := sk.Encrypt(challenge.Bytes())
require.NoError(t, err)
cipher := new(big.Int).SetBytes(bytes)
bytes, err = sk.Encrypt(comm.Bytes())
require.NoError(t, err)
commcipher := new(big.Int).SetBytes(bytes)
// [[ c ]]^resp * [[ comm ]]
cipher.Exp(cipher, resp, sk.NSquared).Mul(cipher, commcipher).Mod(cipher, sk.NSquared)
bytes, err = sk.Decrypt(cipher.Bytes())
require.NoError(t, err)
plaintext := new(big.Int).SetBytes(bytes)
expected := new(big.Int).Set(challenge)
expected.Mul(expected, resp).Add(expected, comm)
require.Equal(t, plaintext, expected)
teardown(t)
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment