Expand description
Implements the HS ntor key exchange, as used in v3 onion services.
The Ntor protocol of this section is specified in section [NTOR-WITH-EXTRA-DATA] of rend-spec-v3.txt.
The main difference between this HS Ntor handshake and the regular Ntor handshake in ./ntor.rs is that this one allows each party to encrypt data (without forward secrecy) after it sends the first message. This opportunistic encryption property is used by clients in the onion service protocol to encrypt introduction data in the INTRODUCE1 cell, and by services to encrypt data in the RENDEZVOUS1 cell.
Β§Status
This module is available only when the hs-common feature is enabled. The
specific handshakes are enabled by hs-client and hs-service.
Re-exportsΒ§
use crate::crypto::handshake::KeyGenerator;πuse crate::crypto::ll::kdf::Kdf;πuse crate::crypto::ll::kdf::ShakeKdf;πuse crate::util::ct;πuse crate::Error;πuse crate::Result;πuse std::result::Result as StdResult;πuse tor_bytes::Reader;πuse tor_bytes::SecretBuf;πuse tor_bytes::Writer;πuse tor_hscrypto::Subcredential;πuse tor_hscrypto::ops::HS_MAC_LEN;πuse tor_hscrypto::ops::hs_mac;πuse tor_hscrypto::pk::HsIntroPtSessionIdKey;πuse tor_hscrypto::pk::HsSvcNtorKey;πuse tor_llcrypto::pk::curve25519;πuse tor_llcrypto::pk::ed25519;πuse tor_llcrypto::util::ct::CtByteArray;πuse cipher::KeyIvInit;πuse cipher::StreamCipher;πuse subtle::ConstantTimeEq as _;πuse tor_error::into_internal;πuse tor_llcrypto::cipher::aes::Aes256Ctr;πuse zeroize::Zeroize as _;πuse zeroize::Zeroize as _;πuse zeroize::Zeroizing;πuse tor_hscrypto::pk::HsSvcNtorKeypair;π
StructsΒ§
- HsNtor
Client State - Client state for an ntor handshake.
- HsNtor
Hkdf KeyGenerator - The key generator used by the HS ntor handshake. Implements the simple key expansion protocol specified in section βKey expansionβ of rend-spec-v3.txt .
- HsNtor
Service Info - Information about an onion service that is needed for a client to perform an hs_ntor handshake with it.
ConstantsΒ§
- INTR
O1_ πTARGET_ LEN - Default target length for our generated Introduce1 messages.
FunctionsΒ§
- encrypt_
and_ πmac - Encrypt the βplaintextβ using βenc_keyβ. Then compute the intro cell MAC
using βmac_keyβ over the text
(other_text, public_key, plaintext)and return (ciphertext, mac_tag). - get_
introduce_ πkey_ material - Helper function: Compute the part of the HS ntor handshake that generates key material for creating and handling INTRODUCE1 cells. Function used by both client and service. Specifically, calculate the following:
- get_
rendezvous_ πkey_ material - Helper function: Compute the last part of the HS ntor handshake which derives key material necessary to create and handle RENDEZVOUS1 cells. Function used by both client and service. The actual calculations is as follows:
- server_
receive_ intro - Conduct the HS Ntor handshake as the service.
- server_
receive_ πintro_ no_ keygen - Helper: Like server_receive_intro, but take an ephemeral key rather than a RNG.
Type AliasesΒ§
- Auth
Input πMac - The AUTH_INPUT_MAC from the HS Ntor protocol
- EncKey π
- The ENC_KEY from the HS Ntor protocol
- MacKey π
- The MAC_KEY from the HS Ntor protocol
- MacTag π
- A generic 256-bit MAC tag