• Stars
    star
    142
  • Rank 258,495 (Top 6 %)
  • Language
    C
  • License
    Other
  • Created almost 3 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

WireGuard Implementation for ESP-IDF

esp_wireguard, WireGuard Implementation for ESP-IDF

This is an implementation of the WireGuardยฎ for ESP-IDF, based on WireGuard Implementation for lwIP.

Build examples

Status

The code is alpha.

A single tunnel to a WireGuard peer has been working.

Supported ESP-IDF versions and targets

The following ESP-IDF versions are supported:

  • esp-idf master
  • esp-idf v4.2.x
  • esp-idf v4.3.x
  • esp-idf v4.4.x
  • ESP8266 RTOS SDK v3.4

The following targets are supported:

  • esp32
  • esp32s2
  • esp32c3
  • esp8266

Usage

In menuconfig under WireGuard, choose a TCP/IP adapter. The default is ESP-NETIF. SDKs older than esp-idf v4.1, including ESP8266 RTOS SDK v3.4 requires TCP/IP Adapter.

Both peers must have synced time. The library does not sync time.

A working network interface is required.

Create WireGuard configuration, wireguard_config_t. Use ESP_WIREGUARD_CONFIG_DEFAULT to initialize wireguard_config_t variable. Create wireguard_ctx_t. Pass the variables to esp_wireguard_init(). Then, call esp_wireguard_connect(). Call esp_wireguard_disconnect() to disconnect from the peer (and destroy the WireGuard interface).

#include <esp_wireguard.h>

esp_err_t err = ESP_FAIL;

wireguard_config_t wg_config = ESP_WIREGUARD_CONFIG_DEFAULT();

wg_config.private_key = CONFIG_WG_PRIVATE_KEY;
wg_config.listen_port = CONFIG_WG_LOCAL_PORT;
wg_config.public_key = CONFIG_WG_PEER_PUBLIC_KEY;
wg_config.allowed_ip = CONFIG_WG_LOCAL_IP_ADDRESS;
wg_config.allowed_ip_mask = CONFIG_WG_LOCAL_IP_NETMASK;
wg_config.endpoint = CONFIG_WG_PEER_ADDRESS;
wg_config.port = CONFIG_WG_PEER_PORT;

/* If the device is behind NAT or stateful firewall, set persistent_keepalive.
   persistent_keepalive is disabled by default */
// wg_config.persistent_keepalive = 10;

wireguard_ctx_t ctx = {0};
err = esp_wireguard_init(&wg_config, &ctx);

/* start establishing the link. after this call, esp_wireguard start
   establishing connection. */
err = esp_wireguard_connect(&ctx);

/* after some time, see if the link is up. note that it takes some time to
   establish the link */
err = esp_wireguardif_peer_is_up(&ctx);
if (err == ESP_OK) {
    /* the link is up */
else {
    /* the link is not up */
}

/* do something */

err = esp_wireguard_disconnect(&ctx);

See examples at examples.

IPv6 support

Enable CONFIG_LWIP_IPV6 under lwip component in menuconfig.

IPv6 support is alpha and probably broken. See also Known issues.

Driver configuration

The driver configuration is under [Component config] -> [WireGuard].

Under WIREGUARD_x25519_IMPLEMENTATION, you may choose an implementation of scalar multiplication. The default is WIREGUARD_x25519_IMPLEMENTATION_DEFAULT, which is derived from WireGuard Implementation for lwIP. WIREGUARD_x25519_IMPLEMENTATION_NACL uses crypto_scalarmult() from NaCL. Note that, with WIREGUARD_x25519_IMPLEMENTATION_NACL, some stack sizes must be increased. In my test, 5KB for both CONFIG_LWIP_TCPIP_TASK_STACK_SIZE, and CONFIG_MAIN_TASK_STACK_SIZE is known to work on ESP32-D0WD-V3.

Known issues

The implementation uses LwIP as TCP/IP protocol stack.

IPv6 support is not tested. Dual stack (IPv4 and IPv6) is not supported (see Issue #5). The first address of endpoint is used to choose IPv4 or IPv6 as a transport. The chosen transport must be available and usable.

The library assumes the interface is WiFi interface. Ethernet is not supported.

Older esp-idf versions with TCP/IP Adapter, such as v4.1.x, should work, but there are others issues, not directly related to the library.

License

BSD 3-Clause "New" or "Revised" License (SPDX ID: BSD-3-Clause). See LICENSE for details.

[src/nacl/crypto_scalarmult/curve25519/ref/smult.c] is Public domain.

Authors

More Repositories

1

esphome-component-ping

esphome component that sends and receives ICMP
C
31
star
2

ansible-role-opendistroforelasticsearch

ansible role for opendistroforelasticsearch. archived. please use https://github.com/trombik/ansible-role-opensearch
Ruby
13
star
3

AS3935-ESP-I2C

AS3935 I2C library for ESP8266
C++
5
star
4

xtensa-esp32-elf

FreeBSD port of Espressif ESP32 toolchain. see https://github.com/trombik/xtensa-esp32-elf/tree/devel/devel/xtensa-esp32-elf for details
Makefile
4
star
5

qansible

Inspect ansible role and complain
Ruby
4
star
6

ansible-role-opensmtpd

Configure `smtpd(8)`, aka OpenSMTPD
Ruby
4
star
7

platformio-freebsd-toolchain-xtensa

Trick platformio so that it thinks toolchain-xtensa, a platformio package, is installed. With recent ESP8266/Arduino (3.0.0), This workaround does not work anymore. Use https://github.com/trombik/freebsd-ports-esp-quick-toolchain/ instead.
Shell
4
star
8

ansible-role-dovecot

Configures dovecot
Ruby
3
star
9

ansible-vm-packer-build

Deprecated and archived. see https://github.com/trombik/ansible-vm-build
Shell
3
star
10

ansible-role-iobroker

Manage iobroker, a home automation system.
Ruby
2
star
11

freebsd-ports-esp-quick-toolchain

GCC toolchain for esp8266/arduino on FreeBSD. see https://github.com/trombik/freebsd-ports-esp-quick-toolchain/tree/main/devel/esp-quick-toolchain for details.
Makefile
2
star
12

esp_hass

Home Assistant WebSocket API client for esp-idf
C
2
star
13

TRB_AS3935

C driver for AS3935 Franklin Lightning Sensor IC
C
2
star
14

esp-adf-component-ai-thinker-esp32-a1s

Ai Thinker ESP32 A1S Audio Kit board definition for esp-adf
C
2
star
15

ansible-vm-build

My vagrant boxes for ansible role development.
HCL
2
star
16

ansible-role-x509_certificate

Manages X509 public and secret keys
Ruby
2
star
17

freebsd-ports-py-home-assistant

Makefile
2
star
18

ansible-role-octoprint

ansible role for octoprint
Ruby
2
star
19

freebsd-ports-xtensa-lx106-elf

FreeBSD port of xtensa-lx106-elf
Makefile
2
star
20

freebsd-cvs2git-mirror

Mirrors FreeBSD CVS repository to git repository
Perl
2
star
21

check_resque

A Nagios/Icinga plugin to check resque
Perl
2
star
22

reallyenglish-nagios-plugins

Nagios plugins at reallyenglish
Shell
2
star
23

reallyenglish-ports

local FreeBSD ports repo at reallyenglish.com
C
2
star
24

check_vm_swap

A Nagios plugin to check swap in/out operations
Perl
2
star
25

ansible-role-opensearch

ansible role for opensearch. supports FreeBSD, Debian-variants, and CentOS.
Ruby
2
star
26

ansible-role-dhcpd_openbsd

Manage `dhcpd(8)` from OpenBSD project
Ruby
1
star
27

ansible-role-zsh

Install zsh
Ruby
1
star
28

ansible-role-e2guardian

configure e2guardian
Ruby
1
star
29

ansible-role-cyrus_sasl

Ruby
1
star
30

kicad-tiny-pov

16 bits PoV display for ATTiny MCUs
C
1
star
31

esp-homie

An esp-idf component for the Homie convention with Homie 4.0 support
C
1
star
32

ansible-role-doas

Configure doas.conf(5)
Ruby
1
star
33

ansible-role-devfsrules

Ruby
1
star
34

ansible-role-squid

Configure squid proxy
Ruby
1
star
35

ansible-role-node_red

Configures node-red
Ruby
1
star
36

make-authpf-user

1
star
37

3d-two-mini-breadboards

A mini breadboard holder
Makefile
1
star
38

TRB_u8g2_esp_idf

Packaged version of u8g2 and HAL for esp-idf
C
1
star
39

ansible-role-netplan

Ruby
1
star
40

ansible-role-influxdb

Install and configure influxdb
Ruby
1
star
41

ansible-role-haproxy

ansible role for haproxy. supports FreeBSD, OpenBSD, Ubuntu, and CentOS
Ruby
1
star
42

freebsd-release

release(7) the latest FreeBSD release
C
1
star
43

Mini-Drawers-Ultimate

A remix of TrevM's Mini Drawers
OpenSCAD
1
star
44

perl-modules

My local Perl modules
Perl
1
star
45

ansible-role-nfsv4-server-freebsd

Manages NFSv4 server daemons on FreeBSD
Ruby
1
star
46

platformio-freebsd-toolchain-atmelavr

Trick platformio so that it thinks toolchain-atmelavr, a platformio package, is installed.
Shell
1
star
47

ansible-role-postgresql

ansible role for postresql
Ruby
1
star
48

ansible-role-grafana

ansible role for grafana. supports FreeBSD, OpenBSD, Ubuntu, and CentOS.
Ruby
1
star
49

kicad-ultrasonic-display

C++
1
star
50

TRB_MCP23017

C driver for MCP23017
C
1
star
51

ansible-role-openntpd

Configure openntpd
Ruby
1
star
52

freebsd-ports-esp-idf

FreeBSD port of `esp-idf`. see https://github.com/trombik/freebsd-ports-esp-idf/tree/main/devel/esp-idf for more details.
Makefile
1
star
53

roomPing

ICMP sensor on ESP32 and ESP8266
C
1
star
54

ansible-role-mariadb

ansible role for maraidb and mysql
Ruby
1
star
55

toolchain-xtensa32

Vagrantfile that builds ESP32 GCC Cross-compiler Toolchain for platform.io on FreeBSD. Deprecated. See https://github.com/trombik/xtensa-esp32-elf
1
star