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
04c1a815
Commit
04c1a815
authored
Feb 11, 2015
by
Jeffrey Wilcke
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2 from Gustav-Simonsson/correct_ecies_shared_key_generation
Correct ECIES shared key length check
parents
d899334b
52a46e61
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
12 deletions
+17
-12
ecies.go
ecies.go
+17
-12
No files found.
ecies.go
View file @
04c1a815
...
...
@@ -13,11 +13,12 @@ import (
)
var
(
ErrImport
=
fmt
.
Errorf
(
"ecies: failed to import key"
)
ErrInvalidCurve
=
fmt
.
Errorf
(
"ecies: invalid elliptic curve"
)
ErrInvalidParams
=
fmt
.
Errorf
(
"ecies: invalid ECIES parameters"
)
ErrInvalidPublicKey
=
fmt
.
Errorf
(
"ecies: invalid public key"
)
ErrSharedKeyTooBig
=
fmt
.
Errorf
(
"ecies: shared key is too big"
)
ErrImport
=
fmt
.
Errorf
(
"ecies: failed to import key"
)
ErrInvalidCurve
=
fmt
.
Errorf
(
"ecies: invalid elliptic curve"
)
ErrInvalidParams
=
fmt
.
Errorf
(
"ecies: invalid ECIES parameters"
)
ErrInvalidPublicKey
=
fmt
.
Errorf
(
"ecies: invalid public key"
)
ErrSharedKeyIsPointAtInfinity
=
fmt
.
Errorf
(
"ecies: shared key is point at infinity"
)
ErrSharedKeyTooBig
=
fmt
.
Errorf
(
"ecies: shared key params are too big"
)
)
// PublicKey is a representation of an elliptic curve public key.
...
...
@@ -90,16 +91,20 @@ func MaxSharedKeyLength(pub *PublicKey) int {
// ECDH key agreement method used to establish secret keys for encryption.
func
(
prv
*
PrivateKey
)
GenerateShared
(
pub
*
PublicKey
,
skLen
,
macLen
int
)
(
sk
[]
byte
,
err
error
)
{
if
prv
.
PublicKey
.
Curve
!=
pub
.
Curve
{
err
=
ErrInvalidCurve
return
return
nil
,
ErrInvalidCurve
}
if
skLen
+
macLen
>
MaxSharedKeyLength
(
pub
)
{
return
nil
,
ErrSharedKeyTooBig
}
x
,
_
:=
pub
.
Curve
.
ScalarMult
(
pub
.
X
,
pub
.
Y
,
prv
.
D
.
Bytes
())
if
x
==
nil
||
(
x
.
BitLen
()
+
7
)
/
8
<
(
skLen
+
macLen
)
{
err
=
ErrSharedKeyTooBig
return
if
x
==
nil
{
return
nil
,
ErrSharedKeyIsPointAtInfinity
}
sk
=
x
.
Bytes
()[
:
skLen
+
macLen
]
return
sk
=
make
([]
byte
,
skLen
+
macLen
)
skBytes
:=
x
.
Bytes
()
copy
(
sk
[
len
(
sk
)
-
len
(
skBytes
)
:
],
skBytes
)
return
sk
,
nil
}
var
(
...
...
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