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+
46package main
57
68import (
@@ -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.
2831type 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.
103107func 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-
0 commit comments