@signature-kit/crypto 0.1.0 → 0.2.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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.0
4
+
5
+ - Fix SHA-512/SHA-384 message-length encoding for inputs ≥ 512 MiB (also corrects
6
+ HMAC-SHA384/512 and PKCS#12 MAC verification over such inputs).
7
+ - Zero-pad HMAC keys longer than the block size instead of relying on out-of-bounds reads.
8
+
3
9
  ## 0.1.0
4
10
 
5
11
  - Initial npm-ready release for `@signature-kit/crypto`.
package/dist/base64.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { Effect } from "effect";
2
+ import { CryptoError } from "./config";
1
3
  export declare const bytesToBase64: (bytes: Uint8Array) => string;
2
- export declare const base64ToBytes: (base64: string) => Uint8Array<ArrayBuffer>;
4
+ export declare const base64ToBytes: (base64: string) => Effect.Effect<Uint8Array<ArrayBuffer>, CryptoError>;
3
5
  //# sourceMappingURL=base64.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"base64.d.ts","sourceRoot":"","sources":["../src/base64.ts"],"names":[],"mappings":"AAYA,eAAO,MAAM,aAAa,GAAI,OAAO,UAAU,KAAG,MAajD,CAAC;AAEF,eAAO,MAAM,aAAa,GAAI,QAAQ,MAAM,KAAG,UAAU,CAAC,WAAW,CA4BpE,CAAC"}
1
+ {"version":3,"file":"base64.d.ts","sourceRoot":"","sources":["../src/base64.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,WAAW,EAA8C,MAAM,UAAU,CAAC;AAcnF,eAAO,MAAM,aAAa,GAAI,OAAO,UAAU,KAAG,MAajD,CAAC;AAEF,eAAO,MAAM,aAAa,GACxB,QAAQ,MAAM,KACb,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE,WAAW,CA2DjD,CAAC"}
package/dist/base64.js CHANGED
@@ -1,3 +1,5 @@
1
+ import { Effect } from "effect";
2
+ import { CryptoError, CryptoErrorCodeValue, CryptoOperationValue } from "./config";
1
3
  const BASE64_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
2
4
  const base64Value = (char) => {
3
5
  const code = char.charCodeAt(0);
@@ -27,16 +29,39 @@ export const bytesToBase64 = (bytes) => {
27
29
  }
28
30
  return output;
29
31
  };
30
- export const base64ToBytes = (base64) => {
32
+ export const base64ToBytes = (base64) => Effect.gen(function* () {
31
33
  const clean = base64.replace(/[\t\n\r ]/g, "");
32
- const padding = clean.endsWith("==") ? 2 : clean.endsWith("=") ? 1 : 0;
33
- const output = new Uint8Array(Math.floor((clean.length * 3) / 4) - padding);
34
+ if (!/^[A-Za-z0-9+/]*={0,2}$/.test(clean)) {
35
+ return yield* Effect.fail(new CryptoError({
36
+ code: CryptoErrorCodeValue.invalidFormat,
37
+ reason: "Base64 input contains invalid characters.",
38
+ operation: CryptoOperationValue.base64Decode,
39
+ }));
40
+ }
41
+ if (clean.length % 4 === 1) {
42
+ return yield* Effect.fail(new CryptoError({
43
+ code: CryptoErrorCodeValue.invalidFormat,
44
+ reason: "Base64 input has an invalid length.",
45
+ operation: CryptoOperationValue.base64Decode,
46
+ }));
47
+ }
48
+ const firstPadding = clean.indexOf("=");
49
+ if (firstPadding >= 0 && firstPadding < clean.length - (clean.endsWith("==") ? 2 : 1)) {
50
+ return yield* Effect.fail(new CryptoError({
51
+ code: CryptoErrorCodeValue.invalidFormat,
52
+ reason: "Base64 padding must be at the end.",
53
+ operation: CryptoOperationValue.base64Decode,
54
+ }));
55
+ }
56
+ const normalized = clean.padEnd(Math.ceil(clean.length / 4) * 4, "=");
57
+ const padding = normalized.endsWith("==") ? 2 : normalized.endsWith("=") ? 1 : 0;
58
+ const output = new Uint8Array(Math.floor((normalized.length * 3) / 4) - padding);
34
59
  let outputOffset = 0;
35
- for (let offset = 0; offset < clean.length; offset += 4) {
36
- const first = base64Value(clean[offset] ?? "");
37
- const second = base64Value(clean[offset + 1] ?? "");
38
- const third = base64Value(clean[offset + 2] ?? "");
39
- const fourth = base64Value(clean[offset + 3] ?? "");
60
+ for (let offset = 0; offset < normalized.length; offset += 4) {
61
+ const first = base64Value(normalized[offset] ?? "");
62
+ const second = base64Value(normalized[offset + 1] ?? "");
63
+ const third = base64Value(normalized[offset + 2] ?? "");
64
+ const fourth = base64Value(normalized[offset + 3] ?? "");
40
65
  const chunk = (first << 18) | (second << 12) | (third << 6) | fourth;
41
66
  if (outputOffset < output.length) {
42
67
  output[outputOffset] = (chunk >> 16) & 0xff;
@@ -52,4 +77,4 @@ export const base64ToBytes = (base64) => {
52
77
  }
53
78
  }
54
79
  return output;
55
- };
80
+ });
package/dist/config.d.ts CHANGED
@@ -18,9 +18,11 @@ export declare const CryptoErrorCodeValue: {
18
18
  cipherError: "crypto.CIPHER_ERROR";
19
19
  unknown: "crypto.UNKNOWN";
20
20
  };
21
- export declare const CryptoOperationSchema: Schema.Literals<readonly ["pkcs12.decode", "pkcs12.mac", "pkcs12.decrypt", "cipher.aes", "cipher.des", "cipher.rc2"]>;
21
+ export declare const CryptoOperationSchema: Schema.Literals<readonly ["base64.decode", "pem.decode", "pkcs12.decode", "pkcs12.mac", "pkcs12.decrypt", "cipher.aes", "cipher.des", "cipher.rc2"]>;
22
22
  export type CryptoOperation = (typeof CryptoOperationSchema)["Type"];
23
23
  export declare const CryptoOperationValue: {
24
+ base64Decode: "base64.decode";
25
+ pemDecode: "pem.decode";
24
26
  pkcs12Decode: "pkcs12.decode";
25
27
  pkcs12Mac: "pkcs12.mac";
26
28
  pkcs12Decrypt: "pkcs12.decrypt";
@@ -31,7 +33,7 @@ export declare const CryptoOperationValue: {
31
33
  declare const CryptoError_base: Schema.Class<CryptoError, Schema.TaggedStruct<"CryptoError", {
32
34
  readonly code: Schema.Literals<readonly ["crypto.DECODE_ERROR", "crypto.INVALID_FORMAT", "crypto.UNSUPPORTED_ALGORITHM", "crypto.WRONG_PASSWORD", "crypto.NO_CERTIFICATE", "crypto.NO_PRIVATE_KEY", "crypto.CORRUPTED_FILE", "crypto.CIPHER_ERROR", "crypto.UNKNOWN"]>;
33
35
  readonly reason: Schema.optional<Schema.String>;
34
- readonly operation: Schema.optional<Schema.Literals<readonly ["pkcs12.decode", "pkcs12.mac", "pkcs12.decrypt", "cipher.aes", "cipher.des", "cipher.rc2"]>>;
36
+ readonly operation: Schema.optional<Schema.Literals<readonly ["base64.decode", "pem.decode", "pkcs12.decode", "pkcs12.mac", "pkcs12.decrypt", "cipher.aes", "cipher.des", "cipher.rc2"]>>;
35
37
  }>, import("effect/Cause").YieldableError>;
36
38
  export declare class CryptoError extends CryptoError_base {
37
39
  get message(): string;
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,eAAO,MAAM,qBAAqB,yPAUhC,CAAC;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,qBAAqB,CAAC,CAAC,MAAM,CAAC,CAAC;AACrE,eAAO,MAAM,oBAAoB;;;;;;;;;;CAUU,CAAC;AAE5C,eAAO,MAAM,qBAAqB,uHAOhC,CAAC;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,qBAAqB,CAAC,CAAC,MAAM,CAAC,CAAC;AACrE,eAAO,MAAM,oBAAoB;;;;;;;CAOU,CAAC;;;;;;AAE5C,qBAAa,WAAY,SAAQ,gBAI/B;IACA,IAAI,OAAO,IAAI,MAAM,CAqBpB;CACF;AAED,eAAO,MAAM,kBAAkB;;;;EAI7B,CAAC;AACH,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,kBAAkB,CAAC,CAAC,MAAM,CAAC,CAAC"}
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,eAAO,MAAM,qBAAqB,yPAUhC,CAAC;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,qBAAqB,CAAC,CAAC,MAAM,CAAC,CAAC;AACrE,eAAO,MAAM,oBAAoB;;;;;;;;;;CAUU,CAAC;AAE5C,eAAO,MAAM,qBAAqB,sJAShC,CAAC;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,qBAAqB,CAAC,CAAC,MAAM,CAAC,CAAC;AACrE,eAAO,MAAM,oBAAoB;;;;;;;;;CASU,CAAC;;;;;;AAE5C,qBAAa,WAAY,SAAQ,gBAI/B;IACA,IAAI,OAAO,IAAI,MAAM,CAqBpB;CACF;AAED,eAAO,MAAM,kBAAkB;;;;EAI7B,CAAC;AACH,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,kBAAkB,CAAC,CAAC,MAAM,CAAC,CAAC"}
package/dist/config.js CHANGED
@@ -28,6 +28,8 @@ export const CryptoErrorCodeValue = {
28
28
  unknown: "crypto.UNKNOWN",
29
29
  };
30
30
  export const CryptoOperationSchema = Schema.Literals([
31
+ "base64.decode",
32
+ "pem.decode",
31
33
  "pkcs12.decode",
32
34
  "pkcs12.mac",
33
35
  "pkcs12.decrypt",
@@ -36,6 +38,8 @@ export const CryptoOperationSchema = Schema.Literals([
36
38
  "cipher.rc2",
37
39
  ]);
38
40
  export const CryptoOperationValue = {
41
+ base64Decode: "base64.decode",
42
+ pemDecode: "pem.decode",
39
43
  pkcs12Decode: "pkcs12.decode",
40
44
  pkcs12Mac: "pkcs12.mac",
41
45
  pkcs12Decrypt: "pkcs12.decrypt",
package/dist/pem.d.ts CHANGED
@@ -1,3 +1,5 @@
1
- export declare const pemToDer: (pem: string) => Uint8Array;
1
+ import { Effect } from "effect";
2
+ import { CryptoError } from "./config";
3
+ export declare const pemToDer: (pem: string) => Effect.Effect<Uint8Array, CryptoError>;
2
4
  export declare const derToPem: (der: Uint8Array, label: string) => string;
3
5
  //# sourceMappingURL=pem.d.ts.map
package/dist/pem.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"pem.d.ts","sourceRoot":"","sources":["../src/pem.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,QAAQ,GAAI,KAAK,MAAM,KAAG,UAMpC,CAAC;AAEJ,eAAO,MAAM,QAAQ,GAAI,KAAK,UAAU,EAAE,OAAO,MAAM,KAAG,MASzD,CAAC"}
1
+ {"version":3,"file":"pem.d.ts","sourceRoot":"","sources":["../src/pem.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,WAAW,EAA8C,MAAM,UAAU,CAAC;AAGnF,eAAO,MAAM,QAAQ,GAAI,KAAK,MAAM,KAAG,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,WAAW,CAe3E,CAAC;AAEF,eAAO,MAAM,QAAQ,GAAI,KAAK,UAAU,EAAE,OAAO,MAAM,KAAG,MASzD,CAAC"}
package/dist/pem.js CHANGED
@@ -1,8 +1,20 @@
1
+ import { Effect } from "effect";
2
+ import { CryptoError, CryptoErrorCodeValue, CryptoOperationValue } from "./config";
1
3
  import { base64ToBytes, bytesToBase64 } from "./base64";
2
- export const pemToDer = (pem) => base64ToBytes(pem
3
- .split(/\r?\n/)
4
- .filter((line) => !line.startsWith("-----"))
5
- .join(""));
4
+ export const pemToDer = (pem) => {
5
+ const base64 = pem
6
+ .split(/\r?\n/)
7
+ .filter((line) => !line.startsWith("-----"))
8
+ .join("");
9
+ if (base64.length === 0) {
10
+ return Effect.fail(new CryptoError({
11
+ code: CryptoErrorCodeValue.invalidFormat,
12
+ reason: "PEM input does not contain base64 DER content.",
13
+ operation: CryptoOperationValue.pemDecode,
14
+ }));
15
+ }
16
+ return base64ToBytes(base64);
17
+ };
6
18
  export const derToPem = (der, label) => {
7
19
  const base64 = bytesToBase64(der);
8
20
  const lines = [];
@@ -1 +1 @@
1
- {"version":3,"file":"pkcs12.d.ts","sourceRoot":"","sources":["../src/pkcs12.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAYH,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAC1C,OAAO,EACL,WAAW,EAGX,KAAK,YAAY,EAClB,MAAM,UAAU,CAAC;AAohBlB,gFAAgF;AAChF,eAAO,MAAM,WAAW,GACtB,MAAM,UAAU,EAChB,UAAU,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,KAClC,MAAM,CAAC,MAAM,CAAC,YAAY,EAAE,WAAW,CAyHvC,CAAC"}
1
+ {"version":3,"file":"pkcs12.d.ts","sourceRoot":"","sources":["../src/pkcs12.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAYH,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAC1C,OAAO,EACL,WAAW,EAGX,KAAK,YAAY,EAClB,MAAM,UAAU,CAAC;AA0hBlB,gFAAgF;AAChF,eAAO,MAAM,WAAW,GACtB,MAAM,UAAU,EAChB,UAAU,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,KAClC,MAAM,CAAC,MAAM,CAAC,YAAY,EAAE,WAAW,CAyHvC,CAAC"}
package/dist/pkcs12.js CHANGED
@@ -33,6 +33,7 @@ const OID_AES_128_CBC = "2.16.840.1.101.3.4.1.2";
33
33
  const OID_AES_192_CBC = "2.16.840.1.101.3.4.1.22";
34
34
  const OID_AES_256_CBC = "2.16.840.1.101.3.4.1.42";
35
35
  const OID_DES_EDE3_CBC = "1.2.840.113549.3.7";
36
+ const OID_HMAC_SHA1 = "1.2.840.113549.2.7";
36
37
  const OID_HMAC_SHA256 = "1.2.840.113549.2.9";
37
38
  const OID_HMAC_SHA384 = "1.2.840.113549.2.10";
38
39
  const OID_HMAC_SHA512 = "1.2.840.113549.2.11";
@@ -204,13 +205,21 @@ const verifyMac = (macNode, authSafeData, bmpPassword) => Effect.gen(function* (
204
205
  // =============================================================================
205
206
  // PBE decryption
206
207
  // =============================================================================
207
- const pbkdf2HashAlgorithm = (oid) => oid === OID_HMAC_SHA256
208
- ? "sha256"
209
- : oid === OID_HMAC_SHA384
210
- ? "sha384"
211
- : oid === OID_HMAC_SHA512
212
- ? "sha512"
213
- : "sha1";
208
+ const pbkdf2HashAlgorithm = (oid) => {
209
+ if (oid === OID_HMAC_SHA1)
210
+ return Effect.succeed("sha1");
211
+ if (oid === OID_HMAC_SHA256)
212
+ return Effect.succeed("sha256");
213
+ if (oid === OID_HMAC_SHA384)
214
+ return Effect.succeed("sha384");
215
+ if (oid === OID_HMAC_SHA512)
216
+ return Effect.succeed("sha512");
217
+ return Effect.fail(new CryptoError({
218
+ code: CryptoErrorCodeValue.unsupportedAlgorithm,
219
+ reason: `Unsupported PBKDF2 PRF: ${oid}`,
220
+ operation: CryptoOperationValue.pkcs12Decode,
221
+ }));
222
+ };
214
223
  const decryptPbes2 = (encryptedData, params, passwordBytes) => Effect.gen(function* () {
215
224
  const pbes2Params = yield* childrenOf(params);
216
225
  const kdfInfo = yield* childrenOf(yield* elementAt(pbes2Params, 0, "KeyDerivationFunc"));
@@ -231,7 +240,7 @@ const decryptPbes2 = (encryptedData, params, passwordBytes) => Effect.gen(functi
231
240
  const param = pbkdf2Params[i];
232
241
  if (param !== undefined && param.kind === "constructed" && param.tag === 0x10) {
233
242
  const prfOid = yield* oidString(yield* elementAt(param.children, 0, "PRF OID"));
234
- prf = pbkdf2HashAlgorithm(prfOid);
243
+ prf = yield* pbkdf2HashAlgorithm(prfOid);
235
244
  }
236
245
  }
237
246
  const encOid = yield* oidString(yield* elementAt(encScheme, 0, "encryption OID"));
@@ -1 +1 @@
1
- {"version":3,"file":"hmac.d.ts","sourceRoot":"","sources":["../../src/primitives/hmac.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAKhC,eAAO,MAAM,uBAAuB,kEAA0D,CAAC;AAC/F,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,uBAAuB,CAAC,CAAC,MAAM,CAAC,CAAC;AAyBzE;;;;;;;GAOG;AACH,wBAAgB,IAAI,CAAC,GAAG,EAAE,iBAAiB,EAAE,GAAG,EAAE,UAAU,EAAE,IAAI,EAAE,UAAU,GAAG,UAAU,CAgC1F;AAED;;;;;;;;GAQG;AAEH,MAAM,MAAM,WAAW,GAAG;IACxB,8CAA8C;IAC9C,QAAQ,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,UAAU,CAAC;CACpD,CAAC;AA0CF;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,iBAAiB,EAAE,GAAG,EAAE,UAAU,GAAG,WAAW,CAkC/E"}
1
+ {"version":3,"file":"hmac.d.ts","sourceRoot":"","sources":["../../src/primitives/hmac.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAKhC,eAAO,MAAM,uBAAuB,kEAA0D,CAAC;AAC/F,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,uBAAuB,CAAC,CAAC,MAAM,CAAC,CAAC;AAsCzE;;;;;;;GAOG;AACH,wBAAgB,IAAI,CAAC,GAAG,EAAE,iBAAiB,EAAE,GAAG,EAAE,UAAU,EAAE,IAAI,EAAE,UAAU,GAAG,UAAU,CAwB1F;AAED;;;;;;;;GAQG;AAEH,MAAM,MAAM,WAAW,GAAG;IACxB,8CAA8C;IAC9C,QAAQ,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,UAAU,CAAC;CACpD,CAAC;AAkCF;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,iBAAiB,EAAE,GAAG,EAAE,UAAU,GAAG,WAAW,CA4B/E"}
@@ -31,6 +31,18 @@ function hashFn(alg, data) {
31
31
  return sha512(data);
32
32
  }
33
33
  }
34
+ const normalizeHmacKey = (alg, key) => {
35
+ const blockLength = blockSize(alg);
36
+ if (key.length <= blockLength) {
37
+ const normalized = new Uint8Array(blockLength);
38
+ normalized.set(key);
39
+ return normalized;
40
+ }
41
+ const hashed = hashFn(alg, key);
42
+ const normalized = new Uint8Array(blockLength);
43
+ normalized.set(hashed);
44
+ return normalized;
45
+ };
34
46
  /**
35
47
  * Compute HMAC(key, data) using the specified hash algorithm.
36
48
  *
@@ -41,15 +53,7 @@ function hashFn(alg, data) {
41
53
  */
42
54
  export function hmac(alg, key, data) {
43
55
  const B = blockSize(alg);
44
- // Step 1: If key > block size, hash it; if shorter, pad with zeros.
45
- let k;
46
- if (key.length > B) {
47
- k = hashFn(alg, key);
48
- }
49
- else {
50
- k = new Uint8Array(B);
51
- k.set(key);
52
- }
56
+ const k = normalizeHmacKey(alg, key);
53
57
  // Step 2: ipad = k XOR 0x36, opad = k XOR 0x5c
54
58
  const ipad = new Uint8Array(B);
55
59
  const opad = new Uint8Array(B);
@@ -77,15 +81,7 @@ export function hmac(alg, key, data) {
77
81
  */
78
82
  function createHmacSha256Context(key) {
79
83
  const B = 64; // SHA-256 block size
80
- // Normalize key
81
- let k;
82
- if (key.length > B) {
83
- k = sha256(key);
84
- }
85
- else {
86
- k = new Uint8Array(B);
87
- k.set(key);
88
- }
84
+ const k = normalizeHmacKey("sha256", key);
89
85
  // Precompute padded ipad and opad blocks
90
86
  const ipadBlock = new Uint8Array(B);
91
87
  const opadBlock = new Uint8Array(B);
@@ -117,14 +113,7 @@ export function createHmac(alg, key) {
117
113
  }
118
114
  // Generic fallback: precompute padded ipad/opad (saves XOR and alloc per call)
119
115
  const B = blockSize(alg);
120
- let k;
121
- if (key.length > B) {
122
- k = hashFn(alg, key);
123
- }
124
- else {
125
- k = new Uint8Array(B);
126
- k.set(key);
127
- }
116
+ const k = normalizeHmacKey(alg, key);
128
117
  const ipad = new Uint8Array(B);
129
118
  const opad = new Uint8Array(B);
130
119
  for (let i = 0; i < B; i++) {
@@ -1 +1 @@
1
- {"version":3,"file":"sha512.d.ts","sourceRoot":"","sources":["../../src/primitives/sha512.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAwNH;;;GAGG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,UAAU,GAAG,UAAU,CAEnD;AAED;;;GAGG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,UAAU,GAAG,UAAU,CAEnD"}
1
+ {"version":3,"file":"sha512.d.ts","sourceRoot":"","sources":["../../src/primitives/sha512.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAoNH;;;GAGG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,UAAU,GAAG,UAAU,CAEnD;AAED;;;GAGG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,UAAU,GAAG,UAAU,CAEnD"}
@@ -63,10 +63,8 @@ function xor3_64(ah, al, bh, bl, ch_, cl) {
63
63
  return [(ah ^ bh ^ ch_) >>> 0, (al ^ bl ^ cl) >>> 0];
64
64
  }
65
65
  function sha512Core(data, initH) {
66
- const byteLenHi = Math.floor(data.length / 0x20000000) | 0;
67
- const byteLenLo = data.length >>> 0;
68
- const bitLenHi = ((byteLenHi << 3) | (byteLenLo >>> 29)) >>> 0;
69
- const bitLenLo = (byteLenLo << 3) >>> 0;
66
+ const bitLenHi = Math.floor(data.length / 0x20000000);
67
+ const bitLenLo = (data.length << 3) >>> 0;
70
68
  const padLen = data.length % 128 < 112 ? 112 - (data.length % 128) : 240 - (data.length % 128);
71
69
  const totalLen = data.length + padLen + 16;
72
70
  const msg = new Uint8Array(totalLen);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@signature-kit/crypto",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "dist",
@@ -37,7 +37,7 @@
37
37
  "test": "vitest run"
38
38
  },
39
39
  "dependencies": {
40
- "@signature-kit/asn1": "^0.1.0",
40
+ "@signature-kit/asn1": "^0.2.0",
41
41
  "effect": "4.0.0-beta.86"
42
42
  },
43
43
  "nx": {