@ac-kit/crypto-rsa 0.0.0-stage → 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 (76) hide show
  1. package/CHANGELOG.md +79 -0
  2. package/LICENSE +28 -0
  3. package/README.md +113 -2
  4. package/dist/_bytes.d.ts +18 -0
  5. package/dist/_bytes.d.ts.map +1 -0
  6. package/dist/_bytes.js +42 -0
  7. package/dist/_bytes.js.map +1 -0
  8. package/dist/encoding/_der.d.ts +51 -0
  9. package/dist/encoding/_der.d.ts.map +1 -0
  10. package/dist/encoding/_der.js +173 -0
  11. package/dist/encoding/_der.js.map +1 -0
  12. package/dist/encoding/rsa-algorithm.d.ts +132 -0
  13. package/dist/encoding/rsa-algorithm.d.ts.map +1 -0
  14. package/dist/encoding/rsa-algorithm.js +475 -0
  15. package/dist/encoding/rsa-algorithm.js.map +1 -0
  16. package/dist/hash/rsa-hash.d.ts +68 -0
  17. package/dist/hash/rsa-hash.d.ts.map +1 -0
  18. package/dist/hash/rsa-hash.js +86 -0
  19. package/dist/hash/rsa-hash.js.map +1 -0
  20. package/dist/index.d.ts +9 -0
  21. package/dist/index.d.ts.map +1 -0
  22. package/dist/index.js +9 -0
  23. package/dist/index.js.map +1 -0
  24. package/dist/key/_generate.d.ts +39 -0
  25. package/dist/key/_generate.d.ts.map +1 -0
  26. package/dist/key/_generate.js +124 -0
  27. package/dist/key/_generate.js.map +1 -0
  28. package/dist/key/_key-state.d.ts +53 -0
  29. package/dist/key/_key-state.d.ts.map +1 -0
  30. package/dist/key/_key-state.js +26 -0
  31. package/dist/key/_key-state.js.map +1 -0
  32. package/dist/key/_primality.d.ts +22 -0
  33. package/dist/key/_primality.d.ts.map +1 -0
  34. package/dist/key/_primality.js +156 -0
  35. package/dist/key/_primality.js.map +1 -0
  36. package/dist/key/_primitives.d.ts +27 -0
  37. package/dist/key/_primitives.d.ts.map +1 -0
  38. package/dist/key/_primitives.js +247 -0
  39. package/dist/key/_primitives.js.map +1 -0
  40. package/dist/key/_validate.d.ts +60 -0
  41. package/dist/key/_validate.d.ts.map +1 -0
  42. package/dist/key/_validate.js +328 -0
  43. package/dist/key/_validate.js.map +1 -0
  44. package/dist/key/rsa-private-key.d.ts +180 -0
  45. package/dist/key/rsa-private-key.d.ts.map +1 -0
  46. package/dist/key/rsa-private-key.js +479 -0
  47. package/dist/key/rsa-private-key.js.map +1 -0
  48. package/dist/key/rsa-public-key.d.ts +117 -0
  49. package/dist/key/rsa-public-key.d.ts.map +1 -0
  50. package/dist/key/rsa-public-key.js +196 -0
  51. package/dist/key/rsa-public-key.js.map +1 -0
  52. package/dist/rsa-error.d.ts +54 -0
  53. package/dist/rsa-error.d.ts.map +1 -0
  54. package/dist/rsa-error.js +14 -0
  55. package/dist/rsa-error.js.map +1 -0
  56. package/dist/scheme/_scheme-checks.d.ts +50 -0
  57. package/dist/scheme/_scheme-checks.d.ts.map +1 -0
  58. package/dist/scheme/_scheme-checks.js +162 -0
  59. package/dist/scheme/_scheme-checks.js.map +1 -0
  60. package/dist/scheme/_signature.d.ts +8 -0
  61. package/dist/scheme/_signature.d.ts.map +1 -0
  62. package/dist/scheme/_signature.js +13 -0
  63. package/dist/scheme/_signature.js.map +1 -0
  64. package/dist/scheme/rsaes-oaep.d.ts +75 -0
  65. package/dist/scheme/rsaes-oaep.d.ts.map +1 -0
  66. package/dist/scheme/rsaes-oaep.js +191 -0
  67. package/dist/scheme/rsaes-oaep.js.map +1 -0
  68. package/dist/scheme/rsassa-pkcs1-v1_5.d.ts +73 -0
  69. package/dist/scheme/rsassa-pkcs1-v1_5.d.ts.map +1 -0
  70. package/dist/scheme/rsassa-pkcs1-v1_5.js +133 -0
  71. package/dist/scheme/rsassa-pkcs1-v1_5.js.map +1 -0
  72. package/dist/scheme/rsassa-pss.d.ts +88 -0
  73. package/dist/scheme/rsassa-pss.d.ts.map +1 -0
  74. package/dist/scheme/rsassa-pss.js +175 -0
  75. package/dist/scheme/rsassa-pss.js.map +1 -0
  76. package/package.json +75 -3
package/CHANGELOG.md ADDED
@@ -0,0 +1,79 @@
1
+ # @ac-kit/crypto-rsa
2
+
3
+ ## 0.1.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [66187b7]
8
+ - @ac-kit/core@0.15.0
9
+ - @ac-kit/format-asn1@0.5.1
10
+ - @ac-kit/crypto-hash@0.2.1
11
+ - @ac-kit/crypto-random@0.3.1
12
+ - @ac-kit/crypto-safe@0.3.1
13
+
14
+ ## 0.1.0
15
+
16
+ ### Minor Changes
17
+
18
+ - 5c203e7: New package: RSA in portable TypeScript, synchronous, constant time on
19
+ private-key data (on `@ac-kit/crypto-safe`'s WebAssembly arithmetic kernel).
20
+
21
+ - `RsaPrivateKey.generate` and `generateAsync` (with `signal` and `sliceMs`)
22
+ make keys by FIPS 186-5 A.1.3: random probable primes with the Miller–Rabin
23
+ rounds of Table B.1, |p − q| and d > 2^(nlen/2) checked, sizes from 2048 to
24
+ 16384 bits, any odd e with 2¹⁶ < e < 2²⁵⁶ (default 65537).
25
+ - `RsaPublicKey` reads and writes PKCS #1 `RSAPublicKey`, X.509
26
+ `SubjectPublicKeyInfo` and components; `RsaPrivateKey` reads and writes
27
+ PKCS #1 `RSAPrivateKey` (multi-prime too), PKCS #8 `PrivateKeyInfo` (and
28
+ reads RFC 5958 `OneAsymmetricKey`), components with or without the CRT
29
+ integers, and primes. DER is read strictly; imports check that the integers
30
+ make a key, primes odd and above 3, and by default also test the primes
31
+ (`{ checkPrimality: false }` skips that for trusted keys). Moduli from 1024
32
+ to 16384 bits.
33
+ - A key's `AlgorithmIdentifier` (`rsaEncryption`, `RSASSA-PSS`, `RSAES-OAEP`,
34
+ with parameters, RFC 4055 and RFC 8702) is validated, kept as a frozen copy
35
+ and enforced by every scheme; OAEP labels read as fresh copies.
36
+ `encodeRsaSignatureAlgorithm`, `decodeRsaSignatureAlgorithm` and
37
+ their key and OAEP siblings read and write the identifiers X.509 and CMS
38
+ carry.
39
+ - `rsassaPss` (MGF1 or SHAKE masks, any salt length) and `rsassaPkcs1V15`
40
+ sign and verify with SHA-1, SHA-2, SHA-3 and SHAKE, from messages or
41
+ digests; verification returns false for any malformed signature.
42
+ - `rsaesOaep` encrypts and decrypts with any label; every bad ciphertext,
43
+ of the wrong length or out of range included, gets the same
44
+ `decryptionError` after the same work.
45
+ - Private-key operations use the CRT with base, exponent and modulus blinding
46
+ and check their result before releasing it. Private keys are `Disposable`,
47
+ frozen, hold no data properties and show a redacted form to `util.inspect`
48
+ and `JSON.stringify`; inputs are never written to or kept. Refused inputs
49
+ throw `RsaError` with a machine-readable `reason`.
50
+
51
+ RSAES-PKCS1-v1_5 encryption is not included.
52
+
53
+ ### Patch Changes
54
+
55
+ - Updated dependencies [5c203e7]
56
+ - Updated dependencies [5c203e7]
57
+ - Updated dependencies [5c203e7]
58
+ - Updated dependencies [5c203e7]
59
+ - Updated dependencies [5c203e7]
60
+ - Updated dependencies [5c203e7]
61
+ - Updated dependencies [5c203e7]
62
+ - Updated dependencies [5c203e7]
63
+ - Updated dependencies [5c203e7]
64
+ - Updated dependencies [5c203e7]
65
+ - Updated dependencies [5c203e7]
66
+ - Updated dependencies [5c203e7]
67
+ - Updated dependencies [5c203e7]
68
+ - Updated dependencies [5c203e7]
69
+ - Updated dependencies [5c203e7]
70
+ - Updated dependencies [5c203e7]
71
+ - Updated dependencies [5c203e7]
72
+ - Updated dependencies [5c203e7]
73
+ - Updated dependencies [5c203e7]
74
+ - @ac-kit/crypto-hash@0.2.0
75
+ - @ac-kit/format-asn1@0.5.0
76
+ - @ac-kit/core@0.14.0
77
+ - @ac-kit/crypto-random@0.3.0
78
+ - @ac-kit/crypto-safe@0.3.0
79
+ - @ac-kit/format-oid@0.3.0
package/LICENSE ADDED
@@ -0,0 +1,28 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2024-2026 Anthony Champagne and contributors
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ this list of conditions and the following disclaimer in the documentation
13
+ and/or other materials provided with the distribution.
14
+
15
+ 3. Neither the name of the copyright holder nor the names of its
16
+ contributors may be used to endorse or promote products derived from
17
+ this software without specific prior written permission.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/README.md CHANGED
@@ -1,3 +1,114 @@
1
- # Temporary Holding Version
1
+ # @ac-kit/crypto-rsa
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ RSA in portable TypeScript with no Node.js built-ins:
4
+
5
+ - key generation by FIPS 186-5 A.1.3 (random probable primes, Miller–Rabin
6
+ rounds of Table B.1), synchronous or in event-loop slices with an
7
+ `AbortSignal`;
8
+ - keys in PKCS #1 (`RSAPublicKey`, `RSAPrivateKey`, multi-prime included),
9
+ X.509 `SubjectPublicKeyInfo` and PKCS #8 (`PrivateKeyInfo` and RFC 5958
10
+ `OneAsymmetricKey`), read strictly as DER, with the `RSASSA-PSS` and
11
+ `RSAES-OAEP` key restrictions of RFC 4055 and RFC 8702;
12
+ - RSASSA-PSS and RSASSA-PKCS1-v1_5 signatures (RFC 8017 §8), SHA-1, SHA-2,
13
+ SHA-3 and, for PSS, SHAKE128/256;
14
+ - RSAES-OAEP encryption (RFC 8017 §7.1);
15
+ - the X.509 and CMS `AlgorithmIdentifier`s of the schemes.
16
+
17
+ Every operation is synchronous. Operations on a private key run in constant
18
+ time in its integers: fixed-width words, fixed-window exponentiation, no
19
+ branch or memory index that depends on a secret. The modular arithmetic is
20
+ `@ac-kit/crypto-safe`'s `ConstantTimeModulus`, on its WebAssembly kernel; key
21
+ generation's division, GCD and inverse on byte strings are still branch-free
22
+ TypeScript. No JavaScript or WebAssembly engine promises constant time, so
23
+ treat this as careful engineering checked by timing tests, not a proof.
24
+
25
+ ## Sign and verify
26
+
27
+ ```typescript
28
+ import { RsaPrivateKey, rsassaPss } from "@ac-kit/crypto-rsa";
29
+
30
+ using key = RsaPrivateKey.generate({ modulusBits: 3072 });
31
+ const scheme = rsassaPss({ hash: "SHA-256" }); // MGF1-SHA-256, 32-byte salt
32
+ const message = new TextEncoder().encode("hello");
33
+ const signature = scheme.sign(key, message);
34
+
35
+ scheme.verify(key.publicKey, message, signature); // true
36
+ ```
37
+
38
+ `rsassaPkcs1V15("SHA-256")` gives the deterministic RSASSA-PKCS1-v1_5 scheme
39
+ with the same methods. `signPrehashed` and `verifyPrehashed` take a digest
40
+ computed elsewhere, for instance over a stream. Verification returns false for
41
+ a signature of the wrong length or out of range; it throws only when the key
42
+ is restricted to another scheme (`algorithmMismatch`).
43
+
44
+ PSS takes `maskGeneration` (`mgf1(RSA_HASHES["SHA-1"])`, or SHAKE itself for a
45
+ SHAKE hash as RFC 8702 says) and `saltLength`. Signing draws a fresh salt;
46
+ `{ salt }` gives one for known-answer tests.
47
+
48
+ ## Encrypt and decrypt with OAEP
49
+
50
+ ```typescript
51
+ import { rsaesOaep } from "@ac-kit/crypto-rsa";
52
+
53
+ const oaep = rsaesOaep({ hash: "SHA-256", label: new TextEncoder().encode("v1") });
54
+ const ciphertext = oaep.encrypt(key.publicKey, secretBytes);
55
+ const plaintext = oaep.decrypt(key, ciphertext);
56
+ ```
57
+
58
+ `maximumMessageLength(key)` is k − 2·hLen − 2 bytes. Decryption turns any
59
+ ciphertext — of the wrong length or out of range included — into a k-byte
60
+ value below n, runs the same private-key operation, unmasking and decoding on
61
+ it, and only then refuses a bad one, with one `RsaError` (`decryptionError`),
62
+ as RFC 8017 §7.1.2 requires.
63
+
64
+ RSAES-PKCS1-v1_5 encryption is not provided: it is kept only for legacy
65
+ protocols, and its decryption is safe only with implicit rejection.
66
+
67
+ ## Keys
68
+
69
+ `RsaPublicKey.fromSpki`, `fromPkcs1` and `fromComponents({ modulus,
70
+ publicExponent })` make public keys; `toSpki`, `toPkcs1` and
71
+ `exportComponents` write them. `RsaPrivateKey.fromPkcs8`, `fromPkcs1`,
72
+ `fromComponents` (with or without the CRT integers) and `fromPrimes` (n, d
73
+ and the CRT integers derived from the primes) make private keys; `toPkcs8`,
74
+ `toPkcs1` and `exportComponents` write them.
75
+
76
+ Imports check that the integers make a key — the primes are odd, above 3 and
77
+ multiply to n, every CRT exponent and coefficient is right, or, without
78
+ primes, that d inverts e — in constant time, and refuse moduli outside 1024 to
79
+ 16384 bits. They also test each prime by default, with trial division and five
80
+ Miller–Rabin rounds as SP 800-56B key-pair validation does: about 80 ms for a
81
+ 2048-bit key and half a second at 4096 bits. `{ checkPrimality: false }` skips
82
+ that test for keys from a trusted source. A key's algorithm (`rsaEncryption`,
83
+ `RSASSA-PSS` or `RSAES-OAEP`, with parameters) comes from its
84
+ `AlgorithmIdentifier` or the `algorithm` option, is validated and kept as a
85
+ frozen copy (an OAEP label reads as a fresh copy), and every scheme enforces
86
+ it; `publicKey.withAlgorithm(…)` makes a restricted copy.
87
+
88
+ `generate({ modulusBits, publicExponent })` takes an even size from 2048 bits
89
+ and an odd e with 2¹⁶ < e < 2²⁵⁶ (default 65537); `generateAsync` takes
90
+ `signal` and `sliceMs` besides.
91
+
92
+ Every private-key operation multiplies its input by a random blinding factor,
93
+ adds a random multiple of the group order to each exponent, works modulo a
94
+ random multiple of each prime, and checks its result before releasing it, so
95
+ that a fault cannot leak a prime (`privateKeyFault`).
96
+
97
+ Inputs are never written to or kept: the package copies what it keeps and
98
+ wipes its working memory on every path. Disposing of a private key, with
99
+ `using` or `key[Symbol.dispose]()`, overwrites its integers; a disposed key
100
+ throws on use. The wipe is best effort: the engine may have copied the bytes.
101
+ Keys are frozen objects with no data properties: `util.inspect`,
102
+ `console.log` and `JSON.stringify` show `RsaPrivateKey { <redacted> }`.
103
+
104
+ ## Errors
105
+
106
+ Refused inputs throw an `RsaError` whose `reason` names the rule broken
107
+ (`invalidLength`, `invalidEncoding`, `invalidKey`, `unsupportedKeySize`,
108
+ `invalidParameters`, `algorithmMismatch`, `unsupportedAlgorithm`,
109
+ `messageTooLong`, `keyTooShort`, `decryptionError`, `keyGenerationFailed`,
110
+ `privateKeyFault`, `disposed`). Messages never carry key or plaintext bytes.
111
+
112
+ See the
113
+ [generated API docs](https://anthochamp.pages.grenadine.io/node-essentials/api/crypto-rsa/)
114
+ for the full reference.
@@ -0,0 +1,18 @@
1
+ /** Helpers for **public** byte strings only: they branch on the bytes. */
2
+ /** `bytes` without its leading zero bytes (one 0 byte for 0), a view. */
3
+ export declare function stripLeadingZeros(bytes: Uint8Array): Uint8Array;
4
+ /** The bit length of the unsigned big-endian `bytes`, 0 for 0. */
5
+ export declare function bitLengthOf(bytes: Uint8Array): number;
6
+ /** The unsigned value of public `bytes`. */
7
+ export declare function unsignedOf(bytes: Uint8Array): bigint;
8
+ /** The `length`-byte big-endian encoding of a public `value` below 2^(8·length). */
9
+ export declare function bytesOfUnsigned(value: bigint, length: number): Uint8Array<ArrayBuffer>;
10
+ /** The minimal big-endian encoding of a public non-negative `value`. */
11
+ export declare function minimalBytesOf(value: bigint): Uint8Array<ArrayBuffer>;
12
+ /**
13
+ * `bytes` left-padded with zeros to `length` bytes, copied; `bytes` must have
14
+ * at most `length` significant bytes (leading zeros beyond are dropped). It
15
+ * depends on the lengths only, so it takes secret bytes too.
16
+ */
17
+ export declare function leftPad(bytes: Uint8Array, length: number): Uint8Array<ArrayBuffer>;
18
+ //# sourceMappingURL=_bytes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_bytes.d.ts","sourceRoot":"","sources":["../src/_bytes.ts"],"names":[],"mappings":"AAEA,0EAA0E;AAE1E,yEAAyE;AACzE,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,UAAU,GAAG,UAAU,CAQ/D;AAED,kEAAkE;AAClE,wBAAgB,WAAW,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAKrD;AAED,4CAA4C;AAC5C,wBAAgB,UAAU,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAEpD;AAED,oFAAoF;AACpF,wBAAgB,eAAe,CAC9B,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,GACZ,UAAU,CAAC,WAAW,CAAC,CAGzB;AAED,wEAAwE;AACxE,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAAC,WAAW,CAAC,CAIrE;AAED;;;;GAIG;AACH,wBAAgB,OAAO,CACtB,KAAK,EAAE,UAAU,EACjB,MAAM,EAAE,MAAM,GACZ,UAAU,CAAC,WAAW,CAAC,CAOzB"}
package/dist/_bytes.js ADDED
@@ -0,0 +1,42 @@
1
+ import { bigIntFromBytesBe, bigIntToBytesBe } from "@ac-kit/core";
2
+ /** Helpers for **public** byte strings only: they branch on the bytes. */
3
+ /** `bytes` without its leading zero bytes (one 0 byte for 0), a view. */
4
+ export function stripLeadingZeros(bytes) {
5
+ let start = 0;
6
+ while (start < bytes.length - 1 && bytes[start] === 0) {
7
+ start++;
8
+ }
9
+ return bytes.length === 0 ? new Uint8Array(1) : bytes.subarray(start);
10
+ }
11
+ /** The bit length of the unsigned big-endian `bytes`, 0 for 0. */
12
+ export function bitLengthOf(bytes) {
13
+ const minimal = stripLeadingZeros(bytes);
14
+ const top = minimal[0];
15
+ return top === 0 ? 0 : 8 * (minimal.length - 1) + (32 - Math.clz32(top));
16
+ }
17
+ /** The unsigned value of public `bytes`. */
18
+ export function unsignedOf(bytes) {
19
+ return BigInt.asUintN(8 * bytes.length, bigIntFromBytesBe(bytes));
20
+ }
21
+ /** The `length`-byte big-endian encoding of a public `value` below 2^(8·length). */
22
+ export function bytesOfUnsigned(value, length) {
23
+ // One spare byte: a set top bit would otherwise read as a sign.
24
+ return bigIntToBytesBe(value, length + 1).slice(1);
25
+ }
26
+ /** The minimal big-endian encoding of a public non-negative `value`. */
27
+ export function minimalBytesOf(value) {
28
+ const length = Math.max(1, Math.ceil(value.toString(16).length / 2));
29
+ return bytesOfUnsigned(value, length);
30
+ }
31
+ /**
32
+ * `bytes` left-padded with zeros to `length` bytes, copied; `bytes` must have
33
+ * at most `length` significant bytes (leading zeros beyond are dropped). It
34
+ * depends on the lengths only, so it takes secret bytes too.
35
+ */
36
+ export function leftPad(bytes, length) {
37
+ const out = new Uint8Array(length);
38
+ const take = Math.min(bytes.length, length);
39
+ out.set(bytes.subarray(bytes.length - take), length - take);
40
+ return out;
41
+ }
42
+ //# sourceMappingURL=_bytes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_bytes.js","sourceRoot":"","sources":["../src/_bytes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAElE,0EAA0E;AAE1E,yEAAyE;AACzE,MAAM,UAAU,iBAAiB,CAAC,KAAiB;IAClD,IAAI,KAAK,GAAG,CAAC,CAAC;IAEd,OAAO,KAAK,GAAG,KAAK,CAA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eAAe,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;AACvC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,OAAO,CACtB,KAAiB,EACjB,MAAc;IAEd,MAAM,GAAG,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC;IACnC,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAE5C,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC,CAAC;IAE5D,OAAO,GAAG,CAAC;AACZ,CAAC"}
@@ -0,0 +1,51 @@
1
+ import { BerReader } from "@ac-kit/format-asn1";
2
+ /**
3
+ * The few DER pieces the key encodings need, written by hand rather than
4
+ * through `@ac-kit/format-asn1`'s schemas because they carry secret integers:
5
+ * the schemas would turn every INTEGER into a `bigint` and leave copies of the
6
+ * encoding in buffers no one wipes. Reading goes through `BerReader` with the
7
+ * DER rules, whose views are never copied; the INTEGER contents rules (X.690
8
+ * §8.3) are checked here.
9
+ *
10
+ * The length of a DER INTEGER is the length of its minimal encoding, so the
11
+ * leading-zero handling here reveals the byte length of each secret integer, as
12
+ * any encoding of it does.
13
+ */
14
+ export declare const TAG_INTEGER = 2;
15
+ export declare const TAG_BIT_STRING = 3;
16
+ export declare const TAG_OCTET_STRING = 4;
17
+ export declare const TAG_NULL = 5;
18
+ export declare const TAG_SEQUENCE = 48;
19
+ /** The DER element `tag ‖ length ‖ contents…`. */
20
+ export declare function derElement(tag: number, contents: readonly Uint8Array[]): Uint8Array<ArrayBuffer>;
21
+ /**
22
+ * The DER INTEGER of the unsigned big-endian `bytes`: leading zeros dropped,
23
+ * one added back when the top bit is set.
24
+ */
25
+ export declare function derUnsignedInteger(bytes: Uint8Array): Uint8Array<ArrayBuffer>;
26
+ /** Wipes every part of `parts`. */
27
+ export declare function wipeAll(parts: readonly Uint8Array[]): void;
28
+ /**
29
+ * Runs `read` over a DER reader of `bytes` and checks nothing follows, turning
30
+ * every `DecodingError` into an `RsaError` `invalidEncoding`.
31
+ */
32
+ export declare function readDer<Result>(bytes: Uint8Array, what: string, read: (reader: BerReader) => Result): Result;
33
+ /** Enters the next element, which must be a SEQUENCE. */
34
+ export declare function enterSequence(reader: BerReader, what: string): BerReader;
35
+ /**
36
+ * The value of the next element, a non-negative DER INTEGER, as its minimal
37
+ * unsigned big-endian bytes (one 0 byte for 0), copied.
38
+ */
39
+ export declare function readUnsignedInteger(reader: BerReader, what: string): Uint8Array<ArrayBuffer>;
40
+ /** The next element, an INTEGER that fits a safe integer, as a number. */
41
+ export declare function readSmallInteger(reader: BerReader, what: string): number;
42
+ /** The contents of the next element, a primitive OCTET STRING. */
43
+ export declare function readOctetString(reader: BerReader, what: string): Uint8Array;
44
+ /**
45
+ * The contents of the next element, a primitive BIT STRING with no unused bits,
46
+ * without its unused-bits octet.
47
+ */
48
+ export declare function readOctetAlignedBitString(reader: BerReader, what: string): Uint8Array;
49
+ /** Whether the next element has `tag` (a one-octet identifier). */
50
+ export declare function nextHasTag(reader: BerReader, tag: number): boolean;
51
+ //# sourceMappingURL=_der.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_der.d.ts","sourceRoot":"","sources":["../../src/encoding/_der.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAiB,MAAM,qBAAqB,CAAC;AAI/D;;;;;;;;;;;GAWG;AAEH,eAAO,MAAM,WAAW,IAAO,CAAC;AAChC,eAAO,MAAM,cAAc,IAAO,CAAC;AACnC,eAAO,MAAM,gBAAgB,IAAO,CAAC;AACrC,eAAO,MAAM,QAAQ,IAAO,CAAC;AAC7B,eAAO,MAAM,YAAY,KAAO,CAAC;AAEjC,kDAAkD;AAClD,wBAAgB,UAAU,CACzB,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,SAAS,UAAU,EAAE,GAC7B,UAAU,CAAC,WAAW,CAAC,CAmBzB;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,UAAU,GAAG,UAAU,CAAC,WAAW,CAAC,CAiB7E;AAED,mCAAmC;AACnC,wBAAgB,OAAO,CAAC,KAAK,EAAE,SAAS,UAAU,EAAE,GAAG,IAAI,CAI1D;AAED;;;GAGG;AACH,wBAAgB,OAAO,CAAC,MAAM,EAC7B,KAAK,EAAE,UAAU,EACjB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,CAAC,MAAM,EAAE,SAAS,KAAK,MAAM,GACjC,MAAM,CAiBR;AAED,yDAAyD;AACzD,wBAAgB,aAAa,CAAC,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS,CAIxE;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAClC,MAAM,EAAE,SAAS,EACjB,IAAI,EAAE,MAAM,GACV,UAAU,CAAC,WAAW,CAAC,CAqBzB;AAED,0EAA0E;AAC1E,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAcxE;AAED,kEAAkE;AAClE,wBAAgB,eAAe,CAAC,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,GAAG,UAAU,CAI3E;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,CACxC,MAAM,EAAE,SAAS,EACjB,IAAI,EAAE,MAAM,GACV,UAAU,CAaZ;AAED,mEAAmE;AACnE,wBAAgB,UAAU,CAAC,MAAM,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAQlE"}
@@ -0,0 +1,173 @@
1
+ import { BerReader, DecodingError } from "@ac-kit/format-asn1";
2
+ import { RsaError } from "../rsa-error.js";
3
+ /**
4
+ * The few DER pieces the key encodings need, written by hand rather than
5
+ * through `@ac-kit/format-asn1`'s schemas because they carry secret integers:
6
+ * the schemas would turn every INTEGER into a `bigint` and leave copies of the
7
+ * encoding in buffers no one wipes. Reading goes through `BerReader` with the
8
+ * DER rules, whose views are never copied; the INTEGER contents rules (X.690
9
+ * §8.3) are checked here.
10
+ *
11
+ * The length of a DER INTEGER is the length of its minimal encoding, so the
12
+ * leading-zero handling here reveals the byte length of each secret integer, as
13
+ * any encoding of it does.
14
+ */
15
+ export const TAG_INTEGER = 0x02;
16
+ export const TAG_BIT_STRING = 0x03;
17
+ export const TAG_OCTET_STRING = 0x04;
18
+ export const TAG_NULL = 0x05;
19
+ export const TAG_SEQUENCE = 0x30;
20
+ /** The DER element `tag ‖ length ‖ contents…`. */
21
+ export function derElement(tag, contents) {
22
+ let length = 0;
23
+ for (const part of contents) {
24
+ length += part.length;
25
+ }
26
+ const header = derHeader_(tag, length);
27
+ const out = new Uint8Array(header.length + length);
28
+ let offset = header.length;
29
+ out.set(header);
30
+ for (const part of contents) {
31
+ out.set(part, offset);
32
+ offset += part.length;
33
+ }
34
+ return out;
35
+ }
36
+ /**
37
+ * The DER INTEGER of the unsigned big-endian `bytes`: leading zeros dropped,
38
+ * one added back when the top bit is set.
39
+ */
40
+ export function derUnsignedInteger(bytes) {
41
+ let start = 0;
42
+ while (start < bytes.length - 1 && bytes[start] === 0) {
43
+ start++;
44
+ }
45
+ const significant = bytes.length === 0 ? Uint8Array.of(0) : bytes.subarray(start);
46
+ const pad = (significant[0] & 0x80) === 0 ? 0 : 1;
47
+ const header = derHeader_(TAG_INTEGER, significant.length + pad);
48
+ const out = new Uint8Array(header.length + pad + significant.length);
49
+ out.set(header);
50
+ out.set(significant, header.length + pad);
51
+ return out;
52
+ }
53
+ /** Wipes every part of `parts`. */
54
+ export function wipeAll(parts) {
55
+ for (const part of parts) {
56
+ part.fill(0);
57
+ }
58
+ }
59
+ /**
60
+ * Runs `read` over a DER reader of `bytes` and checks nothing follows, turning
61
+ * every `DecodingError` into an `RsaError` `invalidEncoding`.
62
+ */
63
+ export function readDer(bytes, what, read) {
64
+ try {
65
+ const reader = new BerReader(bytes, "der");
66
+ const result = read(reader);
67
+ reader.finish();
68
+ return result;
69
+ }
70
+ catch (error) {
71
+ if (error instanceof DecodingError) {
72
+ throw new RsaError("invalidEncoding", `${what} is not valid DER`, {
73
+ cause: error,
74
+ });
75
+ }
76
+ throw error;
77
+ }
78
+ }
79
+ /** Enters the next element, which must be a SEQUENCE. */
80
+ export function enterSequence(reader, what) {
81
+ expectTag_(reader, TAG_SEQUENCE, what);
82
+ return reader.enter();
83
+ }
84
+ /**
85
+ * The value of the next element, a non-negative DER INTEGER, as its minimal
86
+ * unsigned big-endian bytes (one 0 byte for 0), copied.
87
+ */
88
+ export function readUnsignedInteger(reader, what) {
89
+ expectTag_(reader, TAG_INTEGER, what);
90
+ const contents = reader.readContents();
91
+ if (contents.length === 0) {
92
+ throw new RsaError("invalidEncoding", `${what} is an empty INTEGER`);
93
+ }
94
+ if ((contents[0] & 0x80) !== 0) {
95
+ throw new RsaError("invalidEncoding", `${what} must not be negative`);
96
+ }
97
+ if (contents.length > 1 && contents[0] === 0 && (contents[1] & 0x80) === 0) {
98
+ throw new RsaError("invalidEncoding", `${what} is not a minimal INTEGER encoding`);
99
+ }
100
+ return contents.slice(contents.length > 1 && contents[0] === 0 ? 1 : 0);
101
+ }
102
+ /** The next element, an INTEGER that fits a safe integer, as a number. */
103
+ export function readSmallInteger(reader, what) {
104
+ const bytes = readUnsignedInteger(reader, what);
105
+ if (bytes.length > 4) {
106
+ throw new RsaError("invalidEncoding", `${what} is out of range`);
107
+ }
108
+ let value = 0;
109
+ for (const byte of bytes) {
110
+ value = value * 256 + byte;
111
+ }
112
+ return value;
113
+ }
114
+ /** The contents of the next element, a primitive OCTET STRING. */
115
+ export function readOctetString(reader, what) {
116
+ expectTag_(reader, TAG_OCTET_STRING, what);
117
+ return reader.readContents();
118
+ }
119
+ /**
120
+ * The contents of the next element, a primitive BIT STRING with no unused bits,
121
+ * without its unused-bits octet.
122
+ */
123
+ export function readOctetAlignedBitString(reader, what) {
124
+ expectTag_(reader, TAG_BIT_STRING, what);
125
+ const contents = reader.readContents();
126
+ if (contents.length === 0 || contents[0] !== 0) {
127
+ throw new RsaError("invalidEncoding", `${what} must be a BIT STRING of whole octets`);
128
+ }
129
+ return contents.subarray(1);
130
+ }
131
+ /** Whether the next element has `tag` (a one-octet identifier). */
132
+ export function nextHasTag(reader, tag) {
133
+ if (reader.atEnd) {
134
+ return false;
135
+ }
136
+ reader.peekHeader();
137
+ return identifierOf_(reader) === tag;
138
+ }
139
+ function expectTag_(reader, tag, what) {
140
+ if (reader.atEnd) {
141
+ throw new RsaError("invalidEncoding", `${what} is missing`);
142
+ }
143
+ reader.peekHeader();
144
+ if (identifierOf_(reader) !== tag) {
145
+ throw new RsaError("invalidEncoding", `${what} has an unexpected tag`);
146
+ }
147
+ }
148
+ /** The one-octet identifier of the current header, or −1 for a longer one. */
149
+ function identifierOf_(reader) {
150
+ const tagNumber = reader.tagNumber;
151
+ if (tagNumber === null || tagNumber > 30) {
152
+ return -1;
153
+ }
154
+ const classBits = reader.tagClass === "universal"
155
+ ? 0x00
156
+ : reader.tagClass === "application"
157
+ ? 0x40
158
+ : reader.tagClass === "context"
159
+ ? 0x80
160
+ : 0xc0;
161
+ return classBits | (reader.constructed ? 0x20 : 0) | tagNumber;
162
+ }
163
+ function derHeader_(tag, length) {
164
+ if (length < 0x80) {
165
+ return Uint8Array.of(tag, length);
166
+ }
167
+ const lengthBytes = [];
168
+ for (let rest = length; rest > 0; rest = Math.floor(rest / 256)) {
169
+ lengthBytes.unshift(rest % 256);
170
+ }
171
+ return Uint8Array.of(tag, 0x80 | lengthBytes.length, ...lengthBytes);
172
+ }
173
+ //# sourceMappingURL=_der.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_der.js","sourceRoot":"","sources":["../../src/encoding/_der.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAE/D,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE3C;;;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