mirror of
https://github.com/guanzhi/GmSSL.git
synced 2026-05-07 00:46:17 +08:00
Bug fix
Thanks to github.com/Jkinglyf
This commit is contained in:
@@ -6,6 +6,7 @@ keyfile=eckey.pem
|
||||
pubkeyfile=ecpubkey.pem
|
||||
pkeyopt="-pkeyopt ec_paramgen_curve:sm2p256v1"
|
||||
|
||||
|
||||
#echo -n abc | $gmssl dgst -sm3
|
||||
#echo -n abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd | gmssl dgst -sm3
|
||||
|
||||
@@ -17,11 +18,10 @@ $gmssl genpkey -algorithm EC -out sm2key.pem -pkeyopt ec_paramgen_curve:sm2p256v
|
||||
#$gmssl pkey -text -noout -in sm2key.pem
|
||||
#$gmssl pkey -in sm2key.pem -pubout -out sm2pubkey.pem
|
||||
#$gmssl pkey -text -noout -pubin -in $pubkeyfile
|
||||
#echo hello | $gmssl pkeyutl -sign -inkey sm2key.pem -pkeyopt ec_sign_algor:sm2 > sm2sig.der
|
||||
#echo hello | $gmssl pkeyutl -verify -inkey sm2key.pem -sigfile sm2sig.der -pkeyopt ec_sign_algor:sm2
|
||||
#echo hello | $gmssl pkeyutl -encrypt -inkey sm2key.pem -pkeyopt ec_encrypt_algor:sm2 > sm2ciphertext.bin
|
||||
#cat sm2ciphertext.bin | $gmssl pkeyutl -decrypt -inkey sm2key.pem -pkeyopt ec_encrypt_algor:sm2
|
||||
echo hello | $gmssl pkeyutl -sign -inkey sm2key.pem -pkeyopt ec_sign_algor:sm2 > sm2sig.der
|
||||
echo hello | $gmssl pkeyutl -verify -inkey sm2key.pem -sigfile sm2sig.der -pkeyopt ec_sign_algor:sm2
|
||||
echo hello | $gmssl pkeyutl -encrypt -inkey sm2key.pem -pkeyopt ec_encrypt_algor:sm2 > sm2ciphertext.bin
|
||||
cat sm2ciphertext.bin | $gmssl pkeyutl -decrypt -inkey sm2key.pem -pkeyopt ec_encrypt_algor:sm2
|
||||
|
||||
|
||||
$gmssl req -new -x509 -days 3650 -key sm2key.pem -out cert.pem -pkeyopt ec_sign_algor:sm2
|
||||
#$gmssl x509 -text -noout -in $DIR/cacert.pem
|
||||
|
||||
@@ -1,38 +1,9 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <openssl/pem.h>
|
||||
#include <openssl/conf.h>
|
||||
#include <openssl/x509v3.h>
|
||||
|
||||
int mkit(X509 **x509p, EVP_PKEY **pkeyp, int bits, int serial, int days);
|
||||
|
||||
int main()
|
||||
{
|
||||
BIO *bio_err;
|
||||
X509 *x509 = NULL;
|
||||
EVP_PKEY *pkey = NULL;
|
||||
|
||||
CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
|
||||
|
||||
bio_err = BIO_new_fp(stderr, BIO_NOCLOSE);
|
||||
|
||||
mkit(&x509, &pkey, 512, 0, 365);
|
||||
|
||||
EC_KEY_print_fp(stdout, pkey->pkey.ec, 0);
|
||||
X509_print_fp(stdout, x509);
|
||||
|
||||
PEM_write_PrivateKey(stdout, pkey, NULL, NULL, 0, NULL, NULL);
|
||||
PEM_write_X509(stdout, x509);
|
||||
|
||||
X509_free(x509);
|
||||
EVP_PKEY_free(pkey);
|
||||
|
||||
CRYPTO_mem_leaks(bio_err);
|
||||
BIO_free(bio_err);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int mkit(X509 **x509p, EVP_PKEY **pkeyp, int bits, int serial, int days)
|
||||
{
|
||||
X509 *x;
|
||||
@@ -51,8 +22,8 @@ int mkit(X509 **x509p, EVP_PKEY **pkeyp, int bits, int serial, int days)
|
||||
pk = *pkeyp;
|
||||
|
||||
if ((x509p == NULL) || (*x509p == NULL)) {
|
||||
if ((x = X509_new()) == NULL)
|
||||
goto err;
|
||||
if ((x = X509_new()) == NULL)
|
||||
goto err;
|
||||
} else {
|
||||
x = *x509p;
|
||||
}
|
||||
@@ -115,6 +86,33 @@ int mkit(X509 **x509p, EVP_PKEY **pkeyp, int bits, int serial, int days)
|
||||
*x509p = x;
|
||||
*pkeyp = pk;
|
||||
return (1);
|
||||
err:
|
||||
err:
|
||||
return (0);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
BIO *bio_err;
|
||||
X509 *x509 = NULL;
|
||||
EVP_PKEY *pkey = NULL;
|
||||
|
||||
CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
|
||||
|
||||
bio_err = BIO_new_fp(stderr, BIO_NOCLOSE);
|
||||
|
||||
|
||||
mkit(&x509, &pkey, 512, 0, 365);
|
||||
|
||||
EC_KEY_print_fp(stdout, pkey->pkey.ec, 0);
|
||||
X509_print_fp(stdout, x509);
|
||||
|
||||
PEM_write_PrivateKey(stdout, pkey, NULL, NULL, 0, NULL, NULL);
|
||||
PEM_write_X509(stdout, x509);
|
||||
|
||||
X509_free(x509);
|
||||
EVP_PKEY_free(pkey);
|
||||
|
||||
CRYPTO_mem_leaks(bio_err);
|
||||
BIO_free(bio_err);
|
||||
return (0);
|
||||
}
|
||||
0
demos/gmssl/sm2ciphertext.bin
Normal file
0
demos/gmssl/sm2ciphertext.bin
Normal file
@@ -1,5 +1,5 @@
|
||||
-----BEGIN PRIVATE KEY-----
|
||||
MIGHAgEAMBMGByqGSM49AgEGCCqBHM9VAYItBG0wawIBAQQg2MM/g28XAEne6VG/
|
||||
cPYUhVq8H0D/5igtUw9CUaxr2KWhRANCAAQdCrdYHfnyeFhcFQuyRrCxuGH1/bnS
|
||||
wDKinlLUFyVa72SlAz5tBaA4TPY2m5259/55lTkdVkq6gtvyW7L/VFTg
|
||||
MIGHAgEAMBMGByqGSM49AgEGCCqBHM9VAYItBG0wawIBAQQgyeMq+RmwB95Ohl+U
|
||||
K1KmE5/3OzxoG1lOpbyMu8sZxrqhRANCAATGmXcprKn9kYmMBKBLaxckcTFqDzNF
|
||||
qDwzk8rTcWr5/2CmI9KGeSMbp7G9X/v8qh/RIattztrYXlrVP0h7Zk+A
|
||||
-----END PRIVATE KEY-----
|
||||
|
||||
0
demos/gmssl/sm2sig.der
Normal file
0
demos/gmssl/sm2sig.der
Normal file
Reference in New Issue
Block a user