Golang crypto/subtle.ConstantTimeByteEq() function example

package crypto/subtle

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

Golang crypto/subtle.ConstantTimeByteEq() function usage example

 package main

 import (
 "crypto/subtle"
 "fmt"
 )

 func main() {
  X := uint8(1)
  Y := uint8(2)

  n := subtle.ConstantTimeByteEq(X,Y) // X != Y, n = 0
  fmt.Printf("n : %d\n", n)

  X = X + 1

  nn := subtle.ConstantTimeByteEq(X,Y) // X == Y, nn = 1

  fmt.Printf("nn : %d\n", nn)
 }

Output :

n : 0

nn : 1

Reference :

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

Advertisement