BlockchainCommons / seedtool-cli

Cryptographic Seed Tool for the command line
Other
25 stars 16 forks source link

Error parsing hex input when number of bytes is not divisible by 4 #50

Closed guiambros closed 3 years ago

guiambros commented 3 years ago

When entering an hex seed input with 14, 18, 22, 26 or 30 bytes, seedtool returns garbage data, or internal error.

Entering any seed with length between 16-32 that is also divisible by 4 works well (i.e., 16, 20, 24, 28, 32).

I guess there's an unbound string checking somewhere, but wasn't able to find in a cursory look at the code.

Example

Seed is 28 hex characters in length == 14 bytes:

$ ./src/seedtool --in hex --out bip39 1234567890123456789012345678
pb`

$ ./src/seedtool --in hex --out bip39 1234567890123456789012345678
!vz

$ ./src/seedtool --in hex --out bip39 1234567890123456789012345678
./src/seedtool: An internal error occurred.

Seed is 32 hex characters == 16 bytes:

$ ./src/seedtool --in hex --out bip39 12345678901234567890123456789012
banana pencil owner cage cash clinic time across crowd record catch caution
wolfmcnally commented 3 years ago

Thanks for reporting this. Even if seedtool throws an error it should never be an internal error or garbage output. I'll look into it.

wolfmcnally commented 3 years ago

OK, the problem appears to be that I validated the input for BIP39 conversion incorrectly. The BIP39 docs state that the seed length must be in increments of 32 bits, i.e., divisible by 4. So lengths like 14 are in fact invalid and Seedtool should have caught and reported this.