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