Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
crypto
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
elixxir
crypto
Commits
7b2e4024
Commit
7b2e4024
authored
May 16, 2018
by
Jake Taylor
Browse files
Options
Downloads
Patches
Plain Diff
Updated to take pointers to groups for diffie hellman
parent
dc406211
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
diffieHellman/dhkx.go
+4
-3
4 additions, 3 deletions
diffieHellman/dhkx.go
diffieHellman/dhkx_test.go
+8
-5
8 additions, 5 deletions
diffieHellman/dhkx_test.go
with
12 additions
and
8 deletions
diffieHellman/dhkx.go
+
4
−
3
View file @
7b2e4024
...
...
@@ -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
)
...
...
This diff is collapsed.
Click to expand it.
diffieHellman/dhkx_test.go
+
8
−
5
View file @
7b2e4024
...
...
@@ -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"])
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment