mirror of
https://github.com/mumble-voip/grumble.git
synced 2025-12-19 21:59:59 -08:00
pkg/cryptstate: add Overhead(); use it internally.
This commit is contained in:
parent
56b174d983
commit
eacf839182
1 changed files with 8 additions and 2 deletions
|
|
@ -97,12 +97,18 @@ func (cs *CryptState) SetKey(key []byte, eiv []byte, div []byte) error {
|
||||||
return nil
|
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 {
|
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")
|
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 {
|
if len(dst) != plain_len {
|
||||||
return errors.New("cryptstate: plain_len and src len mismatch")
|
return errors.New("cryptstate: plain_len and src len mismatch")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue