Made ring optional

This commit is contained in:
Hannes 2021-05-13 16:41:09 +02:00
parent b65f9c8afd
commit f6ab3e10af
6 changed files with 28 additions and 7 deletions

View file

@ -1,6 +1,6 @@
[package] [package]
name = "double-ratchet-2" name = "double-ratchet-2"
version = "0.1.0" version = "0.1.1"
edition = "2018" edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # 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" hkdf = "0.11.0"
hmac = "0.11.0" hmac = "0.11.0"
aes-gcm-siv = {version = "0.10.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 = {version = "1.0.125", default-features = false, features = ["derive"]}
serde_bytes = "0.11.5" serde_bytes = "0.11.5"
bincode = "1.3.3" bincode = "1.3.3"
@ -20,3 +21,7 @@ hashbrown = "0.11.2"
[profile.release] [profile.release]
lto = true lto = true
opt-level = 3 opt-level = 3
[features]
default = ["sha2"]
ring = ["ring-compat/digest"]

View file

@ -1,5 +1,11 @@
use hmac::{Hmac, Mac, NewMac}; use hmac::{Hmac, Mac, NewMac};
#[cfg(feature = "ring")]
use ring_compat::digest::Sha512; use ring_compat::digest::Sha512;
#[cfg(feature = "default")]
use sha2::Sha512;
use core::convert::TryInto; use core::convert::TryInto;
#[cfg(test)] #[cfg(test)]

View file

@ -1,6 +1,12 @@
use x25519_dalek::SharedSecret; use x25519_dalek::SharedSecret;
use hkdf::Hkdf; use hkdf::Hkdf;
#[cfg(feature = "ring")]
use ring_compat::digest::Sha512; use ring_compat::digest::Sha512;
#[cfg(feature = "default")]
use sha2::Sha512;
use core::convert::TryInto; use core::convert::TryInto;
#[cfg(test)] #[cfg(test)]

View file

@ -1,6 +1,5 @@
#![no_std] #![no_std]
#![allow(stable_features)] #![allow(stable_features)]
#![feature(alloc)]
extern crate alloc; extern crate alloc;
@ -8,5 +7,9 @@ mod aead;
mod dh; mod dh;
mod kdf_root; mod kdf_root;
mod kdf_chain; mod kdf_chain;
mod header;
/// Providing essential functions
pub mod ratchet; pub mod ratchet;
/// Message Header
pub mod header;

View file

@ -9,6 +9,7 @@ use crate::aead::{encrypt, decrypt};
const MAX_SKIP: usize = 100; const MAX_SKIP: usize = 100;
/// Object Representing Ratchet
pub struct Ratchet { pub struct Ratchet {
dhs: DhKeyPair, dhs: DhKeyPair,
dhr: Option<PublicKey>, dhr: Option<PublicKey>,

View file

@ -36,9 +36,9 @@ fn ratchet_enc_skip() {
#[should_panic] #[should_panic]
fn ratchet_panic_bob() { fn ratchet_panic_bob() {
let sk = [1; 32]; 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 data = include_bytes!("../src/header.rs").to_vec();
let (header, encrypted) = bob_ratchet.ratchet_encrypt(&data); let (_, _) = bob_ratchet.ratchet_encrypt(&data);
} }
#[test] #[test]