The core protocol of WoopChain
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
woop/crypto/pki/utils.go

40 lines
1.1 KiB

package pki
import (
"crypto/sha256"
"github.com/dedis/kyber"
"github.com/simple-rules/harmony-benchmark/crypto"
"github.com/simple-rules/harmony-benchmark/log"
)
func GetAddressFromPublicKey(pubKey kyber.Point) [20]byte {
bytes, err := pubKey.MarshalBinary()
if err != nil {
log.Error("Failed to serialize challenge")
}
address := [20]byte{}
hash := sha256.Sum256(bytes)
copy(address[:], hash[12:])
return address
}
// Temporary helper function for benchmark use
func GetAddressFromInt(value int) [20]byte {
return GetAddressFromPublicKey(GetPublicKeyFromScalar(crypto.Ed25519Curve, GetPrivateKeyFromInt(value)))
}
func GetPrivateKeyFromInt(value int) kyber.Scalar {
return crypto.Ed25519Curve.Scalar().SetInt64(int64(value))
}
func GetPublicKeyFromPrivateKey(suite crypto.Suite, priKey [32]byte) kyber.Point {
scalar := suite.Scalar()
scalar.UnmarshalBinary(priKey[:])
return suite.Point().Mul(scalar, nil)
}
// Same as GetPublicKeyFromPrivateKey, but it directly works on kyber.Scalar object.
func GetPublicKeyFromScalar(suite crypto.Suite, priKey kyber.Scalar) kyber.Point {
return suite.Point().Mul(priKey, nil)
}