2020-04-28 13:37:42 +00:00
|
|
|
package crypto
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/core/interop"
|
2020-08-29 15:44:45 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/crypto"
|
2020-04-28 13:37:42 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/crypto/hash"
|
2020-08-29 15:44:45 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/vm/stackitem"
|
2020-04-28 13:37:42 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Sha256 returns sha256 hash of the data.
|
2020-08-07 11:37:49 +00:00
|
|
|
func Sha256(ic *interop.Context) error {
|
2020-08-29 15:44:45 +00:00
|
|
|
h, err := getMessageHash(ic, ic.VM.Estack().Pop().Item())
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
ic.VM.Estack().PushVal(h.BytesBE())
|
2020-04-28 13:37:42 +00:00
|
|
|
return nil
|
|
|
|
}
|
2020-07-22 09:22:20 +00:00
|
|
|
|
|
|
|
// RipeMD160 returns RipeMD160 hash of the data.
|
2020-08-07 11:37:49 +00:00
|
|
|
func RipeMD160(ic *interop.Context) error {
|
2020-08-29 15:44:45 +00:00
|
|
|
var msg []byte
|
|
|
|
|
|
|
|
item := ic.VM.Estack().Pop().Item()
|
|
|
|
switch val := item.(type) {
|
|
|
|
case *stackitem.Interop:
|
|
|
|
msg = val.Value().(crypto.Verifiable).GetSignedPart()
|
|
|
|
case stackitem.Null:
|
|
|
|
msg = ic.Container.GetSignedPart()
|
|
|
|
default:
|
|
|
|
var err error
|
|
|
|
if msg, err = val.TryBytes(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2020-07-22 09:22:20 +00:00
|
|
|
h := hash.RipeMD160(msg).BytesBE()
|
2020-08-07 11:37:49 +00:00
|
|
|
ic.VM.Estack().PushVal(h)
|
2020-07-22 09:22:20 +00:00
|
|
|
return nil
|
|
|
|
}
|