subtle
packagestandard libraryThis package is not in the latest version of its module.
Details
Validgo.mod file
The Go module system was introduced in Go 1.11 and is the official dependency management solution for Go.
Redistributable license
Redistributable licenses place minimal restrictions on how software can be used, modified, and redistributed.
Tagged version
Modules with tagged versions give importers more predictable builds.
Stable version
When a project reaches major version v1 it is considered stable.
- Learn more about best practices
Repository
Links
Documentation¶
Overview¶
Package subtle implements functions that are often useful in cryptographiccode but require careful thought to use correctly.
Index¶
- func ConstantTimeByteEq(x, y uint8) int
- func ConstantTimeCompare(x, y []byte) int
- func ConstantTimeCopy(v int, x, y []byte)
- func ConstantTimeEq(x, y int32) int
- func ConstantTimeLessOrEq(x, y int) int
- func ConstantTimeSelect(v, x, y int) int
- func WithDataIndependentTiming(f func())
- func XORBytes(dst, x, y []byte) int
Constants¶
This section is empty.
Variables¶
This section is empty.
Functions¶
funcConstantTimeByteEq¶
ConstantTimeByteEq returns 1 if x == y and 0 otherwise.
funcConstantTimeCompare¶
ConstantTimeCompare returns 1 if the two slices, x and y, have equal contentsand 0 otherwise. The time taken is a function of the length of the slices andis independent of the contents. If the lengths of x and y do not match itreturns 0 immediately.
funcConstantTimeCopy¶
ConstantTimeCopy copies the contents of y into x (a slice of equal length)if v == 1. If v == 0, x is left unchanged. Its behavior is undefined if vtakes any other value.
funcConstantTimeEq¶
ConstantTimeEq returns 1 if x == y and 0 otherwise.
funcConstantTimeLessOrEq¶added ingo1.2
ConstantTimeLessOrEq returns 1 if x <= y and 0 otherwise.Its behavior is undefined if x or y are negative or > 2**31 - 1.
funcConstantTimeSelect¶
ConstantTimeSelect returns x if v == 1 and y if v == 0.Its behavior is undefined if v takes any other value.
funcWithDataIndependentTiming¶added ingo1.24.0
func WithDataIndependentTiming(f func())
WithDataIndependentTiming enables architecture specific features which ensurethat the timing of specific instructions is independent of their inputsbefore executing f. On f returning it disables these features.
WithDataIndependentTiming should only be used when f is written to make useof constant-time operations. WithDataIndependentTiming does not makevariable-time code constant-time.
WithDataIndependentTiming may lock the current goroutine to the OS thread forthe duration of f. Calls to WithDataIndependentTiming may be nested.
On Arm64 processors with FEAT_DIT, WithDataIndependentTiming enablesPSTATE.DIT. Seehttps://developer.arm.com/documentation/ka005181/1-0/?lang=en.
Currently, on all other architectures WithDataIndependentTiming executes f immediatelywith no other side-effects.
funcXORBytes¶added ingo1.20
XORBytes sets dst[i] = x[i] ^ y[i] for all i < n = min(len(x), len(y)),returning n, the number of bytes written to dst.
If dst does not have length at least n,XORBytes panics without writing anything to dst.
dst and x or y may overlap exactly or not at all,otherwise XORBytes may panic.
Types¶
This section is empty.