Skip to main content

Module hs_ntor

Module hs_ntor 

Source
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Β§

HsNtorClientState
Client state for an ntor handshake.
HsNtorHkdfKeyGenerator
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 .
HsNtorServiceInfo
Information about an onion service that is needed for a client to perform an hs_ntor handshake with it.

ConstantsΒ§

INTRO1_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Β§

AuthInputMac πŸ”’
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