diff --git a/src/or/router.c b/src/or/router.c
index b1c8c3f8872aba772b4cfc5904c763aacbade246..f83bcdda349e290d1ef24626668da1cd29c30aa6 100644
--- a/src/or/router.c
+++ b/src/or/router.c
@@ -61,7 +61,7 @@ void rotate_onion_key(void)
     log(LOG_ERR, "Error creating crypto environment.");
     goto error;
   }
-  if (crypto_pk_generate_key(onionkey)) {
+  if (crypto_pk_generate_key(prkey)) {
     log(LOG_ERR, "Error generating key: %s", crypto_perror());
     goto error;
   }