Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
27a50c8f
Commit
27a50c8f
authored
Sep 28, 2015
by
Gustav Simonsson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
core/secp256k1: update libsecp256k1 Go wrapper and tests
parent
66d47ced
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
18 deletions
+17
-18
secp256.go
crypto/secp256k1/secp256.go
+2
-2
secp256_test.go
crypto/secp256k1/secp256_test.go
+15
-16
No files found.
crypto/secp256k1/secp256.go
View file @
27a50c8f
...
@@ -96,7 +96,7 @@ func GenerateKeyPair() ([]byte, []byte) {
...
@@ -96,7 +96,7 @@ func GenerateKeyPair() ([]byte, []byte) {
var
output_len
C
.
size_t
var
output_len
C
.
size_t
C
.
secp256k1_ec_pubkey_serialize
(
// always returns 1
_
=
C
.
secp256k1_ec_pubkey_serialize
(
// always returns 1
context
,
context
,
pubkey65_ptr
,
pubkey65_ptr
,
&
output_len
,
&
output_len
,
...
@@ -163,7 +163,7 @@ func Sign(msg []byte, seckey []byte) ([]byte, error) {
...
@@ -163,7 +163,7 @@ func Sign(msg []byte, seckey []byte) ([]byte, error) {
sig_serialized_ptr
:=
(
*
C
.
uchar
)(
unsafe
.
Pointer
(
&
sig_serialized
[
0
]))
sig_serialized_ptr
:=
(
*
C
.
uchar
)(
unsafe
.
Pointer
(
&
sig_serialized
[
0
]))
var
recid
C
.
int
var
recid
C
.
int
C
.
secp256k1_ecdsa_recoverable_signature_serialize_compact
(
_
=
C
.
secp256k1_ecdsa_recoverable_signature_serialize_compact
(
context
,
context
,
sig_serialized_ptr
,
// 64 byte compact signature
sig_serialized_ptr
,
// 64 byte compact signature
&
recid
,
&
recid
,
...
...
crypto/secp256k1/secp256_test.go
View file @
27a50c8f
...
@@ -86,10 +86,7 @@ func TestSignAndRecover(t *testing.T) {
...
@@ -86,10 +86,7 @@ func TestSignAndRecover(t *testing.T) {
func
TestRandomMessagesWithSameKey
(
t
*
testing
.
T
)
{
func
TestRandomMessagesWithSameKey
(
t
*
testing
.
T
)
{
pubkey
,
seckey
:=
GenerateKeyPair
()
pubkey
,
seckey
:=
GenerateKeyPair
()
keys
:=
func
()
([]
byte
,
[]
byte
)
{
keys
:=
func
()
([]
byte
,
[]
byte
)
{
// Sign function zeroes the privkey so we need a new one in each call
return
pubkey
,
seckey
newkey
:=
make
([]
byte
,
len
(
seckey
))
copy
(
newkey
,
seckey
)
return
pubkey
,
newkey
}
}
signAndRecoverWithRandomMessages
(
t
,
keys
)
signAndRecoverWithRandomMessages
(
t
,
keys
)
}
}
...
@@ -209,30 +206,32 @@ func compactSigCheck(t *testing.T, sig []byte) {
...
@@ -209,30 +206,32 @@ func compactSigCheck(t *testing.T, sig []byte) {
}
}
}
}
// godep go test -v -run=XXX -bench=BenchmarkSign
RandomInputEachRound
// godep go test -v -run=XXX -bench=BenchmarkSign
// add -benchtime=10s to benchmark longer for more accurate average
// add -benchtime=10s to benchmark longer for more accurate average
func
BenchmarkSignRandomInputEachRound
(
b
*
testing
.
B
)
{
// to avoid compiler optimizing the benchmarked function call
var
err
error
func
BenchmarkSign
(
b
*
testing
.
B
)
{
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
b
.
StopTimer
()
_
,
seckey
:=
GenerateKeyPair
()
_
,
seckey
:=
GenerateKeyPair
()
msg
:=
randentropy
.
GetEntropyCSPRNG
(
32
)
msg
:=
randentropy
.
GetEntropyCSPRNG
(
32
)
b
.
StartTimer
()
b
.
StartTimer
()
if
_
,
err
:=
Sign
(
msg
,
seckey
);
err
!=
nil
{
_
,
e
:=
Sign
(
msg
,
seckey
)
b
.
Fatal
(
err
)
err
=
e
}
b
.
StopTimer
()
}
}
}
}
//godep go test -v -run=XXX -bench=Benchmark
RecoverRandomInputEachRound
//godep go test -v -run=XXX -bench=Benchmark
ECRec
func
BenchmarkRecover
RandomInputEachRound
(
b
*
testing
.
B
)
{
func
BenchmarkRecover
(
b
*
testing
.
B
)
{
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
b
.
StopTimer
()
_
,
seckey
:=
GenerateKeyPair
()
_
,
seckey
:=
GenerateKeyPair
()
msg
:=
randentropy
.
GetEntropyCSPRNG
(
32
)
msg
:=
randentropy
.
GetEntropyCSPRNG
(
32
)
sig
,
_
:=
Sign
(
msg
,
seckey
)
sig
,
_
:=
Sign
(
msg
,
seckey
)
b
.
StartTimer
()
b
.
StartTimer
()
if
_
,
err
:=
RecoverPubkey
(
msg
,
sig
);
err
!=
nil
{
_
,
e
:=
RecoverPubkey
(
msg
,
sig
)
b
.
Fatal
(
err
)
err
=
e
}
b
.
StopTimer
()
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment