Mercurial > hg > quicktun
diff src/common.c @ 64:fa53d1c54886
Use default RNG for key generation, added options to generate public key from private key, use bundled tweetnacl as fallback instead of nacl download
author | Ivo Smits <Ivo@UFO-Net.nl> |
---|---|
date | Sat, 07 Jan 2017 18:07:27 +0100 |
parents | fa4983c5f7ea |
children | c87212fe8883 |
line wrap: on
line diff
--- a/src/common.c Sat Jan 07 16:01:01 2017 +0100 +++ b/src/common.c Sat Jan 07 18:07:27 2017 +0100 @@ -40,6 +40,7 @@ #include <stdlib.h> #include <arpa/inet.h> #include <net/if.h> +#include <stdbool.h> #ifdef linux #include <linux/if_tun.h> #include <linux/if_ether.h> @@ -264,18 +265,21 @@ return ttfd; } -void hex2bin(unsigned char* dest, const char* src, const int count) { +bool hex2bin(unsigned char* dest, const char* src, const int count) { int i; for (i = 0; i < count; i++) { if (*src >= '0' && *src <= '9') *dest = *src - '0'; else if (*src >= 'a' && * src <='f') *dest = *src - 'a' + 10; else if (*src >= 'A' && * src <='F') *dest = *src - 'A' + 10; + else return false; src++; *dest = *dest << 4; if (*src >= '0' && *src <= '9') *dest += *src - '0'; else if (*src >= 'a' && *src <= 'f') *dest += *src - 'a' + 10; else if (*src >= 'A' && *src <= 'F') *dest += *src - 'A' + 10; + else return false; src++; dest++; } + return true; } static int drop_privileges() {