reallyme-crypto
ReallyMe Crypto is the Rust facade for a cross-platform cryptography workspace spanning Rust, Swift, Kotlin, Android, and TypeScript. It exposes typed operation owners, explicit provider routing, and the package surfaces used by the native and WASM adapters.
The protobuf schema is the source of truth for executable structured requests,
responses, algorithm identifiers, and wire errors. Generated bindings feed a
single Rust operation boundary. provider_manifest.json fixes the provider
selected for each SDK lane, and positive and negative vectors prove the byte
and failure contract. Missing providers and unsupported algorithms fail closed.
Install
Rust
The Rust crates require Rust 1.96.0 or newer. That MSRV is intentional:
ReallyMe Crypto tracks current stable Rust so the public packages can use the
compiler, dependency, lint, and target support expected by the conformance wall.
When default features are disabled, enable one backend lane and each algorithm surface your crate calls:
= { = "0.3.10", = false, = [
"native",
"ed25519",
"p256",
"secp256k1",
"sha2",
] }
Messaging-focused consumers can use the narrow primitive bundle instead of the default feature set:
= { = "0.3.10", = false, = [
"native",
"messaging-primitives",
] }
messaging-primitives enables only ChaCha20-Poly1305/XChaCha20-Poly1305,
HKDF, HMAC, ML-KEM-768, SHA-2, and X25519. The ML-KEM-768 and X25519 algorithm
features require the typed router, so this bundle also enables dispatch; it
does not enable signer.
Dispatch and signer surfaces are feature-gated by algorithm, so enabling the router does not pull in unrelated primitives unless the matching algorithm feature is also selected.
The native and wasm features select the Rust backend lane. They do not, by
themselves, enable every primitive. Algorithm features such as ed25519,
p256, or sha2 enable the root modules and re-exports. This keeps
no-default consumers from pulling unused cryptography while still forwarding
the selected backend into every enabled primitive crate. The wasm lane is for
wasm32 builds; host builds should use native.
The poseidon2 feature exposes BN254 byte hashing compatible with ReallyMe ZK
through reallyme_crypto::poseidon2::hash_bytes. Its fixed parameters, byte
encoding, and 515-byte input bound are documented in the
reallyme-crypto-poseidon2 crate. This Rust-only primitive is not a structured
operation or SDK provider route.
Some Rust helper APIs are intentionally lane-scoped. P-256 raw scalar import is
available in both native and wasm lanes through
p256::generate_p256_keypair_from_secret_key; it validates an existing private
scalar and is not random key generation. Keystore and protocol boundaries that
already own SHA-256 hashing use p256::sign_p256_digest_der; it accepts exactly
one 32-byte digest, signs that digest without hashing it again, and returns a
deterministic low-S DER signature. p256::verify_p256_digest_der verifies that
same canonical representation. P-384 and P-521 ECDH are available
in both Rust lanes; the Swift, Kotlin, and TypeScript facades expose their
manifest-declared provider-backed P-384/P-521 ECDH surfaces.
For standalone X25519 and secp256k1 random key generation, prefer
try_generate_x25519_keypair and try_generate_secp256k1_keypair. These
return typed errors when operating-system entropy is unavailable. The legacy
infallible functions remain for compatibility; the dispatch API uses the
fallible path.
The Swift package also includes a P-256 ECDH Secure Enclave / Keychain API for applications that need non-exportable private-key residency, such as JOSE/JWE decryption with platform-held keys. That API uses explicit handles and is separate from raw private-key bytes.
Examples
Fixed keys, nonces, and auxiliary randomness below are public test fixtures. Applications must supply secret keys and enforce nonce uniqueness for each AEAD key; never use these fixed values to protect real data.
// This example requires the `ed25519` feature.
#
#
#
#
BIP-340 uses an x-only secp256k1 public key and requires callers to provide a 32-byte message representative and 32 bytes of auxiliary randomness explicitly:
// This example requires the `secp256k1` feature.
#
#
#
#
Hashing is owned by the semantic operation layer. Adapters should call this surface instead of selecting a primitive independently:
// This example requires the `sha2` feature.
#
#
#
#
HMAC authentication and fail-closed verification share the same semantic operation owner across Rust, structured protobuf, and C ABI adapters:
// This example requires the `hmac` feature.
#
#
#
#
Authenticated encryption uses the same operation owner for algorithm selection, typed failures, and zeroizing recovered plaintext:
// This example requires the `aes` feature.
#
#
#
#
MLS and HPKE derive nonces from their protocol key schedules. The focused AES-256-GCM facade therefore accepts an explicit typed nonce and deliberately does not offer a random-nonce overload:
// This example requires the `aes` feature.
#
#
#
#
The HPKE facade exposes explicit registry identifiers and derives its nonce internally; seal/open requests have no caller-supplied nonce field:
// This example requires the `hpke` and `native` features.
#
#
#
#
AES-KW uses the operation owner for suite selection and returns unwrapped key material in a zeroizing owner:
// This example requires the `aes-kw` feature.
#
#
#
#
Signature verification fails closed: an invalid signature returns an error rather than a boolean that can be accidentally ignored.
Protobuf
Enable operation-response to use
reallyme_crypto::operation_contract::process_operation_response(request_bytes).
It accepts an encoded CryptoOperationRequest and returns binary
CryptoOperationResponse bytes containing a typed result or error. The
ProtoJSON entrypoint accepts only non-secret request selectors and still returns
binary protobuf. Secret-bearing operations must use binary protobuf.
See the protobuf contract for schemas, generated SDK adapters, limits, and JSON restrictions.
Documentation
See the repository overview for the complete algorithm list and other SDKs. The provider policy, memory model, and conformance instructions define the shared guarantees and validation requirements.
License
Licensed under either the MIT License or the Apache License, Version 2.0, at your option. See LICENSE. Third-party components retain their own licenses and notices.