summaryrefslogtreecommitdiff
path: root/src/pkg/crypto/subtle/constant_time.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/pkg/crypto/subtle/constant_time.go')
-rw-r--r--src/pkg/crypto/subtle/constant_time.go8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/pkg/crypto/subtle/constant_time.go b/src/pkg/crypto/subtle/constant_time.go
index 57dbe9db5..dfb658465 100644
--- a/src/pkg/crypto/subtle/constant_time.go
+++ b/src/pkg/crypto/subtle/constant_time.go
@@ -55,3 +55,11 @@ func ConstantTimeCopy(v int, x, y []byte) {
}
return
}
+
+// ConstantTimeLessOrEq returns 1 if x <= y and 0 otherwise.
+// Its behavior is undefined if x or y are negative or > 2**31 - 1.
+func ConstantTimeLessOrEq(x, y int) int {
+ x32 := int32(x)
+ y32 := int32(y)
+ return int(((x32 - y32 - 1) >> 31) & 1)
+}