tinyhmacmd5 0.4.2-es2026 → 0.5.0-es2026
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +20 -18
- package/README.md +43 -68
- package/browser.min.js +1 -1
- package/main.js +1 -5
- package/package.json +3 -3
package/LICENSE
CHANGED
|
@@ -1,22 +1,24 @@
|
|
|
1
|
-
|
|
1
|
+
This is free and unencumbered software released into the public domain.
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
Anyone is free to copy, modify, publish, use, compile, sell, or
|
|
4
|
+
distribute this software, either in source code form or as a compiled
|
|
5
|
+
binary, for any purpose, commercial or non-commercial, and by any
|
|
6
|
+
means.
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
this software
|
|
9
|
-
the
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
In jurisdictions that recognize copyright laws, the author or authors
|
|
9
|
+
of this software dedicate any and all copyright interest in the
|
|
10
|
+
software to the public domain. We make this dedication for the benefit
|
|
11
|
+
of the public at large and to the detriment of our heirs and
|
|
12
|
+
successors. We intend this dedication to be an overt act of
|
|
13
|
+
relinquishment in perpetuity of all present and future rights to this
|
|
14
|
+
software under copyright law.
|
|
13
15
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
19
|
+
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
20
|
+
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
21
|
+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
|
16
23
|
|
|
17
|
-
|
|
18
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
19
|
-
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
20
|
-
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
21
|
-
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
22
|
-
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
24
|
+
For more information, please refer to <https://unlicense.org/>
|
package/README.md
CHANGED
|
@@ -4,22 +4,59 @@ English | [中文](README-zh.md)
|
|
|
4
4
|
|
|
5
5
|
A tiny and reliable HMAC-MD5 implementation for JavaScript:
|
|
6
6
|
|
|
7
|
-
[`browser.min.js`](browser.min.js) is only **
|
|
7
|
+
[`browser.min.js`](browser.min.js) is only **947 bytes**.
|
|
8
8
|
|
|
9
9
|
- **Input type**: `string` (UTF‑8), `Uint8Array` or `Uint8ClampedArray`
|
|
10
10
|
- **Output type**: hex `string` or bytes `Uint8Array`
|
|
11
|
-
- **Supports inputs ≥ 512 MiB**: The input length theoretically supports 0 to 2⁵³-
|
|
11
|
+
- **Supports inputs ≥ 512 MiB**: The input length theoretically supports 0 to 2⁵³-137
|
|
12
12
|
- **TypeScript‑ready**: [`main.d.ts`](main.d.ts)
|
|
13
13
|
- **0 dependencies**
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
**Live demo**: https://bddjr.github.io/tinyhmacmd5/
|
|
16
|
+
|
|
17
|
+
If you need a smaller implementation that targets ECMAScript 2026, see the [`es2026`](https://github.com/bddjr/tinyhmacmd5/tree/es2026) branch.
|
|
18
18
|
|
|
19
19
|
> [!WARNING]
|
|
20
20
|
> MD5 is cryptographically broken and unsafe for security-sensitive applications.
|
|
21
21
|
> Do not rely on it for password hashing, digital signatures, or certificate verification.
|
|
22
22
|
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## Benchmark
|
|
26
|
+
|
|
27
|
+
```
|
|
28
|
+
pnpm benchmark
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
Data length: 104857600 chars (100MiB)
|
|
33
|
+
--------------------------------------------------
|
|
34
|
+
tinyhmacmd5 : 550.92 ms
|
|
35
|
+
js-md5 : 128.96 ms
|
|
36
|
+
blueimp-md5 : 3837.83 ms
|
|
37
|
+
crypto-js : 1562.08 ms
|
|
38
|
+
node:crypto : 129.08 ms
|
|
39
|
+
--------------------------------------------------
|
|
40
|
+
✅ All pure JS implementations match node:crypto result.
|
|
41
|
+
|
|
42
|
+
--- Pure 513MiB Test (No prior small tests) ---
|
|
43
|
+
tinyhmacmd5 HMAC-MD5 timer: 2.706s
|
|
44
|
+
node:crypto HMAC-MD5 timer: 547.808ms
|
|
45
|
+
tinyhmacmd5 MD5 timer: 2.693s
|
|
46
|
+
node:crypto MD5 timer: 550.144ms
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
CPU: i5-10600KF
|
|
50
|
+
DRAM: 64GiB DDR4 3333MT/s
|
|
51
|
+
OS: Windows 11 Pro for Workstations 25H2 26200.8737
|
|
52
|
+
Node.js: v26.8.1
|
|
53
|
+
|
|
54
|
+
`tinyhmacmd5` does not simply aim for the smallest possible size.
|
|
55
|
+
Its goal is to balance code size and runtime performance, so some performance-oriented implementations are intentionally retained.
|
|
56
|
+
As a result, the final size is not the smallest theoretically achievable.
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
23
60
|
## Setup
|
|
24
61
|
|
|
25
62
|
### npm
|
|
@@ -63,10 +100,6 @@ It will define the `md5` function using `var`.
|
|
|
63
100
|
|
|
64
101
|
## Example
|
|
65
102
|
|
|
66
|
-
> [!NOTE]
|
|
67
|
-
> Please ensure that the input type matches the definition in [`main.d.ts`](main.d.ts).
|
|
68
|
-
> Invalid types may return an incorrect MD5 hash.
|
|
69
|
-
|
|
70
103
|
HMAC-MD5:
|
|
71
104
|
|
|
72
105
|
```js
|
|
@@ -161,67 +194,9 @@ Not recommended for use in environments that support `node:crypto`, as `node:cry
|
|
|
161
194
|
|
|
162
195
|
---
|
|
163
196
|
|
|
164
|
-
## Benchmark
|
|
165
|
-
|
|
166
|
-
```
|
|
167
|
-
pnpm benchmark
|
|
168
|
-
```
|
|
169
|
-
|
|
170
|
-
```
|
|
171
|
-
Data length: 104857600 chars (100MiB)
|
|
172
|
-
--------------------------------------------------
|
|
173
|
-
tinyhmacmd5 : 550.92 ms
|
|
174
|
-
js-md5 : 128.96 ms
|
|
175
|
-
blueimp-md5 : 3837.83 ms
|
|
176
|
-
crypto-js : 1562.08 ms
|
|
177
|
-
node:crypto : 129.08 ms
|
|
178
|
-
--------------------------------------------------
|
|
179
|
-
✅ All pure JS implementations match node:crypto result.
|
|
180
|
-
|
|
181
|
-
--- Pure 513MiB Test (No prior small tests) ---
|
|
182
|
-
tinyhmacmd5 HMAC-MD5 timer: 2.706s
|
|
183
|
-
node:crypto HMAC-MD5 timer: 547.808ms
|
|
184
|
-
tinyhmacmd5 MD5 timer: 2.693s
|
|
185
|
-
node:crypto MD5 timer: 550.144ms
|
|
186
|
-
```
|
|
187
|
-
|
|
188
|
-
CPU: i5-10600KF
|
|
189
|
-
DRAM: 64GiB DDR4 3333MT/s
|
|
190
|
-
OS: Windows 11 Pro for Workstations 25H2 26200.8737
|
|
191
|
-
Node.js: v26.8.1
|
|
192
|
-
|
|
193
|
-
---
|
|
194
|
-
|
|
195
|
-
## Why I Made This Project
|
|
196
|
-
|
|
197
|
-
I initially used HMAC-MD5 just to call a certain website's API. That site signs the request body with `crypto-js`'s HMAC-MD5 to make reverse engineering harder.
|
|
198
|
-
|
|
199
|
-
But I only needed HMAC-MD5. Depending on `crypto-js` felt way too bloated. The Web Crypto API doesn't support HMAC-MD5, so I had no choice but to drag in a dependency.
|
|
200
|
-
|
|
201
|
-
Then I found `blueimp-md5`. Its `md5.min.js` is only 3750 bytes, even smaller than `js-md5`.
|
|
202
|
-
|
|
203
|
-
But I felt `blueimp-md5` was still far too bloated. It has some completely unnecessary design choices—it repeatedly parses strings and creates new ones, adding a lot of unnecessary overhead.
|
|
204
|
-
|
|
205
|
-
So I decided to adapt it, use a more modern implementation, and shrink the size even further. That's how `tinyhmacmd5` was born.
|
|
206
|
-
|
|
207
|
-
During the adaptation, I discovered that `blueimp-md5` did not correctly handle the 64-bit length field required by MD5 when the input bit-length exceeded 32 bits. It wrote only the low 32 bits and ignored the high 32 bits. I fixed this bug.
|
|
208
|
-
|
|
209
|
-
I also found that using `Array` to process inputs over 512 MiB could throw a `RangeError`, so I replaced it with `Int32Array`.
|
|
210
|
-
|
|
211
|
-
I demonstrated in practice that HMAC-MD5 can be implemented in an extremely small footprint (975 bytes) while also improving reliability.
|
|
212
|
-
|
|
213
|
-
Maybe not many people care about saving just a few KB, but `tinyhmacmd5` exists precisely to "explore the unknown".
|
|
214
|
-
|
|
215
|
-
INVINCIBLE EXPERIMENT!
|
|
216
|
-
|
|
217
|
-
[Read the original Chinese text](README-zh.md#为什么做这个项目)
|
|
218
|
-
|
|
219
|
-
---
|
|
220
|
-
|
|
221
197
|
## License
|
|
222
198
|
|
|
223
|
-
|
|
224
|
-
See: [`LICENSE`](LICENSE)
|
|
199
|
+
This project is released into the public domain under the [Unlicense](https://unlicense.org).
|
|
225
200
|
|
|
226
201
|
---
|
|
227
202
|
|
package/browser.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
{let e=Int32Array,r=Uint8Array,n=new e(64).map((e,r)=>2**32*Math.abs(Math.sin(r+1))),t=1&new r(n.buffer)[3],f=(r,t,f=0,o,a=1732584193,w=271733878,l,u,h=r.length,s=e.of(a,~w,~a,w),d=new e(s))=>{for(r[h-1]=t/2**29,r[(t-t%4)/4]|=128<<(r[h-2]=t<<3);f<h;f+=16){for(t=o=0;t<16;t+=4)for(;o<4*t+16;)s[u&=3]=((w=s[u]+n[o]+(a=s[3&++u],w=s[3&++u],l=s[3&++u],w^(t>4?t>8?a|~l:a^l:t?l&(a^w):~a&(w^l)))+r[f+(o*(29521>>t)+(1296>>t)&15)])<<(l="',16%).4$+07&*/5".charCodeAt(3&o++|t))|w>>>32-l)+a;for(;u;)d[--u]=s[u]+=d[u]}return s},o=(n,f,o=("string"==typeof n?n=(new TextEncoder).encode(n):n).length,a=new e(f+18+(o-(o+8&63))/4),w=t&&new r(a.buffer,4*f).set(n))=>{for(;w<o;3&++w||f++)a[f]|=n[w]<<8*w;return[a,o]};var md5=(n,t,a)=>{var w=16,l=null!=t,[u,h]=o(n,l*w),s=new r(w);if(l){let[r,n]=o(t,0),a=new e(32);for(n>64&&(r=f(r,n)),n=w;n;)a[--n]=1785358954^(u[n]=909522486^r[n]);a.set(f(u,64+h),w),u=a,h=80}for(u=f(u,h);w;)s[--w]=u[w>>2]>>8*w;return a?s:s.toHex()}}
|
package/main.js
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
/*! npmjs.com/tinyhmacmd5 */
|
|
2
|
-
|
|
3
|
-
// Adapted from https://github.com/blueimp/JavaScript-MD5
|
|
4
|
-
|
|
5
1
|
let $Int32Array = Int32Array
|
|
6
2
|
|
|
7
3
|
let $Uint8Array = Uint8Array
|
|
@@ -125,7 +121,7 @@ let inputToWords = (
|
|
|
125
121
|
* @param {boolean} [raw] If true, the hash is returned as raw bytes (Uint8Array); otherwise, as a hex string.
|
|
126
122
|
* @returns {string | Uint8Array<ArrayBuffer>} The MD5 (or HMAC‑MD5) digest, either as a hex string or a Uint8Array.
|
|
127
123
|
*/
|
|
128
|
-
|
|
124
|
+
let md5 = (data, key, raw) => {
|
|
129
125
|
var i = 16
|
|
130
126
|
, hasKey = key != null
|
|
131
127
|
, [bdata, temp] = inputToWords(data, /**@type {*}*/(hasKey) * i)
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tinyhmacmd5",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "A tiny and reliable HMAC-MD5 implementation for JavaScript: browser.min.js is only
|
|
3
|
+
"version": "0.5.0-es2026",
|
|
4
|
+
"description": "A tiny and reliable HMAC-MD5 implementation for JavaScript: browser.min.js is only 947 bytes.",
|
|
5
5
|
"author": "bddjr",
|
|
6
|
-
"license": "
|
|
6
|
+
"license": "Unlicense",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"main": "main.js",
|
|
9
9
|
"types": "main.d.ts",
|