From de5b1817c782f0f3459a8b7b257d576e6fc5d22c Mon Sep 17 00:00:00 2001 From: Kyle Date: Fri, 10 Jan 2014 16:27:14 -0700 Subject: [PATCH] SHA256 the ECDH shared key This ensures the shared key is a more uniform distribution than just taking the bytes from the shared X. --- ecdh/ecdh.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ecdh/ecdh.go b/ecdh/ecdh.go index b05d6da..5b2c06c 100644 --- a/ecdh/ecdh.go +++ b/ecdh/ecdh.go @@ -11,6 +11,7 @@ import ( "crypto/hmac" "crypto/rand" "crypto/sha1" + "crypto/sha256" "errors" "github.com/cloudflare/redoctober/padding" "github.com/cloudflare/redoctober/symcrypt" @@ -36,7 +37,7 @@ func Encrypt(pub ecdsa.PublicKey, in []byte) (out []byte, err error) { if x == nil { return nil, errors.New("Failed to generate encryption key") } - shared := x.Bytes() + shared := sha256.Sum256(x.Bytes()) iv, err := symcrypt.MakeRandom(16) if err != nil { return @@ -82,7 +83,7 @@ func Decrypt(priv *ecdsa.PrivateKey, in []byte) (out []byte, err error) { if x == nil { return nil, errors.New("Failed to generate encryption key") } - shared := x.Bytes() + shared := sha256.Sum256(x.Bytes()) tagStart := len(ct) - sha1.Size h := hmac.New(sha1.New, shared[16:])