Golang crypto/subtle.ConstantTimeEq() function example

package crypto/subtle

ConstantTimeEq returns 1 if x == y and 0 otherwise.

Golang crypto/subtle.ConstantTimeEq() function usage example

 package main

 import (
 "fmt"
 "crypto/subtle"
 )

 func main() {
 x := int32(1)
 y := int32(2)
 z := int32(1)

 n := subtle.ConstantTimeEq(x,y)
 fmt.Printf("n : %d \n", n)


 nn := subtle.ConstantTimeEq(x,z)
 fmt.Printf("nn : %d \n", nn)

 }

Output :

n : 0

nn : 1

Reference :

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

Advertisement