Skip to content

hashlib release

hashlib 3.0.0

  • Bump convertlib to ^3.8.0
  • [Breaking Changes]:
    • Argon2 tags over 64 bytes follow RFC 9106: the last block of the variable-length hash is a BLAKE2b of the remaining length, not a truncated 64-byte one. Such tags change unless their length is a multiple of 32, and now match other implementations.
    • HashlibRandom.nextBetween(low, high) includes high, as documented (nextBetween(0, 1) always returned 0), and throws ArgumentError for a range of more than 2^32 values instead of covering only the first 2^32.
    • HashlibRandom.nextDouble returns a 53-bit value in [0, 1) from two draws; it could return 1.0. Seeded sequences change.
    • RNG.md5 uses MD5, not MD4. Seeded sequences change.
    • adler32 reads each value as a byte (& 0xFF), like every other algorithm, and its name is 'ADLER-32' (was 'ALDER-32').
    • Bcrypt and uuid.v8 read a salt or nonce that is a typed-data view from the view's own bytes, not from the start of its buffer; a bcrypt hash made with such a salt could never be verified.
    • bcryptVerify throws FormatException when the hash part is not 53 characters; it threw TypeError or RangeError, or returned false.
    • PBKDF2, pbkdf2, Scrypt and scrypt throw ArgumentError instead of StateError for out-of-range parameters, like Argon2 and bcrypt.
    • HOTP and TOTP throw ArgumentError unless digits is 4 to 10; only asserts checked it, and values above 10 just added leading zeros.
    • From convertlib 3.7.0: HashDigest.bigInt() defaults to Endian.big, like number() (pass endian: Endian.little for the old values), and fromHex throws FormatException for values outside 0..255.
  • [Fixes]:
    • Argon2 encoded strings without $v= are read as version 1.0 (0x10), as the reference does; they threw Unknown version.
    • verify of Argon2, bcrypt, scrypt and PBKDF2 compares keys in constant time.
    • fileSync reads from start and stops at end or the end of the file; it ignored start, read past end, and never returned when end was past the end of the file.
    • HashlibRandom.nextBool returns true half the time, not 1 in 16.
    • HashlibRandom.nextString and randomString pick every allowed character equally; some were up to 25% more likely.
    • Random UUIDs and seeds use the full range: nextInt(0xFFFF) and nextInt(0xFFFFFFFF) never returned the top value.
    • uuid.v1 and uuid.v6 set the multicast bit of a random node, as RFC 9562 section 6.10 requires.
    • XXH3 and XXH128 sinks reused after reset() hashed a message of up to 240 bytes together with the end of the previous one.
  • [New]:
    • BLAKE3, with keyed hashing, key derivation and extendable output: blake3, blake3sum, blake3.of, blake3.mac and blake3.deriveKey (#18)
    • HKDF (RFC 5869): HKDF, hkdf, and #.hkdf on block hashes and MACs
    • Whirlpool (ISO/IEC 10118-3): whirlpool and whirlpoolsum (#15)
    • Streebog (GOST R 34.11-2012, RFC 6986): streebog256, streebog512, streebog256sum and streebog512sum (#14)
    • Rapidhash v3, a fast 64-bit non-cryptographic hash: Rapidhash, rapidhash, rapidhashCode and rapidhashSum, with seeds (#34)
    • TOTP.verify(code, window: 1) checks a code against the current period and its neighbors.
    • HOTP.uri and TOTP.uri give the otpauth:// Key Uri Format string that authenticator apps read from a QR code.
    • ChainingStateSink, implemented by the MD4, MD5, SHA-1, SHA-2, SM3 and RIPEMD sinks, so that HMAC can restore their saved state.
  • [Performance]:
    • Sinks copy a Uint8List into the block buffer with setRange on the VM and wasm, and no longer update a field per byte. With Uint8List input on the VM: XXH64 about 7x faster, XXH32 3.6x, BLAKE2b 2.8x, MD4 2.4x, RIPEMD-128 and RIPEMD-256 2x, BLAKE3 1.7x, BLAKE2s and Poly1305 1.6x, SM3 1.4x, and RIPEMD-160 and RIPEMD-320 1.3x.
    • Adler-32: a Uint8List is summed eight bytes per step without masks, about 1.6x faster on the VM.
    • bcrypt: about 17% faster on the VM and over 20% on the web.
    • BLAKE2b: its 12 rounds are written out, about 1.15x faster on the VM.
    • CRC-16, CRC-32 and CRC-64: the default polynomials use built-in tables instead of building one per sink (CRC-32 of 10 bytes about 60x faster), and CRC-32 and CRC-64 read 4 bytes per step (CRC-32 about 1.7x faster on large inputs).
    • CRC-32 (IEEE table): a Uint8List over 72 bytes uses the Chorba method on the VM and wasm, reading 64-bit words through a Uint64List view once it is 8-byte aligned, about 5.5x faster on large inputs.
    • HMAC: about 1.5x faster on short messages. The sink reads its key as a Uint8List (by copies any other list once) and pads it without interface calls, about 1.2x faster on short messages.
    • MD2: about 10% faster on the VM.
    • MD5: about 1.25x faster on the VM, 1.4x on short inputs.
    • PBKDF2: about 1.8x faster on the VM and 1.4x on the web; a reused HMAC sink restores the states saved after the padded keys.
    • Poly1305: each block's limbs come from two 64-bit words instead of 17 bytes, about 1.1x faster on the VM.
    • Rapidhash: whole blocks of 8-byte-aligned Uint8List input are read through a Uint64List view instead of ByteData, about 1.18x faster on large inputs on the VM.
    • SHA-1: a Uint8List block is read without masks or interface calls, about 1.4x faster on the VM.
    • SHA-224 and SHA-256: 8 rounds per pass with no register shuffle, about 1.4x faster on the VM. SHA-384, SHA-512 and SHA-512/t: about 1.15x, and 1.35x on short inputs.
    • SHA-3, SHAKE and Keccak: whole 64-bit lanes of a Uint8List are absorbed at once, about 1.5-2x faster on the VM.
    • UUID generation: about 2x faster; uuid.v1 and uuid.v6 draw the random clock sequence and node from two secure random values, not three.
    • Whirlpool: a Uint8List block is read without masking each byte, about 1.03x faster on the VM.
    • XXH3 and XXH128: about 4x faster on the VM and 1.8x on the web. A Uint8List is hashed in place instead of being copied into the buffer (about 10x faster on large inputs). On the VM, 64-bit words of 8-byte aligned input are read through a Uint64List view instead of ByteData, and the secret's last stripe is read once per sink instead of once per block (together about 1.2x faster on large inputs).
  • [Docs]:
    • HashlibRandom.secure and RNG.secure ignore a seed.
    • The bcrypt cost range is 0 to 31, and $2x is hashed like the other versions, without PHP's sign-extension bug.
    • crc16code, crc32code, crc64code, adler32code and CRC*.code compute an int directly, with no sink, digest or byte array.
    • CRC-16 and CRC-32 slice by 8 bytes over the built-in tables, Adler-32 unrolls List<int> input, and CRC-64 keeps one 64-bit register on the VM, reading Uint8List input by words past 4 KiB.

All posts·RSS feed