From bbe0e55a7459e2bd625b5465e67a517712d8c0a2 Mon Sep 17 00:00:00 2001 From: LiTianjue Date: Mon, 18 Jul 2016 14:51:57 +0800 Subject: [PATCH] fix bug sm2test(enc) fail --- .gitignore | 2 ++ crypto/sm2/sm2test.c | 22 +++++++++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index e291efcb..be981d88 100644 --- a/.gitignore +++ b/.gitignore @@ -174,3 +174,5 @@ cscope.* # auto create by Configure crypto/opensslconf.h tool/c_rehash +# exec file +apps/gmssl diff --git a/crypto/sm2/sm2test.c b/crypto/sm2/sm2test.c index e8ac9eb7..fc4ab2a8 100644 --- a/crypto/sm2/sm2test.c +++ b/crypto/sm2/sm2test.c @@ -5,7 +5,7 @@ #include #include #include -#include "./sm2.h" +#include RAND_METHOD fake_rand; const RAND_METHOD *old_rand; @@ -336,7 +336,15 @@ int test_sm2_enc(const EC_GROUP *group, } buflen = sizeof(buf); - if (!SM2_encrypt_with_recommended(buf, &buflen, + if (!SM2_encrypt_with_recommended(NULL, &buflen, + (const unsigned char *)M, strlen(M), ec_key)) { + fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__); + goto end; + } + if(buflen > sizeof(buf)){ + fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__); + goto end; + }else if (!SM2_encrypt_with_recommended(buf, &buflen, (const unsigned char *)M, strlen(M), ec_key)) { fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__); goto end; @@ -354,7 +362,15 @@ int test_sm2_enc(const EC_GROUP *group, fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__); goto end; } - if (!SM2_decrypt_with_recommended(msg, &msglen, buf, buflen, ec_key)) { + + if (!SM2_decrypt_with_recommended(NULL, &msglen, buf, buflen, ec_key)) { + fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__); + goto end; + } + if(msglen > sizeof(msg)){ + fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__); + goto end; + } else if (!SM2_decrypt_with_recommended(msg, &msglen, buf, buflen, ec_key)) { fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__); goto end; }