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")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With