From fa6aa4d9e7eb48ef4b91009f4638168371da4f37 Mon Sep 17 00:00:00 2001 From: "Richard T. Carback III" <rick.carback@gmail.com> Date: Thu, 2 Dec 2021 03:37:26 +0000 Subject: [PATCH] Add GenerateE2ESessionBaseKey function --- storage/e2e/key.go | 1 - storage/e2e/key_test.go | 57 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/storage/e2e/key.go b/storage/e2e/key.go index ed40e54e5..616952167 100644 --- a/storage/e2e/key.go +++ b/storage/e2e/key.go @@ -15,7 +15,6 @@ import ( "github.com/cloudflare/circl/dh/sidh" "gitlab.com/elixxir/crypto/cyclic" dh "gitlab.com/elixxir/crypto/diffieHellman" - jww "github.com/spf13/jwalterweatherman" ) // GenerateE2ESessionBaseKey returns the baseKey symmetric encryption key root. diff --git a/storage/e2e/key_test.go b/storage/e2e/key_test.go index c548b8c78..8ab67500d 100644 --- a/storage/e2e/key_test.go +++ b/storage/e2e/key_test.go @@ -22,8 +22,51 @@ import ( "math/rand" "reflect" "testing" + "gitlab.com/elixxir/crypto/fastRNG" + "github.com/cloudflare/circl/dh/sidh" ) + +// TestGenerateE2ESessionBaseKey smoke tests the GenerateE2ESessionBaseKey +// function to ensure that it produces the correct key on both sides of the +// connection. +func TestGenerateE2ESessionBaseKey(t *testing.T) { + rng := fastRNG.NewStreamGenerator(1, 3, csprng.NewSystemRNG) + myRng := rng.GetStream() + + // DH Keys + grp := getGroup() + dhPrivateKeyA := dh.GeneratePrivateKey(dh.DefaultPrivateKeyLength, grp, + myRng) + dhPublicKeyA := dh.GeneratePublicKey(dhPrivateKeyA, grp) + dhPrivateKeyB := dh.GeneratePrivateKey(dh.DefaultPrivateKeyLength, grp, + myRng) + dhPublicKeyB := dh.GeneratePublicKey(dhPrivateKeyB, grp) + + // SIDH keys + pubA := sidh.NewPublicKey(sidh.Fp434, sidh.KeyVariantSidhA) + privA := sidh.NewPrivateKey(sidh.Fp434, sidh.KeyVariantSidhA) + privA.Generate(myRng) + privA.GeneratePublicKey(pubA) + pubB := sidh.NewPublicKey(sidh.Fp434, sidh.KeyVariantSidhB) + privB := sidh.NewPrivateKey(sidh.Fp434, sidh.KeyVariantSidhB) + privB.Generate(myRng) + privB.GeneratePublicKey(pubB) + + myRng.Close() + + baseKey1 := GenerateE2ESessionBaseKey(dhPrivateKeyA, dhPublicKeyB, + grp, privA, pubB) + baseKey2 := GenerateE2ESessionBaseKey(dhPrivateKeyB, dhPublicKeyA, + grp, privB, pubA) + + if !reflect.DeepEqual(baseKey1, baseKey2) { + t.Errorf("Cannot produce the same session key:\n%v\n%v", + baseKey1, baseKey2) + } + +} + // Happy path of newKey(). func Test_newKey(t *testing.T) { expectedKey := &Key{ @@ -190,7 +233,19 @@ func getSession(t *testing.T) *Session { // generate the baseKey and session privateKey := dh.GeneratePrivateKey(dh.DefaultPrivateKeyLength, grp, rng) publicKey := dh.GeneratePublicKey(privateKey, grp) - baseKey := dh.GenerateSessionKey(privateKey, publicKey, grp) + + // SIDH keys + pubA := sidh.NewPublicKey(sidh.Fp434, sidh.KeyVariantSidhA) + privA := sidh.NewPrivateKey(sidh.Fp434, sidh.KeyVariantSidhA) + privA.Generate(rng) + privA.GeneratePublicKey(pubA) + pubB := sidh.NewPublicKey(sidh.Fp434, sidh.KeyVariantSidhB) + privB := sidh.NewPrivateKey(sidh.Fp434, sidh.KeyVariantSidhB) + privB.Generate(rng) + privB.GeneratePublicKey(pubB) + + baseKey := GenerateE2ESessionBaseKey(privateKey, publicKey, grp, privA, + pubB) fps := newFingerprints() ctx := &context{ -- GitLab