Add isZeroKey() procedures.

This commit is contained in:
cheatfate 2018-06-20 12:32:39 +03:00
parent 1c2c88cb32
commit ac8cb31178
2 changed files with 26 additions and 0 deletions

View File

@ -318,3 +318,17 @@ proc signRawMessage*(data: openarray[byte], seckey: PrivateKey,
nil, nil) != 1: nil, nil) != 1:
return(EthKeysStatus.Error) return(EthKeysStatus.Error)
return(EthKeysStatus.Success) return(EthKeysStatus.Success)
proc isZeroKey*(seckey: PrivateKey): bool =
## Check if private key `seckey` contains only 0 bytes.
result = true
for i in seckey.data:
if i != byte(0):
result = false
proc isZeroKey*(pubkey: PublicKey): bool =
## Check if public key `pubkey` contains only 0 bytes.
result = true
for i in pubkey.data:
if i != byte(0):
result = false

View File

@ -253,3 +253,15 @@ suite "ECC/ECDSA/ECDHE tests suite":
ecdhAgree(aliceSecret, bobPublic, secret1) == Success ecdhAgree(aliceSecret, bobPublic, secret1) == Success
ecdhAgree(bobSecret, alicePublic, secret2) == Success ecdhAgree(bobSecret, alicePublic, secret2) == Success
secret1 == secret2 secret1 == secret2
test "isZeroKey() checks":
var seckey1: PrivateKey
var pubkey1: PublicKey
var seckey2 = newPrivateKey()
var pubkey2 = seckey2.getPublicKey()
check:
seckey1.isZeroKey() == true
pubkey1.isZeroKey() == true
seckey2.isZeroKey() == false
pubkey2.isZeroKey() == false