Standard library / crypto/subtle

crypto/subtle.ConstantTimeSelect()

Select x if v is 1, otherwise y if v is 0. Other selector values are undefined. Expected stdout: '7 9\n'.

Formal Syntax & Structure

go syntaxgo
func ConstantTimeSelect(v, x, y int) int

Parameters & Attributes

NameTypeDescription
vintSelector, exactly 0 or 1.
xintValue selected for 1.
yintValue selected for 0.

Return Value

int

Selected value.

Working Example

Example Snippetgo
package main
import (  "crypto/subtle"  "fmt")
func main() { fmt.Println(subtle.ConstantTimeSelect(1, 7, 9), subtle.ConstantTimeSelect(0, 7, 9)) }
Go Reference