谷动谷力

 找回密码
 立即注册
查看: 652|回复: 0
打印 上一主题 下一主题
收起左侧

【openwrt】编译OpenWRT15.05(Chaos Calmer)u-boot-2014.10 rsa-sign出错

[复制链接]
跳转到指定楼层
楼主
发表于 2023-6-23 19:41:20 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 sunsili 于 2023-8-16 13:17 编辑

【openwrt】编译OpenWRT15.05(Chaos Calmer)mkimage(u-boot-2014.10) rsa-sign.c出错


编译OpenWRT 15.05(Chaos Calmer)的模块 tools/mkimage(u-boot-2014.10) 的时候碰到了下面的错误信息:

出错提示:
/home/fan/openwrt_CC_mt76xx_zhuotk_source/build_dir/host/u-boot-2014.10/lib/rsa/rsa-sign.c: In function 'rsa_get_exponent':
/home/fan/openwrt_CC_mt76xx_zhuotk_source/build_dir/host/u-boot-2014.10/lib/rsa/rsa-sign.c:279:21: error: dereferencing pointer to incomplete type 'RSA' {aka 'struct rsa_st'}
279 |  if (BN_num_bits(key->e) > 64)
|                     ^
make[5]: *** [scripts/Makefile.host:134: tools/lib/rsa/rsa-sign.o] Error 1
make[4]: *** [Makefile:1195: tools-only] Error 2
make[4]: Leaving directory '/home/fan/openwrt_CC_mt76xx_zhuotk_source/build_dir/host/u-boot-2014.10'
make[3]: *** [Makefile:48: /home/fan/openwrt_CC_mt76xx_zhuotk_source/build_dir/host/u-boot-2014.10/.built] Error 2
make[3]: Leaving directory '/home/fan/openwrt_CC_mt76xx_zhuotk_source/tools/mkimage'
make[2]: *** [tools/Makefile:123: tools/mkimage/compile] Error 2
make[2]: Leaving directory '/home/fan/openwrt_CC_mt76xx_zhuotk_source'
make[1]: *** [tools/Makefile:121: /home/fan/openwrt_CC_mt76xx_zhuotk_source/staging_dir/target-mipsel_mips32_uClibc-0.9.33.2/stamp/.tools_install_yynyynynynyyyyyyyyynyyyyyyyyynyyyyynnyyynnyynnnyy] Error 2
make[1]: Leaving directory '/home/fan/openwrt_CC_mt76xx_zhuotk_source'
make: *** [/home/fan/openwrt_CC_mt76xx_zhuotk_source/include/toplevel.mk:183: world] Error 2

原因
编译Server的OpenSSL版本是1.1x,OpenSSL 1.1.x对一些API做了改动,因此出现错误信息。
$ openssl version
OpenSSL 1.1.0g  2 Nov 2017
解决方法
参考openwrt/tools/mkimage/patches/210-openssl-1.1.x-compat.patch at 70b104f98c0657323b28fce140b73a94bf3eb756
在此路径tools/mkimage/patches/
新建文件:210-openssl-1.1.x-compat.patch
文件内容
tools/mkimage/patches/210-openssl-1.1.x-compat.patch
--- a/lib/rsa/rsa-sign.c
+++ b/lib/rsa/rsa-sign.c
@@ -15,10 +15,25 @@
#include
#include

-#if OPENSSL_VERSION_NUMBER >= 0x10000000L
+#if OPENSSL_VERSION_NUMBER < 0x10000000L
+#define HAVE_ERR_REMOVE_STATE
+#elif OPENSSL_VERSION_NUMBER < 0x10100000L
#define HAVE_ERR_REMOVE_THREAD_STATE
#endif

+#if OPENSSL_VERSION_NUMBER < 0x10100005L
+static void RSA_get0_key(const RSA *r,
+                         const BIGNUM **n, const BIGNUM **e, const BIGNUM **d)
+{
+   if (n != NULL)
+       *n = r->n;
+   if (e != NULL)
+       *e = r->e;
+   if (d != NULL)
+       *d = r->d;
+}
+#endif
+
static int rsa_err(const char *msg)
{
         unsigned long sslErr = ERR_get_error();
@@ -154,7 +169,8 @@ static void rsa_remove(void)
         ERR_free_strings();
#ifdef HAVE_ERR_REMOVE_THREAD_STATE
         ERR_remove_thread_state(NULL);
-#else
+#endif
+#ifdef HAVE_ERR_REMOVE_STATE
         ERR_remove_state(0);
#endif
         EVP_cleanup();
@@ -210,7 +226,6 @@ static int rsa_sign_with_key(RSA *rsa, s
                 ret = rsa_err("Could not obtain signature");
                 goto err_sign;
         }
-        EVP_MD_CTX_cleanup(context);
         EVP_MD_CTX_destroy(context);
         EVP_PKEY_free(key);

@@ -270,23 +285,26 @@ static int rsa_get_exponent(RSA *key, ui
         BIGNUM *bn_te;
         uint64_t te;

+        const BIGNUM *bn_e;
+        RSA_get0_key(key, NULL, &bn_e, NULL);
+
         ret = -EINVAL;
         bn_te = NULL;

         if (!e)
                 goto cleanup;

-        if (BN_num_bits(key->e) > 64)
+        if (BN_num_bits(bn_e) > 64)
                 goto cleanup;

-        *e = BN_get_word(key->e);
+        *e = BN_get_word(bn_e);

-        if (BN_num_bits(key->e) < 33) {
+        if (BN_num_bits(bn_e) < 33) {
                 ret = 0;
                 goto cleanup;
         }

-        bn_te = BN_dup(key->e);
+        bn_te = BN_dup(bn_e);
         if (!bn_te)
                 goto cleanup;

@@ -319,6 +337,9 @@ int rsa_get_params(RSA *key, uint64_t *e
         BN_CTX *bn_ctx = BN_CTX_new();
         int ret = 0;

+        const BIGNUM *bn_n;
+        RSA_get0_key(key, &bn_n, NULL, NULL);
+
         /* Initialize BIGNUMs */
         big1 = BN_new();
         big2 = BN_new();
@@ -337,7 +358,7 @@ int rsa_get_params(RSA *key, uint64_t *e
         if (0 != rsa_get_exponent(key, exponent))
                 ret = -1;

-        if (!BN_copy(n, key->n) || !BN_set_word(big1, 1L) ||
+        if (!BN_copy(n, bn_n) || !BN_set_word(big1, 1L) ||
             !BN_set_word(big2, 2L) || !BN_set_word(big32, 32L))
                 ret = -1; 放入tools/mkimage/patches/的patch,编译时会自动打补丁

重新编译则不会有此错误

+10

本帖被以下淘专辑推荐:

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|深圳市光明谷科技有限公司|光明谷商城|Sunshine Silicon Corpporation ( 粤ICP备14060730号|Sitemap

GMT+8, 2024-4-29 23:08 , Processed in 0.085614 second(s), 42 queries .

Powered by Discuz! X3.2 Licensed

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表