Skip to content

Commit

Permalink
Added pub key recovery function
Browse files Browse the repository at this point in the history
  • Loading branch information
obscuren committed May 2, 2014
1 parent 1da95a0 commit 7a58ba7
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion secp256.go
Expand Up @@ -82,6 +82,26 @@ func GenerateKeyPair() ([]byte, []byte) {
return pubkey, seckey
}

func GeneratePubKey(seckey []byte) ([]byte, error) {
pubkey_len := C.int(65)
const seckey_len = 32

var pubkey []byte = make([]byte, pubkey_len)

var pubkey_ptr *C.uchar = (*C.uchar)(unsafe.Pointer(&pubkey[0]))
var seckey_ptr *C.uchar = (*C.uchar)(unsafe.Pointer(&seckey[0]))

ret := C.secp256k1_ecdsa_pubkey_create(
pubkey_ptr, &pubkey_len,
seckey_ptr, 0)

if ret != C.int(1) {
return nil, errors.New("Unable to generate pubkey from seckey")
}

return pubkey, nil
}

/*
* Create a compact ECDSA signature (64 byte + recovery id).
* Returns: 1: signature created
Expand All @@ -103,7 +123,11 @@ int secp256k1_ecdsa_sign_compact(const unsigned char *msg, int msglen,
*/

func Sign(msg []byte, seckey []byte) ([]byte, error) {
var nonce []byte = RandByte(32)
//var nonce []byte = RandByte(32)

This comment has been minimized.

This comment has been minimized.

Copy link
@obscuren

obscuren Apr 14, 2015

Owner

Were doing stupid things in code back then. Probably should remove this repo in favour of https://github.com/ethereum/go-ethereum/tree/develop/crypto/secp256k1

nonce := make([]byte, 32)
for i := range msg {
nonce[i] = msg[i] ^ seckey[i]
}

var sig []byte = make([]byte, 65)
var recid C.int
Expand Down

0 comments on commit 7a58ba7

Please sign in to comment.