diff --git a/build.rs b/build.rs index cce31f2..e981555 100644 --- a/build.rs +++ b/build.rs @@ -12,8 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -extern crate openssl; - use openssl::asn1; use openssl::ec; use openssl::nid::Nid; diff --git a/examples/crypto_bench.rs b/examples/crypto_bench.rs index ff92ba2..0410140 100644 --- a/examples/crypto_bench.rs +++ b/examples/crypto_bench.rs @@ -14,12 +14,10 @@ #![no_std] -#[macro_use] extern crate alloc; -extern crate crypto; extern crate lang_items; -extern crate libtock_drivers; +use alloc::format; use alloc::vec::Vec; use core::fmt::Write; use crypto::{ diff --git a/examples/oom_test.rs b/examples/oom_test.rs index 665993b..a7074e8 100644 --- a/examples/oom_test.rs +++ b/examples/oom_test.rs @@ -15,9 +15,7 @@ #![no_std] extern crate alloc; -extern crate crypto; extern crate lang_items; -extern crate libtock_drivers; use alloc::vec::Vec; use core::fmt::Write; diff --git a/examples/panic_test.rs b/examples/panic_test.rs index 71c70b0..e646149 100644 --- a/examples/panic_test.rs +++ b/examples/panic_test.rs @@ -14,10 +14,7 @@ #![no_std] -extern crate alloc; -extern crate crypto; extern crate lang_items; -extern crate libtock_drivers; fn main() { panic!("Bye world!") diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml index ce96d47..d9e4216 100644 --- a/fuzz/Cargo.toml +++ b/fuzz/Cargo.toml @@ -13,11 +13,9 @@ libfuzzer-sys = { version = "0.3"} arrayref = "0.3.6" libtock_drivers = { path = "../third_party/libtock-drivers" } crypto = { path = "../libraries/crypto", features = ['std'] } -cbor = { path = "../libraries/cbor" } - -[dependencies.ctap2] -path = ".." -features = ['std', 'ram_storage'] +cbor = { path = "../libraries/cbor", features = ['std'] } +ctap2 = { path = "..", features = ['std', 'ram_storage'] } +lang_items = { path = "../third_party/lang-items", features = ['std'] } # Prevent this from interfering with workspaces [workspace] diff --git a/fuzz/fuzz_targets/fuzz_target_split_assemble.rs b/fuzz/fuzz_targets/fuzz_target_split_assemble.rs index c655e84..6dc42f0 100644 --- a/fuzz/fuzz_targets/fuzz_target_split_assemble.rs +++ b/fuzz/fuzz_targets/fuzz_target_split_assemble.rs @@ -1,10 +1,10 @@ #![no_main] -extern crate ctap2; -extern crate libtock_drivers; -#[macro_use] -extern crate arrayref; +// This explicit "extern crate" is needed to make the linker aware of the +// `libtock_alloc_init` symbol. +extern crate lang_items; +use arrayref::array_ref; use ctap2::ctap::hid::receive::MessageAssembler; use ctap2::ctap::hid::send::HidPacketIterator; use ctap2::ctap::hid::{HidPacket, Message}; diff --git a/libraries/cbor/fuzz/fuzz_targets/fuzz_target_cbor.rs b/libraries/cbor/fuzz/fuzz_targets/fuzz_target_cbor.rs index fe7a5a2..2f7e870 100644 --- a/libraries/cbor/fuzz/fuzz_targets/fuzz_target_cbor.rs +++ b/libraries/cbor/fuzz/fuzz_targets/fuzz_target_cbor.rs @@ -1,10 +1,8 @@ #![no_main] -#[macro_use] -extern crate libfuzzer_sys; extern crate alloc; -extern crate cbor; use alloc::vec::Vec; +use libfuzzer_sys::fuzz_target; fuzz_target!(|data: &[u8]| { if let Ok(value) = cbor::read(data) { diff --git a/libraries/cbor/src/lib.rs b/libraries/cbor/src/lib.rs index 00a9c55..0a128fc 100644 --- a/libraries/cbor/src/lib.rs +++ b/libraries/cbor/src/lib.rs @@ -18,7 +18,6 @@ extern crate alloc; #[cfg(feature = "std")] extern crate core; -#[macro_use] pub mod macros; pub mod reader; pub mod values; diff --git a/libraries/cbor/src/macros.rs b/libraries/cbor/src/macros.rs index d96354e..40669d1 100644 --- a/libraries/cbor/src/macros.rs +++ b/libraries/cbor/src/macros.rs @@ -38,8 +38,7 @@ use core::iter::Peekable; /// /// ```rust /// # extern crate alloc; -/// # #[macro_use] -/// # extern crate cbor; +/// # use cbor::destructure_cbor_map; /// # /// # fn main() { /// # let map = alloc::collections::BTreeMap::new(); @@ -54,8 +53,6 @@ use core::iter::Peekable; /// /// ```rust /// # extern crate alloc; -/// # #[macro_use] -/// # extern crate cbor; /// # /// # fn main() { /// # let mut map = alloc::collections::BTreeMap::::new(); @@ -71,7 +68,7 @@ macro_rules! destructure_cbor_map { // sorted - the behavior is unspecified if the keys are not sorted. // Therefore, in test mode we add assertions that the keys are indeed sorted. #[cfg(test)] - assert_sorted_keys!($( $key, )+); + $crate::assert_sorted_keys!($( $key, )+); use $crate::values::{IntoCborKey, Value}; use $crate::macros::destructure_cbor_map_peek_value; @@ -144,7 +141,7 @@ macro_rules! assert_sorted_keys { k2, ); } - assert_sorted_keys!($key2, $( $keys, )*); + $crate::assert_sorted_keys!($key2, $( $keys, )*); }; } @@ -227,7 +224,7 @@ macro_rules! cbor_array_vec { }}; } -#[cfg(test)] +#[macro_export] macro_rules! cbor_true { ( ) => { $crate::values::Value::Simple($crate::values::SimpleValue::TrueValue) @@ -248,7 +245,7 @@ macro_rules! cbor_null { }; } -#[cfg(test)] +#[macro_export] macro_rules! cbor_undefined { ( ) => { $crate::values::Value::Simple($crate::values::SimpleValue::Undefined) @@ -267,28 +264,28 @@ macro_rules! cbor_bool { #[macro_export] macro_rules! cbor_unsigned { ( $x:expr ) => { - cbor_key_unsigned!($x).into() + $crate::cbor_key_unsigned!($x).into() }; } #[macro_export] macro_rules! cbor_int { ( $x:expr ) => { - cbor_key_int!($x).into() + $crate::cbor_key_int!($x).into() }; } #[macro_export] macro_rules! cbor_text { ( $x:expr ) => { - cbor_key_text!($x).into() + $crate::cbor_key_text!($x).into() }; } #[macro_export] macro_rules! cbor_bytes { ( $x:expr ) => { - cbor_key_bytes!($x).into() + $crate::cbor_key_bytes!($x).into() }; } @@ -296,7 +293,7 @@ macro_rules! cbor_bytes { #[macro_export] macro_rules! cbor_bytes_lit { ( $x:expr ) => { - cbor_bytes!(($x as &[u8]).to_vec()) + $crate::cbor_bytes!(($x as &[u8]).to_vec()) }; } diff --git a/libraries/cbor/src/reader.rs b/libraries/cbor/src/reader.rs index 0ba6a6c..a1061a0 100644 --- a/libraries/cbor/src/reader.rs +++ b/libraries/cbor/src/reader.rs @@ -13,6 +13,7 @@ // limitations under the License. use super::values::{Constants, KeyType, SimpleValue, Value}; +use crate::{cbor_array_vec, cbor_bytes_lit, cbor_map_btree, cbor_text, cbor_unsigned}; use alloc::collections::BTreeMap; use alloc::str; use alloc::vec::Vec; @@ -214,6 +215,10 @@ impl<'a> Reader<'a> { #[cfg(test)] mod test { use super::*; + use crate::{ + cbor_array, cbor_bytes, cbor_false, cbor_int, cbor_map, cbor_null, cbor_true, + cbor_undefined, + }; #[test] fn test_read_unsigned() { diff --git a/libraries/cbor/src/values.rs b/libraries/cbor/src/values.rs index d402730..b20d109 100644 --- a/libraries/cbor/src/values.rs +++ b/libraries/cbor/src/values.rs @@ -239,6 +239,8 @@ where #[cfg(test)] mod test { + use crate::{cbor_key_bytes, cbor_key_int, cbor_key_text}; + #[test] fn test_key_type_ordering() { assert!(cbor_key_int!(0) < cbor_key_int!(23)); diff --git a/libraries/cbor/src/writer.rs b/libraries/cbor/src/writer.rs index 0764851..592048d 100644 --- a/libraries/cbor/src/writer.rs +++ b/libraries/cbor/src/writer.rs @@ -92,6 +92,10 @@ impl<'a> Writer<'a> { #[cfg(test)] mod test { use super::*; + use crate::{ + cbor_array, cbor_array_vec, cbor_bytes, cbor_false, cbor_int, cbor_map, cbor_null, + cbor_text, cbor_true, cbor_undefined, + }; fn write_return(value: Value) -> Option> { let mut encoded_cbor = Vec::new(); diff --git a/libraries/crypto/src/aes256.rs b/libraries/crypto/src/aes256.rs index cdd5905..9c16bd4 100644 --- a/libraries/crypto/src/aes256.rs +++ b/libraries/crypto/src/aes256.rs @@ -14,6 +14,7 @@ use super::util::{xor_block_16, Block16}; use super::{Decrypt16BytesBlock, Encrypt16BytesBlock}; +use arrayref::{array_mut_ref, array_ref}; /** A portable and naive textbook implementation of AES-256 **/ type Word = [u8; 4]; diff --git a/libraries/crypto/src/ec/int256.rs b/libraries/crypto/src/ec/int256.rs index 2f3a1da..a3f572c 100644 --- a/libraries/crypto/src/ec/int256.rs +++ b/libraries/crypto/src/ec/int256.rs @@ -13,7 +13,9 @@ // limitations under the License. use super::super::rng256::Rng256; +use alloc::vec; use alloc::vec::Vec; +use arrayref::{array_mut_ref, array_ref}; use byteorder::{BigEndian, ByteOrder}; use core::ops::{Add, AddAssign, Sub, SubAssign}; use subtle::{self, Choice, ConditionallySelectable, ConstantTimeEq}; diff --git a/libraries/crypto/src/ec/point.rs b/libraries/crypto/src/ec/point.rs index 99b32ed..11c6cde 100644 --- a/libraries/crypto/src/ec/point.rs +++ b/libraries/crypto/src/ec/point.rs @@ -16,6 +16,10 @@ use super::exponent256::ExponentP256; use super::gfp256::GFP256; use super::int256::Int256; use super::montgomery::Montgomery; +#[cfg(test)] +use arrayref::array_mut_ref; +#[cfg(feature = "std")] +use arrayref::array_ref; use core::ops::Add; use subtle::{Choice, ConditionallySelectable, ConstantTimeEq}; diff --git a/libraries/crypto/src/ecdsa.rs b/libraries/crypto/src/ecdsa.rs index 966552d..52949e3 100644 --- a/libraries/crypto/src/ecdsa.rs +++ b/libraries/crypto/src/ecdsa.rs @@ -19,7 +19,12 @@ use super::ec::point::PointP256; use super::hmac::hmac_256; use super::rng256::Rng256; use super::{Hash256, HashBlockSize64Bytes}; +use alloc::vec; use alloc::vec::Vec; +#[cfg(feature = "std")] +use arrayref::array_ref; +use arrayref::{array_mut_ref, mut_array_refs}; +use cbor::{cbor_bytes, cbor_map_options}; use core::marker::PhantomData; #[derive(Clone, PartialEq)] @@ -349,9 +354,6 @@ mod test { use super::super::rng256::ThreadRng256; use super::super::sha256::Sha256; use super::*; - extern crate hex; - extern crate ring; - extern crate untrusted; // Run more test iterations in release mode, as the code should be faster. #[cfg(not(debug_assertions))] diff --git a/libraries/crypto/src/hmac.rs b/libraries/crypto/src/hmac.rs index f09e2b9..338340e 100644 --- a/libraries/crypto/src/hmac.rs +++ b/libraries/crypto/src/hmac.rs @@ -13,6 +13,7 @@ // limitations under the License. use super::{Hash256, HashBlockSize64Bytes}; +use arrayref::array_ref; use subtle::ConstantTimeEq; const BLOCK_SIZE: usize = 64; @@ -71,7 +72,6 @@ fn xor_pads(ipad: &mut [u8; BLOCK_SIZE], opad: &mut [u8; BLOCK_SIZE], key: &[u8] mod test { use super::super::sha256::Sha256; use super::*; - extern crate hex; #[test] fn test_verify_hmac_valid() { diff --git a/libraries/crypto/src/lib.rs b/libraries/crypto/src/lib.rs index 031cfa3..7b35e99 100644 --- a/libraries/crypto/src/lib.rs +++ b/libraries/crypto/src/lib.rs @@ -15,14 +15,7 @@ #![cfg_attr(not(feature = "std"), no_std)] #![feature(wrapping_int_impl)] -#[macro_use] extern crate alloc; -extern crate subtle; -#[macro_use] -extern crate arrayref; -extern crate byteorder; -#[macro_use] -extern crate cbor; pub mod aes256; pub mod cbc; diff --git a/libraries/crypto/src/rng256.rs b/libraries/crypto/src/rng256.rs index 9657bf2..87300b8 100644 --- a/libraries/crypto/src/rng256.rs +++ b/libraries/crypto/src/rng256.rs @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +use arrayref::array_ref; use libtock_drivers::rng; // Lightweight RNG trait to generate uniformly distributed 256 bits. diff --git a/libraries/crypto/src/sha256.rs b/libraries/crypto/src/sha256.rs index 7ad54a8..aa63a4c 100644 --- a/libraries/crypto/src/sha256.rs +++ b/libraries/crypto/src/sha256.rs @@ -13,6 +13,7 @@ // limitations under the License. use super::{Hash256, HashBlockSize64Bytes}; +use arrayref::{array_mut_ref, array_ref}; use byteorder::{BigEndian, ByteOrder}; use core::num::Wrapping; @@ -210,7 +211,6 @@ impl Sha256 { #[cfg(test)] mod test { use super::*; - extern crate hex; #[test] fn test_choice() { diff --git a/libraries/crypto/tests/aesavs.rs b/libraries/crypto/tests/aesavs.rs index e3798e4..5b6731a 100644 --- a/libraries/crypto/tests/aesavs.rs +++ b/libraries/crypto/tests/aesavs.rs @@ -15,11 +15,7 @@ /// Test vectors for AES-ECB from NIST's validation suite. /// /// See also https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Algorithm-Validation-Program/documents/aes/AESAVS.pdf -#[macro_use] -extern crate arrayref; -extern crate hex; -extern crate regex; - +use arrayref::array_ref; use crypto::{aes256, Decrypt16BytesBlock, Encrypt16BytesBlock}; use regex::Regex; use std::fs::File; diff --git a/run_desktop_tests.sh b/run_desktop_tests.sh index d812b22..703e6e6 100755 --- a/run_desktop_tests.sh +++ b/run_desktop_tests.sh @@ -49,6 +49,12 @@ cargo check --release --target=thumbv7em-none-eabi --features debug_ctap,with_ct echo "Checking that examples build properly..." cargo check --release --target=thumbv7em-none-eabi --examples +echo "Checking that fuzz targets build properly..." +cargo fuzz build +cd libraries/cbor +cargo fuzz build +cd ../.. + echo "Checking that CTAP2 builds and links properly (1 set of features)..." cargo build --release --target=thumbv7em-none-eabi --features with_ctap1 ./third_party/tock/tools/sha256sum/target/debug/sha256sum target/thumbv7em-none-eabi/release/ctap2 diff --git a/src/ctap/command.rs b/src/ctap/command.rs index 84ca8df..d76a8b7 100644 --- a/src/ctap/command.rs +++ b/src/ctap/command.rs @@ -21,6 +21,7 @@ use super::data_formats::{ use super::status_code::Ctap2StatusCode; use alloc::string::String; use alloc::vec::Vec; +use cbor::destructure_cbor_map; use core::convert::TryFrom; // Depending on your memory, you can use Some(n) to limit request sizes in @@ -383,6 +384,7 @@ mod test { use super::super::ES256_CRED_PARAM; use super::*; use alloc::collections::BTreeMap; + use cbor::{cbor_array, cbor_map}; #[test] fn test_from_cbor_make_credential_parameters() { diff --git a/src/ctap/ctap1.rs b/src/ctap/ctap1.rs index 6d33d28..84c6fb0 100644 --- a/src/ctap/ctap1.rs +++ b/src/ctap/ctap1.rs @@ -17,6 +17,7 @@ use super::key_material::{ATTESTATION_CERTIFICATE, ATTESTATION_PRIVATE_KEY}; use super::status_code::Ctap2StatusCode; use super::CtapState; use alloc::vec::Vec; +use arrayref::array_ref; use core::convert::Into; use core::convert::TryFrom; use crypto::rng256::Rng256; diff --git a/src/ctap/data_formats.rs b/src/ctap/data_formats.rs index fad5820..c5fa8bd 100644 --- a/src/ctap/data_formats.rs +++ b/src/ctap/data_formats.rs @@ -16,6 +16,8 @@ use super::status_code::Ctap2StatusCode; use alloc::collections::BTreeMap; use alloc::string::String; use alloc::vec::Vec; +use arrayref::array_ref; +use cbor::{cbor_array_vec, cbor_bytes_lit, cbor_map_options, destructure_cbor_map}; use core::convert::TryFrom; use crypto::{ecdh, ecdsa}; #[cfg(test)] @@ -800,6 +802,10 @@ mod test { use self::Ctap2StatusCode::CTAP2_ERR_CBOR_UNEXPECTED_TYPE; use super::*; use alloc::collections::BTreeMap; + use cbor::{ + cbor_array, cbor_bool, cbor_bytes, cbor_false, cbor_int, cbor_map, cbor_null, cbor_text, + cbor_unsigned, + }; use crypto::rng256::{Rng256, ThreadRng256}; #[test] diff --git a/src/ctap/hid/mod.rs b/src/ctap/hid/mod.rs index 115bc3a..7489f6e 100644 --- a/src/ctap/hid/mod.rs +++ b/src/ctap/hid/mod.rs @@ -22,7 +22,9 @@ use super::ctap1; use super::status_code::Ctap2StatusCode; use super::timed_permission::TimedPermission; use super::CtapState; +use alloc::vec; use alloc::vec::Vec; +use arrayref::{array_ref, array_refs}; #[cfg(feature = "debug_ctap")] use core::fmt::Write; use crypto::rng256::Rng256; diff --git a/src/ctap/mod.rs b/src/ctap/mod.rs index 192067a..5b78851 100644 --- a/src/ctap/mod.rs +++ b/src/ctap/mod.rs @@ -51,8 +51,11 @@ use self::storage::PersistentStore; use self::timed_permission::U2fUserPresenceState; use alloc::collections::BTreeMap; use alloc::string::{String, ToString}; +use alloc::vec; use alloc::vec::Vec; +use arrayref::array_ref; use byteorder::{BigEndian, ByteOrder}; +use cbor::{cbor_map, cbor_map_options}; #[cfg(feature = "debug_ctap")] use core::fmt::Write; use crypto::cbc::{cbc_decrypt, cbc_encrypt}; diff --git a/src/ctap/pin_protocol_v1.rs b/src/ctap/pin_protocol_v1.rs index bfdb817..3db4d43 100644 --- a/src/ctap/pin_protocol_v1.rs +++ b/src/ctap/pin_protocol_v1.rs @@ -19,7 +19,10 @@ use super::status_code::Ctap2StatusCode; use super::storage::PersistentStore; #[cfg(feature = "with_ctap2_1")] use alloc::string::String; +#[cfg(feature = "with_ctap2_1")] +use alloc::vec; use alloc::vec::Vec; +use arrayref::array_ref; use core::convert::TryInto; use crypto::cbc::{cbc_decrypt, cbc_encrypt}; use crypto::hmac::{hmac_256, verify_hmac_256_first_128bits}; @@ -635,6 +638,7 @@ impl PinProtocolV1 { #[cfg(test)] mod test { use super::*; + use arrayref::array_refs; use crypto::rng256::ThreadRng256; // Stores a PIN hash corresponding to the dummy PIN "1234". diff --git a/src/ctap/response.rs b/src/ctap/response.rs index 3f16a75..47e1d54 100644 --- a/src/ctap/response.rs +++ b/src/ctap/response.rs @@ -21,6 +21,7 @@ use super::data_formats::{ use alloc::collections::BTreeMap; use alloc::string::String; use alloc::vec::Vec; +use cbor::{cbor_array_vec, cbor_bool, cbor_map_btree, cbor_map_options, cbor_text}; #[cfg_attr(test, derive(PartialEq))] #[cfg_attr(any(test, feature = "debug_ctap"), derive(Debug))] @@ -236,6 +237,7 @@ mod test { #[cfg(feature = "with_ctap2_1")] use super::super::ES256_CRED_PARAM; use super::*; + use cbor::{cbor_bytes, cbor_map}; #[test] fn test_make_credential_into_cbor() { diff --git a/src/ctap/storage.rs b/src/ctap/storage.rs index de5eb03..411f8ae 100644 --- a/src/ctap/storage.rs +++ b/src/ctap/storage.rs @@ -20,7 +20,12 @@ use crate::ctap::status_code::Ctap2StatusCode; use crate::ctap::{key_material, USE_BATCH_ATTESTATION}; use crate::embedded_flash::{self, StoreConfig, StoreEntry, StoreError}; use alloc::string::String; +#[cfg(any(test, feature = "ram_storage", feature = "with_ctap2_1"))] +use alloc::vec; use alloc::vec::Vec; +use arrayref::array_ref; +#[cfg(feature = "with_ctap2_1")] +use cbor::cbor_array_vec; use core::convert::TryInto; use crypto::rng256::Rng256; diff --git a/src/embedded_flash/buffer.rs b/src/embedded_flash/buffer.rs index 4fcd80f..0e7171a 100644 --- a/src/embedded_flash/buffer.rs +++ b/src/embedded_flash/buffer.rs @@ -14,6 +14,7 @@ use super::{Index, Storage, StorageError, StorageResult}; use alloc::boxed::Box; +use alloc::vec; pub struct BufferStorage { storage: Box<[u8]>, diff --git a/src/embedded_flash/store/format.rs b/src/embedded_flash/store/format.rs index 447506c..03787cf 100644 --- a/src/embedded_flash/store/format.rs +++ b/src/embedded_flash/store/format.rs @@ -14,6 +14,7 @@ use super::super::{Index, Storage}; use super::{bitfield, StoreConfig, StoreEntry, StoreError}; +use alloc::vec; use alloc::vec::Vec; /// Whether a user entry is a replace entry. diff --git a/src/embedded_flash/store/mod.rs b/src/embedded_flash/store/mod.rs index 49ab487..170fd87 100644 --- a/src/embedded_flash/store/mod.rs +++ b/src/embedded_flash/store/mod.rs @@ -169,6 +169,7 @@ use crate::embedded_flash::BufferStorage; #[cfg(any(test, feature = "ram_storage"))] use alloc::boxed::Box; use alloc::collections::BTreeMap; +use alloc::vec; use alloc::vec::Vec; /// Configures a store. diff --git a/src/lib.rs b/src/lib.rs index 0df6552..d6260c7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,15 +14,7 @@ #![cfg_attr(not(feature = "std"), no_std)] -#[macro_use] extern crate alloc; -#[macro_use] -extern crate arrayref; -#[macro_use] -extern crate cbor; -extern crate lang_items; -extern crate libtock_core; -extern crate libtock_drivers; pub mod ctap; pub mod embedded_flash; diff --git a/src/main.rs b/src/main.rs index 8a3470f..855325e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,18 +14,10 @@ #![cfg_attr(not(feature = "std"), no_std)] -#[macro_use] extern crate alloc; -#[macro_use] -extern crate arrayref; -extern crate byteorder; #[cfg(feature = "std")] extern crate core; -extern crate ctap2; -extern crate subtle; -#[macro_use] -extern crate cbor; -extern crate crypto; +extern crate lang_items; mod ctap; pub mod embedded_flash;