Skip to content

Commit

Permalink
support no_std
Browse files Browse the repository at this point in the history
  • Loading branch information
soralit committed Mar 28, 2023
1 parent 5a14675 commit 74fe12f
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 10 deletions.
6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ categories = [ "cryptography" ]

[dependencies]
cryptoxide = "0.4"
zeroize = "1.6.0"

[features]
default = []
with-bench = []
default = ["std"]
std = []
with-bench = []
1 change: 1 addition & 0 deletions rust-toolchain
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nightly
3 changes: 3 additions & 0 deletions src/derivation/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#[cfg(not(feature = "std"))]
use core as std;

mod common;
pub mod v2;

Expand Down
6 changes: 6 additions & 0 deletions src/hex.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
#[cfg(not(feature = "std"))]
use alloc::string::String;

#[cfg(not(feature = "std"))]
use alloc::vec::Vec;

const ALPHABET: &'static [u8] = b"0123456789abcdef";

pub fn encode(input: &[u8]) -> String {
Expand Down
3 changes: 3 additions & 0 deletions src/key.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#[cfg(not(feature = "std"))]
use core as std;

use std::fmt;

use cryptoxide::constant_time::CtEqual;
Expand Down
10 changes: 9 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,20 @@
//! In soft derivation, the important property is that given the parent public key,
//! one can derive all softly derived children public key.
#![cfg_attr(feature = "with-bench", feature(test))]
#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(not(feature = "std"), feature(error_in_core))]

#![cfg_attr(feature = "with-bench", feature(test))]
#[cfg(test)]
#[cfg(feature = "with-bench")]
extern crate test;

#[cfg(not(feature = "std"))]
extern crate alloc;

#[cfg(not(feature = "std"))]
extern crate core;

mod derivation;
mod hex;
mod key;
Expand Down
10 changes: 3 additions & 7 deletions src/securemem.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
use zeroize::Zeroize;

pub fn zero(to_zero: &mut [u8]) {
// the unsafety of this call is bounded to the existence of the pointer
// and the accuracy of the length of the array.
//
// since to_zero existence is bound to live at least as long as the call
// of this function and that we use the length (in bytes) of the given
// slice, this call is safe.
unsafe { ::std::ptr::write_bytes(to_zero.as_mut_ptr(), 0, to_zero.len()) }
to_zero.zeroize()
}
3 changes: 3 additions & 0 deletions src/signature.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#[cfg(not(feature = "std"))]
use core as std;

use super::hex;
use std::error::Error;
use std::fmt;
Expand Down

0 comments on commit 74fe12f

Please sign in to comment.