tinyhmacmd5 0.4.1-es2026 → 0.4.1

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 **982 bytes**.
5
+ A tiny and reliable HMAC-MD5 implementation for JavaScript: [`browser.min.js`](browser.min.js) is only **1014 bytes**.
6
6
 
7
7
  - **Input type**: `string` (UTF‑8), `Uint8Array` or `Uint8ClampedArray`
8
8
  - **Output type**: hex `string` or bytes `Uint8Array`
@@ -10,10 +10,14 @@ A tiny and reliable HMAC-MD5 implementation for JavaScript: [`browser.min.js`](b
10
10
  - **TypeScript‑ready**: [`main.d.ts`](main.d.ts)
11
11
  - **0 dependencies**
12
12
 
13
+ **Live demo**: https://bddjr.github.io/tinyhmacmd5/
14
+
13
15
  `tinyhmacmd5` does not simply aim for the smallest possible size.
14
16
  Its goal is to balance code size and runtime performance, so some performance-oriented implementations are intentionally retained.
15
17
  As a result, the final size is not the smallest theoretically achievable.
16
18
 
19
+ If you need a smaller implementation that targets ECMAScript 2026, see the [`es2026`](https://github.com/bddjr/tinyhmacmd5/tree/es2026) branch.
20
+
17
21
  > [!WARNING]
18
22
  > MD5 is cryptographically broken and unsafe for security-sensitive applications.
19
23
  > Do not rely on it for password hashing, digital signatures, or certificate verification.
@@ -23,7 +27,7 @@ As a result, the final size is not the smallest theoretically achievable.
23
27
  ### npm
24
28
 
25
29
  ```
26
- npm i tinyhmacmd5@es2026
30
+ npm i tinyhmacmd5
27
31
  ```
28
32
 
29
33
  ```js
@@ -39,7 +43,7 @@ You can also use other package managers (e.g. `pnpm` or `yarn`) in place of `npm
39
43
  See https://www.jsdelivr.com/package/npm/tinyhmacmd5
40
44
 
41
45
  ```html
42
- <script src="https://cdn.jsdelivr.net/npm/tinyhmacmd5@es2026"></script>
46
+ <script src="https://cdn.jsdelivr.net/npm/tinyhmacmd5"></script>
43
47
  ```
44
48
 
45
49
  It will define the `md5` function using `var`.
@@ -47,7 +51,7 @@ It will define the `md5` function using `var`.
47
51
  ### UNPKG
48
52
 
49
53
  ```html
50
- <script src="https://unpkg.com/tinyhmacmd5@es2026"></script>
54
+ <script src="https://unpkg.com/tinyhmacmd5"></script>
51
55
  ```
52
56
 
53
57
  It will define the `md5` function using `var`.
@@ -138,22 +142,22 @@ md5(data)
138
142
 
139
143
  ## Runtime Environment
140
144
 
141
- Environments that support [`Uint8Array.prototype.toHex()`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array/toHex) :
145
+ Environments that support [Exponentiation (`**`)](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Operators/Exponentiation) and [`TextEncoder`](https://developer.mozilla.org/docs/Web/API/TextEncoder) :
142
146
 
143
147
  - Desktop
144
- - Chrome ≥ 140 (2025-09-02)
145
- - Edge ≥ 140 (2025-09-05)
146
- - Firefox ≥ 133 (2024-11-26)
147
- - Opera ≥ 124 (2025-11-13)
148
- - Safari ≥ 18.2 (2024-12-11)
148
+ - Chrome ≥ 52 (2016-07-20)
149
+ - Edge ≥ 79 (2020-01-15)
150
+ - Firefox ≥ 52 (2017-03-07)
151
+ - Opera ≥ 39 (2016-08-02)
152
+ - Safari ≥ 10.1 (2017-03-27)
149
153
  - Mobile
150
- - Chrome Android ≥ 140 (2025-09-02)
151
- - Firefox for Android ≥ 133 (2024-11-26)
152
- - Opera Android ≥ 92 (2025-10-08)
153
- - Safari on iOS ≥ 18.2 (2024-12-11)
154
- - Samsung Browser ×
155
- - WebView Android ≥ 140 (2025-09-02)
156
- - WebView on iOS ≥ 18.2 (2024-12-11)
154
+ - Chrome Android ≥ 52 (2016-07-27)
155
+ - Firefox for Android ≥ 52 (2017-03-07)
156
+ - Opera Android ≥ 41 (2016-10-25)
157
+ - Safari on iOS ≥ 10.3 (2017-03-27)
158
+ - Samsung Browser ≥ 6 (2017-08-23)
159
+ - WebView Android ≥ 51 (2016-06-08)
160
+ - WebView on iOS ≥ 10.3 (2017-03-27)
157
161
 
158
162
  Not recommended for use in environments that support `node:crypto`, as `node:crypto` already provides HMAC-MD5.
159
163
 
@@ -206,7 +210,7 @@ During the adaptation, I discovered that `blueimp-md5` did not correctly handle
206
210
 
207
211
  I also found that using `Array` to process inputs over 512 MiB could throw a `RangeError`, so I replaced it with `Int32Array`.
208
212
 
209
- I demonstrated in practice that HMAC-MD5 can be implemented in an extremely small footprint (982 bytes) while also improving reliability.
213
+ I demonstrated in practice that HMAC-MD5 can be implemented in an extremely small footprint (1014 bytes) while also improving reliability.
210
214
 
211
215
  Maybe not many people care about saving just a few KB, but `tinyhmacmd5` exists precisely to "explore the unknown".
212
216
 
package/browser.min.js CHANGED
@@ -1 +1 @@
1
- /*! npmjs.com/tinyhmacmd5 */{let e=Math,r=Int32Array,n=Uint8Array,t=new r(64).map((r,n)=>2**32*e.abs(e.sin(n+1))),f=1&new n(t.buffer)[3],o=(n,f,o=0,a,l=1732584193,w=271733878,u,i,s=n.length,c=r.of(l,~w,~l,w),d=new r(c))=>{for(n[s-1]=f/2**29,n[e.floor(f/4)]|=128<<(n[s-2]=f<<3);o<s;o+=16){for(f=0;f<16;f+=4)for(a=0;a<16;)c[i&=3]=((w=c[i]+t[4*f+a]+(l=c[3&++i],w=c[3&++i],u=c[3&++i],w^(f>4?f>8?l|~u:l^u:f?u&(l^w):~l&(w^u)))+n[o+(a*(29521>>f)+(1296>>f)&15)])<<(u="',16%).4$+07&*/5".charCodeAt(3&a++|f))|w>>>32-u)+l;for(;i;)d[--i]=c[i]+=d[i]}return c},a=(t,o,a=("string"==typeof t?t=(new TextEncoder).encode(t):t).length,l=new r(o+16*e.ceil((a+9)/64)),w=f&&new n(l.buffer,4*o).set(t))=>{for(;w<a;3&++w||o++)l[o]|=t[w]<<8*w;return[l,a]};var md5=(e,t,f)=>{var l=16,w=null!=t,[u,i]=a(e,w*l),s=new n(l);if(w){let[e,n]=a(t,0),f=new r(32);for(n>64&&(e=o(e,n)),n=l;n;)f[--n]=1785358954^(u[n]=909522486^e[n]);f.set(o(u,64+i),l),u=f,i=80}for(u=o(u,i);l;)s[--l]=u[l>>2]>>8*l;return f?s:s.toHex()}}
1
+ /*! npmjs.com/tinyhmacmd5 */{let e=Math,r=Int32Array,n=Uint8Array,t=new r(64).map((r,n)=>2**32*e.abs(e.sin(n+1))),f=1&new n(t.buffer)[3],o=(n,f,o=0,a,l=1732584193,w=271733878,i,u,s=n.length,c=r.of(l,~w,~l,w),d=new r(c))=>{for(n[s-1]=f/2**29,n[e.floor(f/4)]|=128<<(n[s-2]=f<<3);o<s;o+=16){for(f=0;f<16;f+=4)for(a=0;a<16;)c[u&=3]=((w=c[u]+t[4*f+a]+(l=c[3&++u],w=c[3&++u],i=c[3&++u],w^(f>4?f>8?l|~i:l^i:f?i&(l^w):~l&(w^i)))+n[o+(a*(29521>>f)+(1296>>f)&15)])<<(i="',16%).4$+07&*/5".charCodeAt(3&a++|f))|w>>>32-i)+l;for(;u;)d[--u]=c[u]+=d[u]}return c},a=(t,o,a=("string"==typeof t?t=(new TextEncoder).encode(t):t).length,l=new r(o+16*e.ceil((a+9)/64)),w=f&&new n(l.buffer,4*o).set(t))=>{for(;w<a;3&++w||o++)l[o]|=t[w]<<8*w;return[l,a]};var md5=(e,t,f)=>{var l=16,w=null!=t,[i,u]=a(e,w*l),s=f?new n(l):"";if(w){let[e,n]=a(t,0),f=new r(32);for(n>64&&(e=o(e,n)),n=l;n;)f[--n]=1785358954^(i[n]=909522486^e[n]);f.set(o(i,64+u),l),i=f,u=80}for(i=o(i,u);l;f?s[l]=u:s=(u>>4&&"")+u.toString(16)+s)u=i[--l>>2]>>8*l&255;return s}}
package/main.js CHANGED
@@ -130,7 +130,9 @@ var md5 = (data, key, raw) => {
130
130
  var i = 16
131
131
  , hasKey = key != null
132
132
  , [bdata, temp] = inputToWords(data, /**@type {*}*/(hasKey) * i)
133
- , out = new $Uint8Array(i)
133
+
134
+ /** @type {*} */
135
+ var out = raw ? new $Uint8Array(i) : ''
134
136
 
135
137
  if (hasKey) {
136
138
  // HMAC
@@ -151,11 +153,15 @@ var md5 = (data, key, raw) => {
151
153
  bdata = wordsMD5(bdata, temp)
152
154
 
153
155
  // words to bytes or hex
154
- for (; i;) {
155
- out[--i] = bdata[i >> 2] >> i * 8
156
+ for (; i;
157
+ raw
158
+ ? out[i] = temp
159
+ : out = (temp >> 4 && '') + temp.toString(16) + out
160
+ ) {
161
+ temp = bdata[--i >> 2] >> i * 8 & 0xff
156
162
  }
157
163
 
158
- return raw ? out : out.toHex()
164
+ return out
159
165
  }
160
166
 
161
167
  export default md5
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "tinyhmacmd5",
3
- "version": "0.4.1-es2026",
4
- "description": "A tiny and reliable HMAC-MD5 implementation for JavaScript: browser.min.js is only 982 bytes.",
3
+ "version": "0.4.1",
4
+ "description": "A tiny and reliable HMAC-MD5 implementation for JavaScript: browser.min.js is only 1014 bytes.",
5
5
  "author": "bddjr",
6
6
  "license": "MIT",
7
7
  "type": "module",
@@ -63,7 +63,7 @@
63
63
  "typescript": "^7.0.2"
64
64
  },
65
65
  "scripts": {
66
- "build": "tsc && node scripts/build.mjs && es-check es2026 --module --checkFeatures main.js browser.min.js",
66
+ "build": "tsc && node scripts/build.mjs && es-check es2016 --module --checkFeatures main.js browser.min.js",
67
67
  "build:unchanged": "node scripts/build-unchanged.mjs",
68
68
  "test": "pnpm build && pnpm test:only",
69
69
  "test:only": "node scripts/test.mjs && node scripts/test-513MiB.mjs",