Skip to content

Commit

Permalink
Fixup ref sphincs golang bindings
Browse files Browse the repository at this point in the history
try to get rid of weird pointer bug, copy data not pointers!
  • Loading branch information
david415 committed Nov 8, 2024
1 parent 1dc77b5 commit e19c8d6
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 20 deletions.
6 changes: 5 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
module github.com/katzenpost/sphincsplus

go 1.20
go 1.22.0

toolchain go1.23.0

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/katzenpost/hpqc v0.0.0-20240114190904-bc8bcfcca4ee // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/stretchr/objx v0.5.0 // indirect
github.com/stretchr/testify v1.8.4 // indirect
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect
golang.org/x/tools v0.25.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
15 changes: 15 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,21 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 h1:VLliZ0d+/avPrXXH+OakdXhpJuEoBZuwh1m2j7U6Iug=
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
golang.org/x/tools v0.25.0 h1:oFU9pkj/iJgs+0DT+VMHrx+oBKs/LJMV+Uvg78sl+fE=
golang.org/x/tools v0.25.0/go.mod h1:/vtpO8WL1N9cQC3FN5zPqb//fRXskFHbLKk4OW1Q7rg=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
Expand Down
29 changes: 10 additions & 19 deletions ref/binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ func (p *PublicKey) Verify(signature, message []byte) bool {

// Bytes returns the PublicKey as a byte slice.
func (p *PublicKey) Bytes() []byte {
return p.publicKey
out := make([]byte, len(p.publicKey))
copy(out, p.publicKey)
return out
}

// FromBytes loads a PublicKey from the given byte slice.
Expand All @@ -84,25 +86,11 @@ func (p *PublicKey) FromBytes(data []byte) error {
return ErrPublicKeySize
}

p.publicKey = data
p.publicKey = make([]byte, len(data))
copy(p.publicKey, data)
return nil
}

// Verify checks whether the given signature is valid.
/*
func (p *PublicKey) Verify(signature, message []byte) bool {
ret := C.crypto_sign_verify((*C.uchar)(unsafe.Pointer(&signature[0])),
C.ulong(len(signature)),
(*C.uchar)(unsafe.Pointer(&message[0])),
C.ulong(len(message)),
(*C.uchar)(unsafe.Pointer(&p.publicKey[0])))
if ret == 0 {
return true
}
return false
}
*/

// PrivateKey is a private Sphincs+ key.
type PrivateKey struct {
privateKey []byte
Expand All @@ -127,7 +115,9 @@ func (p *PrivateKey) Sign(message []byte) []byte {

// Bytes returns the PrivateKey as a byte slice.
func (p *PrivateKey) Bytes() []byte {
return p.privateKey
out := make([]byte, len(p.privateKey))
copy(out, p.privateKey)
return out
}

// FromBytes loads a PrivateKey from the given byte slice.
Expand All @@ -136,6 +126,7 @@ func (p *PrivateKey) FromBytes(data []byte) error {
return ErrPrivateKeySize
}

p.privateKey = data
p.privateKey = make([]byte, len(data))
copy(p.privateKey, data)
return nil
}

0 comments on commit e19c8d6

Please sign in to comment.