Code Monkey home page Code Monkey logo

monte's Introduction

monte

MIT License go.dev reference Discord Chat

The bare minimum for high performance, fully-encrypted RPC over TCP in Go.

Features

  1. Send requests, receive responses, or send messages without waiting for a response.
  2. Send from 50MiB/s to 1500MiB/s, with zero allocations per sent message or RPC call.
  3. Gracefully establish multiple client connections to a single endpoint up to a configurable limit.
  4. Set the total number of connections that may concurrently be accepted and handled by a single endpoint.
  5. Configure read/write timeouts, dial timeouts, handshake timeouts, or customize the handshaking protocol.
  6. All messages, once the handshake protocol is complete, are encrypted and non-distinguishable from each other.
  7. Supports graceful shutdowns for both client and server, with extensive tests for highly-concurrent scenarios.

Protocol

Handshake

  1. Send X25519 curve point (32 bytes) to peer.
  2. Receive X25519 curve point (32 bytes) from our peer.
  3. Multiply X25519 curve scalar with X25519 curve point received from our peer.
  4. Derive a shared key by using BLAKE-2b as a key derivation function over our scalar point multiplication result.
  5. Encrypt further communication with AES 256-bit GCM using our shared key, with a nonce counter increasing for every incoming/outgoing message.

Message Format

  1. Encrypted messages are prefixed with an unsigned 32-bit integer denoting the message's length.
  2. The decoded message content is prefixed with an unsigned 32-bit integer designating a sequence number.
  3. The sequence number is used as an identifier to identify requests/responses from one another.
  4. The sequence number 0 is reserved for requests that do not expect a response.

Benchmarks

$ cat /proc/cpuinfo | grep 'model name' | uniq
model name : Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz

$ go test -bench=. -benchtime=10s
goos: linux
goarch: amd64
pkg: github.com/lithdew/monte
BenchmarkSend-8                          1814391              6690 ns/op         209.27 MB/s         115 B/op          0 allocs/op
BenchmarkSendNoWait-8                   10638730              1153 ns/op        1214.19 MB/s         141 B/op          0 allocs/op
BenchmarkRequest-8                        438381             28556 ns/op          49.03 MB/s         140 B/op          0 allocs/op
BenchmarkParallelSend-8                  4917001              2876 ns/op         486.70 MB/s         115 B/op          0 allocs/op
BenchmarkParallelSendNoWait-8           10317255              1291 ns/op        1084.78 MB/s         150 B/op          0 allocs/op
BenchmarkParallelRequest-8               1341444              8520 ns/op         164.32 MB/s         140 B/op          0 allocs/op

monte's People

Contributors

lithdew avatar thesmallboat avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

monte's Issues

Improve Session misuse resistance

Me again! Hopefully I'm actually correct this time...

Since SessionConn always uses a counter starting at 1 for its GCM nonce, it must never be used with the same encryption key twice. Consider at least documenting this constraint, or if possible don't export SessionConn at all.

Similarly, a single Session must never be reused to connect to the same peer Session twice (since it would then generate the same shared key, violating the requirement above). Here I believe there is a simple fix: move the key generation from NewSession to Establish; as a bonus, you then don't even need to store ourPriv on Session.

Take a look at https://noiseprotocol.org/noise.html (especially section 14).

Session message limits / renegotiation

Though I haven't carefully analyzed the entire code base, it doesn't appear that there is any mitigation for overflowing the GCM counter in a session. At the claimed 1500MiB/s throughput some workloads could blow through GCM's 32-bit counter leading to AES nonce reuse, which is very bad.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.