Browse Source

Update code to work with current nano implementation

pull/1782/head
Ethan Frey 7 years ago
parent
commit
74878ee313
2 changed files with 20 additions and 8 deletions
  1. +8
    -1
      nano/sign.go
  2. +12
    -7
      nano/sign_test.go

+ 8
- 1
nano/sign.go View File

@ -2,9 +2,11 @@ package nano
import (
"bytes"
"crypto/sha512"
"fmt"
"github.com/pkg/errors"
crypto "github.com/tendermint/go-crypto"
)
@ -14,7 +16,7 @@ const (
Update = 0x01
Digest = 0x02
MaxChunk = 253
KeyLength = 65
KeyLength = 32
SigLength = 64
)
@ -76,3 +78,8 @@ func parseSig(data []byte) (key crypto.Signature, err error) {
copy(ed[:], data)
return ed.Wrap(), nil
}
func hashMsg(data []byte) []byte {
res := sha512.Sum512(data)
return res[:]
}

+ 12
- 7
nano/sign_test.go View File

@ -18,9 +18,9 @@ func TestParseDigest(t *testing.T) {
valid bool
}{
{
output: "800204338EB1DD3CCDEE1F6FB586F66E640F56FFDD14537A3F0ED9EEEDF10B528FE4195FD17AC9EDAE9718A50196A1459E2434C1E53F1238F4CFDF177FAFBA8B39249B00CAFE00FFDEA42A699205B217004E7E2FFB884E174A548D644116F4B20469CBC32F60A9CB0EEB5BB6A7F266BD0F6A0A99A45B4F18F0F477AED7C854C404EF43530DAB00",
key: "04338EB1DD3CCDEE1F6FB586F66E640F56FFDD14537A3F0ED9EEEDF10B528FE4195FD17AC9EDAE9718A50196A1459E2434C1E53F1238F4CFDF177FAFBA8B39249B",
sig: "FFDEA42A699205B217004E7E2FFB884E174A548D644116F4B20469CBC32F60A9CB0EEB5BB6A7F266BD0F6A0A99A45B4F18F0F477AED7C854C404EF43530DAB00",
output: "80028E8754F012C2FDB492183D41437FD837CB81D8BBE731924E2E0DAF43FD3F2C9300CAFE00787DC03E9E4EE05983E30BAE0DEFB8DB0671DBC2F5874AC93F8D8CA4018F7A42D6F9A9BCEADB422AC8E27CEE9CA205A0B88D22CD686F0A43EB806E8190A3C400",
key: "8E8754F012C2FDB492183D41437FD837CB81D8BBE731924E2E0DAF43FD3F2C93",
sig: "787DC03E9E4EE05983E30BAE0DEFB8DB0671DBC2F5874AC93F8D8CA4018F7A42D6F9A9BCEADB422AC8E27CEE9CA205A0B88D22CD686F0A43EB806E8190A3C400",
valid: true,
},
{
@ -75,9 +75,9 @@ func TestCryptoConvert(t *testing.T) {
cases := []cryptoCase{
{
msg: "00",
key: "04338EB1DD3CCDEE1F6FB586F66E640F56FFDD14537A3F0ED9EEEDF10B528FE4195FD17AC9EDAE9718A50196A1459E2434C1E53F1238F4CFDF177FAFBA8B39249B",
sig: "FFDEA42A699205B217004E7E2FFB884E174A548D644116F4B20469CBC32F60A9CB0EEB5BB6A7F266BD0F6A0A99A45B4F18F0F477AED7C854C404EF43530DAB00",
msg: "F00D",
key: "8E8754F012C2FDB492183D41437FD837CB81D8BBE731924E2E0DAF43FD3F2C93",
sig: "787DC03E9E4EE05983E30BAE0DEFB8DB0671DBC2F5874AC93F8D8CA4018F7A42D6F9A9BCEADB422AC8E27CEE9CA205A0B88D22CD686F0A43EB806E8190A3C400",
valid: true,
},
}
@ -91,8 +91,13 @@ func TestCryptoConvert(t *testing.T) {
psig, err := parseSig(sig)
require.Nil(err, "%d: %+v", i, err)
// how do i make this valid?
// it is not the signature of the message itself
valid := pk.VerifyBytes(msg, psig)
assert.NotEqual(tc.valid, valid, "%d", i)
// but rather of the hash of the msg
hmsg := hashMsg(msg)
valid = pk.VerifyBytes(hmsg, psig)
assert.Equal(tc.valid, valid, "%d", i)
}
}

Loading…
Cancel
Save