-int send_ans_key(connection_t *c, node_t *from, node_t *to)
-{
- char key[MAX_STRING_SIZE];
+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
+ if (1 != RAND_bytes((unsigned char *)to->inkey, to->inkeylength)) {
+ int err = ERR_get_error();
+ logger(LOG_ERR, "Failed to generate random for key (%s)", ERR_error_string(err, NULL));
+ return false; // Do not send insecure keys, let connection attempt fail.
+ }