mirror of
https://github.com/btcsuite/btcd.git
synced 2025-02-22 22:25:45 +01:00
In this commit, we turn the package into a new Go module (version 2), and then port over the current set of types and functions to mainly alias to the more optimized and maintained dcrec variant. Taking a look at the benchmarks, most operations other than normalization (which IIRC is a bit slower now due to constant time fixes) enjoy some nice speeds up: ``` benchcmp is deprecated in favor of benchstat: https://pkg.go.dev/golang.org/x/perf/cmd/benchstat benchmark old ns/op new ns/op delta BenchmarkAddJacobian-8 464 328 -29.20% BenchmarkAddJacobianNotZOne-8 1138 372 -67.27% BenchmarkScalarBaseMult-8 47336 31531 -33.39% BenchmarkScalarBaseMultLarge-8 42465 32057 -24.51% BenchmarkScalarMult-8 123355 117579 -4.68% BenchmarkNAF-8 582 168 -71.12% BenchmarkSigVerify-8 175414 120794 -31.14% BenchmarkFieldNormalize-8 23.8 24.4 +2.39% BenchmarkParseCompressedPubKey-8 24282 10907 -55.08% ```
31 lines
731 B
Go
31 lines
731 B
Go
// Copyright (c) 2015-2016 The btcsuite developers
|
|
// Use of this source code is governed by an ISC
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package btcec
|
|
|
|
import (
|
|
"bytes"
|
|
"testing"
|
|
)
|
|
|
|
func TestGenerateSharedSecret(t *testing.T) {
|
|
privKey1, err := NewPrivateKey()
|
|
if err != nil {
|
|
t.Errorf("private key generation error: %s", err)
|
|
return
|
|
}
|
|
privKey2, err := NewPrivateKey()
|
|
if err != nil {
|
|
t.Errorf("private key generation error: %s", err)
|
|
return
|
|
}
|
|
|
|
secret1 := GenerateSharedSecret(privKey1, privKey2.PubKey())
|
|
secret2 := GenerateSharedSecret(privKey2, privKey1.PubKey())
|
|
|
|
if !bytes.Equal(secret1, secret2) {
|
|
t.Errorf("ECDH failed, secrets mismatch - first: %x, second: %x",
|
|
secret1, secret2)
|
|
}
|
|
}
|