• 安装ipmitool时报错,EVP_CIPHER_CTX ctx 未识别


    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]
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    出现该问题的原因是,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
                    }
            }
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63

    第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");
            }
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
  • 相关阅读:
    JSP ssh 校园二手商品拍卖系统myeclipse开发mysql数据库MVC模式java编程网页设计
    【猿创征文】Vue3 企业级优雅实战 - 组件库框架 - 3 搭建组件库开发环境
    谷歌、AMD、英特尔加入挑战,英伟达AI解决方案还能继续“遥遥领先”吗?
    计算机毕业设计(附源码)python医院门诊分诊系统
    图像处理之图像的离散余弦变换
    makefile目标规则
    C# 提取Word中插入的多媒体文件(视频、音频)
    idea gradle spring cloud 微服务项目
    顺序表<数据结构 C 版>
    WordPress增加SSL证书实现HTTPS协议访问
  • 原文地址:https://blog.csdn.net/tianyake_1/article/details/134284379