@reallyme/crypto 0.4.2 → 0.4.5
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 +23 -51
- package/dist/aead.js +4 -13
- package/dist/aesKw.js +5 -13
- package/dist/argon2id.js +4 -11
- package/dist/bip340Schnorr.js +14 -0
- package/dist/hpke.js +5 -11
- package/dist/jwk.js +2 -2
- package/dist/kmac.js +4 -13
- package/dist/mlDsa.js +2 -1
- package/dist/mlKem.js +2 -1
- package/dist/operationResponse.js +5 -13
- package/dist/p256Ecdsa.js +3 -4
- package/dist/p384Ecdsa.js +3 -4
- package/dist/p521Ecdsa.js +3 -4
- package/dist/proto/generated/reallyme/crypto/v1/crypto_pb.d.ts +313 -2
- package/dist/proto/generated/reallyme/crypto/v1/crypto_pb.js +257 -187
- package/dist/rsa.js +2 -1
- package/dist/slhDsa.js +5 -1
- package/dist/validateBytes.d.ts +1 -0
- package/dist/validateBytes.js +4 -1
- package/dist/validateSec1PublicKey.d.ts +1 -0
- package/dist/validateSec1PublicKey.js +23 -0
- package/dist/verifyBundledWasmModule.d.ts +1 -1
- package/dist/verifyBundledWasmModule.js +1 -1
- package/dist/wasm/reallyme_crypto_wasm_bg.wasm +0 -0
- package/dist/xWing.js +2 -1
- package/package.json +5 -4
package/README.md
CHANGED
|
@@ -7,10 +7,6 @@
|
|
|
7
7
|
synchronous APIs for Node.js and browsers, with explicit JavaScript and
|
|
8
8
|
package-owned WASM providers.
|
|
9
9
|
|
|
10
|
-
The package shares algorithm identifiers, byte formats, typed failures, and
|
|
11
|
-
conformance vectors with the Rust, Swift, Kotlin, and Android SDKs. Availability
|
|
12
|
-
is provider-specific; unsupported routes fail closed.
|
|
13
|
-
|
|
14
10
|
## Installation
|
|
15
11
|
|
|
16
12
|
```sh
|
|
@@ -29,7 +25,7 @@ const digest = ReallyMeCrypto.hash(
|
|
|
29
25
|
```
|
|
30
26
|
|
|
31
27
|
The API is synchronous. Signature verification throws `ReallyMeCryptoError` on
|
|
32
|
-
|
|
28
|
+
malformed input or an invalid signature.
|
|
33
29
|
|
|
34
30
|
`ReallyMeP256Ecdsa` normalizes canonical DER or fixed-width 64-byte `r || s`
|
|
35
31
|
signatures to low-S form for HSM and platform-keystore integrations. The helper
|
|
@@ -42,18 +38,16 @@ an immutable profile version rather than an iteration count.
|
|
|
42
38
|
|
|
43
39
|
## Post-Quantum and WASM
|
|
44
40
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
41
|
+
Hashes and selected classical asymmetric operations use the pinned JavaScript
|
|
42
|
+
providers. ML-KEM, ML-DSA, SLH-DSA, X-Wing, Argon2id, HPKE and other
|
|
43
|
+
Rust-backed operations require the
|
|
44
|
+
bundled WASM module. Initialize it before calling those methods.
|
|
48
45
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
`provider-failure`. JWK/JWKS helpers delegate base64url and JCS canonicalization
|
|
55
|
-
to the published `@reallyme/codec` package, so applications that use those
|
|
56
|
-
helpers should also install the Codec WASM provider.
|
|
46
|
+
Use `installReallyMeWasmProvider` for the package-level facade or
|
|
47
|
+
`createReallyMeCrypto` for an isolated instance. Explicit facades reject
|
|
48
|
+
structural provider objects, copied hooks and proxies with `provider-failure`.
|
|
49
|
+
Only the package's initialized WASM module is accepted. JWK/JWKS helpers also
|
|
50
|
+
require the Codec WASM provider.
|
|
57
51
|
|
|
58
52
|
JSON and protobuf JWKS ingress routes accept at most 1,024 keys. Encoded JWK
|
|
59
53
|
and JWKS protobuf inputs are capped at one mebibyte before decoding, and an
|
|
@@ -72,8 +66,6 @@ import {
|
|
|
72
66
|
} from "@reallyme/crypto";
|
|
73
67
|
import { initSync as initCryptoWasm } from "@reallyme/crypto/wasm/reallyme_crypto_wasm.js";
|
|
74
68
|
|
|
75
|
-
// Both the global installer and explicit facade bind to this package's
|
|
76
|
-
// initialized module namespace after verifying callable identity.
|
|
77
69
|
const wasmProvider: unknown = await import(
|
|
78
70
|
"@reallyme/crypto/wasm/reallyme_crypto_wasm.js"
|
|
79
71
|
);
|
|
@@ -100,12 +92,10 @@ const keyPair = ReallyMeCrypto.generateKemKeyPair("X-Wing-768");
|
|
|
100
92
|
const isolatedKeyPair = isolatedCrypto.generateKemKeyPair("X-Wing-768");
|
|
101
93
|
```
|
|
102
94
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
The package-owned WASM provider derives ML-DSA, ML-KEM, and X-Wing seed-based
|
|
108
|
-
keypairs inside Rust and returns the public key produced by that implementation.
|
|
95
|
+
P-256, P-384, and P-521 ECDSA verification accepts standard compressed SEC1
|
|
96
|
+
keys (`0x02` or `0x03`) and uncompressed SEC1 keys (`0x04`) at the curve's exact
|
|
97
|
+
width. Key generation and public-key derivation continue to emit compressed
|
|
98
|
+
keys. Compact (`0x05`) and hybrid (`0x06` or `0x07`) encodings are rejected.
|
|
109
99
|
|
|
110
100
|
## Raw WASM Module Contract
|
|
111
101
|
|
|
@@ -115,14 +105,6 @@ instances. Direct raw WASM calls are unsupported for application logic. Use the
|
|
|
115
105
|
typed TypeScript facades, which validate caller inputs, numeric ranges, provider
|
|
116
106
|
outputs, aliasing, and cleanup before invoking the raw module.
|
|
117
107
|
|
|
118
|
-
This distinction matters for numeric parameters: JavaScript-to-WASM glue can
|
|
119
|
-
coerce raw `number` arguments before Rust receives them. The supported facades
|
|
120
|
-
reject out-of-range Argon2id, KMAC, HPKE, and RSA selector or length values
|
|
121
|
-
before provider dispatch. Package checks verify that the README, package
|
|
122
|
-
exports, TypeScript declarations, and generated WASM glue continue to agree on
|
|
123
|
-
this support boundary and that no ambient global crypto-provider functions are
|
|
124
|
-
used.
|
|
125
|
-
|
|
126
108
|
Variable-length direct primitive inputs are capped at one mebibyte before any
|
|
127
109
|
WASM copy or provider dispatch. Authenticated ciphertext may additionally carry
|
|
128
110
|
the 16-byte tag. HPKE `info` is capped at 65,530 bytes so the fixed five-byte
|
|
@@ -147,7 +129,7 @@ but applications that separately host WASM bytes should use immutable asset
|
|
|
147
129
|
URLs and verify those bytes against a deployment-controlled digest before
|
|
148
130
|
initialization.
|
|
149
131
|
|
|
150
|
-
##
|
|
132
|
+
## Secret buffers
|
|
151
133
|
|
|
152
134
|
Rust-owned secret buffers are zeroized by the Rust implementation and WASM
|
|
153
135
|
adapters. JavaScript `Uint8Array` values are best-effort only: engines, WASM
|
|
@@ -156,20 +138,13 @@ create copies outside the SDK's control. Clear caller-owned byte arrays as soon
|
|
|
156
138
|
as practical:
|
|
157
139
|
|
|
158
140
|
```ts
|
|
141
|
+
import { bestEffortClear } from "@reallyme/crypto";
|
|
142
|
+
|
|
159
143
|
bestEffortClear(secretBytes);
|
|
160
144
|
```
|
|
161
145
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
aliases as `provider-failure` without modifying caller storage. Malformed
|
|
165
|
-
provider-owned secret outputs are cleared before the same typed failure is
|
|
166
|
-
returned.
|
|
167
|
-
|
|
168
|
-
AES-KW provider results must have the exact RFC 3394 `plaintext + 8` or
|
|
169
|
-
`wrapped - 8` length. The facade wipes and rejects a returned typed array whose
|
|
170
|
-
length violates that contract. KMAC keys and customization strings are capped
|
|
171
|
-
at 4 KiB, contexts at 64 KiB, and outputs at 64 KiB before WASM copies are
|
|
172
|
-
created.
|
|
146
|
+
KMAC keys and customization strings are capped at 4 KiB, contexts and outputs
|
|
147
|
+
at 64 KiB.
|
|
173
148
|
|
|
174
149
|
Do not move private keys, passwords, plaintext, shared secrets, or derived keys
|
|
175
150
|
through strings or JSON paths.
|
|
@@ -182,19 +157,16 @@ the strict generated ProtoJSON view only for non-secret hash, verification,
|
|
|
182
157
|
key-generation, encapsulation, and sender-export requests. Both return binary
|
|
183
158
|
`CryptoOperationResponse` bytes, so malformed input, unsupported algorithms,
|
|
184
159
|
and resource-limit failures preserve their structured protobuf branch and
|
|
185
|
-
reason.
|
|
160
|
+
reason.
|
|
186
161
|
|
|
187
162
|
ProtoJSON is request-only. Decode returned binary protobuf with the generated
|
|
188
163
|
exports from `@reallyme/crypto/proto`. Secret-bearing operation selectors are
|
|
189
|
-
rejected before JSON value deserialization and must use protobuf bytes.
|
|
190
|
-
caller-owned `Uint8Array` values after use.
|
|
164
|
+
rejected before JSON value deserialization and must use protobuf bytes.
|
|
191
165
|
|
|
192
166
|
## Documentation
|
|
193
167
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
https://github.com/reallyme/crypto
|
|
168
|
+
See the [provider manifest](https://github.com/reallyme/crypto/blob/main/provider_manifest.json)
|
|
169
|
+
and [wire API](https://github.com/reallyme/crypto/blob/main/docs/protobuf.md).
|
|
198
170
|
|
|
199
171
|
## License
|
|
200
172
|
|
package/dist/aead.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
//
|
|
3
3
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
|
4
4
|
import { ReallyMeCryptoError } from "./errors.js";
|
|
5
|
-
import { ensureByteArrayAtMost, ensureBytes,
|
|
6
|
-
import { requireReallyMeWasmProvider } from "./wasmProvider.js";
|
|
5
|
+
import { ensureByteArrayAtMost, ensureBytes, readIndependentProviderBytes, MAX_CRYPTO_INPUT_LENGTH, } from "./validateBytes.js";
|
|
6
|
+
import { requireReallyMeWasmProvider, requireTrustedReallyMeWasmProvider } from "./wasmProvider.js";
|
|
7
7
|
export const AEAD_KEY_LENGTH = 32;
|
|
8
8
|
export const AES_128_GCM_KEY_LENGTH = 16;
|
|
9
9
|
export const AES_192_GCM_KEY_LENGTH = 24;
|
|
@@ -16,6 +16,7 @@ const aeadSuite = (algorithm) => {
|
|
|
16
16
|
return aeadSuiteWithProvider(algorithm, requireReallyMeWasmProvider());
|
|
17
17
|
};
|
|
18
18
|
const aeadSuiteWithProvider = (algorithm, provider) => {
|
|
19
|
+
requireTrustedReallyMeWasmProvider(provider);
|
|
19
20
|
switch (algorithm) {
|
|
20
21
|
case "AES-128-GCM":
|
|
21
22
|
return {
|
|
@@ -79,17 +80,7 @@ const openWithSuite = (suite, key, nonce, aad, ciphertextWithTag) => {
|
|
|
79
80
|
return requireBytesOutput(suite.open(key, nonce, aad, ciphertextWithTag), ciphertextWithTag.length - AEAD_TAG_LENGTH, [key, nonce, aad, ciphertextWithTag]);
|
|
80
81
|
};
|
|
81
82
|
const requireBytesOutput = (value, expectedLength, inputs) => {
|
|
82
|
-
|
|
83
|
-
throw new ReallyMeCryptoError("provider-failure");
|
|
84
|
-
}
|
|
85
|
-
// Validate ownership before clearing malformed provider output so an alias
|
|
86
|
-
// cannot turn error cleanup into mutation of caller-owned secret material.
|
|
87
|
-
ensureIndependentByteArray(value, inputs);
|
|
88
|
-
if (value.length !== expectedLength) {
|
|
89
|
-
value.fill(0);
|
|
90
|
-
throw new ReallyMeCryptoError("provider-failure");
|
|
91
|
-
}
|
|
92
|
-
return value;
|
|
83
|
+
return readIndependentProviderBytes(value, expectedLength, inputs);
|
|
93
84
|
};
|
|
94
85
|
export const ReallyMeAead = {
|
|
95
86
|
seal(algorithm, key, nonce, aad, plaintext) {
|
package/dist/aesKw.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
//
|
|
3
3
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
|
4
4
|
import { ReallyMeCryptoError } from "./errors.js";
|
|
5
|
-
import { ensureByteArray, ensureBytes,
|
|
6
|
-
import { requireReallyMeWasmProvider } from "./wasmProvider.js";
|
|
5
|
+
import { ensureByteArray, ensureBytes, readIndependentProviderBytes, } from "./validateBytes.js";
|
|
6
|
+
import { requireReallyMeWasmProvider, requireTrustedReallyMeWasmProvider } from "./wasmProvider.js";
|
|
7
7
|
export const AES_128_KW_KEK_LENGTH = 16;
|
|
8
8
|
export const AES_192_KW_KEK_LENGTH = 24;
|
|
9
9
|
export const AES_256_KW_KEK_LENGTH = 32;
|
|
@@ -28,17 +28,7 @@ const validateWrappedKeyLength = (length) => {
|
|
|
28
28
|
}
|
|
29
29
|
};
|
|
30
30
|
const requireBytesOutput = (value, expectedLength, inputs) => {
|
|
31
|
-
|
|
32
|
-
throw new ReallyMeCryptoError("provider-failure");
|
|
33
|
-
}
|
|
34
|
-
// Reject aliases before wiping malformed output. Otherwise a provider could
|
|
35
|
-
// return a caller-owned key/input view and make validation erase that input.
|
|
36
|
-
ensureIndependentByteArray(value, inputs);
|
|
37
|
-
if (value.length !== expectedLength) {
|
|
38
|
-
value.fill(0);
|
|
39
|
-
throw new ReallyMeCryptoError("provider-failure");
|
|
40
|
-
}
|
|
41
|
-
return value;
|
|
31
|
+
return readIndependentProviderBytes(value, expectedLength, inputs);
|
|
42
32
|
};
|
|
43
33
|
const kekLengthForAlgorithm = (algorithm) => {
|
|
44
34
|
switch (algorithm) {
|
|
@@ -77,6 +67,7 @@ const wrapKey = (algorithm, wrappingKey, keyToWrap) => {
|
|
|
77
67
|
return requireBytesOutput(wrapFunctionForAlgorithm(requireReallyMeWasmProvider(), algorithm)(wrappingKey, keyToWrap), keyToWrap.length + AES_KW_INTEGRITY_CHECK_LENGTH, [wrappingKey, keyToWrap]);
|
|
78
68
|
};
|
|
79
69
|
const wrapKeyWithProvider = (algorithm, provider, wrappingKey, keyToWrap) => {
|
|
70
|
+
requireTrustedReallyMeWasmProvider(provider);
|
|
80
71
|
ensureBytes(wrappingKey, kekLengthForAlgorithm(algorithm));
|
|
81
72
|
ensureByteArray(keyToWrap);
|
|
82
73
|
validateKeyDataLength(keyToWrap.length);
|
|
@@ -89,6 +80,7 @@ const unwrapKey = (algorithm, wrappingKey, wrappedKey) => {
|
|
|
89
80
|
return requireBytesOutput(unwrapFunctionForAlgorithm(requireReallyMeWasmProvider(), algorithm)(wrappingKey, wrappedKey), wrappedKey.length - AES_KW_INTEGRITY_CHECK_LENGTH, [wrappingKey, wrappedKey]);
|
|
90
81
|
};
|
|
91
82
|
const unwrapKeyWithProvider = (algorithm, provider, wrappingKey, wrappedKey) => {
|
|
83
|
+
requireTrustedReallyMeWasmProvider(provider);
|
|
92
84
|
ensureBytes(wrappingKey, kekLengthForAlgorithm(algorithm));
|
|
93
85
|
ensureByteArray(wrappedKey);
|
|
94
86
|
validateWrappedKeyLength(wrappedKey.length);
|
package/dist/argon2id.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
//
|
|
3
3
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
|
4
4
|
import { ReallyMeCryptoError } from "./errors.js";
|
|
5
|
-
import { ensureByteArrayAtMost,
|
|
6
|
-
import { requireReallyMeWasmProvider } from "./wasmProvider.js";
|
|
5
|
+
import { ensureByteArrayAtMost, readIndependentProviderBytes, } from "./validateBytes.js";
|
|
6
|
+
import { requireReallyMeWasmProvider, requireTrustedReallyMeWasmProvider } from "./wasmProvider.js";
|
|
7
7
|
export const ARGON2ID_DERIVED_KEY_LENGTH = 32;
|
|
8
8
|
export const ARGON2ID_SALT_MIN_LENGTH = 16;
|
|
9
9
|
export const ARGON2ID_SALT_MAX_LENGTH = 32;
|
|
@@ -29,15 +29,7 @@ const validateSalt = (salt) => {
|
|
|
29
29
|
}
|
|
30
30
|
};
|
|
31
31
|
const requireDerivedKey = (value, inputs) => {
|
|
32
|
-
|
|
33
|
-
throw new ReallyMeCryptoError("provider-failure");
|
|
34
|
-
}
|
|
35
|
-
ensureIndependentByteArray(value, inputs);
|
|
36
|
-
if (value.length !== ARGON2ID_DERIVED_KEY_LENGTH) {
|
|
37
|
-
value.fill(0);
|
|
38
|
-
throw new ReallyMeCryptoError("provider-failure");
|
|
39
|
-
}
|
|
40
|
-
return value;
|
|
32
|
+
return readIndependentProviderBytes(value, ARGON2ID_DERIVED_KEY_LENGTH, inputs);
|
|
41
33
|
};
|
|
42
34
|
export const ReallyMeArgon2id = {
|
|
43
35
|
deriveKey(kdfVersion, secret, salt) {
|
|
@@ -47,6 +39,7 @@ export const ReallyMeArgon2id = {
|
|
|
47
39
|
return requireDerivedKey(requireReallyMeWasmProvider().argon2idDeriveKey(kdfVersion, secret, salt), [secret, salt]);
|
|
48
40
|
},
|
|
49
41
|
deriveKeyWithProvider(provider, kdfVersion, secret, salt) {
|
|
42
|
+
requireTrustedReallyMeWasmProvider(provider);
|
|
50
43
|
validateVersion(kdfVersion);
|
|
51
44
|
validateSecret(secret);
|
|
52
45
|
validateSalt(salt);
|
package/dist/bip340Schnorr.js
CHANGED
|
@@ -9,6 +9,8 @@ export const BIP340_SCHNORR_PUBLIC_KEY_LENGTH = 32;
|
|
|
9
9
|
export const BIP340_SCHNORR_MESSAGE_LENGTH = 32;
|
|
10
10
|
export const BIP340_SCHNORR_AUX_RAND_LENGTH = 32;
|
|
11
11
|
export const BIP340_SCHNORR_SIGNATURE_LENGTH = 64;
|
|
12
|
+
const SEC1_COMPRESSED_PUBLIC_KEY_LENGTH = 33;
|
|
13
|
+
const SEC1_EVEN_Y_PREFIX = 0x02;
|
|
12
14
|
/**
|
|
13
15
|
* BIP-340 Schnorr over secp256k1 backed by @noble/curves.
|
|
14
16
|
*
|
|
@@ -69,6 +71,18 @@ export const ReallyMeBip340Schnorr = {
|
|
|
69
71
|
publicKey.length !== BIP340_SCHNORR_PUBLIC_KEY_LENGTH) {
|
|
70
72
|
throw new ReallyMeCryptoError("invalid-input");
|
|
71
73
|
}
|
|
74
|
+
// An unliftable x-coordinate is an invalid public key, independently of
|
|
75
|
+
// the signature. Noble's verify deliberately folds it into false, so
|
|
76
|
+
// validate it separately to preserve the Rust error classification.
|
|
77
|
+
const compressedKey = new Uint8Array(SEC1_COMPRESSED_PUBLIC_KEY_LENGTH);
|
|
78
|
+
compressedKey[0] = SEC1_EVEN_Y_PREFIX;
|
|
79
|
+
compressedKey.set(publicKey, 1);
|
|
80
|
+
try {
|
|
81
|
+
secp256k1.Point.fromBytes(compressedKey);
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
throw new ReallyMeCryptoError("invalid-input");
|
|
85
|
+
}
|
|
72
86
|
try {
|
|
73
87
|
if (!schnorr.verify(signature, message32, publicKey)) {
|
|
74
88
|
throw new ReallyMeCryptoError("invalid-signature");
|
package/dist/hpke.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
//
|
|
3
3
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
|
4
4
|
import { ReallyMeCryptoError } from "./errors.js";
|
|
5
|
-
import { ensureByteArrayAtMost, ensureBytes,
|
|
6
|
-
import { requireReallyMeWasmProvider } from "./wasmProvider.js";
|
|
5
|
+
import { ensureByteArrayAtMost, ensureBytes, readIndependentProviderBytes, MAX_CRYPTO_INPUT_LENGTH, readIndependentByteArrayProperty, } from "./validateBytes.js";
|
|
6
|
+
import { requireReallyMeWasmProvider, requireTrustedReallyMeWasmProvider } from "./wasmProvider.js";
|
|
7
7
|
export const HPKE_P256_PRIVATE_KEY_LENGTH = 32;
|
|
8
8
|
export const HPKE_P256_PUBLIC_KEY_LENGTH = 65;
|
|
9
9
|
export const HPKE_X25519_PRIVATE_KEY_LENGTH = 32;
|
|
@@ -38,15 +38,7 @@ const readSealedMessage = (value, suite, plaintextLength, inputs) => {
|
|
|
38
38
|
return { encapsulatedKey, ciphertext };
|
|
39
39
|
};
|
|
40
40
|
const requirePlaintext = (value, expectedLength, inputs) => {
|
|
41
|
-
|
|
42
|
-
throw new ReallyMeCryptoError("provider-failure");
|
|
43
|
-
}
|
|
44
|
-
ensureIndependentByteArray(value, inputs);
|
|
45
|
-
if (value.length !== expectedLength) {
|
|
46
|
-
value.fill(0);
|
|
47
|
-
throw new ReallyMeCryptoError("provider-failure");
|
|
48
|
-
}
|
|
49
|
-
return value;
|
|
41
|
+
return readIndependentProviderBytes(value, expectedLength, inputs);
|
|
50
42
|
};
|
|
51
43
|
export const ReallyMeHpke = {
|
|
52
44
|
sealBase(suite, recipientPublicKey, info, aad, plaintext) {
|
|
@@ -58,6 +50,7 @@ export const ReallyMeHpke = {
|
|
|
58
50
|
return readSealedMessage(requireReallyMeWasmProvider().hpkeSealBase(config.id, recipientPublicKey, info, aad, plaintext), config, plaintext.length, [recipientPublicKey, info, aad, plaintext]);
|
|
59
51
|
},
|
|
60
52
|
sealBaseWithProvider(provider, suite, recipientPublicKey, info, aad, plaintext) {
|
|
53
|
+
requireTrustedReallyMeWasmProvider(provider);
|
|
61
54
|
const config = hpkeSuite(suite);
|
|
62
55
|
ensureBytes(recipientPublicKey, config.publicKeyLength);
|
|
63
56
|
ensureByteArrayAtMost(info, HPKE_INFO_MAX_LENGTH);
|
|
@@ -78,6 +71,7 @@ export const ReallyMeHpke = {
|
|
|
78
71
|
return requirePlaintext(requireReallyMeWasmProvider().hpkeOpenBase(config.id, recipientSecretKey, encapsulatedKey, info, aad, ciphertext), ciphertext.length - HPKE_AEAD_TAG_LENGTH, [recipientSecretKey, encapsulatedKey, info, aad, ciphertext]);
|
|
79
72
|
},
|
|
80
73
|
openBaseWithProvider(provider, suite, recipientSecretKey, encapsulatedKey, info, aad, ciphertext) {
|
|
74
|
+
requireTrustedReallyMeWasmProvider(provider);
|
|
81
75
|
const config = hpkeSuite(suite);
|
|
82
76
|
ensureBytes(recipientSecretKey, config.privateKeyLength);
|
|
83
77
|
ensureBytes(encapsulatedKey, config.publicKeyLength);
|
package/dist/jwk.js
CHANGED
|
@@ -87,7 +87,7 @@ const optionalString = (value, name) => {
|
|
|
87
87
|
}
|
|
88
88
|
const descriptor = Object.getOwnPropertyDescriptor(value, name);
|
|
89
89
|
if (descriptor !== undefined &&
|
|
90
|
-
(!("value" in descriptor) || typeof descriptor.value !== "string")) {
|
|
90
|
+
(!("value" in descriptor) || (descriptor.value !== null && typeof descriptor.value !== "string"))) {
|
|
91
91
|
throw new ReallyMeCryptoError("invalid-input");
|
|
92
92
|
}
|
|
93
93
|
};
|
|
@@ -120,7 +120,7 @@ const optionalStringMatches = (value, name, expected) => {
|
|
|
120
120
|
}
|
|
121
121
|
const descriptor = Object.getOwnPropertyDescriptor(value, name);
|
|
122
122
|
if (descriptor !== undefined &&
|
|
123
|
-
(!("value" in descriptor) || descriptor.value !== expected)) {
|
|
123
|
+
(!("value" in descriptor) || (descriptor.value !== null && descriptor.value !== expected))) {
|
|
124
124
|
throw new ReallyMeCryptoError("invalid-input");
|
|
125
125
|
}
|
|
126
126
|
};
|
package/dist/kmac.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
//
|
|
3
3
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
|
4
4
|
import { ReallyMeCryptoError } from "./errors.js";
|
|
5
|
-
import { ensureByteArray,
|
|
6
|
-
import { requireReallyMeWasmProvider } from "./wasmProvider.js";
|
|
5
|
+
import { ensureByteArray, readIndependentProviderBytes, } from "./validateBytes.js";
|
|
6
|
+
import { requireReallyMeWasmProvider, requireTrustedReallyMeWasmProvider } from "./wasmProvider.js";
|
|
7
7
|
export const KMAC256_MIN_KEY_LENGTH = 32;
|
|
8
8
|
export const KMAC256_MAX_KEY_LENGTH = 4_096;
|
|
9
9
|
export const KMAC256_MAX_CONTEXT_LENGTH = 65_536;
|
|
@@ -25,17 +25,7 @@ const validate = (key, context, customization, outputLength) => {
|
|
|
25
25
|
}
|
|
26
26
|
};
|
|
27
27
|
const requireDerivedKey = (value, outputLength, inputs) => {
|
|
28
|
-
|
|
29
|
-
throw new ReallyMeCryptoError("provider-failure");
|
|
30
|
-
}
|
|
31
|
-
// A provider result must have independent ownership. Check overlap before
|
|
32
|
-
// clearing malformed output so validation cannot erase caller-owned input.
|
|
33
|
-
ensureIndependentByteArray(value, inputs);
|
|
34
|
-
if (value.length !== outputLength) {
|
|
35
|
-
value.fill(0);
|
|
36
|
-
throw new ReallyMeCryptoError("provider-failure");
|
|
37
|
-
}
|
|
38
|
-
return value;
|
|
28
|
+
return readIndependentProviderBytes(value, outputLength, inputs);
|
|
39
29
|
};
|
|
40
30
|
export const ReallyMeKmac = {
|
|
41
31
|
deriveKmac256(key, context, customization, outputLength) {
|
|
@@ -43,6 +33,7 @@ export const ReallyMeKmac = {
|
|
|
43
33
|
return requireDerivedKey(requireReallyMeWasmProvider().kmac256Derive(key, context, customization, outputLength), outputLength, [key, context, customization]);
|
|
44
34
|
},
|
|
45
35
|
deriveKmac256WithProvider(provider, key, context, customization, outputLength) {
|
|
36
|
+
requireTrustedReallyMeWasmProvider(provider);
|
|
46
37
|
validate(key, context, customization, outputLength);
|
|
47
38
|
return requireDerivedKey(provider.kmac256Derive(key, context, customization, outputLength), outputLength, [key, context, customization]);
|
|
48
39
|
},
|
package/dist/mlDsa.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
|
4
4
|
import { ReallyMeCryptoError } from "./errors.js";
|
|
5
5
|
import { ensureByteArrayAtMost, ensureBytes, ensureIndependentByteArray, MAX_CRYPTO_INPUT_LENGTH, readIndependentByteArrayProperty, } from "./validateBytes.js";
|
|
6
|
-
import { requireReallyMeWasmProvider } from "./wasmProvider.js";
|
|
6
|
+
import { requireReallyMeWasmProvider, requireTrustedReallyMeWasmProvider } from "./wasmProvider.js";
|
|
7
7
|
export const ML_DSA_44_PUBLIC_KEY_LENGTH = 1_312;
|
|
8
8
|
export const ML_DSA_44_SIGNATURE_LENGTH = 2_420;
|
|
9
9
|
export const ML_DSA_65_PUBLIC_KEY_LENGTH = 1_952;
|
|
@@ -16,6 +16,7 @@ const mlDsaSuite = (algorithm) => {
|
|
|
16
16
|
return mlDsaSuiteWithProvider(algorithm, provider);
|
|
17
17
|
};
|
|
18
18
|
const mlDsaSuiteWithProvider = (algorithm, provider) => {
|
|
19
|
+
requireTrustedReallyMeWasmProvider(provider);
|
|
19
20
|
switch (algorithm) {
|
|
20
21
|
case "ML-DSA-44":
|
|
21
22
|
return {
|
package/dist/mlKem.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
|
4
4
|
import { ReallyMeCryptoError } from "./errors.js";
|
|
5
5
|
import { ensureBytes, readIndependentByteArrayProperty, readIndependentProviderBytes, } from "./validateBytes.js";
|
|
6
|
-
import { requireReallyMeWasmProvider } from "./wasmProvider.js";
|
|
6
|
+
import { requireReallyMeWasmProvider, requireTrustedReallyMeWasmProvider } from "./wasmProvider.js";
|
|
7
7
|
export const ML_KEM_512_PUBLIC_KEY_LENGTH = 800;
|
|
8
8
|
export const ML_KEM_512_CIPHERTEXT_LENGTH = 768;
|
|
9
9
|
export const ML_KEM_768_PUBLIC_KEY_LENGTH = 1_184;
|
|
@@ -17,6 +17,7 @@ const mlKemSuite = (algorithm) => {
|
|
|
17
17
|
return mlKemSuiteWithProvider(algorithm, provider);
|
|
18
18
|
};
|
|
19
19
|
const mlKemSuiteWithProvider = (algorithm, provider) => {
|
|
20
|
+
requireTrustedReallyMeWasmProvider(provider);
|
|
20
21
|
switch (algorithm) {
|
|
21
22
|
case "ML-KEM-512":
|
|
22
23
|
return {
|
|
@@ -1,21 +1,11 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: 2026 ReallyMe Technologies Limited
|
|
2
2
|
//
|
|
3
3
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { requireReallyMeWasmProvider } from "./wasmProvider.js";
|
|
4
|
+
import { ensureByteArray, readIndependentProviderBytesInRange, } from "./validateBytes.js";
|
|
5
|
+
import { requireReallyMeWasmProvider, requireTrustedReallyMeWasmProvider } from "./wasmProvider.js";
|
|
7
6
|
const MAX_CRYPTO_OPERATION_RESPONSE_BYTES = 1_048_608;
|
|
8
7
|
const readOperationResponse = (value, request) => {
|
|
9
|
-
|
|
10
|
-
throw new ReallyMeCryptoError("provider-failure");
|
|
11
|
-
}
|
|
12
|
-
ensureIndependentByteArray(value, [request]);
|
|
13
|
-
if (value.length === 0 ||
|
|
14
|
-
value.length > MAX_CRYPTO_OPERATION_RESPONSE_BYTES) {
|
|
15
|
-
value.fill(0);
|
|
16
|
-
throw new ReallyMeCryptoError("provider-failure");
|
|
17
|
-
}
|
|
18
|
-
return value;
|
|
8
|
+
return readIndependentProviderBytesInRange(value, 1, MAX_CRYPTO_OPERATION_RESPONSE_BYTES, [request]);
|
|
19
9
|
};
|
|
20
10
|
/**
|
|
21
11
|
* Execute one generated binary protobuf request.
|
|
@@ -28,6 +18,7 @@ export const processOperationResponse = (requestBytes) => {
|
|
|
28
18
|
return processOperationResponseWithProvider(requireReallyMeWasmProvider(), requestBytes);
|
|
29
19
|
};
|
|
30
20
|
export const processOperationResponseWithProvider = (provider, requestBytes) => {
|
|
21
|
+
requireTrustedReallyMeWasmProvider(provider);
|
|
31
22
|
ensureByteArray(requestBytes);
|
|
32
23
|
return readOperationResponse(provider.processOperationResponse(requestBytes), requestBytes);
|
|
33
24
|
};
|
|
@@ -41,6 +32,7 @@ export const processOperationResponseJson = (requestJson) => {
|
|
|
41
32
|
return processOperationResponseJsonWithProvider(requireReallyMeWasmProvider(), requestJson);
|
|
42
33
|
};
|
|
43
34
|
export const processOperationResponseJsonWithProvider = (provider, requestJson) => {
|
|
35
|
+
requireTrustedReallyMeWasmProvider(provider);
|
|
44
36
|
ensureByteArray(requestJson);
|
|
45
37
|
return readOperationResponse(provider.processOperationResponseJson(requestJson), requestJson);
|
|
46
38
|
};
|
package/dist/p256Ecdsa.js
CHANGED
|
@@ -6,10 +6,12 @@ import { sha256 } from "@noble/hashes/sha2.js";
|
|
|
6
6
|
import { decodeEcdsaDerSignature, encodeEcdsaDerSignature, } from "./encodeEcdsaDer.js";
|
|
7
7
|
import { ReallyMeCryptoError } from "./errors.js";
|
|
8
8
|
import { ensureByteArray } from "./validateBytes.js";
|
|
9
|
+
import { ensureStandardSec1PublicKey } from "./validateSec1PublicKey.js";
|
|
9
10
|
export const P256_ECDSA_SECRET_KEY_LENGTH = 32;
|
|
10
11
|
export const P256_ECDSA_COMPRESSED_PUBLIC_KEY_LENGTH = 33;
|
|
11
12
|
export const P256_ECDSA_COMPACT_SIGNATURE_LENGTH = 64;
|
|
12
13
|
export const P256_ECDSA_DER_SIGNATURE_MAX_LENGTH = 72;
|
|
14
|
+
const P256_ECDSA_UNCOMPRESSED_PUBLIC_KEY_LENGTH = 65;
|
|
13
15
|
const P256_CURVE_ORDER = Uint8Array.from([
|
|
14
16
|
0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
|
|
15
17
|
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
|
|
@@ -157,10 +159,7 @@ export const ReallyMeP256Ecdsa = {
|
|
|
157
159
|
verify(signature, message, publicKey) {
|
|
158
160
|
ensureByteArray(signature);
|
|
159
161
|
ensureByteArray(message);
|
|
160
|
-
|
|
161
|
-
if (publicKey.length !== P256_ECDSA_COMPRESSED_PUBLIC_KEY_LENGTH) {
|
|
162
|
-
throw new ReallyMeCryptoError("invalid-input");
|
|
163
|
-
}
|
|
162
|
+
ensureStandardSec1PublicKey(publicKey, P256_ECDSA_COMPRESSED_PUBLIC_KEY_LENGTH, P256_ECDSA_UNCOMPRESSED_PUBLIC_KEY_LENGTH);
|
|
164
163
|
let compactSignature;
|
|
165
164
|
try {
|
|
166
165
|
p256.Point.fromBytes(publicKey);
|
package/dist/p384Ecdsa.js
CHANGED
|
@@ -6,10 +6,12 @@ import { sha384 } from "@noble/hashes/sha2.js";
|
|
|
6
6
|
import { decodeEcdsaDerSignature, encodeEcdsaDerSignature, } from "./encodeEcdsaDer.js";
|
|
7
7
|
import { ReallyMeCryptoError } from "./errors.js";
|
|
8
8
|
import { ensureByteArray } from "./validateBytes.js";
|
|
9
|
+
import { ensureStandardSec1PublicKey } from "./validateSec1PublicKey.js";
|
|
9
10
|
export const P384_ECDSA_SECRET_KEY_LENGTH = 48;
|
|
10
11
|
export const P384_ECDSA_COMPRESSED_PUBLIC_KEY_LENGTH = 49;
|
|
11
12
|
export const P384_ECDSA_COMPACT_SIGNATURE_LENGTH = 96;
|
|
12
13
|
export const P384_ECDSA_DER_SIGNATURE_MAX_LENGTH = 104;
|
|
14
|
+
const P384_ECDSA_UNCOMPRESSED_PUBLIC_KEY_LENGTH = 97;
|
|
13
15
|
/**
|
|
14
16
|
* P-384 ECDSA backed by @noble/curves.
|
|
15
17
|
*
|
|
@@ -63,10 +65,7 @@ export const ReallyMeP384Ecdsa = {
|
|
|
63
65
|
verify(signature, message, publicKey) {
|
|
64
66
|
ensureByteArray(signature);
|
|
65
67
|
ensureByteArray(message);
|
|
66
|
-
|
|
67
|
-
if (publicKey.length !== P384_ECDSA_COMPRESSED_PUBLIC_KEY_LENGTH) {
|
|
68
|
-
throw new ReallyMeCryptoError("invalid-input");
|
|
69
|
-
}
|
|
68
|
+
ensureStandardSec1PublicKey(publicKey, P384_ECDSA_COMPRESSED_PUBLIC_KEY_LENGTH, P384_ECDSA_UNCOMPRESSED_PUBLIC_KEY_LENGTH);
|
|
70
69
|
let compactSignature;
|
|
71
70
|
try {
|
|
72
71
|
p384.Point.fromBytes(publicKey);
|
package/dist/p521Ecdsa.js
CHANGED
|
@@ -6,10 +6,12 @@ import { sha512 } from "@noble/hashes/sha2.js";
|
|
|
6
6
|
import { decodeEcdsaDerSignature, encodeEcdsaDerSignature, } from "./encodeEcdsaDer.js";
|
|
7
7
|
import { ReallyMeCryptoError } from "./errors.js";
|
|
8
8
|
import { ensureByteArray } from "./validateBytes.js";
|
|
9
|
+
import { ensureStandardSec1PublicKey } from "./validateSec1PublicKey.js";
|
|
9
10
|
export const P521_ECDSA_SECRET_KEY_LENGTH = 66;
|
|
10
11
|
export const P521_ECDSA_COMPRESSED_PUBLIC_KEY_LENGTH = 67;
|
|
11
12
|
export const P521_ECDSA_COMPACT_SIGNATURE_LENGTH = 132;
|
|
12
13
|
export const P521_ECDSA_DER_SIGNATURE_MAX_LENGTH = 139;
|
|
14
|
+
const P521_ECDSA_UNCOMPRESSED_PUBLIC_KEY_LENGTH = 133;
|
|
13
15
|
/**
|
|
14
16
|
* P-521 ECDSA backed by @noble/curves.
|
|
15
17
|
*
|
|
@@ -63,10 +65,7 @@ export const ReallyMeP521Ecdsa = {
|
|
|
63
65
|
verify(signature, message, publicKey) {
|
|
64
66
|
ensureByteArray(signature);
|
|
65
67
|
ensureByteArray(message);
|
|
66
|
-
|
|
67
|
-
if (publicKey.length !== P521_ECDSA_COMPRESSED_PUBLIC_KEY_LENGTH) {
|
|
68
|
-
throw new ReallyMeCryptoError("invalid-input");
|
|
69
|
-
}
|
|
68
|
+
ensureStandardSec1PublicKey(publicKey, P521_ECDSA_COMPRESSED_PUBLIC_KEY_LENGTH, P521_ECDSA_UNCOMPRESSED_PUBLIC_KEY_LENGTH);
|
|
70
69
|
let compactSignature;
|
|
71
70
|
try {
|
|
72
71
|
p521.Point.fromBytes(publicKey);
|