This commit is contained in:
Zhi Guan
2017-05-15 17:23:26 +08:00
parent bba5011e7c
commit 79e2936664
24 changed files with 531 additions and 76 deletions

71
test/base58test.c Normal file
View File

@@ -0,0 +1,71 @@
/* ====================================================================
* Copyright (c) 2014 - 2017 The GmSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the GmSSL Project.
* (http://gmssl.org/)"
*
* 4. The name "GmSSL Project" must not be used to endorse or promote
* products derived from this software without prior written
* permission. For written permission, please contact
* guanzhi1980@gmail.com.
*
* 5. Products derived from this software may not be called "GmSSL"
* nor may "GmSSL" appear in their names without prior written
* permission of the GmSSL Project.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the GmSSL Project
* (http://gmssl.org/)"
*
* THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "../e_os.h"
#ifdef OPENSSL_NO_BASE58
int main(int argc, char **argv)
{
printf("No BASE58 support\n");
return 0;
}
#else
# include <openssl/evp.h>
# include <openssl/base58.h>
int main(int argc, char **argv)
{
int err = 0;
EXIT(err);
}
#endif

View File

@@ -21,7 +21,7 @@ IF[{- !$disabled{tests} -}]
pailliertest cpktest otptest gmapitest ec2test \
bfibetest bb1ibetest sm9test \
saftest sdftest skftest softest zuctest \
serpenttest specktest
serpenttest specktest base58test
SOURCE[aborttest]=aborttest.c
INCLUDE[aborttest]=../include
@@ -376,6 +376,10 @@ IF[{- !$disabled{tests} -}]
INCLUDE[specktest]=../include
DEPEND[specktest]=../libcrypto
SOURCE[base58test]=base58test.c
INCLUDE[base58test]=../include
DEPEND[base58test]=../libcrypto
IF[{- !$disabled{shared} -}]
PROGRAMS_NO_INST=shlibloadtest
SOURCE[shlibloadtest]=shlibloadtest.c

View File

@@ -0,0 +1,12 @@
#! /usr/bin/env perl
# Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
#
# Licensed under the OpenSSL license (the "License"). You may not use
# this file except in compliance with the License. You can obtain a copy
# in the file LICENSE in the source distribution or at
# https://www.openssl.org/source/license.html
use OpenSSL::Test::Simple;
simple_test("test_base58", "base58test", "base58");

View File

@@ -1,3 +1,54 @@
/* ====================================================================
* Copyright (c) 2014 - 2017 The GmSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the GmSSL Project.
* (http://gmssl.org/)"
*
* 4. The name "GmSSL Project" must not be used to endorse or promote
* products derived from this software without prior written
* permission. For written permission, please contact
* guanzhi1980@gmail.com.
*
* 5. Products derived from this software may not be called "GmSSL"
* nor may "GmSSL" appear in their names without prior written
* permission of the GmSSL Project.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the GmSSL Project
* (http://gmssl.org/)"
*
* THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*/
// test unit for serpent-256
// Odzhan

View File

@@ -208,6 +208,10 @@ static int test_evp_pkey_encrypt(EVP_PKEY *pkey, int do_sm2, int verbose)
goto end;
}
/* we need to set the sm2 encrypt params (hash = sm3) */
cbuflen = sizeof(cbuf);
if (!EVP_PKEY_encrypt(pkctx, cbuf, &cbuflen, msg, msglen)) {
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
@@ -251,6 +255,7 @@ static int test_evp_pkey_encrypt(EVP_PKEY *pkey, int do_sm2, int verbose)
ret = 1;
end:
ERR_print_errors_fp(stderr);
EVP_PKEY_CTX_free(pkctx);
return ret;
}
@@ -590,14 +595,14 @@ int main(int argc, char **argv)
goto end;
}
if (!test_evp_pkey_sign(pkey, 1, verbose)) err++;
if (!test_evp_pkey_sign(pkey, 0, verbose)) err++;
//if (!test_evp_pkey_sign(pkey, 1, 0)) err++;
//if (!test_evp_pkey_sign(pkey, 0, 0)) err++;
if (!test_evp_pkey_encrypt(pkey, 1, verbose)) err++;
if (!test_evp_pkey_encrypt(pkey, 0, verbose)) err++;
if (!test_evp_pkey_encrypt_old(pkey, verbose)) err++;
if (!test_evp_sign(pkey, md, verbose)) err++;
if (!test_evp_seal(curve_id, cipher, out, verbose)) err++;
if (!test_evp_digestsign(pkey, 1, md, verbose)) err++;
//if (!test_evp_pkey_encrypt(pkey, 0, verbose)) err++;
//if (!test_evp_pkey_encrypt_old(pkey, verbose)) err++;
//if (!test_evp_sign(pkey, md, 0)) err++;
//if (!test_evp_seal(curve_id, cipher, out, verbose)) err++;
//if (!test_evp_digestsign(pkey, 1, md, verbose)) err++;
end:
EVP_PKEY_free(pkey);

View File

@@ -67,7 +67,6 @@ int main(int argc, char **argv)
# include <openssl/sm2.h>
# include "../crypto/sm2/sm2_lcl.h"
#if 0
# define VERBOSE 1
@@ -424,19 +423,18 @@ static int test_sm2_enc(const EC_GROUP *group, const EVP_MD *md,
EC_KEY *pub_key = NULL;
EC_KEY *pri_key = NULL;
SM2CiphertextValue *cv = NULL;
unsigned char mbuf[128];
unsigned char cbuf[sizeof(mbuf) + 256];
unsigned char *tbuf = NULL;
size_t msglen, buflen;
unsigned char *p = buf;
unsigned char *testcbuf;
long testbuflen;
long tlen;
unsigned char mbuf[128] = {0};
unsigned char cbuf[sizeof(mbuf) + 256] = {0};
size_t mlen, clen;
unsigned char *p;
/* test encrypt */
if (!(pub_key = new_ec_key(group, NULL, xP, yP, NULL, NULL))) {
goto end;
}
/* test encrypt */
change_rand(k);
if (!(cv = SM2_do_encrypt(md, (unsigned char *)M, strlen(M), pub_key))) {
goto end;
@@ -456,7 +454,6 @@ static int test_sm2_enc(const EC_GROUP *group, const EVP_MD *md,
}
/* test decrypt */
if (!(pri_key = new_ec_key(group, d, xP, yP, NULL, NULL))) {
goto end;
}
@@ -475,8 +472,10 @@ static int test_sm2_enc(const EC_GROUP *group, const EVP_MD *md,
end:
ERR_print_errors_fp(stderr);
restore_rand();
EC_KEY_free(ec_key);
EC_KEY_free(pub_key);
EC_KEY_free(pri_key);
SM2CiphertextValue_free(cv);
OPENSSL_free(tbuf);
return ret;
}
@@ -513,24 +512,29 @@ static int test_sm2_kap(const EC_GROUP *group,
pubkeyA = new_ec_key(group, NULL, xA, yA, A, id_md);
pubkeyB = new_ec_key(group, NULL, xB, yB, B, id_md);
if (!eckeyA || !eckeyB || !pubkeyA || !pubkeyB) {
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
goto end;
}
if (!SM2_KAP_CTX_init(&ctxA, eckeyA, A, strlen(A), pubkeyB, B, strlen(B), 1, 1)) {
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
goto end;
}
if (!SM2_KAP_CTX_init(&ctxB, eckeyB, B, strlen(B), pubkeyA, A, strlen(A), 0, 1)) {
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
goto end;
}
change_rand(rA);
if (!SM2_KAP_prepare(&ctxA, RA, &RAlen)) {
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
goto end;
}
restore_rand();
change_rand(rB);
if (!SM2_KAP_prepare(&ctxB, RB, &RBlen)) {
fprintf(stderr, "error: %s %d\n", __FILE__, __LINE__);
goto end;
}
restore_rand();
@@ -555,6 +559,7 @@ static int test_sm2_kap(const EC_GROUP *group,
ret = 1;
end:
ERR_print_errors_fp(stderr);
EC_KEY_free(eckeyA);
EC_KEY_free(eckeyB);
EC_KEY_free(pubkeyA);
@@ -742,11 +747,4 @@ end:
EC_GROUP_free(sm2b257test);
EXIT(err);
}
#else
int main()
{
return 0;
}
#endif
#endif

View File

@@ -1,3 +1,53 @@
/* ====================================================================
* Copyright (c) 2014 - 2017 The GmSSL Project. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. All advertising materials mentioning features or use of this
* software must display the following acknowledgment:
* "This product includes software developed by the GmSSL Project.
* (http://gmssl.org/)"
*
* 4. The name "GmSSL Project" must not be used to endorse or promote
* products derived from this software without prior written
* permission. For written permission, please contact
* guanzhi1980@gmail.com.
*
* 5. Products derived from this software may not be called "GmSSL"
* nor may "GmSSL" appear in their names without prior written
* permission of the GmSSL Project.
*
* 6. Redistributions of any form whatsoever must retain the following
* acknowledgment:
* "This product includes software developed by the GmSSL Project
* (http://gmssl.org/)"
*
* THIS SOFTWARE IS PROVIDED BY THE GmSSL PROJECT ``AS IS'' AND ANY
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE GmSSL PROJECT OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* ====================================================================
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>