Golang crypto/subtle.ConstantTimeLessOrEq() function example

package crypto/subtle

ConstantTimeLessOrEq returns 1 if x <= y and 0 otherwise. Its behavior is undefined if x(1st param) or y(2nd param) are negative or > 2**31 - 1.

Golang crypto/subtle.ConstantTimeLessOrEq() function usage example

 package main

 import (
 "fmt"
 "crypto/subtle"
 )

 func main() {
 x := 3
 y := 4
 z := 1

 n := subtle.ConstantTimeLessOrEq(x,y)
 fmt.Printf("n : %d \n", n) // returns 1


 nn := subtle.ConstantTimeLessOrEq(x,z)
 fmt.Printf("nn : %d \n", nn) // returns 0

 }

Output :

n : 1

nn : 0

Reference :

http://golang.org/pkg/crypto/subtle/#ConstantTimeLessOrEq

Advertisement