summaryrefslogtreecommitdiffhomepage
path: root/device
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2021-01-29 20:10:48 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2021-01-29 20:10:48 +0100
commita9f80d8c587df99c6e8f57704aef3fe1ac62d0db (patch)
tree2a42bbe99b26df0c54f3ef84ac369a0b246d7fed /device
parentde51129e33a5fe4fad3da172539e9be640d39211 (diff)
device: reduce number of append calls when padding
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'device')
-rw-r--r--device/send.go7
1 files changed, 2 insertions, 5 deletions
diff --git a/device/send.go b/device/send.go
index 5261c2f..9d63c4e 100644
--- a/device/send.go
+++ b/device/send.go
@@ -367,7 +367,7 @@ func calculatePaddingSize(packetSize, mtu int) int {
* Obs. One instance per core
*/
func (device *Device) RoutineEncryption() {
-
+ var paddingZeros [PaddingMultiple]byte
var nonce [chacha20poly1305.NonceSize]byte
defer device.log.Verbosef("Routine: encryption worker - stopped")
@@ -386,11 +386,8 @@ func (device *Device) RoutineEncryption() {
binary.LittleEndian.PutUint64(fieldNonce, elem.nonce)
// pad content to multiple of 16
-
paddingSize := calculatePaddingSize(len(elem.packet), int(atomic.LoadInt32(&device.tun.mtu)))
- for i := 0; i < paddingSize; i++ {
- elem.packet = append(elem.packet, 0)
- }
+ elem.packet = append(elem.packet, paddingZeros[:paddingSize]...)
// encrypt content and release to consumer