tinyhmacmd5 0.3.2-es2026 → 0.3.3-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/README.md CHANGED
@@ -2,7 +2,7 @@ English | [中文](README-zh.md)
2
2
 
3
3
  # Tiny HMAC MD5
4
4
 
5
- A tiny and reliable HMAC-MD5 implementation for JavaScript: [`browser.min.js`](browser.min.js) is only **952 bytes**.
5
+ A tiny and reliable HMAC-MD5 implementation for JavaScript: [`browser.min.js`](browser.min.js) is only **950 bytes**.
6
6
 
7
7
  - **Input type**: `string` (UTF‑8), `Uint8Array` or `Uint8ClampedArray`
8
8
  - **Output type**: hex `string` or bytes `Uint8Array`
@@ -168,21 +168,26 @@ pnpm benchmark
168
168
  ```
169
169
  Data length: 104857600 chars (100MiB)
170
170
  --------------------------------------------------
171
- tinyhmacmd5 : 724.91 ms
172
- js-md5 : 138.45 ms
173
- blueimp-md5 : 4014.42 ms
174
- crypto-js : 1637.30 ms
175
- native crypto : 135.11 ms
171
+ tinyhmacmd5 : 640.00 ms
172
+ js-md5 : 131.10 ms
173
+ blueimp-md5 : 3825.62 ms
174
+ crypto-js : 1572.49 ms
175
+ node:crypto : 130.07 ms
176
176
  --------------------------------------------------
177
- ✅ All pure JS implementations match native crypto result.
177
+ ✅ All pure JS implementations match node:crypto result.
178
178
 
179
179
  --- Pure 513MiB Test (No prior small tests) ---
180
- tinyhmacmd5 HMAC-MD5 timer: 3.463s
181
- node:crypto HMAC-MD5 timer: 572.541ms
182
- tinyhmacmd5 MD5 timer: 3.450s
183
- node:crypto MD5 timer: 569.816ms
180
+ tinyhmacmd5 HMAC-MD5 timer: 3.184s
181
+ node:crypto HMAC-MD5 timer: 552.938ms
182
+ tinyhmacmd5 MD5 timer: 3.175s
183
+ node:crypto MD5 timer: 553.263ms
184
184
  ```
185
185
 
186
+ CPU: i5-10600KF
187
+ DRAM: 64GiB DDR4 3333MT/s
188
+ OS: Windows 11 Pro for Workstations 25H2 26200.8737
189
+ Node.js: v26.8.1
190
+
186
191
  ---
187
192
 
188
193
  ## Why I Made This Project
@@ -201,7 +206,7 @@ During the adaptation, I discovered that `blueimp-md5` did not correctly handle
201
206
 
202
207
  I also found that using `Array` to process inputs over 512 MiB could throw a `RangeError`, so I replaced it with `Int32Array`.
203
208
 
204
- I demonstrated in practice that HMAC-MD5 can be implemented in an extremely small footprint (952 bytes) while also improving reliability.
209
+ I demonstrated in practice that HMAC-MD5 can be implemented in an extremely small footprint (950 bytes) while also improving reliability.
205
210
 
206
211
  Maybe not many people care about saving just a few KB, but `tinyhmacmd5` exists precisely to "explore the unknown".
207
212
 
package/browser.min.js CHANGED
@@ -1 +1 @@
1
- /*! npmjs.com/tinyhmacmd5 */{let r=Math,e=r.floor,n=Int32Array,t=new n(64).map((e,n)=>2**32*r.abs(r.sin(n+1))),o=(r,o,f=0,a,l=1732584193,w=271733878,d,h,i=r.length,s=n.of(l,~w,~l,w),u=new n(s))=>{for(r[i-1]=o/2**29,r[e(o/4)]|=128<<(r[i-2]=o<<3);f<i;f+=16){for(o=0;o<16;o+=4)for(a=0;a<16;)s[h&=3]=((w=s[h]+t[4*o|a]+(l=s[3&++h],w=s[3&++h],d=s[3&++h],o?o>4?o>8?w^(l|~d):l^w^d:l&d|w&~d:l&w|~l&d)+r[f+(a*(29521>>o)+(1296>>o)&15)])<<(d="',16%).4$+07&*/5".charCodeAt(3&a++|o))|w>>>64-d)+l;for(;h;)u[--h]=s[h]+=u[h]}return s},f=(r,t,o=("string"==typeof r?r=(new TextEncoder).encode(r):r).length,f=new n(16*e((4*t+o+72)/64)),a=0)=>{for(;a<o;)f[t++]=r[a++]|r[a++]<<8|r[a++]<<16|r[a++]<<24;return[f,o]};var md5=(r,e,t)=>{var a=16,l=null!=e,[w,d]=f(r,l*a),h=new Uint8Array(a);if(l){let[r,t]=f(e,0),l=new n(32);for(t>64&&(r=o(r,t)),t=a;t;)l[--t]=1785358954^(w[t]=909522486^r[t]);l.set(o(w,64+d),a),w=l,d=80}for(w=o(w,d);a;)h[--a]=w[a>>2]>>8*a;return t?h:h.toHex()}}
1
+ /*! npmjs.com/tinyhmacmd5 */{let r=Math,e=Int32Array,n=new e(64).map((e,n)=>2**32*r.abs(r.sin(n+1))),t=(t,o,f=0,a,l=1732584193,w=271733878,i,c,d=t.length,h=e.of(l,~w,~l,w),s=new e(h))=>{for(t[d-1]=o/2**29,t[r.floor(o/4)]|=128<<(t[d-2]=o<<3);f<d;f+=16){for(o=0;o<16;o+=4)for(a=0;a<16;)h[c&=3]=((w=h[c]+n[4*o+a]+(l=h[3&++c],w=h[3&++c],i=h[3&++c],o?w^(o>4?o>8?l|~i:l^i:i&(l^w)):l&w|~l&i)+t[f+(a*(29521>>o)+(1296>>o)&15)])<<(i="',16%).4$+07&*/5".charCodeAt(3&a++|o)-32)|w>>>32-i)+l;for(;c;)s[--c]=h[c]+=s[c]}return h},o=(n,t,o=("string"==typeof n?n=(new TextEncoder).encode(n):n).length,f=new e(t+16*r.ceil((o+9)/64)),a=0)=>{for(;a<o;)f[t++]=n[a++]|n[a++]<<8|n[a++]<<16|n[a++]<<24;return[f,o]};var md5=(r,n,f)=>{var a=16,l=null!=n,[w,i]=o(r,l*a),c=new Uint8Array(a);if(l){let[r,f]=o(n,0),l=new e(32);for(f>64&&(r=t(r,f)),f=a;f;)l[--f]=1785358954^(w[f]=909522486^r[f]);l.set(t(w,64+i),a),w=l,i=80}for(w=t(w,i);a;)c[--a]=w[a>>2]>>8*a;return f?c:c.toHex()}}
package/main.js CHANGED
@@ -4,8 +4,6 @@
4
4
 
5
5
  let $Math = Math
6
6
 
7
- let floor = $Math.floor
8
-
9
7
  let $Int32Array = Int32Array
10
8
 
11
9
  /** MD5 constants cached in memory */
@@ -40,7 +38,7 @@ let wordsMD5 = (
40
38
  // append padding
41
39
  // `l` may be >= 2**32, so cannot use `>>>` as a replacement for `floor`
42
40
  x[xLen - 1] = l / 2 ** 29;
43
- x[floor(l / 4)] |= 0x80 << (x[xLen - 2] = l << 3);
41
+ x[$Math.floor(l / 4)] |= 0x80 << (x[xLen - 2] = l << 3);
44
42
 
45
43
  for (; i < xLen; i += 16) {
46
44
  for (l = 0; l < 16; l += 4) {
@@ -49,24 +47,26 @@ let wordsMD5 = (
49
47
  (
50
48
  t1 = (
51
49
  output[oi] +
52
- K[l * 4 | j] +
50
+ K[l * 4 + j] +
53
51
  (
54
52
  t0 = output[++oi & 3],
55
53
  t1 = output[++oi & 3],
56
54
  t2 = output[++oi & 3],
57
55
  l
58
- ? l > 4
59
- ? l > 8
60
- ? t1 ^ (t0 | ~t2) // Round 4: I
61
- : t0 ^ t1 ^ t2 // Round 3: H
62
- : t0 & t2 | t1 & ~t2 // Round 2: G
63
- : t0 & t1 | ~t0 & t2 // Round 1: F
56
+ ? t1 ^ (
57
+ l > 4
58
+ ? l > 8
59
+ ? t0 | ~t2 // Round 4: I
60
+ : t0 ^ t2 // Round 3: H
61
+ : t2 & (t0 ^ t1) // Round 2: G
62
+ )
63
+ : t0 & t1 | ~t0 & t2 // Round 1: F
64
64
  ) +
65
65
  x[i + (j * (0x7351 >> l) + (0x0510 >> l) & 15)]
66
66
  )
67
67
  ) << (
68
- t2 = "',16%).4$+07&*/5".charCodeAt(j++ & 3 | l)
69
- ) | t1 >>> 64 - t2
68
+ t2 = "',16%).4$+07&*/5".charCodeAt(j++ & 3 | l) - 32
69
+ ) | t1 >>> 32 - t2
70
70
  ) + t0
71
71
  }
72
72
  }
@@ -81,7 +81,7 @@ let wordsMD5 = (
81
81
  * Convert bytes to an array of little-endian words
82
82
  *
83
83
  * @param {*} input
84
- * @param {number} j pad int32 length
84
+ * @param {number} j pad int32 length (0 or 16)
85
85
  *
86
86
  * @returns {[Int32Array<ArrayBuffer>, number]}
87
87
  */
@@ -96,7 +96,7 @@ let inputToWords = (
96
96
  ).length,
97
97
  // Using `Array` to process inputs over 512 MiB could throw a `RangeError`,
98
98
  // so I replaced it with `Int32Array`.
99
- output = new $Int32Array(floor((j * 4 + byteLen + 72) / 64) * 16),
99
+ output = new $Int32Array(j + $Math.ceil((byteLen + 9) / 64) * 16),
100
100
  i = 0,
101
101
  ) => {
102
102
  for (; i < byteLen;) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "tinyhmacmd5",
3
- "version": "0.3.2-es2026",
4
- "description": "A tiny and reliable HMAC-MD5 implementation for JavaScript: browser.min.js is only 952 bytes.",
3
+ "version": "0.3.3-es2026",
4
+ "description": "A tiny and reliable HMAC-MD5 implementation for JavaScript: browser.min.js is only 950 bytes.",
5
5
  "author": "bddjr",
6
6
  "license": "MIT",
7
7
  "type": "module",