xref: /freebsd/contrib/wireguard-tools/encoding.h (revision adf376485712c8fffbf3be330d505a969647f479)
1*adf37648SKyle Evans /* SPDX-License-Identifier: GPL-2.0 OR MIT */
2*adf37648SKyle Evans /*
3*adf37648SKyle Evans  * Copyright (C) 2015-2020 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
4*adf37648SKyle Evans  */
5*adf37648SKyle Evans 
6*adf37648SKyle Evans #ifndef ENCODING_H
7*adf37648SKyle Evans #define ENCODING_H
8*adf37648SKyle Evans 
9*adf37648SKyle Evans #include <stdbool.h>
10*adf37648SKyle Evans #include <stdint.h>
11*adf37648SKyle Evans #include "containers.h"
12*adf37648SKyle Evans 
13*adf37648SKyle Evans #define WG_KEY_LEN_BASE64 ((((WG_KEY_LEN) + 2) / 3) * 4 + 1)
14*adf37648SKyle Evans #define WG_KEY_LEN_HEX (WG_KEY_LEN * 2 + 1)
15*adf37648SKyle Evans 
16*adf37648SKyle Evans void key_to_base64(char base64[static WG_KEY_LEN_BASE64], const uint8_t key[static WG_KEY_LEN]);
17*adf37648SKyle Evans bool key_from_base64(uint8_t key[static WG_KEY_LEN], const char *base64);
18*adf37648SKyle Evans 
19*adf37648SKyle Evans void key_to_hex(char hex[static WG_KEY_LEN_HEX], const uint8_t key[static WG_KEY_LEN]);
20*adf37648SKyle Evans bool key_from_hex(uint8_t key[static WG_KEY_LEN], const char *hex);
21*adf37648SKyle Evans 
22*adf37648SKyle Evans bool key_is_zero(const uint8_t key[static WG_KEY_LEN]);
23*adf37648SKyle Evans 
24*adf37648SKyle Evans #endif
25