summaryrefslogtreecommitdiffstats
path: root/test/evp_extra_test.c
diff options
context:
space:
mode:
authorPaul Yang <yang.yang@baishancloud.com>2018-09-04 17:21:10 +0800
committerPaul Yang <yang.yang@baishancloud.com>2018-09-07 18:12:26 +0800
commit4803717f5e3bcfba3e3442e1611f421bf1090a47 (patch)
treef5745d40a7eeb81e8e49f734ae6f962173981eb7 /test/evp_extra_test.c
parent00433bad41bfa492f2e204675d42061314028ff2 (diff)
Support setting SM2 ID
zero-length ID is allowed, but it's not allowed to skip the ID. Fixes: #6534 Reviewed-by: Tim Hudson <tjh@openssl.org> Reviewed-by: Matt Caswell <matt@openssl.org> (Merged from https://github.com/openssl/openssl/pull/7113)
Diffstat (limited to 'test/evp_extra_test.c')
-rw-r--r--test/evp_extra_test.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/test/evp_extra_test.c b/test/evp_extra_test.c
index 33a957f791..2fb3914ee8 100644
--- a/test/evp_extra_test.c
+++ b/test/evp_extra_test.c
@@ -16,6 +16,7 @@
#include <openssl/evp.h>
#include <openssl/rsa.h>
#include <openssl/x509.h>
+#include <openssl/pem.h>
#include "testutil.h"
#include "internal/nelem.h"
#include "internal/evp_int.h"
@@ -530,6 +531,7 @@ static int test_EVP_SM2(void)
EVP_PKEY *params = NULL;
EVP_PKEY_CTX *pctx = NULL;
EVP_PKEY_CTX *kctx = NULL;
+ EVP_PKEY_CTX *sctx = NULL;
size_t sig_len = 0;
unsigned char *sig = NULL;
EVP_MD_CTX *md_ctx = NULL;
@@ -542,6 +544,8 @@ static int test_EVP_SM2(void)
uint8_t plaintext[8];
size_t ptext_len = sizeof(plaintext);
+ uint8_t sm2_id[] = {1, 2, 3, 4, 'l', 'e', 't', 't', 'e', 'r'};
+
pctx = EVP_PKEY_CTX_new_id(EVP_PKEY_EC, NULL);
if (!TEST_ptr(pctx))
goto done;
@@ -574,6 +578,15 @@ static int test_EVP_SM2(void)
if (!TEST_ptr(md_ctx_verify = EVP_MD_CTX_new()))
goto done;
+ if (!TEST_ptr(sctx = EVP_PKEY_CTX_new(pkey, NULL)))
+ goto done;
+
+ EVP_MD_CTX_set_pkey_ctx(md_ctx, sctx);
+ EVP_MD_CTX_set_pkey_ctx(md_ctx_verify, sctx);
+
+ if (!TEST_int_gt(EVP_PKEY_CTX_set1_id(sctx, sm2_id, sizeof(sm2_id)), 0))
+ goto done;
+
if (!TEST_true(EVP_DigestSignInit(md_ctx, NULL, EVP_sm3(), NULL, pkey)))
goto done;
@@ -631,6 +644,7 @@ static int test_EVP_SM2(void)
done:
EVP_PKEY_CTX_free(pctx);
EVP_PKEY_CTX_free(kctx);
+ EVP_PKEY_CTX_free(sctx);
EVP_PKEY_CTX_free(cctx);
EVP_PKEY_free(pkey);
EVP_PKEY_free(params);