hopr_crypto_packet/
lib.rs

1//! # core-packet
2//!
3//! This crate contains the main packet processing functionality for the HOPR protocol.
4//! It implements the following important protocol building blocks:
5//!
6//! - SPHINX packet format (module [packet])
7//! - Proof of Relay (module [por])
8//!
9//! Finally, it also implements a utility function which is used to validate tickets (module `validation`).
10//! The ticket validation functionality is dependent on `chain-db`.
11//!
12//! The currently used implementation is selected using the `CurrentSphinxSuite` type in the `packet` module.
13//!
14//! The implementation can be easily extended for different elliptic curves (or even arithmetic multiplicative groups).
15//! In particular, as soon as there's way to represent `Ed448` PeerIDs, it would be easy to create e.g. `X448Suite`.
16//!
17
18/// Implements the overlay packet intermediary object.
19pub mod chain;
20/// Enumerates all errors in this crate.
21pub mod errors;
22/// Implements SPHINX packet format.
23pub mod packet;
24/// Implements the Proof of Relay.
25pub mod por;
26/// Implements ticket validation logic.
27pub mod validation;
28
29/// Currently used public key cipher suite for Sphinx.
30pub type CurrentSphinxSuite = hopr_crypto_sphinx::ec_groups::X25519Suite;
31
32#[cfg(test)]
33mod tests {
34    use super::*;
35    use crate::chain::ChainPacketComponents;
36    use crate::packet::{packet_length, MetaPacket};
37    use crate::por::POR_SECRET_LENGTH;
38    use hopr_crypto_sphinx::routing::header_length;
39    use hopr_internal_types::prelude::*;
40    use hopr_primitive_types::prelude::*;
41
42    #[test]
43    fn header_and_packet_lengths() {
44        let header_len = header_length::<CurrentSphinxSuite>(INTERMEDIATE_HOPS + 1, POR_SECRET_LENGTH, 0);
45        assert_eq!(MetaPacket::<CurrentSphinxSuite>::HEADER_LEN, header_len); // 394 bytes
46
47        let packet_len = packet_length::<CurrentSphinxSuite>(INTERMEDIATE_HOPS + 1, POR_SECRET_LENGTH, 0);
48        assert_eq!(MetaPacket::<CurrentSphinxSuite>::PACKET_LEN, packet_len); // 968 bytes
49
50        let hopr_packet_len = ChainPacketComponents::SIZE;
51        assert_eq!(
52            MetaPacket::<CurrentSphinxSuite>::PACKET_LEN + Ticket::SIZE,
53            hopr_packet_len
54        ); // 1116 bytes
55
56        assert!(hopr_packet_len < 1492, "HOPR packet must fit within a layer 4 packet");
57    }
58}