  Device-independent security is the gold standard for quantum cryptography:
not only is security based entirely on the laws of quantum mechanics, but it
holds irrespective of any a priori assumptions on the quantum devices used in a
protocol, making it particularly applicable in a quantum-wary environment.
While the existence of device-independent protocols for tasks such as
randomness expansion and quantum key distribution has recently been
established, the underlying proofs of security remain very challenging, yield
rather poor key rates, and demand very high-quality quantum devices, thus
making them all but impossible to implement in practice.
  We introduce a technique for the analysis of device-independent cryptographic
protocols. We provide a flexible protocol and give a security proof that
provides quantitative bounds that are asymptotically tight, even in the
presence of general quantum adversaries. At a high level our approach amounts
to establishing a reduction to the scenario in which the untrusted device
operates in an identical and independent way in each round of the protocol.
This is achieved by leveraging the sequential nature of the protocol, and makes
use of a newly developed tool, the "entropy accumulation theorem" of Dupuis et
al.
  As concrete applications we give simple and modular security proofs for
device-independent quantum key distribution and randomness expansion protocols
based on the CHSH inequality. For both tasks we establish essentially optimal
asymptotic key rates and noise tolerance. In view of recent experimental
progress, which has culminated in loophole-free Bell tests, it is likely that
these protocols can be practically implemented in the near future.
