Permalink
Browse files

Refactoring validAddress and adding validKey

  • Loading branch information...
1 parent 51f2e4e commit fb67b28a6e3b787710a6f3ec0f96edcd92492701 @marcuswanner marcuswanner committed Nov 21, 2012
Showing with 15 additions and 3 deletions.
  1. +6 −1 crypto/AddressCalc.c
  2. +8 −1 crypto/AddressCalc.h
  3. +1 −1 net/DefaultInterfaceController.c
View
@@ -26,10 +26,15 @@ bool AddressCalc_addressForPublicKey(uint8_t addressOut[16], const uint8_t key[3
return hash[0] == 0xFC;
}
-bool AddressCalc_validAddress(const uint8_t key[32])
+bool AddressCalc_validKey(const uint8_t key[32])
{
uint8_t hash[crypto_hash_sha512_BYTES];
crypto_hash_sha512(hash, key, 32);
crypto_hash_sha512(hash, hash, crypto_hash_sha512_BYTES);
return hash[0] == 0xFC;
}
+
+bool AddressCalc_validAddress(const uint8_t address[16])
+{
+ return address[0] == 0xFC;
+}
View
@@ -32,6 +32,13 @@ bool AddressCalc_addressForPublicKey(uint8_t addressOut[16], const uint8_t key[3
* @param key the 256 bit curve25519 key.
* @return true if the key hashes to a valid cjdns address.
*/
-bool AddressCalc_validAddress(const uint8_t key[32]);
+bool AddressCalc_validKey(const uint8_t key[32]);
+
+/**
+ * Check if an address is valid given the IPv6
+ *
+ * @return true if the IPv6 is a valid cjdns address.
+ */
+bool AddressCalc_validAddress(const uint8_t address[16]);
#endif
@@ -541,7 +541,7 @@ static int insertEndpointPublic(uint8_t key[InterfaceController_KEY_SIZE],
struct Endpoint* ep =
insertEndpoint(key, herPublicKey, false, password, externalInterface, ctx);
if (!ep) {
- if (herPublicKey && !AddressCalc_validAddress(herPublicKey)) {
+ if (herPublicKey && !AddressCalc_validKey(herPublicKey)) {
return InterfaceController_registerInterface_BAD_KEY;
}
return InterfaceController_registerInterface_OUT_OF_SPACE;

0 comments on commit fb67b28

Please sign in to comment.