From: Dan Kortschak Date: Mon, 3 May 2021 03:47:04 +0000 (+0930) Subject: crypto/subtle: note that input length mismatch makes ConstantTimeCompare return immed... X-Git-Tag: go1.19beta1~765 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=07b0c57a75d4b8c94b16983c5a78026ba46377ac;p=gostls13.git crypto/subtle: note that input length mismatch makes ConstantTimeCompare return immediately Change-Id: Id1ae6c8fbb8c2f31b251ba141dc2bbedae189006 Reviewed-on: https://go-review.googlesource.com/c/go/+/316169 Trust: Daniel Martí Reviewed-by: Daniel Martí Trust: Johan Brandhorst-Satzkorn --- diff --git a/src/crypto/subtle/constant_time.go b/src/crypto/subtle/constant_time.go index 7c3cf05c46..4e0527f9d5 100644 --- a/src/crypto/subtle/constant_time.go +++ b/src/crypto/subtle/constant_time.go @@ -8,7 +8,8 @@ package subtle // ConstantTimeCompare returns 1 if the two slices, x and y, have equal contents // and 0 otherwise. The time taken is a function of the length of the slices and -// is independent of the contents. +// is independent of the contents. If the lengths of x and y do not match it +// returns 0 immediately. func ConstantTimeCompare(x, y []byte) int { if len(x) != len(y) { return 0