good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
bor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open
bor
Commits
f35d62b7
Commit
f35d62b7
authored
Feb 13, 2015
by
Gustav Simonsson
Browse files
Options
Downloads
Patches
Plain Diff
Remove secp256_rand.go and update tests
parent
39434e38
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
crypto/secp256k1/secp256_rand.go
+0
-97
0 additions, 97 deletions
crypto/secp256k1/secp256_rand.go
crypto/secp256k1/secp256_test.go
+11
-10
11 additions, 10 deletions
crypto/secp256k1/secp256_test.go
with
11 additions
and
107 deletions
crypto/secp256k1/secp256_rand.go
deleted
100644 → 0
+
0
−
97
View file @
39434e38
package
secp256k1
import
(
crand
"crypto/rand"
"io"
mrand
"math/rand"
"os"
"strings"
"time"
)
/*
Note:
- On windows cryto/rand uses CrytoGenRandom which uses RC4 which is insecure
- Android random number generator is known to be insecure.
- Linux uses /dev/urandom , which is thought to be secure and uses entropy pool
Therefore the output is salted.
*/
//finalizer from MurmerHash3
func
mmh3f
(
key
uint64
)
uint64
{
key
^=
key
>>
33
key
*=
0xff51afd7ed558ccd
key
^=
key
>>
33
key
*=
0xc4ceb9fe1a85ec53
key
^=
key
>>
33
return
key
}
//knuth hash
func
knuth_hash
(
in
[]
byte
)
uint64
{
var
acc
uint64
=
3074457345618258791
for
i
:=
0
;
i
<
len
(
in
);
i
++
{
acc
+=
uint64
(
in
[
i
])
acc
*=
3074457345618258799
}
return
acc
}
var
_rand
*
mrand
.
Rand
func
init
()
{
var
seed1
uint64
=
mmh3f
(
uint64
(
time
.
Now
()
.
UnixNano
()))
var
seed2
uint64
=
knuth_hash
([]
byte
(
strings
.
Join
(
os
.
Environ
(),
""
)))
var
seed3
uint64
=
mmh3f
(
uint64
(
os
.
Getpid
()))
_rand
=
mrand
.
New
(
mrand
.
NewSource
(
int64
(
seed1
^
seed2
^
seed3
)))
}
func
saltByte
(
n
int
)
[]
byte
{
buff
:=
make
([]
byte
,
n
)
for
i
:=
0
;
i
<
len
(
buff
);
i
++
{
var
v
uint64
=
uint64
(
_rand
.
Int63
())
var
b
byte
for
j
:=
0
;
j
<
8
;
j
++
{
b
^=
byte
(
v
&
0xff
)
v
=
v
>>
8
}
buff
[
i
]
=
b
}
return
buff
}
//On Unix-like systems, Reader reads from /dev/urandom.
//On Windows systems, Reader uses the CryptGenRandom API.
//use entropy pool etc and cryptographic random number generator
//mix in time
//mix in mix in cpu cycle count
func
RandByte
(
n
int
)
[]
byte
{
buff
:=
make
([]
byte
,
n
)
ret
,
err
:=
io
.
ReadFull
(
crand
.
Reader
,
buff
)
if
len
(
buff
)
!=
ret
||
err
!=
nil
{
return
nil
}
buff2
:=
saltByte
(
n
)
for
i
:=
0
;
i
<
n
;
i
++
{
buff
[
i
]
^=
buff2
[
2
]
}
return
buff
}
/*
On Unix-like systems, Reader reads from /dev/urandom.
On Windows systems, Reader uses the CryptGenRandom API.
*/
func
RandByteWeakCrypto
(
n
int
)
[]
byte
{
buff
:=
make
([]
byte
,
n
)
ret
,
err
:=
io
.
ReadFull
(
crand
.
Reader
,
buff
)
if
len
(
buff
)
!=
ret
||
err
!=
nil
{
return
nil
}
return
buff
}
This diff is collapsed.
Click to expand it.
crypto/secp256k1/secp256_test.go
+
11
−
10
View file @
f35d62b7
...
...
@@ -3,6 +3,7 @@ package secp256k1
import
(
"bytes"
"fmt"
"github.com/ethereum/go-ethereum/crypto/randentropy"
"log"
"testing"
)
...
...
@@ -12,7 +13,7 @@ const SigSize = 65 //64+1
func
Test_Secp256_00
(
t
*
testing
.
T
)
{
var
nonce
[]
byte
=
R
and
Byte
(
32
)
//going to get bitcoins stolen!
var
nonce
[]
byte
=
r
and
entropy
.
GetEntropyMixed
(
32
)
//going to get bitcoins stolen!
if
len
(
nonce
)
!=
32
{
t
.
Fatal
()
...
...
@@ -50,7 +51,7 @@ func Test_Secp256_01(t *testing.T) {
//test size of messages
func
Test_Secp256_02s
(
t
*
testing
.
T
)
{
pubkey
,
seckey
:=
GenerateKeyPair
()
msg
:=
R
and
Byte
(
32
)
msg
:=
r
and
entropy
.
GetEntropyMixed
(
32
)
sig
,
_
:=
Sign
(
msg
,
seckey
)
CompactSigTest
(
sig
)
if
sig
==
nil
{
...
...
@@ -73,7 +74,7 @@ func Test_Secp256_02s(t *testing.T) {
//test signing message
func
Test_Secp256_02
(
t
*
testing
.
T
)
{
pubkey1
,
seckey
:=
GenerateKeyPair
()
msg
:=
R
and
Byte
(
32
)
msg
:=
r
and
entropy
.
GetEntropyMixed
(
32
)
sig
,
_
:=
Sign
(
msg
,
seckey
)
if
sig
==
nil
{
t
.
Fatal
(
"Signature nil"
)
...
...
@@ -96,7 +97,7 @@ func Test_Secp256_02(t *testing.T) {
//test pubkey recovery
func
Test_Secp256_02a
(
t
*
testing
.
T
)
{
pubkey1
,
seckey1
:=
GenerateKeyPair
()
msg
:=
R
and
Byte
(
32
)
msg
:=
r
and
entropy
.
GetEntropyMixed
(
32
)
sig
,
_
:=
Sign
(
msg
,
seckey1
)
if
sig
==
nil
{
...
...
@@ -125,7 +126,7 @@ func Test_Secp256_02a(t *testing.T) {
func
Test_Secp256_03
(
t
*
testing
.
T
)
{
_
,
seckey
:=
GenerateKeyPair
()
for
i
:=
0
;
i
<
TESTS
;
i
++
{
msg
:=
R
and
Byte
(
32
)
msg
:=
r
and
entropy
.
GetEntropyMixed
(
32
)
sig
,
_
:=
Sign
(
msg
,
seckey
)
CompactSigTest
(
sig
)
...
...
@@ -141,7 +142,7 @@ func Test_Secp256_03(t *testing.T) {
func
Test_Secp256_04
(
t
*
testing
.
T
)
{
for
i
:=
0
;
i
<
TESTS
;
i
++
{
pubkey1
,
seckey
:=
GenerateKeyPair
()
msg
:=
R
and
Byte
(
32
)
msg
:=
r
and
entropy
.
GetEntropyMixed
(
32
)
sig
,
_
:=
Sign
(
msg
,
seckey
)
CompactSigTest
(
sig
)
...
...
@@ -164,7 +165,7 @@ func Test_Secp256_04(t *testing.T) {
// -SIPA look at this
func
randSig
()
[]
byte
{
sig
:=
R
and
Byte
(
65
)
sig
:=
r
and
entropy
.
GetEntropyMixed
(
65
)
sig
[
32
]
&=
0x70
sig
[
64
]
%=
4
return
sig
...
...
@@ -172,7 +173,7 @@ func randSig() []byte {
func
Test_Secp256_06a_alt0
(
t
*
testing
.
T
)
{
pubkey1
,
seckey
:=
GenerateKeyPair
()
msg
:=
R
and
Byte
(
32
)
msg
:=
r
and
entropy
.
GetEntropyMixed
(
32
)
sig
,
_
:=
Sign
(
msg
,
seckey
)
if
sig
==
nil
{
...
...
@@ -203,12 +204,12 @@ func Test_Secp256_06a_alt0(t *testing.T) {
func
Test_Secp256_06b
(
t
*
testing
.
T
)
{
pubkey1
,
seckey
:=
GenerateKeyPair
()
msg
:=
R
and
Byte
(
32
)
msg
:=
r
and
entropy
.
GetEntropyMixed
(
32
)
sig
,
_
:=
Sign
(
msg
,
seckey
)
fail_count
:=
0
for
i
:=
0
;
i
<
TESTS
;
i
++
{
msg
=
R
and
Byte
(
32
)
msg
=
r
and
entropy
.
GetEntropyMixed
(
32
)
pubkey2
,
_
:=
RecoverPubkey
(
msg
,
sig
)
if
bytes
.
Equal
(
pubkey1
,
pubkey2
)
==
true
{
t
.
Fail
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment