Update tools use v3 API

This commit is contained in:
Zhi Guan
2022-02-27 19:11:01 +08:00
parent 381bfb5b99
commit cadbb542e3
6 changed files with 18 additions and 14 deletions

View File

@@ -56,9 +56,11 @@
int main(void) int main(void)
{ {
X509_CERTIFICATE cert; uint8_t cert[1024];
size_t certlen;
for (;;) { for (;;) {
int ret = x509_certificate_from_pem(&cert, stdin); int ret = x509_cert_from_pem(cert, &certlen, sizeof(cert), stdin);
if (ret < 0) { if (ret < 0) {
error_print(); error_print();
return -1; return -1;
@@ -67,8 +69,8 @@ int main(void)
goto end; goto end;
} }
fprintf(stdout, "Certificate\n"); fprintf(stdout, "Certificate\n");
x509_certificate_print(stdout, &cert, 0, 0); x509_cert_print(stdout, 0, 0, cert, certlen);
x509_certificate_to_pem(&cert, stdout); x509_cert_to_pem(cert, certlen, stdout);
fprintf(stdout, "\n"); fprintf(stdout, "\n");
} }
end: end:

View File

@@ -70,7 +70,8 @@ int main(int argc, char **argv)
FILE *certfp = NULL; FILE *certfp = NULL;
FILE *infp = stdin; FILE *infp = stdin;
FILE *outfp = stdout; FILE *outfp = stdout;
X509_CERTIFICATE cert; uint8_t cert[1024];
size_t certlen;
SM2_KEY key; SM2_KEY key;
uint8_t inbuf[SM2_MAX_PLAINTEXT_SIZE]; uint8_t inbuf[SM2_MAX_PLAINTEXT_SIZE];
uint8_t outbuf[SM2_MAX_CIPHERTEXT_SIZE]; uint8_t outbuf[SM2_MAX_CIPHERTEXT_SIZE];
@@ -122,11 +123,11 @@ help:
error_print(); error_print();
return -1; return -1;
} }
if (x509_certificate_from_pem(&cert, certfp) != 1) { if (x509_cert_from_pem(cert, &certlen, sizeof(cert), certfp) != 1) {
error_print(); error_print();
return -1; return -1;
} }
if (x509_certificate_get_public_key(&cert, &key) != 1) { if (x509_cert_get_subject_public_key(cert, certlen, &key) != 1) {
error_print(); error_print();
return -1; return -1;
} }

View File

@@ -129,7 +129,7 @@ help:
} }
} }
if (sm2_keygen(&key) != 1) { if (sm2_key_generate(&key) != 1) {
error_print(); error_print();
return -1; return -1;
} }

View File

@@ -156,7 +156,7 @@ help:
return -1; return -1;
} }
sm2_sign_init(&sign_ctx, &key, id); sm2_sign_init(&sign_ctx, &key, id, strlen(id));
while ((len = fread(buf, 1, sizeof(buf), infp)) > 0) { while ((len = fread(buf, 1, sizeof(buf), infp)) > 0) {
sm2_sign_update(&sign_ctx, buf, len); sm2_sign_update(&sign_ctx, buf, len);

View File

@@ -74,8 +74,9 @@ int main(int argc, char **argv)
FILE *infp = stdin; FILE *infp = stdin;
FILE *sigfp = NULL; FILE *sigfp = NULL;
SM2_KEY key; SM2_KEY key;
X509_CERTIFICATE cert;
SM2_SIGN_CTX verify_ctx; SM2_SIGN_CTX verify_ctx;
uint8_t cert[1024];
size_t certlen;
uint8_t buf[4096]; uint8_t buf[4096];
ssize_t len; ssize_t len;
uint8_t sig[SM2_MAX_SIGNATURE_SIZE]; uint8_t sig[SM2_MAX_SIGNATURE_SIZE];
@@ -134,11 +135,11 @@ help:
error_print(); error_print();
return -1; return -1;
} }
if (x509_certificate_from_pem(&cert, certfp) != 1) { if (x509_cert_from_pem(cert, &certlen, sizeof(cert), certfp) != 1) {
error_print(); error_print();
return -1; return -1;
} }
if (x509_certificate_get_public_key(&cert, &key) != 1) { if (x509_cert_get_subject_public_key(cert, certlen, &key) != 1) {
error_print(); error_print();
return -1; return -1;
} }
@@ -167,7 +168,7 @@ help:
return -1; return -1;
} }
sm2_verify_init(&verify_ctx, &key, id); sm2_verify_init(&verify_ctx, &key, id, strlen(id));
while ((len = fread(buf, 1, sizeof(buf), infp)) > 0) { while ((len = fread(buf, 1, sizeof(buf), infp)) > 0) {
sm2_verify_update(&verify_ctx, buf, len); sm2_verify_update(&verify_ctx, buf, len);
} }

View File

@@ -117,7 +117,7 @@ help:
id = SM2_DEFAULT_ID; id = SM2_DEFAULT_ID;
} }
sm2_compute_z(z, (SM2_POINT *)&sm2_key, id); sm2_compute_z(z, (SM2_POINT *)&sm2_key, id, strlen(id));
sm3_update(&sm3_ctx, z, sizeof(z)); sm3_update(&sm3_ctx, z, sizeof(z));
} else { } else {