diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2015-01-09 11:55:07 +0100 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2015-01-09 11:55:07 +0100 |
commit | f11b14362b05f5965b0d1e6b9af1c48945884b9e (patch) | |
tree | 5ed6c4a921bf47c4259cc8fa7a82a0475f30b116 /src/protocols/ec25519_fhmqvc/ec25519_fhmqvc.c | |
parent | 020c28af111d7d0fc325fc9a55bd185368e049cd (diff) | |
download | fastd-f11b14362b05f5965b0d1e6b9af1c48945884b9e.tar fastd-f11b14362b05f5965b0d1e6b9af1c48945884b9e.zip |
ec25519-fhmqvc: unpack peers' keys only once
Diffstat (limited to 'src/protocols/ec25519_fhmqvc/ec25519_fhmqvc.c')
-rw-r--r-- | src/protocols/ec25519_fhmqvc/ec25519_fhmqvc.c | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/src/protocols/ec25519_fhmqvc/ec25519_fhmqvc.c b/src/protocols/ec25519_fhmqvc/ec25519_fhmqvc.c index c60ce67..17f8268 100644 --- a/src/protocols/ec25519_fhmqvc/ec25519_fhmqvc.c +++ b/src/protocols/ec25519_fhmqvc/ec25519_fhmqvc.c @@ -78,14 +78,32 @@ static fastd_protocol_config_t * protocol_init(void) { static fastd_protocol_key_t * protocol_read_key(const char *key) { fastd_protocol_key_t *ret = fastd_new(fastd_protocol_key_t); - if (!read_key(ret->key.u8, key) || !fastd_protocol_ec25519_fhmqvc_check_key(&ret->key.int256)) { - free(ret); - return NULL; + if (read_key(ret->key.u8, key)) { + if (ecc_25519_load_packed(&ret->unpacked, &ret->key.int256)) { + if (fastd_protocol_ec25519_fhmqvc_check_key(&ret->unpacked)) + return ret; + } } - return ret; + free(ret); + return NULL; +} + +/** Checks if an ecc25519 work structure represents a valid curve point */ +bool fastd_protocol_ec25519_fhmqvc_check_key(const ecc_25519_work_t *key) { + ecc_25519_work_t work; + + if (ecc_25519_is_identity(key)) + return false; + + ecc_25519_scalarmult(&work, &ecc_25519_gf_order, key); + if (!ecc_25519_is_identity(&work)) + return false; + + return true; } + /** Checks if a peer is configured using our own key */ static bool protocol_check_peer(const fastd_peer_t *peer) { if (memcmp(conf.protocol_config->key.public.u8, peer->key->key.u8, PUBLICKEYBYTES) == 0) { |