Update SM2

This commit is contained in:
Zhi Guan
2024-03-10 22:34:43 +08:00
parent cfdcd0c0e3
commit 33baa3df92
15 changed files with 2410 additions and 268 deletions

59
tools/sm2speed.c Normal file
View File

@@ -0,0 +1,59 @@
/*
* Copyright 2014-2024 The GmSSL Project. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the License); you may
* not use this file except in compliance with the License.
*
* http://www.apache.org/licenses/LICENSE-2.0
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <gmssl/sm2.h>
#include <gmssl/error.h>
int sm2sign_speed(void)
{
SM2_KEY sm2_key;
SM2_SIGN_CTX sign_ctx;
uint8_t msg[32];
uint8_t sig[SM2_MAX_SIGNATURE_SIZE];
size_t siglen;
size_t i;
if (sm2_key_generate(&sm2_key) != 1) {
error_print();
return -1;
}
if (sm2_sign_init(&sign_ctx, &sm2_key, SM2_DEFAULT_ID, strlen(SM2_DEFAULT_ID)) != 1) {
error_print();
return -1;
}
for (i = 0; i < 10000; i++) {
/*
if (sm2_sign_init(&sign_ctx, &sm2_key, SM2_DEFAULT_ID, strlen(SM2_DEFAULT_ID)) != 1) {
error_print();
return -1;
}
*/
if (sm2_sign_ctx_reset(&sign_ctx) != 1
|| sm2_sign_update(&sign_ctx, msg, sizeof(msg)) != 1
|| sm2_sign_finish(&sign_ctx, sig, &siglen) != 1) {
error_print();
return -1;
}
}
return 0;
}
int main(void)
{
sm2sign_speed();
return 0;
}