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