This commit is contained in:
Zhi Guan
2015-08-24 14:39:45 +08:00
parent 75f1c45de5
commit 8afb3ef97b
31 changed files with 4942 additions and 95 deletions

View File

@@ -12,9 +12,9 @@ SHLIB_VERSION_HISTORY=
SHLIB_MAJOR=1
SHLIB_MINOR=0.0
SHLIB_EXT=.$(SHLIB_MAJOR).$(SHLIB_MINOR).dylib
PLATFORM=darwin-i386-cc
OPTIONS= no-ec_nistp_64_gcc_128 no-gmp no-jpake no-krb5 no-libunbound no-md2 no-rc5 no-rfc3779 no-sctp no-shared no-ssl-trace no-store no-unit-test no-zlib no-zlib-dynamic static-engine
CONFIGURE_ARGS=darwin-i386-cc
PLATFORM=darwin64-x86_64-cc
OPTIONS=--prefix=/usr/local --openssldir=/usr/local/openssl no-ec_nistp_64_gcc_128 no-gmp no-jpake no-krb5 no-libunbound no-md2 no-rc5 no-rfc3779 no-sctp no-shared no-ssl-trace no-store no-unit-test no-zlib no-zlib-dynamic static-engine
CONFIGURE_ARGS=darwin64-x86_64-cc --prefix=/usr/local --openssldir=/usr/local/openssl
SHLIB_TARGET=darwin-shared
# HERE indicates where this Makefile lives. This can be used to indicate
@@ -26,10 +26,10 @@ HERE=.
# for, say, /usr/ and yet have everything installed to /tmp/somedir/usr/.
# Normally it is left empty.
INSTALL_PREFIX=
INSTALLTOP=/usr/local/ssl
INSTALLTOP=/usr/local
# Do not edit this manually. Use Configure --openssldir=DIR do change this!
OPENSSLDIR=/usr/local/ssl
OPENSSLDIR=/usr/local/openssl
# NO_IDEA - Define to build without the IDEA algorithm
# NO_RC4 - Define to build without the RC4 algorithm
@@ -60,7 +60,7 @@ OPENSSLDIR=/usr/local/ssl
# PKCS1_CHECK - pkcs1 tests.
CC= cc
CFLAG= -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -arch i386 -O3 -fomit-frame-pointer -DL_ENDIAN -DOPENSSL_BN_ASM_PART_WORDS -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_GF2m -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DMD5_ASM -DRMD160_ASM -DAES_ASM -DVPAES_ASM -DWHIRLPOOL_ASM -DGHASH_ASM
CFLAG= -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -arch x86_64 -O3 -DL_ENDIAN -Wall -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5 -DOPENSSL_BN_ASM_GF2m -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DMD5_ASM -DAES_ASM -DVPAES_ASM -DBSAES_ASM -DWHIRLPOOL_ASM -DGHASH_ASM -DECP_NISTZ256_ASM
DEPFLAG= -DOPENSSL_NO_EC_NISTP_64_GCC_128 -DOPENSSL_NO_GMP -DOPENSSL_NO_JPAKE -DOPENSSL_NO_LIBUNBOUND -DOPENSSL_NO_MD2 -DOPENSSL_NO_RC5 -DOPENSSL_NO_RFC3779 -DOPENSSL_NO_SCTP -DOPENSSL_NO_SSL_TRACE -DOPENSSL_NO_STORE -DOPENSSL_NO_UNIT_TEST
PEX_LIBS= -Wl,-search_paths_first
EX_LIBS=
@@ -88,21 +88,21 @@ ASFLAG=$(CFLAG)
PROCESSOR=
# CPUID module collects small commonly used assembler snippets
CPUID_OBJ= x86cpuid.o
BN_ASM= bn-586.o co-586.o x86-mont.o x86-gf2m.o
EC_ASM=
DES_ENC= des-586.o crypt586.o
AES_ENC= aes-586.o vpaes-x86.o aesni-x86.o
BF_ENC= bf-586.o
CPUID_OBJ= x86_64cpuid.o
BN_ASM= x86_64-gcc.o x86_64-mont.o x86_64-mont5.o x86_64-gf2m.o rsaz_exp.o rsaz-x86_64.o rsaz-avx2.o
EC_ASM= ecp_nistz256.o ecp_nistz256-x86_64.o
DES_ENC= des_enc.o fcrypt_b.o
AES_ENC= aes-x86_64.o vpaes-x86_64.o bsaes-x86_64.o aesni-x86_64.o aesni-sha1-x86_64.o aesni-sha256-x86_64.o aesni-mb-x86_64.o
BF_ENC= bf_enc.o
CAST_ENC= c_enc.o
RC4_ENC= rc4-586.o
RC5_ENC= rc5-586.o
MD5_ASM_OBJ= md5-586.o
SHA1_ASM_OBJ= sha1-586.o sha256-586.o sha512-586.o
RMD160_ASM_OBJ= rmd-586.o
WP_ASM_OBJ= wp_block.o wp-mmx.o
CMLL_ENC= cmll-x86.o
MODES_ASM_OBJ= ghash-x86.o
RC4_ENC= rc4_enc.o rc4_skey.o
RC5_ENC= rc5_enc.o
MD5_ASM_OBJ= md5-x86_64.o
SHA1_ASM_OBJ= sha1-x86_64.o sha256-x86_64.o sha512-x86_64.o sha1-mb-x86_64.o sha256-mb-x86_64.o
RMD160_ASM_OBJ=
WP_ASM_OBJ= wp-x86_64.o
CMLL_ENC= cmll-x86_64.o cmll_misc.o
MODES_ASM_OBJ= ghash-x86_64.o aesni-gcm-x86_64.o
ENGINES_ASM_OBJ=
PERLASM_SCHEME= macosx
@@ -147,7 +147,7 @@ SDIRS= \
objects \
md4 md5 sha mdc2 hmac sm3 sms4 ripemd whrlpool \
des aes rc2 rc4 idea bf cast camellia seed modes \
bn ec rsa dsa ecdsa dh ecdh dso engine \
bn ec rsa dsa ecdsa dh ecdh ecies dso engine \
buffer bio stack lhash rand err \
evp asn1 pem x509 x509v3 conf txt_db pkcs7 pkcs12 comp ocsp ui krb5 \
cms pqueue ts srp cmac
@@ -177,7 +177,7 @@ SHARED_CRYPTO=libcrypto$(SHLIB_EXT)
SHARED_SSL=libssl$(SHLIB_EXT)
SHARED_LIBS=
SHARED_LIBS_LINK_EXTS=.$(SHLIB_MAJOR).dylib .dylib
SHARED_LDFLAGS=-arch i386 -dynamiclib
SHARED_LDFLAGS=-arch x86_64 -dynamiclib
GENERAL= Makefile
BASENAME= openssl

View File

@@ -12,9 +12,9 @@ SHLIB_VERSION_HISTORY=
SHLIB_MAJOR=1
SHLIB_MINOR=0.0
SHLIB_EXT=.$(SHLIB_MAJOR).$(SHLIB_MINOR).dylib
PLATFORM=darwin-i386-cc
OPTIONS= no-ec_nistp_64_gcc_128 no-gmp no-jpake no-krb5 no-libunbound no-md2 no-rc5 no-rfc3779 no-sctp no-shared no-ssl-trace no-store no-unit-test no-zlib no-zlib-dynamic static-engine
CONFIGURE_ARGS=darwin-i386-cc
PLATFORM=darwin64-x86_64-cc
OPTIONS=--prefix=/usr/local --openssldir=/usr/local/openssl no-ec_nistp_64_gcc_128 no-gmp no-jpake no-krb5 no-libunbound no-md2 no-rc5 no-rfc3779 no-sctp no-shared no-ssl-trace no-store no-unit-test no-zlib no-zlib-dynamic static-engine
CONFIGURE_ARGS=darwin64-x86_64-cc --prefix=/usr/local --openssldir=/usr/local/openssl
SHLIB_TARGET=darwin-shared
# HERE indicates where this Makefile lives. This can be used to indicate
@@ -26,10 +26,10 @@ HERE=.
# for, say, /usr/ and yet have everything installed to /tmp/somedir/usr/.
# Normally it is left empty.
INSTALL_PREFIX=
INSTALLTOP=/usr/local/ssl
INSTALLTOP=/usr/local
# Do not edit this manually. Use Configure --openssldir=DIR do change this!
OPENSSLDIR=/usr/local/ssl
OPENSSLDIR=/usr/local/openssl
# NO_IDEA - Define to build without the IDEA algorithm
# NO_RC4 - Define to build without the RC4 algorithm
@@ -60,7 +60,7 @@ OPENSSLDIR=/usr/local/ssl
# PKCS1_CHECK - pkcs1 tests.
CC= cc
CFLAG= -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -arch i386 -O3 -fomit-frame-pointer -DL_ENDIAN -DOPENSSL_BN_ASM_PART_WORDS -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_GF2m -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DMD5_ASM -DRMD160_ASM -DAES_ASM -DVPAES_ASM -DWHIRLPOOL_ASM -DGHASH_ASM
CFLAG= -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -arch x86_64 -O3 -DL_ENDIAN -Wall -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5 -DOPENSSL_BN_ASM_GF2m -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DMD5_ASM -DAES_ASM -DVPAES_ASM -DBSAES_ASM -DWHIRLPOOL_ASM -DGHASH_ASM -DECP_NISTZ256_ASM
DEPFLAG= -DOPENSSL_NO_EC_NISTP_64_GCC_128 -DOPENSSL_NO_GMP -DOPENSSL_NO_JPAKE -DOPENSSL_NO_LIBUNBOUND -DOPENSSL_NO_MD2 -DOPENSSL_NO_RC5 -DOPENSSL_NO_RFC3779 -DOPENSSL_NO_SCTP -DOPENSSL_NO_SSL_TRACE -DOPENSSL_NO_STORE -DOPENSSL_NO_UNIT_TEST
PEX_LIBS= -Wl,-search_paths_first
EX_LIBS=
@@ -88,21 +88,21 @@ ASFLAG=$(CFLAG)
PROCESSOR=
# CPUID module collects small commonly used assembler snippets
CPUID_OBJ= x86cpuid.o
BN_ASM= bn-586.o co-586.o x86-mont.o x86-gf2m.o
EC_ASM=
DES_ENC= des-586.o crypt586.o
AES_ENC= aes-586.o vpaes-x86.o aesni-x86.o
BF_ENC= bf-586.o
CPUID_OBJ= x86_64cpuid.o
BN_ASM= x86_64-gcc.o x86_64-mont.o x86_64-mont5.o x86_64-gf2m.o rsaz_exp.o rsaz-x86_64.o rsaz-avx2.o
EC_ASM= ecp_nistz256.o ecp_nistz256-x86_64.o
DES_ENC= des_enc.o fcrypt_b.o
AES_ENC= aes-x86_64.o vpaes-x86_64.o bsaes-x86_64.o aesni-x86_64.o aesni-sha1-x86_64.o aesni-sha256-x86_64.o aesni-mb-x86_64.o
BF_ENC= bf_enc.o
CAST_ENC= c_enc.o
RC4_ENC= rc4-586.o
RC5_ENC= rc5-586.o
MD5_ASM_OBJ= md5-586.o
SHA1_ASM_OBJ= sha1-586.o sha256-586.o sha512-586.o
RMD160_ASM_OBJ= rmd-586.o
WP_ASM_OBJ= wp_block.o wp-mmx.o
CMLL_ENC= cmll-x86.o
MODES_ASM_OBJ= ghash-x86.o
RC4_ENC= rc4_enc.o rc4_skey.o
RC5_ENC= rc5_enc.o
MD5_ASM_OBJ= md5-x86_64.o
SHA1_ASM_OBJ= sha1-x86_64.o sha256-x86_64.o sha512-x86_64.o sha1-mb-x86_64.o sha256-mb-x86_64.o
RMD160_ASM_OBJ=
WP_ASM_OBJ= wp-x86_64.o
CMLL_ENC= cmll-x86_64.o cmll_misc.o
MODES_ASM_OBJ= ghash-x86_64.o aesni-gcm-x86_64.o
ENGINES_ASM_OBJ=
PERLASM_SCHEME= macosx
@@ -147,7 +147,7 @@ SDIRS= \
objects \
md4 md5 sha mdc2 hmac sm3 sms4 ripemd whrlpool \
des aes rc2 rc4 idea bf cast camellia seed modes \
bn ec rsa dsa ecdsa dh ecdh dso engine \
bn ec rsa dsa ecdsa dh ecdh ecies dso engine \
buffer bio stack lhash rand err \
evp asn1 pem x509 x509v3 conf txt_db pkcs7 pkcs12 comp ocsp ui krb5 \
cms pqueue ts srp cmac
@@ -177,7 +177,7 @@ SHARED_CRYPTO=libcrypto$(SHLIB_EXT)
SHARED_SSL=libssl$(SHLIB_EXT)
SHARED_LIBS=
SHARED_LIBS_LINK_EXTS=.$(SHLIB_MAJOR).dylib .dylib
SHARED_LDFLAGS=-arch i386 -dynamiclib
SHARED_LDFLAGS=-arch x86_64 -dynamiclib
GENERAL= Makefile
BASENAME= openssl

View File

@@ -145,7 +145,7 @@ SDIRS= \
objects \
md2 md4 md5 sha mdc2 hmac sm3 sms4 ripemd whrlpool \
des aes rc2 rc4 rc5 idea bf cast camellia seed modes \
bn ec rsa dsa ecdsa dh ecdh dso engine \
bn ec rsa dsa ecdsa dh ecdh ecies dso engine \
buffer bio stack lhash rand err \
evp asn1 pem x509 x509v3 conf txt_db pkcs7 pkcs12 comp ocsp ui krb5 \
cms pqueue ts jpake srp store cmac

View File

@@ -7,4 +7,8 @@ The OpenSSL integrated with Chinese national cryptography standard:
* SM3: Hash algorithm with 256-bit digest length, use `EVP_sm3()`
* SM4: or SMS4, a Feistel-style block cipher with 128-bit key length and 128-bit block size, use `EVP_sms4_ecb()`, `EVP_sms4_cbc()`, `EVP_sms4_cfb()`, `EVP_sms4_ofb()`.
Also SECG algoirthms:
* ECIES: Elliptic Curve Integrated Encryption Scheme

20
a.txt
View File

@@ -1,20 +0,0 @@
libcrypto.a(md5_dgst.o):
U _md5_block_asm_data_order
libcrypto.a(md5_one.o):
libcrypto.a(md5-586.o):
00000000 T _md5_block_asm_data_order
libcrypto.a(m_md5.o):
00000000 T _EVP_md5
00000080 s _md5_md
U _EVP_rc4_hmac_md5
U _EVP_md5
libcrypto.a(e_rc4_hmac_md5.o):
00000000 T _EVP_rc4_hmac_md5
000004e0 d _r4_hmac_md5_cipher
00000080 t _rc4_hmac_md5_cipher
000002c0 t _rc4_hmac_md5_ctrl
00000010 t _rc4_hmac_md5_init_key
U _EVP_md5
U _EVP_md5
U _EVP_md5
U _EVP_md5

12
b.txt
View File

@@ -1,12 +0,0 @@
libcrypto.a(sm3.o):
000006a0 T _sm3
00000160 T _sm3_compress
00000530 T _sm3_final
00000000 T _sm3_init
00000060 T _sm3_update
libcrypto.a(m_sm3.o):
00000000 T _EVP_sm3
U _sm3_final
U _sm3_init
00000080 s _sm3_md
U _sm3_update

View File

@@ -1,5 +1,14 @@
#!/bin/bash
./Configure darwin64-x86_64-cc no-asm --prefix=/usr/local --openssldir=/usr/local/openssl
./Configure darwin64-x86_64-cc --prefix=/usr/local --openssldir=/usr/local/openssl
make
sudo make install
# build libp11
# $ ./bootstrap
# $ LIBP11_CFLAGS='-I/usr/local/include'; export LIBP11_CFLAGS
# $ LIBP11_LIBS='-L/usr/local/lib -lp11'; export LIBP11_LIBS
# $ ./configure

1
certs/demo/.0 Symbolic link
View File

@@ -0,0 +1 @@
ca-cert.pem

File diff suppressed because it is too large Load Diff

142
crypto/ecies/Makefile Normal file
View File

@@ -0,0 +1,142 @@
#
# crypto/ecies/Makefile
#
DIR= ecies
TOP= ../..
CC= cc
INCLUDES= -I.. -I$(TOP) -I../../include
CFLAG=-g -Wall
MAKEFILE= Makefile
AR= ar r
CFLAGS= $(INCLUDES) $(CFLAG)
GENERAL=Makefile
TEST=eciestest.c
APPS=
LIB=$(TOP)/libcrypto.a
LIBSRC= ecies_lib.c ecies_asn1.c ecies_err.c kdf_x9_63.c
LIBOBJ= ecies_lib.o ecies_asn1.o ecies_err.o kdf_x9_63.o
SRC= $(LIBSRC)
EXHEADER= ecies.h kdf.h
HEADER= ecies_locl.h $(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 */*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
# DO NOT DELETE THIS LINE -- make depend depends on it.
ecs_asn1.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
ecs_asn1.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h
ecs_asn1.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
ecs_asn1.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
ecs_asn1.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
ecs_asn1.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
ecs_asn1.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
ecs_asn1.o: ../../include/openssl/symhacks.h ecs_asn1.c ecs_locl.h
ecs_err.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
ecs_err.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
ecs_err.o: ../../include/openssl/ec.h ../../include/openssl/ecdsa.h
ecs_err.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
ecs_err.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
ecs_err.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
ecs_err.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
ecs_err.o: ecs_err.c
ecs_lib.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
ecs_lib.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
ecs_lib.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
ecs_lib.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
ecs_lib.o: ../../include/openssl/ecdsa.h ../../include/openssl/engine.h
ecs_lib.o: ../../include/openssl/err.h ../../include/openssl/evp.h
ecs_lib.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
ecs_lib.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
ecs_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
ecs_lib.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
ecs_lib.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
ecs_lib.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
ecs_lib.o: ../../include/openssl/x509_vfy.h ecs_lib.c ecs_locl.h
ecs_ossl.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
ecs_ossl.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
ecs_ossl.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
ecs_ossl.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
ecs_ossl.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
ecs_ossl.o: ../../include/openssl/opensslconf.h
ecs_ossl.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
ecs_ossl.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
ecs_ossl.o: ../../include/openssl/symhacks.h ecs_locl.h ecs_ossl.c
ecs_sign.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
ecs_sign.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
ecs_sign.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
ecs_sign.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
ecs_sign.o: ../../include/openssl/engine.h ../../include/openssl/evp.h
ecs_sign.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
ecs_sign.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
ecs_sign.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
ecs_sign.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
ecs_sign.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
ecs_sign.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
ecs_sign.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
ecs_sign.o: ecs_locl.h ecs_sign.c
ecs_vrf.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
ecs_vrf.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
ecs_vrf.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
ecs_vrf.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
ecs_vrf.o: ../../include/openssl/engine.h ../../include/openssl/evp.h
ecs_vrf.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
ecs_vrf.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
ecs_vrf.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
ecs_vrf.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
ecs_vrf.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
ecs_vrf.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
ecs_vrf.o: ../../include/openssl/x509_vfy.h ecs_locl.h ecs_vrf.c

72
crypto/ecies/ecies.h Normal file
View File

@@ -0,0 +1,72 @@
#ifndef HEADER_ECIES_H
#define HEADER_ECIES_H
#include <openssl/ec.h>
#include <openssl/err.h>
#include <openssl/evp.h>
#include <openssl/x509.h>
#include <openssl/asn1.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct ecies_params_st {
const EVP_MD *kdf_md;
const EVP_CIPHER *sym_cipher;
const EVP_MD *mac_md;
} ECIES_PARAMS;
typedef struct ecies_ciphertext_value_st {
ASN1_OCTET_STRING *ephem_point;
ASN1_OCTET_STRING *ciphertext;
ASN1_OCTET_STRING *mactag;
} ECIES_CIPHERTEXT_VALUE;
DECLARE_ASN1_FUNCTIONS(ECIES_CIPHERTEXT_VALUE)
int i2d_ECIESParameters(const ECIES_PARAMS *param, unsigned char **out);
ECIES_PARAMS *d2i_ECIESParameters(ECIES_PARAMS **param, const unsigned char **in, long len);
ECIES_CIPHERTEXT_VALUE *ECIES_do_encrypt(const ECIES_PARAMS *param,
const unsigned char *in, size_t inlen, const EC_KEY *pub_key);
int ECIES_do_decrypt(const ECIES_CIPHERTEXT_VALUE *cv,
const ECIES_PARAMS *param, unsigned char *out, size_t *outlen,
EC_KEY *pri_key);
/* ERR function (should in openssl/err.h) begin */
/*
#define ERR_LIB_ECIES 129
#define ERR_R_ECIES_LIB ERR_LIB_ECIES
#define ECIESerr(f,r) ERR_PUT_error(ERR_LIB_ECIES,(f),(r),__FILE__,__LINE__)
*/
void ERR_load_ECIES_strings(void);
/* Error codes for the ECIES functions. */
/* Function codes. */
#define ECIES_F_I2D_ECIESPARAMETERS 100
#define ECIES_F_D2I_ECIESPARAMETERS 101
#define ECIES_F_ECIES_DO_ENCRYPT 102
#define ECIES_F_ECIES_DO_DECRYPT 103
/* Reason codes. */
#define ECIES_R_BAD_DATA 100
#define ECIES_R_UNKNOWN_CIPHER_TYPE 101
#define ECIES_R_ENCRYPT_FAILED 102
#define ECIES_R_DECRYPT_FAILED 103
#define ECIES_R_UNKNOWN_MAC_TYPE 104
#define ECIES_R_GEN_MAC_FAILED 105
#define ECIES_R_VERIFY_MAC_FAILED 106
#define ECIES_R_ECDH_FAILED 107
#define ECIES_R_BUFFER_TOO_SMALL 108
#ifdef __cplusplus
}
#endif
#endif

316
crypto/ecies/ecies_asn1.c Normal file
View File

@@ -0,0 +1,316 @@
#include <string.h>
#include <openssl/err.h>
#include <openssl/asn1.h>
#include <openssl/asn1t.h>
#include <openssl/objects.h>
#include <openssl/obj_mac.h>
#include "ecies.h"
/*
* From SEC 1, Version 1.9 Draft, 2008
*
secg-scheme OBJECT IDENTIFIER ::= {
iso(1) identified-organization(3) certicom(132) schemes(1) }
ECIESAlgorithmSet ALGORITHM ::= {
{ OID ecies-recommendedParameters} |
{ OID ecies-specifiedParameters PARMS ECIESParameters}
}
ECIESParameters ::= SEQUENCE {
kdf [0] KeyDerivationFunction OPTIONAL,
sym [1] SymmetricEncryption OPTIONAL,
mac [2] MessageAuthenticationCode OPTIONAL
}
KeyDerivationFunction ::= AlgorithmIdentifier {{KDFSet}}
KDFSet ALGORITHM ::= {
{ OID x9-63-kdf PARMS HashAlgorithm } |
{ OID nist-concatenation-kdf PARMS HashAlgorithm } |
{ OID tls-kdf PARMS HashAlgorithm } |
{ OID ikev2-kdf PARMS HashAlgorithm }
}
SymmetricEncryption ::= AlgorithmIdentifier {{SYMENCSet}}
SYMENCSet ALGORITHM ::= {
{ OID xor-in-ecies } |
{ OID tdes-cbc-in-ecies } | -- IV should all be set to ZEROs
{ OID aes128-cbc-in-ecies } |
{ OID aes192-cbc-in-ecies } |
{ OID aes256-cbc-in-ecies } |
{ OID aes128-ctr-in-ecies } |
{ OID aes192-ctr-in-ecies } |
{ OID aes256-ctr-in-ecies } ,
}
MessageAuthenticationCode ::= AlgorithmIdentifier {{MACSet}}
MACSet ALGORITHM ::= {
{ OID hmac-full-ecies PARMS HashAlgorithm} |
{ OID hmac-half-ecies PARMS HashAlgorithm} |
{ OID cmac-aes128-ecies } |
{ OID cmac-aes192-ecies } |
{ OID cmac-aes256-ecies } ,
}
*/
/*
* Something about HMAC
* 1. Key Length: As SHA1 provides 160 bits digest and 80 bits security.
* Thus the key length of HMAC-SHA1 should be at least 80 bits. The key
* length should be [80, 160] bits. If the key length is larger than
* 512 bits, need to hash it.
* 2. Ouput Length: The HMAC-SHA1 can ouput at most 160 bits. Sometimes the
* output is truncated but should be at least 4 bytes. The turncated
* output should be the left most bytes (why?) and the length should be
* 80 bits to 160 bits. The standard hmac-full means use full output
* i.e. hmac-sha1-160 and hmac-half means use the left most 80 bits i.e.
* hmac-sha1-80
*
* About CMAC
* In OpenSSL version 1.0.1c CMAC has been supported! For CMAC-AES the
* output is always 128 bits. It is obvious that the CMAC key length
* should be the same as the block cipher key length.
*/
/*
# Add these to "objects.txt" and run `make'
!Alias secg_scheme certicom-arc 1
secg-scheme 7 : ecies-recommendedParameters
secg-scheme 8 : ecies-specifiedParameters
secg-scheme 17 0 : x9-63-kdf
secg-scheme 17 1 : nist-concatenation-kdf
secg-scheme 17 2 : tls-kdf
secg-scheme 17 3 : ikev2-kdf
secg-scheme 18 : xor-in-ecies
secg-scheme 20 0 : aes128-cbc-in-ecies
secg-scheme 20 1 : aes192-cbc-in-ecies
secg-scheme 20 2 : aes256-cbc-in-ecies
secg-scheme 21 0 : aes128-ctr-in-ecies
secg-scheme 21 1 : aes192-ctr-in-ecies
secg-scheme 21 2 : aes256-ctr-in-ecies
secg-scheme 22 : hmac-full-ecies
secg-scheme 23 : hmac-half-ecies
secg-scheme 24 0 : cmac-aes128-ecies
secg-scheme 24 1 : cmac-aes192-ecies
*/
typedef struct ecies_parameters_st {
X509_ALGOR *kdf;
X509_ALGOR *sym;
X509_ALGOR *mac;
} ECIES_PARAMETERS;
ASN1_SEQUENCE(ECIES_PARAMETERS) = {
ASN1_EXP_OPT(ECIES_PARAMETERS, kdf, X509_ALGOR, 0),
ASN1_EXP_OPT(ECIES_PARAMETERS, sym, X509_ALGOR, 1),
ASN1_EXP_OPT(ECIES_PARAMETERS, mac, X509_ALGOR, 2)
} ASN1_SEQUENCE_END(ECIES_PARAMETERS)
IMPLEMENT_ASN1_FUNCTIONS(ECIES_PARAMETERS)
IMPLEMENT_ASN1_DUP_FUNCTION(ECIES_PARAMETERS)
ASN1_SEQUENCE(ECIES_CIPHERTEXT_VALUE) = {
ASN1_SIMPLE(ECIES_CIPHERTEXT_VALUE, ephem_point, ASN1_OCTET_STRING),
ASN1_SIMPLE(ECIES_CIPHERTEXT_VALUE, ciphertext, ASN1_OCTET_STRING),
ASN1_SIMPLE(ECIES_CIPHERTEXT_VALUE, mactag, ASN1_OCTET_STRING)
} ASN1_SEQUENCE_END(ECIES_CIPHERTEXT_VALUE)
IMPLEMENT_ASN1_FUNCTIONS(ECIES_CIPHERTEXT_VALUE)
IMPLEMENT_ASN1_DUP_FUNCTION(ECIES_CIPHERTEXT_VALUE)
int i2d_ECIESParameters(const ECIES_PARAMS *param, unsigned char **out)
{
int ret = 0;
ECIES_PARAMETERS *tmp = NULL;
int sym_nid = NID_xor_in_ecies;
OPENSSL_assert(param);
OPENSSL_assert(param->kdf_md);
OPENSSL_assert(param->mac_md);
OpenSSL_add_all_digests();
if (!(tmp = ECIES_PARAMETERS_new()))
{
ECIESerr(ECIES_F_I2D_ECIESPARAMETERS, ERR_R_MALLOC_FAILURE);
goto err;
}
if (!(tmp->kdf = X509_ALGOR_new()))
{
ECIESerr(ECIES_F_I2D_ECIESPARAMETERS, ERR_R_MALLOC_FAILURE);
goto err;
}
if (!X509_ALGOR_set0(tmp->kdf, OBJ_nid2obj(NID_x9_63_kdf), V_ASN1_OBJECT, OBJ_nid2obj(EVP_MD_nid(param->kdf_md))))
{
ECIESerr(ECIES_F_I2D_ECIESPARAMETERS, ERR_R_X509_LIB);
goto err;
}
if (!(tmp->sym = X509_ALGOR_new()))
{
ECIESerr(ECIES_F_I2D_ECIESPARAMETERS, ERR_R_MALLOC_FAILURE);
goto err;
}
if (param->sym_cipher)
{
switch (EVP_CIPHER_nid(param->sym_cipher))
{
case NID_aes_128_cbc:
sym_nid = NID_aes128_cbc_in_ecies;
break;
case NID_aes_192_cbc:
sym_nid = NID_aes192_cbc_in_ecies;
break;
case NID_aes_256_cbc:
sym_nid = NID_aes256_cbc_in_ecies;
break;
case NID_aes_128_ctr:
sym_nid = NID_aes128_ctr_in_ecies;
break;
case NID_aes_192_ctr:
sym_nid = NID_aes192_ctr_in_ecies;
break;
case NID_aes_256_ctr:
sym_nid = NID_aes256_ctr_in_ecies;
break;
default:
ECIESerr(ECIES_F_I2D_ECIESPARAMETERS, ERR_R_MALLOC_FAILURE);
goto err;
}
}
if (!X509_ALGOR_set0(tmp->sym, OBJ_nid2obj(sym_nid), V_ASN1_UNDEF, NULL))
{
ECIESerr(ECIES_F_I2D_ECIESPARAMETERS, ERR_R_X509_LIB);
goto err;
}
if (!(tmp->mac = X509_ALGOR_new()))
{
ECIESerr(ECIES_F_I2D_ECIESPARAMETERS, ERR_R_MALLOC_FAILURE);
goto err;
}
if (!X509_ALGOR_set0(tmp->mac, OBJ_nid2obj(NID_hmac_full_ecies), V_ASN1_OBJECT, OBJ_nid2obj(EVP_MD_nid(param->mac_md))))
{
ECIESerr(ECIES_F_I2D_ECIESPARAMETERS, ERR_R_X509_LIB);
goto err;
}
if ((ret = i2d_ECIES_PARAMETERS(tmp, out)) <= 0)
{
ECIESerr(ECIES_F_I2D_ECIESPARAMETERS, ERR_R_ASN1_LIB);
goto err;
}
err:
if (tmp)
ECIES_PARAMETERS_free(tmp);
return ret;
}
ECIES_PARAMS *d2i_ECIESParameters(ECIES_PARAMS **param, const unsigned char **in, long len)
{
int e = 1;
ECIES_PARAMS *ret = NULL;
ECIES_PARAMETERS *tmp = NULL;
if (!(ret = OPENSSL_malloc(sizeof(ECIES_PARAMS))))
{
ECIESerr(ECIES_F_D2I_ECIESPARAMETERS, ERR_R_ASN1_LIB);
goto err;
}
if (!(tmp = d2i_ECIES_PARAMETERS(NULL, in, len)))
{
ECIESerr(ECIES_F_D2I_ECIESPARAMETERS, ERR_R_ASN1_LIB);
goto err;
}
/* get kdf, parameter is hash oid */
if (OBJ_obj2nid(tmp->kdf->algorithm) != NID_x9_63_kdf)
{
ECIESerr(ECIES_F_D2I_ECIESPARAMETERS, ERR_R_ECIES_LIB);
goto err;
}
if (tmp->kdf->parameter->type != V_ASN1_OBJECT)
{
ECIESerr(ECIES_F_D2I_ECIESPARAMETERS, ERR_R_ECIES_LIB);
goto err;
}
OpenSSL_add_all_digests();
if (!(ret->kdf_md = EVP_get_digestbynid(OBJ_obj2nid(tmp->kdf->parameter->value.object))))
{
ECIESerr(ECIES_F_D2I_ECIESPARAMETERS, ERR_R_ECIES_LIB);
goto err;
}
/* get sym, no parameter for iv is zero */
switch (OBJ_obj2nid(tmp->sym->algorithm)) {
case NID_xor_in_ecies:
ret->sym_cipher = NULL;
break;
case NID_aes128_cbc_in_ecies:
ret->sym_cipher = EVP_aes_128_cbc();
break;
case NID_aes192_cbc_in_ecies:
ret->sym_cipher = EVP_aes_192_cbc();
break;
case NID_aes256_cbc_in_ecies:
ret->sym_cipher = EVP_aes_256_cbc();
break;
case NID_aes128_ctr_in_ecies:
ret->sym_cipher = EVP_aes_128_ctr();
break;
case NID_aes192_ctr_in_ecies:
ret->sym_cipher = EVP_aes_192_ctr();
break;
case NID_aes256_ctr_in_ecies:
ret->sym_cipher = EVP_aes_256_ctr();
break;
default:
goto err;
}
/* get mac, parameter is hash oid */
switch (OBJ_obj2nid(tmp->mac->algorithm)) {
case NID_hmac_full_ecies:
break;
case NID_hmac_half_ecies:
case NID_cmac_aes128_ecies:
case NID_cmac_aes192_ecies:
goto err;
break;
default:
goto err;
break;
}
if (tmp->mac->parameter->type != V_ASN1_OBJECT)
{
ECIESerr(ECIES_F_D2I_ECIESPARAMETERS, ERR_R_ECIES_LIB);
goto err;
}
if (!(ret->mac_md = EVP_get_digestbynid(OBJ_obj2nid(
tmp->mac->parameter->value.object))))
{
ECIESerr(ECIES_F_D2I_ECIESPARAMETERS, ERR_R_ECIES_LIB);
goto err;
}
if (param && *param)
OPENSSL_free(*param);
if (param)
*param = ret;
e = 0;
err:
if (e && ret)
{
OPENSSL_free(ret);
ret = NULL;
}
if (tmp) ECIES_PARAMETERS_free(tmp);
return ret;
}

41
crypto/ecies/ecies_err.c Normal file
View File

@@ -0,0 +1,41 @@
#include <stdio.h>
#include <openssl/err.h>
#include "ecies.h"
#ifndef OPENSSL_NO_ERR
#define ERR_FUNC(func) ERR_PACK(ERR_LIB_ECIES,func,0)
#define ERR_REASON(reason) ERR_PACK(ERR_LIB_ECIES,0,reason)
static ERR_STRING_DATA ECIES_str_functs[] = {
{ERR_FUNC(ECIES_F_ECIES_DO_ENCRYPT), "ECIES_do_encrypt"},
{ERR_FUNC(ECIES_F_ECIES_DO_DECRYPT), "ECIES_do_decrypt"},
{0,NULL}
};
static ERR_STRING_DATA ECIES_str_reasons[] = {
{ERR_REASON(ECIES_R_BAD_DATA), "bad data"},
{ERR_REASON(ECIES_R_UNKNOWN_CIPHER_TYPE),"unknown cipher type"},
{ERR_REASON(ECIES_R_ENCRYPT_FAILED), "encrypt failed"},
{ERR_REASON(ECIES_R_DECRYPT_FAILED), "decrypt failed"},
{ERR_REASON(ECIES_R_UNKNOWN_MAC_TYPE), "unknown MAC type"},
{ERR_REASON(ECIES_R_GEN_MAC_FAILED), "MAC generation failed"},
{ERR_REASON(ECIES_R_VERIFY_MAC_FAILED), "MAC verification failed"},
{ERR_REASON(ECIES_R_ECDH_FAILED), "ECDH failed"},
{ERR_REASON(ECIES_R_BUFFER_TOO_SMALL), "buffer too small"},
{0,NULL}
};
#endif
void ERR_load_ECIES_strings(void)
{
#ifndef OPENSSL_NO_ERR
if (ERR_func_error_string(ECIES_str_functs[0].error) == NULL) {
ERR_load_strings(0,ECIES_str_functs);
ERR_load_strings(0,ECIES_str_reasons);
}
#endif
}

0
crypto/ecies/ecies_lcl.h Normal file
View File

314
crypto/ecies/ecies_lib.c Normal file
View File

@@ -0,0 +1,314 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <openssl/hmac.h>
#include <openssl/rand.h>
#include <openssl/ecdh.h>
#include "ecies.h"
#include "kdf.h"
ECIES_CIPHERTEXT_VALUE *ECIES_do_encrypt(const ECIES_PARAMS *param,
const unsigned char *in, size_t inlen, const EC_KEY *pub_key)
{
int e = 1;
ECIES_CIPHERTEXT_VALUE *cv = NULL;
EC_KEY *ephem_key = NULL;
unsigned char *share = NULL;
unsigned char *enckey, *mackey, *p;
int sharelen, enckeylen, mackeylen, len;
EVP_CIPHER_CTX cipher_ctx;
EVP_CIPHER_CTX_init(&cipher_ctx);
if (!(cv = ECIES_CIPHERTEXT_VALUE_new()))
{
ECIESerr(ECIES_F_ECIES_DO_ENCRYPT, ERR_R_MALLOC_FAILURE);
goto err;
}
/*
* generate and encode ephem_point
*/
if (!(ephem_key = EC_KEY_new()))
{
ECIESerr(ECIES_F_ECIES_DO_ENCRYPT, ERR_R_MALLOC_FAILURE);
goto err;
}
if (!EC_KEY_set_group(ephem_key, EC_KEY_get0_group(pub_key)))
{
ECIESerr(ECIES_F_ECIES_DO_ENCRYPT, ERR_R_EC_LIB);
goto err;
}
if (!EC_KEY_generate_key(ephem_key))
{
ECIESerr(ECIES_F_ECIES_DO_ENCRYPT, ERR_R_EC_LIB);
goto err;
}
len = (int)EC_POINT_point2oct(EC_KEY_get0_group(ephem_key),
EC_KEY_get0_public_key(ephem_key), POINT_CONVERSION_COMPRESSED,
NULL, 0, NULL);
if (!M_ASN1_OCTET_STRING_set(cv->ephem_point, NULL, len))
{
ECIESerr(ECIES_F_ECIES_DO_ENCRYPT, ERR_R_ASN1_LIB);
goto err;
}
if (EC_POINT_point2oct(EC_KEY_get0_group(ephem_key),
EC_KEY_get0_public_key(ephem_key), POINT_CONVERSION_COMPRESSED,
cv->ephem_point->data, len, NULL) <= 0)
{
ECIESerr(ECIES_F_ECIES_DO_ENCRYPT, ERR_R_EC_LIB);
goto err;
}
/*
* use ecdh to compute enckey and mackey
*/
if (param->sym_cipher)
enckeylen = EVP_CIPHER_key_length(param->sym_cipher);
else enckeylen = inlen;
mackeylen = EVP_MD_size(param->mac_md); //TODO: is this true for hmac-half-ecies?
sharelen = enckeylen + mackeylen;
if (!(share = OPENSSL_malloc(sharelen)))
{
ECIESerr(ECIES_F_ECIES_DO_ENCRYPT, ERR_R_MALLOC_FAILURE);
goto err;
}
if (!ECDH_compute_key(share, sharelen,
EC_KEY_get0_public_key(pub_key), ephem_key,
KDF_get_x9_63(param->kdf_md)))
{
ECIESerr(ECIES_F_ECIES_DO_ENCRYPT, ECIES_R_ECDH_FAILED);
goto err;
}
enckey = share;
mackey = share + enckeylen;
/*
* encrypt data and encode result to ciphertext
*/
if (param->sym_cipher)
len = (int)(inlen + EVP_MAX_BLOCK_LENGTH * 2);
else len = inlen;
if (!M_ASN1_OCTET_STRING_set(cv->ciphertext, NULL, len))
{
ECIESerr(ECIES_F_ECIES_DO_ENCRYPT, ERR_R_MALLOC_FAILURE);
goto err;
}
if (param->sym_cipher)
{
unsigned char iv[EVP_MAX_IV_LENGTH];
memset(iv, 0, sizeof(iv));
if (!EVP_EncryptInit(&cipher_ctx, param->sym_cipher, enckey, iv))
{
ECIESerr(ECIES_F_ECIES_DO_ENCRYPT,
ECIES_R_ENCRYPT_FAILED);
goto err;
}
p = cv->ciphertext->data;
if (!EVP_EncryptUpdate(&cipher_ctx, p, &len, in, (int)inlen))
{
ECIESerr(ECIES_F_ECIES_DO_ENCRYPT,
ECIES_R_ENCRYPT_FAILED);
goto err;
}
p += len;
if (!EVP_EncryptFinal(&cipher_ctx, p, &len))
{
ECIESerr(ECIES_F_ECIES_DO_ENCRYPT,
ECIES_R_ENCRYPT_FAILED);
goto err;
}
p += len;
cv->ciphertext->length = (int)(p - cv->ciphertext->data);
}
else
{
int i;
for (i = 0; i < len; i++)
cv->ciphertext->data[i] = in[i] ^ enckey[i];
cv->ciphertext->length = len;
}
/*
* calculate mactag of ciphertext and encode
*/
cv->mactag->length = EVP_MD_size(param->mac_md);
if (!M_ASN1_OCTET_STRING_set(cv->mactag, NULL, EVP_MD_size(param->mac_md)))
{
ECIESerr(ECIES_F_ECIES_DO_ENCRYPT, ERR_R_MALLOC_FAILURE);
goto err;
}
if (!HMAC(param->mac_md, mackey, mackeylen,
cv->ciphertext->data, (size_t)cv->ciphertext->length,
cv->mactag->data, (unsigned int *)&len))
{
ECIESerr(ECIES_F_ECIES_DO_ENCRYPT, ECIES_R_GEN_MAC_FAILED);
goto err;
}
e = 0;
err:
EVP_CIPHER_CTX_cleanup(&cipher_ctx);
if (share) OPENSSL_free(share);
if (ephem_key) EC_KEY_free(ephem_key);
if (e && cv)
{
ECIES_CIPHERTEXT_VALUE_free(cv);
cv = NULL;
}
return cv;
}
int ECIES_do_decrypt(const ECIES_CIPHERTEXT_VALUE *cv,
const ECIES_PARAMS *param, unsigned char *out, size_t *outlen,
EC_KEY *pri_key)
{
int r = 0;
EC_POINT *ephem_point = NULL;
unsigned char *share = NULL;
unsigned char mac[EVP_MAX_MD_SIZE];
unsigned char *enckey, *mackey;
int sharelen, enckeylen, mackeylen, len;
unsigned char *p;
EVP_CIPHER_CTX ctx;
EVP_CIPHER_CTX_init(&ctx);
// check output buffer size
if (!out)
{
*outlen = cv->ciphertext->length;
r = 1;
goto err;
}
if ((int)(*outlen) < cv->ciphertext->length)
{
*outlen = cv->ciphertext->length;
ECIESerr(ECIES_F_ECIES_DO_DECRYPT, ECIES_R_BUFFER_TOO_SMALL);
goto err;
}
/*
* decode ephem_point
*/
if (!cv->ephem_point || !cv->ephem_point->data)
{
ECIESerr(ECIES_F_ECIES_DO_DECRYPT, ECIES_R_BAD_DATA);
goto err;
}
if (!(ephem_point = EC_POINT_new(EC_KEY_get0_group(pri_key))))
{
ECIESerr(ECIES_F_ECIES_DO_ENCRYPT, ERR_R_MALLOC_FAILURE);
goto err;
}
if (!EC_POINT_oct2point(EC_KEY_get0_group(pri_key), ephem_point,
cv->ephem_point->data, cv->ephem_point->length, NULL))
{
ECIESerr(ECIES_F_ECIES_DO_DECRYPT, ECIES_R_BAD_DATA);
goto err;
}
/*
* use ecdh to compute enckey and mackey
*/
if (param->sym_cipher)
enckeylen = EVP_CIPHER_key_length(param->sym_cipher);
else enckeylen = cv->ciphertext->length;
mackeylen = EVP_MD_size(param->mac_md);
sharelen = enckeylen + mackeylen;
if (!(share = OPENSSL_malloc(sharelen)))
{
ECIESerr(ECIES_F_ECIES_DO_DECRYPT, ERR_R_MALLOC_FAILURE);
goto err;
}
if (!ECDH_compute_key(share, enckeylen + mackeylen,
ephem_point, pri_key,
KDF_get_x9_63(param->kdf_md)))
{
ECIESerr(ECIES_F_ECIES_DO_DECRYPT, ECIES_R_ECDH_FAILED);
goto err;
}
enckey = share;
mackey = share + enckeylen;
/*
* generate and verify mac
*/
if (!cv->mactag || !cv->mactag->data)
{
ECIESerr(ECIES_F_ECIES_DO_DECRYPT, ECIES_R_BAD_DATA);
goto err;
}
if (!HMAC(param->mac_md, mackey, mackeylen,
cv->ciphertext->data, (size_t)cv->ciphertext->length,
mac, (unsigned int *)&len))
{
ECIESerr(ECIES_F_ECIES_DO_DECRYPT, ECIES_R_GEN_MAC_FAILED);
goto err;
}
if (len != cv->mactag->length)
{
ECIESerr(ECIES_F_ECIES_DO_DECRYPT, ECIES_R_VERIFY_MAC_FAILED);
goto err;
}
if (memcmp(cv->mactag->data, mac, len))
{
ECIESerr(ECIES_F_ECIES_DO_DECRYPT, ECIES_R_VERIFY_MAC_FAILED);
goto err;
}
/*
* decrypt ciphertext and output
*/
if (param->sym_cipher)
{
unsigned char iv[EVP_MAX_IV_LENGTH];
memset(iv, 0, sizeof(iv));
if (!EVP_DecryptInit(&ctx, param->sym_cipher, enckey, iv))
{
ECIESerr(ECIES_F_ECIES_DO_DECRYPT, ECIES_R_DECRYPT_FAILED);
goto err;
}
p = out;
if (!EVP_DecryptUpdate(&ctx, p, &len,
cv->ciphertext->data, cv->ciphertext->length))
{
ECIESerr(ECIES_F_ECIES_DO_DECRYPT, ECIES_R_DECRYPT_FAILED);
goto err;
}
p += len;
if (!EVP_DecryptFinal(&ctx, p, &len))
{
ECIESerr(ECIES_F_ECIES_DO_DECRYPT, ECIES_R_DECRYPT_FAILED);
goto err;
}
p += len;
*outlen = (int)(p - out);
}
else
{
int i;
for (i = 0; i < cv->ciphertext->length; i++)
out[i] = cv->ciphertext->data[i] ^ enckey[i];
*outlen = cv->ciphertext->length;
}
r = 1;
err:
if (share) OPENSSL_free(share);
EVP_CIPHER_CTX_cleanup(&ctx);
if (ephem_point) EC_POINT_free(ephem_point);
return r;
}

123
crypto/ecies/eciestest.c Normal file
View File

@@ -0,0 +1,123 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <openssl/evp.h>
#include <openssl/err.h>
#include "ecies.h"
int ecies_test_ECIESParameters(void)
{
int ret = 0;
ECIES_PARAMS buffer;
ECIES_PARAMS *param = &buffer;
unsigned char *der = NULL;
int derlen;
unsigned char *p;
const unsigned char *cp;
param->kdf_md = EVP_sha1();
param->sym_cipher = NULL;
param->mac_md = EVP_sha1();
derlen = i2d_ECIESParameters(param, NULL);
if (derlen <= 0) {
fprintf(stderr, "test i2d_ECIESParameters failed test suite 1\n");
goto end;
}
der = OPENSSL_malloc(derlen);
OPENSSL_assert(der);
p = der;
derlen = i2d_ECIESParameters(param, &p);
param = NULL;
cp = der;
param = d2i_ECIESParameters(NULL, &cp, derlen);
if (!param) {
fprintf(stderr, "test d2i_ECIESParameters faild\n");
goto end;
}
OPENSSL_free(param);
param = NULL;
cp = der;
d2i_ECIESParameters(&param, &cp, derlen);
if (!param) {
fprintf(stderr, "test failed\n");
goto end;
}
ret = 1;
end:
return ret;
}
void ecies_test(void)
{
int r;
EC_GROUP *ec_group = NULL;
EC_KEY *ec_key = NULL;
ECIES_PARAMS params;
ECIES_PARAMS *param2 = NULL;
ECIES_CIPHERTEXT_VALUE *cv = NULL;
unsigned char buffer1[1024];
unsigned char buffer2[1024];
unsigned char buffer3[1024];
unsigned char *der = NULL;
int derlen;
unsigned char *p;
const unsigned char *cp;
ec_key = EC_KEY_new_by_curve_name(OBJ_sn2nid("secp192k1"));
OPENSSL_assert(ec_key);
r = EC_KEY_generate_key(ec_key);
assert(r);
/* set ECIESParameters */
params.kdf_md = EVP_sha1();
params.sym_cipher = EVP_aes_128_cbc();
params.mac_md = EVP_sha1();
derlen = i2d_ECIESParameters(&params, NULL);
printf("ECIESParameters DER length = %d\n", derlen);
memset(buffer1, 0, sizeof(buffer1));
strcpy((char *)buffer1, "hello");
cv = ECIES_do_encrypt(&params, buffer1, strlen(buffer1) + 1, ec_key);
assert(cv);
memset(buffer3, 0, sizeof(buffer3));
if (!ECIES_do_decrypt(cv, &params, buffer3, &derlen, ec_key)) {
ERR_print_errors_fp(stderr);
return;
}
printf("decrypted plaintext length = %d\n", derlen);
printf("%s\n", buffer3);
derlen = i2d_ECIES_CIPHERTEXT_VALUE(cv, NULL);
printf("ECIES Test: ECIES_CIPHERTEXT_VALUE DER encoding length = %d\n", derlen);
der = OPENSSL_malloc(derlen);
assert(der);
p = der;
i2d_ECIES_CIPHERTEXT_VALUE(cv, &p);
ECIES_CIPHERTEXT_VALUE_free(cv);
cv = NULL;
cp = der;
cv = d2i_ECIES_CIPHERTEXT_VALUE(NULL, &cp, derlen);
assert(cv);
ecies_test_ECIESParameters();
}
int main(int argc, char **argv)
{
ecies_test();
return 0;
}

23
crypto/ecies/kdf.h Normal file
View File

@@ -0,0 +1,23 @@
#ifndef HEADER_KDF_H
#define HEADER_KDF_H
#include <openssl/evp.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef void *(*KDF_FUNC)(const void *in, size_t inlen, void *out, size_t *outlen);
KDF_FUNC KDF_get_x9_63(const EVP_MD *md);
KDF_FUNC KDF_get_nist_concatenation(void);
KDF_FUNC KDF_get_tls_kdf(void);
KDF_FUNC KDF_get_ikev2_kdf(void);
#ifdef __cplusplus
}
#endif
#endif

113
crypto/ecies/kdf_x9_63.c Normal file
View File

@@ -0,0 +1,113 @@
#include <string.h>
#include "kdf.h"
#ifdef CPU_BIGENDIAN
#define cpu_to_be16(v) (v)
#define cpu_to_be32(v) (v)
#else
#define cpu_to_be16(v) ((v << 8) | (v >> 8))
#define cpu_to_be32(v) ((cpu_to_be16(v) << 16) | cpu_to_be16(v >> 16))
#endif
static void *x963_kdf(const EVP_MD *md, const void *share, size_t sharelen,
void *key, size_t keylen)
{
EVP_MD_CTX ctx;
unsigned int counter = 1;
unsigned int counter_be;
unsigned char dgst[EVP_MAX_MD_SIZE];
unsigned int dgstlen;
int rlen = (int)keylen;
unsigned char *out = key;
EVP_MD_CTX_init(&ctx);
while (rlen > 0) {
counter_be = cpu_to_be32(counter);
counter++;
EVP_DigestInit(&ctx, md);
EVP_DigestUpdate(&ctx, share, sharelen);
EVP_DigestUpdate(&ctx, (const void *)&counter_be, 4);
EVP_DigestFinal(&ctx, dgst, &dgstlen);
memcpy(out, dgst, (int)dgstlen > rlen ? rlen : dgstlen);
rlen -= dgstlen;
out += dgstlen;
}
EVP_MD_CTX_cleanup(&ctx);
return key;
}
static void *x963_md5kdf(const void *share, size_t sharelen,
void *key, size_t *keylen)
{
return x963_kdf(EVP_md5(), share, sharelen, key, *keylen);
}
static void *x963_rmd160kdf(const void *share, size_t sharelen,
void *key, size_t *keylen)
{
return x963_kdf(EVP_ripemd160(), share, sharelen, key, *keylen);
}
static void *x963_sha1kdf(const void *share, size_t sharelen,
void *key, size_t *keylen)
{
return x963_kdf(EVP_sha1(), share, sharelen, key, *keylen);
}
static void *x963_sha224kdf(const void *share, size_t sharelen,
void *key, size_t *keylen)
{
return x963_kdf(EVP_sha224(), share, sharelen, key, *keylen);
}
static void *x963_sha256kdf(const void *share, size_t sharelen,
void *key, size_t *keylen)
{
return x963_kdf(EVP_sha256(), share, sharelen, key, *keylen);
}
static void *x963_sha384kdf(const void *share, size_t sharelen,
void *key, size_t *keylen)
{
return x963_kdf(EVP_sha384(), share, sharelen, key, *keylen);
}
static void *x963_sha512kdf(const void *share, size_t sharelen,
void *key, size_t *keylen)
{
return x963_kdf(EVP_sha512(), share, sharelen, key, *keylen);
}
static void *x963_sm3kdf(const void *share, size_t sharelen,
void *key, size_t *keylen)
{
return x963_kdf(EVP_sm3(), share, sharelen, key, *keylen);
}
KDF_FUNC KDF_get_x9_63(const EVP_MD *md)
{
if (md == EVP_md5())
return x963_md5kdf;
else if (md == EVP_ripemd160())
return x963_rmd160kdf;
else if (md == EVP_sha1())
return x963_sha1kdf;
else if (md == EVP_sha224())
return x963_sha224kdf;
else if (md == EVP_sha256())
return x963_sha256kdf;
else if (md == EVP_sha384())
return x963_sha384kdf;
else if (md == EVP_sha512())
return x963_sha512kdf;
else if (md == EVP_sm3())
return x963_sm3kdf;
return NULL;
}

View File

@@ -197,6 +197,7 @@ typedef struct err_state_st {
# define ERR_LIB_TS 47
# define ERR_LIB_HMAC 48
# define ERR_LIB_JPAKE 49
# define ERR_LIB_ECIES 50
# define ERR_LIB_USER 128
@@ -233,6 +234,7 @@ typedef struct err_state_st {
# define TSerr(f,r) ERR_PUT_error(ERR_LIB_TS,(f),(r),__FILE__,__LINE__)
# define HMACerr(f,r) ERR_PUT_error(ERR_LIB_HMAC,(f),(r),__FILE__,__LINE__)
# define JPAKEerr(f,r) ERR_PUT_error(ERR_LIB_JPAKE,(f),(r),__FILE__,__LINE__)
# define ECIESerr(f,r) ERR_PUT_error(ERR_LIB_ECIES,(f),(r),__FILE__,__LINE__)
/*
* Borland C seems too stupid to be able to shift and do longs in the
@@ -289,6 +291,7 @@ typedef struct err_state_st {
# define ERR_R_ECDH_LIB ERR_LIB_ECDH/* 43 */
# define ERR_R_STORE_LIB ERR_LIB_STORE/* 44 */
# define ERR_R_TS_LIB ERR_LIB_TS/* 45 */
# define ERR_R_EICES_LIB ERR_LIB_ECIES/* 50 */
# define ERR_R_NESTED_ASN1_ERROR 58
# define ERR_R_BAD_ASN1_OBJECT_HEADER 59

View File

@@ -165,8 +165,8 @@ void OpenSSL_add_all_ciphers(void)
#ifndef OPENSSL_NO_SMS4
EVP_add_cipher(EVP_sms4_ecb());
EVP_add_cipher(EVP_sms4_cfb128());
EVP_add_cipher(EVP_sms4_ofb());
//EVP_add_cipher(EVP_sms4_cfb128());
//EVP_add_cipher(EVP_sms4_ofb());
EVP_add_cipher(EVP_sms4_cbc());
EVP_add_cipher_alias(SN_sms4_cbc,"SMS4");
EVP_add_cipher_alias(SN_sms4_cbc,"sms4");

View File

@@ -62,12 +62,12 @@
* [including the GNU Public Licence.]
*/
#define NUM_NID 983
#define NUM_SN 968
#define NUM_LN 968
#define NUM_OBJ 907
#define NUM_NID 1000
#define NUM_SN 985
#define NUM_LN 985
#define NUM_OBJ 924
static const unsigned char lvalues[6386]={
static const unsigned char lvalues[6483]={
0x2A,0x86,0x48,0x86,0xF7,0x0D, /* [ 0] OBJ_rsadsi */
0x2A,0x86,0x48,0x86,0xF7,0x0D,0x01, /* [ 6] OBJ_pkcs */
0x2A,0x86,0x48,0x86,0xF7,0x0D,0x02,0x02, /* [ 13] OBJ_md2 */
@@ -969,6 +969,23 @@ static const unsigned char lvalues[6386]={
0x2A,0x81,0x1C,0xCF,0x55,0x01,0x68,0x02, /* [6361] OBJ_sms4_cbc */
0x2A,0x81,0x1C,0xCF,0x55,0x01,0x68,0x04, /* [6369] OBJ_sms4_ofb128 */
0x2A,0x81,0x1C,0xCF,0x55,0x01,0x68,0x03, /* [6377] OBJ_sms4_cfb128 */
0x2B,0x81,0x04,0x01,0x07, /* [6385] OBJ_ecies_recommendedParameters */
0x2B,0x81,0x04,0x01,0x08, /* [6390] OBJ_ecies_specifiedParameters */
0x2B,0x81,0x04,0x01,0x11,0x00, /* [6395] OBJ_x9_63_kdf */
0x2B,0x81,0x04,0x01,0x11,0x01, /* [6401] OBJ_nist_concatenation_kdf */
0x2B,0x81,0x04,0x01,0x11,0x02, /* [6407] OBJ_tls_kdf */
0x2B,0x81,0x04,0x01,0x11,0x03, /* [6413] OBJ_ikev2_kdf */
0x2B,0x81,0x04,0x01,0x12, /* [6419] OBJ_xor_in_ecies */
0x2B,0x81,0x04,0x01,0x14,0x00, /* [6424] OBJ_aes128_cbc_in_ecies */
0x2B,0x81,0x04,0x01,0x14,0x01, /* [6430] OBJ_aes192_cbc_in_ecies */
0x2B,0x81,0x04,0x01,0x14,0x02, /* [6436] OBJ_aes256_cbc_in_ecies */
0x2B,0x81,0x04,0x01,0x15,0x00, /* [6442] OBJ_aes128_ctr_in_ecies */
0x2B,0x81,0x04,0x01,0x15,0x01, /* [6448] OBJ_aes192_ctr_in_ecies */
0x2B,0x81,0x04,0x01,0x15,0x02, /* [6454] OBJ_aes256_ctr_in_ecies */
0x2B,0x81,0x04,0x01,0x16, /* [6460] OBJ_hmac_full_ecies */
0x2B,0x81,0x04,0x01,0x17, /* [6465] OBJ_hmac_half_ecies */
0x2B,0x81,0x04,0x01,0x18,0x00, /* [6470] OBJ_cmac_aes128_ecies */
0x2B,0x81,0x04,0x01,0x18,0x01, /* [6476] OBJ_cmac_aes192_ecies */
};
static const ASN1_OBJECT nid_objs[NUM_NID]={
@@ -2560,6 +2577,36 @@ static const ASN1_OBJECT nid_objs[NUM_NID]={
{NULL,NULL,NID_undef,0,NULL,0},
{"SMS4-OFB","sms4-ofb",NID_sms4_ofb128,8,&(lvalues[6369]),0},
{"SMS4-CFB","sms4-cfb",NID_sms4_cfb128,8,&(lvalues[6377]),0},
{"ecies-recommendedParameters","ecies-recommendedParameters",
NID_ecies_recommendedParameters,5,&(lvalues[6385]),0},
{"ecies-specifiedParameters","ecies-specifiedParameters",
NID_ecies_specifiedParameters,5,&(lvalues[6390]),0},
{"x9-63-kdf","x9-63-kdf",NID_x9_63_kdf,6,&(lvalues[6395]),0},
{"nist-concatenation-kdf","nist-concatenation-kdf",
NID_nist_concatenation_kdf,6,&(lvalues[6401]),0},
{"tls-kdf","tls-kdf",NID_tls_kdf,6,&(lvalues[6407]),0},
{"ikev2-kdf","ikev2-kdf",NID_ikev2_kdf,6,&(lvalues[6413]),0},
{"xor-in-ecies","xor-in-ecies",NID_xor_in_ecies,5,&(lvalues[6419]),0},
{"aes128-cbc-in-ecies","aes128-cbc-in-ecies",NID_aes128_cbc_in_ecies,
6,&(lvalues[6424]),0},
{"aes192-cbc-in-ecies","aes192-cbc-in-ecies",NID_aes192_cbc_in_ecies,
6,&(lvalues[6430]),0},
{"aes256-cbc-in-ecies","aes256-cbc-in-ecies",NID_aes256_cbc_in_ecies,
6,&(lvalues[6436]),0},
{"aes128-ctr-in-ecies","aes128-ctr-in-ecies",NID_aes128_ctr_in_ecies,
6,&(lvalues[6442]),0},
{"aes192-ctr-in-ecies","aes192-ctr-in-ecies",NID_aes192_ctr_in_ecies,
6,&(lvalues[6448]),0},
{"aes256-ctr-in-ecies","aes256-ctr-in-ecies",NID_aes256_ctr_in_ecies,
6,&(lvalues[6454]),0},
{"hmac-full-ecies","hmac-full-ecies",NID_hmac_full_ecies,5,
&(lvalues[6460]),0},
{"hmac-half-ecies","hmac-half-ecies",NID_hmac_half_ecies,5,
&(lvalues[6465]),0},
{"cmac-aes128-ecies","cmac-aes128-ecies",NID_cmac_aes128_ecies,6,
&(lvalues[6470]),0},
{"cmac-aes192-ecies","cmac-aes192-ecies",NID_cmac_aes192_ecies,6,
&(lvalues[6476]),0},
};
static const unsigned int sn_objs[NUM_SN]={
@@ -2774,6 +2821,12 @@ static const unsigned int sn_objs[NUM_SN]={
368, /* "acceptableResponses" */
446, /* "account" */
363, /* "ad_timestamping" */
990, /* "aes128-cbc-in-ecies" */
993, /* "aes128-ctr-in-ecies" */
991, /* "aes192-cbc-in-ecies" */
994, /* "aes192-ctr-in-ecies" */
992, /* "aes256-cbc-in-ecies" */
995, /* "aes256-ctr-in-ecies" */
376, /* "algorithm" */
405, /* "ansi-X9-62" */
910, /* "anyExtendedKeyUsage" */
@@ -2838,6 +2891,8 @@ static const unsigned int sn_objs[NUM_SN]={
407, /* "characteristic-two-field" */
395, /* "clearance" */
130, /* "clientAuth" */
998, /* "cmac-aes128-ecies" */
999, /* "cmac-aes192-ecies" */
131, /* "codeSigning" */
50, /* "contentType" */
53, /* "countersignature" */
@@ -2897,6 +2952,8 @@ static const unsigned int sn_objs[NUM_SN]={
795, /* "ecdsa-with-SHA384" */
796, /* "ecdsa-with-SHA512" */
792, /* "ecdsa-with-Specified" */
983, /* "ecies-recommendedParameters" */
984, /* "ecies-specifiedParameters" */
48, /* "emailAddress" */
132, /* "emailProtection" */
885, /* "enhancedSearchGuide" */
@@ -2920,6 +2977,8 @@ static const unsigned int sn_objs[NUM_SN]={
814, /* "gost89-cnt" */
812, /* "gost94" */
850, /* "gost94cc" */
996, /* "hmac-full-ecies" */
997, /* "hmac-half-ecies" */
797, /* "hmacWithMD5" */
163, /* "hmacWithSHA1" */
798, /* "hmacWithSHA224" */
@@ -3172,6 +3231,7 @@ static const unsigned int sn_objs[NUM_SN]={
250, /* "id-smime-spq-ets-sqt-unotice" */
249, /* "id-smime-spq-ets-sqt-uri" */
676, /* "identified-organization" */
988, /* "ikev2-kdf" */
461, /* "info" */
748, /* "inhibitAnyPolicy" */
101, /* "initials" */
@@ -3216,6 +3276,7 @@ static const unsigned int sn_objs[NUM_SN]={
481, /* "nSRecord" */
173, /* "name" */
666, /* "nameConstraints" */
986, /* "nist-concatenation-kdf" */
369, /* "noCheck" */
403, /* "noRevAvail" */
72, /* "nsBaseUrl" */
@@ -3503,6 +3564,7 @@ static const unsigned int sn_objs[NUM_SN]={
293, /* "textNotice" */
133, /* "timeStamping" */
106, /* "title" */
987, /* "tls-kdf" */
682, /* "tpBasis" */
375, /* "trustRoot" */
436, /* "ucl" */
@@ -3531,6 +3593,8 @@ static const unsigned int sn_objs[NUM_SN]={
503, /* "x500UniqueIdentifier" */
158, /* "x509Certificate" */
160, /* "x509Crl" */
985, /* "x9-63-kdf" */
989, /* "xor-in-ecies" */
};
static const unsigned int ln_objs[NUM_LN]={
@@ -3718,6 +3782,12 @@ static const unsigned int ln_objs[NUM_LN]={
901, /* "aes-256-gcm" */
428, /* "aes-256-ofb" */
914, /* "aes-256-xts" */
990, /* "aes128-cbc-in-ecies" */
993, /* "aes128-ctr-in-ecies" */
991, /* "aes192-cbc-in-ecies" */
994, /* "aes192-ctr-in-ecies" */
992, /* "aes256-cbc-in-ecies" */
995, /* "aes256-ctr-in-ecies" */
376, /* "algorithm" */
484, /* "associatedDomain" */
485, /* "associatedName" */
@@ -3797,6 +3867,8 @@ static const unsigned int ln_objs[NUM_LN]={
395, /* "clearance" */
633, /* "cleartext track 2" */
894, /* "cmac" */
998, /* "cmac-aes128-ecies" */
999, /* "cmac-aes192-ecies" */
13, /* "commonName" */
513, /* "content types" */
50, /* "contentType" */
@@ -3876,6 +3948,8 @@ static const unsigned int ln_objs[NUM_LN]={
795, /* "ecdsa-with-SHA384" */
796, /* "ecdsa-with-SHA512" */
792, /* "ecdsa-with-Specified" */
983, /* "ecies-recommendedParameters" */
984, /* "ecies-specifiedParameters" */
48, /* "emailAddress" */
632, /* "encrypted track 2" */
885, /* "enhancedSearchGuide" */
@@ -3891,6 +3965,8 @@ static const unsigned int ln_objs[NUM_LN]={
99, /* "givenName" */
814, /* "gost89-cnt" */
855, /* "hmac" */
996, /* "hmac-full-ecies" */
997, /* "hmac-half-ecies" */
780, /* "hmac-md5" */
781, /* "hmac-sha1" */
963, /* "hmac-sm3" */
@@ -4123,6 +4199,7 @@ static const unsigned int ln_objs[NUM_LN]={
36, /* "idea-ecb" */
46, /* "idea-ofb" */
676, /* "identified-organization" */
988, /* "ikev2-kdf" */
461, /* "info" */
101, /* "initials" */
869, /* "internationaliSDNNumber" */
@@ -4165,6 +4242,7 @@ static const unsigned int ln_objs[NUM_LN]={
488, /* "mobileTelephoneNumber" */
481, /* "nSRecord" */
173, /* "name" */
986, /* "nist-concatenation-kdf" */
681, /* "onBasis" */
379, /* "org" */
17, /* "organizationName" */
@@ -4472,6 +4550,7 @@ static const unsigned int ln_objs[NUM_LN]={
459, /* "textEncodedORAddress" */
293, /* "textNotice" */
106, /* "title" */
987, /* "tls-kdf" */
682, /* "tpBasis" */
436, /* "ucl" */
0, /* "undefined" */
@@ -4501,6 +4580,8 @@ static const unsigned int ln_objs[NUM_LN]={
503, /* "x500UniqueIdentifier" */
158, /* "x509Certificate" */
160, /* "x509Crl" */
985, /* "x9-63-kdf" */
989, /* "xor-in-ecies" */
125, /* "zlib compression" */
};
@@ -4794,6 +4875,11 @@ static const unsigned int obj_objs[NUM_OBJ]={
732, /* OBJ_sect409r1 1 3 132 0 37 */
733, /* OBJ_sect571k1 1 3 132 0 38 */
734, /* OBJ_sect571r1 1 3 132 0 39 */
983, /* OBJ_ecies_recommendedParameters 1 3 132 1 7 */
984, /* OBJ_ecies_specifiedParameters 1 3 132 1 8 */
989, /* OBJ_xor_in_ecies 1 3 132 1 18 */
996, /* OBJ_hmac_full_ecies 1 3 132 1 22 */
997, /* OBJ_hmac_half_ecies 1 3 132 1 23 */
624, /* OBJ_set_rootKeyThumb 2 23 42 3 0 0 */
625, /* OBJ_set_addPolicy 2 23 42 3 0 1 */
626, /* OBJ_setAttr_Token_EMV 2 23 42 3 2 1 */
@@ -4842,6 +4928,18 @@ static const unsigned int obj_objs[NUM_OBJ]={
943, /* OBJ_dhSinglePass_cofactorDH_sha256kdf_scheme 1 3 132 1 14 1 */
944, /* OBJ_dhSinglePass_cofactorDH_sha384kdf_scheme 1 3 132 1 14 2 */
945, /* OBJ_dhSinglePass_cofactorDH_sha512kdf_scheme 1 3 132 1 14 3 */
985, /* OBJ_x9_63_kdf 1 3 132 1 17 0 */
986, /* OBJ_nist_concatenation_kdf 1 3 132 1 17 1 */
987, /* OBJ_tls_kdf 1 3 132 1 17 2 */
988, /* OBJ_ikev2_kdf 1 3 132 1 17 3 */
990, /* OBJ_aes128_cbc_in_ecies 1 3 132 1 20 0 */
991, /* OBJ_aes192_cbc_in_ecies 1 3 132 1 20 1 */
992, /* OBJ_aes256_cbc_in_ecies 1 3 132 1 20 2 */
993, /* OBJ_aes128_ctr_in_ecies 1 3 132 1 21 0 */
994, /* OBJ_aes192_ctr_in_ecies 1 3 132 1 21 1 */
995, /* OBJ_aes256_ctr_in_ecies 1 3 132 1 21 2 */
998, /* OBJ_cmac_aes128_ecies 1 3 132 1 24 0 */
999, /* OBJ_cmac_aes192_ecies 1 3 132 1 24 1 */
631, /* OBJ_setAttr_GenCryptgrm 2 23 42 3 3 3 1 */
632, /* OBJ_setAttr_T2Enc 2 23 42 3 3 4 1 */
633, /* OBJ_setAttr_T2cleartxt 2 23 42 3 3 4 2 */

View File

@@ -4193,6 +4193,76 @@
#define NID_jurisdictionCountryName 957
#define OBJ_jurisdictionCountryName 1L,3L,6L,1L,4L,1L,311L,60L,2L,1L,3L
#define OBJ_secg_scheme OBJ_certicom_arc,1L
#define SN_ecies_recommendedParameters "ecies-recommendedParameters"
#define NID_ecies_recommendedParameters 983
#define OBJ_ecies_recommendedParameters OBJ_secg_scheme,7L
#define SN_ecies_specifiedParameters "ecies-specifiedParameters"
#define NID_ecies_specifiedParameters 984
#define OBJ_ecies_specifiedParameters OBJ_secg_scheme,8L
#define SN_x9_63_kdf "x9-63-kdf"
#define NID_x9_63_kdf 985
#define OBJ_x9_63_kdf OBJ_secg_scheme,17L,0L
#define SN_nist_concatenation_kdf "nist-concatenation-kdf"
#define NID_nist_concatenation_kdf 986
#define OBJ_nist_concatenation_kdf OBJ_secg_scheme,17L,1L
#define SN_tls_kdf "tls-kdf"
#define NID_tls_kdf 987
#define OBJ_tls_kdf OBJ_secg_scheme,17L,2L
#define SN_ikev2_kdf "ikev2-kdf"
#define NID_ikev2_kdf 988
#define OBJ_ikev2_kdf OBJ_secg_scheme,17L,3L
#define SN_xor_in_ecies "xor-in-ecies"
#define NID_xor_in_ecies 989
#define OBJ_xor_in_ecies OBJ_secg_scheme,18L
#define SN_aes128_cbc_in_ecies "aes128-cbc-in-ecies"
#define NID_aes128_cbc_in_ecies 990
#define OBJ_aes128_cbc_in_ecies OBJ_secg_scheme,20L,0L
#define SN_aes192_cbc_in_ecies "aes192-cbc-in-ecies"
#define NID_aes192_cbc_in_ecies 991
#define OBJ_aes192_cbc_in_ecies OBJ_secg_scheme,20L,1L
#define SN_aes256_cbc_in_ecies "aes256-cbc-in-ecies"
#define NID_aes256_cbc_in_ecies 992
#define OBJ_aes256_cbc_in_ecies OBJ_secg_scheme,20L,2L
#define SN_aes128_ctr_in_ecies "aes128-ctr-in-ecies"
#define NID_aes128_ctr_in_ecies 993
#define OBJ_aes128_ctr_in_ecies OBJ_secg_scheme,21L,0L
#define SN_aes192_ctr_in_ecies "aes192-ctr-in-ecies"
#define NID_aes192_ctr_in_ecies 994
#define OBJ_aes192_ctr_in_ecies OBJ_secg_scheme,21L,1L
#define SN_aes256_ctr_in_ecies "aes256-ctr-in-ecies"
#define NID_aes256_ctr_in_ecies 995
#define OBJ_aes256_ctr_in_ecies OBJ_secg_scheme,21L,2L
#define SN_hmac_full_ecies "hmac-full-ecies"
#define NID_hmac_full_ecies 996
#define OBJ_hmac_full_ecies OBJ_secg_scheme,22L
#define SN_hmac_half_ecies "hmac-half-ecies"
#define NID_hmac_half_ecies 997
#define OBJ_hmac_half_ecies OBJ_secg_scheme,23L
#define SN_cmac_aes128_ecies "cmac-aes128-ecies"
#define NID_cmac_aes128_ecies 998
#define OBJ_cmac_aes128_ecies OBJ_secg_scheme,24L,0L
#define SN_cmac_aes192_ecies "cmac-aes192-ecies"
#define NID_cmac_aes192_ecies 999
#define OBJ_cmac_aes192_ecies OBJ_secg_scheme,24L,1L
#define SN_ISO_CN "ISO-CN"
#define LN_ISO_CN "ISO CN Member Body"
#define NID_ISO_CN 960

View File

@@ -980,3 +980,20 @@ sms4_cfb 979
sms4_ofb 980
sms4_ofb128 981
sms4_cfb128 982
ecies_recommendedParameters 983
ecies_specifiedParameters 984
x9_63_kdf 985
nist_concatenation_kdf 986
tls_kdf 987
ikev2_kdf 988
xor_in_ecies 989
aes128_cbc_in_ecies 990
aes192_cbc_in_ecies 991
aes256_cbc_in_ecies 992
aes128_ctr_in_ecies 993
aes192_ctr_in_ecies 994
aes256_ctr_in_ecies 995
hmac_full_ecies 996
hmac_half_ecies 997
cmac_aes128_ecies 998
cmac_aes192_ecies 999

View File

@@ -1349,6 +1349,29 @@ secg-scheme 14 3 : dhSinglePass-cofactorDH-sha512kdf-scheme
1 3 6 1 4 1 311 60 2 1 2 : jurisdictionST : jurisdictionStateOrProvinceName
1 3 6 1 4 1 311 60 2 1 3 : jurisdictionC : jurisdictionCountryName
# ECIES OID
!Alias secg_scheme certicom-arc 1
secg-scheme 7 : ecies-recommendedParameters
secg-scheme 8 : ecies-specifiedParameters
secg-scheme 17 0 : x9-63-kdf
secg-scheme 17 1 : nist-concatenation-kdf
secg-scheme 17 2 : tls-kdf
secg-scheme 17 3 : ikev2-kdf
secg-scheme 18 : xor-in-ecies
secg-scheme 20 0 : aes128-cbc-in-ecies
secg-scheme 20 1 : aes192-cbc-in-ecies
secg-scheme 20 2 : aes256-cbc-in-ecies
secg-scheme 21 0 : aes128-ctr-in-ecies
secg-scheme 21 1 : aes192-ctr-in-ecies
secg-scheme 21 2 : aes256-ctr-in-ecies
secg-scheme 22 : hmac-full-ecies
secg-scheme 23 : hmac-half-ecies
secg-scheme 24 0 : cmac-aes128-ecies
secg-scheme 24 1 : cmac-aes192-ecies
# SM: China National Cryptography Standards
member-body 156 : ISO-CN : ISO CN Member Body
ISO-CN 10197 : oscca

View File

@@ -109,8 +109,8 @@ extern "C" {
#if !(defined(VMS) || defined(__VMS)) /* VMS uses logical names instead */
#if defined(HEADER_CRYPTLIB_H) && !defined(OPENSSLDIR)
#define ENGINESDIR "/usr/local/ssl/lib/engines"
#define OPENSSLDIR "/usr/local/ssl"
#define ENGINESDIR "/usr/local/lib/engines"
#define OPENSSLDIR "/usr/local/openssl"
#endif
#endif
@@ -156,20 +156,20 @@ extern "C" {
/* If this is set to 'unsigned int' on a DEC Alpha, this gives about a
* %20 speed up (longs are 8 bytes, int's are 4). */
#ifndef DES_LONG
#define DES_LONG unsigned long
#define DES_LONG unsigned int
#endif
#endif
#if defined(HEADER_BN_H) && !defined(CONFIG_HEADER_BN_H)
#define CONFIG_HEADER_BN_H
#define BN_LLONG
#undef BN_LLONG
/* Should we define BN_DIV2W here? */
/* Only one for the following should be defined */
#undef SIXTY_FOUR_BIT_LONG
#define SIXTY_FOUR_BIT_LONG
#undef SIXTY_FOUR_BIT
#define THIRTY_TWO_BIT
#undef THIRTY_TWO_BIT
#endif
#if defined(HEADER_RC4_LOCL_H) && !defined(CONFIG_HEADER_RC4_LOCL_H)
@@ -181,7 +181,7 @@ extern "C" {
#if defined(HEADER_BF_LOCL_H) && !defined(CONFIG_HEADER_BF_LOCL_H)
#define CONFIG_HEADER_BF_LOCL_H
#define BF_PTR
#undef BF_PTR
#endif /* HEADER_BF_LOCL_H */
#if defined(HEADER_DES_LOCL_H) && !defined(CONFIG_HEADER_DES_LOCL_H)

1
include/openssl/ecies.h Symbolic link
View File

@@ -0,0 +1 @@
../../crypto/ecies/ecies.h

1
include/openssl/kdf.h Symbolic link
View File

@@ -0,0 +1 @@
../../crypto/ecies/kdf.h

1
test/eciestest.c Symbolic link
View File

@@ -0,0 +1 @@
../crypto/ecies/eciestest.c

View File

@@ -3,8 +3,8 @@
# Perl c_rehash script, scan all files in a directory
# and add symbolic links to their hash values.
my $dir = "/usr/local/ssl";
my $prefix = "/usr/local/ssl";
my $dir = "/usr/local/openssl";
my $prefix = "/usr/local";
my $openssl = $ENV{OPENSSL} || "openssl";
my $pwd;

View File

@@ -84,7 +84,7 @@ my @known_ossl_platforms = ( "VMS", "WIN16", "WIN32", "WINNT", "OS2" );
my @known_algorithms = ( "RC2", "RC4", "RC5", "IDEA", "DES", "BF",
"CAST", "MD2", "MD4", "MD5", "SHA", "SHA0", "SHA1",
"SHA256", "SHA512", "RIPEMD", "SM3", "SMS4",
"MDC2", "WHIRLPOOL", "RSA", "DSA", "DH", "EC", "ECDH", "ECDSA", "EC2M",
"MDC2", "WHIRLPOOL", "RSA", "DSA", "DH", "EC", "ECDH", "ECDSA", "EC2M", "ECIES",
"HMAC", "AES", "CAMELLIA", "SEED", "GOST",
# EC_NISTP_64_GCC_128
"EC_NISTP_64_GCC_128",
@@ -318,6 +318,8 @@ $crypto.=" crypto/dsa/dsa.h" ; # unless $no_dsa;
$crypto.=" crypto/dh/dh.h" ; # unless $no_dh;
$crypto.=" crypto/ec/ec.h" ; # unless $no_ec;
$crypto.=" crypto/ecdsa/ecdsa.h" ; # unless $no_ecdsa;
$crypto.=" crypto/ecies/ecies.h" ;
$crypto.=" crypto/ecies/kdf.h" ;
$crypto.=" crypto/ecdh/ecdh.h" ; # unless $no_ecdh;
$crypto.=" crypto/hmac/hmac.h" ; # unless $no_hmac;
$crypto.=" crypto/cmac/cmac.h" ; # unless $no_hmac;

View File

@@ -38,6 +38,7 @@ my @dirs = (
"crypto/ec",
"crypto/ecdh",
"crypto/ecdsa",
"crypto/ecies",
"crypto/buffer",
"crypto/bio",
"crypto/stack",