Skip to content

Commit 5533284

Browse files
authored
Cleanup pass on Go code in repository (#2951)
### Description of changes: * Go 1.17 is still the targeted "base" Go version our tools are targeting. This limits us to using a `golang.org/x/crypto` module version that was still compatible with Go 1.17. This module version has tagged CVEs, but they aren't relevent to our build/test tools. This is only used for the `ssl/test/runner`, we could in the future be smarter about running or not running tests that require this program based off the detected Go compiler version. * I added `go:build ignore` tag to the Go programs that were pulling in `github.com/ethereum/go-ethereum`. So this won't be recorded in the top-level `go.mod` file anymore. We could move these into a separate nested module, but these only exist if in the rare event we want to regenerate test cases / understand what generated test cases for us. * Ran `go fmt` on the code in the repository, need to add a CI job that actually enforces this.... ### Call-outs: * Will need to fix the `AWS-LC-Build-Glue` script that drops an alternative `go.mod` file, as the path will now be incorrect and will cause build failures when trying to build `ssl/test/runner`. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license.
1 parent 7824b9a commit 5533284

File tree

32 files changed

+207
-203
lines changed

32 files changed

+207
-203
lines changed

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,9 +1220,9 @@ if(BUILD_TESTING)
12201220
add_custom_target(
12211221
build_acvp_tool
12221222
COMMAND ${GO_EXECUTABLE} build -o ${ACVP_TOOL}
1223-
boringssl.googlesource.com/boringssl/util/fipstools/acvp/acvptool
1223+
github.com/aws/aws-lc/util/fipstools/acvp/acvptool
12241224
COMMAND ${GO_EXECUTABLE} build -o ${TEST_WRAPPER}
1225-
boringssl.googlesource.com/boringssl/util/fipstools/acvp/acvptool/testmodulewrapper
1225+
github.com/aws/aws-lc/util/fipstools/acvp/acvptool/testmodulewrapper
12261226
WORKING_DIRECTORY ${AWSLC_SOURCE_DIR}
12271227
DEPENDS modulewrapper
12281228
${MAYBE_USES_TERMINAL})

crypto/ecdh_extra/make_secp256k1_test_vectors.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,18 @@
33

44
// This script is used to generate the ECDH test vectors for secp256k1 curve.
55

6+
//go:build ignore
7+
68
package main
79

810
import (
911
"crypto/sha256"
12+
"fmt"
1013
"math/big"
1114
"strconv"
12-
"fmt"
13-
)
1415

15-
import "github.com/ethereum/go-ethereum/crypto/secp256k1"
16+
"github.com/ethereum/go-ethereum/crypto/secp256k1"
17+
)
1618

1719
// Number of test vectors to be generated
1820
const numOfTests = 25
@@ -45,8 +47,8 @@ func main() {
4547

4648
curve := secp256k1.S256()
4749

48-
fmt.Printf("\n# Test vectors for secp256k1 curve were produced by")
49-
fmt.Printf("\n# the |make_secp256k1_test_vectors.go| script.\n\n")
50+
fmt.Printf("\n# Test vectors for secp256k1 curve were produced by")
51+
fmt.Printf("\n# the |make_secp256k1_test_vectors.go| script.\n\n")
5052

5153
for i := 0; i < numOfTests; i++ {
5254
// Generate a private key for Alice and for Bob
@@ -77,4 +79,3 @@ func main() {
7779
fmt.Printf("\n")
7880
}
7981
}
80-

crypto/fipsmodule/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ if(FIPS_DELOCATE)
442442
set(DELOCATE_EXTRA_ARGS "-no-se-debug-directives")
443443
endif()
444444

445-
go_executable(delocate boringssl.googlesource.com/boringssl/util/fipstools/delocate)
445+
go_executable(delocate github.com/aws/aws-lc/util/fipstools/delocate)
446446
add_custom_command(
447447
OUTPUT bcm-delocated.S
448448
COMMAND
@@ -491,7 +491,7 @@ if(FIPS_DELOCATE)
491491
set_target_properties(bcm_hashunset PROPERTIES LINKER_LANGUAGE C)
492492

493493
go_executable(inject_hash
494-
boringssl.googlesource.com/boringssl/util/fipstools/inject_hash)
494+
github.com/aws/aws-lc/util/fipstools/inject_hash)
495495
add_custom_command(
496496
OUTPUT bcm.o
497497
COMMAND ./inject_hash -o bcm.o -in-archive $<TARGET_FILE:bcm_hashunset>

crypto/fipsmodule/ec/make_large_x_coordinate.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
/*
2-
------------------------------------------------------------------------------------
3-
Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
4-
SPDX-License-Identifier: Apache-2.0 OR ISC
5-
------------------------------------------------------------------------------------
6-
*/
1+
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0 OR ISC
73

84
// Note: The function elliptic.UnmarshalCompressed is available as of go1.15
95

6+
//go:build ignore
7+
108
package main
119

1210
import (

crypto/fipsmodule/ecdsa/make_ecdsa_secp256k1_tests.go

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0 OR ISC
33

4+
//go:build ignore
5+
46
package main
57

68
import (
@@ -12,17 +14,18 @@ import (
1214
"crypto/sha1"
1315
"crypto/sha256"
1416
"crypto/sha512"
15-
"math/big"
16-
mathrand "math/rand"
17-
"hash"
1817
"fmt"
18+
"hash"
1919
"io"
20+
"math/big"
21+
mathrand "math/rand"
2022
"os"
23+
24+
"github.com/ethereum/go-ethereum/crypto/secp256k1"
2125
)
2226

2327
// secp256k1 curve is not available in crypto/elliptic module,
2428
// so we use the implementation from the module listed below.
25-
import "github.com/ethereum/go-ethereum/crypto/secp256k1"
2629

2730
// START - Deterministic RNG helper functions.
2831
type deterministicRandom struct {
@@ -96,8 +99,9 @@ func hashToInt(hash []byte, c elliptic.Curve) *big.Int {
9699

97100
// Helper function needed for generating the ECDSA Sign/Verify test vectors.
98101
// We don't use the Sign function from the ecdsa module because:
99-
// 1) it is not deterministic (even when provided with a deterministic RNG).
100-
// 2) we need to know the chosen nonce k to generate signing test vectors.
102+
// 1. it is not deterministic (even when provided with a deterministic RNG).
103+
// 2. we need to know the chosen nonce k to generate signing test vectors.
104+
//
101105
// This function implements ECDSA signing of a message digest dgst with
102106
// private key priv and nonce k.
103107
func signWithGivenK(priv *ecdsa.PrivateKey, dgst []byte, k *big.Int) (r, s *big.Int) {
@@ -161,14 +165,14 @@ func printVerifyTestVectors(curve elliptic.Curve, curveName string, hash hash.Ha
161165
xOut, yOut := priv.PublicKey.X, priv.PublicKey.Y
162166

163167
switch event {
164-
case 1:
165-
dgst[0] ^= 1 // Invalidate the digest
166-
case 2:
167-
r.Xor(r, one) // Invalidate R
168-
case 3:
169-
s.Xor(s, one) // Invalidate S
170-
case 4:
171-
xOut, yOut = randPoint(curve) // Invalidate the public key
168+
case 1:
169+
dgst[0] ^= 1 // Invalidate the digest
170+
case 2:
171+
r.Xor(r, one) // Invalidate R
172+
case 3:
173+
s.Xor(s, one) // Invalidate S
174+
case 4:
175+
xOut, yOut = randPoint(curve) // Invalidate the public key
172176
}
173177

174178
// Print out the test vector
@@ -230,7 +234,7 @@ func main() {
230234
S256 := secp256k1.S256()
231235

232236
// Initialize the hash functions
233-
hashFuncs := []hash.Hash {sha1.New(), sha256.New224(), sha256.New(), sha512.New384(), sha512.New()}
237+
hashFuncs := []hash.Hash{sha1.New(), sha256.New224(), sha256.New(), sha512.New384(), sha512.New()}
234238

235239
// Print the header
236240
fmt.Printf("# Test vectors for secp256k1 were generated by make_ecdsa_secp256k1_tests.go script.\n")
@@ -245,4 +249,3 @@ func main() {
245249
}
246250
}
247251
}
248-

go.mod

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
1-
module boringssl.googlesource.com/boringssl
1+
module github.com/aws/aws-lc
22

33
// When this changes update /cmake/go.cmake minimum_go_version and /BUILDING.md
44
go 1.17
55

6-
require (
7-
golang.org/x/crypto v0.10.0
8-
golang.org/x/net v0.11.0
9-
)
10-
11-
require github.com/ethereum/go-ethereum v1.11.5
6+
// v0.14.0 was the last version that support 1.17
7+
require golang.org/x/crypto v0.14.0
128

139
require (
14-
golang.org/x/sys v0.9.0 // indirect
15-
golang.org/x/term v0.9.0 // indirect
10+
golang.org/x/sys v0.13.0 // indirect
11+
golang.org/x/term v0.13.0 // indirect
1612
)

go.sum

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
golang.org/x/crypto v0.10.0 h1:LKqV2xt9+kDzSTfOhx4FrkEBcMrAgHSYgzywV9zcGmM=
2-
golang.org/x/crypto v0.10.0/go.mod h1:o4eNf7Ede1fv+hwOwZsTHl9EsPFO6q6ZvYR8vYfY45I=
3-
golang.org/x/net v0.11.0 h1:Gi2tvZIJyBtO9SDr1q9h5hEQCp/4L2RQ+ar0qjx2oNU=
4-
golang.org/x/net v0.11.0/go.mod h1:2L/ixqYpgIVXmeoSA/4Lu7BzTG4KIyPIryS4IsOd1oQ=
5-
golang.org/x/sys v0.9.0 h1:KS/R3tvhPqvJvwcKfnBHJwwthS11LRhmM5D59eEXa0s=
6-
golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
7-
golang.org/x/term v0.9.0 h1:GRRCnKYhdQrD8kfRAdQ6Zcw1P0OcELxGLKJvtjVMZ28=
8-
golang.org/x/term v0.9.0/go.mod h1:M6DEAAIenWoTxdKrOltXcmDY3rSplQUkrvaDU5FcQyo=
1+
golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc=
2+
golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
3+
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
4+
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
5+
golang.org/x/term v0.13.0 h1:bb+I9cTfFazGW51MZqBVmZy7+JEJMouUHTUSKVQLBek=
6+
golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U=

include/openssl/ssl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6171,7 +6171,7 @@ OPENSSL_EXPORT OPENSSL_DEPRECATED int SSL_set_tmp_rsa(SSL *ssl, const RSA *rsa);
61716171
//
61726172
// See PORTING.md in the BoringSSL source tree for a table of corresponding
61736173
// functions.
6174-
// https://boringssl.googlesource.com/boringssl/+/master/PORTING.md#Replacements-for-values
6174+
// https://github.com/aws/aws-lc/blob/main/PORTING.md#replacements-for-ctrl-values
61756175

61766176
#define DTLS_CTRL_GET_TIMEOUT doesnt_exist
61776177
#define DTLS_CTRL_HANDLE_TIMEOUT doesnt_exist

ssl/test/runner/common.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"sync"
2121
"time"
2222

23-
"boringssl.googlesource.com/boringssl/ssl/test/runner/hpke"
23+
"github.com/aws/aws-lc/ssl/test/runner/hpke"
2424
)
2525

2626
const (
@@ -152,11 +152,11 @@ var tls13HelloRetryRequest = []uint8{
152152
type CurveID uint16
153153

154154
const (
155-
CurveP224 CurveID = 21
156-
CurveP256 CurveID = 23
157-
CurveP384 CurveID = 24
158-
CurveP521 CurveID = 25
159-
CurveX25519 CurveID = 29
155+
CurveP224 CurveID = 21
156+
CurveP256 CurveID = 23
157+
CurveP384 CurveID = 24
158+
CurveP521 CurveID = 25
159+
CurveX25519 CurveID = 29
160160
)
161161

162162
// TLS Elliptic Curve Point Formats

ssl/test/runner/conn.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1206,7 +1206,7 @@ func (c *Conn) doWriteRecord(typ recordType, data []byte) (n int, err error) {
12061206
}
12071207

12081208
if typ != recordTypeHandshake && c.config.Bugs.MaxRecordSize > 0 && c.config.Bugs.MaxRecordSize < m {
1209-
m = c.config.Bugs.MaxRecordSize
1209+
m = c.config.Bugs.MaxRecordSize
12101210
}
12111211

12121212
explicitIVLen := 0

0 commit comments

Comments
 (0)