diff --git a/Cargo.lock b/Cargo.lock index dbf90f3..abb38c3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2056,7 +2056,6 @@ version = "0.7.0" dependencies = [ "abscissa_core", "atomicwrites", - "byteorder", "bytes", "chacha20poly1305", "chrono", diff --git a/Cargo.toml b/Cargo.toml index 493656b..1073b46 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,6 @@ circle-ci = { repository = "tendermint/kms" } [dependencies] abscissa_core = "0.5" atomicwrites = "0.2" -byteorder = "1.2" bytes = "0.5" chacha20poly1305 = "0.3" chrono = "0.4" diff --git a/src/connection/secret_connection.rs b/src/connection/secret_connection.rs index 101dc21..266f4f0 100644 --- a/src/connection/secret_connection.rs +++ b/src/connection/secret_connection.rs @@ -7,7 +7,6 @@ mod public_key; pub use self::{amino_types::AuthSigMessage, kdf::Kdf, nonce::Nonce, public_key::PublicKey}; use crate::error::{Error, ErrorKind}; -use byteorder::{ByteOrder, LE}; use bytes::BufMut; use chacha20poly1305::{ aead::{generic_array::GenericArray, Aead, NewAead}, @@ -21,6 +20,7 @@ use signatory::{ use signatory_dalek::Ed25519Verifier; use std::{ cmp, + convert::TryInto, io::{self, Read, Write}, marker::{Send, Sync}, }; @@ -138,7 +138,7 @@ impl SecretConnection { sealed_frame: &mut [u8; TAG_SIZE + TOTAL_FRAME_SIZE], ) -> Result<(), Error> { debug_assert!(chunk.len() <= TOTAL_FRAME_SIZE - DATA_LEN_SIZE); - LE::write_u32(&mut sealed_frame[..DATA_LEN_SIZE], chunk.len() as u32); + sealed_frame[..DATA_LEN_SIZE].copy_from_slice(&(chunk.len() as u32).to_le_bytes()); sealed_frame[DATA_LEN_SIZE..DATA_LEN_SIZE + chunk.len()].copy_from_slice(chunk); let tag = self @@ -219,10 +219,7 @@ where self.recv_nonce.increment(); // end decryption - let mut chunk_length_specifier = vec![0; 4]; - chunk_length_specifier.clone_from_slice(&frame[..4]); - - let chunk_length = LE::read_u32(&chunk_length_specifier); + let chunk_length = u32::from_le_bytes(frame[..4].try_into().unwrap()); if chunk_length as usize > DATA_MAX_SIZE { return Err(io::Error::new( diff --git a/src/connection/secret_connection/nonce.rs b/src/connection/secret_connection/nonce.rs index a4117fc..59c0038 100644 --- a/src/connection/secret_connection/nonce.rs +++ b/src/connection/secret_connection/nonce.rs @@ -1,6 +1,8 @@ -use byteorder::{ByteOrder, LE}; +//! Secret Connection nonces -/// Size of a ChaCha20 nonce +use std::convert::TryInto; + +/// Size of a ChaCha20 (IETF) nonce pub const SIZE: usize = 12; /// SecretConnection nonces (i.e. ChaCha20 nonces) @@ -15,8 +17,8 @@ impl Default for Nonce { impl Nonce { /// Increment the nonce's counter by 1 pub fn increment(&mut self) { - let counter: u64 = LE::read_u64(&self.0[4..]); - LE::write_u64(&mut self.0[4..], counter.checked_add(1).unwrap()); + let counter: u64 = u64::from_le_bytes(self.0[4..].try_into().unwrap()); + self.0[4..].copy_from_slice(&counter.checked_add(1).unwrap().to_le_bytes()); } /// Serialize nonce as bytes (little endian)