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
96778a1c
Commit
96778a1c
authored
Jan 22, 2017
by
Felix Lange
Committed by
GitHub
Jan 22, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
crypto/secp256k1: sign with deterministic K (rfc6979) (#3561)
parent
935d891e
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
8 deletions
+22
-8
secp256.go
crypto/secp256k1/secp256.go
+4
-8
secp256_test.go
crypto/secp256k1/secp256_test.go
+18
-0
No files found.
crypto/secp256k1/secp256.go
View file @
96778a1c
...
...
@@ -40,8 +40,6 @@ import (
"errors"
"math/big"
"unsafe"
"github.com/ethereum/go-ethereum/crypto/randentropy"
)
var
(
...
...
@@ -90,12 +88,10 @@ func Sign(msg []byte, seckey []byte) ([]byte, error) {
var
(
msgdata
=
(
*
C
.
uchar
)(
unsafe
.
Pointer
(
&
msg
[
0
]))
nonce
=
randentropy
.
GetEntropyCSPRNG
(
32
)
noncefunc
=
&
(
*
C
.
secp256k1_nonce_function_default
)
noncefuncData
=
unsafe
.
Pointer
(
&
nonce
[
0
])
noncefunc
=
C
.
secp256k1_nonce_function_rfc6979
sigstruct
C
.
secp256k1_ecdsa_recoverable_signature
)
if
C
.
secp256k1_ecdsa_sign_recoverable
(
context
,
&
sigstruct
,
msgdata
,
seckeydata
,
noncefunc
,
n
oncefuncData
)
==
0
{
if
C
.
secp256k1_ecdsa_sign_recoverable
(
context
,
&
sigstruct
,
msgdata
,
seckeydata
,
noncefunc
,
n
il
)
==
0
{
return
nil
,
ErrSignFailed
}
...
...
crypto/secp256k1/secp256_test.go
View file @
96778a1c
...
...
@@ -112,6 +112,24 @@ func TestSignAndRecover(t *testing.T) {
}
}
func
TestSignDeterministic
(
t
*
testing
.
T
)
{
_
,
seckey
:=
generateKeyPair
()
msg
:=
make
([]
byte
,
32
)
copy
(
msg
,
"hi there"
)
sig1
,
err
:=
Sign
(
msg
,
seckey
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
sig2
,
err
:=
Sign
(
msg
,
seckey
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
!
bytes
.
Equal
(
sig1
,
sig2
)
{
t
.
Fatal
(
"signatures not equal"
)
}
}
func
TestRandomMessagesWithSameKey
(
t
*
testing
.
T
)
{
pubkey
,
seckey
:=
generateKeyPair
()
keys
:=
func
()
([]
byte
,
[]
byte
)
{
...
...
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