imported from https://bitbucket.org/ustraca/crypto
This commit is contained in:
1 parent
ca20730438
commit
8a9743f08e
11 files changed
+1805
No files matched your search
@@ -0,0 +1,70 @@
|
||||
package paillier
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"math/big"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestLCM(t *testing.T) {
|
||||
a := big.NewInt(2 * 3 * 3 * 3 * 5 * 5)
|
||||
b := big.NewInt(3 * 3 * 5 * 5 * 57 * 11)
|
||||
exp := big.NewInt(3 * 3 * 5 * 5)
|
||||
if reflect.DeepEqual(exp, LCM(a, b)) {
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
||||
func TestL(t *testing.T) {
|
||||
u := big.NewInt(21)
|
||||
n := big.NewInt(3)
|
||||
exp := big.NewInt(6)
|
||||
if !reflect.DeepEqual(exp, L(u, n)) {
|
||||
t.Error("L function is not good")
|
||||
}
|
||||
}
|
||||
|
||||
func TestComputeMu(t *testing.T) {
|
||||
p := big.NewInt(13)
|
||||
q := big.NewInt(11)
|
||||
|
||||
lambda := computeLamda(p, q)
|
||||
g := big.NewInt(5000)
|
||||
n := new(big.Int).Mul(p, q)
|
||||
|
||||
exp := big.NewInt(3)
|
||||
if !reflect.DeepEqual(computeMu(g, lambda, n), exp) {
|
||||
t.Error("lambda is not well computed")
|
||||
}
|
||||
}
|
||||
|
||||
func TestEncryptDecryptSmall(t *testing.T) {
|
||||
p := big.NewInt(13)
|
||||
q := big.NewInt(11)
|
||||
for i := 1; i < 10; i++ {
|
||||
privateKey := CreatePrivateKey(p, q)
|
||||
|
||||
inicialValue := big.NewInt(100)
|
||||
cypher, err := privateKey.Encrypt(inicialValue, rand.Reader)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
returnedValue := privateKey.Decrypt(cypher)
|
||||
if !reflect.DeepEqual(inicialValue, returnedValue) {
|
||||
t.Error("wrond decryption ", returnedValue, " is not ", inicialValue)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestAddCypher(t *testing.T) {
|
||||
privateKey := CreatePrivateKey(big.NewInt(13), big.NewInt(11))
|
||||
cypher1, _ := privateKey.Encrypt(big.NewInt(12), rand.Reader)
|
||||
cypher2, _ := privateKey.Encrypt(big.NewInt(13), rand.Reader)
|
||||
cypher3 := privateKey.Add(cypher1, cypher2)
|
||||
m := privateKey.Decrypt(cypher3)
|
||||
if !reflect.DeepEqual(m, big.NewInt(25)) {
|
||||
t.Error(m)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user