diff options
Diffstat (limited to 'src/crypto/pubkey.c')
-rw-r--r-- | src/crypto/pubkey.c | 27 |
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; +} |