diff options
author | Felix Lange <fjl@twurst.com> | 2016-02-10 03:05:49 +0800 |
---|---|---|
committer | Felix Lange <fjl@twurst.com> | 2016-02-12 16:49:18 +0800 |
commit | fdb936ee95d09b1b98418735a813deba6770ad5a (patch) | |
tree | a53f1293b6cd4a87607d1dc8887cad0f6ee0aca7 /crypto/ecies/ecies_test.go | |
parent | b05e472c076d30035233d6a8b5fb3360b236e3ff (diff) | |
download | dexon-fdb936ee95d09b1b98418735a813deba6770ad5a.tar.gz dexon-fdb936ee95d09b1b98418735a813deba6770ad5a.tar.zst dexon-fdb936ee95d09b1b98418735a813deba6770ad5a.zip |
crypto/ecies: make authenticated shared data work
The s2 parameter was not actually written to the MAC.
Diffstat (limited to 'crypto/ecies/ecies_test.go')
-rw-r--r-- | crypto/ecies/ecies_test.go | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/crypto/ecies/ecies_test.go b/crypto/ecies/ecies_test.go index 6a0ea3f02..cb09061ce 100644 --- a/crypto/ecies/ecies_test.go +++ b/crypto/ecies/ecies_test.go @@ -408,6 +408,36 @@ func TestEncryptDecrypt(t *testing.T) { } } +func TestDecryptShared2(t *testing.T) { + prv, err := GenerateKey(rand.Reader, DefaultCurve, nil) + if err != nil { + t.Fatal(err) + } + message := []byte("Hello, world.") + shared2 := []byte("shared data 2") + ct, err := Encrypt(rand.Reader, &prv.PublicKey, message, nil, shared2) + if err != nil { + t.Fatal(err) + } + + // Check that decrypting with correct shared data works. + pt, err := prv.Decrypt(rand.Reader, ct, nil, shared2) + if err != nil { + t.Fatal(err) + } + if !bytes.Equal(pt, message) { + t.Fatal("ecies: plaintext doesn't match message") + } + + // Decrypting without shared data or incorrect shared data fails. + if _, err = prv.Decrypt(rand.Reader, ct, nil, nil); err == nil { + t.Fatal("ecies: decrypting without shared data didn't fail") + } + if _, err = prv.Decrypt(rand.Reader, ct, nil, []byte("garbage")); err == nil { + t.Fatal("ecies: decrypting with incorrect shared data didn't fail") + } +} + // TestMarshalEncryption validates the encode/decode produces a valid // ECIES encryption key. func TestMarshalEncryption(t *testing.T) { |