MCPcopy Create free account
hub / github.com/DOSNetwork/core / Sign

Function Sign

sign/schnorr/schnorr.go:32–58  ·  view source on GitHub ↗

Sign creates a Sign signature from a msg and a private key. This signature can be verified with VerifySchnorr. It's also a valid EdDSA signature when using the edwards25519 Group.

(s Suite, private kyber.Scalar, msg []byte)

Source from the content-addressed store, hash-verified

30// signature can be verified with VerifySchnorr. It's also a valid EdDSA
31// signature when using the edwards25519 Group.
32func Sign(s Suite, private kyber.Scalar, msg []byte) ([]byte, error) {
33 var g kyber.Group = s
34 // create random secret k and public point commitment R
35 k := g.Scalar().Pick(s.RandomStream())
36 R := g.Point().Mul(k, nil)
37
38 // create hash(public || R || message)
39 public := g.Point().Mul(private, nil)
40 h, err := hash(g, public, R, msg)
41 if err != nil {
42 return nil, err
43 }
44
45 // compute response s = k + x*h
46 xh := g.Scalar().Mul(private, h)
47 S := g.Scalar().Add(k, xh)
48
49 // return R || s
50 var b bytes.Buffer
51 if _, err := R.MarshalTo(&b); err != nil {
52 return nil, err
53 }
54 if _, err := S.MarshalTo(&b); err != nil {
55 return nil, err
56 }
57 return b.Bytes(), nil
58}
59
60// Verify verifies a given Schnorr signature. It returns nil iff the
61// given signature is valid.

Callers 2

TestSchnorrSignatureFunction · 0.70
TestEdDSACompatibilityFunction · 0.70

Calls 8

hashFunction · 0.85
PickMethod · 0.45
ScalarMethod · 0.45
RandomStreamMethod · 0.45
MulMethod · 0.45
PointMethod · 0.45
AddMethod · 0.45
MarshalToMethod · 0.45

Tested by 2

TestSchnorrSignatureFunction · 0.56
TestEdDSACompatibilityFunction · 0.56