- return send_request(c, "%d %s %s %s %d %d %d %d", ANS_KEY,
- from->name, to->name, key,
- from->cipher ? from->cipher->nid : 0,
- from->digest ? from->digest->type : 0, from->maclength,
- from->compression);
+bool send_ans_key(node_t *to) {
+ // Set key parameters
+ to->incipher = myself->incipher;
+ to->inkeylength = myself->inkeylength;
+ to->indigest = myself->indigest;
+ to->inmaclength = myself->inmaclength;
+ to->incompression = myself->incompression;
+
+ // Allocate memory for key
+ to->inkey = xrealloc(to->inkey, to->inkeylength);
+
+ // Create a new key
+ RAND_pseudo_bytes((unsigned char *)to->inkey, to->inkeylength);
+ if(to->incipher)
+ EVP_DecryptInit_ex(&to->inctx, to->incipher, NULL, (unsigned char *)to->inkey, (unsigned char *)to->inkey + to->incipher->key_len);
+
+ // Reset sequence number and late packet window
+ mykeyused = true;
+ to->received_seqno = 0;
+ if(replaywin) memset(to->late, 0, replaywin);
+
+ // Convert to hexadecimal and send
+ char key[2 * to->inkeylength + 1];
+ bin2hex(to->inkey, key, to->inkeylength);
+ key[to->inkeylength * 2] = '\0';
+
+ return send_request(to->nexthop->connection, "%d %s %s %s %d %d %d %d", ANS_KEY,
+ myself->name, to->name, key,
+ to->incipher ? to->incipher->nid : 0,
+ to->indigest ? to->indigest->type : 0, to->inmaclength,
+ to->incompression);