///| test "Noise_XK_25519_ChaChaPoly_SHA256 full 3-message handshake and transport" { let alice_s = @noise.KeyPair::from_private( @encoding.hex_decode( "77076d0a7318a57d3c16c17251b26645df4c2f87ebc0992ab177fba51db92c2a", ), ) let bob_s = @noise.KeyPair::from_private( @encoding.hex_decode( "5dab087e624a8a4b79e17f8b83800ee66f3bb1292618b6fd1c2f8b27ff88e0eb", ), ) let alice_e = @noise.KeyPair::from_private( @encoding.hex_decode( "a546e36bf0527c9d3b16154b82465edd62144c0ac1fc5a18506a2244ba449ac4", ), ) let bob_e = @noise.KeyPair::from_private( @encoding.hex_decode( "4b66e9d4d1b4673c5ad22691957d6af5c11b6421e0ea01d42ca4169e7918ba0d", ), ) let alice = @noise.HandshakeState::new_initiator( alice_s, bob_s.public_key, protocol_name=@noise.ntcp2_protocol_name, ) let bob = @noise.HandshakeState::new_responder( bob_s, protocol_name=@noise.ntcp2_protocol_name, ) alice.set_ephemeral(alice_e) bob.set_ephemeral(bob_e) // Message 1: -> e, es (SessionRequest) let msg1 = alice.write_message(b"ntcp2-session-request-options") let req_pt = bob.read_message(msg1) assert_eq(req_pt, b"ntcp2-session-request-options") // Message 2: <- e, ee (SessionCreated) let msg2 = bob.write_message(b"ntcp2-session-created-options") let created_pt = alice.read_message(msg2) assert_eq(created_pt, b"ntcp2-session-created-options") // Message 3: -> s, se (SessionConfirmed) let msg3 = alice.write_message(b"alice-router-info-block") let confirmed_pt = bob.read_message(msg3) assert_eq(confirmed_pt, b"alice-router-info-block") // Split into transport sessions let alice_tx = alice.into_transport() let bob_tx = bob.into_transport() // Both sides derive identical handshake hash and authenticate peer static keys assert_eq(alice_tx.handshake_hash(), bob_tx.handshake_hash()) assert_eq(bob_tx.remote_static(), alice_s.public_key) assert_eq(alice_tx.remote_static(), bob_s.public_key) // Bidirectional encrypted data phase let ct1 = alice_tx.encrypt(b"hello bob over NTCP2") assert_eq(bob_tx.decrypt(ct1), b"hello bob over NTCP2") let ct2 = bob_tx.encrypt(b"hello alice from floodfill") assert_eq(alice_tx.decrypt(ct2), b"hello alice from floodfill") } ///| test "NTCP2 SipHash-2-4 length obfuscation round-trip" { let key = @encoding.hex_decode("000102030405060708090a0b0c0d0e0f") let iv = @encoding.hex_decode("1122334455667788") let sender = @noise.SipHashLengthMask::new(key, iv) let receiver = @noise.SipHashLengthMask::new(key, iv) let lengths : Array[UInt32] = [48U, 1024U, 16384U, 65519U] for orig in lengths { let obf = sender.xor_length(orig) assert_true(obf != orig) let restored = receiver.xor_length(obf) assert_eq(restored, orig) } }