1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4 5 // Package subtle implements functions that are often useful in cryptographic
6 // code but require careful thought to use correctly.
7 package subtle
8 9 import "crypto/internal/fips140/subtle"
10 11 // ConstantTimeCompare returns 1 if the two slices, x and y, have equal contents
12 // and 0 otherwise. The time taken is a function of the length of the slices and
13 // is independent of the contents. If the lengths of x and y do not match it
14 // returns 0 immediately.
15 func ConstantTimeCompare(x, y []byte) int {
16 return subtle.ConstantTimeCompare(x, y)
17 }
18 19 // ConstantTimeSelect returns x if v == 1 and y if v == 0.
20 // Its behavior is undefined if v takes any other value.
21 func ConstantTimeSelect(v, x, y int) int {
22 return subtle.ConstantTimeSelect(v, x, y)
23 }
24 25 // ConstantTimeByteEq returns 1 if x == y and 0 otherwise.
26 func ConstantTimeByteEq(x, y uint8) int {
27 return subtle.ConstantTimeByteEq(x, y)
28 }
29 30 // ConstantTimeEq returns 1 if x == y and 0 otherwise.
31 func ConstantTimeEq(x, y int32) int {
32 return subtle.ConstantTimeEq(x, y)
33 }
34 35 // ConstantTimeCopy copies the contents of y into x (a slice of equal length)
36 // if v == 1. If v == 0, x is left unchanged. Its behavior is undefined if v
37 // takes any other value.
38 func ConstantTimeCopy(v int, x, y []byte) {
39 subtle.ConstantTimeCopy(v, x, y)
40 }
41 42 // ConstantTimeLessOrEq returns 1 if x <= y and 0 otherwise.
43 // Its behavior is undefined if x or y are negative or > 2**31 - 1.
44 func ConstantTimeLessOrEq(x, y int) int {
45 return subtle.ConstantTimeLessOrEq(x, y)
46 }
47