Permalink
Browse files

Added pub key recovery function

  • Loading branch information...
obscuren
obscuren committed May 2, 2014
1 parent 1da95a0 commit 7a58ba75df031897c4cb94bb3b7792959fc06c22
Showing with 25 additions and 1 deletion.
  1. +25 −1 secp256.go
View
@@ -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
@@ -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.

Show comment
Hide comment
@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

@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

0 comments on commit 7a58ba7

Please sign in to comment.