tinyhmacmd5 0.3.0-es2026 → 0.3.1-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 **963 bytes**.
5
+ A tiny and reliable HMAC-MD5 implementation for JavaScript: [`browser.min.js`](browser.min.js) is only **953 bytes**.
6
6
 
7
7
  - **Input type**: `string` (UTF‑8), `Uint8Array` or `Uint8ClampedArray`
8
8
  - **Output type**: hex `string` or bytes `Uint8Array`
@@ -166,22 +166,21 @@ pnpm benchmark
166
166
  ```
167
167
 
168
168
  ```
169
- Generating 100MiB string data (this might take a moment)...
170
169
  Data length: 104857600 chars (100MiB)
171
170
  --------------------------------------------------
172
- tinyhmacmd5 : 718.27 ms
173
- js-md5 : 141.43 ms
174
- blueimp-md5 : 3934.98 ms
175
- crypto-js : 1732.55 ms
176
- native crypto : 136.60 ms
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
177
176
  --------------------------------------------------
178
177
  ✅ All pure JS implementations match native crypto result.
179
178
 
180
179
  --- Pure 513MiB Test (No prior small tests) ---
181
- tinyhmacmd5 HMAC-MD5 timer: 3.465s
182
- node:crypto HMAC-MD5 timer: 572.686ms
183
- tinyhmacmd5 MD5 timer: 3.451s
184
- node:crypto MD5 timer: 571.58ms
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
185
184
  ```
186
185
 
187
186
  ---
@@ -202,7 +201,7 @@ During the adaptation, I discovered that `blueimp-md5` did not correctly handle
202
201
 
203
202
  I also found that using `Array` to process inputs over 512 MiB could throw a `RangeError`, so I replaced it with `Int32Array`.
204
203
 
205
- I demonstrated in practice that HMAC-MD5 can be implemented in an extremely small footprint (963 bytes) while also improving reliability.
204
+ I demonstrated in practice that HMAC-MD5 can be implemented in an extremely small footprint (953 bytes) while also improving reliability.
206
205
 
207
206
  Maybe not many people care about saving just a few KB, but `tinyhmacmd5` exists precisely to "explore the unknown".
208
207
 
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=>16*e((r+72)/64),f=(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},a=(r,e,t=("string"==typeof r?r=(new TextEncoder).encode(r):r).length,f=new n(o(4*e+t)),a=0)=>{for(;a<t;)f[e++]=r[a++]|r[a++]<<8|r[a++]<<16|r[a++]<<24;return[f,t]};var md5=(r,e,t)=>{var o=16,l=null!=e,[w,d]=a(r,l*o),h=new Uint8Array(o);if(l){let[r,t]=a(e,0),l=new n(32);for(t>64&&(r=f(r,t)),t=o;t;)l[--t]=1785358954^(w[t]=909522486^r[t]);l.set(f(w,64+d),16),w=l,d=80}for(w=f(w,d);o;)h[--o]=w[o>>2]>>8*o;return t?h:h.toHex()}}
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),16),w=l,d=80}for(w=o(w,d);a;)h[--a]=w[a>>2]>>8*a;return t?h:h.toHex()}}
package/main.js CHANGED
@@ -11,10 +11,6 @@ let $Int32Array = Int32Array
11
11
  /** MD5 constants cached in memory */
12
12
  let K = new $Int32Array(64).map((v, i) => 2 ** 32 * $Math.abs($Math.sin(i + 1)))
13
13
 
14
- /** @param {number} byteLen */
15
- // `byteLen` may be >= 2**32, so cannot use `>>>` as a replacement for `floor`
16
- let wordsLen = (byteLen) => floor((byteLen + 72) / 64) * 16
17
-
18
14
  /**
19
15
  * Calculate the MD5 of an array of little-endian words, and a byte length.
20
16
  *
@@ -100,7 +96,7 @@ let inputToWords = (
100
96
  ).length,
101
97
  // Using `Array` to process inputs over 512 MiB could throw a `RangeError`,
102
98
  // so I replaced it with `Int32Array`.
103
- output = new $Int32Array(wordsLen(j * 4 + byteLen)),
99
+ output = new $Int32Array(floor((j * 4 + byteLen + 72) / 64) * 16),
104
100
  i = 0,
105
101
  ) => {
106
102
  for (; i < byteLen;) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "tinyhmacmd5",
3
- "version": "0.3.0-es2026",
4
- "description": "A tiny and reliable HMAC-MD5 implementation for JavaScript: browser.min.js is only 963 bytes.",
3
+ "version": "0.3.1-es2026",
4
+ "description": "A tiny and reliable HMAC-MD5 implementation for JavaScript: browser.min.js is only 953 bytes.",
5
5
  "author": "bddjr",
6
6
  "license": "MIT",
7
7
  "type": "module",