tinyhmacmd5 0.2.2-es2026 → 0.2.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 +3 -3
- package/browser.min.js +1 -1
- package/main.js +17 -19
- package/package.json +2 -2
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 **
|
|
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`
|
|
@@ -26,7 +26,7 @@ As a result, the final size is not the smallest theoretically achievable.
|
|
|
26
26
|
|
|
27
27
|
|
|
28
28
|
```
|
|
29
|
-
npm i tinyhmacmd5
|
|
29
|
+
npm i tinyhmacmd5@es2026
|
|
30
30
|
```
|
|
31
31
|
|
|
32
32
|
```js
|
|
@@ -178,7 +178,7 @@ During the adaptation, I discovered that `blueimp-md5` did not correctly handle
|
|
|
178
178
|
|
|
179
179
|
I also found that using `Array` to process inputs over 512 MiB could throw a `RangeError`, so I replaced it with `Int32Array`.
|
|
180
180
|
|
|
181
|
-
I demonstrated in practice that HMAC-MD5 can be implemented in an extremely small footprint (
|
|
181
|
+
I demonstrated in practice that HMAC-MD5 can be implemented in an extremely small footprint (950 bytes) while also improving reliability.
|
|
182
182
|
|
|
183
183
|
Maybe not many people care about saving just a few KB, but `tinyhmacmd5` exists precisely to "explore the unknown".
|
|
184
184
|
|
package/browser.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
/*! npmjs.com/tinyhmacmd5 */{let r=[],e=0,n=Math,t=n.floor,o=r=>16*t((r+72)/64),f=(e,n,f=0,a=o(n),l=1732584193,c=271733878,d,h,i=[l,~c,~l,c],u=[...i])=>{for(e[a-1]=0|n/2**29,e[t(n/4)]|=128<<(e[a-2]=n<<3);f<e.length;){for(a=0;a<64;
|
|
1
|
+
/*! npmjs.com/tinyhmacmd5 */{let r=[],e=0,n=Math,t=n.floor,o=r=>16*t((r+72)/64),f=(e,n,f=0,a=o(n),l=1732584193,c=271733878,d,h,i=[l,~c,~l,c],u=[...i])=>{for(e[a-1]=0|n/2**29,e[t(n/4)]|=128<<(e[a-2]=n<<3);f<e.length;f+=16){for(a=0;a<64;i[h&=3]=0|((c=0|i[h]+r[a]+(l=i[3&++h],c=i[3&++h],d=i[3&++h],n?n>4?n>8?c^(l|~d):l^c^d:l&d|c&~d:l&c|~l&d)+(0|e[f+(a*(29521>>n)+(1296>>n)&15)]))<<(d="',16%).4$+07&*/5".charCodeAt(3&a++|n))|c>>>64-d)+l)n=a>>4<<2;for(;h;)u[--h]=i[h]=0|u[h]+i[h]}return i},a=(r,e,n=("string"==typeof r?r=(new TextEncoder).encode(r):r).length,t=new Int32Array(o(4*e+n)),f=0)=>{for(;f<n;)t[e++]=r[f++]|r[f++]<<8|r[f++]<<16|r[f++]<<24;return[t,n]};for(var md5=(r,e,n)=>{var t=16,o=null!=e,[l,c]=a(r,o*t),d=new Uint8Array(t);if(o){let[r,n]=a(e,0),o=[];for(n>64&&(r=f(r,n)),n=t;n;)o[--n]=1785358954^(l[n]=909522486^r[n]);l=o.concat(f(l,64+c)),c=80}for(l=f(l,c);t;)d[--t]=l[t>>2]>>8*t;return n?d:d.toHex()};e<64;)r[e]=0|2**32*n.abs(n.sin(++e))}
|
package/main.js
CHANGED
|
@@ -44,8 +44,8 @@ let wordsMD5 = (
|
|
|
44
44
|
x[j - 1] = 0 | l / 2 ** 29;
|
|
45
45
|
x[floor(l / 4)] |= 0x80 << (x[j - 2] = l << 3);
|
|
46
46
|
|
|
47
|
-
for (; i < x.length;) {
|
|
48
|
-
for (j = 0; j < 64;
|
|
47
|
+
for (; i < x.length; i += 16) {
|
|
48
|
+
for (j = 0; j < 64;
|
|
49
49
|
output[oi &= 3] = 0 | (
|
|
50
50
|
(
|
|
51
51
|
t1 = 0 | (
|
|
@@ -55,7 +55,7 @@ let wordsMD5 = (
|
|
|
55
55
|
t0 = output[++oi & 3],
|
|
56
56
|
t1 = output[++oi & 3],
|
|
57
57
|
t2 = output[++oi & 3],
|
|
58
|
-
|
|
58
|
+
l
|
|
59
59
|
? l > 4
|
|
60
60
|
? l > 8
|
|
61
61
|
? t1 ^ (t0 | ~t2) // Round 4: I
|
|
@@ -71,8 +71,10 @@ let wordsMD5 = (
|
|
|
71
71
|
t2 = "',16%).4$+07&*/5".charCodeAt(j++ & 3 | l)
|
|
72
72
|
) | t1 >>> 64 - t2
|
|
73
73
|
) + t0
|
|
74
|
+
) {
|
|
75
|
+
l = j >> 4 << 2
|
|
74
76
|
}
|
|
75
|
-
for (; oi;
|
|
77
|
+
for (; oi;) {
|
|
76
78
|
oldOutput[--oi] = output[oi] = 0 | oldOutput[oi] + output[oi]
|
|
77
79
|
}
|
|
78
80
|
}
|
|
@@ -126,29 +128,25 @@ let inputToWords = (
|
|
|
126
128
|
var md5 = (data, key, raw) => {
|
|
127
129
|
var i = 16
|
|
128
130
|
, hasKey = key != null
|
|
129
|
-
, [bdata,
|
|
130
|
-
|
|
131
|
-
/** @type {*} */
|
|
132
|
-
var temp = []
|
|
133
|
-
|
|
134
|
-
var out = new Uint8Array(i)
|
|
131
|
+
, [bdata, temp] = inputToWords(data, /**@type {*}*/(hasKey) * i)
|
|
132
|
+
, out = new Uint8Array(i)
|
|
135
133
|
|
|
136
134
|
if (hasKey) {
|
|
137
135
|
// HMAC
|
|
138
|
-
let [bkey,
|
|
139
|
-
|
|
140
|
-
|
|
136
|
+
let [bkey, j] = inputToWords(key, 0)
|
|
137
|
+
, opad = []
|
|
138
|
+
if (j > 64) {
|
|
139
|
+
bkey = wordsMD5(bkey, j)
|
|
141
140
|
}
|
|
142
|
-
for (
|
|
141
|
+
for (j = i; j;) {
|
|
143
142
|
// (0x36363636 ^ 0x5c5c5c5c) == 0x6a6a6a6a
|
|
144
|
-
|
|
143
|
+
opad[--j] = 0x6a6a6a6a ^ (bdata[j] = 0x36363636 ^ bkey[j])
|
|
145
144
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
dataByteLen = 80
|
|
145
|
+
bdata = opad.concat(wordsMD5(bdata, 64 + temp))
|
|
146
|
+
temp = 80
|
|
149
147
|
}
|
|
150
148
|
|
|
151
|
-
bdata = wordsMD5(bdata,
|
|
149
|
+
bdata = wordsMD5(bdata, temp)
|
|
152
150
|
|
|
153
151
|
// words to bytes or hex
|
|
154
152
|
for (; i;) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tinyhmacmd5",
|
|
3
|
-
"version": "0.2.
|
|
4
|
-
"description": "A tiny and reliable HMAC-MD5 implementation for JavaScript: browser.min.js is only
|
|
3
|
+
"version": "0.2.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",
|