diff --git a/storage/e2e/key.go b/storage/e2e/key.go index ed40e54e5d11e39a8e1ec2e2b41befca1a9b97d3..616952167a9bfc73183d8411ac2503900c765dea 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 c548b8c78b496dc2981269c9c4a1a33fe0977d6e..8ab67500dc5c70517d76e67eef2a525bae6dec38 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{