Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crypto v0.43 Audit updates #9292

Merged
merged 4 commits into from
May 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crypto/keys/internal/ecdsa/privkey_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (suite *SKSuite) TestPubKey() {
suite.True(suite.sk.PublicKey.Equal(&pk.PublicKey))
}

func (suite *SKSuite) Bytes() {
func (suite *SKSuite) TestBytes() {
bz := suite.sk.Bytes()
suite.Len(bz, 32)
var sk *PrivKey
Expand Down
4 changes: 3 additions & 1 deletion crypto/keys/internal/ecdsa/pubkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ type PubKey struct {
address tmcrypto.Address
}

// Address creates an ADR-28 address for ECDSA keys. protoName is a concrete proto structure id.
// Address gets the address associated with a pubkey. If no address exists, it returns a newly created ADR-28 address
// for ECDSA keys.
// protoName is a concrete proto structure id.
func (pk *PubKey) Address(protoName string) tmcrypto.Address {
if pk.address == nil {
pk.address = address.Hash(protoName, pk.Bytes())
Expand Down
6 changes: 4 additions & 2 deletions crypto/keys/internal/ecdsa/pubkey_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ func (suite *PKSuite) TestString() {
}

func (suite *PKSuite) TestBytes() {
require := suite.Require()
bz := suite.sk.Bytes()
fieldSize := (suite.sk.Curve.Params().BitSize + 7) / 8
suite.Len(bz, fieldSize)
var pk *PubKey
require.Nil(pk.Bytes())
suite.Nil(pk.Bytes())
}

func (suite *PKSuite) TestMarshal() {
Expand Down
3 changes: 3 additions & 0 deletions crypto/keys/secp256r1/privkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ func (m *PrivKey) Sign(msg []byte) ([]byte, error) {

// Bytes serialize the private key.
func (m *PrivKey) Bytes() []byte {
if m == nil {
return nil
}
return m.Secret.Bytes()
}

Expand Down
4 changes: 2 additions & 2 deletions crypto/keys/secp256r1/privkey_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package secp256r1
import (
"testing"

proto "github.com/gogo/protobuf/proto"
"github.com/gogo/protobuf/proto"
"github.com/stretchr/testify/suite"
"github.com/tendermint/tendermint/crypto"

Expand Down Expand Up @@ -41,7 +41,7 @@ func (suite *SKSuite) TestPubKey() {
suite.True(suite.sk.(*PrivKey).Secret.PublicKey.Equal(&pk.(*PubKey).Key.PublicKey))
}

func (suite *SKSuite) Bytes() {
func (suite *SKSuite) TestBytes() {
bz := suite.sk.Bytes()
suite.Len(bz, fieldSize)
var sk *PrivKey
Expand Down
3 changes: 3 additions & 0 deletions crypto/keys/secp256r1/pubkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ func (m *PubKey) String() string {

// Bytes implements SDK PubKey interface.
func (m *PubKey) Bytes() []byte {
if m == nil {
return nil
}
return m.Key.Bytes()
}

Expand Down
7 changes: 7 additions & 0 deletions crypto/keys/secp256r1/pubkey_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ func (suite *PKSuite) TestType() {
suite.Require().Equal(name, suite.pk.Type())
}

func (suite *PKSuite) TestBytes() {
bz := suite.pk.Bytes()
suite.Len(bz, fieldSize+1)
var pk *PubKey
suite.Nil(pk.Bytes())
}

func (suite *PKSuite) TestEquals() {
require := suite.Require()

Expand Down