This commit is contained in:
Zhi Guan
2016-06-06 22:04:44 +02:00
parent 2bf25bd29f
commit 2cb43b7f80
142 changed files with 7768 additions and 1678 deletions

View File

@@ -1,36 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <openssl/evp.h>
#include <openssl/asn1.h>
int main(int argc, char **argv)
{
int i;
/*
int EVP_PKEY_asn1_get_count(void);
const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_get0(int idx);
const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_find(ENGINE **pe, int type);
const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_find_str(ENGINE **pe,
const char *str, int len);
*/
int count = EVP_PKEY_asn1_get_count();
printf("EVP_PKEY_asn1_get_count() = %d\n", count);
for (i = 0; i < count; i++) {
const EVP_PKEY_ASN1_METHOD *ameth;
ameth = EVP_PKEY_asn1_get0(i);
int j;
const unsigned char *p = (const unsigned char *)ameth;
for (j = 0; j < 64; j++) {
printf("%02x", p[j]);
}
printf("\n");
}
}

14
demos/gmssl/Makefile Normal file
View File

@@ -0,0 +1,14 @@
all:
cc -o ciphers -Wall ciphers.c -L/usr/local/lib -lcrypto
cc -o sm3 -Wall sm3.c -L/usr/local/lib -lcrypto
cc -o evpsm3 -Wall evpsm3.c -L/usr/local/lib -lcrypto
cc -o hmacsm3 -Wall hmacsm3.c -L/usr/local/lib -lcrypto
clean:
rm -fr a.out *.o
rm -fr ciphers
rm -fr sm3
rm -fr evpsm3
rm -fr hmacsm3

BIN
demos/gmssl/a.out Executable file

Binary file not shown.

View File

@@ -1,13 +0,0 @@
-----BEGIN CERTIFICATE-----
MIIB9jCCAZ2gAwIBAgIJAI6saFfpzqpLMAoGCCqGSM49BAMCMFgxCzAJBgNVBAYT
AkNOMQwwCgYDVQQIDANQS1UxDDAKBgNVBAcMA1BLVTEMMAoGA1UECgwDUEtVMQ0w
CwYDVQQLDARERFNTMRAwDgYDVQQDDAdERFNTLUFTMB4XDTE2MDUxODExNTgyMVoX
DTI2MDUxNjExNTgyMVowWDELMAkGA1UEBhMCQ04xDDAKBgNVBAgMA1BLVTEMMAoG
A1UEBwwDUEtVMQwwCgYDVQQKDANQS1UxDTALBgNVBAsMBEREU1MxEDAOBgNVBAMM
B0REU1MtQVMwWTATBgcqhkjOPQIBBggqgRzPVQGCLQNCAATFBdPQp/tqJHjfL+eZ
Jv1tUCMFpWCzoskQgDImhLP8+snkNSmZhRtHeerUr8oP6FtWAPnhUzwMOVb4JcNC
CYSbo1AwTjAdBgNVHQ4EFgQUCz8gNn0NMxyIW/gRF13zl6ExeLUwHwYDVR0jBBgw
FoAUCz8gNn0NMxyIW/gRF13zl6ExeLUwDAYDVR0TBAUwAwEB/zAKBggqhkjOPQQD
AgNHADBEAiARFx9dY1LE+ELs/SWIkMLxbikA3P4YE0JZZkAmXZVo/gIgEs8G6fJw
8AEbDwMcMiLLyJ7RhcUhEX+oj3Ibm8JgQXo=
-----END CERTIFICATE-----

89
demos/gmssl/ciphers.c Normal file
View File

@@ -0,0 +1,89 @@
/* demo/gmssl/ciphers.c */
/* ====================================================================
* Copyright (c) 2014 - 2015 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 <openssl/evp.h>
int main(int argc, char **argv)
{
int i;
char *names[] = {
"sms4-ecb",
"sms4-cbc",
"sms4-cfb",
"sms4-ofb",
"sms4-ctr",
"zuc",
};
const EVP_CIPHER *cipher;
OpenSSL_add_all_ciphers();
printf("%s New Ciphers:\n\n", OPENSSL_VERSION_TEXT);
for (i = 0; i < sizeof(names)/sizeof(names[i]); i++) {
if (!(cipher = EVP_get_cipherbyname(names[i]))) {
fprintf(stderr, "cipher \"%s\" is not supported\n", names[i]);
continue;
}
printf(" cipher nid : %d\n", EVP_CIPHER_nid(cipher));
printf(" cipher name : %s\n", EVP_CIPHER_name(cipher));
printf(" block size : %d\n", EVP_CIPHER_block_size(cipher));
printf(" key length : %d\n", EVP_CIPHER_key_length(cipher));
printf(" iv length : %d\n", EVP_CIPHER_iv_length(cipher));
printf(" flags : 0x%016lx\n", EVP_CIPHER_flags(cipher));
printf("\n");
}
return 0;
}

109
demos/gmssl/evpsm3.c Normal file
View File

@@ -0,0 +1,109 @@
/* demo/gmssl/sm3evp.c */
/* ====================================================================
* Copyright (c) 2014 - 2015 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 <stdlib.h>
#include <openssl/evp.h>
#include <openssl/err.h>
int main(int argc, char **argv)
{
int ret = -1;
FILE *fp = stdin;
unsigned char buf[1024];
size_t len;
const EVP_MD *md;
EVP_MD_CTX mdctx;
unsigned char dgst[EVP_MAX_MD_SIZE];
unsigned int dgstlen, i;
if (argc == 2) {
if (!(fp = fopen(argv[1], "r"))) {
fprintf(stderr, "open file %s failed\n", argv[1]);
return -1;
}
}
OpenSSL_add_all_digests();
if (!(md = EVP_get_digestbyname("sm3"))) {
ERR_print_errors_fp(stderr);
goto end;
}
if (!EVP_DigestInit(&mdctx, md)) {
ERR_print_errors_fp(stderr);
goto end;
}
while ((len = fread(buf, 1, sizeof(buf), fp))) {
if (!EVP_DigestUpdate(&mdctx, buf, len)) {
ERR_print_errors_fp(stderr);
goto end;
}
}
if (!EVP_DigestFinal(&mdctx, dgst, &dgstlen)) {
ERR_print_errors_fp(stderr);
goto end;
}
for (i = 0; i < dgstlen; i++) {
printf("%02x", dgst[i]);
}
printf("\n");
ret = 0;
end:
fclose(fp);
EVP_cleanup();
return ret;
}

View File

@@ -18,10 +18,15 @@ $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
$gmssl req -new -x509 -days 3650 -key sm2key.pem -out cert.pem -pkeyopt ec_sign_algor:sm2
$gmssl req -new -x509 -days 3650 -key sm2key.pem -out cert.pem
#$gmssl x509 -text -noout -in $DIR/cacert.pem

View File

@@ -84,7 +84,7 @@ int main(int argc, char **argv)
ERR_print_errors_fp(stderr);
goto end;
}
HMAC_Init_ex(&hmctx, key, sizeof(key), md, NULL);
while ((len = fread(buf, 1, sizeof(buf), fp))) {

View File

@@ -1,38 +0,0 @@
#include <stdio.h>
#include <string.h>
#include <openssl/evp.h>
#include <openssl/opensslv.h>
int main(int argc, char **argv)
{
int i;
char *names[] = {
"sms4-ecb",
"sms4-cbc",
"sms4-cfb",
"sms4-ofb",
"sms4-ctr",
};
const EVP_CIPHER *cipher;
OpenSSL_add_all_ciphers();
printf("%s new ciphers:\n\n", OPENSSL_VERSION_TEXT);
for (i = 0; i < sizeof(names)/sizeof(names[i]); i++) {
if (!(cipher = EVP_get_cipherbyname(names[i]))) {
fprintf(stderr, "cipher \"%s\" is not supported\n", names[i]);
continue;
}
printf(" cipher nid : %d\n", EVP_CIPHER_nid(cipher));
printf(" cipher name : %s\n", EVP_CIPHER_name(cipher));
printf(" block size : %d\n", EVP_CIPHER_block_size(cipher));
printf(" key length : %d\n", EVP_CIPHER_key_length(cipher));
printf(" iv length : %d\n", EVP_CIPHER_iv_length(cipher));
printf(" flags : 0x%016lx\n", EVP_CIPHER_flags(cipher));
printf("\n");
}
return 0;
}

20
demos/gmssl/memleak.c Normal file
View File

@@ -0,0 +1,20 @@
#include <stdio.h>
#include <stdlib.h>
#include <openssl/pem.h>
#include <openssl/conf.h>
int main()
{
BIO *bio_err;
void *ptr;
CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
bio_err = BIO_new_fp(stderr, BIO_NOCLOSE);
ptr = OPENSSL_malloc(1024);
CRYPTO_mem_leaks(bio_err);
BIO_free(bio_err);
return (0);
}

View File

@@ -4,104 +4,55 @@
#include <openssl/conf.h>
#include <openssl/x509v3.h>
int mkit(X509 **x509p, EVP_PKEY **pkeyp, int bits, int serial, int days)
{
X509 *x;
EVP_PKEY *pk;
EC_KEY *ec_key;
X509_NAME *name = NULL;
X509_NAME_ENTRY *ne = NULL;
X509_EXTENSION *ex = NULL;
if ((pkeyp == NULL) || (*pkeyp == NULL)) {
if ((pk = EVP_PKEY_new()) == NULL) {
abort();
return (0);
}
} else
pk = *pkeyp;
if ((x509p == NULL) || (*x509p == NULL)) {
if ((x = X509_new()) == NULL)
goto err;
} else {
x = *x509p;
}
ec_key = EC_KEY_new_by_curve_name(NID_sm2p256v1);
EC_KEY_generate_key(ec_key);
if (!EVP_PKEY_assign_EC_KEY(pk, ec_key)) {
abort();
goto err;
}
ec_key = NULL;
X509_set_version(x, 3);
ASN1_INTEGER_set(X509_get_serialNumber(x), serial);
X509_gmtime_adj(X509_get_notBefore(x), 0);
X509_gmtime_adj(X509_get_notAfter(x), (long)60 * 60 * 24 * days);
X509_set_pubkey(x, pk);
name = X509_get_subject_name(x);
/*
* This function creates and adds the entry, working out the correct
* string type and performing checks on its length. Normally we'd check
* the return value for errors...
*/
X509_NAME_add_entry_by_txt(name, "C", MBSTRING_ASC, "UK", -1, -1, 0);
X509_NAME_add_entry_by_txt(name, "CN",
MBSTRING_ASC, "OpenSSL Group", -1, -1, 0);
X509_set_issuer_name(x, name);
/*
* Add extension using V3 code: we can set the config file as NULL
* because we wont reference any other sections. We can also set the
* context to NULL because none of these extensions below will need to
* access it.
*/
ex = X509V3_EXT_conf_nid(NULL, NULL, NID_netscape_cert_type, "server");
X509_add_ext(x, ex, -1);
X509_EXTENSION_free(ex);
ex = X509V3_EXT_conf_nid(NULL, NULL, NID_netscape_comment,
"example comment extension");
X509_add_ext(x, ex, -1);
X509_EXTENSION_free(ex);
ex = X509V3_EXT_conf_nid(NULL, NULL, NID_netscape_ssl_server_name,
"www.openssl.org");
X509_add_ext(x, ex, -1);
X509_EXTENSION_free(ex);
if (!X509_sign(x, pk, EVP_sm3()))
goto err;
*x509p = x;
*pkeyp = pk;
return (1);
err:
return (0);
}
int main()
{
BIO *bio_err;
X509 *x509 = NULL;
EC_KEY *ec_key = NULL;
EVP_PKEY *pkey = NULL;
X509 *x509 = NULL;
int serial = 123;
int days = 365;
X509_NAME *name = NULL;
X509_NAME_ENTRY *ne = NULL;
X509_EXTENSION *ex = NULL;
CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
bio_err = BIO_new_fp(stderr, BIO_NOCLOSE);
ec_key = EC_KEY_new_by_curve_name(NID_sm2p256v1);
EC_KEY_generate_key(ec_key);
pkey = EVP_PKEY_new();
EVP_PKEY_set1_EC_KEY(pkey, ec_key);
ec_key = NULL;
mkit(&x509, &pkey, 512, 0, 365);
x509 = X509_new();
X509_set_version(x509, 3);
ASN1_INTEGER_set(X509_get_serialNumber(x509), serial);
X509_gmtime_adj(X509_get_notBefore(x509), 0);
X509_gmtime_adj(X509_get_notAfter(x509), (long)60 * 60 * 24 * days);
X509_set_pubkey(x509, pkey);
name = X509_get_subject_name(x509);
X509_NAME_add_entry_by_txt(name, "C", MBSTRING_ASC, "UK", -1, -1, 0);
X509_NAME_add_entry_by_txt(name, "CN", MBSTRING_ASC, "OpenSSL Group", -1, -1, 0);
X509_set_issuer_name(x509, name);
ex = X509V3_EXT_conf_nid(NULL, NULL, NID_netscape_cert_type, "server");
X509_add_ext(x509, ex, -1);
X509_EXTENSION_free(ex);
ex = X509V3_EXT_conf_nid(NULL, NULL, NID_netscape_comment, "example comment extension");
X509_add_ext(x509, ex, -1);
X509_EXTENSION_free(ex);
ex = X509V3_EXT_conf_nid(NULL, NULL, NID_netscape_ssl_server_name, "www.openssl.org");
X509_add_ext(x509, ex, -1);
X509_EXTENSION_free(ex);
X509_sign(x509, pkey, EVP_sm3());
EC_KEY_print_fp(stdout, pkey->pkey.ec, 0);
X509_print_fp(stdout, x509);
@@ -114,5 +65,6 @@ int main()
CRYPTO_mem_leaks(bio_err);
BIO_free(bio_err);
return (0);
}

View File

@@ -0,0 +1,2 @@
ÙÁ'‘Þ R.—ÜäN¹áZzÆ+âûÐÓÜ
N&‰Jš€Ê<E282AC>¾×b l0Þwya>Ã7]"ˆ~½æß»·ÍC„9»Šû 5ýO4ïWJqå/ûŠœ€æZ|Ãïihí[

View File

@@ -1,5 +1,5 @@
-----BEGIN PRIVATE KEY-----
MIGHAgEAMBMGByqGSM49AgEGCCqBHM9VAYItBG0wawIBAQQgyeMq+RmwB95Ohl+U
K1KmE5/3OzxoG1lOpbyMu8sZxrqhRANCAATGmXcprKn9kYmMBKBLaxckcTFqDzNF
qDwzk8rTcWr5/2CmI9KGeSMbp7G9X/v8qh/RIattztrYXlrVP0h7Zk+A
MIGHAgEAMBMGByqGSM49AgEGCCqBHM9VAYItBG0wawIBAQQgMfsFkjZrB5XuA5eX
Utr1XlgaqbL4aJHLSvtOteur2oehRANCAASygUdsxLAxiuHlr42o93jHr7lJnAbW
AsGM8lpqpz9803V6jGREo8Ajdh5lhqo0KPsfqwnVqjAE4CVLwCobJ6GZ
-----END PRIVATE KEY-----

Binary file not shown.

View File

@@ -1,32 +0,0 @@
#include <stdio.h>
#include <openssl/bio.h>
#include <openssl/pem.h>
#include <openssl/ec.h>
int main(int argc, char **argv)
{
BIO *in = BIO_new_fp(stdin, BIO_NOCLOSE);
EC_GROUP *group = NULL;
EC_KEY *ec_key = NULL;
ERR_load_crypto_strings();
group = PEM_read_bio_SM2PKParameters(in, NULL, NULL, NULL);
if (!group) {
ERR_print_errors_fp(stderr);
return 0;
}
if (!EC_GROUP_check(group, NULL)) {
ERR_print_errors_fp(stderr);
return 0;
}
return 0;
ec_key = EC_KEY_new();
EC_KEY_set_group(ec_key, group);
return 0;
}

View File

@@ -1,6 +1,6 @@
/* demo/gmssl/sm3.c */
/* ====================================================================
* Copyright (c) 2014 - 2015 The GmSSL Project. All rights reserved.
* 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
@@ -50,60 +50,48 @@
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <openssl/evp.h>
#include <openssl/err.h>
#include <unistd.h>
#include <libgen.h>
#include <openssl/sm3.h>
/*
* usage of sm3dgst:
* ./sm3dgst <file>
* 324234234234235234234234234234
*
* echo "hello world" | sm3dgst
* lksjdlfksdjlfkjsdlfkjsdlfkjsdljkfffffffldjfk=
*
*/
int main(int argc, char **argv)
{
int ret = -1;
FILE *fp = stdin;
unsigned char buf[1024];
size_t len;
const EVP_MD *md;
EVP_MD_CTX mdctx;
unsigned char dgst[EVP_MAX_MD_SIZE];
unsigned int dgstlen, i;
sm3_ctx_t ctx;
unsigned char dgst[SM3_DIGEST_LENGTH];
unsigned char buf[4096];
ssize_t len;
int i;
if (argc == 2) {
if (!(fp = fopen(argv[1], "r"))) {
fprintf(stderr, "open file %s failed\n", argv[1]);
return -1;
}
if (argc > 1) {
printf("usage: %s < file\n", basename(argv[0]));
return 0;
}
OpenSSL_add_all_digests();
if (!(md = EVP_get_digestbyname("sm3"))) {
ERR_print_errors_fp(stderr);
goto end;
}
sm3_init(&ctx);
if (!EVP_DigestInit(&mdctx, md)) {
ERR_print_errors_fp(stderr);
goto end;
while ((len = read(STDIN_FILENO, buf, sizeof(buf))) > 0) {
sm3_update(&ctx, buf, len);
}
memset(dgst, 0, sizeof(dgst));
sm3_final(&ctx, dgst);
while ((len = fread(buf, 1, sizeof(buf), fp))) {
if (!EVP_DigestUpdate(&mdctx, buf, len)) {
ERR_print_errors_fp(stderr);
goto end;
}
}
if (!EVP_DigestFinal(&mdctx, dgst, &dgstlen)) {
ERR_print_errors_fp(stderr);
goto end;
}
for (i = 0; i < dgstlen; i++) {
for (i = 0; i < sizeof(dgst); i++) {
printf("%02x", dgst[i]);
}
printf("\n");
ret = 0;
end:
fclose(fp);
EVP_cleanup();
return ret;
return 0;
}

78
demos/mycipher/Makefile Normal file
View File

@@ -0,0 +1,78 @@
#
# OpenSSL/crypto/mycipher/Makefile
#
DIR= mycipher
TOP= ../..
CC= cc
INCLUDES=
CFLAG=-g
MAKEFILE= Makefile
AR= ar r
CFLAGS= $(INCLUDES) $(CFLAG)
GENERAL=Makefile
TEST=
APPS=
LIB=$(TOP)/libcrypto.a
LIBSRC=mycipher.c
LIBOBJ=mycipher.o
SRC= $(LIBSRC)
EXHEADER= mycipher.h
HEADER= $(EXHEADER)
ALL= $(GENERAL) $(SRC) $(HEADER)
top:
(cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
all: lib
lib: $(LIBOBJ)
$(AR) $(LIB) $(LIBOBJ)
$(RANLIB) $(LIB) || echo Never mind.
@touch lib
files:
$(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
links:
@$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
@$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
@$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
install:
@[ -n "$(INSTALLTOP)" ] # should be set by top Makefile...
@headerlist="$(EXHEADER)"; for i in $$headerlist ; \
do \
(cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
done;
tags:
ctags $(SRC)
tests:
lint:
lint -DLINT $(INCLUDES) $(SRC)>fluff
update: depend
depend:
@[ -n "$(MAKEDEPEND)" ] # should be set by upper Makefile...
$(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
dclean:
$(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
mv -f Makefile.new $(MAKEFILE)
clean:
rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
# DO NOT DELETE THIS LINE -- make depend depends on it.

9
demos/mycipher/README.md Normal file
View File

@@ -0,0 +1,9 @@
## MyCipher Block Cipher
The official specification of MyCipher can be found at
http://example.com/mycipher.pdf
The OID (Object Identifier) of MyCipher is 1.2.345.6789,
which is defined in standard http://example.com/mycipher.pdf

72
demos/mycipher/mycipher.c Normal file
View File

@@ -0,0 +1,72 @@
/* crypto/mycipher/mycipher.c */
/* ====================================================================
* 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.
* ====================================================================
*
*/
/*
* author's information
*/
#include "mycipher.h"
void mycipher_set_encrypt_key(mycipher_key_t *key, const unsigned char *user_key)
{
}
void mycipher_set_decrypt_key(mycipher_key_t *key, const unsigned char *user_key)
{
}
void mycipher_encrypt(const unsigned char *in, unsigned char *out, const mycipher_key_t *key)
{
}
void mycipher_decrypt(const unsigned char *in, unsigned char *out, const mycipher_key_t *key)
{
}

85
demos/mycipher/mycipher.h Normal file
View File

@@ -0,0 +1,85 @@
/* crypto/mycipher/mycipher.h */
/* ====================================================================
* 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.
* ====================================================================
*
*/
/*
* author's information
*/
#ifndef HEADER_MYCIPHER_H
#define HEADER_MYCIPHER_H
#define MYCIPHER_KEY_LENGTH 16
#define MYCIPHER_BLOCK_SIZE 16
#define MYCIPHER_IV_LENGTH (MYCIPHER_BLOCK_SIZE)
#include <sys/types.h>
#include <stdint.h>
#include <string.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
unsigned char rk[100];
} mycipher_key_t;
void mycipher_set_encrypt_key(mycipher_key_t *key, const unsigned char *user_key);
void mycipher_set_decrypt_key(mycipher_key_t *key, const unsigned char *user_key);
void mycipher_encrypt(const unsigned char *in, unsigned char *out, const mycipher_key_t *key);
void mycipher_decrypt(const unsigned char *in, unsigned char *out, const mycipher_key_t *key);
#ifdef __cplusplus
}
#endif
#endif

BIN
demos/mycipher/mycipher.o Normal file

Binary file not shown.

View File

@@ -0,0 +1,77 @@
/* crypto/mycipher/mycipher.h */
/* ====================================================================
* 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.
* ====================================================================
*
*/
/*
* author's information
*/
#include "mycipher.h"
int main(int argc, char **argv)
{
mycipher_key_t key;
unsigned char userkey[MYCIPHER_KEY_LENGTH] = {0x01, 0x02, };
unsigned char msg[MYCIPHER_BLOCK_SIZE] = {0xab, 0xcd, };
unsigned char cbuf[MYCIPHER_BLOCK_SIZE];
unsigned char mbuf[MYCIPHER_BLOCK_SIZE];
mycipher_set_encrypt_key(&key, userkey);
mycipher_encrypt(msg, cbuf, &key);
mycipher_set_decrypt_key(&key, userkey);
mycipehr_decrypt(cbuf, mbuf, &key);
if (memcmp(cbuf, mbuf, MYCIPHER_BLOCK_SIZE)) {
return -1;
}
return 0;
}

78
demos/mystream/Makefile Normal file
View File

@@ -0,0 +1,78 @@
#
# OpenSSL/crypto/mystream/Makefile
#
DIR= mystream
TOP= ../..
CC= cc
INCLUDES=
CFLAG=-g
MAKEFILE= Makefile
AR= ar r
CFLAGS= $(INCLUDES) $(CFLAG)
GENERAL=Makefile
TEST=
APPS=
LIB=$(TOP)/libcrypto.a
LIBSRC=mystream.c
LIBOBJ=mystream.o
SRC= $(LIBSRC)
EXHEADER= mystream.h
HEADER= $(EXHEADER)
ALL= $(GENERAL) $(SRC) $(HEADER)
top:
(cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
all: lib
lib: $(LIBOBJ)
$(AR) $(LIB) $(LIBOBJ)
$(RANLIB) $(LIB) || echo Never mind.
@touch lib
files:
$(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
links:
@$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
@$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
@$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
install:
@[ -n "$(INSTALLTOP)" ] # should be set by top Makefile...
@headerlist="$(EXHEADER)"; for i in $$headerlist ; \
do \
(cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
done;
tags:
ctags $(SRC)
tests:
lint:
lint -DLINT $(INCLUDES) $(SRC)>fluff
update: depend
depend:
@[ -n "$(MAKEDEPEND)" ] # should be set by upper Makefile...
$(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
dclean:
$(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
mv -f Makefile.new $(MAKEFILE)
clean:
rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
# DO NOT DELETE THIS LINE -- make depend depends on it.

9
demos/mystream/README.md Normal file
View File

@@ -0,0 +1,9 @@
## MyStream Stream Cipher
The official specification of MyStream can be found at
http://example.com/mystream.pdf
The OID (Object Identifier) of MyStream is 1.2.345.6789,
which is defined in standard http://example.com/mystream.pdf

64
demos/mystream/mystream.c Normal file
View File

@@ -0,0 +1,64 @@
/* crypto/mycipher/mycipher.c */
/* ====================================================================
* 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.
* ====================================================================
*
*/
/*
* author's information
*/
#include "mystream.h"
void mystream_set_key(mystream_key_t *key, const unsigned char *user_key, const unsigned char *iv)
{
}
void mystream_encrypt(mystream_key_t *key, size_t len, const unsigned char *in, unsigned char *out)
{
}

80
demos/mystream/mystream.h Normal file
View File

@@ -0,0 +1,80 @@
/* crypto/mystream/mystream.h */
/* ====================================================================
* 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.
* ====================================================================
*
*/
/*
* author's information
*/
#ifndef HEADER_MYSTREAM_H
#define HEADER_MYSTREAM_H
#define MYSTREAM_KEY_LENGTH 256
#include <sys/types.h>
#include <stdint.h>
#include <string.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
unsigned char state[100];
} mystream_key_t;
void mystream_set_key(mystream_key_t *key, const unsigned char *user_key, const unsigned char *iv);
void mystream_encrypt(mystream_key_t *key, size_t len, const unsigned char *in, unsigned char *out);
#ifdef __cplusplus
}
#endif
#endif

BIN
demos/mystream/mystream.o Normal file

Binary file not shown.

View File

@@ -0,0 +1,62 @@
/* crypto/mycipher/mycipher.h */
/* ====================================================================
* 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.
* ====================================================================
*
*/
/*
* author's information
*/
#include "mystream.h"
int main(int argc, char **argv)
{
return 0;
}