Fixed slice aliasing error in signature creation
This commit is contained in:
parent
a27044154a
commit
a1bbcbd5a8
2 changed files with 12 additions and 9 deletions
|
@ -344,10 +344,13 @@ func (sk *PrivateKey) SignMessage(ck []byte, comment string) (*Signature, error)
|
||||||
return nil, fmt.Errorf("can't sign %x: %s", ck, err)
|
return nil, fmt.Errorf("can't sign %x: %s", ck, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &Signature{
|
ss := &Signature{
|
||||||
Sig: sig,
|
Sig: sig,
|
||||||
pkhash: sk.pk.hash,
|
pkhash: make([]byte, len(sk.pk.hash)),
|
||||||
}, nil
|
}
|
||||||
|
|
||||||
|
copy(ss.pkhash, sk.pk.hash)
|
||||||
|
return ss, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read and sign a file
|
// Read and sign a file
|
||||||
|
|
|
@ -14,7 +14,6 @@
|
||||||
package sign
|
package sign
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/rand"
|
|
||||||
"crypto/subtle"
|
"crypto/subtle"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
@ -55,7 +54,7 @@ func tempdir(t *testing.T) string {
|
||||||
var b [10]byte
|
var b [10]byte
|
||||||
|
|
||||||
dn := os.TempDir()
|
dn := os.TempDir()
|
||||||
rand.Read(b[:])
|
randread(b[:])
|
||||||
|
|
||||||
tmp := path.Join(dn, fmt.Sprintf("%x", b[:]))
|
tmp := path.Join(dn, fmt.Sprintf("%x", b[:]))
|
||||||
err := os.MkdirAll(tmp, 0755)
|
err := os.MkdirAll(tmp, 0755)
|
||||||
|
@ -91,6 +90,7 @@ r: 8
|
||||||
p: 1
|
p: 1
|
||||||
`
|
`
|
||||||
|
|
||||||
|
|
||||||
// #1. Create new key pair, and read them back.
|
// #1. Create new key pair, and read them back.
|
||||||
func Test0(t *testing.T) {
|
func Test0(t *testing.T) {
|
||||||
assert := newAsserter(t)
|
assert := newAsserter(t)
|
||||||
|
@ -154,7 +154,7 @@ func Test1(t *testing.T) {
|
||||||
|
|
||||||
var ck [64]byte // simulates sha512 sum
|
var ck [64]byte // simulates sha512 sum
|
||||||
|
|
||||||
rand.Read(ck[:])
|
randread(ck[:])
|
||||||
|
|
||||||
pk := &kp.Pub
|
pk := &kp.Pub
|
||||||
sk := &kp.Sec
|
sk := &kp.Sec
|
||||||
|
@ -167,7 +167,7 @@ func Test1(t *testing.T) {
|
||||||
assert(ss.IsPKMatch(pk), "pk match fail")
|
assert(ss.IsPKMatch(pk), "pk match fail")
|
||||||
|
|
||||||
// Corrupt the pkhash and see
|
// Corrupt the pkhash and see
|
||||||
rand.Read(ss.pkhash[:])
|
randread(ss.pkhash)
|
||||||
assert(!ss.IsPKMatch(pk), "corrupt pk match fail")
|
assert(!ss.IsPKMatch(pk), "corrupt pk match fail")
|
||||||
|
|
||||||
// Incorrect checksum == should fail verification
|
// Incorrect checksum == should fail verification
|
||||||
|
@ -204,7 +204,7 @@ func Test1(t *testing.T) {
|
||||||
assert(err == nil, "file.dat creat file")
|
assert(err == nil, "file.dat creat file")
|
||||||
|
|
||||||
for i := 0; i < 8; i++ {
|
for i := 0; i < 8; i++ {
|
||||||
rand.Read(buf[:])
|
randread(buf[:])
|
||||||
n, err := fd.Write(buf[:])
|
n, err := fd.Write(buf[:])
|
||||||
assert(err == nil, fmt.Sprintf("file.dat write fail: %s", err))
|
assert(err == nil, fmt.Sprintf("file.dat write fail: %s", err))
|
||||||
assert(n == 8192, fmt.Sprintf("file.dat i/o fail: exp 8192 saw %v", n))
|
assert(n == 8192, fmt.Sprintf("file.dat i/o fail: exp 8192 saw %v", n))
|
||||||
|
@ -300,7 +300,7 @@ func benchVerify(b *testing.B, buf []byte, sig *Signature, pk *PublicKey) {
|
||||||
|
|
||||||
func randbuf(sz uint) []byte {
|
func randbuf(sz uint) []byte {
|
||||||
b := make([]byte, sz)
|
b := make([]byte, sz)
|
||||||
rand.Read(b)
|
randread(b)
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue