MCPcopy Index your code
hub / github.com/conradludgate/rustyguard

github.com/conradludgate/rustyguard @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
396 symbols 891 edges 52 files 69 documented · 17%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

RustyGuard

A WireGuard(R) implementation in pure Rust.

Project Goals

  • [x] #![forbid(unsafe_code)]
  • [x] zerocopy/sans-io API design.
  • [x] blazingly fast, low overhead.
  • [x] works as a tun virtual network device.
  • [x] embeddable into applications:
    • Like how you might terminate TLS at the application level.
  • [x] embeddable into microcontrollers:
    • [x] no-std compatible.
    • [ ] no-alloc compatible.
  • [ ] hard to fuck up.
  • [ ] clean code, for my definition of clean.

What is this?

WireGuard(R) is a protocol for secure tunnels, as a building block for Virtual Private Networks.

This project, RustyGuard, is an "unmanaged" memory safe implementation of the WireGuard.

Unmanaged in this context means it is an application developer's responsibility to process UDP packets going in and out of the RustyGuard interface - as well as manage IP routing etc. RustyGuard will only take care of the byte processing and the cryptography.

You can see the tun example codebase to see what that looks like. In that file we: 1. Manage the IP routing rules with the iptrie crate. 2. Manage the UDP socket 3. Manage the TUN interface using the tun crate.

This library is zero-copy where possible. WireGuard(R) has been designed with this in mind. The only parsing we need to do is: 1. Check the first byte for the message type. 2. Check the message length.

This makes it very easy to avoid both buffer exploits, as well as reducing bounds-check overhead as we only need to perform 1 bounds check. This comes courtesy of zerocopy.

This also means we can focus on the things that actually matter, the cryptography, the key schedule, and the timing system.

Embedding into applications

[!NOTE] This article is a stub

Much like with rustls or openssl, you can embed rustyguard into your applications. Unlike TLS, WireGuard(R) is not a client-server architecture but is instead peer-to-peer. However, WireGuard(R) can support client-server models just fine - the client will configure the server peer to have a known endpoint, whereas the server will not specify any known endpoints for the client peers.

To effectively make use of this crate in an application setting, you will likely need to provide your own userspace TCP stack. See smoltcp for a possible crate to provide this. I would like to eventually provide a wrapper library that provides a simple Read/Write wrapper on top of rustyguard that does this for you.

Embedding into microcontrollers

[!NOTE] This article is a stub

Because rustyguard is #![no_std], it supports most embedded devices with little effort. Only need an allocator. All the allocations currently performed by rustyguard could be replaced with heapless to truly be no-alloc and support most embedded targets. However, It is still necessary for the application developer to provide: 1. UDP Network 2. Time 3. Cryptographic RNG

Project TODO:

  • [ ] Overload detection for DDoS mitigation
  • [x] Reject data packet replay with sliding counter window bitset
  • [ ] More efficient timer management
  • [ ] Optional multithreadding support
  • [ ] Live peer updating

[!NOTE] "WireGuard" and the "WireGuard" logo are registered trademarks of Jason A. Donenfeld.

Extension points exported contracts — how you extend this code

IntoAddress (Interface)
(no doc) [15 implementers]
rustyguard-tun/src/tun/address.rs
HasMac (Interface)
Both handshake messages are protected via MACs which can quickly be used to rule out invalid messages. The first MAC ve
rustyguard-crypto/src/lib.rs
Device (Interface)
A TUN device.
rustyguard-tun/src/tun/device.rs
CryptoPrimatives (Interface)
(no doc) [1 implementers]
rustyguard-crypto/src/prim.rs
Encrypted (Interface)
(no doc)
rustyguard-crypto/src/prim.rs

Core symbols most depended-on inside this repo

exec
called by 25
tests/e2e/rustyguard_e2e/provider.py
recv_message
called by 15
rustyguard-core/src/lib.rs
get_mut
called by 12
rustyguard-core/src/lib.rs
parse
called by 12
rustyguard-tun/src/lib.rs
as_ptr
called by 11
rustyguard-tun/src/tun/platform/posix/sockaddr.rs
data
called by 10
rustyguard-core/src/lib.rs
as_raw_fd
called by 8
rustyguard-tun/src/tun/platform/macos/device.rs
split
called by 7
rustyguard-crypto/src/prim.rs

Shape

Method 206
Function 99
Class 76
Enum 10
Interface 5

Languages

Rust77%
Python23%

Modules by API surface

rustyguard-core/src/lib.rs52 symbols
rustyguard-crypto/src/prim.rs40 symbols
rustyguard-crypto/src/lib.rs26 symbols
rustyguard-tun/src/tun/platform/macos/device.rs24 symbols
rustyguard-tun/src/tun/platform/linux/device.rs22 symbols
rustyguard-core/examples/server.rs18 symbols
tests/e2e/rustyguard_e2e/providers/lima.py16 symbols
rustyguard-types/src/lib.rs15 symbols
tests/e2e/conftest.py13 symbols
tests/e2e/rustyguard_e2e/providers/orb.py12 symbols
tests/e2e/rustyguard_e2e/providers/multipass.py12 symbols
tests/e2e/rustyguard_e2e/provider.py12 symbols

For agents

$ claude mcp add rustyguard \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact