Skip to main content

Tutorial 6 — QKD Key Exchange (BB84)

Objective: Run the run_qkd() protocol between two nodes and inspect the BB84 security metrics: QBER, secret key length, and efficiency rate.

Quantum Key Distribution (QKD) uses entanglement distribution as its physical layer to establish a shared secret key. The BB84 protocol is the most widely deployed QKD scheme. qnet-core simulates this protocol end-to-end using the underlying entanglement engine.

Define the Network

from qnet_core import QNetEngine, NodeDefinition, LinkDefinition, QKDParameters

engine = QNetEngine()

nodes = [
NodeDefinition(id="Alice", memory_lifetime_t2=1.0),
NodeDefinition(id="Bob", memory_lifetime_t2=1.0),
]

links = [
LinkDefinition("Alice", "Bob", distance_km=10.0, base_fidelity=0.95,
generation_rate_hz=1_000.0),
]

engine.define_network(nodes, links)

Configure QKD Protocol Parameters

qkd_params = QKDParameters(
from_node="Alice",
to_node="Bob",
fidelity_target=0.90, # minimum entanglement fidelity
max_latency_ms=10_000.0, # protocol timeout
rounds=200, # number of BB84 signal rounds
error_rate_tolerance=0.11, # BB84 threshold — abort if QBER > this
sifting_overhead_ratio=0.5, # fraction lost during basis reconciliation
privacy_amplification_factor=0.8, # compression for security proof
)

Execute the Protocol

result = engine.run_qkd(qkd_params)

print("=== BB84 QKD Key Exchange ===")
print(f"Success: {result.success}")
print(f"Secret key length: {result.secret_key_length_bits} bits")
print(f"Efficiency rate: {result.efficiency_rate:.4f}")
print(f"QBER: {result.qber:.4f}")
print(f"Latency: {result.latency_ms:.1f} ms")
print(f"Path: {' → '.join(result.execution_path)}")
print(f"Rounds completed: {result.rounds_completed} / {qkd_params.rounds}")
print(f"Rounds failed: {result.rounds_failed}")

Result Fields

FieldTypeDescription
successboolWhether a secure key was established
secret_key_length_bitsintLength of the final secret key in bits
efficiency_ratefloatKey generation efficiency [0, 1] — ratio of output bits to input rounds
qberfloatQuantum Bit Error Rate — if QBER > error_rate_tolerance, the protocol aborts
latency_msfloatTotal protocol latency (entanglement + classical post-processing)
execution_pathList[str]Node IDs traversed during entanglement distribution
rounds_completedintNumber of successful round-end measurements
rounds_failedintNumber of rounds that failed (link generation failure or decoherence)

QKD Protocol Flow

  1. Entanglement distribution — engine establishes entangled pairs between Alice and Bob
  2. Basis sifting — each party randomly measures in one of two bases; sifting_overhead_ratio controls wasted rounds
  3. QBER estimation — compare a subset of results; if error rate exceeds tolerance, abort
  4. Privacy amplification — compress the sifted key to eliminate eavesdropper information
QKDStats (Planned)

The QKDStats Monte Carlo ensemble type is planned but not yet implemented. run_qkd() currently returns a single QKDResult. To estimate statistics, call simulate() on the engine and check each result's success field.

What's next