Skip to content

Commit

Permalink
MAC is computed for encrypted key also.
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiocolacio committed Dec 10, 2018
1 parent 251805d commit c350888
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions crypto/eecdh.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@ func EncryptMessage(clearText, aesKey, nxt []byte, sid, rid int) (msg *Encrypted

// Generate MAC tag for data
mac := hmac.New(secureHash, hmacKey)
mac.Write(cipherText)
tmp := make([]byte, 0, len(cipherText) + len(encryptedNxt))
tmp = append(tmp, cipherText...)
tmp = append(tmp, encryptedNxt...)
mac.Write(tmp)
tag := mac.Sum(nil)

msg = &EncryptedMessage{
Expand Down Expand Up @@ -133,7 +136,10 @@ func (message *EncryptedMessage) Decrypt(aesKey []byte) (clearText, nextKey []by
cbc.CryptBlocks(message.Key, message.Key)

// Compare MAC tags
if !CheckMAC(message.Msg, message.Tag, message.Key) {
tmp := make([]byte, 0, len(message.Msg) + len(message.Nxt))
tmp = append(tmp, message.Msg...)
tmp = append(tmp, message.Nxt...)
if !CheckMAC(tmp, message.Tag, message.Key) {
err = ErrUnexpectedMAC
return
}
Expand Down

0 comments on commit c350888

Please sign in to comment.