Skip to content

Commit

Permalink
wip: no_std
Browse files Browse the repository at this point in the history
  • Loading branch information
aep committed Aug 31, 2019
1 parent 781c050 commit c10d34c
Show file tree
Hide file tree
Showing 14 changed files with 24 additions and 9 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ default-resolver = ["chacha20-poly1305-aead", "blake2-rfc", "sha2", "x25519-dale
ring-resolver = ["ring"]
ring-accelerated = ["ring-resolver", "default-resolver"]
vector-tests = []
std = ["subtle/std"]

[[bench]]
name = "benches"
Expand All @@ -34,7 +35,7 @@ appveyor = { repository = "mcginty/snow", branch = "master", service = "github"
[dependencies]
arrayref = "0.3.5"
rand_core = "0.5"
subtle = "2.1"
subtle = { version = "2.1", default-features = false}

# default crypto provider
chacha20-poly1305-aead = { version = "0.1", optional = true }
Expand Down
3 changes: 3 additions & 0 deletions src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ use crate::params::NoiseParams;
use crate::resolvers::CryptoResolver;
use crate::error::{Error, InitStage, Prerequisite};
use subtle::ConstantTimeEq;
use alloc::vec::Vec;
use alloc::boxed::Box;
use alloc::vec;

/// A keypair object returned by [`Builder::generate_keypair()`]
///
Expand Down
1 change: 1 addition & 0 deletions src/cipherstate.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::constants::TAGLEN;
use crate::error::{Error, InitStage, StateProblem};
use crate::types::Cipher;
use alloc::boxed::Box;

pub(crate) struct CipherState {
cipher : Box<dyn Cipher>,
Expand Down
3 changes: 2 additions & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! All error types used by Snow operations.
use std::fmt;
use core::fmt;

/// All errors in snow will include an `ErrorKind`.
#[allow(missing_docs)]
Expand Down Expand Up @@ -126,4 +126,5 @@ impl fmt::Display for Error {
}
}

#[cfg(feature = "std")]
impl std::error::Error for Error {}
3 changes: 2 additions & 1 deletion src/handshakestate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ use crate::params::{HandshakeTokens, MessagePatterns, NoiseParams, Token};
use crate::transportstate::TransportState;
use crate::stateless_transportstate::StatelessTransportState;
use crate::error::{Error, InitStage, StateProblem};
use std::{convert::{TryFrom, TryInto}, fmt};
use core::{convert::{TryFrom, TryInto}, fmt};
use alloc::boxed::Box;

/// A state machine encompassing the handshake phase of a Noise session.
///
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![no_std]
//! The `snow` crate is a straightforward, Hard To Fuck Up™ Noise Protocol implementation.
//!
//! Read the [Noise Protocol Framework Spec](http://noiseprotocol.org/noise.html) for more
Expand Down Expand Up @@ -71,6 +72,7 @@ macro_rules! bail {
return Err(($e).into());
};
}
extern crate alloc;

pub mod error;
mod utils;
Expand Down
6 changes: 4 additions & 2 deletions src/params/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
//! patterns/names)
use crate::error::{Error, PatternProblem};
use std::str::FromStr;
use core::str::FromStr;
use alloc::string::String;
mod patterns;


pub use self::patterns::{
HandshakeChoice,
HandshakeModifier,
Expand Down Expand Up @@ -143,7 +145,7 @@ impl FromStr for NoiseParams {

fn from_str(s: &str) -> Result<Self, Self::Err> {
let mut split = s.split('_');
Ok(NoiseParams::new(s.to_owned(),
Ok(NoiseParams::new(String::from(s),
split.next().ok_or(PatternProblem::TooFewParameters)?.parse()?,
split.next().ok_or(PatternProblem::TooFewParameters)?.parse()?,
split.next().ok_or(PatternProblem::TooFewParameters)?.parse()?,
Expand Down
3 changes: 2 additions & 1 deletion src/params/patterns.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::error::{Error, PatternProblem};
use std::{convert::TryFrom, str::FromStr};
use core::{convert::TryFrom, str::FromStr};
use alloc::{vec, vec::Vec};

/// A small helper macro that behaves similar to the `vec![]` standard macro,
/// except it allocates a bit extra to avoid resizing.
Expand Down
1 change: 1 addition & 0 deletions src/resolvers/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use x25519_dalek as x25519;
use crate::types::{Cipher, Dh, Hash, Random};
use crate::constants::TAGLEN;
use crate::params::{CipherChoice, DHChoice, HashChoice};
use alloc::boxed::Box;
use std::io::{Cursor, Write};
use super::CryptoResolver;

Expand Down
1 change: 1 addition & 0 deletions src/resolvers/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! The wrappers around the default collection of cryptography and entropy providers.
use alloc::boxed::Box;

/// The default primitive resolver.
#[cfg(feature = "default-resolver")] mod default;
Expand Down
2 changes: 1 addition & 1 deletion src/stateless_transportstate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::cipherstate::StatelessCipherStates;
use crate::constants::{MAXDHLEN, MAXMSGLEN, TAGLEN};
use crate::handshakestate::HandshakeState;
use crate::utils::Toggle;
use std::{convert::TryFrom, fmt};
use core::{convert::TryFrom, fmt};

/// A state machine encompassing the transport phase of a Noise session, using the two
/// `CipherState`s (for sending and receiving) that were spawned from the `SymmetricState`'s
Expand Down
1 change: 1 addition & 0 deletions src/symmetricstate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::error::Error;
use crate::constants::{CIPHERKEYLEN, MAXHASHLEN};
use crate::types::Hash;
use crate::cipherstate::CipherState;
use alloc::boxed::Box;

#[derive(Copy, Clone)]
pub(crate) struct SymmetricStateData {
Expand Down
2 changes: 1 addition & 1 deletion src/transportstate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::cipherstate::CipherStates;
use crate::constants::{MAXDHLEN, MAXMSGLEN, TAGLEN};
use crate::utils::Toggle;
use crate::handshakestate::HandshakeState;
use std::{convert::TryFrom, fmt};
use core::{convert::TryFrom, fmt};

/// A state machine encompassing the transport phase of a Noise session, using the two
/// `CipherState`s (for sending and receiving) that were spawned from the `SymmetricState`'s
Expand Down
2 changes: 1 addition & 1 deletion src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::ops::{Deref, DerefMut};
use core::ops::{Deref, DerefMut};

/// Toggle is similar to Option, except that even in the Off/"None" case, there is still
/// an owned allocated inner object. This is useful for holding onto pre-allocated objects
Expand Down

0 comments on commit c10d34c

Please sign in to comment.