[#190] Refactor cryptographic functionality

Remove `signature` and `util/signature` packages. Re-implement their
functionality in new `crypto` package. Generalize the approach of
digital signature computation and verification by adding `Signer` and
`PublicKey` primitives similar to standard `crypto` package. Support
already exising in protocol signature schemes.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2022-04-05 14:13:34 +03:00 committed by LeL
parent 2deaaeef05
commit ea043f4ca3
33 changed files with 728 additions and 627 deletions

51
crypto/crypto_test.go Normal file
View file

@ -0,0 +1,51 @@
package neofscrypto_test
import (
"math/rand"
"testing"
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/nspcc-dev/neofs-api-go/v2/refs"
neofscrypto "github.com/nspcc-dev/neofs-sdk-go/crypto"
neofsecdsa "github.com/nspcc-dev/neofs-sdk-go/crypto/ecdsa"
"github.com/stretchr/testify/require"
)
func TestSignature(t *testing.T) {
data := make([]byte, 512)
rand.Read(data)
k, err := keys.NewPrivateKey()
require.NoError(t, err)
var s neofscrypto.Signature
var m refs.Signature
for _, f := range []func() neofscrypto.Signer{
func() neofscrypto.Signer {
var key neofsecdsa.Signer
key.SetKey(k.PrivateKey)
return &key
},
func() neofscrypto.Signer {
var key neofsecdsa.Signer
key.SetKey(k.PrivateKey)
key.MakeDeterministic()
return &key
},
} {
signer := f()
err := s.Calculate(signer, data)
require.NoError(t, err)
s.WriteToV2(&m)
s.ReadFromV2(m)
valid := s.Verify(data)
require.True(t, valid)
}
}