Skip to content
This repository has been archived by the owner on Jan 14, 2025. It is now read-only.

Commit

Permalink
switch to chachapoly and hacl-star
Browse files Browse the repository at this point in the history
  • Loading branch information
aep committed Sep 27, 2018
1 parent 91092e8 commit bfbdfaa
Show file tree
Hide file tree
Showing 7 changed files with 267 additions and 382 deletions.
543 changes: 183 additions & 360 deletions Cargo.lock

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@ members = [
"cli",
"build",
"build-core",
"web",
"wsx",
"broker",
]


[profile.release]
lto = true


[patch.crates-io]
failure = {git = "https://github.com/aep/failure.git"}
hacl-star-sys = {git= "https://github.com/quininer/rust-hacl-star.git", branch="fix32"}

8 changes: 5 additions & 3 deletions binrelease.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ THIS=$(dirname $(readlink -f $0))
set -ex


VER=0.4.0
VER=0.4.1

rm -rf target/binrelease
mkdir -p target/binrelease
Expand All @@ -22,7 +22,7 @@ b(){

if $staticpie
then
export RUSTFLAGS="$RUSTFLAGS -C linker=/opt/toolchains/$gcctarget/bin/${gcctarget}-rustcc -C link-arg=-static -C link-arg=-pie"
export RUSTFLAGS="$RUSTFLAGS -C linker=rust-musl-cc -C link-arg=-static -C link-arg=-pie"
else
export RUSTFLAGS="$RUSTFLAGS -C linker=/opt/toolchains/$gcctarget/bin/${gcctarget}-gcc"
fi
Expand All @@ -34,9 +34,11 @@ b(){
}

#b staticpie name rust-target gcc-target
b false mipsel-linux-musleabi mipsel-unknown-linux-musl mipsel-linux-musleabi
b false mips-linux-musleabi mips-unknown-linux-musl mips-linux-musleabi
b false arm-linux-gnueabihf armv7-unknown-linux-gnueabihf arm-linux-gnueabihf
b false arm-linux-androideabi armv7-linux-androideabi arm-linux-androideabi
b true x86_64-linux-musl x86_64-unknown-linux-musl x86_64-linux-musl
b true x86_64-linux x86_64-unknown-linux-musl x86_64-linux-musl



3 changes: 0 additions & 3 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,5 @@ default-features = false
name = "carrier"
path = "src/main.rs"

[patch.crates-io]
failure = {git = "https://github.com/aep/failure.git"}

[build-dependencies]
cc = "1.0"
11 changes: 5 additions & 6 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,14 @@ wasm-bindgen = {optional = true, git = "https://github.com/rustwasm/wasm-
hpack = "0.3.0"

[dependencies.snow]
version = "0.4.0-alpha2"
#git = "https://github.com/aep/snow.git"
path = "../../snow/"
branch = "wasm"
version = "0.4.0"
default-features = false
features = ["hacl-star-resolver"]

[features]
default = ["snow/default-resolver"]
web = ["rand/wasm-bindgen", "snow/wasm-resolver", "clear_on_drop/nightly", "wasm-bindgen"]
web = ["rand/wasm-bindgen", "clear_on_drop/nightly", "wasm-bindgen"]

[build-dependencies]
carrier-build-core = {path = "../build-core"}


2 changes: 1 addition & 1 deletion core/src/identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use clear_on_drop::ClearOnDrop;
use crc8;
use ed25519_dalek;
use failure::Error;
use rand::{self, RngCore};
use rand::{RngCore};
use sha2;
use std::fmt;
use std::str::FromStr;
Expand Down
75 changes: 67 additions & 8 deletions core/src/noise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use failure::Error;
use identity::{Identity, Signature, Secret, Address};
use packet::{self, RoutingDirection, RoutingKey};
use snow::{self, params::NoiseParams, Builder};
use snow::resolvers::{FallbackResolver, CryptoResolver};
use std::io::Write;
use std::io::Read;

Expand Down Expand Up @@ -305,15 +306,15 @@ pub fn initiate(
timestamp: u64,
) -> Result<(HandshakeRequester, packet::EncryptedPacket), Error> {
let mut noise = if let Some(remote_static) = remote_static {
let params: NoiseParams = "Noise_NK_25519_AESGCM_SHA256".parse().unwrap();
Builder::new(params)
let params: NoiseParams = "Noise_NK_25519_ChaChaPoly_SHA256".parse().unwrap();
new_noise_builder(params)
.remote_public_key(remote_static.as_bytes())
.prologue("carrier has arrived".as_bytes())
.build_initiator()
.expect("building noise session")
} else {
let params: NoiseParams = "Noise_NN_25519_AESGCM_SHA256".parse().unwrap();
Builder::new(params)
let params: NoiseParams = "Noise_NN_25519_ChaChaPoly_SHA256".parse().unwrap();
new_noise_builder(params)
.prologue("carrier has arrived".as_bytes())
.build_initiator()
.expect("building noise session")
Expand Down Expand Up @@ -357,15 +358,15 @@ pub fn respond(
) -> Result<(HandshakeResponder, Identity, u64), Error> {

let mut noise = if let Some(xsecret) = xsecret{
let params: NoiseParams = "Noise_NK_25519_AESGCM_SHA256".parse().unwrap();
Builder::new(params)
let params: NoiseParams = "Noise_NK_25519_ChaChaPoly_SHA256".parse().unwrap();
new_noise_builder(params)
.local_private_key(xsecret.as_bytes())
.prologue("carrier has arrived".as_bytes())
.build_responder()
.expect("building noise session")
} else {
let params: NoiseParams = "Noise_NN_25519_AESGCM_SHA256".parse().unwrap();
Builder::new(params)
let params: NoiseParams = "Noise_NN_25519_ChaChaPoly_SHA256".parse().unwrap();
new_noise_builder(params)
.prologue("carrier has arrived".as_bytes())
.build_responder()
.expect("building noise session")
Expand All @@ -383,6 +384,64 @@ pub fn respond(
))
}




#[derive(Default)]
struct RandResolver {
}

use rand::{RngCore};
use rand::rngs::{OsRng};

struct RandomOs {
rng : OsRng
}

impl Default for RandomOs {
fn default() -> RandomOs {
RandomOs {rng: OsRng::new().unwrap()}
}
}

impl snow::types::Random for RandomOs {
fn fill_bytes(&mut self, out: &mut [u8]) {
self.rng.fill_bytes(out);
}
}

impl CryptoResolver for RandResolver {
fn resolve_rng(&self) -> Option<Box<snow::types::Random>> {
Some(Box::new(RandomOs::default()))
}

fn resolve_dh (&self, _ : &snow::params::DHChoice)
-> Option<Box<(dyn snow::types::Dh + 'static)>>
{
None
}

fn resolve_hash(&self, _ : &snow::params::HashChoice)
-> Option<Box<(dyn snow::types::Hash + 'static)>>
{
None
}

fn resolve_cipher(&self, _:&snow::params::CipherChoice)
-> Option<Box<(dyn snow::types::Cipher + 'static)>>
{
None
}
}

fn new_noise_builder<'builder>(params: NoiseParams) -> Builder<'builder> {
Builder::with_resolver(params, Box::new(
FallbackResolver::new(
Box::new(snow::resolvers::HaclStarResolver::default()),
Box::new(RandResolver::default()),
)))
}

/*
#[test]
Expand Down

0 comments on commit bfbdfaa

Please sign in to comment.