main #23

Merged
sangge merged 5 commits from :main into main 2023-11-19 20:57:55 +08:00
15 changed files with 260 additions and 20 deletions
Showing only changes of commit f4a866d316 - Show all commits

View File

@ -19,5 +19,5 @@ jobs:
- name: Run script in Docker container
run: |
ls $PWD
docker run -v $PWD:/app git.mamahaha.work/sangge/tpre:base python src/speed_test.py
ls $PWD/src
docker run -v .:/app git.mamahaha.work/sangge/tpre:base ls

View File

@ -68,7 +68,7 @@ pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
```bash
docker build . -f basedockerfile -t git.mamahaha.work/sangge/tpre:base
docker pull git.mamahaha.work/sangge/tpre:base
(or docker pull git.mamahaha.work/sangge/tpre:base)
docker build . -t your_image_name
```
@ -76,7 +76,6 @@ docker build . -t your_image_name
```bash
docker pull git.mamahaha.work/sangge/tpre:latest
docker run git.mamahaha.work/sangge/tpre:latest
```
## Usage Instructions

BIN
lib/linux/arm64/libgmssl.so Executable file

Binary file not shown.

BIN
lib/linux/arm64/libgmssl.so.3 Executable file

Binary file not shown.

BIN
lib/linux/arm64/libgmssl.so.3.1 Executable file

Binary file not shown.

BIN
lib/linux/arm64/libsdf_dummy.so Executable file

Binary file not shown.

BIN
lib/linux/arm64/libsdf_dummy.so.3 Executable file

Binary file not shown.

Binary file not shown.

BIN
lib/linux/arm64/libskf_dummy.so Executable file

Binary file not shown.

BIN
lib/linux/arm64/libskf_dummy.so.3 Executable file

Binary file not shown.

Binary file not shown.

63
src/lenth_test.py Normal file
View File

@ -0,0 +1,63 @@
from tpre import *
import time
N = 20
T = N // 2
print(f"当前门限值: N = {N}, T = {T}")
for i in range(1, 10):
total_time = 0
# 1
start_time = time.time()
pk_a, sk_a = GenerateKeyPair()
m = b"hello world" * pow(10, i)
print(f"明文长度:{len(m)}")
end_time = time.time()
elapsed_time = end_time - start_time
total_time += elapsed_time
print(f"密钥生成运行时间:{elapsed_time}")
# 2
start_time = time.time()
capsule_ct = Encrypt(pk_a, m)
end_time = time.time()
elapsed_time = end_time - start_time
total_time += elapsed_time
print(f"加密算法运行时间:{elapsed_time}")
# 3
pk_b, sk_b = GenerateKeyPair()
# 5
start_time = time.time()
id_tuple = tuple(range(N))
rekeys = GenerateReKey(sk_a, pk_b, N, T, id_tuple)
end_time = time.time()
elapsed_time = end_time - start_time
total_time += elapsed_time
print(f"重加密密钥生成算法运行时间:{elapsed_time}")
# 7
start_time = time.time()
cfrag_cts = []
for rekey in rekeys:
cfrag_ct = ReEncrypt(rekey, capsule_ct)
cfrag_cts.append(cfrag_ct)
end_time = time.time()
elapsed_time = (end_time - start_time) / len(rekeys)
total_time += elapsed_time
print(f"重加密算法运行时间:{elapsed_time}")
# 9
start_time = time.time()
cfrags = mergecfrag(cfrag_cts)
m = DecryptFrags(sk_b, pk_b, pk_a, cfrags)
end_time = time.time()
elapsed_time = end_time - start_time
total_time += elapsed_time
print(f"解密算法运行时间:{elapsed_time}")
print("成功解密:")
print(f"算法总运行时间:{total_time}")
print()

66
src/maxnode_test.py Normal file
View File

@ -0,0 +1,66 @@
from tpre import *
import time
N = 80
total_time = 0
while total_time < 1:
T = N // 2
print(f"当前门限值: N = {N}, T = {T}")
total_time = 0
# 1
start_time = time.time()
pk_a, sk_a = GenerateKeyPair()
m = b"hello world"
end_time = time.time()
elapsed_time = end_time - start_time
total_time += elapsed_time
# print(f"密钥生成运行时间:{elapsed_time}秒")
# 2
start_time = time.time()
capsule_ct = Encrypt(pk_a, m)
end_time = time.time()
elapsed_time = end_time - start_time
total_time += elapsed_time
# print(f"加密算法运行时间:{elapsed_time}秒")
# 3
pk_b, sk_b = GenerateKeyPair()
# 5
start_time = time.time()
id_tuple = tuple(range(N))
rekeys = GenerateReKey(sk_a, pk_b, N, T, id_tuple)
end_time = time.time()
elapsed_time = end_time - start_time
total_time += elapsed_time
# print(f"重加密密钥生成算法运行时间:{elapsed_time}秒")
# 7
start_time = time.time()
cfrag_cts = []
for rekey in rekeys:
cfrag_ct = ReEncrypt(rekey, capsule_ct)
cfrag_cts.append(cfrag_ct)
end_time = time.time()
elapsed_time = (end_time - start_time) / len(rekeys)
total_time += elapsed_time
# print(f"重加密算法运行时间:{elapsed_time}秒")
# 9
start_time = time.time()
cfrags = mergecfrag(cfrag_cts)
m = DecryptFrags(sk_b, pk_b, pk_a, cfrags)
end_time = time.time()
elapsed_time = end_time - start_time
total_time += elapsed_time
# print(f"解密算法运行时间:{elapsed_time}秒")
# print("成功解密:", m)
print(f"算法总运行时间:{total_time}")
print()
N += 1

View File

@ -1,12 +1,4 @@
default
当前门限值: N = 20, T = 10
密钥生成运行时间:0.0026531219482421875秒
加密算法运行时间:0.005305290222167969秒
重加密密钥生成算法运行时间:0.0764169692993164秒
重加密算法运行时间:0.007088994979858399秒
解密算法运行时间:0.08717870712280273秒
成功解密: b'hello world'
算法总运行时间:0.1786430835723877秒
12th Gen Intel(R) Core(TM) i5-12490F
0.01 cores
当前门限值: N = 20, T = 10
@ -46,4 +38,111 @@ default
重加密算法运行时间:0.006896591186523438秒
解密算法运行时间:0.08880448341369629秒
成功解密: b'hello world'
算法总运行时间:0.17643699645996094秒
算法总运行时间:0.17643699645996094秒
rk3399
0.01 cores
当前门限值: N = 20, T = 10
密钥生成运行时间:3.9984750747680664秒
加密算法运行时间:9.599598169326782秒
重加密密钥生成算法运行时间:132.99906015396118秒
重加密算法运行时间:12.120013177394867秒
解密算法运行时间:153.29800581932068秒
成功解密: b'hello world'
算法总运行时间:312.0151523947716秒
0.1 cores
当前门限值: N = 20, T = 10
密钥生成运行时间:0.09907650947570801秒
加密算法运行时间:0.205247163772583秒
重加密密钥生成算法运行时间:7.498294830322266秒
重加密算法运行时间:0.7300507187843323秒
解密算法运行时间:8.998314619064331秒
成功解密: b'hello world'
算法总运行时间:17.53098384141922秒
1 cores
当前门限值: N = 20, T = 10
密钥生成运行时间:0.008650541305541992秒
加密算法运行时间:0.02130866050720215秒
重加密密钥生成算法运行时间:0.30187034606933594秒
重加密算法运行时间:0.0274674654006958秒
解密算法运行时间:0.3521096706390381秒
成功解密: b'hello world'
算法总运行时间:0.7114066839218139秒
4 cores
当前门限值: N = 20, T = 10
密钥生成运行时间:0.00883340835571289秒
加密算法运行时间:0.021309614181518555秒
重加密密钥生成算法运行时间:0.3036940097808838秒
重加密算法运行时间:0.0277299165725708秒
解密算法运行时间:0.3464491367340088秒
成功解密: b'hello world'
算法总运行时间:0.7080160856246949秒
12th Gen Intel(R) Core(TM) i5-12490F
当前门限值: N = 20, T = 10
明文长度:110
密钥生成运行时间:0.0033216476440429688秒
加密算法运行时间:0.00811624526977539秒
重加密密钥生成算法运行时间:0.11786699295043945秒
重加密算法运行时间:0.009650790691375732秒
解密算法运行时间:0.12125396728515625秒
成功解密:
算法总运行时间:0.2602096438407898秒
明文长度:1100
密钥生成运行时间:0.0034990310668945312秒
加密算法运行时间:0.008537054061889648秒
重加密密钥生成算法运行时间:0.10165071487426758秒
重加密算法运行时间:0.009756004810333252秒
解密算法运行时间:0.13438773155212402秒
成功解密:
算法总运行时间:0.257830536365509秒
明文长度:11000
密钥生成运行时间:0.0035142898559570312秒
加密算法运行时间:0.005819797515869141秒
重加密密钥生成算法运行时间:0.1130058765411377秒
重加密算法运行时间:0.010429942607879638秒
解密算法运行时间:0.1242990493774414秒
成功解密:
算法总运行时间:0.25706895589828493秒
明文长度:110000
密钥生成运行时间:0.002706289291381836秒
加密算法运行时间:0.00833749771118164秒
重加密密钥生成算法运行时间:0.11022734642028809秒
重加密算法运行时间:0.010864639282226562秒
解密算法运行时间:0.13867974281311035秒
成功解密:
算法总运行时间:0.2708155155181885秒
明文长度:1100000
密钥生成运行时间:0.003710031509399414秒
加密算法运行时间:0.04558920860290527秒
重加密密钥生成算法运行时间:0.10261368751525879秒
重加密算法运行时间:0.009720635414123536秒
解密算法运行时间:0.15311646461486816秒
成功解密:
算法总运行时间:0.3147500276565552秒
明文长度:11000000
密钥生成运行时间:0.008045673370361328秒
加密算法运行时间:0.3575568199157715秒
重加密密钥生成算法运行时间:0.09267783164978027秒
重加密算法运行时间:0.009347784519195556秒
解密算法运行时间:0.4754812717437744秒
成功解密:
算法总运行时间:0.9431093811988831秒
当前门限值: N = 94, T = 47
算法总运行时间:0.967951292687274秒
当前门限值: N = 95, T = 47
算法总运行时间:0.9765587304767809秒
当前门限值: N = 96, T = 48
算法总运行时间:1.019304744899273秒

View File

@ -1,8 +1,21 @@
# todolist
测试单核和多核性能
测试不同cpu性能的差异
测试极限1s时的节点数
非docker部署需要获取本机ip
复习预备知识
准备圆场话术
- [x] 测试单核和多核性能
- 这个算法在获得足够的CPU资源即接近或等于1个完整核心时表现最佳。
- 过低的CPU资源分配会严重影响性能而适度的分配如0.1核心)则能提供更合理的性能。
- 单核和多核性能差异不大
- [x] 测试不同cpu架构性能的差异
- 测试了12th Gen Intel(R) Core(TM) i5-12490F 和 rk3399两颗cpu的性能
- [x] 测试不同消息长度的时间
- 测试了10M文本的加密速度在1s内可以完成全部算法内容
- [ ] 测试极限1s时的节点数
- 12th Gen i5 CPU大概是90多个节点时达到1s的时间上限
- [x] 非docker部署需要获取本机ip
- 添加了通过网卡获取ip的方法
- [ ] 复习预备知识
- [ ] 准备圆场话术