@ac-kit/crypto-mac 0.2.6 → 0.3.0
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/CHANGELOG.md +50 -0
- package/README.md +8 -0
- package/dist/hmac-core.d.ts +22 -2
- package/dist/hmac-core.d.ts.map +1 -1
- package/dist/hmac-core.js +84 -26
- package/dist/hmac-core.js.map +1 -1
- package/dist/hmac-input-error.d.ts +18 -0
- package/dist/hmac-input-error.d.ts.map +1 -0
- package/dist/hmac-input-error.js +14 -0
- package/dist/hmac-input-error.js.map +1 -0
- package/dist/hmac-md5.d.ts +1 -1
- package/dist/hmac-md5.d.ts.map +1 -1
- package/dist/hmac-md5.js.map +1 -1
- package/dist/hmac-sha224.d.ts +1 -1
- package/dist/hmac-sha224.d.ts.map +1 -1
- package/dist/hmac-sha224.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,55 @@
|
|
|
1
1
|
# @ac-kit/crypto-mac
|
|
2
2
|
|
|
3
|
+
## 0.3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 5c203e7: `hmac` and `hmacVerify` throw the new `HmacInputError`, with reason
|
|
8
|
+
`invalidBlockSize`, when `blockSizeBytes` is not a positive safe integer or is
|
|
9
|
+
smaller than the hash's digest (FIPS 198-1 §4), instead of a `RangeError` or a
|
|
10
|
+
wrong tag.
|
|
11
|
+
|
|
12
|
+
`hmac` and `hmacVerify` overwrite their key-derived blocks (the padded key
|
|
13
|
+
XORed with `ipad` and `opad`), the hash of a key longer than a block, the inner
|
|
14
|
+
digest and, in `hmacVerify`, the computed tag with zeros before they return or
|
|
15
|
+
throw; the caller's key and message are still only read. `hmacVerify` now
|
|
16
|
+
returns `false` for an empty tag, which it used to accept for any key and
|
|
17
|
+
message.
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- 5c203e7: Encoded bytes, digests and tags are typed `Uint8Array<ArrayBuffer>`, so they
|
|
22
|
+
are `BufferSource`s and go straight to `crypto.subtle` or any other Web API
|
|
23
|
+
without a cast:
|
|
24
|
+
|
|
25
|
+
- `@ac-kit/crypto-hash`: `sha224`, `sha3_224`, `sha3_256`, `sha3_384`,
|
|
26
|
+
`sha3_512`, `shake128`, `shake256` and every sink's `digest`, like the other
|
|
27
|
+
digests already were. Every digest is a fresh array spanning the whole of its
|
|
28
|
+
own plain buffer.
|
|
29
|
+
- `@ac-kit/crypto-mac`: `hmacMd5` and `hmacSha224`, like the other wrappers.
|
|
30
|
+
A tag truncated with `tagLengthBytes` is a view of the full digest's buffer,
|
|
31
|
+
not a copy.
|
|
32
|
+
- `@ac-kit/fixture-util`: `fetchArtifact`.
|
|
33
|
+
- `@ac-kit/format-asn1`: `berEncode`, `cerEncode` and `derEncode`, always a
|
|
34
|
+
fresh array over the whole of a plain buffer. `berEncode` now copies a
|
|
35
|
+
top-level ANY value instead of returning the caller's array, as `cerEncode`
|
|
36
|
+
and `derEncode` already did.
|
|
37
|
+
- `@ac-kit/format-cbor`: `encodeCbor`.
|
|
38
|
+
- `@ac-kit/format-netstring`: `encodeNetstring`.
|
|
39
|
+
- Updated dependencies [5c203e7]
|
|
40
|
+
- Updated dependencies [5c203e7]
|
|
41
|
+
- Updated dependencies [5c203e7]
|
|
42
|
+
- Updated dependencies [5c203e7]
|
|
43
|
+
- Updated dependencies [5c203e7]
|
|
44
|
+
- Updated dependencies [5c203e7]
|
|
45
|
+
- Updated dependencies [5c203e7]
|
|
46
|
+
- Updated dependencies [5c203e7]
|
|
47
|
+
- Updated dependencies [5c203e7]
|
|
48
|
+
- Updated dependencies [5c203e7]
|
|
49
|
+
- @ac-kit/crypto-hash@0.2.0
|
|
50
|
+
- @ac-kit/core@0.14.0
|
|
51
|
+
- @ac-kit/crypto-safe@0.3.0
|
|
52
|
+
|
|
3
53
|
## 0.2.6
|
|
4
54
|
|
|
5
55
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -37,6 +37,8 @@ as a right one — never compare tags with `===`.
|
|
|
37
37
|
comparison against a freshly computed tag.
|
|
38
38
|
- Named wrappers binding one hash each: `hmacMd5`, `hmacSha1`, `hmacSha224`,
|
|
39
39
|
`hmacSha256`, `hmacSha384`, `hmacSha512`.
|
|
40
|
+
- `HmacInputError` — thrown with reason `invalidBlockSize` when
|
|
41
|
+
`blockSizeBytes` is not a positive integer or is smaller than the digest.
|
|
40
42
|
|
|
41
43
|
Wrappers come in two shapes. A bare name (`hmacSha256`) prefers the Web Crypto
|
|
42
44
|
kernel and returns `Uint8Array | Promise<Uint8Array>`; the `Ts` suffix
|
|
@@ -44,6 +46,12 @@ kernel and returns `Uint8Array | Promise<Uint8Array>`; the `Ts` suffix
|
|
|
44
46
|
SHA-224 have no Web Crypto equivalent, so each offers a single synchronous
|
|
45
47
|
function.
|
|
46
48
|
|
|
49
|
+
Every named wrapper's tag is a `Uint8Array<ArrayBuffer>`, a `BufferSource`
|
|
50
|
+
that can be handed straight to a Web API; the generic `hmac` returns the buffer
|
|
51
|
+
type of the `hash` it is given. A full tag spans its own fresh buffer; a tag
|
|
52
|
+
truncated with `tagLengthBytes` is a view of the first bytes of the full
|
|
53
|
+
digest's buffer, so copy it with `slice()` before sharing its `buffer`.
|
|
54
|
+
|
|
47
55
|
Portable: no Node.js built-ins, so it runs unchanged in browsers, Deno, Bun and
|
|
48
56
|
edge runtimes.
|
|
49
57
|
|
package/dist/hmac-core.d.ts
CHANGED
|
@@ -17,7 +17,8 @@ export type HmacInput<THashReturnArrayBuffer extends ArrayBufferLike> = {
|
|
|
17
17
|
readonly hash: (data: Uint8Array) => Uint8Array<THashReturnArrayBuffer>;
|
|
18
18
|
/**
|
|
19
19
|
* `hash`'s compression function's block size — 64 for
|
|
20
|
-
* MD5/SHA-1/SHA-224/SHA-256, 128 for SHA-384/SHA-512.
|
|
20
|
+
* MD5/SHA-1/SHA-224/SHA-256, 128 for SHA-384/SHA-512. A positive safe integer
|
|
21
|
+
* of at least the digest length (FIPS 198-1 §4).
|
|
21
22
|
*/
|
|
22
23
|
readonly blockSizeBytes: number;
|
|
23
24
|
readonly key: Uint8Array;
|
|
@@ -37,6 +38,22 @@ export type HmacVerifyInput = Omit<HmacInput<ArrayBufferLike>, "options"> & {
|
|
|
37
38
|
* block-size-parametrized primitive in `crypto/hash` (`merkleDamgardPad`)
|
|
38
39
|
* rather than a hash-algorithm registry; the caller owns algorithm
|
|
39
40
|
* specificities.
|
|
41
|
+
*
|
|
42
|
+
* The key-derived padded blocks, the hash of a key longer than a block and the
|
|
43
|
+
* inner digest are overwritten with zeros before it returns or throws; `key`
|
|
44
|
+
* and `message` are only read. The hash function's own internal copies are
|
|
45
|
+
* outside its reach.
|
|
46
|
+
*
|
|
47
|
+
* The tag is whatever `hash` returned for the outer input, so it carries the
|
|
48
|
+
* hash's buffer type: every `@ac-kit/crypto-hash` kernel allocates a fresh
|
|
49
|
+
* plain `ArrayBuffer`, which makes the tag a `BufferSource`. With
|
|
50
|
+
* `tagLengthBytes`, it is a `subarray` view of that full-length digest (offset
|
|
51
|
+
* 0, its `buffer` longer than the tag), not a copy; the hidden bytes past the
|
|
52
|
+
* tag stay in the buffer. Copy it with `slice()` before handing out the
|
|
53
|
+
* `buffer` itself.
|
|
54
|
+
*
|
|
55
|
+
* @throws {HmacInputError} With `invalidBlockSize` if `blockSizeBytes` is not a
|
|
56
|
+
* positive safe integer or is smaller than the hash's digest.
|
|
40
57
|
*/
|
|
41
58
|
export declare function hmac<THashReturnArrayBuffer extends ArrayBufferLike>(input: HmacInput<THashReturnArrayBuffer>): Uint8Array<THashReturnArrayBuffer>;
|
|
42
59
|
/**
|
|
@@ -46,7 +63,10 @@ export declare function hmac<THashReturnArrayBuffer extends ArrayBufferLike>(inp
|
|
|
46
63
|
* its own callers always know the expected length in advance — a length
|
|
47
64
|
* mismatch here is ordinary invalid input (the tag is attacker-controlled at
|
|
48
65
|
* this boundary, e.g. a modified or truncated tag from a Wycheproof `"invalid"`
|
|
49
|
-
* test vector) and simply fails verification rather than throwing.
|
|
66
|
+
* test vector) and simply fails verification rather than throwing. An empty tag
|
|
67
|
+
* never verifies. The computed tag is overwritten with zeros once compared.
|
|
68
|
+
*
|
|
69
|
+
* @throws {HmacInputError} As {@link hmac}.
|
|
50
70
|
*/
|
|
51
71
|
export declare function hmacVerify(input: HmacVerifyInput): boolean;
|
|
52
72
|
//# sourceMappingURL=hmac-core.d.ts.map
|
package/dist/hmac-core.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hmac-core.d.ts","sourceRoot":"","sources":["../src/hmac-core.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"hmac-core.d.ts","sourceRoot":"","sources":["../src/hmac-core.ts"],"names":[],"mappings":"AAIA,0CAA0C;AAC1C,MAAM,MAAM,WAAW,GAAG;IACzB;;;OAGG;IACH,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;CACjC,CAAC;AAEF,6BAA6B;AAC7B,MAAM,MAAM,SAAS,CAAC,sBAAsB,SAAS,eAAe,IAAI;IACvE;;;;;OAKG;IACH,QAAQ,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,UAAU,CAAC,sBAAsB,CAAC,CAAC;IAExE;;;;OAIG;IACH,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;IAEhC,QAAQ,CAAC,GAAG,EAAE,UAAU,CAAC;IACzB,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC;IAC7B,QAAQ,CAAC,OAAO,CAAC,EAAE,WAAW,CAAC;CAC/B,CAAC;AAEF,mCAAmC;AACnC,MAAM,MAAM,eAAe,GAAG,IAAI,CAAC,SAAS,CAAC,eAAe,CAAC,EAAE,SAAS,CAAC,GAAG;IAC3E,0DAA0D;IAC1D,QAAQ,CAAC,GAAG,EAAE,UAAU,CAAC;CACzB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,IAAI,CAAC,sBAAsB,SAAS,eAAe,EAClE,KAAK,EAAE,SAAS,CAAC,sBAAsB,CAAC,GACtC,UAAU,CAAC,sBAAsB,CAAC,CAKpC;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,GAAG,OAAO,CAa1D"}
|
package/dist/hmac-core.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { concatBytes } from "@ac-kit/core";
|
|
2
1
|
import { constantTimeBytesIsEqual } from "@ac-kit/crypto-safe";
|
|
2
|
+
import { HmacInputError } from "./hmac-input-error.js";
|
|
3
3
|
/**
|
|
4
4
|
* HMAC (RFC 2104 / FIPS 198-1): a keyed-hash message authentication code built
|
|
5
5
|
* from any hash function and its compression function's block size — both
|
|
@@ -8,20 +8,26 @@ import { constantTimeBytesIsEqual } from "@ac-kit/crypto-safe";
|
|
|
8
8
|
* block-size-parametrized primitive in `crypto/hash` (`merkleDamgardPad`)
|
|
9
9
|
* rather than a hash-algorithm registry; the caller owns algorithm
|
|
10
10
|
* specificities.
|
|
11
|
+
*
|
|
12
|
+
* The key-derived padded blocks, the hash of a key longer than a block and the
|
|
13
|
+
* inner digest are overwritten with zeros before it returns or throws; `key`
|
|
14
|
+
* and `message` are only read. The hash function's own internal copies are
|
|
15
|
+
* outside its reach.
|
|
16
|
+
*
|
|
17
|
+
* The tag is whatever `hash` returned for the outer input, so it carries the
|
|
18
|
+
* hash's buffer type: every `@ac-kit/crypto-hash` kernel allocates a fresh
|
|
19
|
+
* plain `ArrayBuffer`, which makes the tag a `BufferSource`. With
|
|
20
|
+
* `tagLengthBytes`, it is a `subarray` view of that full-length digest (offset
|
|
21
|
+
* 0, its `buffer` longer than the tag), not a copy; the hidden bytes past the
|
|
22
|
+
* tag stay in the buffer. Copy it with `slice()` before handing out the
|
|
23
|
+
* `buffer` itself.
|
|
24
|
+
*
|
|
25
|
+
* @throws {HmacInputError} With `invalidBlockSize` if `blockSizeBytes` is not a
|
|
26
|
+
* positive safe integer or is smaller than the hash's digest.
|
|
11
27
|
*/
|
|
12
28
|
export function hmac(input) {
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const blockSizedKey = deriveBlockSizedKey_(hash, blockSizeBytes, key);
|
|
16
|
-
const ipad = new Uint8Array(blockSizeBytes);
|
|
17
|
-
const opad = new Uint8Array(blockSizeBytes);
|
|
18
|
-
for (let index = 0; index < blockSizeBytes; index++) {
|
|
19
|
-
const keyByte = blockSizedKey[index];
|
|
20
|
-
ipad[index] = keyByte ^ 0x36;
|
|
21
|
-
opad[index] = keyByte ^ 0x5c;
|
|
22
|
-
}
|
|
23
|
-
const innerDigest = hash(concatBytes(ipad, message));
|
|
24
|
-
const tag = hash(concatBytes(opad, innerDigest));
|
|
29
|
+
const tagLengthBytes = input.options?.tagLengthBytes;
|
|
30
|
+
const tag = fullTag_(input);
|
|
25
31
|
return tagLengthBytes === undefined ? tag : tag.subarray(0, tagLengthBytes);
|
|
26
32
|
}
|
|
27
33
|
/**
|
|
@@ -31,25 +37,77 @@ export function hmac(input) {
|
|
|
31
37
|
* its own callers always know the expected length in advance — a length
|
|
32
38
|
* mismatch here is ordinary invalid input (the tag is attacker-controlled at
|
|
33
39
|
* this boundary, e.g. a modified or truncated tag from a Wycheproof `"invalid"`
|
|
34
|
-
* test vector) and simply fails verification rather than throwing.
|
|
40
|
+
* test vector) and simply fails verification rather than throwing. An empty tag
|
|
41
|
+
* never verifies. The computed tag is overwritten with zeros once compared.
|
|
42
|
+
*
|
|
43
|
+
* @throws {HmacInputError} As {@link hmac}.
|
|
35
44
|
*/
|
|
36
45
|
export function hmacVerify(input) {
|
|
37
46
|
const { tag, ...rest } = input;
|
|
38
|
-
const expected =
|
|
39
|
-
|
|
47
|
+
const expected = fullTag_(rest);
|
|
48
|
+
try {
|
|
49
|
+
return (tag.length > 0 &&
|
|
50
|
+
expected.length >= tag.length &&
|
|
51
|
+
constantTimeBytesIsEqual(expected.subarray(0, tag.length), tag));
|
|
52
|
+
}
|
|
53
|
+
finally {
|
|
54
|
+
expected.fill(0);
|
|
55
|
+
}
|
|
40
56
|
}
|
|
41
57
|
/**
|
|
42
|
-
* FIPS 198-1 §4:
|
|
43
|
-
*
|
|
44
|
-
*
|
|
58
|
+
* The untruncated tag. The key-derived blocks (FIPS 198-1 §4: a key longer than
|
|
59
|
+
* the block size is hashed first, a shorter one zero-padded on the right), the
|
|
60
|
+
* hashed key and the inner digest are overwritten with zeros before this
|
|
61
|
+
* returns or throws; the caller's key and message are only read.
|
|
45
62
|
*/
|
|
46
|
-
function
|
|
47
|
-
const
|
|
48
|
-
if (
|
|
49
|
-
|
|
63
|
+
function fullTag_(input) {
|
|
64
|
+
const { hash, blockSizeBytes, key, message } = input;
|
|
65
|
+
if (!Number.isSafeInteger(blockSizeBytes) || blockSizeBytes < 1) {
|
|
66
|
+
throw new HmacInputError("invalidBlockSize", "HMAC block size must be a positive safe integer");
|
|
67
|
+
}
|
|
68
|
+
// K0 ⊕ ipad ‖ message, then K0 ⊕ opad ‖ inner digest.
|
|
69
|
+
const innerInput = new Uint8Array(blockSizeBytes + message.length);
|
|
70
|
+
const outerPad = new Uint8Array(blockSizeBytes);
|
|
71
|
+
let outerInput;
|
|
72
|
+
let innerDigest;
|
|
73
|
+
try {
|
|
74
|
+
if (key.length > blockSizeBytes) {
|
|
75
|
+
const hashedKey = hash(key);
|
|
76
|
+
try {
|
|
77
|
+
checkBlockSize_(blockSizeBytes, hashedKey.length);
|
|
78
|
+
innerInput.set(hashedKey);
|
|
79
|
+
}
|
|
80
|
+
finally {
|
|
81
|
+
hashedKey.fill(0);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
innerInput.set(key);
|
|
86
|
+
}
|
|
87
|
+
for (let index = 0; index < blockSizeBytes; index++) {
|
|
88
|
+
const keyByte = innerInput[index];
|
|
89
|
+
innerInput[index] = keyByte ^ 0x36;
|
|
90
|
+
outerPad[index] = keyByte ^ 0x5c;
|
|
91
|
+
}
|
|
92
|
+
innerInput.set(message, blockSizeBytes);
|
|
93
|
+
innerDigest = hash(innerInput);
|
|
94
|
+
checkBlockSize_(blockSizeBytes, innerDigest.length);
|
|
95
|
+
outerInput = new Uint8Array(blockSizeBytes + innerDigest.length);
|
|
96
|
+
outerInput.set(outerPad);
|
|
97
|
+
outerInput.set(innerDigest, blockSizeBytes);
|
|
98
|
+
return hash(outerInput);
|
|
99
|
+
}
|
|
100
|
+
finally {
|
|
101
|
+
innerInput.fill(0);
|
|
102
|
+
outerPad.fill(0);
|
|
103
|
+
outerInput?.fill(0);
|
|
104
|
+
innerDigest?.fill(0);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
// FIPS 198-1 §4 requires a block at least one digest long.
|
|
108
|
+
function checkBlockSize_(blockSizeBytes, digestLengthBytes) {
|
|
109
|
+
if (blockSizeBytes < digestLengthBytes) {
|
|
110
|
+
throw new HmacInputError("invalidBlockSize", "HMAC block size must not be smaller than the hash's digest");
|
|
50
111
|
}
|
|
51
|
-
const blockSizedKey = new Uint8Array(blockSizeBytes);
|
|
52
|
-
blockSizedKey.set(baseKey);
|
|
53
|
-
return blockSizedKey;
|
|
54
112
|
}
|
|
55
113
|
//# sourceMappingURL=hmac-core.js.map
|
package/dist/hmac-core.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hmac-core.js","sourceRoot":"","sources":["../src/hmac-core.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"hmac-core.js","sourceRoot":"","sources":["../src/hmac-core.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAE/D,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAuCvD;;;;;;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V,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACnB,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACjB,UAAU,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;QACpB,WAAW,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;IACtB,CAAC;AACF,CAAC;AAED,2DAA2D;AAC3D,SAAS,eAAe,CACvB,cAAsB,EACtB,iBAAyB;IAEzB,IAAI,cAAc,GAAG,iBAAiB,EAAE,CAAC;QACxC,MAAM,IAAI,cAAc,CACvB,kBAAkB,EAClB,4DAA4D,CAC5D,CAAC;IACH,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** Why {@link hmac} or {@link hmacVerify} refused its input. */
|
|
2
|
+
export type HmacInputErrorReason =
|
|
3
|
+
/**
|
|
4
|
+
* The block size is not a positive safe integer, or is smaller than the
|
|
5
|
+
* hash's digest (FIPS 198-1 §4 requires `B >= L`).
|
|
6
|
+
*/
|
|
7
|
+
"invalidBlockSize";
|
|
8
|
+
/**
|
|
9
|
+
* An input outside HMAC's domain. The message names the rule broken, never a
|
|
10
|
+
* key or message byte.
|
|
11
|
+
*/
|
|
12
|
+
export declare class HmacInputError extends Error {
|
|
13
|
+
readonly name = "HmacInputError";
|
|
14
|
+
/** Stable, machine-readable cause. */
|
|
15
|
+
readonly reason: HmacInputErrorReason;
|
|
16
|
+
constructor(reason: HmacInputErrorReason, message: string);
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=hmac-input-error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hmac-input-error.d.ts","sourceRoot":"","sources":["../src/hmac-input-error.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAChE,MAAM,MAAM,oBAAoB;AAC/B;;;GAGG;AACH,kBAAkB,CAAC;AAEpB;;;GAGG;AACH,qBAAa,cAAe,SAAQ,KAAK;IACxC,SAAkB,IAAI,oBAAoB;IAC1C,sCAAsC;IACtC,QAAQ,CAAC,MAAM,EAAE,oBAAoB,CAAC;IAEtC,YAAY,MAAM,EAAE,oBAAoB,EAAE,OAAO,EAAE,MAAM,EAGxD;CACD"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An input outside HMAC's domain. The message names the rule broken, never a
|
|
3
|
+
* key or message byte.
|
|
4
|
+
*/
|
|
5
|
+
export class HmacInputError extends Error {
|
|
6
|
+
name = "HmacInputError";
|
|
7
|
+
/** Stable, machine-readable cause. */
|
|
8
|
+
reason;
|
|
9
|
+
constructor(reason, message) {
|
|
10
|
+
super(message);
|
|
11
|
+
this.reason = reason;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=hmac-input-error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hmac-input-error.js","sourceRoot":"","sources":["../src/hmac-input-error.ts"],"names":[],"mappings":"AAQA;;;GAGG;AACH,MAAM,OAAO,cAAe,SAAQ,KAAK;IACtB,IAAI,GAAG,gBAAgB,CAAC;IAC1C,sCAAsC;IAC7B,MAAM,CAAuB;IAEtC,YAAY,MAA4B,EAAE,OAAe;QACxD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACtB,CAAC;CACD"}
|
package/dist/hmac-md5.d.ts
CHANGED
|
@@ -3,5 +3,5 @@
|
|
|
3
3
|
* default; see `@ac-kit/crypto-hash`'s `md5` for the same caveat one level
|
|
4
4
|
* down. No Web Crypto kernel, matching `md5` itself.
|
|
5
5
|
*/
|
|
6
|
-
export declare function hmacMd5(key: Uint8Array, message: Uint8Array): Uint8Array
|
|
6
|
+
export declare function hmacMd5(key: Uint8Array, message: Uint8Array): Uint8Array<ArrayBuffer>;
|
|
7
7
|
//# sourceMappingURL=hmac-md5.d.ts.map
|
package/dist/hmac-md5.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hmac-md5.d.ts","sourceRoot":"","sources":["../src/hmac-md5.ts"],"names":[],"mappings":"AAMA;;;;GAIG;AACH,wBAAgB,OAAO,
|
|
1
|
+
{"version":3,"file":"hmac-md5.d.ts","sourceRoot":"","sources":["../src/hmac-md5.ts"],"names":[],"mappings":"AAMA;;;;GAIG;AACH,wBAAgB,OAAO,CACtB,GAAG,EAAE,UAAU,EACf,OAAO,EAAE,UAAU,GACjB,UAAU,CAAC,WAAW,CAAC,CAEzB"}
|
package/dist/hmac-md5.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hmac-md5.js","sourceRoot":"","sources":["../src/hmac-md5.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,qBAAqB,CAAC;AAE1C,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAEtC,MAAM,gBAAgB,GAAG,EAAE,CAAC;AAE5B;;;;GAIG;AACH,MAAM,UAAU,OAAO,
|
|
1
|
+
{"version":3,"file":"hmac-md5.js","sourceRoot":"","sources":["../src/hmac-md5.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,qBAAqB,CAAC;AAE1C,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAEtC,MAAM,gBAAgB,GAAG,EAAE,CAAC;AAE5B;;;;GAIG;AACH,MAAM,UAAU,OAAO,CACtB,GAAe,EACf,OAAmB;IAEnB,OAAO,IAAI,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,cAAc,EAAE,gBAAgB,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC,CAAC;AAC5E,CAAC"}
|
package/dist/hmac-sha224.d.ts
CHANGED
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
* HMAC-SHA-224 (RFC 2104). No Web Crypto kernel, matching `sha224` itself — no
|
|
3
3
|
* engine recognises the algorithm name.
|
|
4
4
|
*/
|
|
5
|
-
export declare function hmacSha224(key: Uint8Array, message: Uint8Array): Uint8Array
|
|
5
|
+
export declare function hmacSha224(key: Uint8Array, message: Uint8Array): Uint8Array<ArrayBuffer>;
|
|
6
6
|
//# sourceMappingURL=hmac-sha224.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hmac-sha224.d.ts","sourceRoot":"","sources":["../src/hmac-sha224.ts"],"names":[],"mappings":"AAMA;;;GAGG;AACH,wBAAgB,UAAU,
|
|
1
|
+
{"version":3,"file":"hmac-sha224.d.ts","sourceRoot":"","sources":["../src/hmac-sha224.ts"],"names":[],"mappings":"AAMA;;;GAGG;AACH,wBAAgB,UAAU,CACzB,GAAG,EAAE,UAAU,EACf,OAAO,EAAE,UAAU,GACjB,UAAU,CAAC,WAAW,CAAC,CAEzB"}
|
package/dist/hmac-sha224.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hmac-sha224.js","sourceRoot":"","sources":["../src/hmac-sha224.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAE7C,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAEtC,MAAM,gBAAgB,GAAG,EAAE,CAAC;AAE5B;;;GAGG;AACH,MAAM,UAAU,UAAU,
|
|
1
|
+
{"version":3,"file":"hmac-sha224.js","sourceRoot":"","sources":["../src/hmac-sha224.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAE7C,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAEtC,MAAM,gBAAgB,GAAG,EAAE,CAAC;AAE5B;;;GAGG;AACH,MAAM,UAAU,UAAU,CACzB,GAAe,EACf,OAAmB;IAEnB,OAAO,IAAI,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,cAAc,EAAE,gBAAgB,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC,CAAC;AAC/E,CAAC"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC"}
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,cAAc,gBAAgB,CAAC;AAC/B,cAAc,uBAAuB,CAAC;AACtC,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ac-kit/crypto-mac",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Message authentication codes: generic hmac() and hmacVerify() plus named MD5, SHA-1 and SHA-2 HMAC wrappers.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"authentication",
|
|
@@ -44,16 +44,16 @@
|
|
|
44
44
|
"prepack": "yarn build"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@ac-kit/core": "^0.
|
|
48
|
-
"@ac-kit/crypto-hash": "^0.
|
|
49
|
-
"@ac-kit/crypto-safe": "^0.
|
|
47
|
+
"@ac-kit/core": "^0.14.0",
|
|
48
|
+
"@ac-kit/crypto-hash": "^0.2.0",
|
|
49
|
+
"@ac-kit/crypto-safe": "^0.3.0",
|
|
50
50
|
"@types/web": "^0.0.367"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@ac-kit/fixture-crypto": "0.1.0",
|
|
54
54
|
"@ac-kit/tsconfig": "0.1.0",
|
|
55
55
|
"@ac-kit/typedoc-config": "0.1.0",
|
|
56
|
-
"@ac-kit/vitest-config": "0.
|
|
56
|
+
"@ac-kit/vitest-config": "0.3.0",
|
|
57
57
|
"@types/node": "26.6.11",
|
|
58
58
|
"@typescript/native": "typescript@7.0.2",
|
|
59
59
|
"rimraf": "6.1.4",
|