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
f1534f57
Commit
f1534f57
authored
Mar 22, 2017
by
Felix Lange
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
trie, whisper/whisperv5: use math/rand Read function
parent
9a2720fb
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
23 additions
and
54 deletions
+23
-54
trie_test.go
trie/trie_test.go
+1
-17
filter_test.go
whisper/whisperv5/filter_test.go
+10
-10
message.go
whisper/whisperv5/message.go
+1
-17
message_test.go
whisper/whisperv5/message_test.go
+8
-8
whisper_test.go
whisper/whisperv5/whisper_test.go
+3
-2
No files found.
trie/trie_test.go
View file @
f1534f57
...
@@ -377,7 +377,7 @@ func (randTest) Generate(r *rand.Rand, size int) reflect.Value {
...
@@ -377,7 +377,7 @@ func (randTest) Generate(r *rand.Rand, size int) reflect.Value {
if
len
(
allKeys
)
<
2
||
r
.
Intn
(
100
)
<
10
{
if
len
(
allKeys
)
<
2
||
r
.
Intn
(
100
)
<
10
{
// new key
// new key
key
:=
make
([]
byte
,
r
.
Intn
(
50
))
key
:=
make
([]
byte
,
r
.
Intn
(
50
))
r
andRead
(
r
,
key
)
r
.
Read
(
key
)
allKeys
=
append
(
allKeys
,
key
)
allKeys
=
append
(
allKeys
,
key
)
return
key
return
key
}
}
...
@@ -401,22 +401,6 @@ func (randTest) Generate(r *rand.Rand, size int) reflect.Value {
...
@@ -401,22 +401,6 @@ func (randTest) Generate(r *rand.Rand, size int) reflect.Value {
return
reflect
.
ValueOf
(
steps
)
return
reflect
.
ValueOf
(
steps
)
}
}
// rand.Rand provides a Read method in Go 1.7 and later, but
// we can't use it yet.
func
randRead
(
r
*
rand
.
Rand
,
b
[]
byte
)
{
pos
:=
0
val
:=
0
for
n
:=
0
;
n
<
len
(
b
);
n
++
{
if
pos
==
0
{
val
=
r
.
Int
()
pos
=
7
}
b
[
n
]
=
byte
(
val
)
val
>>=
8
pos
--
}
}
func
runRandTest
(
rt
randTest
)
bool
{
func
runRandTest
(
rt
randTest
)
bool
{
db
,
_
:=
ethdb
.
NewMemDatabase
()
db
,
_
:=
ethdb
.
NewMemDatabase
()
tr
,
_
:=
New
(
common
.
Hash
{},
db
)
tr
,
_
:=
New
(
common
.
Hash
{},
db
)
...
...
whisper/whisperv5/filter_test.go
View file @
f1534f57
...
@@ -18,7 +18,7 @@ package whisperv5
...
@@ -18,7 +18,7 @@ package whisperv5
import
(
import
(
"math/big"
"math/big"
"math/rand"
mrand
"math/rand"
"testing"
"testing"
"time"
"time"
...
@@ -33,12 +33,12 @@ var seed int64
...
@@ -33,12 +33,12 @@ var seed int64
// reproduciblity independent of their sequence.
// reproduciblity independent of their sequence.
func
InitSingleTest
()
{
func
InitSingleTest
()
{
seed
=
time
.
Now
()
.
Unix
()
seed
=
time
.
Now
()
.
Unix
()
rand
.
Seed
(
seed
)
m
rand
.
Seed
(
seed
)
}
}
func
InitDebugTest
(
i
int64
)
{
func
InitDebugTest
(
i
int64
)
{
seed
=
i
seed
=
i
rand
.
Seed
(
seed
)
m
rand
.
Seed
(
seed
)
}
}
type
FilterTestCase
struct
{
type
FilterTestCase
struct
{
...
@@ -55,7 +55,7 @@ func generateFilter(t *testing.T, symmetric bool) (*Filter, error) {
...
@@ -55,7 +55,7 @@ func generateFilter(t *testing.T, symmetric bool) (*Filter, error) {
const
topicNum
=
8
const
topicNum
=
8
f
.
Topics
=
make
([]
TopicType
,
topicNum
)
f
.
Topics
=
make
([]
TopicType
,
topicNum
)
for
i
:=
0
;
i
<
topicNum
;
i
++
{
for
i
:=
0
;
i
<
topicNum
;
i
++
{
randomize
(
f
.
Topics
[
i
][
:
])
mrand
.
Read
(
f
.
Topics
[
i
][
:
])
f
.
Topics
[
i
][
0
]
=
0x01
f
.
Topics
[
i
][
0
]
=
0x01
}
}
...
@@ -68,7 +68,7 @@ func generateFilter(t *testing.T, symmetric bool) (*Filter, error) {
...
@@ -68,7 +68,7 @@ func generateFilter(t *testing.T, symmetric bool) (*Filter, error) {
if
symmetric
{
if
symmetric
{
f
.
KeySym
=
make
([]
byte
,
12
)
f
.
KeySym
=
make
([]
byte
,
12
)
randomize
(
f
.
KeySym
)
mrand
.
Read
(
f
.
KeySym
)
f
.
SymKeyHash
=
crypto
.
Keccak256Hash
(
f
.
KeySym
)
f
.
SymKeyHash
=
crypto
.
Keccak256Hash
(
f
.
KeySym
)
}
else
{
}
else
{
f
.
KeyAsym
,
err
=
crypto
.
GenerateKey
()
f
.
KeyAsym
,
err
=
crypto
.
GenerateKey
()
...
@@ -87,7 +87,7 @@ func generateTestCases(t *testing.T, SizeTestFilters int) []FilterTestCase {
...
@@ -87,7 +87,7 @@ func generateTestCases(t *testing.T, SizeTestFilters int) []FilterTestCase {
for
i
:=
0
;
i
<
SizeTestFilters
;
i
++
{
for
i
:=
0
;
i
<
SizeTestFilters
;
i
++
{
f
,
_
:=
generateFilter
(
t
,
true
)
f
,
_
:=
generateFilter
(
t
,
true
)
cases
[
i
]
.
f
=
f
cases
[
i
]
.
f
=
f
cases
[
i
]
.
alive
=
(
rand
.
Int
()
&
int
(
1
)
==
0
)
cases
[
i
]
.
alive
=
(
m
rand
.
Int
()
&
int
(
1
)
==
0
)
}
}
return
cases
return
cases
}
}
...
@@ -147,7 +147,7 @@ func TestComparePubKey(t *testing.T) {
...
@@ -147,7 +147,7 @@ func TestComparePubKey(t *testing.T) {
}
}
// generate key3 == key1
// generate key3 == key1
rand
.
Seed
(
seed
)
m
rand
.
Seed
(
seed
)
key3
,
err
:=
crypto
.
GenerateKey
()
key3
,
err
:=
crypto
.
GenerateKey
()
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"failed to generate third key with seed %d: %s."
,
seed
,
err
)
t
.
Fatalf
(
"failed to generate third key with seed %d: %s."
,
seed
,
err
)
...
@@ -193,7 +193,7 @@ func TestMatchEnvelope(t *testing.T) {
...
@@ -193,7 +193,7 @@ func TestMatchEnvelope(t *testing.T) {
}
}
// encrypt symmetrically
// encrypt symmetrically
i
:=
rand
.
Int
()
%
4
i
:=
m
rand
.
Int
()
%
4
fsym
.
Topics
[
i
]
=
params
.
Topic
fsym
.
Topics
[
i
]
=
params
.
Topic
fasym
.
Topics
[
i
]
=
params
.
Topic
fasym
.
Topics
[
i
]
=
params
.
Topic
msg
=
NewSentMessage
(
params
)
msg
=
NewSentMessage
(
params
)
...
@@ -544,7 +544,7 @@ func TestWatchers(t *testing.T) {
...
@@ -544,7 +544,7 @@ func TestWatchers(t *testing.T) {
var
envelopes
[
NumMessages
]
*
Envelope
var
envelopes
[
NumMessages
]
*
Envelope
for
i
=
0
;
i
<
NumMessages
;
i
++
{
for
i
=
0
;
i
<
NumMessages
;
i
++
{
j
=
rand
.
Uint32
()
%
NumFilters
j
=
m
rand
.
Uint32
()
%
NumFilters
e
=
generateCompatibeEnvelope
(
t
,
tst
[
j
]
.
f
)
e
=
generateCompatibeEnvelope
(
t
,
tst
[
j
]
.
f
)
envelopes
[
i
]
=
e
envelopes
[
i
]
=
e
tst
[
j
]
.
msgCnt
++
tst
[
j
]
.
msgCnt
++
...
@@ -597,7 +597,7 @@ func TestWatchers(t *testing.T) {
...
@@ -597,7 +597,7 @@ func TestWatchers(t *testing.T) {
envelopes
[
0
]
=
e
envelopes
[
0
]
=
e
tst
[
0
]
.
msgCnt
++
tst
[
0
]
.
msgCnt
++
for
i
=
1
;
i
<
NumMessages
;
i
++
{
for
i
=
1
;
i
<
NumMessages
;
i
++
{
j
=
rand
.
Uint32
()
%
NumFilters
j
=
m
rand
.
Uint32
()
%
NumFilters
e
=
generateCompatibeEnvelope
(
t
,
tst
[
j
]
.
f
)
e
=
generateCompatibeEnvelope
(
t
,
tst
[
j
]
.
f
)
envelopes
[
i
]
=
e
envelopes
[
i
]
=
e
tst
[
j
]
.
msgCnt
++
tst
[
j
]
.
msgCnt
++
...
...
whisper/whisperv5/message.go
View file @
f1534f57
...
@@ -128,7 +128,7 @@ func (msg *SentMessage) appendPadding(params *MessageParams) {
...
@@ -128,7 +128,7 @@ func (msg *SentMessage) appendPadding(params *MessageParams) {
panic
(
"please fix the padding algorithm before releasing new version"
)
panic
(
"please fix the padding algorithm before releasing new version"
)
}
}
buf
:=
make
([]
byte
,
padSize
)
buf
:=
make
([]
byte
,
padSize
)
randomize
(
buf
[
1
:
])
mrand
.
Read
(
buf
[
1
:
])
buf
[
0
]
=
byte
(
padSize
)
buf
[
0
]
=
byte
(
padSize
)
if
params
.
Padding
!=
nil
{
if
params
.
Padding
!=
nil
{
copy
(
buf
[
1
:
],
params
.
Padding
)
copy
(
buf
[
1
:
],
params
.
Padding
)
...
@@ -365,19 +365,3 @@ func (msg *ReceivedMessage) hash() []byte {
...
@@ -365,19 +365,3 @@ func (msg *ReceivedMessage) hash() []byte {
}
}
return
crypto
.
Keccak256
(
msg
.
Raw
)
return
crypto
.
Keccak256
(
msg
.
Raw
)
}
}
// rand.Rand provides a Read method in Go 1.7 and later,
// but we can't use it yet.
func
randomize
(
b
[]
byte
)
{
cnt
:=
0
val
:=
mrand
.
Int63
()
for
n
:=
0
;
n
<
len
(
b
);
n
++
{
b
[
n
]
=
byte
(
val
)
val
>>=
8
cnt
++
if
cnt
>=
7
{
cnt
=
0
val
=
mrand
.
Int63
()
}
}
}
whisper/whisperv5/message_test.go
View file @
f1534f57
...
@@ -18,7 +18,7 @@ package whisperv5
...
@@ -18,7 +18,7 @@ package whisperv5
import
(
import
(
"bytes"
"bytes"
"math/rand"
mrand
"math/rand"
"testing"
"testing"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/crypto"
...
@@ -34,13 +34,13 @@ func generateMessageParams() (*MessageParams, error) {
...
@@ -34,13 +34,13 @@ func generateMessageParams() (*MessageParams, error) {
// set all the parameters except p.Dst
// set all the parameters except p.Dst
buf
:=
make
([]
byte
,
1024
)
buf
:=
make
([]
byte
,
1024
)
randomize
(
buf
)
mrand
.
Read
(
buf
)
sz
:=
rand
.
Intn
(
400
)
sz
:=
m
rand
.
Intn
(
400
)
var
p
MessageParams
var
p
MessageParams
p
.
PoW
=
0.01
p
.
PoW
=
0.01
p
.
WorkTime
=
1
p
.
WorkTime
=
1
p
.
TTL
=
uint32
(
rand
.
Intn
(
1024
))
p
.
TTL
=
uint32
(
m
rand
.
Intn
(
1024
))
p
.
Payload
=
make
([]
byte
,
sz
)
p
.
Payload
=
make
([]
byte
,
sz
)
p
.
Padding
=
make
([]
byte
,
padSizeLimitUpper
)
p
.
Padding
=
make
([]
byte
,
padSizeLimitUpper
)
p
.
KeySym
=
make
([]
byte
,
aesKeyLength
)
p
.
KeySym
=
make
([]
byte
,
aesKeyLength
)
...
@@ -132,7 +132,7 @@ func TestMessageEncryption(t *testing.T) {
...
@@ -132,7 +132,7 @@ func TestMessageEncryption(t *testing.T) {
func
TestMessageWrap
(
t
*
testing
.
T
)
{
func
TestMessageWrap
(
t
*
testing
.
T
)
{
seed
=
int64
(
1777444222
)
seed
=
int64
(
1777444222
)
rand
.
Seed
(
seed
)
m
rand
.
Seed
(
seed
)
target
:=
128.0
target
:=
128.0
params
,
err
:=
generateMessageParams
()
params
,
err
:=
generateMessageParams
()
...
@@ -168,7 +168,7 @@ func TestMessageWrap(t *testing.T) {
...
@@ -168,7 +168,7 @@ func TestMessageWrap(t *testing.T) {
func
TestMessageSeal
(
t
*
testing
.
T
)
{
func
TestMessageSeal
(
t
*
testing
.
T
)
{
// this test depends on deterministic choice of seed (1976726903)
// this test depends on deterministic choice of seed (1976726903)
seed
=
int64
(
1976726903
)
seed
=
int64
(
1976726903
)
rand
.
Seed
(
seed
)
m
rand
.
Seed
(
seed
)
params
,
err
:=
generateMessageParams
()
params
,
err
:=
generateMessageParams
()
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -179,8 +179,8 @@ func TestMessageSeal(t *testing.T) {
...
@@ -179,8 +179,8 @@ func TestMessageSeal(t *testing.T) {
params
.
TTL
=
1
params
.
TTL
=
1
aesnonce
:=
make
([]
byte
,
12
)
aesnonce
:=
make
([]
byte
,
12
)
salt
:=
make
([]
byte
,
12
)
salt
:=
make
([]
byte
,
12
)
randomize
(
aesnonce
)
mrand
.
Read
(
aesnonce
)
randomize
(
salt
)
mrand
.
Read
(
salt
)
env
:=
NewEnvelope
(
params
.
TTL
,
params
.
Topic
,
salt
,
aesnonce
,
msg
)
env
:=
NewEnvelope
(
params
.
TTL
,
params
.
Topic
,
salt
,
aesnonce
,
msg
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
whisper/whisperv5/whisper_test.go
View file @
f1534f57
...
@@ -18,6 +18,7 @@ package whisperv5
...
@@ -18,6 +18,7 @@ package whisperv5
import
(
import
(
"bytes"
"bytes"
mrand
"math/rand"
"testing"
"testing"
"time"
"time"
...
@@ -49,7 +50,7 @@ func TestWhisperBasic(t *testing.T) {
...
@@ -49,7 +50,7 @@ func TestWhisperBasic(t *testing.T) {
}
}
peerID
:=
make
([]
byte
,
64
)
peerID
:=
make
([]
byte
,
64
)
randomize
(
peerID
)
mrand
.
Read
(
peerID
)
peer
,
_
:=
w
.
getPeer
(
peerID
)
peer
,
_
:=
w
.
getPeer
(
peerID
)
if
peer
!=
nil
{
if
peer
!=
nil
{
t
.
Fatal
(
"found peer for random key."
)
t
.
Fatal
(
"found peer for random key."
)
...
@@ -212,7 +213,7 @@ func TestWhisperSymKeyManagement(t *testing.T) {
...
@@ -212,7 +213,7 @@ func TestWhisperSymKeyManagement(t *testing.T) {
// add existing id, nothing should change
// add existing id, nothing should change
randomKey
:=
make
([]
byte
,
16
)
randomKey
:=
make
([]
byte
,
16
)
randomize
(
randomKey
)
mrand
.
Read
(
randomKey
)
err
=
w
.
AddSymKey
(
id1
,
randomKey
)
err
=
w
.
AddSymKey
(
id1
,
randomKey
)
if
err
==
nil
{
if
err
==
nil
{
t
.
Fatalf
(
"failed AddSymKey with seed %d."
,
seed
)
t
.
Fatalf
(
"failed AddSymKey with seed %d."
,
seed
)
...
...
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