Skip to content
Snippets Groups Projects
Commit 7b2e4024 authored by Jake Taylor's avatar Jake Taylor :lips:
Browse files

Updated to take pointers to groups for diffie hellman

parent dc406211
No related branches found
No related tags found
No related merge requests found
......@@ -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)
......
......@@ -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"])
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment