diff --git a/Cargo.toml b/Cargo.toml index 4ac4d61..030ea21 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "double-ratchet-2" -version = "0.1.0" +version = "0.1.1" edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -11,7 +11,8 @@ rand_core = "0.5" hkdf = "0.11.0" hmac = "0.11.0" aes-gcm-siv = {version = "0.10.0"} -ring-compat = {version = "0.2.1", features = ["digest"]} +ring-compat = {version = "0.2.1", optional = true, features = ["digest"]} +sha2 = {version = "0.9.5", optional = true} serde = {version = "1.0.125", default-features = false, features = ["derive"]} serde_bytes = "0.11.5" bincode = "1.3.3" @@ -19,4 +20,8 @@ hashbrown = "0.11.2" [profile.release] lto = true -opt-level = 3 \ No newline at end of file +opt-level = 3 + +[features] +default = ["sha2"] +ring = ["ring-compat/digest"] \ No newline at end of file diff --git a/src/kdf_chain.rs b/src/kdf_chain.rs index 181ef94..7e41995 100644 --- a/src/kdf_chain.rs +++ b/src/kdf_chain.rs @@ -1,5 +1,11 @@ use hmac::{Hmac, Mac, NewMac}; + +#[cfg(feature = "ring")] use ring_compat::digest::Sha512; + +#[cfg(feature = "default")] +use sha2::Sha512; + use core::convert::TryInto; #[cfg(test)] diff --git a/src/kdf_root.rs b/src/kdf_root.rs index b08b8f4..cc971f3 100644 --- a/src/kdf_root.rs +++ b/src/kdf_root.rs @@ -1,6 +1,12 @@ use x25519_dalek::SharedSecret; use hkdf::Hkdf; + +#[cfg(feature = "ring")] use ring_compat::digest::Sha512; + +#[cfg(feature = "default")] +use sha2::Sha512; + use core::convert::TryInto; #[cfg(test)] diff --git a/src/lib.rs b/src/lib.rs index ddacdac..741fdd9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,5 @@ #![no_std] #![allow(stable_features)] -#![feature(alloc)] extern crate alloc; @@ -8,5 +7,9 @@ mod aead; mod dh; mod kdf_root; mod kdf_chain; -mod header; + +/// Providing essential functions pub mod ratchet; + +/// Message Header +pub mod header; diff --git a/src/ratchet.rs b/src/ratchet.rs index 50e0ae4..fb54f8d 100644 --- a/src/ratchet.rs +++ b/src/ratchet.rs @@ -9,6 +9,7 @@ use crate::aead::{encrypt, decrypt}; const MAX_SKIP: usize = 100; +/// Object Representing Ratchet pub struct Ratchet { dhs: DhKeyPair, dhr: Option, diff --git a/tests/mod.rs b/tests/mod.rs index 26f54a4..3dbd3db 100644 --- a/tests/mod.rs +++ b/tests/mod.rs @@ -36,9 +36,9 @@ fn ratchet_enc_skip() { #[should_panic] fn ratchet_panic_bob() { let sk = [1; 32]; - let (mut bob_ratchet, public_key) = Ratchet::init_bob(sk); + let (mut bob_ratchet, _) = Ratchet::init_bob(sk); let data = include_bytes!("../src/header.rs").to_vec(); - let (header, encrypted) = bob_ratchet.ratchet_encrypt(&data); + let (_, _) = bob_ratchet.ratchet_encrypt(&data); } #[test]