Skip to content
Snippets Groups Projects
Commit 8bdf1ec0 authored by Richard T. Carback III's avatar Richard T. Carback III
Browse files

Modify sent request to store the sidh key variant

parent 5c65bbb5
No related branches found
No related tags found
2 merge requests!117Release,!73Quantum secure xx messenger key negotiation
...@@ -9,7 +9,7 @@ package auth ...@@ -9,7 +9,7 @@ package auth
import ( import (
"github.com/cloudflare/circl/dh/sidh" "github.com/cloudflare/circl/dh/sidh"
sidhinterface "gitlab.com/elixxir/client/interfaces/sidh" util "gitlab.com/elixxir/client/storage/utility"
"github.com/pkg/errors" "github.com/pkg/errors"
jww "github.com/spf13/jwalterweatherman" jww "github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/crypto/cyclic" "gitlab.com/elixxir/crypto/cyclic"
...@@ -22,16 +22,17 @@ const saltSize = 32 ...@@ -22,16 +22,17 @@ const saltSize = 32
type baseFormat struct { type baseFormat struct {
data []byte data []byte
pubkey []byte pubkey []byte
sidHpubkey []byte sidHpubkey []byte
salt []byte salt []byte
ecrPayload []byte ecrPayload []byte
} }
func newBaseFormat(payloadSize, pubkeySize, sidHPubkeySize int ) baseFormat { func newBaseFormat(payloadSize, pubkeySize, sidHPubkeySize int ) baseFormat {
total := pubkeySize + sidHPubkeySize + saltSize // NOTE: sidhPubKey needs an extra byte to hold the variant setting
total := pubkeySize + sidHPubkeySize + 1 + saltSize
if payloadSize < total { if payloadSize < total {
jww.FATAL.Panicf("Size of baseFormat is too small (%d), must be big " + jww.FATAL.Panicf("Size of baseFormat is too small (%d), must be big " +
"enough to contain public key (%d) sidHPublicKey (%d) and salt (%d) " + "enough to contain public key (%d) sidHPublicKey (%d + 1) and salt (%d) " +
"which totals to %d", payloadSize, pubkeySize, sidHPubkeySize, saltSize, "which totals to %d", payloadSize, pubkeySize, sidHPubkeySize, saltSize,
total) total)
} }
...@@ -48,7 +49,7 @@ func buildBaseFormat(data []byte, pubkeySize, sidHPubkeySize int) baseFormat { ...@@ -48,7 +49,7 @@ func buildBaseFormat(data []byte, pubkeySize, sidHPubkeySize int) baseFormat {
} }
f.pubkey = f.data[:pubkeySize] f.pubkey = f.data[:pubkeySize]
f.sidHpubkey = f.data[pubkeySize: pubkeySize + sidHPubkeySize] f.sidHpubkey = f.data[pubkeySize: pubkeySize + sidHPubkeySize + 1]
f.salt = f.data[pubkeySize + sidHPubkeySize: pubkeySize+sidHPubkeySize+saltSize] f.salt = f.data[pubkeySize + sidHPubkeySize: pubkeySize+sidHPubkeySize+saltSize]
f.ecrPayload = f.data[pubkeySize+sidHPubkeySize+saltSize:] f.ecrPayload = f.data[pubkeySize+sidHPubkeySize+saltSize:]
return f return f
...@@ -76,13 +77,14 @@ func (f baseFormat) SetPubKey(pubKey *cyclic.Int) { ...@@ -76,13 +77,14 @@ func (f baseFormat) SetPubKey(pubKey *cyclic.Int) {
} }
func (f baseFormat) SetSidHPubKey(pubKey *sidh.PublicKey) { func (f baseFormat) SetSidHPubKey(pubKey *sidh.PublicKey) {
pubKey.Export(f.sidHpubkey) f.sidHpubkey[0] = byte(pubKey.Variant())
pubKey.Export(f.sidHpubkey[1:])
} }
func (f baseFormat) GetSidhPubKey() (*sidh.PublicKey, error) { func (f baseFormat) GetSidhPubKey() (*sidh.PublicKey, error) {
pubKey := sidh.NewPublicKey(sidhinterface.KeyId, variant := sidh.KeyVariant(f.sidHpubkey[0])
sidh.KeyVariantSidhA) pubKey := util.NewSIDHPublicKey(variant)
err := pubKey.Import(f.sidHpubkey) err := pubKey.Import(f.sidHpubkey[1:])
return pubKey, err return pubKey, err
} }
......
...@@ -20,7 +20,7 @@ import ( ...@@ -20,7 +20,7 @@ import (
func TestNewBaseFormat(t *testing.T) { func TestNewBaseFormat(t *testing.T) {
// Construct message // Construct message
pubKeySize := 256 pubKeySize := 256
payloadSize := saltSize + pubKeySize + sidhinterface.PubKeyByteSize payloadSize := saltSize + pubKeySize + sidhinterface.PubKeyByteSize + 1
baseMsg := newBaseFormat(payloadSize, pubKeySize, baseMsg := newBaseFormat(payloadSize, pubKeySize,
sidhinterface.PubKeyByteSize) sidhinterface.PubKeyByteSize)
...@@ -65,7 +65,7 @@ func TestNewBaseFormat(t *testing.T) { ...@@ -65,7 +65,7 @@ func TestNewBaseFormat(t *testing.T) {
func TestBaseFormat_SetGetPubKey(t *testing.T) { func TestBaseFormat_SetGetPubKey(t *testing.T) {
// Construct message // Construct message
pubKeySize := 256 pubKeySize := 256
payloadSize := saltSize + pubKeySize + sidhinterface.PubKeyByteSize payloadSize := saltSize + pubKeySize + sidhinterface.PubKeyByteSize + 1
baseMsg := newBaseFormat(payloadSize, pubKeySize, baseMsg := newBaseFormat(payloadSize, pubKeySize,
sidhinterface.PubKeyByteSize) sidhinterface.PubKeyByteSize)
...@@ -94,7 +94,7 @@ func TestBaseFormat_SetGetPubKey(t *testing.T) { ...@@ -94,7 +94,7 @@ func TestBaseFormat_SetGetPubKey(t *testing.T) {
func TestBaseFormat_SetGetSalt(t *testing.T) { func TestBaseFormat_SetGetSalt(t *testing.T) {
// Construct message // Construct message
pubKeySize := 256 pubKeySize := 256
payloadSize := saltSize + pubKeySize + sidhinterface.PubKeyByteSize payloadSize := saltSize + pubKeySize + sidhinterface.PubKeyByteSize + 1
baseMsg := newBaseFormat(payloadSize, pubKeySize, baseMsg := newBaseFormat(payloadSize, pubKeySize,
sidhinterface.PubKeyByteSize) sidhinterface.PubKeyByteSize)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment