Be defensive about short ciphertexts

This commit is contained in:
Jonathan Rudenberg 2014-07-21 23:20:44 -07:00
parent 23f8d99470
commit 36a0b41364
1 changed files with 3 additions and 0 deletions

View File

@ -291,6 +291,9 @@ func (n *noise255ctx) Encrypt(dst, plaintext, authtext []byte) []byte {
var ErrAuthFailed = errors.New("box: message authentication failed")
func (n *noise255ctx) Decrypt(ciphertext, authtext []byte) ([]byte, error) {
if len(ciphertext) < 16 {
return nil, ErrAuthFailed
}
digest := ciphertext[len(ciphertext)-16:]
ciphertext = ciphertext[:len(ciphertext)-16]
c, keystream := n.key()