aboutsummaryrefslogtreecommitdiff
path: root/src/crypto/pubkey.c
diff options
context:
space:
mode:
authorflu0r1ne <flu0r1ne@flu0r1ne.net>2023-08-26 20:58:33 -0500
committerflu0r1ne <flu0r1ne@flu0r1ne.net>2023-08-26 22:39:35 -0500
commitba286e5d624978f4f53ed5f9154790ef3595922e (patch)
tree05a88849f4c9133fc60311ac355a079186073d51 /src/crypto/pubkey.c
parentc1554d0a1cd337fb1edf23ab0fa4e0e178ced1fc (diff)
downloadwg2nd-ba286e5d624978f4f53ed5f9154790ef3595922e.tar.xz
wg2nd-ba286e5d624978f4f53ed5f9154790ef3595922e.zip
Store private key in a file with the public keyname, get rid of argon2
Diffstat (limited to 'src/crypto/pubkey.c')
-rw-r--r--src/crypto/pubkey.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/crypto/pubkey.c b/src/crypto/pubkey.c
new file mode 100644
index 0000000..1224b07
--- /dev/null
+++ b/src/crypto/pubkey.c
@@ -0,0 +1,27 @@
+#include "curve25519.h"
+#include "encoding.h"
+
+int wg_pubkey_base64(char const * privkey, char * base64) {
+
+ uint8_t key[WG_KEY_LEN] __attribute((aligned(sizeof(uintptr_t))));
+
+ int i;
+ for(i = 0; privkey[i] && i < WG_KEY_LEN_BASE64 - 1; i++)
+ base64[i] = privkey[i];
+
+ base64[WG_KEY_LEN_BASE64 - 1] = '\0';
+
+ if(i != WG_KEY_LEN_BASE64 - 1 || privkey[i]) {
+ return 1;
+ }
+
+ if(!key_from_base64(key, base64)) {
+ return 1;
+ }
+
+ curve25519_generate_public(key, key);
+
+ key_to_base64(base64, key);
+
+ return 0;
+}