mirror of
https://github.com/status-im/nim-eth-keys.git
synced 2025-02-20 04:58:25 +00:00
Fix message size checks.
This commit is contained in:
parent
bb1fa6346e
commit
ddc80f8bff
@ -18,7 +18,6 @@ const
|
|||||||
InvalidPublicKey = "Invalid public key!"
|
InvalidPublicKey = "Invalid public key!"
|
||||||
InvalidSignature = "Invalid signature!"
|
InvalidSignature = "Invalid signature!"
|
||||||
VerificationFailed = "Signature verification has been failed!"
|
VerificationFailed = "Signature verification has been failed!"
|
||||||
EmptyMessageError = "Data/Message could not be empty!"
|
|
||||||
MessageSizeError = "Size of message to sign must be KeyLength bytes!"
|
MessageSizeError = "Size of message to sign must be KeyLength bytes!"
|
||||||
|
|
||||||
type
|
type
|
||||||
@ -266,8 +265,8 @@ proc recoverSignatureKey*(data: openarray[byte],
|
|||||||
## recover public key to `pubkey` on success.
|
## recover public key to `pubkey` on success.
|
||||||
let ctx = getSecpContext()
|
let ctx = getSecpContext()
|
||||||
let length = len(data)
|
let length = len(data)
|
||||||
if len(msg) == 0 or length == 0:
|
if len(msg) < KeyLength:
|
||||||
setErrorMsg(EmptyMessageError)
|
setErrorMsg(MessageSizeError)
|
||||||
return(EthKeysStatus.Error)
|
return(EthKeysStatus.Error)
|
||||||
if length < RawSignatureSize:
|
if length < RawSignatureSize:
|
||||||
setErrorMsg(InvalidSignature)
|
setErrorMsg(InvalidSignature)
|
||||||
@ -290,8 +289,8 @@ proc recoverSignatureKey*(signature: Signature,
|
|||||||
## Perform check of `signature` using original message `msg` and
|
## Perform check of `signature` using original message `msg` and
|
||||||
## recover public key to `pubkey` on success.
|
## recover public key to `pubkey` on success.
|
||||||
let ctx = getSecpContext()
|
let ctx = getSecpContext()
|
||||||
if len(msg) == 0:
|
if len(msg) < KeyLength:
|
||||||
setErrorMsg(EmptyMessageError)
|
setErrorMsg(MessageSizeError)
|
||||||
return(EthKeysStatus.Error)
|
return(EthKeysStatus.Error)
|
||||||
if secp256k1_ecdsa_recover(ctx, addr pubkey, unsafeAddr signature,
|
if secp256k1_ecdsa_recover(ctx, addr pubkey, unsafeAddr signature,
|
||||||
cast[ptr cuchar](msg)) != 1:
|
cast[ptr cuchar](msg)) != 1:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user