mirror of
https://github.com/guanzhi/GmSSL.git
synced 2026-05-07 00:46:17 +08:00
Update CPK sub-lib
Use simple NID as arguments, and fix some bugs
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
all:
|
||||
gcc cpk-setup.c -lcrypto -o cpk-setup
|
||||
gcc cpk-keygen.c -lcrypto -o cpk-keygen
|
||||
gcc cpk-sign.c -lcrypto -o cpk-sign
|
||||
gcc cpk-verify.c -lcrypto -o cpk-verify
|
||||
gcc cpk-setup.c -L/usr/local/lib -lcrypto -o cpk-setup
|
||||
gcc cpk-keygen.c -L/usr/local/lib -lcrypto -o cpk-keygen
|
||||
gcc cpk-sign.c -L/usr/local/lib -lcrypto -o cpk-sign
|
||||
gcc cpk-verify.c -L/usr/local/lib -lcrypto -o cpk-verify
|
||||
|
||||
test:
|
||||
./cpk-setup sign.mpk sign.msk
|
||||
|
||||
@@ -71,12 +71,7 @@ int main(int argc, char **argv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!(map = CPK_MAP_new_default())
|
||||
|| !(ec_key = EC_KEY_new_by_curve_name(NID_sm2p256v1))
|
||||
|| !EC_KEY_generate_key(ec_key)
|
||||
|| !(pkey = EVP_PKEY_new())
|
||||
|| !EVP_PKEY_set1_EC_KEY(pkey, ec_key)
|
||||
|| !(msk = CPK_MASTER_SECRET_create("codesign", pkey, map))
|
||||
if (!(msk = CPK_MASTER_SECRET_create("codesign", 0, NID_cpk_map_sha1))
|
||||
|| !(mpk = CPK_MASTER_SECRET_extract_public_params(msk))) {
|
||||
ERR_print_errors_fp(stderr);
|
||||
goto end;
|
||||
|
||||
@@ -52,6 +52,8 @@
|
||||
#include <libgen.h>
|
||||
#include <openssl/cpk.h>
|
||||
#include <openssl/pem.h>
|
||||
#include <openssl/sm2.h>
|
||||
#include <openssl/is_gmssl.h>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
@@ -100,6 +102,10 @@ int main(int argc, char **argv)
|
||||
ERR_print_errors_fp(stderr);
|
||||
goto end;
|
||||
}
|
||||
if (!EVP_PKEY_CTX_set_ec_scheme(pctx, NID_sm_scheme)) {
|
||||
ERR_print_errors_fp(stderr);
|
||||
goto end;
|
||||
}
|
||||
while ((len = BIO_read(in_bio, buf, sizeof(buf))) > 0) {
|
||||
if (!EVP_DigestSignUpdate(md_ctx, buf, len)) {
|
||||
ERR_print_errors_fp(stderr);
|
||||
|
||||
@@ -51,6 +51,9 @@
|
||||
#include <stdlib.h>
|
||||
#include <libgen.h>
|
||||
#include <openssl/cpk.h>
|
||||
#include <openssl/pem.h>
|
||||
#include <openssl/sm2.h>
|
||||
#include <openssl/is_gmssl.h>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
@@ -65,7 +68,7 @@ int main(int argc, char **argv)
|
||||
EVP_PKEY_CTX *pctx;
|
||||
unsigned char magicstr[] = "~CPK signature appended~";
|
||||
unsigned char magic[sizeof(magicstr)] = {0};
|
||||
unsigned char id[128];
|
||||
unsigned char id[128] = {0};
|
||||
unsigned char sig[128];
|
||||
unsigned int idlen, siglen, totallen;
|
||||
int datalen;
|
||||
@@ -155,6 +158,10 @@ int main(int argc, char **argv)
|
||||
ERR_print_errors_fp(stderr);
|
||||
goto end;
|
||||
}
|
||||
if (!EVP_PKEY_CTX_set_ec_scheme(pctx, NID_sm_scheme)) {
|
||||
ERR_print_errors_fp(stderr);
|
||||
goto end;
|
||||
}
|
||||
|
||||
while (datalen > 0) {
|
||||
unsigned char buf[1024];
|
||||
@@ -182,7 +189,6 @@ int main(int argc, char **argv)
|
||||
}
|
||||
printf("%s: success\n", argv[1]);
|
||||
|
||||
|
||||
ret = 0;
|
||||
end:
|
||||
return ret;
|
||||
|
||||
Reference in New Issue
Block a user