已合并
fix sm9_bench compile error #949
dumb创建于 2025年12月26日
fix sm9_bench compile error #949
已合并
共 3 个文件变更+8-18
| @@ -16,7 +16,7 @@ PROJECT(openHiTLS_BENCHMARK) | |||
| 16 | 16 | ||
| 17 | set(OPENHITLS_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../..) | 17 | set(OPENHITLS_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../..) |
| 18 | set(BENCHS sm2_bench.c slh_dsa_bench.c ecdsa_bench.c md_bench.c cipher_bench.c mac_bench.c | 18 | set(BENCHS sm2_bench.c slh_dsa_bench.c ecdsa_bench.c md_bench.c cipher_bench.c mac_bench.c |
| 19 | - dh_bench.c ecdh_bench.c 25519_bench.c mldsa_bench.c mlkem_bench.c) | 19 | + dh_bench.c ecdh_bench.c 25519_bench.c mldsa_bench.c mlkem_bench.c sm9_bench.c) |
| 20 | 20 | ||
| 21 | add_compile_options(-g) | 21 | add_compile_options(-g) |
| 22 | # -z noexecstack: Mark the stack as non-executable (ELF security feature) | 22 | # -z noexecstack: Mark the stack as non-executable (ELF security feature) |
| @@ -147,7 +147,9 @@ static StrIdMap g_strIdMap[] = { | |||
| 147 | {"dh-rfc7919-4096", CRYPT_DH_RFC7919_4096}, | 147 | {"dh-rfc7919-4096", CRYPT_DH_RFC7919_4096}, |
| 148 | {"dh-rfc7919-6144", CRYPT_DH_RFC7919_6144}, | 148 | {"dh-rfc7919-6144", CRYPT_DH_RFC7919_6144}, |
| 149 | {"dh-rfc7919-8192", CRYPT_DH_RFC7919_8192}, | 149 | {"dh-rfc7919-8192", CRYPT_DH_RFC7919_8192}, |
| 150 | - | 150 | + {"mlkem-512", CRYPT_KEM_TYPE_MLKEM_512}, |
| 151 | + {"mlkem-768", CRYPT_KEM_TYPE_MLKEM_768}, | ||
| 152 | + {"mlkem-1024", CRYPT_KEM_TYPE_MLKEM_1024}, | ||
| 151 | }; | 153 | }; |
| 152 | 154 | ||
| 153 | static int32_t AlgStr2Id(char *str) | 155 | static int32_t AlgStr2Id(char *str) |
| @@ -60,14 +60,6 @@ static unsigned char g_enc_master_key[32] = { | |||
| 60 | 60 | ||
| 61 | static unsigned char g_user_id[] = "BenchmarkUser"; | 61 | static unsigned char g_user_id[] = "BenchmarkUser"; |
| 62 | 62 | ||
| 63 | -// Random number generator callback | ||
| 64 | -static int32_t RandFunc(uint8_t *randNum, uint32_t randLen) | ||
| 65 | -{ | ||
| 66 | - for (uint32_t i = 0; i < randLen; i++) { | ||
| 67 | - randNum[i] = (uint8_t)(rand() % 255); | ||
| 68 | - } | ||
| 69 | - return 0; | ||
| 70 | -} | ||
| 71 | 63 | ||
| 72 | static int32_t Sm9SetUp(void **ctx, BenchCtx *bench, const CtxOps *ops, int32_t paraId) | 64 | static int32_t Sm9SetUp(void **ctx, BenchCtx *bench, const CtxOps *ops, int32_t paraId) |
| 73 | { | 65 | { |
| @@ -83,10 +75,6 @@ static int32_t Sm9SetUp(void **ctx, BenchCtx *bench, const CtxOps *ops, int32_t | |||
| 83 | return CRYPT_MEM_ALLOC_FAIL; | 75 | return CRYPT_MEM_ALLOC_FAIL; |
| 84 | } | 76 | } |
| 85 | memset(sm9Ctx, 0, sizeof(Sm9Context)); | 77 | memset(sm9Ctx, 0, sizeof(Sm9Context)); |
| 86 | - | ||
| 87 | - // Register random number generator | ||
| 88 | - CRYPT_RandRegist(RandFunc); | ||
| 89 | - | ||
| 90 | // Create SM9 context | 78 | // Create SM9 context |
| 91 | sm9Ctx->ctx = CRYPT_EAL_PkeyNewCtx(CRYPT_PKEY_SM9); | 79 | sm9Ctx->ctx = CRYPT_EAL_PkeyNewCtx(CRYPT_PKEY_SM9); |
| 92 | if (sm9Ctx->ctx == NULL) { | 80 | if (sm9Ctx->ctx == NULL) { |
| @@ -170,7 +158,7 @@ static int32_t Sm9Sign(void *ctx, BenchCtx *bench, BenchOptions *opts) | |||
| 170 | BENCH_TIMES( | 158 | BENCH_TIMES( |
| 171 | CRYPT_EAL_PkeySign(sm9Ctx->ctx, CRYPT_MD_SM3, g_msg, sizeof(g_msg), | 159 | CRYPT_EAL_PkeySign(sm9Ctx->ctx, CRYPT_MD_SM3, g_msg, sizeof(g_msg), |
| 172 | sm9Ctx->sign, &sm9Ctx->signLen), | 160 | sm9Ctx->sign, &sm9Ctx->signLen), |
| 173 | - rc, CRYPT_SUCCESS, sizeof(g_msg), opts->times, "sm9 sign" | 161 | + rc, CRYPT_SUCCESS, (int32_t)sizeof(g_msg), opts->times, "sm9 sign" |
| 174 | ); | 162 | ); |
| 175 | 163 | ||
| 176 | return rc; | 164 | return rc; |
| @@ -193,7 +181,7 @@ static int32_t Sm9Verify(void *ctx, BenchCtx *bench, BenchOptions *opts) | |||
| 193 | BENCH_TIMES( | 181 | BENCH_TIMES( |
| 194 | CRYPT_EAL_PkeyVerify(sm9Ctx->ctx, CRYPT_MD_SM3, g_msg, sizeof(g_msg), | 182 | CRYPT_EAL_PkeyVerify(sm9Ctx->ctx, CRYPT_MD_SM3, g_msg, sizeof(g_msg), |
| 195 | sm9Ctx->sign, sm9Ctx->signLen), | 183 | sm9Ctx->sign, sm9Ctx->signLen), |
| 196 | - rc, CRYPT_SUCCESS, sizeof(g_msg), opts->times, "sm9 verify" | 184 | + rc, CRYPT_SUCCESS, (int32_t)sizeof(g_msg), opts->times, "sm9 verify" |
| 197 | ); | 185 | ); |
| 198 | 186 | ||
| 199 | return rc; | 187 | return rc; |
| @@ -236,7 +224,7 @@ static int32_t Sm9Enc(void *ctx, BenchCtx *bench, BenchOptions *opts) | |||
| 236 | BENCH_TIMES( | 224 | BENCH_TIMES( |
| 237 | CRYPT_EAL_PkeyEncrypt(sm9Ctx->ctx, g_plaintext, sizeof(g_plaintext), | 225 | CRYPT_EAL_PkeyEncrypt(sm9Ctx->ctx, g_plaintext, sizeof(g_plaintext), |
| 238 | sm9Ctx->ciphertext, &sm9Ctx->cipherLen), | 226 | sm9Ctx->ciphertext, &sm9Ctx->cipherLen), |
| 239 | - rc, CRYPT_SUCCESS, sizeof(g_plaintext), opts->times, "sm9 encrypt" | 227 | + rc, CRYPT_SUCCESS, (int32_t)sizeof(g_plaintext), opts->times, "sm9 encrypt" |
| 240 | ); | 228 | ); |
| 241 | 229 | ||
| 242 | return rc; | 230 | return rc; |
| @@ -287,7 +275,7 @@ static int32_t Sm9Dec(void *ctx, BenchCtx *bench, BenchOptions *opts) | |||
| 287 | BENCH_TIMES( | 275 | BENCH_TIMES( |
| 288 | CRYPT_EAL_PkeyDecrypt(sm9Ctx->ctx, sm9Ctx->ciphertext, sm9Ctx->cipherLen, | 276 | CRYPT_EAL_PkeyDecrypt(sm9Ctx->ctx, sm9Ctx->ciphertext, sm9Ctx->cipherLen, |
| 289 | decrypted, &decryptLen), | 277 | decrypted, &decryptLen), |
| 290 | - rc, CRYPT_SUCCESS, sizeof(g_plaintext), opts->times, "sm9 decrypt" | 278 | + rc, CRYPT_SUCCESS, (int32_t)sizeof(g_plaintext), opts->times, "sm9 decrypt" |
| 291 | ); | 279 | ); |
| 292 | 280 | ||
| 293 | return rc; | 281 | return rc; |