Vitamin C is like vitamins for your Rust code, especially code dealing with cryptography and managing sensitive data. It is actually a suite of crates that you can use individually or via this top-level crate via features.
Vitamin C is in active development and aims to address the following:
-
Misuse Resistance: it aims to make it difficult to write code that is insecure.
-
Verified: be verified using formal methods and testing and selects dependencies that are verified.
-
Vetted: be vetted by security experts and selects dependencies that are vetted.
-
Minimal: be minimal and only include what is necessary.
-
Consistent: have a consistent interface with everything in one place.
-
Compatible: support native and WebAssembly applications, with embedded (
no_std) support as a future goal. All crates currently requirestd. -
Fast: speed and security can be friends!
| I want to… | Start with |
|---|---|
| Encrypt and decrypt Rust values with AES-256-GCM | vitaminc-encrypt |
| Keep sensitive values out of debug output and wipe them on drop | vitaminc-protected |
| Generate cryptographic randomness | vitaminc-random |
| Describe structured values or implement an encryption backend | vitaminc-aead, with vitaminc-context for associated data |
| Derive pseudorandom values or equality-index terms | vitaminc-prf for the interfaces, vitaminc-hmac for HMAC-SHA256, and vitaminc-normalize for equality encodings |
| Integrate an order-revealing encryption scheme | vitaminc-ore for terms and scheme interfaces; supply an ORE backend |
| Implement a hash/MAC adapter, including a remote provider | vitaminc-traits and vitaminc-async-traits; vitaminc-kms supplies AWS KMS HMAC |
| Exchange encoded values across a language boundary, or store versioned blobs | vitaminc-aead-frame; read its storage contract before persisting data |
| Build a native Node.js addon | vitaminc-aead-napi; this is a Rust library for addons, not an npm package |
The facade's features expose most of these crates. vitaminc-aead-frame and
vitaminc-aead-napi are direct dependencies. Indexes reveal information about
values; read the normalization and ORE guides before choosing an index.
You can install the top-level vitaminc crate and enable specific features:
cargo add vitaminc --features protected,random
Or, if you only need a specific capability, you can install a crate directly:
cargo add vitaminc-protected
With the protected feature enabled, keep a value in a Protected wrapper
to redact its debug output and wipe its contents when it is dropped:
use vitaminc::protected::{Controlled, Protected};
let mut token = Protected::new(String::from("example-token"));
token.update(|value| value.push_str("-updated"));
let debug = format!("{token:?}");
assert!(debug.contains("***"));
assert!(!debug.contains("example-token"));The minimum supported Rust version (MSRV) is 1.88.0, except for
vitaminc-kms, which requires 1.94.1. Enabling the facade's aws-kms
feature raises its requirement to 1.94.1 too.
MSRV increases require a minor release (for example, 0.8 to 0.9) and must be called out in release notes. Patch releases retain the existing floor.
All crates require std; there is no no_std configuration yet. Supported
targets include native builds, vitaminc-encrypt on wasm32-unknown-unknown,
and the separate encryption guest on wasm32-wasip1. JavaScript WASM hosts need Web
Crypto and the generated bindings described in the
encryption setup guide.
The KMS adapter and Node addon bindings target native applications.
License: MIT. vitaminc-ore also includes Unicode-licensed data and declares
MIT AND Unicode-3.0; see its license files.
The facade enables no features by default. Each feature exposes the named crate. Some also enable supporting facade features:
| Feature | Also enables |
|---|---|
context, permutation |
protected |
prf |
context |
hmac |
prf |
async-traits, aws-kms |
traits |
aead |
context |
encrypt |
traits, aead |
normalize |
aead; also PRF normalization if prf is enabled |
ore |
normalize |
These dependencies apply transitively. normalize alone does not enable
prf. For options such as hlist, chrono, or bitvec, add the relevant
crate directly and enable its feature; the facade does not forward them.
| Feature | Source | Crates.io | Documentation |
|---|---|---|---|
aead |
vitaminc-aead |
||
| Direct dependency | vitaminc-aead-frame |
||
| Direct dependency | vitaminc-aead-napi |
||
async-traits |
vitaminc-async-traits |
||
context |
vitaminc-context |
||
encrypt |
vitaminc-encrypt |
||
hmac |
vitaminc-hmac |
||
normalize |
vitaminc-normalize |
||
ore |
vitaminc-ore |
||
aws-kms |
vitaminc-kms |
||
| —¹ | vitaminc-password |
||
permutation |
vitaminc-permutation |
||
prf |
vitaminc-prf |
||
protected |
vitaminc-protected |
||
random |
vitaminc-random |
||
traits |
vitaminc-traits |
¹ vitaminc-password is not currently exposed as a vitaminc facade feature — depend on the crate directly.