Is the a built-in way of doing constant time string comparison in Go?
I've used the Devise.secure_compare
method when I've needed this functionality in Ruby.
Not for strings but for []byte
. See crypto/subtle
, especially ConstantTimeCompare
:
func ConstantTimeCompare(x, y []byte) int
ConstantTimeCompare returns 1 iff the two equal length slices, x and y, have equal contents. The time taken is a function of the length of the slices and is independent of the contents.
As you may know, you can easily convert a string to a byte slice:
var x []byte = []byte("someString")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.