Remove some ciphers

This commit is contained in:
Zhi Guan
2019-06-13 20:35:11 +08:00
parent c0984b6436
commit 74d7992dda
78 changed files with 5565 additions and 8797 deletions

View File

@@ -1,134 +0,0 @@
/* ====================================================================
* Copyright (c) 2014 - 2016 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_BB1IBE
int main(int argc, char **argv)
{
printf("NO BB1IBE support\n");
return 0;
}
#else
# include <openssl/evp.h>
# include <openssl/bb1ibe.h>
int main(int argc, char **argv)
{
int err = 1;
int curve_id = NID_sm2p256v1;//FIXME
const EVP_MD *md = EVP_sm3();
char *id = "guanzhi1980@gmail.com";
char *in = "message to be signed or encrypted";
EC_GROUP *group = NULL;
BB1PublicParameters *mpk = NULL;
BB1MasterSecret *msk = NULL;
BB1PrivateKeyBlock *sk = NULL;
unsigned char *c = NULL;
unsigned char *m = NULL;
size_t clen, mlen;
/* setup */
if (!(group = EC_GROUP_new_by_curve_name(curve_id))) {
goto end;
}
if (!BB1IBE_setup(group, md, &mpk, &msk)) {
goto end;
}
/* keygen */
if (!(sk = BB1IBE_extract_private_key(mpk, msk, id, strlen(id)))) {
goto end;
}
/* encrypt */
clen = 0;
if (!BB1IBE_encrypt(mpk, (unsigned char *)in, strlen(in),
NULL, &clen, id, strlen(id))) {
goto end;
}
if (!(c = OPENSSL_zalloc(clen))) {
goto end;
}
if (!BB1IBE_encrypt(mpk, (unsigned char *)in, strlen(in),
c, &clen, id, strlen(id))) {
goto end;
}
/* decrypt */
mlen = 0;
if (!BB1IBE_decrypt(mpk, c, clen, NULL, &mlen, sk)) {
goto end;
}
if (!(m = OPENSSL_zalloc(mlen))) {
goto end;
}
if (!BB1IBE_decrypt(mpk, c, clen, m, &mlen, sk)) {
goto end;
}
if (strlen(in) != mlen || memcmp(in, m, mlen) != 0) {
goto end;
}
err = 0;
end:
EC_GROUP_free(group);
BB1PublicParameters_free(mpk);
BB1MasterSecret_free(msk);
BB1PrivateKeyBlock_free(sk);
OPENSSL_free(c);
OPENSSL_free(m);
//FIXME:
//return err;
return 0;
}
#endif

View File

@@ -1,133 +0,0 @@
/* ====================================================================
* Copyright (c) 2014 - 2016 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_BFIBE
int main(int argc, char **argv)
{
printf("NO BFIBE support\n");
return 0;
}
#else
# include <openssl/evp.h>
# include <openssl/bfibe.h>
int main(int argc, char **argv)
{
int err = 1;
int curve_id = NID_sm2p256v1;
const EVP_MD *md = EVP_sm3();
char *id = "guanzhi1980@gmail.com";
char *in = "message to be signed or encrypted";
EC_GROUP *group = NULL;
BFPublicParameters *mpk = NULL;
BFMasterSecret *msk = NULL;
BFPrivateKeyBlock *sk = NULL;
unsigned char *c = NULL;
unsigned char *m = NULL;
size_t clen, mlen;
/* setup */
if (!(group = EC_GROUP_new_by_curve_name(curve_id))) {
goto end;
}
if (!BFIBE_setup(group, md, &mpk, &msk)) {
goto end;
}
/* keygen */
if (!(sk = BFIBE_extract_private_key(mpk, msk, id, strlen(id)))) {
goto end;
}
/* encrypt */
clen = 0;
if (!BFIBE_encrypt(mpk, (unsigned char *)in, strlen(in),
NULL, &clen, id, strlen(id))) {
goto end;
}
if (!(c = OPENSSL_zalloc(clen))) {
goto end;
}
if (!BFIBE_encrypt(mpk, (unsigned char *)in, strlen(in),
c, &clen, id, strlen(id))) {
goto end;
}
/* decrypt */
mlen = 0;
if (!BFIBE_decrypt(mpk, c, clen, NULL, &mlen, sk)) {
goto end;
}
if (!(m = OPENSSL_zalloc(mlen))) {
goto end;
}
if (!BFIBE_decrypt(mpk, c, clen, m, &mlen, sk)) {
goto end;
}
if (strlen(in) != mlen || memcmp(in, m, mlen) != 0) {
goto end;
}
err = 0;
end:
EC_GROUP_free(group);
BFPublicParameters_free(mpk);
BFMasterSecret_free(msk);
BFPrivateKeyBlock_free(sk);
OPENSSL_free(c);
OPENSSL_free(m);
//FIXME: return err;
return 0;
}
#endif

View File

@@ -17,11 +17,10 @@ IF[{- !$disabled{tests} -}]
dtlsv1listentest ct_test threadstest afalgtest d2i_test \
ssl_test_ctx_test ssl_test x509aux cipherlist_test asynciotest \
bioprinttest sslapitest dtlstest sslcorrupttest bio_enc_test \
sm3test sms4test kdf2test eciestest ffxtest sm2test \
pailliertest otptest gmapitest ec2test \
bfibetest bb1ibetest sm9test \
sm2test sm3test sms4test kdf2test eciestest \
pailliertest otptest gmapitest sm9test \
sdftest skftest zuctest \
serpenttest specktest base58test
base58test
SOURCE[aborttest]=aborttest.c
INCLUDE[aborttest]=../include
@@ -304,10 +303,6 @@ IF[{- !$disabled{tests} -}]
INCLUDE[eciestest]=../include
DEPEND[eciestest]=../libcrypto
SOURCE[ffxtest]=ffxtest.c
INCLUDE[ffxtest]=../include
DEPEND[ffxtest]=../libcrypto
SOURCE[sm2test]=sm2test.c
INCLUDE[sm2test]=../include
DEPEND[sm2test]=../libcrypto
@@ -324,18 +319,6 @@ IF[{- !$disabled{tests} -}]
INCLUDE[gmapitest]=../include
DEPEND[gmapitest]=../libcrypto
SOURCE[ec2test]=ec2test.c
INCLUDE[ec2test]=../include
DEPEND[ec2test]=../libcrypto
SOURCE[bfibetest]=bfibetest.c
INCLUDE[bfibetest]=../include
DEPEND[bfibetest]=../libcrypto
SOURCE[bb1ibetest]=bb1ibetest.c
INCLUDE[bb1ibetest]=../include
DEPEND[bb1ibetest]=../libcrypto
SOURCE[sm9test]=sm9test.c
INCLUDE[sm9test]=../include
DEPEND[sm9test]=../libcrypto
@@ -352,14 +335,6 @@ IF[{- !$disabled{tests} -}]
INCLUDE[zuctest]=../include
DEPEND[zuctest]=../libcrypto
SOURCE[serpenttest]=serpenttest.c
INCLUDE[serpenttest]=../include
DEPEND[serpenttest]=../libcrypto
SOURCE[specktest]=specktest.c
INCLUDE[specktest]=../include
DEPEND[specktest]=../libcrypto
SOURCE[base58test]=base58test.c
INCLUDE[base58test]=../include
DEPEND[base58test]=../libcrypto

View File

@@ -1,69 +0,0 @@
/* ====================================================================
* Copyright (c) 2014 - 2016 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_EC2
int main(int argc, char **argv)
{
printf("NO EC2 (EC Extensions) support\n");
return 0;
}
#else
# include <openssl/evp.h>
int main(int argc, char **argv)
{
int err = 0;
return err;
}
#endif

View File

@@ -1,163 +0,0 @@
/* ====================================================================
* Copyright (c) 2014 - 2016 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_FFX
int main(int argc, char **argv)
{
printf("No FFX support\n");
return 0;
}
#else
# include <openssl/err.h>
# include <openssl/evp.h>
# include <openssl/ffx.h>
static int test_ffx(int verbose)
{
int ret = 0;
FFX_CTX *ctx = NULL;
char *in = "99999999999999999";
const EVP_CIPHER *cipher[] = {
EVP_sms4_ecb(),
EVP_aes_128_ecb(),
EVP_aes_256_ecb(),
};
unsigned char key[32] = {0};
unsigned char tweak[8] = {
0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38
};
char buf1[100];
char buf2[100];
int i;
if (!(ctx = FFX_CTX_new())) {
ERR_print_errors_fp(stderr);
return 0;
}
for (i = 0; i < OSSL_NELEM(cipher); i++) {
memset(buf1, 0, sizeof(buf1));
memset(buf2, 0, sizeof(buf2));
if (!FFX_init(ctx, cipher[i], key, 0)) {
ERR_print_errors_fp(stderr);
goto end;
}
if (!FFX_encrypt(ctx, in, buf1, strlen(in), tweak, sizeof(tweak))) {
ERR_print_errors_fp(stderr);
goto end;
}
if (!FFX_decrypt(ctx, buf1, buf2, strlen(in), tweak, sizeof(tweak))) {
ERR_print_errors_fp(stderr);
goto end;
}
if (strcmp(in, buf2) != 0) {
printf("error ffx-%s\n", EVP_CIPHER_name(cipher[i]));
printf("encrypt/decrypt not match\n");
} else {
printf("test %d ok\n", i + 1);
}
if (verbose) {
printf("ffx-%s-encrypt(\"%s\") = \"%s\"\n",
EVP_CIPHER_name(cipher[i]), in, buf1);
}
}
ret = 1;
end:
FFX_CTX_free(ctx);
return ret;
}
char *digits[] = {
"7992739871",
};
int luhn_checksums[] = {
'3',
};
int test_luhn(int verbose)
{
int i;
int checksum;
for (i = 0; i < OSSL_NELEM(digits); i++) {
checksum = FFX_compute_luhn(digits[i], strlen(digits[i]));
if (checksum != luhn_checksums[i]) {
printf("error calculating Luhn checksum on %s\n", digits[i]);
printf("got %c instead of %c\n", checksum, luhn_checksums[i]);
} else {
printf("test %d ok\n", i+1);
}
}
return 1;
}
int main(int argc, char **argv)
{
int err = 0;
if (!test_ffx(1)) {
err = 1;
}
if (!test_luhn(1)) {
err = 1;
}
return err;
}
#endif

View File

@@ -1,12 +0,0 @@
#! /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_serpent", "serpenttest", "serpent");

View File

@@ -1,12 +0,0 @@
#! /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_speck", "specktest", "speck");

View File

@@ -1,12 +0,0 @@
#! /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_bb1ibe", "bb1ibetest", "bb1ibe");

View File

@@ -1,12 +0,0 @@
#! /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_bfibe", "bfibetest", "bfibe");

View File

@@ -1,12 +0,0 @@
#! /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_ec2", "ec2test", "ec2");

View File

@@ -1,12 +0,0 @@
#! /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_ffx", "ffxtest", "ffx");

View File

@@ -1,203 +0,0 @@
/* ====================================================================
* Copyright (c) 2014 - 2016 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_SAF
int main(int argc, char **argv)
{
printf("NO SAF support\n");
return 0;
}
#else
# include <openssl/err.h>
# include <openssl/evp.h>
# include <openssl/rand.h>
# include <openssl/gmsaf.h>
int test_saf_base64(int verbose)
{
int ret = SAR_UnknownErr;
/* sizeof(buf1)%3 == 1 makes base64 ended with "==" */
unsigned char buf1[121];
unsigned char buf2[512];
unsigned char buf3[512];
unsigned int len1, len2, len3;
/* generate some random binary for testing */
RAND_bytes(buf1, sizeof(buf1));
memset(buf2, 0, sizeof(buf2));
memset(buf3, 0, sizeof(buf3));
len1 = (unsigned int)sizeof(buf1);
len2 = (unsigned int)sizeof(buf2);
if ((ret = SAF_Base64_Encode(buf1, len1, buf2, &len2)) != SAR_Ok) {
ERR_print_errors_fp(stderr);
goto end;
}
if (verbose) {
printf("%s\n", buf2);
}
len3 = sizeof(buf3);
if ((ret = SAF_Base64_Decode(buf2, len2, buf3, &len3)) != SAR_Ok) {
ERR_print_errors_fp(stderr);
goto end;
}
/* check correctness */
if (len1 == len3 && memcmp(buf1, buf3, len1) == 0) {
ret = SAR_Ok;
} else {
/* make sure to assign `ret`, or it might be set as OK by
* previous functions */
ret = SAR_UnknownErr;
}
end:
if (verbose) {
printf("%s %s\n", __FUNCTION__,
ret == SAR_Ok ? "passed" : "failed");
}
return ret;
}
static int test_saf_cert(int verbose)
{
return 0;
}
static int test_saf_ec(int verbose)
{
return 0;
}
static int test_saf_hash(int verbose)
{
unsigned char msg[3] = "abc";
unsigned char pubkey[] = "FIXME";
unsigned char id[] = "FIXME";
unsigned char dgst[EVP_MAX_MD_SIZE];
unsigned int dgstlen;
dgstlen = (unsigned int)sizeof(dgst);
if (SAF_Hash(SGD_SM3, msg, sizeof(msg), NULL, 0, NULL, 0,
dgst, &dgstlen) != SAR_Ok) {
if (verbose) {
fprintf(stderr, "%s() error on test 1\n", __FUNCTION__);
}
return 0;
}
dgstlen = (unsigned int)sizeof(dgst);
if (SAF_Hash(SGD_SM3, msg, sizeof(msg), pubkey, sizeof(pubkey),
id, sizeof(id), dgst, &dgstlen) != SAR_Ok) {
if (verbose) {
fprintf(stderr, "%s() error on test 2\n", __FUNCTION__);
}
return 0;
}
return 1;
}
static int test_saf_enc(int verbose)
{
return 0;
}
static int test_saf_mac(int verbose)
{
return 0;
}
static int test_saf_pkcs7(int verbose)
{
return 0;
}
static int test_saf_rand(int verbose)
{
return 0;
}
static int test_saf_rsa(int verbose)
{
return 0;
}
static int test_saf_sm2(int verbose)
{
return 0;
}
int main(int argc, char **argv)
{
int err = 0;
int verbose = 2;
if (SAR_Ok != test_saf_base64(verbose)) err++;
if (!test_saf_cert(verbose)) err++;
if (!test_saf_ec(verbose)) err++;
if (!test_saf_enc(verbose)) err++;
if (!test_saf_hash(verbose)) err++;
if (!test_saf_mac(verbose)) err++;
if (!test_saf_pkcs7(verbose)) err++;
if (!test_saf_rand(verbose)) err++;
if (!test_saf_rsa(verbose)) err++;
if (!test_saf_sm2(verbose)) err++;
//FIXME: return err;
return 0;
}
#endif

View File

@@ -1,174 +0,0 @@
/* ====================================================================
* 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
*========================
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <openssl/e_os2.h>
#include "../e_os.h"
#ifdef OPENSSL_NO_SERPENT
int main(int argc, char **argv)
{
printf("No Serpent support\n");
return 0;
}
#else
#include <ctype.h>
#include <openssl/serpent.h>
char *plain[] =
{ "3DA46FFA6F4D6F30CD258333E5A61369" };
char *keys[] =
{ "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F"
};
char *cipher[] =
{ "00112233445566778899AABBCCDDEEFF" };
size_t hex2bin(void *bin, char hex[]) {
size_t len, i;
int x;
uint8_t *p = (uint8_t*)bin;
len = strlen(hex);
if ((len & 1) != 0) {
return 0;
}
for (i = 0; i<len; i++) {
if (isxdigit((int)hex[i]) == 0) {
return 0;
}
}
for (i = 0; i<len / 2; i++) {
sscanf(&hex[i * 2], "%2x", &x);
p[i] = (uint8_t)x;
}
return len / 2;
}
void dump_hex(char *s, uint8_t bin[], int len)
{
int i;
printf("\n%s=", s);
for (i = 0; i<len; i++) {
printf("%02x", bin[i]);
}
}
int main(void)
{
uint8_t ct1[32], pt1[32], pt2[32], key[64];
int klen, plen, clen, i, j;
serpent_key_t skey;
serpent_blk ct2;
uint32_t *p;
printf("\nserpent-256 test\n");
for (i = 0; i<sizeof(keys) / sizeof(char*); i++) {
clen = hex2bin(ct1, cipher[i]);
plen = hex2bin(pt1, plain[i]);
klen = hex2bin(key, keys[i]);
/* set key */
memset(&skey, 0, sizeof(skey));
p = (uint32_t*)&skey.x[0][0];
serpent_set_encrypt_key(&skey, key);
printf("\nkey=");
for (j = 0; j<sizeof(skey) / sizeof(serpent_subkey_t) * 4; j++) {
if ((j % 8) == 0)
putchar('\n');
printf("%08X ", p[j]);
}
/* encrypt */
memcpy(ct2.b, pt1, SERPENT_BLOCK_SIZE);
printf("\n\n");
dump_hex("plaintext", ct2.b, 16);
serpent_encrypt(pt1,ct2.b, &skey);
dump_hex("ciphertext", ct2.b, 16);
if (memcmp(ct1, ct2.b, clen) == 0) {
printf("\nEncryption OK");
serpent_decrypt(ct2.b,pt1, &skey);
if (memcmp(pt1, ct2.b, plen) == 0) {
printf("\nDecryption OK");
dump_hex("plaintext", ct2.b, 16);
}
else {
printf("\nDecryption failed");
}
}
else {
printf("\nEncryption failed");
}
}
return 0;
}
#endif

View File

@@ -1,69 +0,0 @@
/* ====================================================================
* Copyright (c) 2014 - 2016 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_SOF
int main(int argc, char **argv)
{
printf("NO SOF support\n");
return 0;
}
#else
# include <openssl/evp.h>
int main(int argc, char **argv)
{
int err = 0;
return err;
}
#endif

View File

@@ -1,130 +0,0 @@
/* ====================================================================
* 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_SPECK
int main(int argc, char **argv)
{
printf("No SPECK support\n");
return 0;
}
#else
# include <openssl/e_os2.h>
# include <openssl/speck.h>
# include <openssl/evp.h>
int main(int argc, char** argv)
{
int sum = 0;
uint16_t key16[4] = { 0x0100, 0x0908, 0x1110, 0x1918 };
uint16_t plain16[2] = { 0x694c, 0x6574 };
uint16_t enc16[2] = { 0x42f2, 0xa868 };
uint32_t key32[4] = { 0x03020100, 0x0b0a0908, 0x13121110, 0x1b1a1918 };
uint32_t plain32[2] = { 0x7475432d, 0x3b726574 };
uint32_t enc32[2] = { 0x454e028b, 0x8c6fa548 };
uint64_t key64[4] = { 0x0706050403020100, 0x0f0e0d0c0b0a0908, 0x1716151413121110, 0x1f1e1d1c1b1a1918 };
uint64_t plain64[2] = { 0x202e72656e6f6f70, 0x65736f6874206e49 };
uint64_t enc64[2] = { 0x4eeeb48d9c188f43, 0x4109010405c0f53e };
uint16_t buffer[2] = { 0 };
uint16_t exp[SPECK_ROUNDS16];
uint32_t exp32[SPECK_ROUNDS32];
uint32_t buffer32[2] = { 0 };
uint64_t exp64[SPECK_ROUNDS64];
uint64_t buffer64[2] = { 0 };
speck_set_encrypt_key16(key16, exp);
speck_encrypt16(plain16, buffer, exp);
if (memcmp(buffer, enc16, sizeof(enc16))) {
fprintf(stderr, "%s %d: speck error\n", __FILE__, __LINE__);
sum++;
}
speck_decrypt16(enc16, buffer, exp);
if (memcmp(buffer, plain16, sizeof(enc16))) {
fprintf(stderr, "%s %d: speck error\n", __FILE__, __LINE__);
sum++;
}
speck_set_encrypt_key32(key32, exp32);
speck_encrypt32(plain32, buffer32, exp32);
if (memcmp(buffer, enc32, sizeof(enc32))) {
fprintf(stderr, "%s %d: speck error\n", __FILE__, __LINE__);
sum++;
}
speck_decrypt32(enc32, buffer32, exp32);
if (memcmp(buffer32, plain32, sizeof(enc32))) {
fprintf(stderr, "%s %d: speck error\n", __FILE__, __LINE__);
sum++;
}
speck_set_encrypt_key64(key64, exp64);
speck_encrypt64(plain64, buffer64, exp64);
if (memcmp(buffer64, enc64, sizeof(enc64))) {
fprintf(stderr, "%s %d: speck error\n", __FILE__, __LINE__);
sum++;
}
speck_decrypt64(enc64, buffer64, exp64);
if (memcmp(buffer64, plain64, sizeof(enc64))) {
fprintf(stderr, "%s %d: speck error\n", __FILE__, __LINE__);
sum++;
}
return sum;
}
#endif