// This is a port of Andrew Moons poly1305-donna
// https://github.com/floodyberry/poly1305-donna
-use ln::msgs::DecodeError;
-use util::ser::{FixedLengthReader, LengthRead, LengthReadableArgs, Readable, Writeable, Writer};
-use io::{self, Read, Write};
+use crate::ln::msgs::DecodeError;
+use crate::util::ser::{FixedLengthReader, LengthRead, LengthReadableArgs, Readable, Writeable, Writer};
+use crate::io::{self, Read, Write};
#[cfg(not(fuzzing))]
mod real_chachapoly {
- use util::chacha20::ChaCha20;
- use util::poly1305::Poly1305;
+ use crate::util::chacha20::ChaCha20;
+ use crate::util::poly1305::Poly1305;
use bitcoin::hashes::cmp::fixed_time_eq;
#[derive(Clone, Copy)]
self.mac.raw_result(out_tag);
}
+ pub fn encrypt_full_message_in_place(&mut self, input_output: &mut [u8], out_tag: &mut [u8]) {
+ self.encrypt_in_place(input_output);
+ self.finish_and_get_tag(out_tag);
+ }
+
// Encrypt `input_output` in-place. To finish and calculate the tag, use `finish_and_get_tag`
// below.
pub(super) fn encrypt_in_place(&mut self, input_output: &mut [u8]) {
/// Enables the use of the serialization macros for objects that need to be simultaneously decrypted and
/// deserialized. This allows us to avoid an intermediate Vec allocation.
pub(crate) struct ChaChaPolyReadAdapter<R: Readable> {
- #[allow(unused)] // This will be used soon for onion messages
pub readable: R,
}
self.finished = true;
}
+ pub fn encrypt_full_message_in_place(&mut self, input_output: &mut [u8], out_tag: &mut [u8]) {
+ self.encrypt_in_place(input_output);
+ self.finish_and_get_tag(out_tag);
+ }
+
pub(super) fn encrypt_in_place(&mut self, _input_output: &mut [u8]) {
assert!(self.finished == false);
- self.finished = true;
}
pub(super) fn finish_and_get_tag(&mut self, out_tag: &mut [u8]) {
+ assert!(self.finished == false);
out_tag.copy_from_slice(&self.tag);
self.finished = true;
}
#[cfg(test)]
mod tests {
- use ln::msgs::DecodeError;
+ use crate::ln::msgs::DecodeError;
use super::{ChaChaPolyReadAdapter, ChaChaPolyWriteAdapter};
- use util::ser::{self, FixedLengthReader, LengthReadableArgs, Writeable};
+ use crate::util::ser::{self, FixedLengthReader, LengthReadableArgs, Writeable};
// Used for for testing various lengths of serialization.
- #[derive(Debug, PartialEq)]
+ #[derive(Debug, PartialEq, Eq)]
struct TestWriteable {
field1: Vec<u8>,
field2: Vec<u8>,