From 2fe28cffc607f93064df13141da539011c2935fd Mon Sep 17 00:00:00 2001 From: Nick Johnson Date: Wed, 2 Oct 2024 11:18:35 -0700 Subject: [PATCH 1/4] Move script to contrib --- protocol/{tests => contrib}/regtest.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename protocol/{tests => contrib}/regtest.sh (100%) diff --git a/protocol/tests/regtest.sh b/protocol/contrib/regtest.sh similarity index 100% rename from protocol/tests/regtest.sh rename to protocol/contrib/regtest.sh From 43e5373fff682ac7d66a66cac39e44b8fc7d9c55 Mon Sep 17 00:00:00 2001 From: Nick Johnson Date: Wed, 2 Oct 2024 11:31:06 -0700 Subject: [PATCH 2/4] Make state private in packet handler --- protocol/src/lib.rs | 21 ++++++++++++++++++--- protocol/tests/round_trips.rs | 8 ++++---- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/protocol/src/lib.rs b/protocol/src/lib.rs index be695db..4b9d82a 100644 --- a/protocol/src/lib.rs +++ b/protocol/src/lib.rs @@ -450,11 +450,11 @@ impl PacketWriter { #[derive(Clone)] pub struct PacketHandler { /// A unique identifier for the communication session. - pub session_id: [u8; 32], + session_id: [u8; 32], /// Decrypt packets. - pub packet_reader: PacketReader, + packet_reader: PacketReader, /// Encrypt packets. - pub packet_writer: PacketWriter, + packet_writer: PacketWriter, } impl PacketHandler { @@ -501,6 +501,21 @@ impl PacketHandler { } } + /// Unique session ID. + pub fn session_id(&self) -> &[u8; 32] { + &self.session_id + } + + /// Read reference for packet decryption. + pub fn reader(&mut self) -> &mut PacketReader { + &mut self.packet_reader + } + + /// Write reference for packet encryption. + pub fn writer(&mut self) -> &mut PacketWriter { + &mut self.packet_writer + } + /// Split the handler into separate reader and a writer. pub fn into_split(self) -> (PacketReader, PacketWriter) { (self.packet_reader, self.packet_writer) diff --git a/protocol/tests/round_trips.rs b/protocol/tests/round_trips.rs index 96075b4..aa3ff82 100644 --- a/protocol/tests/round_trips.rs +++ b/protocol/tests/round_trips.rs @@ -45,21 +45,21 @@ fn hello_world_happy_path() { // Alice and Bob can freely exchange encrypted messages using the packet handler returned by each handshake. let message = b"Hello world".to_vec(); let encrypted_message_to_alice = bob - .packet_writer + .writer() .encrypt_packet_with_alloc(&message, None, PacketType::Genuine) .unwrap(); let messages = alice - .packet_reader + .reader() .decrypt_payload_with_alloc(&encrypted_message_to_alice[3..], None) .unwrap(); assert_eq!(message, messages.contents()); let message = b"Goodbye!".to_vec(); let encrypted_message_to_bob = alice - .packet_writer + .writer() .encrypt_packet_with_alloc(&message, None, PacketType::Genuine) .unwrap(); let messages = bob - .packet_reader + .reader() .decrypt_payload_with_alloc(&encrypted_message_to_bob[3..], None) .unwrap(); assert_eq!(message, messages.contents()); From 510ae2693b161681da5cacd803545e0433a2f4ad Mon Sep 17 00:00:00 2001 From: Nick Johnson Date: Wed, 2 Oct 2024 11:48:26 -0700 Subject: [PATCH 3/4] Condense handshake functions --- protocol/src/lib.rs | 177 ++++++++++++++++++-------------------------- 1 file changed, 71 insertions(+), 106 deletions(-) diff --git a/protocol/src/lib.rs b/protocol/src/lib.rs index 4b9d82a..9cb32d2 100644 --- a/protocol/src/lib.rs +++ b/protocol/src/lib.rs @@ -186,8 +186,8 @@ pub struct SessionKeyMaterial { initiator_packet_key: [u8; 32], responder_length_key: [u8; 32], responder_packet_key: [u8; 32], - initiator_garbage_terminator: [u8; 16], - responder_garbage_terminator: [u8; 16], + initiator_garbage_terminator: [u8; NUM_GARBAGE_TERMINTOR_BYTES], + responder_garbage_terminator: [u8; NUM_GARBAGE_TERMINTOR_BYTES], } /// Role in the handshake. @@ -522,76 +522,6 @@ impl PacketHandler { } } -fn gen_key(rng: &mut impl Rng) -> Result { - let mut buffer = [0u8; 32]; - rng.fill(&mut buffer[..]); - let sk = SecretKey::from_slice(&buffer)?; - Ok(sk) -} - -fn new_elligator_swift( - sk: SecretKey, - curve: &Secp256k1, -) -> Result { - let pk = PublicKey::from_secret_key(curve, &sk); - Ok(ElligatorSwift::from_pubkey(pk)) -} - -fn get_shared_secrets( - a: ElligatorSwift, - b: ElligatorSwift, - secret: SecretKey, - party: ElligatorSwiftParty, - network: Network, -) -> Result { - let data = "bip324_ellswift_xonly_ecdh".as_bytes(); - let ecdh_sk = ElligatorSwift::shared_secret(a, b, secret, party, Some(data)); - initialize_session_key_material(ecdh_sk.as_secret_bytes(), network) -} - -fn initialize_session_key_material( - ikm: &[u8], - network: Network, -) -> Result { - let ikm_salt = "bitcoin_v2_shared_secret".as_bytes(); - let magic = network.magic().to_bytes(); - let salt = [ikm_salt, &magic].concat(); - let hk = Hkdf::::new(salt.as_slice(), ikm); - let mut session_id = [0u8; 32]; - let session_info = "session_id".as_bytes(); - hk.expand(session_info, &mut session_id)?; - let mut initiator_length_key = [0u8; 32]; - let intiiator_l_info = "initiator_L".as_bytes(); - hk.expand(intiiator_l_info, &mut initiator_length_key)?; - let mut initiator_packet_key = [0u8; 32]; - let intiiator_p_info = "initiator_P".as_bytes(); - hk.expand(intiiator_p_info, &mut initiator_packet_key)?; - let mut responder_length_key = [0u8; 32]; - let responder_l_info = "responder_L".as_bytes(); - hk.expand(responder_l_info, &mut responder_length_key)?; - let mut responder_packet_key = [0u8; 32]; - let responder_p_info = "responder_P".as_bytes(); - hk.expand(responder_p_info, &mut responder_packet_key)?; - let mut garbage = [0u8; 32]; - let garbage_info = "garbage_terminators".as_bytes(); - hk.expand(garbage_info, &mut garbage)?; - let initiator_garbage_terminator: [u8; 16] = garbage[..16] - .try_into() - .expect("first 16 btyes of expanded garbage"); - let responder_garbage_terminator: [u8; 16] = garbage[16..] - .try_into() - .expect("last 16 bytes of expanded garbage"); - Ok(SessionKeyMaterial { - session_id, - initiator_length_key, - initiator_packet_key, - responder_length_key, - responder_packet_key, - initiator_garbage_terminator, - responder_garbage_terminator, - }) -} - /// Handshake state-machine to establish the secret material in the communication channel. /// /// A handshake is first initialized to create local materials needed to setup communication @@ -673,8 +603,12 @@ impl<'a> Handshake<'a> { rng: &mut impl Rng, curve: &Secp256k1, ) -> Result { - let sk = gen_key(rng)?; - let es = new_elligator_swift(sk, curve)?; + let mut secret_key_buffer = [0u8; 32]; + rng.fill(&mut secret_key_buffer[..]); + let sk = SecretKey::from_slice(&secret_key_buffer)?; + let pk = PublicKey::from_secret_key(curve, &sk); + let es = ElligatorSwift::from_pubkey(pk); + let point = EcdhPoint { secret_key: sk, elligator_swift: es, @@ -716,7 +650,7 @@ impl<'a> Handshake<'a> { // garbage terminator haggling. let materials = match self.role { Role::Initiator => { - let materials = get_shared_secrets( + let materials = Handshake::get_shared_secrets( self.point.elligator_swift, theirs, self.point.secret_key, @@ -730,7 +664,7 @@ impl<'a> Handshake<'a> { materials } Role::Responder => { - let materials = get_shared_secrets( + let materials = Handshake::get_shared_secrets( theirs, self.point.elligator_swift, self.point.secret_key, @@ -954,6 +888,56 @@ impl<'a> Handshake<'a> { Err(Error::CiphertextTooSmall) } } + + /// Calculate secret material for session based on exchanged keys. + fn get_shared_secrets( + a: ElligatorSwift, + b: ElligatorSwift, + secret: SecretKey, + party: ElligatorSwiftParty, + network: Network, + ) -> Result { + let data = "bip324_ellswift_xonly_ecdh".as_bytes(); + let ecdh_sk = ElligatorSwift::shared_secret(a, b, secret, party, Some(data)); + + let ikm_salt = "bitcoin_v2_shared_secret".as_bytes(); + let magic = network.magic().to_bytes(); + let salt = [ikm_salt, &magic].concat(); + let hk = Hkdf::::new(salt.as_slice(), ecdh_sk.as_secret_bytes()); + let mut session_id = [0u8; 32]; + let session_info = "session_id".as_bytes(); + hk.expand(session_info, &mut session_id)?; + let mut initiator_length_key = [0u8; 32]; + let intiiator_l_info = "initiator_L".as_bytes(); + hk.expand(intiiator_l_info, &mut initiator_length_key)?; + let mut initiator_packet_key = [0u8; 32]; + let intiiator_p_info = "initiator_P".as_bytes(); + hk.expand(intiiator_p_info, &mut initiator_packet_key)?; + let mut responder_length_key = [0u8; 32]; + let responder_l_info = "responder_L".as_bytes(); + hk.expand(responder_l_info, &mut responder_length_key)?; + let mut responder_packet_key = [0u8; 32]; + let responder_p_info = "responder_P".as_bytes(); + hk.expand(responder_p_info, &mut responder_packet_key)?; + let mut garbage = [0u8; 32]; + let garbage_info = "garbage_terminators".as_bytes(); + hk.expand(garbage_info, &mut garbage)?; + let initiator_garbage_terminator: [u8; 16] = garbage[..16] + .try_into() + .expect("first 16 btyes of expanded garbage"); + let responder_garbage_terminator: [u8; 16] = garbage[16..] + .try_into() + .expect("last 16 bytes of expanded garbage"); + Ok(SessionKeyMaterial { + session_id, + initiator_length_key, + initiator_packet_key, + responder_length_key, + responder_packet_key, + initiator_garbage_terminator, + responder_garbage_terminator, + }) + } } /// High level error type for the protocol interface. @@ -1217,13 +1201,6 @@ mod tests { buffer } - #[test] - #[cfg(feature = "std")] - fn test_sec_keygen() { - let mut rng = rand::thread_rng(); - gen_key(&mut rng).unwrap(); - } - #[test] #[cfg(feature = "std")] fn test_initial_message() { @@ -1257,18 +1234,6 @@ mod tests { .unwrap(); } - #[test] - #[cfg(feature = "std")] - fn test_expand_extract() { - let ikm = Vec::from_hex("c6992a117f5edbea70c3f511d32d26b9798be4b81a62eaee1a5acaa8459a3592") - .unwrap(); - let session_keys = initialize_session_key_material(&ikm, Network::Bitcoin).unwrap(); - assert_eq!( - session_keys.session_id.to_lower_hex_string(), - "ce72dffb015da62b0d0f5474cab8bc72605225b0cee3f62312ec680ec5f41ba5" - ); - } - #[test] fn test_shared_secret() { let alice = @@ -1276,7 +1241,7 @@ mod tests { .unwrap(); let elliswift_alice = ElligatorSwift::from_str("ec0adff257bbfe500c188c80b4fdd640f6b45a482bbc15fc7cef5931deff0aa186f6eb9bba7b85dc4dcc28b28722de1e3d9108b985e2967045668f66098e475b").unwrap(); let elliswift_bob = ElligatorSwift::from_str("a4a94dfce69b4a2a0a099313d10f9f7e7d649d60501c9e1d274c300e0d89aafaffffffffffffffffffffffffffffffffffffffffffffffffffffffff8faf88d5").unwrap(); - let session_keys = get_shared_secrets( + let session_keys = Handshake::get_shared_secrets( elliswift_alice, elliswift_bob, alice, @@ -1322,7 +1287,7 @@ mod tests { .unwrap(); let elliswift_alice = ElligatorSwift::from_str("ec0adff257bbfe500c188c80b4fdd640f6b45a482bbc15fc7cef5931deff0aa186f6eb9bba7b85dc4dcc28b28722de1e3d9108b985e2967045668f66098e475b").unwrap(); let elliswift_bob = ElligatorSwift::from_str("a4a94dfce69b4a2a0a099313d10f9f7e7d649d60501c9e1d274c300e0d89aafaffffffffffffffffffffffffffffffffffffffffffffffffffffffff8faf88d5").unwrap(); - let session_keys = get_shared_secrets( + let session_keys = Handshake::get_shared_secrets( elliswift_alice, elliswift_bob, alice, @@ -1363,7 +1328,7 @@ mod tests { .unwrap(); let elliswift_alice = ElligatorSwift::from_str("ec0adff257bbfe500c188c80b4fdd640f6b45a482bbc15fc7cef5931deff0aa186f6eb9bba7b85dc4dcc28b28722de1e3d9108b985e2967045668f66098e475b").unwrap(); let elliswift_bob = ElligatorSwift::from_str("a4a94dfce69b4a2a0a099313d10f9f7e7d649d60501c9e1d274c300e0d89aafaffffffffffffffffffffffffffffffffffffffffffffffffffffffff8faf88d5").unwrap(); - let session_keys = get_shared_secrets( + let session_keys = Handshake::get_shared_secrets( elliswift_alice, elliswift_bob, alice, @@ -1407,7 +1372,7 @@ mod tests { .unwrap(); let elliswift_alice = ElligatorSwift::from_str("ec0adff257bbfe500c188c80b4fdd640f6b45a482bbc15fc7cef5931deff0aa186f6eb9bba7b85dc4dcc28b28722de1e3d9108b985e2967045668f66098e475b").unwrap(); let elliswift_bob = ElligatorSwift::from_str("a4a94dfce69b4a2a0a099313d10f9f7e7d649d60501c9e1d274c300e0d89aafaffffffffffffffffffffffffffffffffffffffffffffffffffffffff8faf88d5").unwrap(); - let session_keys = get_shared_secrets( + let session_keys = Handshake::get_shared_secrets( elliswift_alice, elliswift_bob, alice, @@ -1619,7 +1584,7 @@ mod tests { .unwrap(); let elliswift_alice = ElligatorSwift::from_str("ec0adff257bbfe500c188c80b4fdd640f6b45a482bbc15fc7cef5931deff0aa186f6eb9bba7b85dc4dcc28b28722de1e3d9108b985e2967045668f66098e475b").unwrap(); let elliswift_bob = ElligatorSwift::from_str("a4a94dfce69b4a2a0a099313d10f9f7e7d649d60501c9e1d274c300e0d89aafaffffffffffffffffffffffffffffffffffffffffffffffffffffffff8faf88d5").unwrap(); - let session_keys = get_shared_secrets( + let session_keys = Handshake::get_shared_secrets( elliswift_alice, elliswift_bob, alice, @@ -1658,7 +1623,7 @@ mod tests { .unwrap(); let elliswift_alice = ElligatorSwift::from_str("a1855e10e94e00baa23041d916e259f7044e491da6171269694763f018c7e63693d29575dcb464ac816baa1be353ba12e3876cba7628bd0bd8e755e721eb0140").unwrap(); let elliswift_bob = ElligatorSwift::from_str("fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f0000000000000000000000000000000000000000000000000000000000000000").unwrap(); - let session_keys = get_shared_secrets( + let session_keys = Handshake::get_shared_secrets( elliswift_bob, elliswift_alice, alice, @@ -1701,7 +1666,7 @@ mod tests { .unwrap(); let elliswift_alice = ElligatorSwift::from_str("d1ee8a93a01130cbf299249a258f94feb5f469e7d0f2f28f69ee5e9aa8f9b54a60f2c3ff2d023634ec7f4127a96cc11662e402894cf1f694fb9a7eaa5f1d9244").unwrap(); let elliswift_bob = ElligatorSwift::from_str("ffffffffffffffffffffffffffffffffffffffffffffffffffffffff22d5e441524d571a52b3def126189d3f416890a99d4da6ede2b0cde1760ce2c3f98457ae").unwrap(); - let session_keys = get_shared_secrets( + let session_keys = Handshake::get_shared_secrets( elliswift_alice, elliswift_bob, alice, @@ -1728,7 +1693,7 @@ mod tests { .unwrap(); let elliswift_alice = ElligatorSwift::from_str("d2685070c1e6376e633e825296634fd461fa9e5bdf2109bcebd735e5a91f3e587c5cb782abb797fbf6bb5074fd1542a474f2a45b673763ec2db7fb99b737bbb9").unwrap(); let elliswift_bob = ElligatorSwift::from_str("56bd0c06f10352c3a1a9f4b4c92f6fa2b26df124b57878353c1fc691c51abea77c8817daeeb9fa546b77c8daf79d89b22b0e1b87574ece42371f00237aa9d83a").unwrap(); - let session_keys = get_shared_secrets( + let session_keys = Handshake::get_shared_secrets( elliswift_bob, elliswift_alice, alice, @@ -1767,7 +1732,7 @@ mod tests { .unwrap(); let elliswift_alice = ElligatorSwift::from_str("ffffffffffffffffffffffffffffffffffffffffffffffffffffffff053d7ecca53e33e185a8b9be4e7699a97c6ff4c795522e5918ab7cd6b6884f67e683f3dc").unwrap(); let elliswift_bob = ElligatorSwift::from_str("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffa7730be30000000000000000000000000000000000000000000000000000000000000000").unwrap(); - let session_keys = get_shared_secrets( + let session_keys = Handshake::get_shared_secrets( elliswift_alice, elliswift_bob, alice, @@ -1800,7 +1765,7 @@ mod tests { .unwrap(); let elliswift_alice = ElligatorSwift::from_str("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffc81017fd92fd31637c26c906b42092e11cc0d3afae8d9019d2578af22735ce7bc469c72d").unwrap(); let elliswift_bob = ElligatorSwift::from_str("9652d78baefc028cd37a6a92625b8b8f85fde1e4c944ad3f20e198bef8c02f19fffffffffffffffffffffffffffffffffffffffffffffffffffffffff2e91870").unwrap(); - let session_keys = get_shared_secrets( + let session_keys = Handshake::get_shared_secrets( elliswift_bob, elliswift_alice, alice, @@ -1838,7 +1803,7 @@ mod tests { .unwrap(); let elliswift_alice = ElligatorSwift::from_str("ffffffffffffffffffffffffffffffffffffffffffffffffffffffff115173765dc202cf029ad3f15479735d57697af12b0131dd21430d5772e4ef11474d58b9").unwrap(); let elliswift_bob = ElligatorSwift::from_str("12a50f3fafea7c1eeada4cf8d33777704b77361453afc83bda91eef349ae044d20126c6200547ea5a6911776c05dee2a7f1a9ba7dfbabbbd273c3ef29ef46e46").unwrap(); - let session_keys = get_shared_secrets( + let session_keys = Handshake::get_shared_secrets( elliswift_alice, elliswift_bob, alice, From 380ed5a6bc4fd7ca97b0ee567228aec84b5d9396 Mon Sep 17 00:00:00 2001 From: Nick Johnson Date: Wed, 2 Oct 2024 11:52:40 -0700 Subject: [PATCH 4/4] Invert alloc function names --- protocol/src/lib.rs | 111 ++++++++++++++++------------------ protocol/tests/round_trips.rs | 22 +++---- 2 files changed, 61 insertions(+), 72 deletions(-) diff --git a/protocol/src/lib.rs b/protocol/src/lib.rs index 9cb32d2..aa29cbb 100644 --- a/protocol/src/lib.rs +++ b/protocol/src/lib.rs @@ -307,7 +307,7 @@ impl PacketReader { /// * `CiphertextTooSmall` - Ciphertext argument does not contain a whole packet. /// * `BufferTooSmall ` - Contents buffer argument is not large enough for plaintext. /// * Decryption errors for any failures such as a tag mismatch. - pub fn decrypt_payload( + pub fn decrypt_payload_no_alloc( &mut self, ciphertext: &[u8], contents: &mut [u8], @@ -353,13 +353,13 @@ impl PacketReader { /// /// * `CiphertextTooSmall` - Ciphertext argument does not contain a whole packet. #[cfg(feature = "alloc")] - pub fn decrypt_payload_with_alloc( + pub fn decrypt_payload( &mut self, ciphertext: &[u8], aad: Option<&[u8]>, ) -> Result { let mut payload = vec![0u8; ciphertext.len() - NUM_TAG_BYTES]; - self.decrypt_payload(ciphertext, &mut payload, aad)?; + self.decrypt_payload_no_alloc(ciphertext, &mut payload, aad)?; Ok(Payload::new(payload)) } } @@ -386,7 +386,7 @@ impl PacketWriter { /// /// * `Error::BufferTooSmall` - Buffer does not have enough allocated memory for the /// ciphertext plus the 20 bytes needed for the length, header, and tag bytes. - pub fn encrypt_packet( + pub fn encrypt_packet_no_alloc( &mut self, plaintext: &[u8], aad: Option<&[u8]>, @@ -434,14 +434,14 @@ impl PacketWriter { /// * `aad` - Optional associated authenticated data. /// * `packet_type` - Is this a genuine packet or a decoy. #[cfg(feature = "alloc")] - pub fn encrypt_packet_with_alloc( + pub fn encrypt_packet( &mut self, plaintext: &[u8], aad: Option<&[u8]>, packet_type: PacketType, ) -> Result, Error> { let mut packet = vec![0u8; plaintext.len() + NUM_PACKET_OVERHEAD_BYTES]; - self.encrypt_packet(plaintext, aad, &mut packet, packet_type)?; + self.encrypt_packet_no_alloc(plaintext, aad, &mut packet, packet_type)?; Ok(packet) } } @@ -688,7 +688,7 @@ impl<'a> Handshake<'a> { if let Some(decoys) = decoys { for (i, decoy) in decoys.iter().enumerate() { let end_index = start_index + decoy.len() + NUM_PACKET_OVERHEAD_BYTES; - packet_handler.packet_writer.encrypt_packet( + packet_handler.packet_writer.encrypt_packet_no_alloc( decoy, if i == 0 { self.garbage } else { None }, &mut response_buffer[start_index..end_index], @@ -699,7 +699,7 @@ impl<'a> Handshake<'a> { } } - packet_handler.packet_writer.encrypt_packet( + packet_handler.packet_writer.encrypt_packet_no_alloc( &VERSION_CONTENT, if decoys.is_none() { self.garbage } else { None }, &mut response_buffer @@ -724,14 +724,11 @@ impl<'a> Handshake<'a> { /// /// Returns the same errors of [`authenticate_garbage_and_version`], except `BufferTooSmall` is managed internally. #[cfg(feature = "alloc")] - pub fn authenticate_garbage_and_version_with_alloc( - &mut self, - buffer: &[u8], - ) -> Result<(), Error> { + pub fn authenticate_garbage_and_version(&mut self, buffer: &[u8]) -> Result<(), Error> { let mut packet_buffer = vec![0u8; NUM_INITIAL_HANDSHAKE_BUFFER_BYTES]; loop { - match self.authenticate_garbage_and_version(buffer, &mut packet_buffer) { + match self.authenticate_garbage_and_version_no_alloc(buffer, &mut packet_buffer) { Ok(()) => return Ok(()), Err(Error::BufferTooSmall { required_bytes }) => { packet_buffer.resize(required_bytes, 0); @@ -760,7 +757,7 @@ impl<'a> Handshake<'a> { /// * `BufferTooSmall` - The supplied packet_buffer is not large enough for decrypting the decoy and version packets. /// * `HandshakeOutOfOrder` - The handshake sequence is in a bad state and should be restarted. /// * `MaxGarbageLength` - Buffer did not contain the garbage terminator, should not be retried. - pub fn authenticate_garbage_and_version( + pub fn authenticate_garbage_and_version_no_alloc( &mut self, buffer: &[u8], packet_buffer: &mut [u8], @@ -835,7 +832,7 @@ impl<'a> Handshake<'a> { if ciphertext.len() < self.current_buffer_index + NUM_LENGTH_BYTES + packet_length { return Err(Error::CiphertextTooSmall); } - packet_handler.packet_reader.decrypt_payload( + packet_handler.packet_reader.decrypt_payload_no_alloc( &ciphertext[self.current_buffer_index + NUM_LENGTH_BYTES ..self.current_buffer_index + NUM_LENGTH_BYTES + packet_length], packet_buffer, @@ -1048,9 +1045,9 @@ where Ok(bytes_read) => { remote_garbage_and_version_buffer.extend_from_slice(&temp_buffer[..bytes_read]); - match handshake.authenticate_garbage_and_version_with_alloc( - &remote_garbage_and_version_buffer, - ) { + match handshake + .authenticate_garbage_and_version(&remote_garbage_and_version_buffer) + { Ok(()) => break, // Not enough data, continue reading. Err(Error::CiphertextTooSmall) => continue, @@ -1146,9 +1143,7 @@ where } DecryptState::ReadingPayload { packet_bytes } => { self.buffer.read_exact(packet_bytes).await?; - let payload = self - .packet_reader - .decrypt_payload_with_alloc(packet_bytes, None)?; + let payload = self.packet_reader.decrypt_payload(packet_bytes, None)?; self.state = DecryptState::ReadingLength; return Ok(payload); } @@ -1182,7 +1177,7 @@ where pub async fn encrypt(&mut self, plaintext: &[u8]) -> Result<(), ProtocolError> { let write_bytes = self.packet_writer - .encrypt_packet_with_alloc(plaintext, None, PacketType::Genuine)?; + .encrypt_packet(plaintext, None, PacketType::Genuine)?; self.buffer.write_all(&write_bytes[..]).await?; self.buffer.flush().await?; Ok(()) @@ -1300,21 +1295,21 @@ mod tests { let message = b"Bitcoin rox!".to_vec(); let enc_packet = alice_packet_handler .packet_writer - .encrypt_packet_with_alloc(&message, None, PacketType::Decoy) + .encrypt_packet(&message, None, PacketType::Decoy) .unwrap(); let dec = bob_packet_handler .packet_reader - .decrypt_payload_with_alloc(&enc_packet[NUM_LENGTH_BYTES..], None) + .decrypt_payload(&enc_packet[NUM_LENGTH_BYTES..], None) .unwrap(); assert_eq!(PacketType::Decoy, dec.packet_type()); let message = b"Windows sox!".to_vec(); let enc_packet = bob_packet_handler .packet_writer - .encrypt_packet_with_alloc(&message, None, PacketType::Genuine) + .encrypt_packet(&message, None, PacketType::Genuine) .unwrap(); let dec = alice_packet_handler .packet_reader - .decrypt_payload_with_alloc(&enc_packet[NUM_LENGTH_BYTES..], None) + .decrypt_payload(&enc_packet[NUM_LENGTH_BYTES..], None) .unwrap(); assert_eq!(message, dec.contents()); } @@ -1343,21 +1338,21 @@ mod tests { let message = gen_garbage(4095, &mut rng); let enc_packet = alice_packet_handler .packet_writer - .encrypt_packet_with_alloc(&message, None, PacketType::Genuine) + .encrypt_packet(&message, None, PacketType::Genuine) .unwrap(); let dec_packet = bob_packet_handler .packet_reader - .decrypt_payload_with_alloc(&enc_packet[NUM_LENGTH_BYTES..], None) + .decrypt_payload(&enc_packet[NUM_LENGTH_BYTES..], None) .unwrap(); assert_eq!(message, dec_packet.contents()); let message = gen_garbage(420, &mut rng); let enc_packet = bob_packet_handler .packet_writer - .encrypt_packet_with_alloc(&message, None, PacketType::Genuine) + .encrypt_packet(&message, None, PacketType::Genuine) .unwrap(); let dec_packet = alice_packet_handler .packet_reader - .decrypt_payload_with_alloc(&enc_packet[NUM_LENGTH_BYTES..], None) + .decrypt_payload(&enc_packet[NUM_LENGTH_BYTES..], None) .unwrap(); assert_eq!(message, dec_packet.contents()); } @@ -1385,11 +1380,11 @@ mod tests { let auth_garbage = gen_garbage(200, &mut rng); let enc_packet = alice_packet_handler .packet_writer - .encrypt_packet_with_alloc(&VERSION_CONTENT, Some(&auth_garbage), PacketType::Genuine) + .encrypt_packet(&VERSION_CONTENT, Some(&auth_garbage), PacketType::Genuine) .unwrap(); let _ = bob_packet_handler .packet_reader - .decrypt_payload_with_alloc(&enc_packet[NUM_LENGTH_BYTES..], Some(&auth_garbage)) + .decrypt_payload(&enc_packet[NUM_LENGTH_BYTES..], Some(&auth_garbage)) .unwrap(); } @@ -1479,17 +1474,13 @@ mod tests { // The initiator verifies the second half of the responders message which // includes the garbage, garbage terminator, decoys, and version packet. initiator_handshake - .authenticate_garbage_and_version_with_alloc( - &responder_buffer[NUM_ELLIGATOR_SWIFT_BYTES..], - ) + .authenticate_garbage_and_version(&responder_buffer[NUM_ELLIGATOR_SWIFT_BYTES..]) .unwrap(); // The responder verifies the second message from the initiator which // includes the garbage, garbage terminator, decoys, and version packet. responder_handshake - .authenticate_garbage_and_version_with_alloc( - &initiator_buffer[NUM_ELLIGATOR_SWIFT_BYTES..], - ) + .authenticate_garbage_and_version(&initiator_buffer[NUM_ELLIGATOR_SWIFT_BYTES..]) .unwrap(); let mut alice = initiator_handshake.finalize().unwrap(); @@ -1498,21 +1489,21 @@ mod tests { let message = b"Hello world".to_vec(); let encrypted_message_to_alice = bob .packet_writer - .encrypt_packet_with_alloc(&message, None, PacketType::Genuine) + .encrypt_packet(&message, None, PacketType::Genuine) .unwrap(); let dec = alice .packet_reader - .decrypt_payload_with_alloc(&encrypted_message_to_alice[NUM_LENGTH_BYTES..], None) + .decrypt_payload(&encrypted_message_to_alice[NUM_LENGTH_BYTES..], None) .unwrap(); assert_eq!(message, dec.contents()); let message = b"g!".to_vec(); let encrypted_message_to_bob = alice .packet_writer - .encrypt_packet_with_alloc(&message, None, PacketType::Genuine) + .encrypt_packet(&message, None, PacketType::Genuine) .unwrap(); let dec = bob .packet_reader - .decrypt_payload_with_alloc(&encrypted_message_to_bob[NUM_LENGTH_BYTES..], None) + .decrypt_payload(&encrypted_message_to_bob[NUM_LENGTH_BYTES..], None) .unwrap(); assert_eq!(message, dec.contents()); } @@ -1547,10 +1538,10 @@ mod tests { .unwrap(); init_handshake - .authenticate_garbage_and_version_with_alloc(&resp_message[64..]) + .authenticate_garbage_and_version(&resp_message[64..]) .unwrap(); resp_handshake - .authenticate_garbage_and_version_with_alloc(&init_finalize_message) + .authenticate_garbage_and_version(&init_finalize_message) .unwrap(); let mut alice = init_handshake.finalize().unwrap(); @@ -1560,7 +1551,7 @@ mod tests { let message = gen_garbage(420, &mut rng); let enc_packet = alice .packet_writer - .encrypt_packet_with_alloc(&message, None, PacketType::Genuine) + .encrypt_packet(&message, None, PacketType::Genuine) .unwrap(); message_to_bob.extend(enc_packet); let alice_message_len = bob @@ -1568,7 +1559,7 @@ mod tests { .decypt_len(message_to_bob[..3].try_into().unwrap()); let contents = bob .packet_reader - .decrypt_payload_with_alloc(&message_to_bob[3..3 + alice_message_len], None) + .decrypt_payload(&message_to_bob[3..3 + alice_message_len], None) .unwrap(); assert_eq!(contents.contents(), message); } @@ -1597,17 +1588,17 @@ mod tests { let first = gen_garbage(100, &mut rng); let enc = alice_packet_handler .packet_writer - .encrypt_packet_with_alloc(&first, None, PacketType::Genuine) + .encrypt_packet(&first, None, PacketType::Genuine) .unwrap(); let dec_packet = bob_packet_handler .packet_reader - .decrypt_payload_with_alloc(&enc[NUM_LENGTH_BYTES..], None) + .decrypt_payload(&enc[NUM_LENGTH_BYTES..], None) .unwrap(); assert_eq!(first, dec_packet.contents()); let contents: Vec = vec![0x8e]; let enc = alice_packet_handler .packet_writer - .encrypt_packet_with_alloc(&contents, None, PacketType::Genuine) + .encrypt_packet(&contents, None, PacketType::Genuine) .unwrap(); assert_eq!( enc, @@ -1642,12 +1633,12 @@ mod tests { for _ in 0..999 { alice_packet_handler .packet_writer - .encrypt_packet_with_alloc(&Vec::new(), None, PacketType::Genuine) + .encrypt_packet(&Vec::new(), None, PacketType::Genuine) .unwrap(); } let enc = alice_packet_handler .packet_writer - .encrypt_packet_with_alloc(&contents, None, PacketType::Genuine) + .encrypt_packet(&contents, None, PacketType::Genuine) .unwrap(); assert_eq!( enc, @@ -1679,7 +1670,7 @@ mod tests { let aad = Vec::from_hex("84932a55aac22b51e7b128d31d9f0550da28e6a3f394224707d878603386b2f9d0c6bcd8046679bfed7b68c517e7431e75d9dd34605727d2ef1c2babbf680ecc8d68d2c4886e9953a4034abde6da4189cd47c6bb3192242cf714d502ca6103ee84e08bc2ca4fd370d5ad4e7d06c7fbf496c6c7cc7eb19c40c61fb33df2a9ba48497a96c98d7b10c1f91098a6b7b16b4bab9687f27585ade1491ae0dba6a79e1e2d85dd9d9d45c5135ca5fca3f0f99a60ea39edbc9efc7923111c937913f225d67788d5f7e8852b697e26b92ec7bfcaa334a1665511c2b4c0a42d06f7ab98a9719516c8fd17f73804555ee84ab3b7d1762f6096b778d3cb9c799cbd49a9e4a325197b4e6cc4a5c4651f8b41ff88a92ec428354531f970263b467c77ed11312e2617d0d53fe9a8707f51f9f57a77bfb49afe3d89d85ec05ee17b9186f360c94ab8bb2926b65ca99dae1d6ee1af96cad09de70b6767e949023e4b380e66669914a741ed0fa420a48dbc7bfae5ef2019af36d1022283dd90655f25eec7151d471265d22a6d3f91dc700ba749bb67c0fe4bc0888593fbaf59d3c6fff1bf756a125910a63b9682b597c20f560ecb99c11a92c8c8c3f7fbfaa103146083a0ccaecf7a5f5e735a784a8820155914a289d57d8141870ffcaf588882332e0bcd8779efa931aa108dab6c3cce76691e345df4a91a03b71074d66333fd3591bff071ea099360f787bbe43b7b3dff2a59c41c7642eb79870222ad1c6f2e5a191ed5acea51134679587c9cf71c7d8ee290be6bf465c4ee47897a125708704ad610d8d00252d01959209d7cd04d5ecbbb1419a7e84037a55fefa13dee464b48a35c96bcb9a53e7ed461c3a1607ee00c3c302fd47cd73fda7493e947c9834a92d63dcfbd65aa7c38c3e3a2748bb5d9a58e7495d243d6b741078c8f7ee9c8813e473a323375702702b0afae1550c8341eedf5247627343a95240cb02e3e17d5dca16f8d8d3b2228e19c06399f8ec5c5e9dbe4caef6a0ea3ffb1d3c7eac03ae030e791fa12e537c80d56b55b764cadf27a8701052df1282ba8b5e3eb62b5dc7973ac40160e00722fa958d95102fc25c549d8c0e84bed95b7acb61ba65700c4de4feebf78d13b9682c52e937d23026fb4c6193e6644e2d3c99f91f4f39a8b9fc6d013f89c3793ef703987954dc0412b550652c01d922f525704d32d70d6d4079bc3551b563fb29577b3aecdc9505011701dddfd94830431e7a4918927ee44fb3831ce8c4513839e2deea1287f3fa1ab9b61a256c09637dbc7b4f0f8fbb783840f9c24526da883b0df0c473cf231656bd7bc1aaba7f321fec0971c8c2c3444bff2f55e1df7fea66ec3e440a612db9aa87bb505163a59e06b96d46f50d8120b92814ac5ab146bc78dbbf91065af26107815678ce6e33812e6bf3285d4ef3b7b04b076f21e7820dcbfdb4ad5218cf4ff6a65812d8fcb98ecc1e95e2fa58e3efe4ce26cd0bd400d6036ab2ad4f6c713082b5e3f1e04eb9e3b6c8f63f57953894b9e220e0130308e1fd91f72d398c1e7962ca2c31be83f31d6157633581a0a6910496de8d55d3d07090b6aa087159e388b7e7dec60f5d8a60d93ca2ae91296bd484d916bfaaa17c8f45ea4b1a91b37c82821199a2b7596672c37156d8701e7352aa48671d3b1bbbd2bd5f0a2268894a25b0cb2514af39c8743f8cce8ab4b523053739fd8a522222a09acf51ac704489cf17e4b7125455cb8f125b4d31af1eba1f8cf7f81a5a100a141a7ee72e8083e065616649c241f233645c5fc865d17f0285f5c52d9f45312c979bfb3ce5f2a1b951deddf280ffb3f370410cffd1583bfa90077835aa201a0712d1dcd1293ee177738b14e6b5e2a496d05220c3253bb6578d6aff774be91946a614dd7e879fb3dcf7451e0b9adb6a8c44f53c2c464bcc0019e9fad89cac7791a0a3f2974f759a9856351d4d2d7c5612c17cfc50f8479945df57716767b120a590f4bf656f4645029a525694d8a238446c5f5c2c1c995c09c1405b8b1eb9e0352ffdf766cc964f8dcf9f8f043dfab6d102cf4b298021abd78f1d9025fa1f8e1d710b38d9d1652f2d88d1305874ec41609b6617b65c5adb19b6295dc5c5da5fdf69f28144ea12f17c3c6fcce6b9b5157b3dfc969d6725fa5b098a4d9b1d31547ed4c9187452d281d0a5d456008caf1aa251fac8f950ca561982dc2dc908d3691ee3b6ad3ae3d22d002577264ca8e49c523bd51c4846be0d198ad9407bf6f7b82c79893eb2c05fe9981f687a97a4f01fe45ff8c8b7ecc551135cd960a0d6001ad35020be07ffb53cb9e731522ca8ae9364628914b9b8e8cc2f37f03393263603cc2b45295767eb0aac29b0930390eb89587ab2779d2e3decb8042acece725ba42eda650863f418f8d0d50d104e44fbbe5aa7389a4a144a8cecf00f45fb14c39112f9bfb56c0acbd44fa3ff261f5ce4acaa5134c2c1d0cca447040820c81ab1bcdc16aa075b7c68b10d06bbb7ce08b5b805e0238f24402cf24a4b4e00701935a0c68add3de090903f9b85b153cb179a582f57113bfc21c2093803f0cfa4d9d4672c2b05a24f7e4c34a8e9101b70303a7378b9c50b6cddd46814ef7fd73ef6923feceab8fc5aa8b0d185f2e83c7a99dcb1077c0ab5c1f5d5f01ba2f0420443f75c4417db9ebf1665efbb33dca224989920a64b44dc26f682cc77b4632c8454d49135e52503da855bc0f6ff8edc1145451a9772c06891f41064036b66c3119a0fc6e80dffeb65dc456108b7ca0296f4175fff3ed2b0f842cd46bd7e86f4c62dfaf1ddbf836263c00b34803de164983d0811cebfac86e7720c726d3048934c36c23189b02386a722ca9f0fe00233ab50db928d3bccea355cc681144b8b7edcaae4884d5a8f04425c0890ae2c74326e138066d8c05f4c82b29df99b034ea727afde590a1f2177ace3af99cfb1729d6539ce7f7f7314b046aab74497e63dd399e1f7d5f16517c23bd830d1fdee810f3c3b77573dd69c4b97d80d71fb5a632e00acdfa4f8e829faf3580d6a72c40b28a82172f8dcd4627663ebf6069736f21735fd84a226f427cd06bb055f94e7c92f31c48075a2955d82a5b9d2d0198ce0d4e131a112570a8ee40fb80462a81436a58e7db4e34b6e2c422e82f934ecda9949893da5730fc5c23c7c920f363f85ab28cc6a4206713c3152669b47efa8238fa826735f17b4e78750276162024ec85458cd5808e06f40dd9fd43775a456a3ff6cae90550d76d8b2899e0762ad9a371482b3e38083b1274708301d6346c22fea9bb4b73db490ff3ab05b2f7f9e187adef139a7794454b7300b8cc64d3ad76c0e4bc54e08833a4419251550655380d675bc91855aeb82585220bb97f03e976579c08f321b5f8f70988d3061f41465517d53ac571dbf1b24b94443d2e9a8e8a79b392b3d6a4ecdd7f626925c365ef6221305105ce9b5f5b6ecc5bed3d702bd4b7f5008aa8eb8c7aa3ade8ecf6251516fbefeea4e1082aa0e1848eddb31ffe44b04792d296054402826e4bd054e671f223e5557e4c94f89ca01c25c44f1a2ff2c05a70b43408250705e1b858bf0670679fdcd379203e36be3500dd981b1a6422c3cf15224f7fefdef0a5f225c5a09d15767598ecd9e262460bb33a4b5d09a64591efabc57c923d3be406979032ae0bc0997b65336a06dd75b253332ad6a8b63ef043f780a1b3fb6d0b6cad98b1ef4a02535eb39e14a866cfc5fc3a9c5deb2261300d71280ebe66a0776a151469551c3c5fa308757f956655278ec6330ae9e3625468c5f87e02cd9a6489910d4143c1f4ee13aa21a6859d907b788e28572fecee273d44e4a900fa0aa668dd861a60fb6b6b12c2c5ef3c8df1bd7ef5d4b0d1cdb8c15fffbb365b9784bd94abd001c6966216b9b67554ad7cb7f958b70092514f7800fc40244003e0fd1133a9b850fb17f4fcafde07fc87b07fb510670654a5d2d6fc9876ac74728ea41593beef003d6858786a52d3a40af7529596767c17000bfaf8dc52e871359f4ad8bf6e7b2853e5229bdf39657e213580294a5317c5df172865e1e17fe37093b585e04613f5f078f761b2b1752eb32983afda24b523af8851df9a02b37e77f543f18888a782a994a50563334282bf9cdfccc183fdf4fcd75ad86ee0d94f91ee2300a5befbccd14e03a77fc031a8cfe4f01e4c5290f5ac1da0d58ea054bd4837cfd93e5e34fc0eb16e48044ba76131f228d16cde9b0bb978ca7cdcd10653c358bdb26fdb723a530232c32ae0a4cecc06082f46e1c1d596bfe60621ad1e354e01e07b040cc7347c016653f44d926d13ca74e6cbc9d4ab4c99f4491c95c76fff5076b3936eb9d0a286b97c035ca88a3c6309f5febfd4cdaac869e4f58ed409b1e9eb4192fb2f9c2f12176d460fd98286c9d6df84598f260119fd29c63f800c07d8df83d5cc95f8c2fea2812e7890e8a0718bb1e031ecbebc0436dcf3e3b9a58bcc06b4c17f711f80fe1dffc3326a6eb6e00283055c6dabe20d311bfd5019591b7954f8163c9afad9ef8390a38f3582e0a79cdf0353de8eeb6b5f9f27b16ffdef7dd62869b4840ee226ccdce95e02c4545eb981b60571cd83f03dc5eaf8c97a0829a4318a9b3dc06c0e003db700b2260ff1fa8fee66890e637b109abb03ec901b05ca599775f48af50154c0e67d82bf0f558d7d3e0778dc38bea1eb5f74dc8d7f90abdf5511a424be66bf8b6a3cacb477d2e7ef4db68d2eba4d5289122d851f9501ba7e9c4957d8eba3be3fc8e785c4265a1d65c46f2809b70846c693864b169c9dcb78be26ea14b8613f145b01887222979a9e67aee5f800caa6f5c4229bdeefc901232ace6143c9865e4d9c07f51aa200afaf7e48a7d1d8faf366023beab12906ffcb3eaf72c0eb68075e4daf3c080e0c31911befc16f0cc4a09908bb7c1e26abab38bd7b788e1a09c0edf1a35a38d2ff1d3ed47fcdaae2f0934224694f5b56705b9409b6d3d64f3833b686f7576ec64bbdd6ff174e56c2d1edac0011f904681a73face26573fbba4e34652f7ae84acfb2fa5a5b3046f98178cd0831df7477de70e06a4c00e305f31aafc026ef064dd68fd3e4252b1b91d617b26c6d09b6891a00df68f105b5962e7f9d82da101dd595d286da721443b72b2aba2377f6e7772e33b3a5e3753da9c2578c5d1daab80187f55518c72a64ee150a7cb5649823c08c9f62cd7d020b45ec2cba8310db1a7785a46ab24785b4d54ff1660b5ca78e05a9a55edba9c60bf044737bc468101c4e8bd1480d749be5024adefca1d998abe33eaeb6b11fbb39da5d905fdd3f611b2e51517ccee4b8af72c2d948573505590d61a6783ab7278fc43fe55b1fcc0e7216444d3c8039bb8145ef1ce01c50e95a3f3feab0aee883fdb94cc13ee4d21c542aa795e18932228981690f4d4c57ca4db6eb5c092e29d8a05139d509a8aeb48baa1eb97a76e597a32b280b5e9d6c36859064c98ff96ef5126130264fa8d2f49213870d9fb036cff95da51f270311d9976208554e48ffd486470d0ecdb4e619ccbd8226147204baf8e235f54d8b1cba8fa34a9a4d055de515cdf180d2bb6739a175183c472e30b5c914d09eeb1b7dafd6872b38b48c6afc146101200e6e6a44fe5684e220adc11f5c403ddb15df8051e6bdef09117a3a5349938513776286473a3cf1d2788bb875052a2e6459fa7926da33380149c7f98d7700528a60c954e6f5ecb65842fde69d614be69eaa2040a4819ae6e756accf936e14c1e894489744a79c1f2c1eb295d13e2d767c09964b61f9cfe497649f712").unwrap(); let auth = alice_packet_handler .packet_writer - .encrypt_packet_with_alloc(&contents, Some(&aad), PacketType::Genuine) + .encrypt_packet(&contents, Some(&aad), PacketType::Genuine) .unwrap(); let challenge = Vec::from_hex("8da7de6ea7bf2a81a396a42880ba1f5756734c4821309ac9aeffa2a26ce86873b9dc4935a772de6ec5162c6d075b14536800fb174841153511bfb597e992e2fe8a450c4bce102cc550bb37fd564c4d60bf884e").unwrap(); assert_eq!(auth, challenge); @@ -1712,12 +1703,12 @@ mod tests { for _ in 0..223 { alice_packet_handler .packet_writer - .encrypt_packet_with_alloc(&Vec::new(), None, PacketType::Decoy) + .encrypt_packet(&Vec::new(), None, PacketType::Decoy) .unwrap(); } let enc = alice_packet_handler .packet_writer - .encrypt_packet_with_alloc(&contents, None, PacketType::Decoy) + .encrypt_packet(&contents, None, PacketType::Decoy) .unwrap(); assert!( enc.to_lower_hex_string().ends_with("729847a3e9eba7a5bff454b5de3b393431ee360736b6c030d7a5bd01d1203d2e98f528543fd2bf886ccaa1ada5e215a730a36b3f4abfc4e252c89eb01d9512f94916dae8a76bf16e4da28986ffe159090fe5267ee3394300b7ccf4dfad389a26321b3a3423e4594a82ccfbad16d6561ecb8772b0cb040280ff999a29e3d9d4fd"), @@ -1745,12 +1736,12 @@ mod tests { for _ in 0..448 { alice_packet_handler .packet_writer - .encrypt_packet_with_alloc(&Vec::new(), None, PacketType::Genuine) + .encrypt_packet(&Vec::new(), None, PacketType::Genuine) .unwrap(); } let enc = alice_packet_handler .packet_writer - .encrypt_packet_with_alloc(&contents, None, PacketType::Genuine) + .encrypt_packet(&contents, None, PacketType::Genuine) .unwrap(); assert!( enc.to_lower_hex_string().ends_with("77b4656934a82de1a593d8481f020194ddafd8cac441f9d72aeb8721e6a14f49698ca6d9b2b6d59d07a01aa552fd4d5b68d0d1617574c77dea10bfadbaa31b83885b7ceac2fd45e3e4a331c51a74e7b1698d81b64c87c73c5b9258b4d83297f9debc2e9aa07f8572ff434dc792b83ecf07b3197de8dc9cf7be56acb59c66cff5"), @@ -1783,12 +1774,12 @@ mod tests { for _ in 0..673 { alice_packet_handler .packet_writer - .encrypt_packet_with_alloc(&Vec::new(), None, PacketType::Genuine) + .encrypt_packet(&Vec::new(), None, PacketType::Genuine) .unwrap(); } let enc = alice_packet_handler .packet_writer - .encrypt_packet_with_alloc(&contents, None, PacketType::Genuine) + .encrypt_packet(&contents, None, PacketType::Genuine) .unwrap(); assert!( enc.to_lower_hex_string().ends_with("657a4a19711ce593c3844cb391b224f60124aba7e04266233bc50cafb971e26c7716b76e98376448f7d214dd11e629ef9a974d60e3770a695810a61c4ba66d78b936ee7892b98f0b48ddae9fcd8b599dca1c9b43e9b95e0226cf8d4459b8a7c2c4e6db80f1d58c7b20dd7208fa5c1057fb78734223ee801dbd851db601fee61e"), @@ -1821,12 +1812,12 @@ mod tests { for _ in 0..1024 { alice_packet_handler .packet_writer - .encrypt_packet_with_alloc(&Vec::new(), None, PacketType::Genuine) + .encrypt_packet(&Vec::new(), None, PacketType::Genuine) .unwrap(); } let enc = alice_packet_handler .packet_writer - .encrypt_packet_with_alloc(&contents, None, PacketType::Decoy) + .encrypt_packet(&contents, None, PacketType::Decoy) .unwrap(); assert!( enc.to_lower_hex_string().ends_with("7c4b9e1e6c1ce69da7b01513cdc4588fd93b04dafefaf87f31561763d906c672bac3dfceb751ebd126728ac017d4d580e931b8e5c7d5dfe0123be4dc9b2d2238b655c8a7fadaf8082c31e310909b5b731efc12f0a56e849eae6bfeedcc86dd27ef9b91d159256aa8e8d2b71a311f73350863d70f18d0d7302cf551e4303c7733"), diff --git a/protocol/tests/round_trips.rs b/protocol/tests/round_trips.rs index aa3ff82..5b75a8a 100644 --- a/protocol/tests/round_trips.rs +++ b/protocol/tests/round_trips.rs @@ -33,10 +33,10 @@ fn hello_world_happy_path() { .unwrap(); init_handshake - .authenticate_garbage_and_version_with_alloc(&resp_message[64..]) + .authenticate_garbage_and_version(&resp_message[64..]) .unwrap(); resp_handshake - .authenticate_garbage_and_version_with_alloc(&init_finalize_message) + .authenticate_garbage_and_version(&init_finalize_message) .unwrap(); let mut alice = init_handshake.finalize().unwrap(); @@ -46,28 +46,28 @@ fn hello_world_happy_path() { let message = b"Hello world".to_vec(); let encrypted_message_to_alice = bob .writer() - .encrypt_packet_with_alloc(&message, None, PacketType::Genuine) + .encrypt_packet(&message, None, PacketType::Genuine) .unwrap(); let messages = alice .reader() - .decrypt_payload_with_alloc(&encrypted_message_to_alice[3..], None) + .decrypt_payload(&encrypted_message_to_alice[3..], None) .unwrap(); assert_eq!(message, messages.contents()); let message = b"Goodbye!".to_vec(); let encrypted_message_to_bob = alice .writer() - .encrypt_packet_with_alloc(&message, None, PacketType::Genuine) + .encrypt_packet(&message, None, PacketType::Genuine) .unwrap(); let messages = bob .reader() - .decrypt_payload_with_alloc(&encrypted_message_to_bob[3..], None) + .decrypt_payload(&encrypted_message_to_bob[3..], None) .unwrap(); assert_eq!(message, messages.contents()); } #[test] #[cfg(feature = "std")] -#[ignore = "Requires a running bitcoin daemon."] +#[ignore = "requires a running bitcoin daemon."] fn regtest_handshake() { use std::{ io::{Read, Write}, @@ -113,7 +113,7 @@ fn regtest_handshake() { let response = &mut max_response[..size]; println!("Authenticating the handshake"); handshake - .authenticate_garbage_and_version_with_alloc(response) + .authenticate_garbage_and_version(response) .unwrap(); println!("Finalizing the handshake"); let packet_handler = handshake.finalize().unwrap(); @@ -137,7 +137,7 @@ fn regtest_handshake() { }; let message = serialize(NetworkMessage::Version(msg)).unwrap(); let packet = encrypter - .encrypt_packet_with_alloc(&message, None, PacketType::Genuine) + .encrypt_packet(&message, None, PacketType::Genuine) .unwrap(); println!("Serializing and writing version message"); stream.write_all(&packet).unwrap(); @@ -147,9 +147,7 @@ fn regtest_handshake() { let message_len = decrypter.decypt_len(response_len); let mut response_message = vec![0; message_len]; stream.read_exact(&mut response_message).unwrap(); - let msg = decrypter - .decrypt_payload_with_alloc(&response_message, None) - .unwrap(); + let msg = decrypter.decrypt_payload(&response_message, None).unwrap(); let message = deserialize(msg.contents()).unwrap(); assert_eq!(message.cmd(), "version"); }