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
21c87e0f
Unverified
Commit
21c87e0f
authored
May 24, 2023
by
Delweng
Committed by
GitHub
May 24, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
crypto: replace noarg fmt.Errorf with errors.New (#27333)
Signed-off-by:
jsvisa
<
delweng@gmail.com
>
parent
b0095eeb
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
20 additions
and
18 deletions
+20
-18
crypto.go
crypto/crypto.go
+3
-3
ecies.go
crypto/ecies/ecies.go
+8
-8
ecies_test.go
crypto/ecies/ecies_test.go
+2
-2
params.go
crypto/ecies/params.go
+3
-2
signature_cgo.go
crypto/signature_cgo.go
+2
-1
signature_nocgo.go
crypto/signature_nocgo.go
+2
-2
No files found.
crypto/crypto.go
View file @
21c87e0f
...
...
@@ -141,11 +141,11 @@ func toECDSA(d []byte, strict bool) (*ecdsa.PrivateKey, error) {
// The priv.D must < N
if
priv
.
D
.
Cmp
(
secp256k1N
)
>=
0
{
return
nil
,
fmt
.
Errorf
(
"invalid private key, >=N"
)
return
nil
,
errors
.
New
(
"invalid private key, >=N"
)
}
// The priv.D must not be zero or negative.
if
priv
.
D
.
Sign
()
<=
0
{
return
nil
,
fmt
.
Errorf
(
"invalid private key, zero or negative"
)
return
nil
,
errors
.
New
(
"invalid private key, zero or negative"
)
}
priv
.
PublicKey
.
X
,
priv
.
PublicKey
.
Y
=
priv
.
PublicKey
.
Curve
.
ScalarBaseMult
(
d
)
...
...
@@ -204,7 +204,7 @@ func LoadECDSA(file string) (*ecdsa.PrivateKey, error) {
if
err
!=
nil
{
return
nil
,
err
}
else
if
n
!=
len
(
buf
)
{
return
nil
,
fmt
.
Errorf
(
"key file too short, want 64 hex characters"
)
return
nil
,
errors
.
New
(
"key file too short, want 64 hex characters"
)
}
if
err
:=
checkKeyFileEnd
(
r
);
err
!=
nil
{
return
nil
,
err
...
...
crypto/ecies/ecies.go
View file @
21c87e0f
...
...
@@ -36,18 +36,18 @@ import (
"crypto/hmac"
"crypto/subtle"
"encoding/binary"
"
fmt
"
"
errors
"
"hash"
"io"
"math/big"
)
var
(
ErrImport
=
fmt
.
Errorf
(
"ecies: failed to import key"
)
ErrInvalidCurve
=
fmt
.
Errorf
(
"ecies: invalid elliptic curve"
)
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"
)
ErrImport
=
errors
.
New
(
"ecies: failed to import key"
)
ErrInvalidCurve
=
errors
.
New
(
"ecies: invalid elliptic curve"
)
ErrInvalidPublicKey
=
errors
.
New
(
"ecies: invalid public key"
)
ErrSharedKeyIsPointAtInfinity
=
errors
.
New
(
"ecies: shared key is point at infinity"
)
ErrSharedKeyTooBig
=
errors
.
New
(
"ecies: shared key params are too big"
)
)
// PublicKey is a representation of an elliptic curve public key.
...
...
@@ -138,8 +138,8 @@ func (prv *PrivateKey) GenerateShared(pub *PublicKey, skLen, macLen int) (sk []b
}
var
(
ErrSharedTooLong
=
fmt
.
Errorf
(
"ecies: shared secret is too long"
)
ErrInvalidMessage
=
fmt
.
Errorf
(
"ecies: invalid message"
)
ErrSharedTooLong
=
errors
.
New
(
"ecies: shared secret is too long"
)
ErrInvalidMessage
=
errors
.
New
(
"ecies: invalid message"
)
)
// NIST SP 800-56 Concatenation Key Derivation Function (see section 5.8.1).
...
...
crypto/ecies/ecies_test.go
View file @
21c87e0f
...
...
@@ -35,7 +35,7 @@ import (
"crypto/rand"
"crypto/sha256"
"encoding/hex"
"
fmt
"
"
errors
"
"math/big"
"testing"
...
...
@@ -62,7 +62,7 @@ func TestKDF(t *testing.T) {
}
}
var
ErrBadSharedKeys
=
fmt
.
Errorf
(
"ecies: shared keys don't match"
)
var
ErrBadSharedKeys
=
errors
.
New
(
"ecies: shared keys don't match"
)
// cmpParams compares a set of ECIES parameters. We assume, as per the
// docs, that AES is the only supported symmetric encryption algorithm.
...
...
crypto/ecies/params.go
View file @
21c87e0f
...
...
@@ -39,6 +39,7 @@ import (
"crypto/elliptic"
"crypto/sha256"
"crypto/sha512"
"errors"
"fmt"
"hash"
...
...
@@ -47,8 +48,8 @@ import (
var
(
DefaultCurve
=
ethcrypto
.
S256
()
ErrUnsupportedECDHAlgorithm
=
fmt
.
Errorf
(
"ecies: unsupported ECDH algorithm"
)
ErrUnsupportedECIESParameters
=
fmt
.
Errorf
(
"ecies: unsupported ECIES parameters"
)
ErrUnsupportedECDHAlgorithm
=
errors
.
New
(
"ecies: unsupported ECDH algorithm"
)
ErrUnsupportedECIESParameters
=
errors
.
New
(
"ecies: unsupported ECIES parameters"
)
ErrInvalidKeyLen
=
fmt
.
Errorf
(
"ecies: invalid key size (> %d) in ECIESParams"
,
maxKeyLen
)
)
...
...
crypto/signature_cgo.go
View file @
21c87e0f
...
...
@@ -22,6 +22,7 @@ package crypto
import
(
"crypto/ecdsa"
"crypto/elliptic"
"errors"
"fmt"
"github.com/ethereum/go-ethereum/common/math"
...
...
@@ -72,7 +73,7 @@ func VerifySignature(pubkey, digestHash, signature []byte) bool {
func
DecompressPubkey
(
pubkey
[]
byte
)
(
*
ecdsa
.
PublicKey
,
error
)
{
x
,
y
:=
secp256k1
.
DecompressPubkey
(
pubkey
)
if
x
==
nil
{
return
nil
,
fmt
.
Errorf
(
"invalid public key"
)
return
nil
,
errors
.
New
(
"invalid public key"
)
}
return
&
ecdsa
.
PublicKey
{
X
:
x
,
Y
:
y
,
Curve
:
S256
()},
nil
}
...
...
crypto/signature_nocgo.go
View file @
21c87e0f
...
...
@@ -74,12 +74,12 @@ func Sign(hash []byte, prv *ecdsa.PrivateKey) ([]byte, error) {
return
nil
,
fmt
.
Errorf
(
"hash is required to be exactly 32 bytes (%d)"
,
len
(
hash
))
}
if
prv
.
Curve
!=
btcec
.
S256
()
{
return
nil
,
fmt
.
Errorf
(
"private key curve is not secp256k1"
)
return
nil
,
errors
.
New
(
"private key curve is not secp256k1"
)
}
// ecdsa.PrivateKey -> btcec.PrivateKey
var
priv
btcec
.
PrivateKey
if
overflow
:=
priv
.
Key
.
SetByteSlice
(
prv
.
D
.
Bytes
());
overflow
||
priv
.
Key
.
IsZero
()
{
return
nil
,
fmt
.
Errorf
(
"invalid private key"
)
return
nil
,
errors
.
New
(
"invalid private key"
)
}
defer
priv
.
Zero
()
sig
,
err
:=
btc_ecdsa
.
SignCompact
(
&
priv
,
hash
,
false
)
// ref uncompressed pubkey
...
...
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