diff --git a/diffieHellman/dhkx.go b/diffieHellman/dhkx.go index 1dd7b265f0287bf36dc0b436db683897c316bae3..cedba60c0b014627ae65e38c74ddf79c32fef033 100644 --- a/diffieHellman/dhkx.go +++ b/diffieHellman/dhkx.go @@ -7,7 +7,7 @@ import ( // CreateDHKeyPair is a function that receives the generator and prime and // returns a Diffie-Hellman Key pair withing the group -func CreateDHKeyPair(group cyclic.Group) (*cyclic.Int, *cyclic.Int) { +func CreateDHKeyPair(group *cyclic.Group) (*cyclic.Int, *cyclic.Int) { prime := group.GetP(cyclic.NewInt(0)) @@ -30,7 +30,8 @@ func CreateDHKeyPair(group cyclic.Group) (*cyclic.Int, *cyclic.Int) { // NewDHSessionKey takes the prime, the other party's public key and private key // Function returns a valid session Key within the group // v1.0 still does not include the CheckPublicKeyFeature -func CreateDHSessionKey(publicKey *cyclic.Int, privateKey *cyclic.Int, group cyclic.Group) (*cyclic.Int, error) { +func CreateDHSessionKey(publicKey *cyclic.Int, privateKey *cyclic.Int, + group *cyclic.Group) (*cyclic.Int, error) { prime := group.GetP(cyclic.NewInt(0)) @@ -44,7 +45,7 @@ func CreateDHSessionKey(publicKey *cyclic.Int, privateKey *cyclic.Int, group cyc // This function can return false positives, but never false negatives // A valid public key will never trigger a negative response from this function // Legendre Symbol = a^(p-1)/2 mod p -func CheckPublicKey(group cyclic.Group, publicKey *cyclic.Int) bool { +func CheckPublicKey(group *cyclic.Group, publicKey *cyclic.Int) bool { prime := cyclic.NewInt(0) group.GetP(prime) diff --git a/diffieHellman/dhkx_test.go b/diffieHellman/dhkx_test.go index 00ce67d032a2c9000552abdf9adc9e859f941254..fd788dbec67806d9243e3770918cd330860534cb 100644 --- a/diffieHellman/dhkx_test.go +++ b/diffieHellman/dhkx_test.go @@ -31,8 +31,8 @@ func TestDHKX(t *testing.T) { min := cyclic.NewInt(2) max := p rng := cyclic.NewRandom(min, max) - - testGroup := cyclic.NewGroup(p, s, g, rng) + grp := cyclic.NewGroup(p, s, g, rng) + testGroup := &grp // Creation of two different DH Key Pairs with valid parameters privKey, pubKey := CreateDHKeyPair(testGroup) @@ -85,7 +85,8 @@ func TestCreateDHKeyPair(t *testing.T) { max := p rng := cyclic.NewRandom(min, max) - testGroup := cyclic.NewGroup(p, s, g, rng) + grp := cyclic.NewGroup(p, s, g, rng) + testGroup := &grp defer Catch("TestCreateDHKeyPair():", t) CreateDHKeyPair(testGroup) @@ -115,7 +116,8 @@ func TestCheckPublicKey(t *testing.T) { max := p rng := cyclic.NewRandom(min, max) - testGroup := cyclic.NewGroup(p, s, g, rng) + grp := cyclic.NewGroup(p, s, g, rng) + testGroup := &grp // Creation of a DH Key Pair with valid parameters _, pubKey := CreateDHKeyPair(testGroup) @@ -183,7 +185,8 @@ func TestDHNodeKeys(t *testing.T) { max := p rng := cyclic.NewRandom(min, max) - testGroup := cyclic.NewGroup(p, s, g, rng) + grp := cyclic.NewGroup(p, s, g, rng) + testGroup := &grp // This is a map key(string) -> value (hex string) // To convert the contents to byte, one should do: res, _ := hex.DecodeString(nodeDHKeys["key"])