From e68546eec5d3303afc32f16bc2a9d79f83ddac47 Mon Sep 17 00:00:00 2001 From: "Brandon McGinty (chatgpt)" Date: Mon, 10 Aug 2026 09:42:49 -0400 Subject: [PATCH] Compare UDP authentication tags in constant time --- gumble/gumble/crypt.go | 7 +++---- gumble/gumble/udp15.go | 3 ++- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/gumble/gumble/crypt.go b/gumble/gumble/crypt.go index 4abedc5..152292e 100644 --- a/gumble/gumble/crypt.go +++ b/gumble/gumble/crypt.go @@ -3,6 +3,7 @@ package gumble import ( "crypto/aes" "crypto/cipher" + "crypto/subtle" "encoding/binary" "errors" "sync" @@ -201,10 +202,8 @@ func ocbCrypt(block cipher.Block, nonce, data, ad []byte, encrypt bool) ([]byte, out = append(out, offset[:tagLen]...) } else { tag := data[len(data)-tagLen:] - for j := 0; j < tagLen; j++ { - if tag[j] != offset[j] { - return nil, errors.New("gumble: OCB authentication failed") - } + if subtle.ConstantTimeCompare(tag, offset[:tagLen]) != 1 { + return nil, errors.New("gumble: OCB authentication failed") } } return out, nil diff --git a/gumble/gumble/udp15.go b/gumble/gumble/udp15.go index 9a53dd0..aa484b1 100644 --- a/gumble/gumble/udp15.go +++ b/gumble/gumble/udp15.go @@ -3,6 +3,7 @@ package gumble import ( "bytes" "crypto/aes" + "crypto/subtle" "encoding/binary" "errors" "math" @@ -314,7 +315,7 @@ func (cs *cryptState15) decrypt15(packet []byte) ([]byte, error) { } // Verify first 3 bytes of tag. - if tag[0] != expectedTag[0] || tag[1] != expectedTag[1] || tag[2] != expectedTag[2] { + if subtle.ConstantTimeCompare(tag[:3], expectedTag) != 1 { cs.decryptIV = savedIV return nil, errors.New("gumble: OCB authentication failed") }