tinyhmacmd5 0.1.0 → 0.1.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.
Files changed (4) hide show
  1. package/README.md +9 -1
  2. package/main.d.ts +12 -4
  3. package/main.js +10 -10
  4. package/package.json +2 -2
package/README.md CHANGED
@@ -1,11 +1,15 @@
1
1
  # Tiny HMAC MD5
2
2
 
3
- A tiny, reliable JavaScript HMAC-MD5 implementation.
3
+ A tiny JavaScript HMAC-MD5 implementation.
4
4
 
5
5
  The minified browser bundle ([`browser.min.js`](browser.min.js)) is only 1057 bytes.
6
6
 
7
7
  Preview: https://bddjr.github.io/tinyhmacmd5/
8
8
 
9
+ > [!WARNING]
10
+ > MD5 is cryptographically broken and unsafe for security-sensitive applications.
11
+ > Do not rely on it for password hashing, digital signatures, or certificate verification.
12
+
9
13
  ## Setup
10
14
 
11
15
  ### npm
@@ -30,6 +34,10 @@ See https://www.jsdelivr.com/package/npm/tinyhmacmd5
30
34
 
31
35
  ## Example
32
36
 
37
+ > [!WARNING]
38
+ > Please make sure on your own that the types of input parameters conform to the definitions in [`main.d.ts`](main.d.ts).
39
+ > If you pass wrong types, it may not throw an error and may produce incorrect results.
40
+
33
41
  HMAC-MD5:
34
42
 
35
43
  ```js
package/main.d.ts CHANGED
@@ -4,13 +4,21 @@
4
4
  * By default, returns the hash as a lowercase hexadecimal string.
5
5
  * If `raw` is true, returns a Uint8Array.
6
6
  *
7
- * @param {string | Uint8Array} data The input data to hash. Strings are UTF‑8 encoded.
8
- * @param {string | Uint8Array | null} [key] Optional HMAC key. When given, HMAC‑MD5 is calculated instead of plain MD5.
7
+ * @param {string | Uint8Array | Uint8ClampedArray} data The input data to hash. Strings are UTF‑8 encoded.
8
+ * @param {string | Uint8Array | Uint8ClampedArray | null} [key] Optional HMAC key. When given, HMAC‑MD5 is calculated instead of plain MD5.
9
9
  * @param {boolean} [raw] If true, the hash is returned as raw bytes (Uint8Array); otherwise, as a hex string.
10
10
  * @returns {string | Uint8Array<ArrayBuffer>} The MD5 (or HMAC‑MD5) digest, either as a hex string or a Uint8Array.
11
11
  */
12
12
  declare var md5: {
13
- (data: string | Uint8Array, key?: string | Uint8Array | null, raw?: false): string;
14
- (data: string | Uint8Array, key: string | Uint8Array | null | undefined, raw: true): Uint8Array<ArrayBuffer>;
13
+ (
14
+ data: string | Uint8Array | Uint8ClampedArray,
15
+ key?: string | Uint8Array | Uint8ClampedArray | null,
16
+ raw?: false
17
+ ): string;
18
+ (
19
+ data: string | Uint8Array | Uint8ClampedArray,
20
+ key: string | Uint8Array | Uint8ClampedArray | null | undefined,
21
+ raw: true
22
+ ): Uint8Array<ArrayBuffer>;
15
23
  };
16
24
  export default md5;
package/main.js CHANGED
@@ -125,15 +125,15 @@ let inputToBinl = (
125
125
 
126
126
  /**
127
127
  * @overload
128
- * @param {string | Uint8Array} data
129
- * @param {string | Uint8Array | null} [key]
128
+ * @param {string | Uint8Array | Uint8ClampedArray} data
129
+ * @param {string | Uint8Array | Uint8ClampedArray | null} [key]
130
130
  * @param {false} [raw]
131
131
  * @returns {string}
132
132
  */
133
133
  /**
134
134
  * @overload
135
- * @param {string | Uint8Array} data
136
- * @param {string | Uint8Array | null | undefined} key
135
+ * @param {string | Uint8Array | Uint8ClampedArray} data
136
+ * @param {string | Uint8Array | Uint8ClampedArray | null | undefined} key
137
137
  * @param {true} raw
138
138
  * @returns {Uint8Array<ArrayBuffer>}
139
139
  */
@@ -143,8 +143,8 @@ let inputToBinl = (
143
143
  * By default, returns the hash as a lowercase hexadecimal string.
144
144
  * If `raw` is true, returns a Uint8Array.
145
145
  *
146
- * @param {string | Uint8Array} data The input data to hash. Strings are UTF‑8 encoded.
147
- * @param {string | Uint8Array | null} [key] Optional HMAC key. When given, HMAC‑MD5 is calculated instead of plain MD5.
146
+ * @param {string | Uint8Array | Uint8ClampedArray} data The input data to hash. Strings are UTF‑8 encoded.
147
+ * @param {string | Uint8Array | Uint8ClampedArray | null} [key] Optional HMAC key. When given, HMAC‑MD5 is calculated instead of plain MD5.
148
148
  * @param {boolean} [raw] If true, the hash is returned as raw bytes (Uint8Array); otherwise, as a hex string.
149
149
  * @returns {string | Uint8Array<ArrayBuffer>} The MD5 (or HMAC‑MD5) digest, either as a hex string or a Uint8Array.
150
150
  */
@@ -157,17 +157,17 @@ var md5 = (data, key, raw) => {
157
157
  if (hasKey) {
158
158
  // HMAC
159
159
  let [bkey, keyByteLen] = inputToBinl(key, 0)
160
- let pad5cArr = []
160
+ let opad = []
161
161
  if (keyByteLen > 64) {
162
162
  bkey = binlMD5(bkey, keyByteLen)
163
163
  }
164
164
  for (; i;) {
165
- bdata[--i] = 0x36363636 ^ bkey[i]
166
- pad5cArr[i] = 0x5c5c5c5c ^ bkey[i]
165
+ bdata[--i] = 0x36363636 ^ bkey[i] // ipad
166
+ opad[i] = 0x5c5c5c5c ^ bkey[i]
167
167
  }
168
168
  i = 16
169
169
  bdata = binlMD5(bdata, 64 + dataByteLen)
170
- bdata.unshift(...pad5cArr)
170
+ bdata.unshift(...opad)
171
171
  dataByteLen = 80
172
172
  }
173
173
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "tinyhmacmd5",
3
- "version": "0.1.0",
4
- "description": "A tiny, reliable JavaScript HMAC-MD5 implementation. The minified browser bundle is only 1057 bytes.",
3
+ "version": "0.1.1",
4
+ "description": "A tiny JavaScript HMAC-MD5 implementation. The minified browser bundle is only 1057 bytes.",
5
5
  "author": "bddjr",
6
6
  "license": "MIT",
7
7
  "type": "module",