基于CLT13实现的证据加密代码部署

代码源地址

https://github.com/guberti/witness-encryption-demos

代码介绍

代码相对应的论文地址:
https://arxiv.org/abs/2112.04581

论文作者和代码作者为同一个人,通过分析论文,我们可以了解到作者的贡献如下:

  1. 可实现的应用
  2. 防止归零攻击

代码工作流程

给定一个输入 .txt 文件,其中包含以指定格式描述的数独谜题或 Pentomino 平铺问题,Python 脚本将其转换为精确的集合覆盖问题,将其编码打印成单独的文本文件。然后,基于 Carmer 和 Malozemooff [2] 修改的 CLT13 实现构建的 C 代码基于精确集合覆盖问题执行消息加密。以下部分描述了每个阶段的实施细节。

代码部署

系统版本:Ubuntu20.04

基础环境(推荐):cmake 3.24.1 OpenSSL -3.0.0-alpha10 libgmp-6.2.1

安装基础环境推荐链接(将链接中使用的版本换为上述版本):

ubuntu安装zlib详细教程
Ubuntu20.04安装Cmake指南
Ubuntu20 安装使用OpenSSL
Linux 下安装GMP库

可能出现的错误和解决方案链接:

Cmake无root权限安装出现Linking C executable curltest错误
ubuntu16.04下cmake提示Could NOT find CURL

部署过程

在witness-encryption-demos(源代码主目录下)目录下执行代码:

/build.sh

程序开始运行但会报错,错误提示缺少flint库,之后找到官网进行下载,经过后面的不断尝试,发现只有flint-2.6.3的版本才是能让代码适应的环境,一定要从官网下载,正常的词条搜索找不到这个的flint版本,链接如下:

官网链接

之后解压,进入目录,执行如下代码:

./Configure

make

sudo make install

如果中间过程中报错,提示缺少mpfr库,使用下面链接下载,选择mpfr_4.0.2-1_amd64.deb进行安装,一定要用deb的安装包进行安装,因为tgz解压安装后系统仍然找不到mpfr库。

mpfr3.1.2和mpfr4.x源码及对应deb安装包

安装之后进入flint的目录,执行如下代码:

./Configure

make

sudo make install

flint安装成功后,回到witness-encryption-demos(源代码主目录下)目录下执行代码:

/build.sh

如果中间运行出现如下问题:

withinboredom@Legion:~/code/witness-encryption-demos$ ./build.sh

builddir = /home/withinboredom/code/witness-encryption-demos/build

building libaesrand
~/code/witness-encryption-demos/libaesrand ~/code/witness-encryption-demos
From https://github.com/5GenCrypto/libaesrand
 * branch            master     -> FETCH_HEAD
Already up to date.
~/code/witness-encryption-demos
~/code/witness-encryption-demos/libaesrand ~/code/witness-encryption-demos
-- Build type: Release
-- Configuring done
-- Generating done
-- Build files have been written to: /home/withinboredom/code/witness-encryption-demos/libaesrand
[ 12%] Building C object CMakeFiles/aesrand.dir/aesrand/aesrand_buf.c.o
[ 25%] Building C object CMakeFiles/aesrand.dir/aesrand/aesrand_gmp.c.o
[ 37%] Building C object CMakeFiles/aesrand.dir/aesrand/aesrand_init.c.o
/home/withinboredom/code/witness-encryption-demos/libaesrand/aesrand/aesrand_init.c: In function ‘aes_randinit_seedn’:
/home/withinboredom/code/witness-encryption-demos/libaesrand/aesrand/aesrand_init.c:43:5: error: ‘SHA256_Init’ is deprecated: Since OpenSSL 3.0 [-Werror=deprecated-declarations]
   43 |     SHA256_Init(&sha256);
      |     ^~~~~~~~~~~
In file included from /home/withinboredom/code/witness-encryption-demos/libaesrand/aesrand/aesrand_init.c:7:
/usr/include/openssl/sha.h:73:27: note: declared here
   73 | OSSL_DEPRECATEDIN_3_0 int SHA256_Init(SHA256_CTX *c);
      |                           ^~~~~~~~~~~
/home/withinboredom/code/witness-encryption-demos/libaesrand/aesrand/aesrand_init.c:44:5: error: ‘SHA256_Update’ is deprecated: Since OpenSSL 3.0 [-Werror=deprecated-declarations]
   44 |     SHA256_Update(&sha256, seed, seed_len);
      |     ^~~~~~~~~~~~~
In file included from /home/withinboredom/code/witness-encryption-demos/libaesrand/aesrand/aesrand_init.c:7:
/usr/include/openssl/sha.h:74:27: note: declared here
   74 | OSSL_DEPRECATEDIN_3_0 int SHA256_Update(SHA256_CTX *c,
      |                           ^~~~~~~~~~~~~
/home/withinboredom/code/witness-encryption-demos/libaesrand/aesrand/aesrand_init.c:46:9: error: ‘SHA256_Update’ is deprecated: Since OpenSSL 3.0 [-Werror=deprecated-declarations]
   46 |         SHA256_Update(&sha256, additional, additional_len);
      |         ^~~~~~~~~~~~~
In file included from /home/withinboredom/code/witness-encryption-demos/libaesrand/aesrand/aesrand_init.c:7:
/usr/include/openssl/sha.h:74:27: note: declared here
   74 | OSSL_DEPRECATEDIN_3_0 int SHA256_Update(SHA256_CTX *c,
      |                           ^~~~~~~~~~~~~
/home/withinboredom/code/witness-encryption-demos/libaesrand/aesrand/aesrand_init.c:47:5: error: ‘SHA256_Final’ is deprecated: Since OpenSSL 3.0 [-Werror=deprecated-declarations]
   47 |     SHA256_Final(key, &sha256);
      |     ^~~~~~~~~~~~
In file included from /home/withinboredom/code/witness-encryption-demos/libaesrand/aesrand/aesrand_init.c:7:
/usr/include/openssl/sha.h:76:27: note: declared here
   76 | OSSL_DEPRECATEDIN_3_0 int SHA256_Final(unsigned char *md, SHA256_CTX *c);
      |                           ^~~~~~~~~~~~
cc1: all warnings being treated as errors
make[2]: *** [CMakeFiles/aesrand.dir/build.make:104: CMakeFiles/aesrand.dir/aesrand/aesrand_init.c.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:85: CMakeFiles/aesrand.dir/all] Error 2
make: *** [Makefile:146: all] Error 2

这表示一句警告,简单来说就是在你代码中使用的XXX函数已经被弃用了。不过,这并不影响,在build.sh运行后的生成目录libaesrand下的CMakeLists.txt中,42行下面,添加下面的一句代码(如果因为没有运行过build.sh而没有生成目录,就先执行一次):

set(CMAKE_C_FLAGS "-Wno-error=deprecated-declarations -Wno-deprecated-declarations ")

保存退出,后返回witness-encryption-demos目录继续执行./build.sh命令,会提示compute_clt_witness.c中缺少puzzles/easywallet1.c,但显然目录puzzles下并没用这个文件,应该是作者忘记放上去了,但这个文件并没用被调用过,所以在compute_clt_witness.c中把相应的include代码删除即可。
之后同样是这个文件下,在102行用一个message数组没有被创建或者声明过,就直接被使用了,这个问题也会影响./build.sh的执行,所以我在compute_clt_witness.c的第20行下面添加代码:

int message[256];

在102行下添加代码:

message[b_i]=rand()%2;

之后回到主目录下运行./build.sh成功

之后我们就可以运行测试命令:

ctest -R "test_clt_witness_scheme"

之后如果遇到问题,缺少动态链接库libaesrand,就将witness-encryption-demos/build/lib/下的libaesrand.so文件复制粘贴到根目录的lib或者是usr/lib下,之后执行lgconfig即可。
之后我们就可以运行测试命令:

ctest -R "test_clt_witness_scheme"
ctest -R "compute_clt_witness"
ctest -R "test_clt_state_new"
ctest -R "test_clt"

执行后的输出在testing文件夹下。

但在此之前的message数组的修改会影响运行结果,所以后面为会通过阅读论文,理解代码后,将正确的代码修改的过程发到后续文章中,再进行测试。
同时该代码作者调用的多线性映射部分的代码是在https://github.com/5GenCrypto/clt13这里拉取的,在witness-encryption-demos目录下也能找到,我们运行的ctest -R "test_clt"的代码就是测试clt13代码接口,这一部分是测试成功的,不会被上述所说的message数组的修改而影响。

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值