Beispiel #1
0
//Rename SignHash
func Sign(msg []byte, seckey []byte) []byte {

	if len(seckey) != 32 {
		log.Panic("Sign, Invalid seckey length")
	}
	if secp.SeckeyIsValid(seckey) != 1 {
		log.Panic("Attempting to sign with invalid seckey")
	}
	if msg == nil {
		log.Panic("Sign, message nil")
	}
	var nonce []byte = RandByte(32)
	var sig []byte = make([]byte, 65)
	var recid int

	var cSig secp.Signature

	var seckey1 secp.Number
	var msg1 secp.Number
	var nonce1 secp.Number

	seckey1.SetBytes(seckey)
	msg1.SetBytes(msg)
	nonce1.SetBytes(nonce)

	ret := cSig.Sign(&seckey1, &msg1, &nonce1, &recid)

	if ret != 1 {
		log.Panic("Secp25k1-go, Sign, signature operation failed")
	}

	sig_bytes := cSig.Bytes()
	for i := 0; i < 64; i++ {
		sig[i] = sig_bytes[i]
	}
	if len(sig_bytes) != 64 {
		log.Fatal("Invalid signature byte count: %s", len(sig_bytes))
	}
	sig[64] = byte(int(recid))

	if int(recid) > 4 {
		log.Panic()
	}

	return sig
}
Beispiel #2
0
//generate signature in repeatable way
func SignDeterministic(msg []byte, seckey []byte, nonce_seed []byte) []byte {
	nonce_seed2 := SumSHA256(nonce_seed) //deterministicly generate nonce

	var sig []byte = make([]byte, 65)
	var recid int

	var cSig secp.Signature

	var seckey1 secp.Number
	var msg1 secp.Number
	var nonce1 secp.Number

	seckey1.SetBytes(seckey)
	msg1.SetBytes(msg)
	nonce1.SetBytes(nonce_seed2)

	ret := cSig.Sign(&seckey1, &msg1, &nonce1, &recid)
	if ret != 1 {
		log.Panic("Secp256k1-go, SignDeterministic, signature fail")
	}

	sig_bytes := cSig.Bytes()
	for i := 0; i < 64; i++ {
		sig[i] = sig_bytes[i]
	}

	sig[64] = byte(recid)

	if len(sig_bytes) != 64 {
		log.Fatal("Invalid signature byte count: %s", len(sig_bytes))
	}

	if int(recid) > 4 {
		log.Panic()
	}

	return sig

}