Skip to content

Commit ea54216

Browse files
committed
crypto/internal/fips/subtle: provide XORBytes
This is needed from inside the module, and we generally don't want to import the crypto tree from it. For golang#69536 Change-Id: I69e91e4df89ecac0016c671ccd28e733a7131533
1 parent 96f3fa4 commit ea54216

File tree

13 files changed

+26
-10
lines changed

13 files changed

+26
-10
lines changed
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2022 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
6+
7+
// XORBytes sets dst[i] = x[i] ^ y[i] for all i < n = min(len(x), len(y)),
8+
// returning n, the number of bytes written to dst.
9+
// If dst does not have length at least n,
10+
// XORBytes panics without writing anything to dst.
11+
func XORBytes(dst, x, y []byte) int {
12+
n := min(len(x), len(y))
13+
if n == 0 {
14+
return 0
15+
}
16+
if n > len(dst) {
17+
panic("subtle.XORBytes: dst too short")
18+
}
19+
xorBytes(&dst[0], &x[0], &y[0], n) // arch-specific
20+
return n
21+
}

src/crypto/subtle/xor_test.go renamed to src/crypto/internal/fips/subtle/xor_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ package subtle_test
66

77
import (
88
"bytes"
9+
. "crypto/internal/fips/subtle"
910
"crypto/rand"
10-
. "crypto/subtle"
1111
"fmt"
1212
"io"
1313
"testing"

src/crypto/subtle/xor.go

+3-9
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,12 @@
44

55
package subtle
66

7+
import "crypto/internal/fips/subtle"
8+
79
// XORBytes sets dst[i] = x[i] ^ y[i] for all i < n = min(len(x), len(y)),
810
// returning n, the number of bytes written to dst.
911
// If dst does not have length at least n,
1012
// XORBytes panics without writing anything to dst.
1113
func XORBytes(dst, x, y []byte) int {
12-
n := min(len(x), len(y))
13-
if n == 0 {
14-
return 0
15-
}
16-
if n > len(dst) {
17-
panic("subtle.XORBytes: dst too short")
18-
}
19-
xorBytes(&dst[0], &x[0], &y[0], n) // arch-specific
20-
return n
14+
return subtle.XORBytes(dst, x, y)
2115
}

src/go/build/deps_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,7 @@ var depsRules = `
449449
# backwards compatibility with older versions of the module.
450450
STR, crypto/internal/impl
451451
< crypto/internal/fips
452+
< crypto/internal/fips/subtle
452453
< crypto/internal/fips/sha256
453454
< crypto/internal/fips/sha512
454455
< crypto/internal/fips/hmac

0 commit comments

Comments
 (0)