-bool cipher_regenerate_key(cipher_t *cipher, bool encrypt) {
- bool result;
-
- RAND_pseudo_bytes((unsigned char *)cipher->key, cipher->keylen + cipher->blklen);
-
- if(encrypt)
- result = EVP_EncryptInit_ex(&cipher->ctx, cipher->cipher, NULL, (unsigned char *)cipher->key, (unsigned char *)cipher->key + cipher->keylen);
- else
- result = EVP_DecryptInit_ex(&cipher->ctx, cipher->cipher, NULL, (unsigned char *)cipher->key, (unsigned char *)cipher->key + cipher->keylen);
-
- if(result)
- return true;
-
- logger(LOG_ERR, "Error while regenerating key: %s", ERR_error_string(ERR_get_error(), NULL));
- return false;
-}
-