forked from haltingstate/secp256k1-go
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
obscuren
committed
May 2, 2014
1 parent
1da95a0
commit 7a58ba7
Showing
1 changed file
with
25 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
obscuren
Owner
|
||
nonce := make([]byte, 32) | ||
for i := range msg { | ||
nonce[i] = msg[i] ^ seckey[i] | ||
} | ||
|
||
var sig []byte = make([]byte, 65) | ||
var recid C.int | ||
|
http://0xdabbad00.com/2015/04/12/looking_for_security_trouble_spots_in_go_code/