zerotier / libzt

Encrypted P2P sockets over ZeroTier

Home Page:https://zerotier.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`Identity` initialisation with arbitrary private key (or "secret").

aarlt opened this issue · comments

I just understood how you do the identity and address generation. For zts_id_new the Identity class is used to generate a new valid Identity, where only key pairs are accepted, that meet a specific hashcash generation halting condition. This condition is also checked in zts_init_from_memory.

I would like to have an initialisation function that would allow the initialisation with arbitrary private keys (maybe aka "secrets"). I think one way to allow this in a deterministic way would be just to search for the "next" private key, that is matching the hashcash criteria. An easy way would be to just generate the identity with that given private key, check the condition, where the private key is just incremented by one (or the private key is just getting hashed again) until the condition is met. Shouldn’t that work?

The basic idea is just to deterministically generate an identity for any given private key (or "secret"). Wouldn’t that make sense?

Maybe this could be easily achieved by adding another function similar to C25519::generateSatisfying, without always overwriting the private key with new a new random key - e.g. just by not calling Utils::getSecureRandom(priv,ZT_C25519_PRIVATE_KEY_LEN);. Where the initial private key (keypair containing the initial private key) will be given to the function.

	template<typename F>
	static inline Pair generateNextSatisfyingKeypairFromPrivateKey(F cond, Pair& kp)
	{
		void *const priv = (void *)kp.priv.data;
		_calcPubED(kp); // do Ed25519 key -- bytes 32-63 of pub and priv
		do {
			++(((uint64_t *)priv)[1]);
			--(((uint64_t *)priv)[2]);
			_calcPubDH(kp); // keep regenerating bytes 0-31 until satisfied
		} while (!cond(kp));
		return kp;
	}

Shouldn't that work?