Skip to content

Commit ef82ecd

Browse files
committed
crypto/subtle: normalize constant time ops docs
ConstantTimeCompare is fairly useless if you can't rely on it being zero when the slices are different, but thankfully it has that property thanks to the final ConstantTimeByteEq. Change-Id: Id51100ed7d8237abbbb15778a259065b162a48ad Reviewed-on: https://go-review.googlesource.com/c/158643 Reviewed-by: Brad Fitzpatrick <[email protected]> Reviewed-by: Adam Langley <[email protected]>
1 parent 8d2e65d commit ef82ecd

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/crypto/subtle/constant_time.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
// code but require careful thought to use correctly.
77
package subtle
88

9-
// ConstantTimeCompare returns 1 if and only if the two slices, x
10-
// and y, have equal contents. The time taken is a function of the length of
11-
// the slices and is independent of the contents.
9+
// ConstantTimeCompare returns 1 if the two slices, x and y, have equal contents
10+
// and 0 otherwise. The time taken is a function of the length of the slices and
11+
// is independent of the contents.
1212
func ConstantTimeCompare(x, y []byte) int {
1313
if len(x) != len(y) {
1414
return 0
@@ -23,7 +23,7 @@ func ConstantTimeCompare(x, y []byte) int {
2323
return ConstantTimeByteEq(v, 0)
2424
}
2525

26-
// ConstantTimeSelect returns x if v is 1 and y if v is 0.
26+
// ConstantTimeSelect returns x if v == 1 and y if v == 0.
2727
// Its behavior is undefined if v takes any other value.
2828
func ConstantTimeSelect(v, x, y int) int { return ^(v-1)&x | (v-1)&y }
2929

0 commit comments

Comments
 (0)