Avoid a needless decode/re-encode step in assigning onion keys

Previously we had decoded the asn.1 to get a public key, and then
discarded the asn.1 so that we had to re-encode the key to store it
in the onion_pkey field of a microdesc_t or routerinfo_t.

Now we can just do a tor_memdup() instead, which should be loads
faster.
This commit is contained in:
Nick Mathewson 2018-12-14 13:28:07 -05:00
parent 0556942284
commit 7113a339dc
2 changed files with 4 additions and 4 deletions

View File

@ -177,8 +177,8 @@ microdescs_parse_from_string(const char *s, const char *eos,
"Relay's onion key had invalid exponent.");
goto next;
}
router_set_rsa_onion_pkey(tok->key, &md->onion_pkey,
&md->onion_pkey_len);
md->onion_pkey = tor_memdup(tok->object_body, tok->object_size);
md->onion_pkey_len = tok->object_size;
crypto_pk_free(tok->key);
if ((tok = find_opt_by_keyword(tokens, K_ONION_KEY_NTOR))) {

View File

@ -588,8 +588,8 @@ router_parse_entry_from_string(const char *s, const char *end,
"Relay's onion key had invalid exponent.");
goto err;
}
router_set_rsa_onion_pkey(tok->key, &router->onion_pkey,
&router->onion_pkey_len);
router->onion_pkey = tor_memdup(tok->object_body, tok->object_size);
router->onion_pkey_len = tok->object_size;
crypto_pk_free(tok->key);
if ((tok = find_opt_by_keyword(tokens, K_ONION_KEY_NTOR))) {