Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
whqwjb
go-ethereum
提交
aa734202
G
go-ethereum
项目概览
whqwjb
/
go-ethereum
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
go-ethereum
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
aa734202
编写于
5月 23, 2017
作者:
P
Péter Szilágyi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
accounts/keystore, crypto: enforce 256 bit keys on import
上级
35569620
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
32 addition
and
31 deletion
+32
-31
accounts/keystore/key.go
accounts/keystore/key.go
+2
-3
accounts/keystore/keystore.go
accounts/keystore/keystore.go
+0
-1
accounts/keystore/keystore_passphrase.go
accounts/keystore/keystore_passphrase.go
+4
-1
accounts/keystore/keystore_passphrase_test.go
accounts/keystore/keystore_passphrase_test.go
+1
-1
accounts/keystore/presale.go
accounts/keystore/presale.go
+4
-1
core/types/transaction_test.go
core/types/transaction_test.go
+1
-1
crypto/crypto.go
crypto/crypto.go
+12
-15
internal/ethapi/api.go
internal/ethapi/api.go
+2
-4
swarm/api/config_test.go
swarm/api/config_test.go
+4
-1
tests/util.go
tests/util.go
+2
-3
未找到文件。
accounts/keystore/key.go
浏览文件 @
aa734202
...
...
@@ -124,14 +124,13 @@ func (k *Key) UnmarshalJSON(j []byte) (err error) {
if
err
!=
nil
{
return
err
}
privkey
,
err
:=
hex
.
DecodeString
(
keyJSON
.
PrivateKey
)
privkey
,
err
:=
crypto
.
HexToECDSA
(
keyJSON
.
PrivateKey
)
if
err
!=
nil
{
return
err
}
k
.
Address
=
common
.
BytesToAddress
(
addr
)
k
.
PrivateKey
=
crypto
.
ToECDSA
(
privkey
)
k
.
PrivateKey
=
privkey
return
nil
}
...
...
accounts/keystore/keystore.go
浏览文件 @
aa734202
...
...
@@ -450,7 +450,6 @@ func (ks *KeyStore) ImportECDSA(priv *ecdsa.PrivateKey, passphrase string) (acco
if
ks
.
cache
.
hasAddress
(
key
.
Address
)
{
return
accounts
.
Account
{},
fmt
.
Errorf
(
"account already exists"
)
}
return
ks
.
importKey
(
key
,
passphrase
)
}
...
...
accounts/keystore/keystore_passphrase.go
浏览文件 @
aa734202
...
...
@@ -182,7 +182,10 @@ func DecryptKey(keyjson []byte, auth string) (*Key, error) {
if
err
!=
nil
{
return
nil
,
err
}
key
:=
crypto
.
ToECDSA
(
keyBytes
)
key
,
err
:=
crypto
.
ToECDSA
(
keyBytes
)
if
err
!=
nil
{
return
nil
,
err
}
return
&
Key
{
Id
:
uuid
.
UUID
(
keyId
),
Address
:
crypto
.
PubkeyToAddress
(
key
.
PublicKey
),
...
...
accounts/keystore/keystore_passphrase_test.go
浏览文件 @
aa734202
...
...
@@ -46,7 +46,7 @@ func TestKeyEncryptDecrypt(t *testing.T) {
// Decrypt with the correct password
key
,
err
:=
DecryptKey
(
keyjson
,
password
)
if
err
!=
nil
{
t
.
Error
f
(
"test %d: json key failed to decrypt: %v"
,
i
,
err
)
t
.
Fatal
f
(
"test %d: json key failed to decrypt: %v"
,
i
,
err
)
}
if
key
.
Address
!=
address
{
t
.
Errorf
(
"test %d: key address mismatch: have %x, want %x"
,
i
,
key
.
Address
,
address
)
...
...
accounts/keystore/presale.go
浏览文件 @
aa734202
...
...
@@ -74,7 +74,10 @@ func decryptPreSaleKey(fileContent []byte, password string) (key *Key, err error
return
nil
,
err
}
ethPriv
:=
crypto
.
Keccak256
(
plainText
)
ecKey
:=
crypto
.
ToECDSA
(
ethPriv
)
ecKey
,
err
:=
crypto
.
ToECDSA
(
ethPriv
)
if
err
!=
nil
{
return
nil
,
err
}
key
=
&
Key
{
Id
:
nil
,
Address
:
crypto
.
PubkeyToAddress
(
ecKey
.
PublicKey
),
...
...
core/types/transaction_test.go
浏览文件 @
aa734202
...
...
@@ -79,7 +79,7 @@ func decodeTx(data []byte) (*Transaction, error) {
}
func
defaultTestKey
()
(
*
ecdsa
.
PrivateKey
,
common
.
Address
)
{
key
:=
crypto
.
ToECDSA
(
common
.
Hex2Bytes
(
"45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8"
)
)
key
,
_
:=
crypto
.
HexToECDSA
(
"45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8"
)
addr
:=
crypto
.
PubkeyToAddress
(
key
.
PublicKey
)
return
key
,
addr
}
...
...
crypto/crypto.go
浏览文件 @
aa734202
...
...
@@ -22,12 +22,14 @@ import (
"crypto/rand"
"encoding/hex"
"errors"
"fmt"
"io"
"io/ioutil"
"math/big"
"os"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/crypto/sha3"
"github.com/ethereum/go-ethereum/rlp"
)
...
...
@@ -76,23 +78,22 @@ func CreateAddress(b common.Address, nonce uint64) common.Address {
}
// ToECDSA creates a private key with the given D value.
func
ToECDSA
(
prv
[]
byte
)
*
ecdsa
.
PrivateKey
{
if
len
(
prv
)
==
0
{
return
nil
}
func
ToECDSA
(
d
[]
byte
)
(
*
ecdsa
.
PrivateKey
,
error
)
{
priv
:=
new
(
ecdsa
.
PrivateKey
)
priv
.
PublicKey
.
Curve
=
S256
()
priv
.
D
=
new
(
big
.
Int
)
.
SetBytes
(
prv
)
priv
.
PublicKey
.
X
,
priv
.
PublicKey
.
Y
=
priv
.
PublicKey
.
Curve
.
ScalarBaseMult
(
prv
)
return
priv
if
8
*
len
(
d
)
!=
priv
.
Params
()
.
BitSize
{
return
nil
,
fmt
.
Errorf
(
"invalid length, need %d bits"
,
priv
.
Params
()
.
BitSize
)
}
priv
.
D
=
new
(
big
.
Int
)
.
SetBytes
(
d
)
priv
.
PublicKey
.
X
,
priv
.
PublicKey
.
Y
=
priv
.
PublicKey
.
Curve
.
ScalarBaseMult
(
d
)
return
priv
,
nil
}
func
FromECDSA
(
prv
*
ecdsa
.
PrivateKey
)
[]
byte
{
if
prv
==
nil
{
return
nil
}
return
prv
.
D
.
Bytes
(
)
return
math
.
PaddedBigBytes
(
prv
.
D
,
32
)
}
func
ToECDSAPub
(
pub
[]
byte
)
*
ecdsa
.
PublicKey
{
...
...
@@ -116,10 +117,7 @@ func HexToECDSA(hexkey string) (*ecdsa.PrivateKey, error) {
if
err
!=
nil
{
return
nil
,
errors
.
New
(
"invalid hex string"
)
}
if
len
(
b
)
!=
32
{
return
nil
,
errors
.
New
(
"invalid length, need 256 bits"
)
}
return
ToECDSA
(
b
),
nil
return
ToECDSA
(
b
)
}
// LoadECDSA loads a secp256k1 private key from the given file.
...
...
@@ -139,8 +137,7 @@ func LoadECDSA(file string) (*ecdsa.PrivateKey, error) {
if
err
!=
nil
{
return
nil
,
err
}
return
ToECDSA
(
key
),
nil
return
ToECDSA
(
key
)
}
// SaveECDSA saves a secp256k1 private key to the given file with
...
...
internal/ethapi/api.go
浏览文件 @
aa734202
...
...
@@ -19,7 +19,6 @@ package ethapi
import
(
"bytes"
"context"
"encoding/hex"
"errors"
"fmt"
"math/big"
...
...
@@ -283,12 +282,11 @@ func fetchKeystore(am *accounts.Manager) *keystore.KeyStore {
// ImportRawKey stores the given hex encoded ECDSA key into the key directory,
// encrypting it with the passphrase.
func
(
s
*
PrivateAccountAPI
)
ImportRawKey
(
privkey
string
,
password
string
)
(
common
.
Address
,
error
)
{
hexkey
,
err
:=
hex
.
DecodeString
(
privkey
)
key
,
err
:=
crypto
.
HexToECDSA
(
privkey
)
if
err
!=
nil
{
return
common
.
Address
{},
err
}
acc
,
err
:=
fetchKeystore
(
s
.
am
)
.
ImportECDSA
(
crypto
.
ToECDSA
(
hexkey
),
password
)
acc
,
err
:=
fetchKeystore
(
s
.
am
)
.
ImportECDSA
(
key
,
password
)
return
acc
.
Address
,
err
}
...
...
swarm/api/config_test.go
浏览文件 @
aa734202
...
...
@@ -96,7 +96,10 @@ func TestConfigWriteRead(t *testing.T) {
}
defer
os
.
RemoveAll
(
tmp
)
prvkey
:=
crypto
.
ToECDSA
(
common
.
Hex2Bytes
(
hexprvkey
))
prvkey
,
err
:=
crypto
.
HexToECDSA
(
hexprvkey
)
if
err
!=
nil
{
t
.
Fatalf
(
"failed to load private key: %v"
,
err
)
}
orig
,
err
:=
NewConfig
(
tmp
,
common
.
Address
{},
prvkey
,
323
)
if
err
!=
nil
{
t
.
Fatalf
(
"expected no error, got %v"
,
err
)
...
...
tests/util.go
浏览文件 @
aa734202
...
...
@@ -18,7 +18,6 @@ package tests
import
(
"bytes"
"encoding/hex"
"fmt"
"math/big"
"os"
...
...
@@ -161,8 +160,8 @@ func NewEVMEnvironment(vmTest bool, chainConfig *params.ChainConfig, statedb *st
origin
:=
common
.
HexToAddress
(
tx
[
"caller"
])
if
len
(
tx
[
"secretKey"
])
>
0
{
key
,
_
:=
hex
.
DecodeString
(
tx
[
"secretKey"
])
origin
=
crypto
.
PubkeyToAddress
(
crypto
.
ToECDSA
(
key
)
.
PublicKey
)
key
,
_
:=
crypto
.
HexToECDSA
(
tx
[
"secretKey"
])
origin
=
crypto
.
PubkeyToAddress
(
key
.
PublicKey
)
}
var
to
*
common
.
Address
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录