添加栈测量
Some checks failed
CMake / build (OFF, AUTO, SYSTEM, x64, ref, 10, ) (push) Has been cancelled
CMake / build (ON, 32, BUILD, x64, ref, 10, .cmake/32bit.cmake) (push) Has been cancelled
CMake / build (ON, 32, SYSTEM, arm64, ref, 10, ) (push) Has been cancelled
CMake / build (ON, 32, SYSTEM, x64, ref, 10, ) (push) Has been cancelled
CMake / build (ON, AUTO, MINI, x64, ref, 10, ) (push) Has been cancelled
CMake / build (ON, AUTO, SYSTEM, arm64, ref, 10, ) (push) Has been cancelled
CMake / build (ON, AUTO, SYSTEM, x64, broadwell, 10, ) (push) Has been cancelled
CMake / build (ON, AUTO, SYSTEM, x64, ref, 10, ) (push) Has been cancelled
Big-endian s390x test (Daily Workflow) / s390-be (Debug) (push) Has been cancelled
Big-endian s390x test (Daily Workflow) / s390-be (Release) (push) Has been cancelled
Benchmarks (Daily Workflow) / benchmarks (arm64, ref, ) (push) Has been cancelled
Benchmarks (Daily Workflow) / benchmarks (x64, broadwell, 10, ) (push) Has been cancelled
Benchmarks (Daily Workflow) / benchmarks (x64, ref, ) (push) Has been cancelled
Benchmarks (Daily Workflow) / benchmarks (x64, ref, 10, .cmake/32bit.cmake) (push) Has been cancelled
Daily workflow for various checks / checks (push) Has been cancelled
Some checks failed
CMake / build (OFF, AUTO, SYSTEM, x64, ref, 10, ) (push) Has been cancelled
CMake / build (ON, 32, BUILD, x64, ref, 10, .cmake/32bit.cmake) (push) Has been cancelled
CMake / build (ON, 32, SYSTEM, arm64, ref, 10, ) (push) Has been cancelled
CMake / build (ON, 32, SYSTEM, x64, ref, 10, ) (push) Has been cancelled
CMake / build (ON, AUTO, MINI, x64, ref, 10, ) (push) Has been cancelled
CMake / build (ON, AUTO, SYSTEM, arm64, ref, 10, ) (push) Has been cancelled
CMake / build (ON, AUTO, SYSTEM, x64, broadwell, 10, ) (push) Has been cancelled
CMake / build (ON, AUTO, SYSTEM, x64, ref, 10, ) (push) Has been cancelled
Big-endian s390x test (Daily Workflow) / s390-be (Debug) (push) Has been cancelled
Big-endian s390x test (Daily Workflow) / s390-be (Release) (push) Has been cancelled
Benchmarks (Daily Workflow) / benchmarks (arm64, ref, ) (push) Has been cancelled
Benchmarks (Daily Workflow) / benchmarks (x64, broadwell, 10, ) (push) Has been cancelled
Benchmarks (Daily Workflow) / benchmarks (x64, ref, ) (push) Has been cancelled
Benchmarks (Daily Workflow) / benchmarks (x64, ref, 10, .cmake/32bit.cmake) (push) Has been cancelled
Daily workflow for various checks / checks (push) Has been cancelled
This commit is contained in:
@@ -13,6 +13,10 @@
|
||||
#include <tutil.h>
|
||||
#endif
|
||||
|
||||
// 添加栈测量的外部声明
|
||||
extern void* get_stack_start(void);
|
||||
extern size_t get_stack_size(void);
|
||||
|
||||
void
|
||||
bench(size_t runs)
|
||||
{
|
||||
@@ -35,16 +39,29 @@ bench(size_t runs)
|
||||
}
|
||||
|
||||
unsigned long long len;
|
||||
size_t max_stack_size = 0;
|
||||
size_t current_stack_size = 0;
|
||||
void* stack_start = get_stack_start();
|
||||
|
||||
printf("%s (%zu iterations)\n", CRYPTO_ALGNAME, runs);
|
||||
|
||||
BENCH_CODE_1(runs);
|
||||
// 记录密钥生成前的栈指针
|
||||
get_stack_size(); // 初始化栈测量
|
||||
crypto_sign_keypair(pk[i], sk[i]);
|
||||
// 计算密钥生成过程中的最大栈使用量
|
||||
current_stack_size = (char*)stack_start - (char*)¤t_stack_size;
|
||||
if (current_stack_size > max_stack_size) max_stack_size = current_stack_size;
|
||||
BENCH_CODE_2("keypair");
|
||||
|
||||
BENCH_CODE_1(runs);
|
||||
len = sm_len;
|
||||
// 记录签名前的栈指针
|
||||
get_stack_size(); // 重新初始化栈测量
|
||||
crypto_sign(sm[i], &len, m[i], m_len, sk[i]);
|
||||
// 计算签名过程中的最大栈使用量
|
||||
current_stack_size = (char*)stack_start - (char*)¤t_stack_size;
|
||||
if (current_stack_size > max_stack_size) max_stack_size = current_stack_size;
|
||||
if (len != sm_len)
|
||||
abort();
|
||||
BENCH_CODE_2("sign");
|
||||
@@ -52,11 +69,19 @@ bench(size_t runs)
|
||||
int ret;
|
||||
BENCH_CODE_1(runs);
|
||||
len = m_len;
|
||||
// 记录验证前的栈指针
|
||||
get_stack_size(); // 重新初始化栈测量
|
||||
ret = crypto_sign_open(m[i], &len, sm[i], sm_len, pk[i]);
|
||||
// 计算验证过程中的最大栈使用量
|
||||
current_stack_size = (char*)stack_start - (char*)¤t_stack_size;
|
||||
if (current_stack_size > max_stack_size) max_stack_size = current_stack_size;
|
||||
if (ret)
|
||||
abort();
|
||||
BENCH_CODE_2("verify");
|
||||
|
||||
// 输出最大栈使用量
|
||||
printf("Maximum stack usage: %zu bytes\n", max_stack_size);
|
||||
|
||||
free(pkbuf);
|
||||
free(skbuf);
|
||||
free(smbuf);
|
||||
|
||||
Reference in New Issue
Block a user