|
1 | | -HashLib4Pascal: Hashing for Modern Object Pascal [](https://github.com/Xor-el/HashLib4Pascal/blob/master/LICENSE) |
2 | | -======================================== |
| 1 | +# HashLib4Pascal |
3 | 2 |
|
4 | | -``HashLib4Pascal`` is an Object Pascal hashing library released under the permissive [MIT License](https://github.com/Xor-el/HashLib4Pascal/blob/master/LICENSE) which provides an easy to use interface for computing hashes and checksums of data. It also supports state based (incremental) hashing. |
| 3 | +[](https://github.com/Xor-el/HashLib4Pascal/actions/workflows/make.yml) |
| 4 | +[](https://github.com/Xor-el/HashLib4Pascal/blob/master/LICENSE) |
| 5 | +[](https://www.embarcadero.com/products/delphi) |
| 6 | +[](https://www.freepascal.org/) |
5 | 7 |
|
6 | | -``HashLib4Pascal's`` goal is to be the best option for hashing in Object Pascal by offering various hashing primitives via an easy to use API to Object Pascal developers. |
| 8 | +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](LICENSE). |
7 | 9 |
|
8 | | -Development is coordinated on [GitHub](https://github.com/Xor-el/HashLib4Pascal) and contributions are welcome. If you need help, please open an issue [here](https://github.com/Xor-el/HashLib4Pascal/issues). |
| 10 | +## Table of Contents |
9 | 11 |
|
| 12 | +- [Features](#features) |
| 13 | +- [Available Algorithms](#available-algorithms) |
| 14 | +- [Getting Started](#getting-started) |
| 15 | +- [Quick Examples](#quick-examples) |
| 16 | +- [Running Tests](#running-tests) |
| 17 | +- [Contributing](#contributing) |
| 18 | +- [Other Implementations](#other-implementations) |
| 19 | +- [Tip Jar](#tip-jar) |
| 20 | +- [License](#license) |
10 | 21 |
|
11 | | -**Build Status** |
12 | | -[](https://github.com/Xor-el/HashLib4Pascal/actions/workflows/make.yml) |
| 22 | +## Features |
| 23 | + |
| 24 | +- **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) |
| 25 | +- **State-based (incremental) hashing** -- feed data in chunks via `TransformBytes` / `TransformString`, then finalize with `TransformFinal` |
| 26 | +- **One-shot convenience** -- `ComputeString`, `ComputeBytes`, `ComputeFile`, `ComputeStream` for single-call hashing |
| 27 | +- **Password hashing / KDFs** -- Argon2 (2i/2d/2id), Scrypt, PBKDF2-HMAC |
| 28 | +- **MACs** -- HMAC (all supported hashes), KMAC (128/256), Blake2BMAC, Blake2SMAC |
| 29 | +- **Extendable output functions (XOFs)** -- Shake, CShake, Blake2X, KMACXOF, Blake3XOF |
| 30 | +- **Cloneable state** -- clone any hash instance mid-computation for parallel/divergent processing |
| 31 | +- **Cross-platform** -- Delphi and FreePascal on Windows, Linux, macOS, and more |
| 32 | + |
| 33 | +## Available Algorithms |
| 34 | + |
| 35 | +<details> |
| 36 | +<summary>Checksums</summary> |
| 37 | + |
| 38 | +#### CRC |
| 39 | +`All CRC variants from CRC3 to CRC64` |
| 40 | + |
| 41 | +#### Other |
| 42 | +`Adler32` |
| 43 | + |
| 44 | +</details> |
| 45 | + |
| 46 | +<details> |
| 47 | +<summary>Non-Cryptographic Hash Functions</summary> |
13 | 48 |
|
14 | | -Available Algorithms |
15 | | ----------------------------------------- |
| 49 | +#### 32-bit |
| 50 | +`AP` | `BKDR` | `Bernstein` | `Bernstein1` | `DEK` | `DJB` | `ELF` | `FNV` | `FNV1a` | `Jenkins3` | `JS` | `Murmur2` | `MurmurHash3_x86_32` | `OneAtTime` | `PJW` | `Rotating` | `RS` | `SDBM` | `ShiftAndXor` | `SuperFast` | `XXHash32` |
16 | 51 |
|
17 | | - ### Hashes |
18 | | ----------------------------------------- |
19 | | -##### Cyclic Redundancy Checks |
| 52 | +#### 64-bit |
| 53 | +`FNV64` | `FNV1a64` | `Murmur2_64` | `SipHash2_4` | `XXHash64` |
20 | 54 |
|
21 | | -* `All CRC Variants from CRC3 to CRC64` |
| 55 | +#### 128-bit |
| 56 | +`SipHash128_2_4` | `MurmurHash3_x86_128` | `MurmurHash3_x64_128` |
22 | 57 |
|
23 | | -##### Checksums |
| 58 | +</details> |
24 | 59 |
|
25 | | -* `Adler32` |
| 60 | +<details> |
| 61 | +<summary>Cryptographic Hash Functions</summary> |
26 | 62 |
|
27 | | -##### Non-Cryptographic Hash Functions |
28 | | ----------------------------------------- |
| 63 | +| Family | Variants | |
| 64 | +|---|---| |
| 65 | +| MD | MD2, MD4, MD5 | |
| 66 | +| SHA-0 | SHA-0 | |
| 67 | +| SHA-1 | SHA-1 | |
| 68 | +| SHA-2 | 224, 256, 384, 512, 512-224, 512-256 | |
| 69 | +| SHA-3 | 224, 256, 384, 512 | |
| 70 | +| Keccak | 224, 256, 288, 384, 512 | |
| 71 | +| Blake2B | 160, 256, 384, 512 | |
| 72 | +| Blake2S | 128, 160, 224, 256 | |
| 73 | +| Blake2BP | Blake2BP | |
| 74 | +| Blake2SP | Blake2SP | |
| 75 | +| Blake3 | Blake3 | |
| 76 | +| GOST | 34.11-94, R 34.11-2012 (256, 512) | |
| 77 | +| Grindahl | 256, 512 | |
| 78 | +| HAS160 | HAS160 | |
| 79 | +| RIPEMD | 128, 160, 256, 320 | |
| 80 | +| Tiger | 128, 160, 192 (Rounds 3, 4, 5) | |
| 81 | +| Tiger2 | 128, 160, 192 (Rounds 3, 4, 5) | |
| 82 | +| Snefru | 128, 256 | |
| 83 | +| Haval | 128, 160, 192, 224, 256 (Rounds 3, 4, 5) | |
| 84 | +| Panama | Panama | |
| 85 | +| RadioGatun | RadioGatun32, RadioGatun64 | |
| 86 | +| WhirlPool | WhirlPool | |
29 | 87 |
|
30 | | -###### 32 bit hashes |
| 88 | +</details> |
31 | 89 |
|
32 | | -* `AP` `BKDR` `Bernstein` `Bernstein1` `DEK` `DJB` `ELF` `FNV` |
| 90 | +<details> |
| 91 | +<summary>Key Derivation Functions</summary> |
33 | 92 |
|
34 | | -* `FNV1a` `JS` `Jenkins3` `Murmur2` `MurmurHash3_x86_32` `OneAtTime` |
| 93 | +#### Password Hashing |
| 94 | +`PBKDF2-HMAC` | `Argon2 (2i, 2d, 2id)` | `Scrypt` |
35 | 95 |
|
36 | | -* `PJW` `RS` `Rotating` `SDBM` `ShiftAndXor` `SuperFast` `XXHash32` |
| 96 | +</details> |
37 | 97 |
|
38 | | -###### 64 bit hashes |
| 98 | +<details> |
| 99 | +<summary>MACs</summary> |
39 | 100 |
|
40 | | -* `FNV64` `FNV1a64` `Murmur2_64` `SipHash2_4` `XXHash64` |
| 101 | +`HMAC (all supported hashes)` | `KMAC (128, 256)` | `Blake2BMAC` | `Blake2SMAC` |
41 | 102 |
|
42 | | -###### 128 bit hashes |
| 103 | +</details> |
43 | 104 |
|
44 | | -* `MurmurHash3_x86_128` `MurmurHash3_x64_128` |
| 105 | +<details> |
| 106 | +<summary>XOF (Extendable Output Functions)</summary> |
45 | 107 |
|
46 | | -##### Cryptographic Hash Functions |
47 | | ----------------------------------------- |
| 108 | +`Shake (128, 256)` | `CShake (128, 256)` | `Blake2XS` | `Blake2XB` | `KMAC128XOF` | `KMAC256XOF` | `Blake3XOF` |
48 | 109 |
|
49 | | - * `MD2` |
| 110 | +</details> |
50 | 111 |
|
51 | | - * `MD4` |
| 112 | +## Getting Started |
52 | 113 |
|
53 | | - * `MD5` |
| 114 | +### Prerequisites |
54 | 115 |
|
55 | | - * `SHA-0` |
| 116 | +| Compiler | Minimum Version | |
| 117 | +|---|---| |
| 118 | +| Delphi | 2010 or later | |
| 119 | +| FreePascal | 3.2.2 or later | |
56 | 120 |
|
57 | | - * `SHA-1` |
| 121 | +### Installation |
58 | 122 |
|
59 | | - * `SHA-2 (224, 256, 384, 512, 512-224, 512-256)` |
| 123 | +#### Delphi |
60 | 124 |
|
61 | | - * `GOST 34.11-94` |
| 125 | +1. Open and install the package: `HashLib/src/Packages/Delphi/HashLib4PascalPackage.dpk` |
| 126 | +2. Add the `HashLib/src` subdirectories to your project's search path. |
62 | 127 |
|
63 | | - * `GOST R 34.11-2012 (AKA Streebog) (256, 512)` |
64 | | - |
65 | | - * `Grindahl (256, 512)` |
66 | | - |
67 | | - * `Has160` |
| 128 | +#### FreePascal / Lazarus |
68 | 129 |
|
69 | | - * `RIPEMD (128, 160, 256, 256, 320)` |
| 130 | +1. Open and install the package: `HashLib/src/Packages/FPC/HashLib4PascalPackage.lpk` |
70 | 131 |
|
71 | | - * `Tiger (128, 160, 192 (Rounds 3, 4, 5))` |
| 132 | +## Quick Examples |
72 | 133 |
|
73 | | - * `Tiger2 (128, 160, 192 (Rounds 3, 4, 5))` |
74 | | - |
75 | | - * `Snefru (128, 256)` |
76 | | - |
77 | | - * `Haval (128, 160, 192, 224, 256 (Rounds 3, 4, 5))` |
78 | | - |
79 | | - * `Panama` |
80 | | - |
81 | | - * `RadioGatun (RadioGatun32, RadioGatun64)` |
| 134 | +### SHA-256 Hash |
82 | 135 |
|
83 | | - * `WhirlPool` |
| 136 | +```pascal |
| 137 | +uses |
| 138 | + SysUtils, HlpHashFactory; |
84 | 139 |
|
85 | | - * `Blake2B (160, 256, 384, 512)` |
86 | | - |
87 | | - * `Blake2S (128, 160, 224, 256)` |
| 140 | +var |
| 141 | + LHash: String; |
| 142 | +begin |
| 143 | + LHash := THashFactory.TCrypto.CreateSHA2_256() |
| 144 | + .ComputeString('Hello HashLib4Pascal', TEncoding.UTF8) |
| 145 | + .ToString(); |
88 | 146 |
|
89 | | - * `SHA-3 (224, 256, 384, 512)` |
90 | | - |
91 | | - * `Keccak (224, 256, 288, 384, 512)` |
| 147 | + WriteLn(LHash); |
| 148 | +end; |
| 149 | +``` |
92 | 150 |
|
93 | | - * `Blake2BP` |
| 151 | +### Incremental (Streaming) Hash |
94 | 152 |
|
95 | | - * `Blake2SP` |
| 153 | +```pascal |
| 154 | +uses |
| 155 | + SysUtils, HlpIHash, HlpHashFactory; |
96 | 156 |
|
97 | | - * `Blake3` |
| 157 | +var |
| 158 | + LHashInstance: IHash; |
| 159 | +begin |
| 160 | + LHashInstance := THashFactory.TCrypto.CreateBlake2B_256(); |
| 161 | + LHashInstance.Initialize(); |
98 | 162 |
|
99 | | -### Key Derivation Functions |
100 | | ----------------------------------------- |
| 163 | + LHashInstance.TransformString('chunk one', TEncoding.UTF8); |
| 164 | + LHashInstance.TransformString('chunk two', TEncoding.UTF8); |
| 165 | + LHashInstance.TransformString('chunk three', TEncoding.UTF8); |
101 | 166 |
|
102 | | -###### Password Hashing Schemes (Password Based Key Derivation Functions) |
| 167 | + WriteLn(LHashInstance.TransformFinal().ToString()); |
| 168 | +end; |
| 169 | +``` |
103 | 170 |
|
104 | | ----------------------------------------- |
| 171 | +### HMAC |
105 | 172 |
|
106 | | -* `PBKDF2` |
107 | | - |
108 | | -* `Argon2 (2i, 2d and 2id variants)` |
| 173 | +```pascal |
| 174 | +uses |
| 175 | + SysUtils, HlpIHashInfo, HlpHashFactory, HlpConverters; |
109 | 176 |
|
110 | | -* `Scrypt` |
| 177 | +var |
| 178 | + LHMAC: IHMAC; |
| 179 | +begin |
| 180 | + LHMAC := THashFactory.THMAC.CreateHMAC( |
| 181 | + THashFactory.TCrypto.CreateSHA2_256(), |
| 182 | + TConverters.ConvertStringToBytes('secret key', TEncoding.UTF8)); |
111 | 183 |
|
112 | | -### MAC |
113 | | ----------------------------------------- |
| 184 | + WriteLn(LHMAC.ComputeString('message', TEncoding.UTF8).ToString()); |
| 185 | +end; |
| 186 | +``` |
114 | 187 |
|
115 | | -* `HMAC (all supported hashes)` |
| 188 | +### Scrypt KDF |
116 | 189 |
|
117 | | -* `KMAC (KMAC128, KMAC256)` |
| 190 | +```pascal |
| 191 | +uses |
| 192 | + SysUtils, HlpIHashInfo, HlpHashFactory, HlpConverters; |
118 | 193 |
|
119 | | -* `Blake2MAC (Blake2BMAC, Blake2SMAC)` |
| 194 | +var |
| 195 | + LDerivedKey: TBytes; |
| 196 | +begin |
| 197 | + LDerivedKey := TKDF.TPBKDF_Scrypt.CreatePBKDF_Scrypt( |
| 198 | + TConverters.ConvertStringToBytes('password', TEncoding.UTF8), |
| 199 | + TConverters.ConvertStringToBytes('salt', TEncoding.UTF8), |
| 200 | + 1024, 8, 1) |
| 201 | + .GetBytes(32); |
120 | 202 |
|
121 | | -### XOF (Extendable Output Function) |
122 | | ----------------------------------------- |
| 203 | + WriteLn(TConverters.ConvertBytesToHexString(LDerivedKey)); |
| 204 | +end; |
| 205 | +``` |
123 | 206 |
|
124 | | -* `Shake (Shake-128, Shake-256)` |
| 207 | +## Running Tests |
125 | 208 |
|
126 | | -* `CShake (CShake-128, CShake-256)` |
| 209 | +Tests use **DUnit** (Delphi) and **FPCUnit** (FreePascal). |
127 | 210 |
|
128 | | -* `Blake2X (Blake2XS, Blake2XB)` |
| 211 | +- **Delphi:** Open `HashLib.Tests/Delphi.Tests/HashLib.Tests.dpr` in the IDE and run. |
| 212 | +- **FreePascal / Lazarus:** Open `HashLib.Tests/FreePascal.Tests/HashLib.Tests.lpi` in the IDE and run. |
129 | 213 |
|
130 | | -* `KMACXOF (KMAC128XOF, KMAC256XOF)` |
| 214 | +## Contributing |
131 | 215 |
|
132 | | -* `Blake3XOF` |
| 216 | +Contributions are welcome. Please open an [issue](https://github.com/Xor-el/HashLib4Pascal/issues) for bug reports or feature requests, and submit pull requests. |
133 | 217 |
|
134 | | -### Supported Compilers |
135 | | ----------------------------------------- |
| 218 | +## Other Implementations |
136 | 219 |
|
137 | | -* `FreePascal 3.0.0+` |
| 220 | +If you want implementations in other languages, you can check out these: |
138 | 221 |
|
139 | | -* `Delphi 2010+` |
| 222 | +- [HashLib4CPP](https://github.com/ron4fun/HashLib4CPP) by Mbadiwe Nnaemeka Ronald |
140 | 223 |
|
141 | | -### Other Implementations |
142 | | ----------------------------------------- |
| 224 | +## Tip Jar |
143 | 225 |
|
144 | | -If you want implementations in other languages, you can check out these |
| 226 | +If you find this library useful and would like to support its continued development, tips are greatly appreciated! 🙏 |
145 | 227 |
|
146 | | -* [HashLib4CPP](https://github.com/ron4fun/HashLib4CPP) by Mbadiwe Nnaemeka Ronald |
| 228 | +| Cryptocurrency | Wallet Address | |
| 229 | +|---|---| |
| 230 | +| <img src="https://raw.githubusercontent.com/spothq/cryptocurrency-icons/master/32/icon/btc.png" width="20" alt="Bitcoin" /> **Bitcoin (BTC)** | `bc1quqhe342vw4ml909g334w9ygade64szqupqulmu` | |
| 231 | +| <img src="https://raw.githubusercontent.com/spothq/cryptocurrency-icons/master/32/icon/eth.png" width="20" alt="Ethereum" /> **Ethereum (ETH)** | `0x53651185b7467c27facab542da5868bfebe2bb69` | |
| 232 | +| <img src="https://raw.githubusercontent.com/spothq/cryptocurrency-icons/master/32/icon/sol.png" width="20" alt="Solana" /> **Solana (SOL)** | `BPZHjY1eYCdQjLecumvrTJRi5TXj3Yz1vAWcmyEB9Miu` | |
147 | 233 |
|
148 | | -### Tip Jar |
149 | | ----------------------------------------- |
| 234 | +## License |
150 | 235 |
|
151 | | -* :dollar: **Bitcoin**: `1MhFfW7tDuEHQSgie65uJcAfJgCNchGeKf` |
152 | | -* :euro: **Ethereum**: `0x6c1DC21aeC49A822A4f1E3bf07c623C2C1978a98` |
153 | | -* :pound: **Pascalcoin**: `345367-40` |
| 236 | +HashLib4Pascal is released under the [MIT License](LICENSE). |
0 commit comments