veyron/runtimes/google/ipc/stream/crypto: use nacl/crypto_box
nacl/box is a well-studied, simple and robust public key encryption
scheme. A plain C implementation of the box function is less than 400
lines without any external dependencies (tweetnacl), compared to current
TLS implementations that consist of tens of thousands of lines. Chrome,
Quic, Tor, OpenSSH, ZeroMQ, End-to-End and other applications have recently
adopted a variant of nacl/box as several dreadful bugs have been found
in common implementations of either TLS or the cryptographic primitives
it uses. In particular, the Go crypto/tls package is not considered
production ready because timing-based attacks are not prevented.
Currently, Veyron is essentially using TLS as a glorified Diffie-Hellman
key exchange implementation -- all the complicated
public-key-infrastructure-related features are not needed at all.
This change implements the connection encryption hinted at in the end of
the spec (http://nacl.cr.yp.to/box.html). This change is here mostly for
experimentation, but it could in principle replace our use of TLS
entirely. Currently, replacing all uses of TLS in the codebase with the
implementation results in all non-TLS-specifc tests passing.
BenchmarkTLSEncrypt_1B: 0.57 MB/s; BenchmarkBoxEncrypt_1B: 1.23 MB/s
BenchmarkTLSEncrypt_5M: 272.84 MB/s; BenchmarkBoxEncrypt_5M: 596.14 MB/s.
BenchmarkRoundTrip results are essentially the same (134 MB/s at 5M).
TLS has 25 bytes of per-message overhead, box has 16.
Change-Id: Ia313b1a78467317e994d66897b23fd1a7888320f
2 files changed