aboutsummaryrefslogtreecommitdiff
path: root/src/models/crypto/pubkey.hpp
diff options
context:
space:
mode:
authorflu0r1ne <flu0r1ne@flu0r1ne.net>2023-08-27 20:11:39 -0500
committerflu0r1ne <flu0r1ne@flu0r1ne.net>2023-08-27 20:11:39 -0500
commitca592cb6e6a9aeee619d3fd7311030ab34844c2f (patch)
tree11f669e706938416c6139de7650efa05a243fac9 /src/models/crypto/pubkey.hpp
downloadwg2nd-web-main.tar.xz
wg2nd-web-main.zip
Add wg2nd-web sourceHEADmain
Diffstat (limited to 'src/models/crypto/pubkey.hpp')
-rw-r--r--src/models/crypto/pubkey.hpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/models/crypto/pubkey.hpp b/src/models/crypto/pubkey.hpp
new file mode 100644
index 0000000..cb1f794
--- /dev/null
+++ b/src/models/crypto/pubkey.hpp
@@ -0,0 +1,25 @@
+extern "C" {
+
+#ifndef WG_KEY_LEN
+#define WG_KEY_LEN 32
+#endif
+
+#define WG_KEY_LEN_BASE64 ((((WG_KEY_LEN) + 2) / 3) * 4 + 1)
+#define WG_KEY_LEN_BASE32 (((WG_KEY_LEN + 4) / 5) * 8 + 1)
+
+/*
+ * wg_pubkey_base64 is a C++-compatible wrapper for the curve25519 public-key
+ * derivation routines used natively in `wg(8)`
+ *
+ * PRIVKEY: a c-style string containing the base64-encoded private key
+ * BASE32: a c-style string of capacity WG_KEY_LEN_BASE64 containing the
+ * encoded public key
+ *
+ * returns: 0 on success
+ * > 0 when an error occurs (due to improper key formatting)
+ */
+int wg_pubkey_base32(char const * privkey, char * base32);
+
+int wg_key_convert_base32(char const * base64, char * base32);
+
+}