2020-05-18 07:58:27 +00:00
|
|
|
/*
|
|
|
|
Package crypto provides an interface to cryptographic syscalls.
|
|
|
|
*/
|
2018-08-22 08:12:57 +00:00
|
|
|
package crypto
|
|
|
|
|
2021-02-05 16:02:09 +00:00
|
|
|
import (
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/interop"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/interop/neogointernal"
|
|
|
|
)
|
2020-08-28 07:47:15 +00:00
|
|
|
|
2020-05-18 07:58:27 +00:00
|
|
|
// SHA256 computes SHA256 hash of b. It uses `Neo.Crypto.SHA256` syscall.
|
2020-08-28 07:47:15 +00:00
|
|
|
func SHA256(b []byte) interop.Hash256 {
|
2021-02-05 16:02:09 +00:00
|
|
|
return neogointernal.Syscall1("Neo.Crypto.SHA256", b).(interop.Hash256)
|
2018-08-22 08:12:57 +00:00
|
|
|
}
|
|
|
|
|
2020-07-22 09:22:20 +00:00
|
|
|
// RIPEMD160 computes RIPEMD160 hash of b. It uses `Neo.Crypto.RIPEMD160` syscall.
|
2020-08-28 07:47:15 +00:00
|
|
|
func RIPEMD160(b []byte) interop.Hash160 {
|
2021-02-05 16:02:09 +00:00
|
|
|
return neogointernal.Syscall1("Neo.Crypto.RIPEMD160", b).(interop.Hash160)
|
2020-07-22 09:22:20 +00:00
|
|
|
}
|
|
|
|
|
2020-07-10 06:56:15 +00:00
|
|
|
// ECDsaSecp256r1Verify checks that sig is correct msg's signature for a given pub
|
|
|
|
// (serialized public key). It uses `Neo.Crypto.VerifyWithECDsaSecp256r1` syscall.
|
2020-08-28 07:47:15 +00:00
|
|
|
func ECDsaSecp256r1Verify(msg []byte, pub interop.PublicKey, sig interop.Signature) bool {
|
2021-02-05 16:02:09 +00:00
|
|
|
return neogointernal.Syscall3("Neo.Crypto.VerifyWithECDsaSecp256r1", msg, pub, sig).(bool)
|
2020-01-22 15:24:58 +00:00
|
|
|
}
|
2020-07-13 09:59:41 +00:00
|
|
|
|
|
|
|
// ECDsaSecp256k1Verify checks that sig is correct msg's signature for a given pub
|
|
|
|
// (serialized public key). It uses `Neo.Crypto.VerifyWithECDsaSecp256k1` syscall.
|
2020-08-28 07:47:15 +00:00
|
|
|
func ECDsaSecp256k1Verify(msg []byte, pub interop.PublicKey, sig interop.Signature) bool {
|
2021-02-05 16:02:09 +00:00
|
|
|
return neogointernal.Syscall3("Neo.Crypto.VerifyWithECDsaSecp256k1", msg, pub, sig).(bool)
|
2020-07-13 09:59:41 +00:00
|
|
|
}
|
2020-07-14 09:09:26 +00:00
|
|
|
|
|
|
|
// ECDSASecp256r1CheckMultisig checks multiple ECDSA signatures at once. It uses
|
|
|
|
// `Neo.Crypto.CheckMultisigWithECDsaSecp256r1` syscall.
|
2020-08-28 07:47:15 +00:00
|
|
|
func ECDSASecp256r1CheckMultisig(msg []byte, pubs []interop.PublicKey, sigs []interop.Signature) bool {
|
2021-02-05 16:02:09 +00:00
|
|
|
return neogointernal.Syscall3("Neo.Crypto.CheckMultisigWithECDsaSecp256r1", msg, pubs, sigs).(bool)
|
2020-07-14 09:09:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ECDSASecp256k1CheckMultisig checks multiple ECDSA signatures at once. It uses
|
|
|
|
// `Neo.Crypto.CheckMultisigWithECDsaSecp256k1` syscall.
|
2020-08-28 07:47:15 +00:00
|
|
|
func ECDSASecp256k1CheckMultisig(msg []byte, pubs []interop.PublicKey, sigs []interop.Signature) bool {
|
2021-02-05 16:02:09 +00:00
|
|
|
return neogointernal.Syscall3("Neo.Crypto.CheckMultisigWithECDsaSecp256k1", msg, pubs, sigs).(bool)
|
2020-07-14 09:09:26 +00:00
|
|
|
}
|