dint-dev / cryptography

Cryptography for Flutter developers: encryption, digital signatures, key agreement, etc.
https://pub.dev/packages/cryptography
Apache License 2.0
155 stars 75 forks source link

Blake2b produces incorrect hash when using 64 or more bytes as input #145

Closed akecht closed 9 months ago

akecht commented 1 year ago

When you compare the hashes with other tools (i.e. https://toolkitbay.com/tkb/tool/BLAKE2b_512, libsodium, ..) the hashes differ when 64 or more bytes are used.

example code:

var blake2b = Blake2b();

var hash = await blake2b.hash(utf8.encode("Lorem ipsum dolor sit amet, consectetur adipiscing elit turpis.")); // 63 bytes
print(hex.encode(hash.bytes)); // 058460852577e7de15323b6dbfc3656b325dc67a608fa555cfd7694b64a3433d3088eb9572fca9b7e776801bf032f84e179dbec34361f5edb47128d0cf236459
// matches with expected hash

hash = await blake2b.hash(utf8.encode("Lorem ipsum dolor sit amet, consectetur adipiscing elit aliquam.")); // 64 bytes
print(hex.encode(hash.bytes)); // 8715b7b58c747a49e371ba0b02b7de8f35da26ff2c8a60b80715d0272021266283af3eedb537683dd74cb1708601a80c9970376f1226d16afc242765eccd592a
// expected hash: fc32fd5f4a3c6859cb6779cb14b277dd8483ae6da7fb593b62c4387a3dfe0f22fe96592b1affc725c2fd37f8d09ed5d096af377bf3b2453746d4fa79906d3221
terrier989 commented 9 months ago

Hi! Thank you for the issue report! This was fixed in a past version so I close the ticket.