Sha256: 45898ef0e205c50a6cd02ad2fba345339683d0658da005038a5548780646befb

Contents?: true

Size: 702 Bytes

Versions: 16

Compression:

Stored size: 702 Bytes

Contents

package crypto

import "fmt"

// ConstantTimeByteCompare is a constant-time byte comparison of x and y. This function performs an absolute comparison
// if the two byte slices assuming they represent a big-endian number.
//
//		 error if len(x) != len(y)
//	  -1 if x <  y
//	   0 if x == y
//	  +1 if x >  y
func ConstantTimeByteCompare(x, y []byte) (int, error) {
	if len(x) != len(y) {
		return 0, fmt.Errorf("slice lengths do not match")
	}

	xLarger, yLarger := 0, 0

	for i := 0; i < len(x); i++ {
		xByte, yByte := int(x[i]), int(y[i])

		x := ((yByte - xByte) >> 8) & 1
		y := ((xByte - yByte) >> 8) & 1

		xLarger |= x &^ yLarger
		yLarger |= y &^ xLarger
	}

	return xLarger - yLarger, nil
}

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
ruby_snowflake_client-1.3.7 ext/vendor/github.com/aws/aws-sdk-go-v2/internal/v4a/internal/crypto/compare.go
ruby_snowflake_client-1.3.6 ext/vendor/github.com/aws/aws-sdk-go-v2/internal/v4a/internal/crypto/compare.go
ruby_snowflake_client-1.3.5 ext/vendor/github.com/aws/aws-sdk-go-v2/internal/v4a/internal/crypto/compare.go
ruby_snowflake_client-1.3.4 ext/vendor/github.com/aws/aws-sdk-go-v2/internal/v4a/internal/crypto/compare.go
ruby_snowflake_client-1.3.4.pre.debug ext/vendor/github.com/aws/aws-sdk-go-v2/internal/v4a/internal/crypto/compare.go
ruby_snowflake_client-1.3.3.pre.debug ext/vendor/github.com/aws/aws-sdk-go-v2/internal/v4a/internal/crypto/compare.go
ruby_snowflake_client-1.3.2 ext/vendor/github.com/aws/aws-sdk-go-v2/internal/v4a/internal/crypto/compare.go
ruby_snowflake_client-1.3.1 ext/vendor/github.com/aws/aws-sdk-go-v2/internal/v4a/internal/crypto/compare.go
ruby_snowflake_client-1.3.0 ext/vendor/github.com/aws/aws-sdk-go-v2/internal/v4a/internal/crypto/compare.go
ruby_snowflake_client-1.2.1 ext/vendor/github.com/aws/aws-sdk-go-v2/internal/v4a/internal/crypto/compare.go
ruby_snowflake_client-1.2.0 ext/vendor/github.com/aws/aws-sdk-go-v2/internal/v4a/internal/crypto/compare.go
ruby_snowflake_client-1.1.1 ext/vendor/github.com/aws/aws-sdk-go-v2/internal/v4a/internal/crypto/compare.go
ruby_snowflake_client-1.1.0 ext/vendor/github.com/aws/aws-sdk-go-v2/internal/v4a/internal/crypto/compare.go
ruby_snowflake_client-1.0.2 ext/vendor/github.com/aws/aws-sdk-go-v2/internal/v4a/internal/crypto/compare.go
ruby_snowflake_client-1.0.1 ext/vendor/github.com/aws/aws-sdk-go-v2/internal/v4a/internal/crypto/compare.go
ruby_snowflake_client-1.0.0 ext/vendor/github.com/aws/aws-sdk-go-v2/internal/v4a/internal/crypto/compare.go