lanplus_crypt_impl.c: In function 'lanplus_encrypt_aes_cbc_128':
lanplus_crypt_impl.c:167:17: error: storage size of 'ctx' isn't known
167 | EVP_CIPHER_CTX ctx;
| ^~~
lanplus_crypt_impl.c:167:17: warning: unused variable 'ctx' [-Wunused-variable]
lanplus_crypt_impl.c: In function 'lanplus_decrypt_aes_cbc_128':
lanplus_crypt_impl.c:242:17: error: storage size of 'ctx' isn't known
242 | EVP_CIPHER_CTX ctx;
| ^~~
lanplus_crypt_impl.c:242:17: warning: unused variable 'ctx' [-Wunused-variable]
出现该问题的原因是,openssl版本不同,其函数接口发生了变化,老接口"EVP_CIPHER_CTX ctx;"在新opensll版本上不能识别,需要改成新的语法格式。
vim src/plugins/lanplus/lanplus_crypt_impl.c
文件里的两个函数即可。第1个函数,159行
void
lanplus_encrypt_aes_cbc_128(const uint8_t * iv,
const uint8_t * key,
const uint8_t * input,
uint32_t input_length,
uint8_t * output,
uint32_t * bytes_written)
{
//EVP_CIPHER_CTX ctx;
EVP_CIPHER_CTX *ctx; //修改1
ctx = EVP_CIPHER_CTX_new(); //修改2
EVP_CIPHER_CTX_init(ctx); //修改3
EVP_EncryptInit_ex(ctx, EVP_aes_128_cbc(), NULL, key, iv); //修改4
EVP_CIPHER_CTX_set_padding(ctx, 0); //修改5
*bytes_written = 0;
if (input_length == 0)
{
EVP_CIPHER_CTX_free(ctx); //修改6
return;
}
if (verbose >= 5)
{
printbuf(iv, 16, "encrypting with this IV");
printbuf(key, 16, "encrypting with this key");
printbuf(input, input_length, "encrypting this data");
}
/*
* The default implementation adds a whole block of padding if the input
* data is perfectly aligned. We would like to keep that from happening.
* We have made a point to have our input perfectly padded.
*/
assert((input_length % IPMI_CRYPT_AES_CBC_128_BLOCK_SIZE) == 0);
if(!EVP_EncryptUpdate(ctx, output, (int *)bytes_written, input, input_length)) //修改7
{
/* Error */
*bytes_written = 0;
EVP_CIPHER_CTX_free(ctx); //修改8
return;
}
else
{
uint32_t tmplen;
if(!EVP_EncryptFinal_ex(ctx, output + *bytes_written, (int *)&tmplen)) //修改9
{
*bytes_written = 0;
EVP_CIPHER_CTX_free(ctx); //修改10
return; /* Error */
}
else
{
/* Success */
*bytes_written += tmplen;
EVP_CIPHER_CTX_cleanup(ctx); //修改11
}
}
}
第2个函数,242行
void
lanplus_decrypt_aes_cbc_128(const uint8_t * iv,
const uint8_t * key,
const uint8_t * input,
uint32_t input_length,
uint8_t * output,
uint32_t * bytes_written)
{
EVP_CIPHER_CTX *ctx; //修改1
ctx = EVP_CIPHER_CTX_new(); //修改2
EVP_CIPHER_CTX_init(ctx); //修改3
EVP_DecryptInit_ex(ctx, EVP_aes_128_cbc(), NULL, key, iv); //修改4
EVP_CIPHER_CTX_set_padding(ctx, 0); //修改5
if (verbose >= 5)
{
printbuf(iv, 16, "decrypting with this IV");
printbuf(key, 16, "decrypting with this key");
printbuf(input, input_length, "decrypting this data");
}
*bytes_written = 0;
if (input_length == 0)
{
EVP_CIPHER_CTX_free(ctx); //修改6
return;
}
/*
* The default implementation adds a whole block of padding if the input
* data is perfectly aligned. We would like to keep that from happening.
* We have made a point to have our input perfectly padded.
*/
assert((input_length % IPMI_CRYPT_AES_CBC_128_BLOCK_SIZE) == 0);
if (!EVP_DecryptUpdate(ctx, output, (int *)bytes_written, input, input_length))
{
/* Error */
lprintf(LOG_DEBUG, "ERROR: decrypt update failed");
*bytes_written = 0;
EVP_CIPHER_CTX_free(ctx); //修改7
return;
}
else
{
uint32_t tmplen;
if (!EVP_DecryptFinal_ex(ctx, output + *bytes_written, (int *)&tmplen))
{
char buffer[1000];
ERR_error_string(ERR_get_error(), buffer);
lprintf(LOG_DEBUG, "the ERR error %s", buffer);
lprintf(LOG_DEBUG, "ERROR: decrypt final failed");
*bytes_written = 0;
EVP_CIPHER_CTX_free(ctx); //修改8
return; /* Error */
}
else
{
/* Success */
*bytes_written += tmplen;
EVP_CIPHER_CTX_cleanup(ctx); //修改9
}
}
if (verbose >= 5)
{
lprintf(LOG_DEBUG, "Decrypted %d encrypted bytes", input_length);
printbuf(output, *bytes_written, "Decrypted this data");
}
}