send: more precise padding calculation
This commit is contained in:
parent
47d1140361
commit
942abf948a
10
send.go
10
send.go
|
@ -488,11 +488,13 @@ func (device *Device) RoutineEncryption() {
|
||||||
// pad content to multiple of 16
|
// pad content to multiple of 16
|
||||||
|
|
||||||
mtu := int(atomic.LoadInt32(&device.tun.mtu))
|
mtu := int(atomic.LoadInt32(&device.tun.mtu))
|
||||||
rem := len(elem.packet) % PaddingMultiple
|
lastUnit := len(elem.packet) % mtu
|
||||||
if rem > 0 {
|
paddedSize := (lastUnit + PaddingMultiple - 1) & ^(PaddingMultiple - 1)
|
||||||
for i := 0; i < PaddingMultiple-rem && len(elem.packet) < mtu; i++ {
|
if paddedSize > mtu {
|
||||||
elem.packet = append(elem.packet, 0)
|
paddedSize = mtu
|
||||||
}
|
}
|
||||||
|
for i := len(elem.packet); i < paddedSize; i++ {
|
||||||
|
elem.packet = append(elem.packet, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// encrypt content and release to consumer
|
// encrypt content and release to consumer
|
||||||
|
|
Loading…
Reference in a new issue