hashlib release
hashlib 3.0.0
- Bump
convertlibto^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)includeshigh, as documented (nextBetween(0, 1)always returned 0), and throwsArgumentErrorfor a range of more than 2^32 values instead of covering only the first 2^32.HashlibRandom.nextDoublereturns a 53-bit value in[0, 1)from two draws; it could return1.0. Seeded sequences change.RNG.md5uses MD5, not MD4. Seeded sequences change.adler32reads each value as a byte (& 0xFF), like every other algorithm, and itsnameis'ADLER-32'(was'ALDER-32').Bcryptanduuid.v8read 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.bcryptVerifythrowsFormatExceptionwhen the hash part is not 53 characters; it threwTypeErrororRangeError, or returnedfalse.PBKDF2,pbkdf2,ScryptandscryptthrowArgumentErrorinstead ofStateErrorfor out-of-range parameters, like Argon2 and bcrypt.HOTPandTOTPthrowArgumentErrorunlessdigitsis 4 to 10; only asserts checked it, and values above 10 just added leading zeros.- From
convertlib3.7.0:HashDigest.bigInt()defaults toEndian.big, likenumber()(passendian: Endian.littlefor the old values), andfromHexthrowsFormatExceptionfor values outside0..255.
- [Fixes]:
- Argon2 encoded strings without
$v=are read as version 1.0 (0x10), as the reference does; they threwUnknown version. verifyof Argon2, bcrypt, scrypt and PBKDF2 compares keys in constant time.fileSyncreads fromstartand stops atendor the end of the file; it ignoredstart, read pastend, and never returned whenendwas past the end of the file.HashlibRandom.nextBoolreturnstruehalf the time, not 1 in 16.HashlibRandom.nextStringandrandomStringpick every allowed character equally; some were up to 25% more likely.- Random UUIDs and seeds use the full range:
nextInt(0xFFFF)andnextInt(0xFFFFFFFF)never returned the top value. uuid.v1anduuid.v6set 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.
- Argon2 encoded strings without
- [New]:
- BLAKE3, with keyed hashing, key derivation and extendable output:
blake3,blake3sum,blake3.of,blake3.macandblake3.deriveKey(#18) - HKDF (RFC 5869):
HKDF,hkdf, and#.hkdfon block hashes and MACs - Whirlpool (ISO/IEC 10118-3):
whirlpoolandwhirlpoolsum(#15) - Streebog (GOST R 34.11-2012, RFC 6986):
streebog256,streebog512,streebog256sumandstreebog512sum(#14) - Rapidhash v3, a fast 64-bit non-cryptographic hash:
Rapidhash,rapidhash,rapidhashCodeandrapidhashSum, with seeds (#34) TOTP.verify(code, window: 1)checks a code against the current period and its neighbors.HOTP.uriandTOTP.urigive theotpauth://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.
- BLAKE3, with keyed hashing, key derivation and extendable output:
- [Performance]:
- Sinks copy a
Uint8Listinto the block buffer withsetRangeon the VM and wasm, and no longer update a field per byte. WithUint8Listinput 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
Uint8Listis 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
Uint8Listover 72 bytes uses the Chorba method on the VM and wasm, reading 64-bit words through aUint64Listview 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(bycopies 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
Uint8Listinput are read through aUint64Listview instead ofByteData, about 1.18x faster on large inputs on the VM. - SHA-1: a
Uint8Listblock 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
Uint8Listare absorbed at once, about 1.5-2x faster on the VM. - UUID generation: about 2x faster;
uuid.v1anduuid.v6draw the random clock sequence and node from two secure random values, not three. - Whirlpool: a
Uint8Listblock 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
Uint8Listis 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 aUint64Listview instead ofByteData, and the secret's last stripe is read once per sink instead of once per block (together about 1.2x faster on large inputs).
- Sinks copy a
- [Docs]:
HashlibRandom.secureandRNG.secureignore a seed.- The bcrypt cost range is 0 to 31, and
$2xis hashed like the other versions, without PHP's sign-extension bug. crc16code,crc32code,crc64code,adler32codeandCRC*.codecompute anintdirectly, 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, readingUint8Listinput by words past 4 KiB.