From 1c9a2640e935e3ce3186fb66c361c21996dc9cb1 Mon Sep 17 00:00:00 2001 From: Marko Date: Fri, 7 Aug 2020 19:05:31 +0200 Subject: [PATCH] crypto: consistent api across keys (#5214) ## Description This Pr changes `GenPrivKeySecp256k1` to `GenPrivKeyFromSecret` to be consistent with the other keys. Also the previous name was not descriptive on what it did. Closes: #XXX --- CHANGELOG_PENDING.md | 3 ++- crypto/secp256k1/secp256k1.go | 4 ++-- crypto/secp256k1/secp256k1_test.go | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/CHANGELOG_PENDING.md b/CHANGELOG_PENDING.md index 2117814d5..02656e1c4 100644 --- a/CHANGELOG_PENDING.md +++ b/CHANGELOG_PENDING.md @@ -8,7 +8,8 @@ Friendly reminder, we have a [bug bounty program](https://hackerone.com/tendermi - Go API - - [evidence] [\#5181](https://github.com/tendermint/tendermint/pull/5181) Phantom validator evidence was removed (also from abci) (@cmwaters) + - [evidence] [\#5181](https://github.com/tendermint/tendermint/pull/5181) Phantom validator evidence was removed (also from abci) (@cmwaters) + - [crypto] [\#5214] Change `GenPrivKeySecp256k1` to `GenPrivKeyFromSecret` to be consistent with other keys ### FEATURES: diff --git a/crypto/secp256k1/secp256k1.go b/crypto/secp256k1/secp256k1.go index ec57c1648..68a523946 100644 --- a/crypto/secp256k1/secp256k1.go +++ b/crypto/secp256k1/secp256k1.go @@ -79,7 +79,7 @@ func genPrivKey(rand io.Reader) PrivKey { var one = new(big.Int).SetInt64(1) -// GenPrivKeySecp256k1 hashes the secret with SHA2, and uses +// GenPrivKeyFromSecret hashes the secret with SHA2, and uses // that 32 byte output to create the private key. // // It makes sure the private key is a valid field element by setting: @@ -89,7 +89,7 @@ var one = new(big.Int).SetInt64(1) // // NOTE: secret should be the output of a KDF like bcrypt, // if it's derived from user input. -func GenPrivKeySecp256k1(secret []byte) PrivKey { +func GenPrivKeyFromSecret(secret []byte) PrivKey { secHash := sha256.Sum256(secret) // to guarantee that we have a valid field element, we use the approach of: // "Suite B Implementer’s Guide to FIPS 186-3", A.2.1 diff --git a/crypto/secp256k1/secp256k1_test.go b/crypto/secp256k1/secp256k1_test.go index de2454310..c6316eb25 100644 --- a/crypto/secp256k1/secp256k1_test.go +++ b/crypto/secp256k1/secp256k1_test.go @@ -84,7 +84,7 @@ func TestSecp256k1LoadPrivkeyAndSerializeIsIdentity(t *testing.T) { } } -func TestGenPrivKeySecp256k1(t *testing.T) { +func TestGenPrivKeyFromSecret(t *testing.T) { // curve oder N N := underlyingSecp256k1.S256().N tests := []struct { @@ -104,7 +104,7 @@ func TestGenPrivKeySecp256k1(t *testing.T) { for _, tt := range tests { tt := tt t.Run(tt.name, func(t *testing.T) { - gotPrivKey := secp256k1.GenPrivKeySecp256k1(tt.secret) + gotPrivKey := secp256k1.GenPrivKeyFromSecret(tt.secret) require.NotNil(t, gotPrivKey) // interpret as a big.Int and make sure it is a valid field element: fe := new(big.Int).SetBytes(gotPrivKey[:])