From abf359a5a41b832fcacf5380cbf1a2ec2a762112 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Fri, 9 Feb 2024 15:17:00 +0700 Subject: [PATCH] handshake: embed the mask as an array into the aesHeaderProtector --- internal/handshake/header_protector.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/internal/handshake/header_protector.go b/internal/handshake/header_protector.go index 455f2507010..2c5ee42f12d 100644 --- a/internal/handshake/header_protector.go +++ b/internal/handshake/header_protector.go @@ -37,7 +37,7 @@ func newHeaderProtector(suite *cipherSuite, trafficSecret []byte, isLongHeader b } type aesHeaderProtector struct { - mask []byte + mask [16]byte // AES always has a 16 byte block size block cipher.Block isLongHeader bool } @@ -52,7 +52,6 @@ func newAESHeaderProtector(suite *cipherSuite, trafficSecret []byte, isLongHeade } return &aesHeaderProtector{ block: block, - mask: make([]byte, block.BlockSize()), isLongHeader: isLongHeader, } } @@ -69,7 +68,7 @@ func (p *aesHeaderProtector) apply(sample []byte, firstByte *byte, hdrBytes []by if len(sample) != len(p.mask) { panic("invalid sample size") } - p.block.Encrypt(p.mask, sample) + p.block.Encrypt(p.mask[:], sample) if p.isLongHeader { *firstByte ^= p.mask[0] & 0xf } else {