mirror of
https://github.com/guanzhi/GmSSL.git
synced 2026-05-27 02:36:29 +08:00
Adjust SM3 SM4 API
Remove sm3_digest. Use more _gmssl_export
This commit is contained in:
@@ -12,10 +12,8 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <gmssl/sm2.h>
|
||||
#include <gmssl/sm2_z256.h>
|
||||
#include <gmssl/sm3.h>
|
||||
#include <gmssl/sm3_digest.h>
|
||||
#include <gmssl/hex.h>
|
||||
#include <gmssl/rand.h>
|
||||
#include <gmssl/error.h>
|
||||
|
||||
@@ -144,14 +144,18 @@ static int test_sm3(void)
|
||||
uint8_t testbuf[sizeof(testhex)/2 + 1000];
|
||||
uint8_t dgstbuf[32];
|
||||
size_t testbuflen, dgstbuflen;
|
||||
SM3_CTX sm3_ctx;
|
||||
uint8_t dgst[32];
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < sizeof(testhex)/sizeof(testhex[0]); i++) {
|
||||
|
||||
hex_to_bytes(testhex[i], strlen(testhex[i]), testbuf, &testbuflen);
|
||||
hex_to_bytes(dgsthex[i], strlen(dgsthex[i]), dgstbuf, &dgstbuflen);
|
||||
|
||||
sm3_digest(testbuf, testbuflen, dgst);
|
||||
sm3_init(&sm3_ctx);
|
||||
sm3_update(&sm3_ctx, testbuf, testbuflen);
|
||||
sm3_finish(&sm3_ctx, dgst);
|
||||
|
||||
if (memcmp(dgstbuf, dgst, sizeof(dgst)) != 0) {
|
||||
int n;
|
||||
|
||||
@@ -80,7 +80,7 @@ static int test_sm4(void)
|
||||
memset(&key, 0, sizeof(key));
|
||||
memset(buf, 0, sizeof(buf));
|
||||
sm4_set_decrypt_key(&key, user_key);
|
||||
sm4_decrypt(&key, ciphertext, buf);
|
||||
sm4_encrypt(&key, ciphertext, buf);
|
||||
if (memcmp(buf, plaintext, sizeof(plaintext)) != 0) {
|
||||
fprintf(stderr, "sm4 decrypt not pass!\n");
|
||||
return -1;
|
||||
@@ -185,7 +185,7 @@ static int test_sm4_ctr(void)
|
||||
sm4_ctr_encrypt(&sm4_key, ctr, buf1, sizeof(buf1), buf2);
|
||||
|
||||
memset(ctr, 0, sizeof(ctr));
|
||||
sm4_ctr_decrypt(&sm4_key, ctr, buf2, sizeof(buf2), buf3);
|
||||
sm4_ctr_encrypt(&sm4_key, ctr, buf2, sizeof(buf2), buf3);
|
||||
|
||||
if (memcmp(buf1, buf3, sizeof(buf3)) != 0) {
|
||||
fprintf(stderr, "%s %d: error\n", __FILE__, __LINE__);
|
||||
@@ -229,7 +229,7 @@ static int test_sm4_ctr_with_carray(void)
|
||||
}
|
||||
|
||||
hex_to_bytes(hex_ctr, strlen(hex_ctr), ctr, &ctrlen);
|
||||
sm4_ctr_decrypt(&sm4_key, ctr, buf3, sizeof(buf3), buf2);
|
||||
sm4_ctr_encrypt(&sm4_key, ctr, buf3, sizeof(buf3), buf2);
|
||||
|
||||
if (memcmp(buf2, buf1, sizeof(buf1)) != 0) {
|
||||
error_print();
|
||||
@@ -690,7 +690,7 @@ static int test_sm4_ctr_update_multi_times(void)
|
||||
in = cbuf;
|
||||
out = pbuf;
|
||||
for (i = 0; i < sizeof(lens)/sizeof(lens[0]); i++) {
|
||||
if (sm4_ctr_decrypt_update(&dec_ctx, in, lens[i], out, &len) != 1) {
|
||||
if (sm4_ctr_encrypt_update(&dec_ctx, in, lens[i], out, &len) != 1) {
|
||||
error_print();
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -204,7 +204,11 @@ static int test_x509_authority_key_identifier(void)
|
||||
const uint8_t *serialp;
|
||||
size_t seriallen;
|
||||
|
||||
sm3_digest((uint8_t *)"abc", 3, keyid);
|
||||
SM3_CTX sm3_ctx;
|
||||
sm3_init(&sm3_ctx);
|
||||
sm3_update(&sm3_ctx, (uint8_t *)"abc", 3);
|
||||
sm3_finish(&sm3_ctx, keyid);
|
||||
|
||||
rand_bytes(serial, sizeof(serial));
|
||||
|
||||
if (x509_authority_key_identifier_to_der(
|
||||
@@ -796,7 +800,8 @@ static int test_x509_cert_with_exts(void)
|
||||
time(¬_before);
|
||||
x509_validity_add_days(¬_after, not_before, 365);
|
||||
sm2_key_generate(&sm2_key);
|
||||
sm3_digest((uint8_t *)&(sm2_key.public_key), sizeof(SM2_POINT), uniq_id);
|
||||
|
||||
sm2_public_key_digest(&sm2_key, uniq_id);
|
||||
|
||||
if (x509_exts_add_authority_key_identifier(exts, &extslen, sizeof(exts), 1,
|
||||
keyid, sizeof(keyid),
|
||||
|
||||
Reference in New Issue
Block a user