Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 51 additions & 33 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[workspace]
resolver = "2"
members = [
"nucypher-core",
"nucypher-core-python",
Expand Down
2 changes: 1 addition & 1 deletion nucypher-core-wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ default = ["console_error_panic_hook"]
umbral-pre = { version = "0.11.0", features = ["bindings-wasm"] }
ferveo = { package = "ferveo-pre-release", version = "0.3.0", features = ["bindings-wasm"] }
nucypher-core = { path = "../nucypher-core" }
wasm-bindgen = "0.2.86"
wasm-bindgen = "0.2.88"
js-sys = "0.3.63"
console_error_panic_hook = { version = "0.1", optional = true }
derive_more = { version = "0.99", default-features = false, features = ["from", "as_ref"] }
Expand Down
3 changes: 3 additions & 0 deletions nucypher-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ zeroize = { version = "1.6.0", features = ["derive"] }
rand_core = "0.6.4"
rand_chacha = "0.3.1"
rand = "0.8.5"

[dev-dependencies]
serde_json = "1.0.140"
13 changes: 13 additions & 0 deletions nucypher-core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,19 @@ Bindings for several languages are available:
* [JavaScript](https://github.com/nucypher/nucypher-core/tree/main/nucypher-core-wasm) (WASM-based)
* [Python](https://github.com/nucypher/nucypher-core/tree/main/nucypher-core-python)

## Cross-Implementation Testing

This library tests generate test vectors for ensuring compatibility between different implementations. The test vector generators automatically produce JSON files in both the Rust project and the TypeScript project.

### Setting Custom Path for TypeScript Test Vectors

By default, the test vector generators will look for the TypeScript project at a relative path. If your project structure is different, you can customize the TypeScript project path using an environment variable:

```bash
# Generate shared secret test vectors with custom TypeScript project path
TS_PROJECT_TEST_VECTORS_PATH=/path/to/taco-web/packages/shared/test/fixtures/ cargo test -p nucypher-core --test generate_shared_secret_vectors
```

[crate-image]: https://img.shields.io/crates/v/nucypher-core.svg
[crate-link]: https://crates.io/crates/nucypher-core
[docs-image]: https://docs.rs/nucypher-core/badge.svg
Expand Down
35 changes: 33 additions & 2 deletions nucypher-core/src/dkg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ impl fmt::Display for DecryptionError {

type NonceSize = <ChaCha20Poly1305 as AeadCore>::NonceSize;

fn encrypt_with_shared_secret(
/// Encrypt data using the provided shared secret.
///
/// The ciphertext consists of a randomly generated nonce followed by the encrypted data.
pub fn encrypt_with_shared_secret(
shared_secret: &SessionSharedSecret,
plaintext: &[u8],
) -> Result<Box<[u8]>, EncryptionError> {
Expand All @@ -79,7 +82,10 @@ fn encrypt_with_shared_secret(
Ok(result.into_boxed_slice())
}

fn decrypt_with_shared_secret(
/// Decrypt data using the provided shared secret.
///
/// The ciphertext is expected to start with a nonce, followed by the encrypted data.
pub fn decrypt_with_shared_secret(
shared_secret: &SessionSharedSecret,
ciphertext: &[u8],
) -> Result<Box<[u8]>, DecryptionError> {
Expand Down Expand Up @@ -138,6 +144,31 @@ pub mod session {
Self { derived_bytes }
}

/// Create a shared secret directly from raw bytes for testing purposes.
///
/// This bypasses the normal key derivation process and should only be used for
/// testing with known byte vectors.
#[cfg(test)]
pub fn from_bytes(bytes: &[u8]) -> Self {
let mut array = [0u8; 32];
array.copy_from_slice(&bytes[0..32]);
Self {
derived_bytes: array,
}
}

/// Create a shared secret directly from raw bytes for test vectors.
///
/// This is a public API only intended for use in test vectors. It bypasses
/// the normal key derivation process to allow for deterministic tests.
pub fn from_test_vector(bytes: &[u8]) -> Self {
let mut array = [0u8; 32];
array.copy_from_slice(&bytes[0..32]);
Self {
derived_bytes: array,
}
}

/// View this shared secret as a byte array.
pub fn as_bytes(&self) -> &[u8; 32] {
&self.derived_bytes
Expand Down
1 change: 1 addition & 0 deletions nucypher-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pub use access_control::{encrypt_for_dkg, AccessControlPolicy, AuthenticatedData
pub use address::Address;
pub use conditions::{Conditions, Context};
pub use dkg::{
decrypt_with_shared_secret, encrypt_with_shared_secret,
session::{SessionSecretFactory, SessionSharedSecret, SessionStaticKey, SessionStaticSecret},
DecryptionError, EncryptedThresholdDecryptionRequest, EncryptedThresholdDecryptionResponse,
EncryptionError, ThresholdDecryptionRequest, ThresholdDecryptionResponse,
Expand Down
Loading
Loading