1
0
Fork 0
forked from External/grumble

pkg/cryptstate: add Overhead(); use it internally.

This commit is contained in:
Mikkel Krautz 2012-12-08 23:39:19 +01:00
parent 56b174d983
commit eacf839182

View file

@ -97,12 +97,18 @@ func (cs *CryptState) SetKey(key []byte, eiv []byte, div []byte) error {
return nil
}
// Overhead returns the length, in bytes, that a ciphertext
// is longer than a plaintext.
func (cs *CryptState) Overhead() int {
return 1 + cs.mode.Overhead()
}
func (cs *CryptState) Decrypt(dst, src []byte) error {
if len(src) < 4 {
if len(src) < cs.Overhead() {
return errors.New("cryptstate: crypted length too short to decrypt")
}
plain_len := len(src) - 4
plain_len := len(src) - cs.Overhead()
if len(dst) != plain_len {
return errors.New("cryptstate: plain_len and src len mismatch")
}