-bool send_ans_key(node_t *to)
-{
- char *key;
-
- cp();
-
- if(!to->inkey) {
- to->incipher = myself->incipher;
- to->inkeylength = myself->inkeylength;
- to->indigest = myself->indigest;
- to->incompression = myself->incompression;
- to->inkey = xmalloc(to->inkeylength);
-
- RAND_pseudo_bytes((unsigned char *)to->inkey, to->inkeylength);
- if(to->incipher)
- EVP_DecryptInit_ex(&packet_ctx, to->incipher, NULL, (unsigned char *)to->inkey, (unsigned char *)to->inkey + to->incipher->key_len);
- }
-
- key = alloca(2 * to->inkeylength + 1);
+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];