summaryrefslogtreecommitdiffstats
path: root/src/protocols
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2014-04-24 03:33:09 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2014-04-24 03:33:09 +0200
commite8296fbc9f88154830a68a0a7d53aa38f93cbd66 (patch)
tree9484285e61f9b68073295f025f885939772e66dd /src/protocols
parent4872dd03e73aac434d735782417e40ca33336dac (diff)
downloadfastd-e8296fbc9f88154830a68a0a7d53aa38f93cbd66.tar
fastd-e8296fbc9f88154830a68a0a7d53aa38f93cbd66.zip
ec25519-fhmqvc: use PUBLICKEYBYTES and SECRETKEYBYTES defines more
Diffstat (limited to 'src/protocols')
-rw-r--r--src/protocols/ec25519_fhmqvc/ec25519_fhmqvc.c4
-rw-r--r--src/protocols/ec25519_fhmqvc/ec25519_fhmqvc.h6
-rw-r--r--src/protocols/ec25519_fhmqvc/handshake.c14
-rw-r--r--src/protocols/ec25519_fhmqvc/state.c2
-rw-r--r--src/protocols/ec25519_fhmqvc/util.c2
5 files changed, 15 insertions, 13 deletions
diff --git a/src/protocols/ec25519_fhmqvc/ec25519_fhmqvc.c b/src/protocols/ec25519_fhmqvc/ec25519_fhmqvc.c
index 9d32f3b..ec19da3 100644
--- a/src/protocols/ec25519_fhmqvc/ec25519_fhmqvc.c
+++ b/src/protocols/ec25519_fhmqvc/ec25519_fhmqvc.c
@@ -31,7 +31,7 @@ static inline bool read_key(uint8_t key[32], const char *hexkey) {
if ((strlen(hexkey) != 64) || (strspn(hexkey, "0123456789abcdefABCDEF") != 64))
return false;
- int i;
+ size_t i;
for (i = 0; i < 32; i++)
sscanf(&hexkey[2*i], "%02hhx", &key[i]);
@@ -92,7 +92,7 @@ static void protocol_peer_configure(fastd_peer_config_t *peer_conf) {
peer_conf->protocol_config = malloc(sizeof(fastd_protocol_peer_config_t));
peer_conf->protocol_config->public_key = key;
- if (memcmp(&peer_conf->protocol_config->public_key, &conf.protocol_config->key.public, 32) == 0)
+ if (memcmp(&peer_conf->protocol_config->public_key, &conf.protocol_config->key.public, PUBLICKEYBYTES) == 0)
pr_debug("found own key as `%s', ignoring peer", peer_conf->name);
}
diff --git a/src/protocols/ec25519_fhmqvc/ec25519_fhmqvc.h b/src/protocols/ec25519_fhmqvc/ec25519_fhmqvc.h
index 468a7b2..e7c80e0 100644
--- a/src/protocols/ec25519_fhmqvc/ec25519_fhmqvc.h
+++ b/src/protocols/ec25519_fhmqvc/ec25519_fhmqvc.h
@@ -34,6 +34,10 @@
#include <libuecc/ecc.h>
+#define PUBLICKEYBYTES 32
+#define SECRETKEYBYTES 32
+
+
typedef union aligned_int256 {
ecc_int256_t int256;
uint32_t u32[8];
@@ -96,7 +100,7 @@ bool fastd_protocol_ec25519_fhmqvc_describe_peer(const fastd_peer_t *peer, char
static inline void hexdump(char out[65], const unsigned char d[32]) {
- int i;
+ size_t i;
for (i = 0; i < 32; i++)
snprintf(out+2*i, 3, "%02x", d[i]);
}
diff --git a/src/protocols/ec25519_fhmqvc/handshake.c b/src/protocols/ec25519_fhmqvc/handshake.c
index f3a697d..845e790 100644
--- a/src/protocols/ec25519_fhmqvc/handshake.c
+++ b/src/protocols/ec25519_fhmqvc/handshake.c
@@ -29,8 +29,6 @@
#include "../../hkdf_sha256.h"
-#define PUBLICKEYBYTES 32
-#define SECRETKEYBYTES 32
#define HASHBYTES FASTD_SHA256_HASH_BYTES
@@ -391,7 +389,7 @@ static void handle_finish_handshake(fastd_socket_t *sock, const fastd_peer_addre
clear_shared_handshake_key(peer);
}
-static fastd_peer_t* find_sender_key(const fastd_peer_address_t *address, const unsigned char key[32]) {
+static fastd_peer_t* find_sender_key(const fastd_peer_address_t *address, const unsigned char key[PUBLICKEYBYTES]) {
errno = 0;
fastd_peer_t *ret = NULL;
@@ -422,7 +420,7 @@ static fastd_peer_t* find_sender_key(const fastd_peer_address_t *address, const
return ret;
}
-static fastd_peer_t* match_sender_key(const fastd_socket_t *sock, const fastd_peer_address_t *address, fastd_peer_t *peer, const unsigned char key[32]) {
+static fastd_peer_t* match_sender_key(const fastd_socket_t *sock, const fastd_peer_address_t *address, fastd_peer_t *peer, const unsigned char key[PUBLICKEYBYTES]) {
errno = 0;
if (sock->peer && peer != sock->peer)
@@ -441,7 +439,7 @@ static fastd_peer_t* match_sender_key(const fastd_socket_t *sock, const fastd_pe
return find_sender_key(address, key);
}
-static size_t key_count(const unsigned char key[32]) {
+static size_t key_count(const unsigned char key[PUBLICKEYBYTES]) {
size_t ret = 0;
fastd_peer_config_t *p;
@@ -449,7 +447,7 @@ static size_t key_count(const unsigned char key[32]) {
if (!p->protocol_config)
continue;
- if (memcmp(&p->protocol_config->public_key, key, 32) == 0)
+ if (memcmp(&p->protocol_config->public_key, key, PUBLICKEYBYTES) == 0)
ret++;
}
@@ -460,7 +458,7 @@ bool fastd_protocol_ec25519_fhmqvc_peer_check(fastd_peer_config_t *peer_conf) {
if (!peer_conf->protocol_config)
return false;
- if (memcmp(&peer_conf->protocol_config->public_key, &conf.protocol_config->key.public, 32) == 0)
+ if (memcmp(&peer_conf->protocol_config->public_key, &conf.protocol_config->key.public, PUBLICKEYBYTES) == 0)
return false;
if (key_count(peer_conf->protocol_config->public_key.u8) > 1) {
@@ -488,7 +486,7 @@ static inline bool allow_unknown(void) {
return fastd_shell_command_isset(&conf.on_verify);
}
-static inline fastd_peer_t* add_temporary(const fastd_peer_address_t *addr, const unsigned char key[32]) {
+static inline fastd_peer_t* add_temporary(const fastd_peer_address_t *addr, const unsigned char key[PUBLICKEYBYTES]) {
if (!allow_unknown()) {
pr_debug("ignoring handshake from %I (unknown key)", addr);
return NULL;
diff --git a/src/protocols/ec25519_fhmqvc/state.c b/src/protocols/ec25519_fhmqvc/state.c
index 7f3b847..f20b381 100644
--- a/src/protocols/ec25519_fhmqvc/state.c
+++ b/src/protocols/ec25519_fhmqvc/state.c
@@ -38,7 +38,7 @@ static void init_protocol_state(void) {
}
static void new_handshake_key(keypair_t *key) {
- fastd_random_bytes(key->secret.p, 32, false);
+ fastd_random_bytes(key->secret.p, SECRETKEYBYTES, false);
ecc_25519_gf_sanitize_secret(&key->secret, &key->secret);
ecc_25519_work_t work;
diff --git a/src/protocols/ec25519_fhmqvc/util.c b/src/protocols/ec25519_fhmqvc/util.c
index 5bd23b3..8d11eeb 100644
--- a/src/protocols/ec25519_fhmqvc/util.c
+++ b/src/protocols/ec25519_fhmqvc/util.c
@@ -41,7 +41,7 @@ void fastd_protocol_ec25519_fhmqvc_generate_key(void) {
if (!conf.machine_readable)
pr_info("Reading 32 bytes from /dev/random...");
- fastd_random_bytes(secret_key.p, 32, true);
+ fastd_random_bytes(secret_key.p, SECRETKEYBYTES, true);
ecc_25519_gf_sanitize_secret(&secret_key, &secret_key);
ecc_25519_work_t work;