- 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);
- }
+ // 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);