HashLib4Pascal is a comprehensive hashing library for Object Pascal, providing an easy-to-use interface for computing hashes, checksums, MACs, KDFs, and XOFs with support for state-based (incremental) hashing, released under the permissive MIT License.
Table of Contents
- Features
- Available Algorithms
- Getting Started
- Quick Examples
- Running Tests
- Contributing
- Other Implementations
- Tip Jar
- License
Features
- Extensive hash coverage -- CRC (all standard variants from CRC3 to CRC64), non-cryptographic (Murmur, XXHash, SipHash, etc.), and cryptographic (SHA-2, SHA-3, Blake2, Blake3, and more)
- State-based (incremental) hashing -- feed data in chunks via
TransformBytes/TransformString, then finalize withTransformFinal - One-shot convenience --
ComputeString,ComputeBytes,ComputeFile,ComputeStreamfor single-call hashing - Password hashing / KDFs -- Argon2 (2i/2d/2id), Scrypt, PBKDF2-HMAC
- MACs -- HMAC (all supported hashes), KMAC (128/256), Blake2BMAC, Blake2SMAC
- Extendable output functions (XOFs) -- Shake, CShake, Blake2X, KMACXOF, Blake3XOF
- Cloneable state -- clone any hash instance mid-computation for parallel/divergent processing
- Cross-platform -- Delphi and FreePascal on Windows, Linux, macOS, and more
Available Algorithms
Non-Cryptographic Hash Functions
32-bit
AP | BKDR | Bernstein | Bernstein1 | DEK | DJB | ELF | FNV | FNV1a | Jenkins3 | JS | Murmur2 | MurmurHash3_x86_32 | OneAtTime | PJW | Rotating | RS | SDBM | ShiftAndXor | SuperFast | XXHash32
64-bit
FNV64 | FNV1a64 | Murmur2_64 | SipHash2_4 | XXHash64 | XXHash3
128-bit
SipHash128_2_4 | MurmurHash3_x86_128 | MurmurHash3_x64_128 | XXHash128
Cryptographic Hash Functions
| Family | Variants |
|---|---|
| MD | MD2, MD4, MD5 |
| SHA-0 | SHA-0 |
| SHA-1 | SHA-1 |
| SHA-2 | 224, 256, 384, 512, 512-224, 512-256 |
| SHA-3 | 224, 256, 384, 512 |
| Keccak | 224, 256, 288, 384, 512 |
| Blake2B | 160, 256, 384, 512 |
| Blake2S | 128, 160, 224, 256 |
| Blake2BP | Blake2BP |
| Blake2SP | Blake2SP |
| Blake3 | Blake3 |
| GOST | 34.11-94, R 34.11-2012 (256, 512) |
| Grindahl | 256, 512 |
| HAS160 | HAS160 |
| RIPEMD | 128, 160, 256, 320 |
| Tiger | 128, 160, 192 (Rounds 3, 4, 5) |
| Tiger2 | 128, 160, 192 (Rounds 3, 4, 5) |
| Snefru | 128, 256 |
| Haval | 128, 160, 192, 224, 256 (Rounds 3, 4, 5) |
| Panama | Panama |
| RadioGatun | RadioGatun32, RadioGatun64 |
| WhirlPool | WhirlPool |
MACs
HMAC (all supported hashes) | KMAC (128, 256) | Blake2BMAC | Blake2SMAC
XOF (Extendable Output Functions)
Shake (128, 256) | CShake (128, 256) | Blake2XS | Blake2XB | KMAC128XOF | KMAC256XOF | Blake3XOF
Getting Started
Prerequisites
| Compiler | Minimum Version |
|---|---|
| Delphi | 2010 or later |
| FreePascal | 3.2.2 or later |
Installation
Delphi
- Open and install the package:
HashLib/src/Packages/Delphi/HashLib4PascalPackage.dpk - Add the
HashLib/srcsubdirectories to your project's search path.
FreePascal / Lazarus
- Open and install the package:
HashLib/src/Packages/FPC/HashLib4PascalPackage.lpk
Quick Examples
SHA-256 Hash
uses SysUtils, HlpHashFactory; var LHash: String; begin LHash := THashFactory.TCrypto.CreateSHA2_256() .ComputeString('Hello HashLib4Pascal', TEncoding.UTF8) .ToString(); WriteLn(LHash); end;
Incremental (Streaming) Hash
uses SysUtils, HlpIHash, HlpHashFactory; var LHashInstance: IHash; begin LHashInstance := THashFactory.TCrypto.CreateBlake2B_256(); LHashInstance.Initialize(); LHashInstance.TransformString('chunk one', TEncoding.UTF8); LHashInstance.TransformString('chunk two', TEncoding.UTF8); LHashInstance.TransformString('chunk three', TEncoding.UTF8); WriteLn(LHashInstance.TransformFinal().ToString()); end;
HMAC
uses SysUtils, HlpIHashInfo, HlpHashFactory, HlpConverters; var LHMAC: IHMAC; begin LHMAC := THashFactory.THMAC.CreateHMAC( THashFactory.TCrypto.CreateSHA2_256(), TConverters.ConvertStringToBytes('secret key', TEncoding.UTF8)); WriteLn(LHMAC.ComputeString('message', TEncoding.UTF8).ToString()); end;
Scrypt KDF
uses SysUtils, HlpHashFactory, HlpConverters; var LDerivedKey: TBytes; begin LDerivedKey := TKDF.TPBKDF_Scrypt.CreatePBKDF_Scrypt( TConverters.ConvertStringToBytes('password', TEncoding.UTF8), TConverters.ConvertStringToBytes('salt', TEncoding.UTF8), 1024, 8, 1) .GetBytes(32); WriteLn(TConverters.ConvertBytesToHexString(LDerivedKey)); end;
Running Tests
Tests use DUnit (Delphi) and FPCUnit (FreePascal).
- Delphi: Open
HashLib.Tests/Delphi.Tests/HashLib.Tests.dprin the IDE and run. - FreePascal / Lazarus: Open
HashLib.Tests/FreePascal.Tests/HashLib.Tests.lpiin the IDE and run.
Contributing
Contributions are welcome. Please open an issue for bug reports or feature requests, and submit pull requests.
Other Implementations
If you want implementations in other languages, you can check out these:
- HashLib4CPP by Mbadiwe Nnaemeka Ronald
Tip Jar
If you find this library useful and would like to support its continued development, tips are greatly appreciated! 🙏
License
HashLib4Pascal is released under the MIT License.