X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Futil%2Fchacha20poly1305rfc.rs;h=fdd51e757b5bd12f1b973db7737efb802c3d2284;hb=963f8d93b58ebf5d5ee1d6e3e3654c11a4597a0f;hp=1d3af1ea32072b4622756dcb8ef292921293904b;hpb=88fef649b15fa030cb91de76d58346a0bc408834;p=rust-lightning diff --git a/lightning/src/util/chacha20poly1305rfc.rs b/lightning/src/util/chacha20poly1305rfc.rs index 1d3af1ea..fdd51e75 100644 --- a/lightning/src/util/chacha20poly1305rfc.rs +++ b/lightning/src/util/chacha20poly1305rfc.rs @@ -1,12 +1,12 @@ // ring has a garbage API so its use is avoided, but rust-crypto doesn't have RFC-variant poly1305 // Instead, we steal rust-crypto's implementation and tweak it to match the RFC. - -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - +// +// This file is licensed under the Apache License, Version 2.0 or the MIT license +// , at your option. +// You may not use this file except in accordance with one or both of these +// licenses. +// // This is a port of Andrew Moons poly1305-donna // https://github.com/floodyberry/poly1305-donna @@ -14,9 +14,7 @@ mod real_chachapoly { use util::chacha20::ChaCha20; use util::poly1305::Poly1305; - use bitcoin_hashes::cmp::fixed_time_eq; - - use util::byte_utils; + use bitcoin::hashes::cmp::fixed_time_eq; #[derive(Clone, Copy)] pub struct ChaCha20Poly1305RFC { @@ -51,8 +49,8 @@ mod real_chachapoly { ChaCha20Poly1305RFC::pad_mac_16(&mut mac, aad.len()); ChaCha20Poly1305RFC { - cipher: cipher, - mac: mac, + cipher, + mac, finished: false, data_len: 0, aad_len: aad.len() as u64, @@ -67,8 +65,8 @@ mod real_chachapoly { self.mac.input(output); ChaCha20Poly1305RFC::pad_mac_16(&mut self.mac, self.data_len); self.finished = true; - self.mac.input(&byte_utils::le64_to_array(self.aad_len)); - self.mac.input(&byte_utils::le64_to_array(self.data_len as u64)); + self.mac.input(&self.aad_len.to_le_bytes()); + self.mac.input(&(self.data_len as u64).to_le_bytes()); self.mac.raw_result(out_tag); } @@ -82,8 +80,8 @@ mod real_chachapoly { self.data_len += input.len(); ChaCha20Poly1305RFC::pad_mac_16(&mut self.mac, self.data_len); - self.mac.input(&byte_utils::le64_to_array(self.aad_len)); - self.mac.input(&byte_utils::le64_to_array(self.data_len as u64)); + self.mac.input(&self.aad_len.to_le_bytes()); + self.mac.input(&(self.data_len as u64).to_le_bytes()); let mut calc_tag = [0u8; 16]; self.mac.raw_result(&mut calc_tag);